Browse Source

bank doesn't spawn infinite money!

pbs
andy 4 years ago
parent
commit
e1360e4958
  1. 1
      src/ship/items/bank.rs
  2. 1
      src/ship/items/inventory.rs
  3. 6
      src/ship/packet/builder/message.rs
  4. 16
      src/ship/packet/handler/direct_message.rs

1
src/ship/items/bank.rs

@ -5,6 +5,7 @@ use crate::entity::item::tool::Tool;
use crate::ship::items::inventory::{InventoryItemHandle, InventoryItem}; use crate::ship::items::inventory::{InventoryItemHandle, InventoryItem};
const BANK_CAPACITY: usize = 200; const BANK_CAPACITY: usize = 200;
// const BANK_MESETA_CAPACITY: u32 = 999999; compiler error: private module
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct IndividualBankItem { pub struct IndividualBankItem {

1
src/ship/items/inventory.rs

@ -8,6 +8,7 @@ use crate::ship::items::{ClientItemId, BankItem, BankItemHandle};
use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem}; use crate::ship::items::floor::{IndividualFloorItem, StackedFloorItem};
const INVENTORY_CAPACITY: usize = 30; const INVENTORY_CAPACITY: usize = 30;
// const INVENTORY_MESETA_CAPACITY: u32 = 999999; // compiler error: private module
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

6
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 { BankItemList {
aflag: 0, aflag: 0,
cmd: 0xBC, cmd: 0xBC,
@ -127,7 +127,7 @@ pub fn bank_item_list(bank: &CharacterBank) -> BankItemList {
size: bank.count() as u32 * 0x18 + 0x14, size: bank.count() as u32 * 0x18 + 0x14,
checksum: 0x123434, checksum: 0x123434,
item_count: bank.count() as u32, item_count: bank.count() as u32,
meseta: 12345,
meseta: char_bank_meseta,
items: bank.as_client_bank_request() items: bank.as_client_bank_request()
} }
} }

16
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::location::{ClientLocation, ClientLocationError};
use crate::ship::drops::ItemDrop; use crate::ship::drops::ItemDrop;
use crate::ship::items::{ItemManager, ClientItemId, TriggerCreateItem, FloorItem}; 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 crate::entity::gateway::EntityGateway;
use libpso::utf8_to_utf16_array; use libpso::utf8_to_utf16_array;
use crate::ship::packet::builder; use crate::ship::packet::builder;
@ -19,6 +21,9 @@ const SHOP_OPTION_TOOL: u8 = 0;
const SHOP_OPTION_WEAPON: u8 = 1; const SHOP_OPTION_WEAPON: u8 = 1;
const SHOP_OPTION_ARMOR: u8 = 2; const SHOP_OPTION_ARMOR: u8 = 2;
const INVENTORY_MESETA_CAPACITY: u32 = 999999;
const BANK_MESETA_CAPACITY: u32 = 999999;
//const BANK_ACTION_: u8 = 1; //const BANK_ACTION_: u8 = 1;
fn send_to_client(id: ClientId, target: u8, msg: DirectMessage, client_location: &ClientLocation) 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 client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
let bank_items = item_manager.get_character_bank(&client.character)?; 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())) 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<EG>(id: ClientId, pub async fn bank_interaction<EG>(id: ClientId,
bank_interaction: &BankInteraction, bank_interaction: &BankInteraction,
entity_gateway: &mut EG, entity_gateway: &mut EG,
@ -233,11 +239,11 @@ where
let bank_action_pkts = match bank_interaction.action { let bank_action_pkts = match bank_interaction.action {
BANK_ACTION_DEPOSIT => { BANK_ACTION_DEPOSIT => {
if bank_interaction.item_id == 0xFFFFFFFF { 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.meseta -= bank_interaction.meseta_amount;
client.character.bank_meseta += bank_interaction.meseta_amount; client.character.bank_meseta += bank_interaction.meseta_amount;
entity_gateway.save_character(&client.character).await?; entity_gateway.save_character(&client.character).await?;
}
} /* else {error deposited too much money} */
Vec::new() Vec::new()
} }
else { else {
@ -248,11 +254,11 @@ where
}, },
BANK_ACTION_WITHDRAW => { BANK_ACTION_WITHDRAW => {
if bank_interaction.item_id == 0xFFFFFFFF { 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.meseta += bank_interaction.meseta_amount;
client.character.bank_meseta -= bank_interaction.meseta_amount; client.character.bank_meseta -= bank_interaction.meseta_amount;
entity_gateway.save_character(&client.character).await?; entity_gateway.save_character(&client.character).await?;
}
} /* else {error withdrew too much money} */
Vec::new() Vec::new()
} }
else { else {

Loading…
Cancel
Save