diff --git a/src/bin/kawari-world.rs b/src/bin/kawari-world.rs index 30b7caa..20d3822 100644 --- a/src/bin/kawari-world.rs +++ b/src/bin/kawari-world.rs @@ -1,8 +1,8 @@ use std::sync::{Arc, Mutex}; use kawari::common::custom_ipc::{CustomIpcData, CustomIpcSegment, CustomIpcType}; -use kawari::common::timestamp_secs; use kawari::common::{Position, determine_initial_starting_zone, get_citystate, get_world_name}; +use kawari::common::{get_racial_base_attributes, timestamp_secs}; use kawari::config::get_config; use kawari::lobby::CharaMake; use kawari::oodle::OodleNetwork; @@ -246,11 +246,19 @@ async fn main() { // Stats { + let attributes = get_racial_base_attributes( + chara_details.chara_make.customize.subrace, + ); + let ipc = ServerZoneIpcSegment { op_code: ServerZoneIpcType::PlayerStats, timestamp: timestamp_secs(), data: ServerZoneIpcData::PlayerStats(PlayerStats { - strength: 1, + strength: attributes.strength, + dexterity: attributes.dexterity, + vitality: attributes.vitality, + intelligence: attributes.intelligence, + mind: attributes.mind, hp: 100, mp: 100, ..Default::default() diff --git a/src/common/mod.rs b/src/common/mod.rs index fe6d79f..20688de 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -153,6 +153,46 @@ pub fn determine_initial_starting_zone(citystate_id: u8) -> u16 { } } +pub struct Attributes { + pub strength: u32, + pub dexterity: u32, + pub vitality: u32, + pub intelligence: u32, + pub mind: u32, +} + +pub fn get_racial_base_attributes(tribe_id: u8) -> Attributes { + // The Tribe Excel sheet only has deltas (e.g. 2 or -2) which are applied to a base 20 number... from somewhere + let base_stat = 20; + + let config = get_config(); + + let mut game_data = GameData::from_existing(Platform::Win32, &config.game_location).unwrap(); + + let exh = game_data.read_excel_sheet_header("Tribe").unwrap(); + let exd = game_data + .read_excel_sheet("Tribe", &exh, Language::English, 0) + .unwrap(); + + let tribe_row = &exd.read_row(&exh, tribe_id as u32).unwrap()[0]; + + let get_column = |column_index: usize| { + let physis::exd::ColumnData::Int8(delta) = &tribe_row.data[column_index] else { + panic!("Unexpected type!"); + }; + + *delta + }; + + Attributes { + strength: (base_stat + get_column(4)) as u32, + dexterity: (base_stat + get_column(6)) as u32, + vitality: (base_stat + get_column(5)) as u32, + intelligence: (base_stat + get_column(7)) as u32, + mind: (base_stat + get_column(8)) as u32, + } +} + #[cfg(test)] mod tests { use super::*;