From 88c7d2ee773647b015c0a60d647b5f8255215d70 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 29 Mar 2025 14:52:27 -0400 Subject: [PATCH] Fix sending status effects setting the player HP/MP to 0 For some reason we send some of the player's stats in this packet, and we can't keep them as 0 because the client will just kill the player. --- resources/scripts/test.lua | 3 +-- src/bin/kawari-world.rs | 27 ++++++++++++++++++--------- src/world/connection.rs | 19 ++++++++++++++++--- src/world/database.rs | 1 + 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/resources/scripts/test.lua b/resources/scripts/test.lua index bfbfc76..f2d23a0 100644 --- a/resources/scripts/test.lua +++ b/resources/scripts/test.lua @@ -5,6 +5,5 @@ end function doAction(player) -- give sprint - -- commented out because it breaks other stats due to stubs - --player:give_status_effect(50, 5.0) + player:give_status_effect(50, 5.0) end diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 52ec9f1..f7360ff 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -2,8 +2,8 @@ use std::sync::{Arc, Mutex}; use kawari::common::custom_ipc::{CustomIpcData, CustomIpcSegment, CustomIpcType}; use kawari::common::{ - INVALID_OBJECT_ID, ObjectId, ObjectTypeId, Position, determine_initial_starting_zone, - get_citystate, get_world_name, + ObjectId, ObjectTypeId, Position, determine_initial_starting_zone, get_citystate, + get_world_name, }; use kawari::common::{get_racial_base_attributes, timestamp_secs}; use kawari::config::get_config; @@ -115,6 +115,13 @@ async fn main() { // collect actor data connection.player_data = database.find_player_data(actor_id.parse::().unwrap()); + // some still hardcoded values + connection.player_data.classjob_id = 1; + connection.player_data.level = 5; + connection.player_data.curr_hp = 100; + connection.player_data.max_hp = 100; + connection.player_data.curr_mp = 10000; + connection.player_data.max_mp = 10000; exit_position = Some(connection.player_data.position); exit_rotation = Some(connection.player_data.rotation); @@ -274,8 +281,8 @@ async fn main() { vitality: attributes.vitality, intelligence: attributes.intelligence, mind: attributes.mind, - hp: 100, - mp: 100, + hp: connection.player_data.max_hp, + mp: connection.player_data.max_mp as u32, ..Default::default() }), ..Default::default() @@ -373,12 +380,14 @@ async fn main() { gm_rank: GameMasterRank::Debug, online_status: OnlineStatus::GameMasterBlue, common: CommonSpawn { - class_job: 1, + class_job: connection + .player_data + .classjob_id, name: chara_details.name, - hp_curr: 100, - hp_max: 100, - mp_curr: 100, - mp_max: 100, + hp_curr: connection.player_data.curr_hp, + hp_max: connection.player_data.max_hp, + mp_curr: connection.player_data.curr_mp, + mp_max: connection.player_data.max_mp, object_kind: ObjectKind::Player( PlayerSubKind::Player, ), diff --git a/src/world/connection.rs b/src/world/connection.rs index 2ac33f5..0578564 100644 --- a/src/world/connection.rs +++ b/src/world/connection.rs @@ -25,6 +25,13 @@ pub struct PlayerData { pub content_id: u64, pub account_id: u32, + pub classjob_id: u8, + pub level: u8, + pub curr_hp: u32, + pub max_hp: u32, + pub curr_mp: u16, + pub max_mp: u16, + // Dynamic data pub position: Position, /// In radians. @@ -132,10 +139,10 @@ impl ZoneConnection { op_code: ServerZoneIpcType::UpdateClassInfo, timestamp: timestamp_secs(), data: ServerZoneIpcData::UpdateClassInfo(UpdateClassInfo { - class_id: 1, + class_id: self.player_data.classjob_id as u16, unknown: 1, - synced_level: 90, - class_level: 90, + synced_level: self.player_data.level as u16, + class_level: self.player_data.level as u16, ..Default::default() }), ..Default::default() @@ -323,6 +330,12 @@ impl ZoneConnection { timestamp: timestamp_secs(), data: ServerZoneIpcData::StatusEffectList(StatusEffectList { statues: list, + classjob_id: self.player_data.classjob_id, + level: self.player_data.level, + curr_hp: self.player_data.curr_hp, + max_hp: self.player_data.max_hp, + curr_mp: self.player_data.curr_mp, + max_mp: self.player_data.max_mp, ..Default::default() }), ..Default::default() diff --git a/src/world/database.rs b/src/world/database.rs index c5e81d1..478c964 100644 --- a/src/world/database.rs +++ b/src/world/database.rs @@ -84,6 +84,7 @@ impl WorldDatabase { }, rotation, zone_id, + ..Default::default() } }