pub struct TradeWindow {
pub id: u64,
pub player_a: String,
pub player_b: String,
pub offer_a: Vec<(String, u32)>,
pub offer_b: Vec<(String, u32)>,
pub gold_a: u64,
pub gold_b: u64,
pub confirmed_a: bool,
pub confirmed_b: bool,
pub completed: bool,
pub cancelled: bool,
}Expand description
State of an active trade negotiation between two players.
Fields§
§id: u64§player_a: String§player_b: String§offer_a: Vec<(String, u32)>Items offered by player A (item_id, quantity).
offer_b: Vec<(String, u32)>Items offered by player B (item_id, quantity).
gold_a: u64Additional gold offered by A (in copper; can be 0).
gold_b: u64Additional gold offered by B (in copper; can be 0).
confirmed_a: bool§confirmed_b: bool§completed: boolWhether the trade was executed (items already swapped).
cancelled: boolWhether the trade was cancelled.
Implementations§
Source§impl TradeWindow
impl TradeWindow
pub fn new(id: u64, player_a: &str, player_b: &str) -> Self
Sourcepub fn add_item_a(&mut self, item_id: impl Into<String>, quantity: u32)
pub fn add_item_a(&mut self, item_id: impl Into<String>, quantity: u32)
Add an item to player A’s offer. Resets both confirmations.
Sourcepub fn add_item_b(&mut self, item_id: impl Into<String>, quantity: u32)
pub fn add_item_b(&mut self, item_id: impl Into<String>, quantity: u32)
Add an item to player B’s offer. Resets both confirmations.
Sourcepub fn set_gold_a(&mut self, copper: u64)
pub fn set_gold_a(&mut self, copper: u64)
Set gold offer for player A. Resets both confirmations.
Sourcepub fn set_gold_b(&mut self, copper: u64)
pub fn set_gold_b(&mut self, copper: u64)
Set gold offer for player B. Resets both confirmations.
Sourcepub fn remove_item_a(&mut self, index: usize)
pub fn remove_item_a(&mut self, index: usize)
Remove an item from player A’s offer by index.
Sourcepub fn remove_item_b(&mut self, index: usize)
pub fn remove_item_b(&mut self, index: usize)
Remove an item from player B’s offer by index.
Sourcepub fn unconfirm(&mut self, player_id: &str)
pub fn unconfirm(&mut self, player_id: &str)
Un-confirm (e.g. when the other player changes their offer).
Sourcepub fn execute(
&mut self,
inventory_a: &mut HashMap<String, u32>,
inventory_b: &mut HashMap<String, u32>,
currency_a: &mut Currency,
currency_b: &mut Currency,
) -> Result<(), String>
pub fn execute( &mut self, inventory_a: &mut HashMap<String, u32>, inventory_b: &mut HashMap<String, u32>, currency_a: &mut Currency, currency_b: &mut Currency, ) -> Result<(), String>
Execute the trade, validating both parties have sufficient funds and inventory.
inventory_a and inventory_b are item_id -> quantity maps for each player.
currency_a and currency_b are each player’s wallet (modified in place).
Returns Ok(()) if the trade succeeded, Err with reason otherwise.
Trait Implementations§
Source§impl Clone for TradeWindow
impl Clone for TradeWindow
Source§fn clone(&self) -> TradeWindow
fn clone(&self) -> TradeWindow
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TradeWindow
impl RefUnwindSafe for TradeWindow
impl Send for TradeWindow
impl Sync for TradeWindow
impl Unpin for TradeWindow
impl UnsafeUnpin for TradeWindow
impl UnwindSafe for TradeWindow
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.