From 1480baae706161aed278f0c4d97573848ac42e67 Mon Sep 17 00:00:00 2001 From: RabbyDevs <67389402+RabbyDevs@users.noreply.github.com> Date: Tue, 20 May 2025 04:10:52 +0300 Subject: [PATCH] submit work for now --- wicked-waifus-data/src/lib.rs | 1 + .../src/model_config_preload.rs | 26 ++ wicked-waifus-data/src/pb_components/model.rs | 4 +- wicked-waifus-data/src/role_info.rs | 1 - .../src/logic/ecs/buf.rs | 28 +- .../src/logic/ecs/world.rs | 8 +- .../src/logic/handler/combat.rs | 64 +-- .../src/logic/handler/mod.rs | 2 +- .../src/logic/handler/role.rs | 55 ++- .../src/logic/player/mod.rs | 33 +- .../src/logic/role/mod.rs | 8 +- .../src/logic/thread_mgr.rs | 13 +- .../src/logic/utils/world_util.rs | 414 +++++++----------- 13 files changed, 306 insertions(+), 351 deletions(-) create mode 100644 wicked-waifus-data/src/model_config_preload.rs diff --git a/wicked-waifus-data/src/lib.rs b/wicked-waifus-data/src/lib.rs index c92daf1..cf5efb9 100644 --- a/wicked-waifus-data/src/lib.rs +++ b/wicked-waifus-data/src/lib.rs @@ -138,6 +138,7 @@ json_data! { LevelPlayNodeData; LivenessTask; LordGym; + ModelConfigPreload; MonsterDetection; MonsterPropertyGrowth; Motion; diff --git a/wicked-waifus-data/src/model_config_preload.rs b/wicked-waifus-data/src/model_config_preload.rs new file mode 100644 index 0000000..381fcfe --- /dev/null +++ b/wicked-waifus-data/src/model_config_preload.rs @@ -0,0 +1,26 @@ +use serde::Deserialize; + +#[derive(Deserialize)] +#[cfg_attr(feature = "strict_json_fields", serde(deny_unknown_fields))] +#[serde(rename_all = "PascalCase")] +pub struct ModelConfigPreloadData { + pub id: i32, + pub actor_class_path: String, + #[cfg(feature = "strict_json_fields")] + pub actor_class: Vec, + #[cfg(feature = "strict_json_fields")] + pub animations: Vec, + #[cfg(feature = "strict_json_fields")] + pub effects: Vec, + #[cfg(feature = "strict_json_fields")] + pub audios: Vec, + #[cfg(feature = "strict_json_fields")] + pub meshes: Vec, + #[cfg(feature = "strict_json_fields")] + pub materials: Vec, + #[cfg(feature = "strict_json_fields")] + pub animation_blueprints: Vec, + #[cfg(feature = "strict_json_fields")] + pub others: Vec, + +} \ No newline at end of file diff --git a/wicked-waifus-data/src/pb_components/model.rs b/wicked-waifus-data/src/pb_components/model.rs index 52cb255..5b7f49e 100644 --- a/wicked-waifus-data/src/pb_components/model.rs +++ b/wicked-waifus-data/src/pb_components/model.rs @@ -4,8 +4,8 @@ use serde::Deserialize; #[cfg_attr(feature = "strict_json_fields", serde(deny_unknown_fields))] #[serde(rename_all = "PascalCase")] pub struct ModelType { - r#type: Option, - model_id: Option + pub r#type: Option, + pub model_id: Option } #[derive(Deserialize, Debug, Clone)] diff --git a/wicked-waifus-data/src/role_info.rs b/wicked-waifus-data/src/role_info.rs index 83aaf1e..22c49dd 100644 --- a/wicked-waifus-data/src/role_info.rs +++ b/wicked-waifus-data/src/role_info.rs @@ -100,7 +100,6 @@ pub struct RoleInfoData { pub role_guide: i32, #[cfg(feature = "strict_json_fields")] pub red_dot_disable_rule: i32, - #[cfg(feature = "strict_json_fields")] pub skin_damage: Vec, #[cfg(feature = "strict_json_fields")] pub hide_hu_lu: bool, diff --git a/wicked-waifus-game-server/src/logic/ecs/buf.rs b/wicked-waifus-game-server/src/logic/ecs/buf.rs index 3f056b7..b709153 100644 --- a/wicked-waifus-game-server/src/logic/ecs/buf.rs +++ b/wicked-waifus-game-server/src/logic/ecs/buf.rs @@ -26,14 +26,6 @@ const ROLE_OVERRIDES: &[(i32, &[i64])] = &[ ]), ]; -const ROLE_BUFF_BLACKLIST: &[(i32, &[i64])] = &[ - (1407, &[ - // ciaconna's forte buffs are completely fucked to get from an algorithm and i hate kuro! - 1407900003, - 1407500040, - ]), -]; - fn get_role_buff_overrides(role_id: i32) -> Option<&'static [i64]> { for &(role, buff) in ROLE_OVERRIDES { if role == role_id { @@ -128,6 +120,26 @@ impl BufManager { }) .collect::>() } + + pub fn create_buff(&mut self, origin_id: i64, buff_id: i64) -> FightBuffInformation { + let mut buff = FightBuffInformation { + handle_id: 0, + buff_id, + level: 1, + stack_count: 1, + instigator_id: origin_id, + entity_id: origin_id, + apply_type: 0, + duration: -1f32, + left_duration: -1f32, + context: vec![], + is_active: true, + server_id: 0, + message_id: 0, + }; + self.create(&mut buff); + buff + } } impl Default for BufManager { diff --git a/wicked-waifus-game-server/src/logic/ecs/world.rs b/wicked-waifus-game-server/src/logic/ecs/world.rs index 453ffed..ba23019 100644 --- a/wicked-waifus-game-server/src/logic/ecs/world.rs +++ b/wicked-waifus-game-server/src/logic/ecs/world.rs @@ -108,11 +108,15 @@ impl WorldEntity { self.components.remove(&entity_id).is_some() && self.entity_manager.remove(entity_id) } - pub fn active_entity_empty(&self) -> bool { - self.entity_manager.active_entity_empty() + pub fn get_all_entity_ids(&mut self) -> Vec { + self.entity_manager.get_all_entity_id() } pub fn generate_role_permanent_buffs(&mut self, entity_id: i32, role_id: i32) -> Vec { self.buff_manager.create_permanent_buffs(entity_id as i64, role_id) } + + pub fn create_buff(&mut self, entity_id: i32, buff_id: i64) -> FightBuffInformation { + self.buff_manager.create_buff(entity_id as i64, buff_id) + } } diff --git a/wicked-waifus-game-server/src/logic/handler/combat.rs b/wicked-waifus-game-server/src/logic/handler/combat.rs index c7e18f2..4ac1df2 100644 --- a/wicked-waifus-game-server/src/logic/handler/combat.rs +++ b/wicked-waifus-game-server/src/logic/handler/combat.rs @@ -160,38 +160,38 @@ fn handle_damage_execute_request( ..Default::default() }), )); - if let Some((value, _)) = query_components!(world, request.target_entity_id, Attribute) - .0 - .unwrap() - .attr_map - .get(&EAttributeType::Life) - { - let updated_value = match value - damage >= 0 { - true => value - damage, - false => 0, - }; - receive_pack.data.push(create_combat_notify( - CombatCommon { - entity_id: request.target_entity_id, - ..Default::default() - }, - combat_notify_data::Message::AttributeChangedNotify(AttributeChangedNotify { - id: request.target_entity_id, - attributes: vec![GameplayAttributeData { - current_value: updated_value, - value_increment: updated_value, - attribute_type: EAttributeType::Life.into(), - }], - }), - )); - if updated_value == 0 { - world_util::remove_entity( - player, - request.target_entity_id, - ERemoveEntityType::HpIsZero, - ); - } - } + // if let Some((value, _)) = query_components!(world, request.target_entity_id, Attribute) + // .0 + // .unwrap() + // .attr_map + // .get(&EAttributeType::Life) + // { + // let updated_value = match value - damage >= 0 { + // true => value - damage, + // false => 0, + // }; + // receive_pack.data.push(create_combat_notify( + // CombatCommon { + // entity_id: request.target_entity_id, + // ..Default::default() + // }, + // combat_notify_data::Message::AttributeChangedNotify(AttributeChangedNotify { + // id: request.target_entity_id, + // attributes: vec![GameplayAttributeData { + // current_value: updated_value, + // value_increment: updated_value, + // attribute_type: EAttributeType::Life.into(), + // }], + // }), + // )); + // if updated_value == 0 { + // world_util::remove_entity( + // player, + // request.target_entity_id, + // ERemoveEntityType::HpIsZero, + // ); + // } + // } response.error_code = ErrorCode::Success.into(); } diff --git a/wicked-waifus-game-server/src/logic/handler/mod.rs b/wicked-waifus-game-server/src/logic/handler/mod.rs index ed537b5..2ad6461 100644 --- a/wicked-waifus-game-server/src/logic/handler/mod.rs +++ b/wicked-waifus-game-server/src/logic/handler/mod.rs @@ -59,7 +59,7 @@ macro_rules! handle_request { return; }; - tracing::debug!("logic: processing request {}", stringify!($($inner_package::)?[<$name Request>])); + // tracing::debug!("logic: processing request {}", stringify!($($inner_package::)?[<$name Request>])); let mut response = ::wicked_waifus_protocol::$($inner_package::)?[<$name Response>]::default(); [](player, request, &mut response); diff --git a/wicked-waifus-game-server/src/logic/handler/role.rs b/wicked-waifus-game-server/src/logic/handler/role.rs index 6aee48f..8320e92 100644 --- a/wicked-waifus-game-server/src/logic/handler/role.rs +++ b/wicked-waifus-game-server/src/logic/handler/role.rs @@ -7,9 +7,12 @@ use wicked_waifus_protocol::{ RoleShowListUpdateResponse, UpdateFormationRequest, UpdateFormationResponse, }; +use crate::logic::ecs::world; use crate::logic::player::Player; use crate::logic::role::{Role, RoleFormation}; -use crate::logic::utils::world_util::summon_concomitant; +use crate::logic::utils::world_util::{add_player_entities, summon_concomitant}; +use crate::query_components; +use crate::logic::ecs::component::ComponentContainer; pub fn on_role_show_list_update_request( player: &mut Player, @@ -58,6 +61,22 @@ pub fn on_update_formation_request( let cur_role = formation.cur_role; let is_current = formation.is_current; + // update all formation and check formation_list + player + .formation_list + .entry(formation_id) + .and_modify(|r| { + r.cur_role = formation.cur_role; + r.role_ids = formation.role_ids.clone(); + r.is_current = is_current; + }) + .or_insert(RoleFormation { + id: formation_id, + cur_role: formation.cur_role, + role_ids: formation.role_ids.clone(), + is_current, + }); + if is_current { // update player current formation id player.cur_formation_id = formation_id; @@ -74,11 +93,16 @@ pub fn on_update_formation_request( } if let Some(old_formation) = player.formation_list.get(&real_formation_id) { - let removed_entities: Vec = old_formation + let mut removed_entities: Vec = old_formation .role_ids .iter() .map(|&role_id| world.get_entity_id(role_id)) .collect(); + for id in removed_entities.clone() { + if let (Some(concomitant),) = query_components!(world, id, Concomitant) { + removed_entities.extend(concomitant.custom_entity_ids.clone()); + }; + } removed_entities.iter().for_each(|&entity_id| { world.remove_entity(entity_id as i32); }); @@ -88,16 +112,7 @@ pub fn on_update_formation_request( )); } - let added_roles: Vec = formation - .role_ids - .iter() - .map(|&role_id| Role::new(role_id)) - .collect(); - - if !added_roles.is_empty() { - // add new role entities - player.notify(player.build_player_entity_add_notify(added_roles, world)); - } + player.build_player_entity_add_notify(world); // send update group formation notify player.notify(player.build_update_group_formation_notify( @@ -112,22 +127,6 @@ pub fn on_update_formation_request( response.formation = Some(formation.clone()); } - - // update all formation and check formation_list - player - .formation_list - .entry(formation_id) - .and_modify(|r| { - r.cur_role = formation.cur_role; - r.role_ids = formation.role_ids.clone(); - r.is_current = is_current; - }) - .or_insert(RoleFormation { - id: formation_id, - cur_role: formation.cur_role, - role_ids: formation.role_ids, - is_current, - }); } player.notify(player.build_update_formation_notify()); diff --git a/wicked-waifus-game-server/src/logic/player/mod.rs b/wicked-waifus-game-server/src/logic/player/mod.rs index 2c8fe21..df1d9ad 100644 --- a/wicked-waifus-game-server/src/logic/player/mod.rs +++ b/wicked-waifus-game-server/src/logic/player/mod.rs @@ -9,11 +9,11 @@ use wicked_waifus_protocol::message::Message; use wicked_waifus_protocol::player_attr::Value; use wicked_waifus_protocol::{ AdventreTask, AdventureManualData, AdventureUpdateNotify, AdviceSettingNotify, BuffItemNotify, - ControlInfoNotify, EEntityType, ERemoveEntityType, EnergyInfo, EnergyUpdateNotify, - EntityAddNotify, EntityConfigType, EntityPb, EntityRemoveInfo, EntityRemoveNotify, EntityState, + ControlInfoNotify, ERemoveEntityType, EnergyInfo, EnergyUpdateNotify, + EntityRemoveInfo, EntityRemoveNotify, FavorItem, FightFormationNotifyInfo, FightRoleInfo, FightRoleInfos, FormationRoleInfo, GroupFormation, HostTeleportUnlockNotify, InstDataNotify, ItemPkgOpenNotify, - LevelPlayInfoNotify, LivingStatus, MailInfosNotify, MapUnlockFieldNotify, + LevelPlayInfoNotify, LivingStatus, MailInfosNotify, MonthCardDailyRewardNotify, MoonChasingTargetGetCountNotify, MoonChasingTrackMoonHandbookRewardNotify, NormalItemUpdateNotify, PassiveSkillNotify, PbGetRoleListNotify, PlayerAttr, PlayerAttrKey, PlayerAttrNotify, PlayerAttrType, @@ -24,11 +24,12 @@ use wicked_waifus_protocol::{ }; use wicked_waifus_protocol_internal::{PlayerBasicData, PlayerRoleData, PlayerSaveData}; +use super::ecs::component::ComponentContainer; +use super::utils::world_util::add_player_entities; use super::{ ecs::world::World, role::{Role, RoleFormation}, }; -use crate::logic::components::RoleSkin; use crate::logic::ecs::world::WorldEntity; use crate::logic::player::basic_info::PlayerBasicInfo; use crate::logic::player::explore_tools::ExploreTools; @@ -46,15 +47,8 @@ use crate::logic::player::player_mc_element::PlayerMcElement; use crate::logic::player::player_month_card::PlayerMonthCard; use crate::logic::player::player_teleports::{PlayerTeleport, PlayerTeleports}; use crate::logic::player::player_tutorials::{PlayerTutorial, PlayerTutorials}; -use crate::logic::{ - components::{ - Attribute, EntityConfig, Equip, FightBuff, Movement, OwnerPlayer, PlayerOwnedEntityMarker, - Position, Visibility, VisionSkill, SoarWingSkin - }, - ecs::component::ComponentContainer, -}; use crate::session::Session; -use crate::{config, create_player_entity_pb, query_components}; +use crate::{config, query_components}; use crate::logic::player::Element::Spectro; mod basic_info; @@ -358,16 +352,8 @@ impl Player { } } - pub fn build_player_entity_add_notify(&self, role_list: Vec, world: &mut WorldEntity) -> EntityAddNotify { - create_player_entity_pb!( - role_list, - self.basic_info.cur_map_id, - self, - self.basic_info.id, - self.location.position.clone(), - self.explore_tools, - world - ) + pub fn build_player_entity_add_notify(&self, world: &mut WorldEntity) { + add_player_entities(self, self.formation_list.get(&self.cur_formation_id).unwrap(), Some(world)) } pub fn build_player_entity_remove_notify( @@ -403,8 +389,7 @@ impl Player { .iter() .map(|&role_id| { let entity_id = world.get_entity_id(role_id); - let _role_skin = - query_components!(world, entity_id, RoleSkin).0.unwrap(); + let _role_skin = query_components!(world, entity_id, RoleSkin).0.unwrap(); FightRoleInfo { role_id, entity_id: world.get_entity_id(role_id), diff --git a/wicked-waifus-game-server/src/logic/role/mod.rs b/wicked-waifus-game-server/src/logic/role/mod.rs index 60afc36..9a01aad 100644 --- a/wicked-waifus-game-server/src/logic/role/mod.rs +++ b/wicked-waifus-game-server/src/logic/role/mod.rs @@ -160,10 +160,10 @@ impl Role { // TODO: Integrity check, value has to be between 0 and max base_stats.life = base_stats.life_max; base_stats.energy = base_stats.energy_max; - base_stats.special_energy_1 = base_stats.special_energy_1_max; - base_stats.special_energy_2 = base_stats.special_energy_2_max; - base_stats.special_energy_3 = base_stats.special_energy_3_max; - base_stats.special_energy_4 = base_stats.special_energy_4_max; + base_stats.special_energy_1 = self.special_energy_1; + base_stats.special_energy_2 = self.special_energy_2; + base_stats.special_energy_3 = self.special_energy_3; + base_stats.special_energy_4 = self.special_energy_4; base_stats.element_energy = base_stats.element_energy_max; base_stats } diff --git a/wicked-waifus-game-server/src/logic/thread_mgr.rs b/wicked-waifus-game-server/src/logic/thread_mgr.rs index 978c7c5..d4cad1e 100644 --- a/wicked-waifus-game-server/src/logic/thread_mgr.rs +++ b/wicked-waifus-game-server/src/logic/thread_mgr.rs @@ -169,8 +169,7 @@ fn handle_logic_input(state: &mut LogicState, input: LogicInput) { .world .borrow_mut() .set_in_world_player_data(player.build_in_world_player()); - - world_util::add_player_entities(&player); + world_util::add_player_entities(&player, player.formation_list.get(&player.cur_formation_id).unwrap(), None); let scene_info = world_util::build_scene_information(&player); player.notify(SilenceNpcNotify::default()); @@ -237,10 +236,14 @@ fn handle_logic_input(state: &mut LogicState, input: LogicInput) { return; }; - let _ = state.worlds.remove(&player_id); + let removed_world = state.worlds.remove(&player_id).unwrap(); + let mut removed_world_ref = removed_world.borrow_mut(); + let world = removed_world_ref.get_mut_world_entity(); + for entity_id in world.get_all_entity_ids() { + world.remove_entity(entity_id); + } + // TODO: kick co-op players from removed world - // TODO: Remove all entities - player_save_task::push( player_id, player.borrow().build_save_data(), diff --git a/wicked-waifus-game-server/src/logic/utils/world_util.rs b/wicked-waifus-game-server/src/logic/utils/world_util.rs index 5b77048..8447a61 100644 --- a/wicked-waifus-game-server/src/logic/utils/world_util.rs +++ b/wicked-waifus-game-server/src/logic/utils/world_util.rs @@ -5,7 +5,7 @@ use wicked_waifus_protocol::{ use wicked_waifus_data::pb_components::ComponentsData; use wicked_waifus_data::{ - base_property_data, blueprint_config_data, template_config_data, EntityLogic, EntityType, LevelEntityConfigData + base_property_data, blueprint_config_data, summon_cfg_data, template_config_data, EntityLogic, EntityType, LevelEntityConfigData }; use crate::logic::components::{Autonomous, Fsm, Interact, MonsterAi, SoarWingSkin, StateTag, Tag}; @@ -13,6 +13,7 @@ use crate::logic::ecs::entity::{Entity, EntityBuilder}; use crate::logic::ecs::world::{World, WorldEntity}; use crate::logic::math::Transform; use crate::logic::player::Player; +use crate::logic::role::RoleFormation; use crate::logic::utils::growth_utils::get_monster_props_by_level; use crate::logic::utils::{entity_serializer, tag_utils}; use crate::logic::{ @@ -24,35 +25,13 @@ use crate::logic::{ }; //use crate::resonator_data::{ResonatorData, Concomitant, SummonerComponent}; -use crate::{query_components, query_with}; +use crate::query_with; -pub fn summon_concomitant(player: &Player, world: &mut WorldEntity, summon_cfg: &wicked_waifus_data::SummonCfgData, cur_summon_id: i32) -> Entity { +pub fn summon_concomitant(player: &Player, world: &mut WorldEntity, template_cfg: &wicked_waifus_data::TemplateConfigData, cur_summon_id: i32) -> (Entity, Vec) { let mut concomitant_buffs: Vec = Vec::new(); - for buff_id in &summon_cfg.born_buff_id { - concomitant_buffs - .push(FightBuffInformation { - handle_id: 1, - buff_id: *buff_id, - level: 1, - stack_count: 1, - instigator_id: 0, - entity_id: 0, - apply_type: 0, - duration: -1.0, - left_duration: -1.0, - context: vec![], - is_active: true, - server_id: 1, - message_id: 1, - } - ); - } - - let template_config = template_config_data::get(&summon_cfg.blueprint_type).unwrap(); - let concomitant_config_id = template_config.id; - tracing::info!("Adding Concomitant with id: {}", concomitant_config_id); - let con_buffs = concomitant_buffs.clone(); + let summon_cfg = summon_cfg_data::get(&template_cfg.blueprint_type).unwrap(); + let concomitant_config_id = template_cfg.id; let con_entity = world.create_entity( cur_summon_id, @@ -60,7 +39,13 @@ pub fn summon_concomitant(player: &Player, world: &mut WorldEntity, summon_cfg: player.basic_info.cur_map_id, ); - world + for buff_id in &summon_cfg.born_buff_id { + concomitant_buffs.push(world.create_buff(cur_summon_id, *buff_id)); + } + + tracing::info!("Adding Concomitant with id: {} and buffs {:#?}", concomitant_config_id, concomitant_buffs); + + (world .create_builder(con_entity) .with(ComponentContainer::PlayerOwnedEntityMarker(PlayerOwnedEntityMarker { entity_type: EEntityType::Monster, @@ -84,249 +69,190 @@ pub fn summon_concomitant(player: &Player, world: &mut WorldEntity, summon_cfg: })) .with(ComponentContainer::Attribute(Attribute::from_data( base_property_data::iter() - .find(|d| d.id == template_config.components_data.attribute_component.clone().unwrap().property_id.unwrap()) + .find(|d| d.id == template_cfg.components_data.attribute_component.clone().unwrap().property_id.unwrap()) .unwrap(), None, None, ))) - .with(ComponentContainer::Movement(Movement::default())) - .with(ComponentContainer::FightBuff(FightBuff { fight_buff_infos: con_buffs, ..Default::default() })) + .with(ComponentContainer::FightBuff(FightBuff { fight_buff_infos: concomitant_buffs, ..Default::default() })) .with(ComponentContainer::Summoner(Summoner { summon_cfg_id: summon_cfg.id, summon_skill_id: 0, summon_type: ESummonType::ESummonTypeConcomitantCustom.into() })) - .build() + .with(ComponentContainer::Autonomous(Autonomous { autonomous_id: 3 })) + .build(), summon_cfg.born_buff_id.clone()) } -#[macro_export] -macro_rules! create_player_entity_pb { - ($role_list:expr, $cur_map_id:expr, $player:expr, $player_id:expr, $position:expr, $explore_tools:expr, $world:expr) => {{ - use $crate::logic::components::Concomitant; - use $crate::logic::utils::world_util::summon_concomitant; - - let current_formation = $player - .formation_list - .get(&$player.cur_formation_id) - .unwrap(); - let cur_role_id = current_formation.cur_role; - - let mut pbs = Vec::new(); - - for role in $role_list { - let role_id: i32 = role.role_id; - let entity = - $world.create_entity(role.role_id, EEntityType::Player.into(), $cur_map_id); - let fight_buff_infos = $world.generate_role_permanent_buffs(entity.entity_id, role_id); - - let buffs = FightBuff { - fight_buff_infos, - ..Default::default() - }; - - // TODO: add actual weapon switching and remove this! - rabby - let equip_weapon = match role.role_id { - 1409 => 21020056, // cartethyia - 1207 => 21010036, // lupa - 1301 => 21010036, - _ => role.equip_weapon, - }; - - let mut concomitants: Vec = vec![]; - let mut summon_id = 1000; - - for (_, summon_cfg) in wicked_waifus_data::summon_cfg_data::iter().filter(|(_, cfg)| { - cfg.blueprint_type.starts_with("Player0") && cfg.born_buff_id.iter().any(|x| { - x.to_string().starts_with(&role.role_id.to_string()) - }) - }) { - let concomitant = summon_concomitant($player, $world, summon_cfg, summon_id); - summon_id += 1; - concomitants.push(concomitant.entity_id.into()); - - let pb = EntityPb { - id: summon_id as i64, - ..Default::default() - }; - - pbs.push(pb); - } - - let entity = $world - .create_builder(entity) - .with(ComponentContainer::PlayerOwnedEntityMarker( - PlayerOwnedEntityMarker { - entity_type: EEntityType::Player, - }, - )) - .with(ComponentContainer::EntityConfig(EntityConfig { - camp: 0, - config_id: role.role_id, - config_type: EntityConfigType::Character, - entity_type: EEntityType::Player.into(), - entity_state: EntityState::Default, - })) - .with(ComponentContainer::OwnerPlayer(OwnerPlayer($player_id))) - .with(ComponentContainer::Position(Position($position))) - .with(ComponentContainer::Visibility(Visibility { - is_visible: role.role_id == cur_role_id, - is_actor_visible: true, - })) - .with(ComponentContainer::Attribute(Attribute::from_data( - &role.get_base_properties(), - None, - None, - ))) - .with(ComponentContainer::Movement(Movement::default())) - .with(ComponentContainer::Equip(Equip { - weapon_id: equip_weapon, - weapon_breach_level: 90, - })) - .with(ComponentContainer::VisionSkill(VisionSkill { - skill_id: $explore_tools.active_explore_skill, - })) - .with(ComponentContainer::RoleSkin(RoleSkin { - skin_id: role.skin_id, - })) - .with(ComponentContainer::SoarWingSkin(SoarWingSkin { - skin_id: 84000001, - })) - .with(ComponentContainer::FightBuff(buffs)) - .with(ComponentContainer::Concomitant(Concomitant { - vision_entity_id: 0, - custom_entity_ids: concomitants, - phantom_role_id: 0 - })) - .build(); - - let mut pb = EntityPb { - id: entity.entity_id as i64, - ..Default::default() - }; - - $world - .get_entity_components(entity.entity_id) - .into_iter() - .for_each(|comp| comp.set_pb_data(&mut pb)); - pbs.push(pb); - } - - EntityAddNotify { - entity_pbs: pbs, - remove_tag_ids: true, - } - }}; -} - -pub fn add_player_entities(player: &Player) { - let mut world_ref = player.world.borrow_mut(); - let world = world_ref.get_mut_world_entity(); - - let current_formation = player.formation_list.get(&player.cur_formation_id).unwrap(); - - let role_vec = current_formation +fn add_player_entity(player: &Player, formation: &RoleFormation, world: &mut WorldEntity) { + let role_vec = formation .role_ids .iter() .map(|role_id| player.role_list.get(role_id).unwrap()) .collect::>(); - let cur_role_id = current_formation.cur_role; - if world.active_entity_empty() { - for role in role_vec { - let entity = world.create_entity( - role.role_id, - EEntityType::Player.into(), - player.basic_info.cur_map_id, - ); + tracing::info!("adding player entity for formation {:#?}", formation.role_ids); + let cur_role_id = formation.cur_role; - let fight_buff_infos = world.generate_role_permanent_buffs(entity.entity_id, role.role_id); - let buf_manager = FightBuff { - fight_buff_infos, - list_buff_effect_cd: vec![] - }; + let mut pbs = Vec::new(); - // TODO: add actual weapon switching and remove this! - rabby - let equip_weapon = match role.role_id { - 1409 => 21020056, // cartethyia - 1207 => 21010036, // lupa - 1301 => 21010036, - _ => role.equip_weapon, - }; + for role in role_vec { + let entity = world.create_entity( + role.role_id, + EEntityType::Player.into(), + player.basic_info.cur_map_id, + ); + + let mut fight_buff_infos = world.generate_role_permanent_buffs(entity.entity_id, role.role_id); + + // TODO: add actual weapon switching and remove this! - rabby + let equip_weapon = match role.role_id { + 1409 => 21020056, // cartethyia + 1207 => 21010036, // lupa + 1301 => 21010036, + _ => role.equip_weapon, + }; + + let mut concomitants: Vec = vec![]; + let mut concom_pbs = Vec::new(); + + let role_data = wicked_waifus_data::role_info_data::iter().find(|r| r.id == role.role_id).unwrap(); + if let Some(skin_damage_first) = role_data.skin_damage.first() { + let role_name = skin_damage_first.as_str() + .split('/').next_back() + .and_then(|s| s.strip_prefix("DA_")) + .and_then(|s| s.split('_').next()).unwrap(); - let mut concomitants: Vec = vec![]; let mut summon_id = 1000; - - for (_, summon_cfg) in wicked_waifus_data::summon_cfg_data::iter().filter(|(_, cfg)| { - cfg.blueprint_type.starts_with("Player0") && cfg.born_buff_id.iter().any(|x| { - x.to_string().starts_with(&role.role_id.to_string()) - }) + for model_config in wicked_waifus_data::model_config_preload_data::iter().filter(|cfg| { + cfg.actor_class_path.starts_with("/Game/Aki/Character/Monster/Summon/") && cfg.actor_class_path.contains(role_name) }) { - let concomitant = summon_concomitant(player, world, summon_cfg, summon_id); + let template_cfg = wicked_waifus_data::template_config_data::iter().find(|cfg| { + let template_model_component = cfg.1.components_data.model_component.clone(); + template_model_component.is_some() + && + template_model_component.clone().unwrap().model_type.unwrap().model_id.is_some() + && + template_model_component.unwrap().model_type.unwrap().model_id.unwrap() == model_config.id + }).unwrap().1; + + let (concomitant, buffs) = summon_concomitant(player, world, template_cfg, summon_id); + let mut pb = EntityPb { + id: summon_id as i64, + ..Default::default() + }; + + for buff_id in buffs { + fight_buff_infos.push(world.create_buff(entity.entity_id, buff_id)); + } + + world + .get_entity_components(summon_id) + .into_iter() + .for_each(|comp| comp.set_pb_data(&mut pb)); + concom_pbs.push(pb); summon_id += 1; concomitants.push(concomitant.entity_id.into()); } - let entity = world - .create_builder(entity) - .with(ComponentContainer::PlayerOwnedEntityMarker( - PlayerOwnedEntityMarker { - entity_type: EEntityType::Player, - }, - )) - .with(ComponentContainer::EntityConfig(EntityConfig { - camp: 0, - config_id: role.role_id, - config_type: EntityConfigType::Character, - entity_type: EEntityType::Player, - entity_state: EntityState::Default, - })) - .with(ComponentContainer::OwnerPlayer(OwnerPlayer( - player.basic_info.id, - ))) - .with(ComponentContainer::Position(Position( - player.location.position.clone(), - ))) - .with(ComponentContainer::Visibility(Visibility { - is_visible: role.role_id == cur_role_id, - is_actor_visible: true, - })) - // TODO: from role - // TODO: Check if role has hardness or rage_mode - // TODO: Support AddProp from Equipment(Echo, weapon, buffs??), weapon base state goes to base_prop too. - .with(ComponentContainer::Attribute(Attribute::from_data( - &role.get_base_properties(), - None, - None, - ))) - .with(ComponentContainer::Movement(Movement::default())) - .with(ComponentContainer::Equip(Equip { - weapon_id: equip_weapon, - weapon_breach_level: 0, // TODO: store this too - })) - .with(ComponentContainer::VisionSkill(VisionSkill { - skill_id: player.explore_tools.active_explore_skill, - })) - .with(ComponentContainer::RoleSkin(RoleSkin { - skin_id: role.skin_id, - })) - .with(ComponentContainer::SoarWingSkin(SoarWingSkin { - skin_id: 84000001, - })) - .with(ComponentContainer::FightBuff(buf_manager)) - .with(ComponentContainer::Concomitant(Concomitant { - vision_entity_id: 0, - custom_entity_ids: concomitants, - phantom_role_id: 0 - })) - .build(); - - tracing::debug!( - "created player entity, id: {}, role_id: {}", - entity.entity_id, - role.role_id - ); + player.notify(EntityAddNotify { + entity_pbs: concom_pbs, + remove_tag_ids: true, + }); } + fight_buff_infos.dedup_by(|x, z| x.buff_id == z.buff_id); + + let buf_manager = FightBuff { + fight_buff_infos, + list_buff_effect_cd: vec![] + }; + + let entity = world + .create_builder(entity) + .with(ComponentContainer::PlayerOwnedEntityMarker( + PlayerOwnedEntityMarker { + entity_type: EEntityType::Player, + }, + )) + .with(ComponentContainer::EntityConfig(EntityConfig { + camp: 0, + config_id: role.role_id, + config_type: EntityConfigType::Character, + entity_type: EEntityType::Player, + entity_state: EntityState::Default, + })) + .with(ComponentContainer::OwnerPlayer(OwnerPlayer( + player.basic_info.id, + ))) + .with(ComponentContainer::Position(Position( + player.location.position.clone(), + ))) + .with(ComponentContainer::Visibility(Visibility { + is_visible: role.role_id == cur_role_id, + is_actor_visible: true, + })) + // TODO: from role + // TODO: Check if role has hardness or rage_mode + // TODO: Support AddProp from Equipment(Echo, weapon, buffs??), weapon base state goes to base_prop too. + .with(ComponentContainer::Attribute(Attribute::from_data( + &role.get_base_properties(), + None, + None, + ))) + .with(ComponentContainer::Movement(Movement::default())) + .with(ComponentContainer::Equip(Equip { + weapon_id: equip_weapon, + weapon_breach_level: 0, // TODO: store this too + })) + .with(ComponentContainer::VisionSkill(VisionSkill { + skill_id: player.explore_tools.active_explore_skill, + })) + .with(ComponentContainer::RoleSkin(RoleSkin { + skin_id: role.skin_id, + })) + .with(ComponentContainer::SoarWingSkin(SoarWingSkin { + skin_id: 84000001, + })) + .with(ComponentContainer::FightBuff(buf_manager)) + .with(ComponentContainer::Concomitant(Concomitant { + vision_entity_id: 0, + custom_entity_ids: concomitants, + phantom_role_id: 0 + })) + .build(); + + let mut pb = EntityPb { + id: entity.entity_id as i64, + ..Default::default() + }; + + world + .get_entity_components(entity.entity_id) + .into_iter() + .for_each(|comp| comp.set_pb_data(&mut pb)); + pbs.push(pb); + + tracing::debug!( + "created player entity, id: {}, role_id: {}", + entity.entity_id, + role.role_id + ); } + + player.notify(EntityAddNotify { + entity_pbs: pbs, + remove_tag_ids: true, + }); +} + +pub fn add_player_entities(player: &Player, formation: &RoleFormation, possible_world: Option<&mut WorldEntity>) { + match possible_world { + Some(world) => add_player_entity(player, formation, world), + None => { + let mut world_ref = player.world.borrow_mut(); + add_player_entity(player, formation, world_ref.get_mut_world_entity()) + } + }; } pub fn build_scene_information(player: &Player) -> SceneInformation {