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:
parent
75993bf933
commit
69e8e4055e
7 changed files with 22 additions and 13 deletions
|
@ -173,7 +173,7 @@
|
||||||
{
|
{
|
||||||
"name": "CurrencyCrystalInfo",
|
"name": "CurrencyCrystalInfo",
|
||||||
"opcode": 548,
|
"opcode": 548,
|
||||||
"size": 32
|
"size": 24
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ClientZoneIpcType": [
|
"ClientZoneIpcType": [
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl Storage for CurrencyStorage {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn num_items(&self) -> u32 {
|
fn num_items(&self) -> u32 {
|
||||||
self.gil.quantity
|
1
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_slot_mut(&mut self, index: u16) -> &mut Item {
|
fn get_slot_mut(&mut self, index: u16) -> &mut Item {
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl<'a> Iterator for InventoryIterator<'a> {
|
||||||
let curr = self.curr;
|
let curr = self.curr;
|
||||||
self.curr += 1;
|
self.curr += 1;
|
||||||
|
|
||||||
if curr >= 17 {
|
if curr >= 18 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,9 @@ impl<'a> Iterator for InventoryIterator<'a> {
|
||||||
|
|
||||||
// equipped
|
// equipped
|
||||||
16 => ContainerType::Equipped,
|
16 => ContainerType::Equipped,
|
||||||
|
|
||||||
|
// currency
|
||||||
|
17 => ContainerType::Currency,
|
||||||
_ => panic!("Inventory iterator invalid!"),
|
_ => panic!("Inventory iterator invalid!"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ use binrw::binrw;
|
||||||
|
|
||||||
use super::Item;
|
use super::Item;
|
||||||
|
|
||||||
|
/// When adding a new container type, make sure to add it to InventoryIterator
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
#[brw(repr = u16)]
|
#[brw(repr = u16)]
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
use binrw::binrw;
|
use binrw::binrw;
|
||||||
|
|
||||||
|
use crate::inventory::ContainerType;
|
||||||
|
|
||||||
#[binrw]
|
#[binrw]
|
||||||
#[brw(little)]
|
#[brw(little)]
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct CurrencyInfo {
|
pub struct CurrencyInfo {
|
||||||
pub sequence: u32,
|
pub sequence: u32,
|
||||||
pub container: u16,
|
pub container: ContainerType,
|
||||||
pub slot: u16,
|
pub slot: u16,
|
||||||
pub quantity: u32,
|
pub quantity: u32,
|
||||||
pub unk1: u32,
|
pub unk1: u32,
|
||||||
|
|
|
@ -487,16 +487,16 @@ impl ZoneConnection {
|
||||||
for (container_type, container) in &self.player_data.inventory.clone() {
|
for (container_type, container) in &self.player_data.inventory.clone() {
|
||||||
// currencies
|
// currencies
|
||||||
if container_type == ContainerType::Currency {
|
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 {
|
let ipc = ServerZoneIpcSegment {
|
||||||
op_code: ServerZoneIpcType::CurrencyCrystalInfo,
|
op_code: ServerZoneIpcType::CurrencyCrystalInfo,
|
||||||
timestamp: timestamp_secs(),
|
timestamp: timestamp_secs(),
|
||||||
data: ServerZoneIpcData::CurrencyCrystalInfo(CurrencyInfo {
|
data: ServerZoneIpcData::CurrencyCrystalInfo(CurrencyInfo {
|
||||||
sequence,
|
sequence,
|
||||||
container: item.id as u16,
|
container: container_type,
|
||||||
slot: slot_index,
|
|
||||||
quantity: item.quantity,
|
quantity: item.quantity,
|
||||||
catalog_id: item.id,
|
catalog_id: item.id,
|
||||||
|
unk1: 1,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}),
|
}),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -512,7 +512,7 @@ impl ZoneConnection {
|
||||||
};
|
};
|
||||||
|
|
||||||
for i in 0..container.max_slots() {
|
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 {
|
} else {
|
||||||
// items
|
// items
|
||||||
|
|
|
@ -225,11 +225,14 @@ impl LuaPlayer {
|
||||||
|
|
||||||
impl UserData for LuaPlayer {
|
impl UserData for LuaPlayer {
|
||||||
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
|
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(
|
||||||
let param: u8 = lua.from_value(param).unwrap_or(0);
|
"send_message",
|
||||||
this.send_message(&message, param);
|
|lua, this, (message, param): (String, Value)| {
|
||||||
Ok(())
|
let param: u8 = lua.from_value(param).unwrap_or(0);
|
||||||
});
|
this.send_message(&message, param);
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
);
|
||||||
methods.add_method_mut(
|
methods.add_method_mut(
|
||||||
"give_status_effect",
|
"give_status_effect",
|
||||||
|_, this, (effect_id, duration): (u16, f32)| {
|
|_, this, (effect_id, duration): (u16, f32)| {
|
||||||
|
|
Loading…
Add table
Reference in a new issue