From c2759e9e8e562b5c9bc8e33a3b1876bf1822e093 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Fri, 28 Jul 2023 06:57:14 +0100 Subject: [PATCH] continuing with the overhaul, allowed entities to wear stuff --- raws/items.json | 104 ++++++++++++++++++++++++++++++++++++++++ raws/mobs.json | 3 +- raws/spawn_tables.json | 27 ++++++++--- src/components.rs | 6 +-- src/raws/mob_structs.rs | 1 + src/raws/rawmaster.rs | 20 ++++++-- 6 files changed, 148 insertions(+), 13 deletions(-) diff --git a/raws/items.json b/raws/items.json index c1b59b1..8ec6e2c 100644 --- a/raws/items.json +++ b/raws/items.json @@ -97,6 +97,110 @@ "flags": ["EQUIP_SHIELD"], "effects": { "ac": "4", "melee_power_bonus": "-2" } }, + { + "id": "equip_body_weakleather", + "name": { "name": "leather jacket", "plural": "leather jackets" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_BODY"], + "effects": { "ac": "1" } + }, + { + "id": "equip_body_leather", + "name": { "name": "leather chestpiece", "plural": "leather chestpiece" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_BODY"], + "effects": { "ac": "2" } + }, + { + "id": "equip_body_studdedleather", + "name": { "name": "studded leather chestpiece", "plural": "studded leather chestpieces" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_BODY"], + "effects": { "ac": "3" } + }, + { + "id": "equip_body_ringmail_o", + "name": { "name": "orcish ring mail", "plural": "orcish ring mail" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_BODY"], + "effects": { "ac": "3" } + }, + { + "id": "equip_body_ringmail", + "name": { "name": "ring mail", "plural": "ring mail" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_BODY"], + "effects": { "ac": "4" } + }, + { + "id": "equip_head_leather", + "name": { "name": "leather cap", "plural": "leather caps" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_HEAD"], + "effects": { "ac": "1" } + }, + { + "id": "equip_head_elvish", + "name": { "name": "elvish leather helm", "plural": "elvish leather helms" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_HEAD"], + "effects": { "ac": "2" } + }, + { + "id": "equip_head_o", + "name": { "name": "orcish helm", "plural": "orcish helm" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_HEAD"], + "effects": { "ac": "2" } + }, + { + "id": "equip_head_iron", + "name": { "name": "iron helm", "plural": "iron helm" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_HEAD"], + "effects": { "ac": "3" } + }, + { + "id": "equip_feet_leather", + "name": { "name": "leather shoes", "plural": "leather shoes" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_FEET"] + }, + { + "id": "equip_feet_elvish", + "name": { "name": "elvish leather shoes", "plural": "elvish leather shoes" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_FEET"], + "effects": { "ac": "1" } + }, + { + "id": "equip_feet_o", + "name": { "name": "orcish boots", "plural": "orcish boots" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_FEET"], + "effects": { "ac": "1" } + }, + { + "id": "equip_feet_iron", + "name": { "name": "iron boots", "plural": "iron boots" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_FEET"], + "effects": { "ac": "2" } + }, + { + "id": "equip_neck_protection", + "name": { "name": "amulet of protection", "plural": "amulets of protection" }, + "renderable": { "glyph": "\"", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_NECK"], + "effects": { "ac": "1" } + }, + { + "id": "equip_back_protection", + "name": { "name": "cloak of protection", "plural": "cloaks of protection" }, + "renderable": { "glyph": "[", "fg": "#aa6000", "bg": "#000000", "order": 2 }, + "flags": ["EQUIP_BACK"], + "effects": { "ac": "1" } + }, { "id": "wand_magicmissile", "name": { "name": "wand of magic missile", "plural": "wands of magic missile" }, diff --git a/raws/mobs.json b/raws/mobs.json index 39c5d0a..df8d62f 100644 --- a/raws/mobs.json +++ b/raws/mobs.json @@ -66,7 +66,8 @@ "quips": ["You wont catch me down the mine.", "I'm not paid enough for that."], "attacks": [ { "name": "hits", "hit_bonus": 0, "damage": "1d8"} - ] + ], + "equipped": ["equip_shortsword", "equip_body_leather"] }, { "id": "dog_little", diff --git a/raws/spawn_tables.json b/raws/spawn_tables.json index d28e501..3437fee 100644 --- a/raws/spawn_tables.json +++ b/raws/spawn_tables.json @@ -2,12 +2,27 @@ { "id": "equipment", "table": [ - { "id": "equip_dagger", "weight": 4, "difficulty": 1}, - { "id": "equip_shortsword", "weight": 2, "difficulty": 1}, - { "id": "equip_smallshield", "weight": 4, "difficulty": 1}, - { "id": "equip_mediumshield", "weight": 2, "difficulty": 1}, - { "id": "equip_longsword", "weight": 1, "difficulty": 3}, - { "id": "equip_largeshield", "weight": 1, "difficulty": 3} + { "id": "equip_dagger", "weight": 3, "difficulty": 1}, + { "id": "equip_shortsword", "weight": 3, "difficulty": 1}, + { "id": "equip_smallshield", "weight": 3, "difficulty": 1}, + { "id": "equip_mediumshield", "weight": 2, "difficulty": 1}, + { "id": "equip_body_weakleather", "weight": 4, "difficulty": 1}, + { "id": "equip_head_leather", "weight": 4, "difficulty": 1}, + { "id": "equip_feet_leather", "weight": 4, "difficulty": 1}, + { "id": "equip_body_leather", "weight": 4, "difficulty": 1}, + { "id": "equip_neck_protection", "weight": 1, "difficulty": 1}, + { "id": "equip_back_protection", "weight": 1, "difficulty": 1}, + { "id": "equip_body_studdedleather","weight": 3, "difficulty": 2}, + { "id": "equip_head_o", "weight": 4, "difficulty": 2}, + { "id": "equip_longsword", "weight": 2, "difficulty": 3}, + { "id": "equip_head_elvish", "weight": 3, "difficulty": 3}, + { "id": "equip_feet_elvish", "weight": 3, "difficulty": 3}, + { "id": "equip_body_ringmail_o", "weight": 4, "difficulty": 3}, + { "id": "equip_feet_o", "weight": 4, "difficulty": 3}, + { "id": "equip_body_ringmail", "weight": 2, "difficulty": 3}, + { "id": "equip_largeshield", "weight": 2, "difficulty": 3}, + { "id": "equip_head_iron", "weight": 3, "difficulty": 4}, + { "id": "equip_feet_iron", "weight": 2, "difficulty": 4} ] }, { diff --git a/src/components.rs b/src/components.rs index abcb6b9..86d2df2 100644 --- a/src/components.rs +++ b/src/components.rs @@ -173,11 +173,11 @@ pub enum EquipmentSlot { Melee, Shield, Head, - Neck, - Torso, + Body, Hands, - Legs, Feet, + Neck, + Back, } #[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] diff --git a/src/raws/mob_structs.rs b/src/raws/mob_structs.rs index bf0d480..93cad89 100644 --- a/src/raws/mob_structs.rs +++ b/src/raws/mob_structs.rs @@ -15,6 +15,7 @@ pub struct Mob { pub skills: Option>, pub vision_range: i32, pub quips: Option>, + pub equipped: Option>, } #[derive(Deserialize, Debug)] diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index 128f482..56fdb88 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -107,11 +107,11 @@ pub fn spawn_named_item(raws: &RawMaster, ecs: &mut World, key: &str, pos: Spawn "EQUIP_MELEE" => eb = eb.with(Equippable { slot: EquipmentSlot::Melee }), "EQUIP_SHIELD" => eb = eb.with(Equippable { slot: EquipmentSlot::Shield }), "EQUIP_HEAD" => eb = eb.with(Equippable { slot: EquipmentSlot::Head }), - "EQUIP_TORSO" => eb = eb.with(Equippable { slot: EquipmentSlot::Torso }), - "EQUIP_LEGS" => eb = eb.with(Equippable { slot: EquipmentSlot::Legs }), + "EQUIP_BODY" => eb = eb.with(Equippable { slot: EquipmentSlot::Body }), "EQUIP_FEET" => eb = eb.with(Equippable { slot: EquipmentSlot::Feet }), "EQUIP_HANDS" => eb = eb.with(Equippable { slot: EquipmentSlot::Hands }), "EQUIP_NECK" => eb = eb.with(Equippable { slot: EquipmentSlot::Neck }), + "EQUIP_BACK" => eb = eb.with(Equippable { slot: EquipmentSlot::Back }), "WAND" => eb = eb.with(Wand { uses: 3, max_uses: 3 }), "FOOD" => eb = eb.with(ProvidesNutrition {}), "STRENGTH" => weapon_type = 0, @@ -285,7 +285,15 @@ pub fn spawn_named_mob(raws: &RawMaster, ecs: &mut World, key: &str, pos: SpawnT eb = eb.with(natural); } - return Some(eb.build()); + let new_mob = eb.build(); + + // Build entity, then check for anything they're wearing + if let Some(wielding) = &mob_template.equipped { + for tag in wielding.iter() { + spawn_named_entity(raws, ecs, tag, SpawnType::Equipped { by: new_mob }); + } + } + return Some(new_mob); } None } @@ -414,6 +422,12 @@ fn find_slot_for_equippable_item(tag: &str, raws: &RawMaster) -> EquipmentSlot { match flag.as_str() { "EQUIP_MELEE" => return EquipmentSlot::Melee, "EQUIP_SHIELD" => return EquipmentSlot::Shield, + "EQUIP_BODY" => return EquipmentSlot::Body, + "EQUIP_HEAD" => return EquipmentSlot::Head, + "EQUIP_FEET" => return EquipmentSlot::Feet, + "EQUIP_NECK" => return EquipmentSlot::Neck, + "EQUIP_BACK" => return EquipmentSlot::Back, + "EQUIP_HANDS" => return EquipmentSlot::Hands, _ => {} } }