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 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::<Result<Vec<_>, 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 {}))

17
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<TradeItem>,
pub status: TradeStatus,
}
pub struct ClientState {
pub user: UserAccountEntity,
@ -273,8 +286,7 @@ pub struct ClientState {
pub tool_shop: Vec<ToolShopItem>,
pub armor_shop: Vec<ArmorShopItem>,
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 {
@ -296,7 +308,6 @@ impl ClientState {
armor_shop: Vec::new(),
tek: None,
trade: None,
confirmed_trade: false,
}
}
}

Loading…
Cancel
Save