Make ItemDrop component with Item again

This commit is contained in:
juliancoffee 2021-09-27 20:36:18 +03:00
parent 943e7cd0e1
commit 7291d32209
12 changed files with 26 additions and 30 deletions

View File

@ -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<T: AsRef<str>>(pub LootSpec<T>);
pub struct ItemDrop(pub Item);
impl Component for ItemDrop<String> {
impl Component for ItemDrop {
type Storage = IdvStorage<Self>;
}

View File

@ -134,7 +134,7 @@ pub enum ServerEvent {
alignment: comp::Alignment,
scale: comp::Scale,
anchor: Option<comp::Anchor>,
drop_item: Option<LootSpec<String>>,
loot: LootSpec<String>,
rtsim_entity: Option<RtSimEntity>,
projectile: Option<comp::Projectile>,
},

View File

@ -160,7 +160,7 @@ pub struct EntityInfo {
pub scale: f32,
// TODO: Properly give NPCs skills
pub health_scaling: Option<u16>,
pub loot_drop: Option<LootSpec<String>>,
pub loot: LootSpec<String>,
pub loadout_asset: Option<String>,
pub make_loadout: Option<fn(LoadoutBuilder, Option<&trade::SiteInformation>) -> LoadoutBuilder>,
pub skillset_asset: Option<String>,
@ -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<String>) -> Self {
self.loot_drop = Some(loot_drop);
self.loot = loot_drop;
self
}

View File

@ -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,
});

View File

@ -189,7 +189,7 @@ impl State {
ecs.register::<comp::Waypoint>();
ecs.register::<comp::Projectile>();
ecs.register::<comp::Melee>();
ecs.register::<comp::ItemDrop<String>>();
ecs.register::<comp::ItemDrop>();
ecs.register::<comp::ChatMode>();
ecs.register::<comp::Faction>();
ecs.register::<comp::invite::Invite>();

View File

@ -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));
}

View File

@ -63,7 +63,7 @@ pub fn handle_create_npc(
agent: impl Into<Option<Agent>>,
alignment: Alignment,
scale: Scale,
drop_item: Option<LootSpec<String>>,
loot: LootSpec<String>,
home_chunk: Option<Anchor>,
rtsim_entity: Option<RtSimEntity>,
projectile: Option<Projectile>,
@ -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

View File

@ -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::<Body>().remove(entity);
let loot_spec = {
let mut item_drop = state.ecs().write_storage::<comp::ItemDrop<String>>();
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::<comp::ItemDrop>();
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::<comp::Pos>().get(entity).cloned();
let vel = state.ecs().read_storage::<comp::Vel>().get(entity).cloned();
if let Some(pos) = pos {

View File

@ -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,

View File

@ -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(

View File

@ -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,
},

View File

@ -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<LootSpec<String>>,
loot: LootSpec<String>,
},
Waypoint(Vec3<f32>),
}
@ -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,
}
}
}