1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-06-30 11:47:45 +00:00

Finish implementing currency

I made various mistakes in the initial implementation, which
are now fixed.
This commit is contained in:
Joshua Goins 2025-06-25 17:02:19 -04:00
parent 75993bf933
commit 69e8e4055e
7 changed files with 22 additions and 13 deletions

View file

@ -173,7 +173,7 @@
{
"name": "CurrencyCrystalInfo",
"opcode": 548,
"size": 32
"size": 24
}
],
"ClientZoneIpcType": [

View file

@ -21,7 +21,7 @@ impl Storage for CurrencyStorage {
}
fn num_items(&self) -> u32 {
self.gil.quantity
1
}
fn get_slot_mut(&mut self, index: u16) -> &mut Item {

View file

@ -88,7 +88,7 @@ impl<'a> Iterator for InventoryIterator<'a> {
let curr = self.curr;
self.curr += 1;
if curr >= 17 {
if curr >= 18 {
return None;
}
@ -115,6 +115,9 @@ impl<'a> Iterator for InventoryIterator<'a> {
// equipped
16 => ContainerType::Equipped,
// currency
17 => ContainerType::Currency,
_ => panic!("Inventory iterator invalid!"),
};

View file

@ -2,6 +2,7 @@ use binrw::binrw;
use super::Item;
/// When adding a new container type, make sure to add it to InventoryIterator
#[binrw]
#[brw(little)]
#[brw(repr = u16)]

View file

@ -1,11 +1,13 @@
use binrw::binrw;
use crate::inventory::ContainerType;
#[binrw]
#[brw(little)]
#[derive(Debug, Clone, Default)]
pub struct CurrencyInfo {
pub sequence: u32,
pub container: u16,
pub container: ContainerType,
pub slot: u16,
pub quantity: u32,
pub unk1: u32,

View file

@ -487,16 +487,16 @@ impl ZoneConnection {
for (container_type, container) in &self.player_data.inventory.clone() {
// currencies
if container_type == ContainerType::Currency {
let mut send_currency = async |slot_index: u16, item: &Item| {
let mut send_currency = async |item: &Item| {
let ipc = ServerZoneIpcSegment {
op_code: ServerZoneIpcType::CurrencyCrystalInfo,
timestamp: timestamp_secs(),
data: ServerZoneIpcData::CurrencyCrystalInfo(CurrencyInfo {
sequence,
container: item.id as u16,
slot: slot_index,
container: container_type,
quantity: item.quantity,
catalog_id: item.id,
unk1: 1,
..Default::default()
}),
..Default::default()
@ -512,7 +512,7 @@ impl ZoneConnection {
};
for i in 0..container.max_slots() {
send_currency(i as u16, container.get_slot(i as u16)).await;
send_currency(container.get_slot(i as u16)).await;
}
} else {
// items

View file

@ -225,11 +225,14 @@ impl LuaPlayer {
impl UserData for LuaPlayer {
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
methods.add_method_mut("send_message", |lua, this, (message, param): (String, Value)| {
methods.add_method_mut(
"send_message",
|lua, this, (message, param): (String, Value)| {
let param: u8 = lua.from_value(param).unwrap_or(0);
this.send_message(&message, param);
Ok(())
});
},
);
methods.add_method_mut(
"give_status_effect",
|_, this, (effect_id, duration): (u16, f32)| {