From c042bd18cfdbdb3972079b17f478aab39c4562bf Mon Sep 17 00:00:00 2001 From: xavo95 Date: Fri, 13 Sep 2024 18:55:51 +0200 Subject: [PATCH] Weapon addition --- game-server/src/logic/components/mod.rs | 2 ++ game-server/src/logic/ecs/component.rs | 1 + game-server/src/logic/player/mod.rs | 6 +++--- game-server/src/logic/role/mod.rs | 13 ++++++++++--- game-server/src/logic/utils/world_util.rs | 7 +++++-- shorekeeper-protocol/proto/data.proto | 1 + 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/game-server/src/logic/components/mod.rs b/game-server/src/logic/components/mod.rs index 33f840b..d090d34 100644 --- a/game-server/src/logic/components/mod.rs +++ b/game-server/src/logic/components/mod.rs @@ -5,6 +5,7 @@ mod owner_player; mod player_entity_marker; mod position; mod visibility; +mod weapon; pub use attribute::Attribute; pub use entity_config::EntityConfig; @@ -13,3 +14,4 @@ pub use owner_player::OwnerPlayer; pub use player_entity_marker::PlayerEntityMarker; pub use position::Position; pub use visibility::Visibility; +pub use weapon::Weapon; diff --git a/game-server/src/logic/ecs/component.rs b/game-server/src/logic/ecs/component.rs index bf073be..a50c162 100644 --- a/game-server/src/logic/ecs/component.rs +++ b/game-server/src/logic/ecs/component.rs @@ -30,6 +30,7 @@ impl_component_container! { Attribute; PlayerEntityMarker; Movement; + Weapon; } pub trait Component { diff --git a/game-server/src/logic/player/mod.rs b/game-server/src/logic/player/mod.rs index fd1331a..323dc7f 100644 --- a/game-server/src/logic/player/mod.rs +++ b/game-server/src/logic/player/mod.rs @@ -43,7 +43,7 @@ impl Player { // we need shorekeeper // TODO: remove this part after implementing team switch if !self.role_list.iter().any(|r| r.role_id == 1505) { - self.role_list.push(Role::new(1505)); + self.role_list.push(Role::new(1505, Some(21050036))); } self.formation_list.clear(); @@ -217,8 +217,8 @@ impl Player { fn create_main_character_role(name: String, sex: i32) -> Role { let mut role = match sex { - 0 => Role::new(Role::MAIN_CHARACTER_FEMALE_ID), - 1 => Role::new(Role::MAIN_CHARACTER_MALE_ID), + 0 => Role::new(Role::MAIN_CHARACTER_FEMALE_ID, None), + 1 => Role::new(Role::MAIN_CHARACTER_MALE_ID, None), _ => unreachable!(), }; diff --git a/game-server/src/logic/role/mod.rs b/game-server/src/logic/role/mod.rs index beaafc1..e3a76a0 100644 --- a/game-server/src/logic/role/mod.rs +++ b/game-server/src/logic/role/mod.rs @@ -1,12 +1,11 @@ use std::collections::HashMap; use common::time_util; +pub use formation::RoleFormation; use shorekeeper_data::role_info_data; use shorekeeper_protocol::{ArrayIntInt, RoleData, RoleInfo}; mod formation; -pub use formation::RoleFormation; - pub struct Role { pub role_id: i32, pub name: String, @@ -17,14 +16,19 @@ pub struct Role { pub star: i32, pub favor: i32, pub create_time: u32, + pub equip_weapon: i32, } impl Role { pub const MAIN_CHARACTER_MALE_ID: i32 = 1501; pub const MAIN_CHARACTER_FEMALE_ID: i32 = 1502; - pub fn new(role_id: i32) -> Self { + pub fn new(role_id: i32, weapon_id: Option) -> Self { let data = role_info_data::iter().find(|d| d.id == role_id).unwrap(); + let equip_weapon = match weapon_id { + None => data.init_weapon_item_id, + Some(x) => x, + }; Self { role_id, @@ -36,6 +40,7 @@ impl Role { star: 0, favor: 0, create_time: time_util::unix_timestamp() as u32, + equip_weapon, } } @@ -69,6 +74,7 @@ impl Role { star: data.star, favor: data.favor, create_time: data.create_time, + equip_weapon: data.equip_weapon, } } @@ -83,6 +89,7 @@ impl Role { star: self.star, favor: self.favor, create_time: self.create_time, + equip_weapon: self.equip_weapon, ..Default::default() } } diff --git a/game-server/src/logic/utils/world_util.rs b/game-server/src/logic/utils/world_util.rs index dbf74e1..5099a17 100644 --- a/game-server/src/logic/utils/world_util.rs +++ b/game-server/src/logic/utils/world_util.rs @@ -8,14 +8,13 @@ use crate::{ logic::{ components::{ Attribute, EntityConfig, Movement, OwnerPlayer, PlayerEntityMarker, Position, - Visibility, + Visibility, Weapon }, ecs::{component::ComponentContainer, world::World}, player::Player, }, query_with, }; - use super::entity_serializer; pub fn add_player_entities(world: &mut World, player: &Player) { @@ -44,6 +43,10 @@ pub fn add_player_entities(world: &mut World, player: &Player) { .unwrap(), ))) .with(ComponentContainer::Movement(Movement::default())) + .with(ComponentContainer::Weapon(Weapon { + weapon_id: role.equip_weapon, + weapon_breach_level: 0, // TODO: store this too + })) .build(); tracing::debug!( diff --git a/shorekeeper-protocol/proto/data.proto b/shorekeeper-protocol/proto/data.proto index 637e418..87e4d68 100644 --- a/shorekeeper-protocol/proto/data.proto +++ b/shorekeeper-protocol/proto/data.proto @@ -43,6 +43,7 @@ message RoleData { repeated int32 models = 12; repeated RoleSkillNodeData skill_node_state = 13; int32 resonant_chain_group_index = 14; + int32 equip_weapon = 15; } message RoleFormationData {