From e1360e4958ee2094e83987667bbf7be1ebe5e2f6 Mon Sep 17 00:00:00 2001 From: andy Date: Sun, 1 Nov 2020 23:14:38 -0400 Subject: [PATCH] bank doesn't spawn infinite money! --- src/ship/items/bank.rs | 1 + src/ship/items/inventory.rs | 1 + src/ship/packet/builder/message.rs | 6 +++--- src/ship/packet/handler/direct_message.rs | 16 +++++++++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ship/items/bank.rs b/src/ship/items/bank.rs index 2bbe097..c9d280a 100644 --- a/src/ship/items/bank.rs +++ b/src/ship/items/bank.rs @@ -5,6 +5,7 @@ use crate::entity::item::tool::Tool; use crate::ship::items::inventory::{InventoryItemHandle, InventoryItem}; const BANK_CAPACITY: usize = 200; +// const BANK_MESETA_CAPACITY: u32 = 999999; compiler error: private module #[derive(Debug, Clone)] pub struct IndividualBankItem { diff --git a/src/ship/items/inventory.rs b/src/ship/items/inventory.rs index 6360037..52d1d79 100644 --- a/src/ship/items/inventory.rs +++ b/src/ship/items/inventory.rs @@ -8,6 +8,7 @@ use crate::ship::items::{ClientItemId, BankItem, BankItemHandle}; use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem}; const INVENTORY_CAPACITY: usize = 30; +// const INVENTORY_MESETA_CAPACITY: u32 = 999999; // compiler error: private module #[derive(Debug, Clone)] diff --git a/src/ship/packet/builder/message.rs b/src/ship/packet/builder/message.rs index d7bfe75..e57f626 100644 --- a/src/ship/packet/builder/message.rs +++ b/src/ship/packet/builder/message.rs @@ -118,8 +118,8 @@ pub fn character_leveled_up(area_client: AreaClient, level: u32, before_stats: C } } -// TOOD: meseta -pub fn bank_item_list(bank: &CharacterBank) -> BankItemList { +// TOOD: checksum? +pub fn bank_item_list(bank: &CharacterBank, char_bank_meseta: u32) -> BankItemList { BankItemList { aflag: 0, cmd: 0xBC, @@ -127,7 +127,7 @@ pub fn bank_item_list(bank: &CharacterBank) -> BankItemList { size: bank.count() as u32 * 0x18 + 0x14, checksum: 0x123434, item_count: bank.count() as u32, - meseta: 12345, + meseta: char_bank_meseta, items: bank.as_client_bank_request() } } diff --git a/src/ship/packet/handler/direct_message.rs b/src/ship/packet/handler/direct_message.rs index 7084516..2ff98b3 100644 --- a/src/ship/packet/handler/direct_message.rs +++ b/src/ship/packet/handler/direct_message.rs @@ -7,6 +7,8 @@ use crate::ship::ship::{SendShipPacket, ShipError, Clients, Rooms, ItemShops}; use crate::ship::location::{ClientLocation, ClientLocationError}; use crate::ship::drops::ItemDrop; use crate::ship::items::{ItemManager, ClientItemId, TriggerCreateItem, FloorItem}; +// use crate::ship::items::bank::{BANK_MESETA_CAPACITY}; // compiler error: private module +// use crate::ship::items::inventory::{INVENTORY_MESETA_CAPACITY}; // compiler error: private module use crate::entity::gateway::EntityGateway; use libpso::utf8_to_utf16_array; use crate::ship::packet::builder; @@ -19,6 +21,9 @@ const SHOP_OPTION_TOOL: u8 = 0; const SHOP_OPTION_WEAPON: u8 = 1; const SHOP_OPTION_ARMOR: u8 = 2; +const INVENTORY_MESETA_CAPACITY: u32 = 999999; +const BANK_MESETA_CAPACITY: u32 = 999999; + //const BANK_ACTION_: u8 = 1; fn send_to_client(id: ClientId, target: u8, msg: DirectMessage, client_location: &ClientLocation) @@ -213,10 +218,11 @@ pub async fn send_bank_list(id: ClientId, let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; let bank_items = item_manager.get_character_bank(&client.character)?; - let bank_items_pkt = builder::message::bank_item_list(&bank_items); + let bank_items_pkt = builder::message::bank_item_list(&bank_items, client.character.bank_meseta); Ok(Box::new(vec![(id, SendShipPacket::BankItemList(bank_items_pkt))].into_iter())) } +// TODO: error if too much money is deposited/withdrawn pub async fn bank_interaction(id: ClientId, bank_interaction: &BankInteraction, entity_gateway: &mut EG, @@ -233,11 +239,11 @@ where let bank_action_pkts = match bank_interaction.action { BANK_ACTION_DEPOSIT => { if bank_interaction.item_id == 0xFFFFFFFF { - if client.character.meseta > bank_interaction.meseta_amount && (bank_interaction.meseta_amount + client.character.bank_meseta) <= 999999 { + if client.character.meseta >= bank_interaction.meseta_amount && (bank_interaction.meseta_amount + client.character.bank_meseta) <= BANK_MESETA_CAPACITY { client.character.meseta -= bank_interaction.meseta_amount; client.character.bank_meseta += bank_interaction.meseta_amount; entity_gateway.save_character(&client.character).await?; - } + } /* else {error deposited too much money} */ Vec::new() } else { @@ -248,11 +254,11 @@ where }, BANK_ACTION_WITHDRAW => { if bank_interaction.item_id == 0xFFFFFFFF { - if client.character.meseta + bank_interaction.meseta_amount <= 999999 { + if client.character.meseta + bank_interaction.meseta_amount <= INVENTORY_MESETA_CAPACITY { client.character.meseta += bank_interaction.meseta_amount; client.character.bank_meseta -= bank_interaction.meseta_amount; entity_gateway.save_character(&client.character).await?; - } + } /* else {error withdrew too much money} */ Vec::new() } else {