From 7df22ceaec75790a527cf3d09046bbcfe693f311 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Mon, 27 Sep 2021 20:36:18 +0300 Subject: [PATCH] Make ItemDrop component with Item again --- common/src/comp/inventory/item/mod.rs | 5 ++--- common/src/event.rs | 2 +- common/src/generation.rs | 6 +++--- common/src/states/basic_summon.rs | 2 +- common/state/src/state.rs | 2 +- server/src/cmd.rs | 4 ++-- server/src/events/entity_creation.rs | 4 ++-- server/src/events/entity_manipulation.rs | 10 +++------- server/src/events/mod.rs | 4 ++-- server/src/rtsim/entity.rs | 3 ++- server/src/rtsim/tick.rs | 4 ++-- server/src/sys/terrain.rs | 10 +++++----- 12 files changed, 26 insertions(+), 30 deletions(-) diff --git a/common/src/comp/inventory/item/mod.rs b/common/src/comp/inventory/item/mod.rs index b262a64420..547fd2a8a0 100644 --- a/common/src/comp/inventory/item/mod.rs +++ b/common/src/comp/inventory/item/mod.rs @@ -13,7 +13,6 @@ use crate::{ CharacterAbility, }, effect::Effect, - lottery::LootSpec, recipe::RecipeInput, terrain::Block, }; @@ -871,9 +870,9 @@ impl Component for Item { // } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct ItemDrop>(pub LootSpec); +pub struct ItemDrop(pub Item); -impl Component for ItemDrop { +impl Component for ItemDrop { type Storage = IdvStorage; } diff --git a/common/src/event.rs b/common/src/event.rs index e271d4000d..c9eded34a1 100644 --- a/common/src/event.rs +++ b/common/src/event.rs @@ -134,7 +134,7 @@ pub enum ServerEvent { alignment: comp::Alignment, scale: comp::Scale, anchor: Option, - drop_item: Option>, + loot: LootSpec, rtsim_entity: Option, projectile: Option, }, diff --git a/common/src/generation.rs b/common/src/generation.rs index 167fe8da67..efb16b1b3f 100644 --- a/common/src/generation.rs +++ b/common/src/generation.rs @@ -160,7 +160,7 @@ pub struct EntityInfo { pub scale: f32, // TODO: Properly give NPCs skills pub health_scaling: Option, - pub loot_drop: Option>, + pub loot: LootSpec, pub loadout_asset: Option, pub make_loadout: Option) -> LoadoutBuilder>, pub skillset_asset: Option, @@ -184,7 +184,7 @@ impl EntityInfo { second_tool: None, scale: 1.0, health_scaling: None, - loot_drop: None, + loot: LootSpec::Nothing, loadout_asset: None, make_loadout: None, skillset_asset: None, @@ -337,7 +337,7 @@ impl EntityInfo { } pub fn with_loot_drop(mut self, loot_drop: LootSpec) -> Self { - self.loot_drop = Some(loot_drop); + self.loot = loot_drop; self } diff --git a/common/src/states/basic_summon.rs b/common/src/states/basic_summon.rs index eab53dd47b..9ad22acf23 100644 --- a/common/src/states/basic_summon.rs +++ b/common/src/states/basic_summon.rs @@ -187,7 +187,7 @@ impl CharacterBehavior for Data { .scale .unwrap_or(comp::Scale(1.0)), anchor: None, - drop_item: Some(crate::lottery::LootSpec::Nothing), + loot: crate::lottery::LootSpec::Nothing, rtsim_entity: None, projectile, }); diff --git a/common/state/src/state.rs b/common/state/src/state.rs index 141fc82d1b..599d6013d4 100644 --- a/common/state/src/state.rs +++ b/common/state/src/state.rs @@ -189,7 +189,7 @@ impl State { ecs.register::(); ecs.register::(); ecs.register::(); - ecs.register::>(); + ecs.register::(); ecs.register::(); ecs.register::(); ecs.register::(); diff --git a/server/src/cmd.rs b/server/src/cmd.rs index a214a4baf5..375e4ccc08 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -605,7 +605,7 @@ fn handle_make_npc( agent, alignment, scale, - drop_item, + loot, } => { let inventory = Inventory::new_with_loadout(loadout); @@ -621,7 +621,7 @@ fn handle_make_npc( entity_builder = entity_builder.with(agent); } - if let Some(drop_item) = drop_item { + if let Some(drop_item) = loot.to_item() { entity_builder = entity_builder.with(comp::ItemDrop(drop_item)); } diff --git a/server/src/events/entity_creation.rs b/server/src/events/entity_creation.rs index 16243b71c8..4d6cbc4cd2 100644 --- a/server/src/events/entity_creation.rs +++ b/server/src/events/entity_creation.rs @@ -63,7 +63,7 @@ pub fn handle_create_npc( agent: impl Into>, alignment: Alignment, scale: Scale, - drop_item: Option>, + loot: LootSpec, home_chunk: Option, rtsim_entity: Option, projectile: Option, @@ -82,7 +82,7 @@ pub fn handle_create_npc( entity }; - let entity = if let Some(drop_item) = drop_item { + let entity = if let Some(drop_item) = loot.to_item() { entity.with(ItemDrop(drop_item)) } else { entity diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 3d5652d14e..111facb639 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -19,7 +19,6 @@ use common::{ Inventory, Player, Poise, Pos, SkillSet, Stats, }, event::{EventBus, ServerEvent}, - lottery::LootSpec, outcome::Outcome, resources::Time, rtsim::RtSimEntity, @@ -354,14 +353,11 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, last_change: Healt let old_body = state.ecs().write_storage::().remove(entity); let loot_spec = { - let mut item_drop = state.ecs().write_storage::>(); - item_drop.remove(entity).map_or_else( - || LootSpec::LootTable("common.loot_tables.fallback".to_string()), - |item| item.0, - ) + let mut item_drop = state.ecs().write_storage::(); + item_drop.remove(entity).map(|comp::ItemDrop(item)| item) }; - if let Some(item) = loot_spec.to_item() { + if let Some(item) = loot_spec { let pos = state.ecs().read_storage::().get(entity).cloned(); let vel = state.ecs().read_storage::().get(entity).cloned(); if let Some(pos) = pos { diff --git a/server/src/events/mod.rs b/server/src/events/mod.rs index 6846333301..201d9a1258 100644 --- a/server/src/events/mod.rs +++ b/server/src/events/mod.rs @@ -152,7 +152,7 @@ impl Server { alignment, scale, anchor: home_chunk, - drop_item, + loot, rtsim_entity, projectile, } => handle_create_npc( @@ -167,7 +167,7 @@ impl Server { agent, alignment, scale, - drop_item, + loot, home_chunk, rtsim_entity, projectile, diff --git a/server/src/rtsim/entity.rs b/server/src/rtsim/entity.rs index 5c4afcb4b9..d10a2faf2d 100644 --- a/server/src/rtsim/entity.rs +++ b/server/src/rtsim/entity.rs @@ -96,7 +96,8 @@ impl Entity { } } - /// Escape hatch for runtime creation of loadout not covered by entity config. + /// Escape hatch for runtime creation of loadout not covered by entity + /// config. // NOTE: Signature is part of interface of EntityInfo, and site information // is not used for RtSim as of now. pub fn get_adhoc_loadout( diff --git a/server/src/rtsim/tick.rs b/server/src/rtsim/tick.rs index 3769526538..c69ec4e5ed 100644 --- a/server/src/rtsim/tick.rs +++ b/server/src/rtsim/tick.rs @@ -149,7 +149,7 @@ impl<'a> System<'a> for Sys { body, alignment, scale, - drop_item, + loot, } => ServerEvent::CreateNpc { pos, stats, @@ -162,7 +162,7 @@ impl<'a> System<'a> for Sys { alignment, scale, anchor: None, - drop_item, + loot, rtsim_entity, projectile: None, }, diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 3714f9137e..6d9751e892 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -219,7 +219,7 @@ impl<'a> System<'a> for Sys { body, alignment, scale, - drop_item, + loot, } => { server_emitter.emit(ServerEvent::CreateNpc { pos, @@ -233,7 +233,7 @@ impl<'a> System<'a> for Sys { alignment, scale, anchor: Some(comp::Anchor::Chunk(key)), - drop_item, + loot, rtsim_entity: None, projectile: None, }); @@ -358,7 +358,7 @@ pub enum NpcData { body: comp::Body, alignment: comp::Alignment, scale: comp::Scale, - drop_item: Option>, + loot: LootSpec, }, Waypoint(Vec3), } @@ -377,7 +377,7 @@ impl NpcData { scale, pos, health_scaling, - loot_drop, + loot, // tools and skills skillset_asset, main_tool, @@ -484,7 +484,7 @@ impl NpcData { body, alignment, scale: comp::Scale(scale), - drop_item: loot_drop, + loot, } } }