From ac423fa6ba28e890b07d9717d412d3387e3b03e6 Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 14 Oct 2021 00:18:51 -0600 Subject: [PATCH] change trade structure in clientstate --- src/ship/packet/handler/trade.rs | 12 ++++++++---- src/ship/ship.rs | 17 ++++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/ship/packet/handler/trade.rs b/src/ship/packet/handler/trade.rs index a1ea277..1718f63 100644 --- a/src/ship/packet/handler/trade.rs +++ b/src/ship/packet/handler/trade.rs @@ -6,7 +6,7 @@ use libpso::packet::ship::*; use libpso::packet::messages::*; use crate::common::leveltable::CharacterLevelTable; use crate::common::serverstate::ClientId; -use crate::ship::ship::{SendShipPacket, ShipError, Clients, Rooms, ItemShops, TradeItem}; +use crate::ship::ship::{SendShipPacket, ShipError, Clients, Rooms, ItemShops, TradeItem, TradeState, TradeStatus}; use crate::ship::location::{ClientLocation, ClientLocationError}; use crate::ship::drops::ItemDrop; use crate::ship::items::{ItemManager, ItemManagerError, ClientItemId, TriggerCreateItem, FloorItem, FloorType}; @@ -86,7 +86,11 @@ where .collect::, anyhow::Error>>()?; // TODO: check room in inventory for items - client.trade = Some((trade_partner.client, trade_items)); + client.trade = Some(TradeState { + other_client: trade_partner.client, + items: trade_items, + status: TradeStatus::Unconfirmed + }); Ok(Box::new(vec![(trade_partner.client, SendShipPacket::AcknowledgeTrade(AcknowledgeTrade {}))].into_iter())) } @@ -107,8 +111,8 @@ where Err(err) => { let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; let trade_partner = client.trade.as_ref() - .and_then(|(trade_partner, _)| { - client_location.get_local_client(*trade_partner).ok() + .and_then(|trade_state| { + client_location.get_local_client(trade_state.other_client).ok() }) .map(|trade_partner| { (trade_partner.client, SendShipPacket::CancelTrade(CancelTrade {})) diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 1478143..8166936 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -248,12 +248,25 @@ pub struct LoadingQuest { } +#[derive(Clone)] pub enum TradeItem { Individual(items::ClientItemId), Stacked(items::ClientItemId, usize), Meseta(usize), } +#[derive(Clone, Eq, PartialEq)] +pub enum TradeStatus { + Confirmed, + Unconfirmed, +} + +#[derive(Clone)] +pub struct TradeState { + pub other_client: ClientId, + pub items: Vec, + pub status: TradeStatus, +} pub struct ClientState { pub user: UserAccountEntity, @@ -273,8 +286,7 @@ pub struct ClientState { pub tool_shop: Vec, pub armor_shop: Vec, pub tek: Option<(items::ClientItemId, item::weapon::TekSpecialModifier, item::weapon::TekPercentModifier, i32)>, - pub trade: Option<(ClientId, Vec)>, - pub confirmed_trade: bool, + pub trade: Option, } impl ClientState { @@ -296,7 +308,6 @@ impl ClientState { armor_shop: Vec::new(), tek: None, trade: None, - confirmed_trade: false, } } }