Weapon addition

This commit is contained in:
xavo95 2024-09-13 18:55:51 +02:00
parent 022d056901
commit c042bd18cf
Signed by: xavo95
GPG key ID: CBF8ADED6DEBB783
6 changed files with 22 additions and 8 deletions

View file

@ -5,6 +5,7 @@ mod owner_player;
mod player_entity_marker; mod player_entity_marker;
mod position; mod position;
mod visibility; mod visibility;
mod weapon;
pub use attribute::Attribute; pub use attribute::Attribute;
pub use entity_config::EntityConfig; pub use entity_config::EntityConfig;
@ -13,3 +14,4 @@ pub use owner_player::OwnerPlayer;
pub use player_entity_marker::PlayerEntityMarker; pub use player_entity_marker::PlayerEntityMarker;
pub use position::Position; pub use position::Position;
pub use visibility::Visibility; pub use visibility::Visibility;
pub use weapon::Weapon;

View file

@ -30,6 +30,7 @@ impl_component_container! {
Attribute; Attribute;
PlayerEntityMarker; PlayerEntityMarker;
Movement; Movement;
Weapon;
} }
pub trait Component { pub trait Component {

View file

@ -43,7 +43,7 @@ impl Player {
// we need shorekeeper // we need shorekeeper
// TODO: remove this part after implementing team switch // TODO: remove this part after implementing team switch
if !self.role_list.iter().any(|r| r.role_id == 1505) { 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(); self.formation_list.clear();
@ -217,8 +217,8 @@ impl Player {
fn create_main_character_role(name: String, sex: i32) -> Role { fn create_main_character_role(name: String, sex: i32) -> Role {
let mut role = match sex { let mut role = match sex {
0 => Role::new(Role::MAIN_CHARACTER_FEMALE_ID), 0 => Role::new(Role::MAIN_CHARACTER_FEMALE_ID, None),
1 => Role::new(Role::MAIN_CHARACTER_MALE_ID), 1 => Role::new(Role::MAIN_CHARACTER_MALE_ID, None),
_ => unreachable!(), _ => unreachable!(),
}; };

View file

@ -1,12 +1,11 @@
use std::collections::HashMap; use std::collections::HashMap;
use common::time_util; use common::time_util;
pub use formation::RoleFormation;
use shorekeeper_data::role_info_data; use shorekeeper_data::role_info_data;
use shorekeeper_protocol::{ArrayIntInt, RoleData, RoleInfo}; use shorekeeper_protocol::{ArrayIntInt, RoleData, RoleInfo};
mod formation; mod formation;
pub use formation::RoleFormation;
pub struct Role { pub struct Role {
pub role_id: i32, pub role_id: i32,
pub name: String, pub name: String,
@ -17,14 +16,19 @@ pub struct Role {
pub star: i32, pub star: i32,
pub favor: i32, pub favor: i32,
pub create_time: u32, pub create_time: u32,
pub equip_weapon: i32,
} }
impl Role { impl Role {
pub const MAIN_CHARACTER_MALE_ID: i32 = 1501; pub const MAIN_CHARACTER_MALE_ID: i32 = 1501;
pub const MAIN_CHARACTER_FEMALE_ID: i32 = 1502; pub const MAIN_CHARACTER_FEMALE_ID: i32 = 1502;
pub fn new(role_id: i32) -> Self { pub fn new(role_id: i32, weapon_id: Option<i32>) -> Self {
let data = role_info_data::iter().find(|d| d.id == role_id).unwrap(); 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 { Self {
role_id, role_id,
@ -36,6 +40,7 @@ impl Role {
star: 0, star: 0,
favor: 0, favor: 0,
create_time: time_util::unix_timestamp() as u32, create_time: time_util::unix_timestamp() as u32,
equip_weapon,
} }
} }
@ -69,6 +74,7 @@ impl Role {
star: data.star, star: data.star,
favor: data.favor, favor: data.favor,
create_time: data.create_time, create_time: data.create_time,
equip_weapon: data.equip_weapon,
} }
} }
@ -83,6 +89,7 @@ impl Role {
star: self.star, star: self.star,
favor: self.favor, favor: self.favor,
create_time: self.create_time, create_time: self.create_time,
equip_weapon: self.equip_weapon,
..Default::default() ..Default::default()
} }
} }

View file

@ -8,14 +8,13 @@ use crate::{
logic::{ logic::{
components::{ components::{
Attribute, EntityConfig, Movement, OwnerPlayer, PlayerEntityMarker, Position, Attribute, EntityConfig, Movement, OwnerPlayer, PlayerEntityMarker, Position,
Visibility, Visibility, Weapon
}, },
ecs::{component::ComponentContainer, world::World}, ecs::{component::ComponentContainer, world::World},
player::Player, player::Player,
}, },
query_with, query_with,
}; };
use super::entity_serializer; use super::entity_serializer;
pub fn add_player_entities(world: &mut World, player: &Player) { 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(), .unwrap(),
))) )))
.with(ComponentContainer::Movement(Movement::default())) .with(ComponentContainer::Movement(Movement::default()))
.with(ComponentContainer::Weapon(Weapon {
weapon_id: role.equip_weapon,
weapon_breach_level: 0, // TODO: store this too
}))
.build(); .build();
tracing::debug!( tracing::debug!(

View file

@ -43,6 +43,7 @@ message RoleData {
repeated int32 models = 12; repeated int32 models = 12;
repeated RoleSkillNodeData skill_node_state = 13; repeated RoleSkillNodeData skill_node_state = 13;
int32 resonant_chain_group_index = 14; int32 resonant_chain_group_index = 14;
int32 equip_weapon = 15;
} }
message RoleFormationData { message RoleFormationData {