Browse Source

change trade structure in clientstate

pull/80/head
jake 3 years ago
parent
commit
ac423fa6ba
  1. 12
      src/ship/packet/handler/trade.rs
  2. 17
      src/ship/ship.rs

12
src/ship/packet/handler/trade.rs

@ -6,7 +6,7 @@ use libpso::packet::ship::*;
use libpso::packet::messages::*; use libpso::packet::messages::*;
use crate::common::leveltable::CharacterLevelTable; use crate::common::leveltable::CharacterLevelTable;
use crate::common::serverstate::ClientId; 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::location::{ClientLocation, ClientLocationError};
use crate::ship::drops::ItemDrop; use crate::ship::drops::ItemDrop;
use crate::ship::items::{ItemManager, ItemManagerError, ClientItemId, TriggerCreateItem, FloorItem, FloorType}; use crate::ship::items::{ItemManager, ItemManagerError, ClientItemId, TriggerCreateItem, FloorItem, FloorType};
@ -86,7 +86,11 @@ where
.collect::<Result<Vec<_>, anyhow::Error>>()?; .collect::<Result<Vec<_>, anyhow::Error>>()?;
// TODO: check room in inventory for items // 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())) Ok(Box::new(vec![(trade_partner.client, SendShipPacket::AcknowledgeTrade(AcknowledgeTrade {}))].into_iter()))
} }
@ -107,8 +111,8 @@ where
Err(err) => { Err(err) => {
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
let trade_partner = client.trade.as_ref() 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| { .map(|trade_partner| {
(trade_partner.client, SendShipPacket::CancelTrade(CancelTrade {})) (trade_partner.client, SendShipPacket::CancelTrade(CancelTrade {}))

17
src/ship/ship.rs

@ -248,12 +248,25 @@ pub struct LoadingQuest {
} }
#[derive(Clone)]
pub enum TradeItem { pub enum TradeItem {
Individual(items::ClientItemId), Individual(items::ClientItemId),
Stacked(items::ClientItemId, usize), Stacked(items::ClientItemId, usize),
Meseta(usize), Meseta(usize),
} }
#[derive(Clone, Eq, PartialEq)]
pub enum TradeStatus {
Confirmed,
Unconfirmed,
}
#[derive(Clone)]
pub struct TradeState {
pub other_client: ClientId,
pub items: Vec<TradeItem>,
pub status: TradeStatus,
}
pub struct ClientState { pub struct ClientState {
pub user: UserAccountEntity, pub user: UserAccountEntity,
@ -273,8 +286,7 @@ pub struct ClientState {
pub tool_shop: Vec<ToolShopItem>, pub tool_shop: Vec<ToolShopItem>,
pub armor_shop: Vec<ArmorShopItem>, pub armor_shop: Vec<ArmorShopItem>,
pub tek: Option<(items::ClientItemId, item::weapon::TekSpecialModifier, item::weapon::TekPercentModifier, i32)>, pub tek: Option<(items::ClientItemId, item::weapon::TekSpecialModifier, item::weapon::TekPercentModifier, i32)>,
pub trade: Option<(ClientId, Vec<TradeItem>)>,
pub confirmed_trade: bool,
pub trade: Option<TradeState>,
} }
impl ClientState { impl ClientState {
@ -296,7 +308,6 @@ impl ClientState {
armor_shop: Vec::new(), armor_shop: Vec::new(),
tek: None, tek: None,
trade: None, trade: None,
confirmed_trade: false,
} }
} }
} }

Loading…
Cancel
Save