weapon fix, and inability to remove cursed items

This commit is contained in:
Llywelwyn 2023-08-22 08:43:56 +01:00
parent d277384cc5
commit e403a6d845
6 changed files with 79 additions and 23 deletions

View file

@ -110,7 +110,8 @@
"renderable": { "glyph": ")", "fg": "#808080", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#808080", "bg": "#000000", "order": 2 },
"weight": 1, "weight": 1,
"value": 2, "value": 2,
"equip": { "slot": "EQUIP_MELEE", "flag": "FINESSE", "damage": "1d4", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "FINESSE", "damage": "1d4", "to_hit": 0 }
}, },
{ {
"id": "equip_shortsword", "id": "equip_shortsword",
@ -118,7 +119,8 @@
"renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 },
"weight": 2, "weight": 2,
"value": 10, "value": 10,
"equip": { "slot": "EQUIP_MELEE", "flag": "STRENGTH", "damage": "1d6", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "STRENGTH", "damage": "1d6", "to_hit": 0 }
}, },
{ {
"id": "equip_rapier", "id": "equip_rapier",
@ -126,7 +128,8 @@
"renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 },
"weight": 2, "weight": 2,
"value": 10, "value": 10,
"equip": { "slot": "EQUIP_MELEE", "flag": "FINESSE", "damage": "1d8", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "FINESSE", "damage": "1d8", "to_hit": 0 }
}, },
{ {
"id": "equip_pitchfork", "id": "equip_pitchfork",
@ -134,7 +137,8 @@
"renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 },
"weight": 2, "weight": 2,
"value": 5, "value": 5,
"equip": { "slot": "EQUIP_MELEE", "flag": "FINESSE", "damage": "1d6", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "FINESSE", "damage": "1d6", "to_hit": 0 }
}, },
{ {
"id": "equip_sickle", "id": "equip_sickle",
@ -142,7 +146,8 @@
"renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 },
"weight": 2, "weight": 2,
"value": 5, "value": 5,
"equip": { "slot": "EQUIP_MELEE", "flag": "FINESSE", "damage": "1d6", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "FINESSE", "damage": "1d6", "to_hit": 0 }
}, },
{ {
"id": "equip_handaxe", "id": "equip_handaxe",
@ -150,7 +155,8 @@
"renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#C0C0C0", "bg": "#000000", "order": 2 },
"weight": 2, "weight": 2,
"value": 5, "value": 5,
"equip": { "slot": "EQUIP_MELEE", "flag": "STRENGTH", "damage": "1d6", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "STRENGTH", "damage": "1d6", "to_hit": 0 }
}, },
{ {
"id": "equip_longsword", "id": "equip_longsword",
@ -158,7 +164,8 @@
"renderable": { "glyph": ")", "fg": "#FFF8DC", "bg": "#000000", "order": 2 }, "renderable": { "glyph": ")", "fg": "#FFF8DC", "bg": "#000000", "order": 2 },
"weight": 3, "weight": 3,
"value": 15, "value": 15,
"equip": { "slot": "EQUIP_MELEE", "flag": "STRENGTH", "damage": "1d8", "to_hit": 0 } "flags": ["EQUIP_MELEE"],
"equip": { "flag": "STRENGTH", "damage": "1d8", "to_hit": 0 }
}, },
{ {
"id": "equip_smallshield", "id": "equip_smallshield",

View file

@ -48,12 +48,10 @@
"id": "scrolls", "id": "scrolls",
"table": [ "table": [
{ "id": "scroll_confusion", "weight": 2, "difficulty": 1}, { "id": "scroll_confusion", "weight": 2, "difficulty": 1},
{ "id": "scroll_magicmap_c", "weight": 2, "difficulty": 1},
{ "id": "scroll_magicmap", "weight": 2, "difficulty": 1}, { "id": "scroll_magicmap", "weight": 2, "difficulty": 1},
{ "id": "scroll_embers", "weight": 2, "difficulty": 2}, { "id": "scroll_embers", "weight": 2, "difficulty": 2},
{ "id": "scroll_health", "weight": 2, "difficulty": 2}, { "id": "scroll_health", "weight": 2, "difficulty": 2},
{ "id": "scroll_fireball", "weight": 2, "difficulty": 2}, { "id": "scroll_fireball", "weight": 2, "difficulty": 2},
{ "id": "scroll_fireball_c", "weight": 2, "difficulty": 2},
{ "id": "scroll_mass_health", "weight": 1, "difficulty": 2}, { "id": "scroll_mass_health", "weight": 1, "difficulty": 2},
{ "id": "scroll_mass_confusion", "weight": 1, "difficulty": 3} { "id": "scroll_mass_confusion", "weight": 1, "difficulty": 3}
] ]

View file

@ -2,7 +2,7 @@ use crate::{
gamelog, gamelog,
gui::{item_colour, obfuscate_name}, gui::{item_colour, obfuscate_name},
Beatitude, EquipmentChanged, Equippable, Equipped, InBackpack, MagicItem, MasterDungeonMap, Name, ObfuscatedName, Beatitude, EquipmentChanged, Equippable, Equipped, InBackpack, MagicItem, MasterDungeonMap, Name, ObfuscatedName,
WantsToUseItem, WantsToUseItem, BUC,
}; };
use specs::prelude::*; use specs::prelude::*;
@ -47,14 +47,40 @@ impl<'a> System<'a> for ItemEquipSystem {
if let Some(can_equip) = equippable.get(wants_to_use_item.item) { if let Some(can_equip) = equippable.get(wants_to_use_item.item) {
let target_slot = can_equip.slot; let target_slot = can_equip.slot;
let mut logger = gamelog::Logger::new(); let mut logger = gamelog::Logger::new();
// Remove any items target has in item's slot // Remove any items target has in item's slot
let mut can_equip = true;
let mut to_unequip: Vec<Entity> = Vec::new(); let mut to_unequip: Vec<Entity> = Vec::new();
for (item_entity, already_equipped, _name) in (&entities, &equipped, &names).join() { for (item_entity, already_equipped, _name) in (&entities, &equipped, &names).join() {
if already_equipped.owner == target && already_equipped.slot == target_slot { if already_equipped.owner == target && already_equipped.slot == target_slot {
if let Some(beatitude) = beatitudes.get(item_entity) {
if beatitude.buc == BUC::Cursed {
can_equip = false;
logger = logger
.append("You can't remove the")
.colour(item_colour(item_entity, &beatitudes, &dm))
.append_n(
obfuscate_name(
item_entity,
&names,
&magic_items,
&obfuscated_names,
&beatitudes,
&dm,
None,
)
.0,
)
.colour(rltk::WHITE)
.append("!");
}
}
to_unequip.push(item_entity); to_unequip.push(item_entity);
} }
} }
if !can_equip {
logger.log();
continue;
}
for item in to_unequip.iter() { for item in to_unequip.iter() {
equipped.remove(*item); equipped.remove(*item);
backpack.insert(*item, InBackpack { owner: target }).expect("Unable to insert backpack"); backpack.insert(*item, InBackpack { owner: target }).expect("Unable to insert backpack");

View file

@ -1,8 +1,9 @@
use crate::{ use crate::{
gamelog, gamelog,
gui::{item_colour, obfuscate_name}, gui::{item_colour, obfuscate_name},
Beatitude, Equipped, InBackpack, MagicItem, MasterDungeonMap, Name, ObfuscatedName, WantsToRemoveItem, Beatitude, Equipped, InBackpack, MagicItem, MasterDungeonMap, Name, ObfuscatedName, WantsToRemoveItem, BUC,
}; };
use rltk::prelude::*;
use specs::prelude::*; use specs::prelude::*;
pub struct ItemRemoveSystem {} pub struct ItemRemoveSystem {}
@ -37,11 +38,14 @@ impl<'a> System<'a> for ItemRemoveSystem {
) = data; ) = data;
for (entity, to_remove) in (&entities, &wants_remove).join() { for (entity, to_remove) in (&entities, &wants_remove).join() {
equipped.remove(to_remove.item); let mut can_remove = true;
if let Some(_) = names.get(to_remove.item) { if let Some(beatitude) = beatitudes.get(to_remove.item) {
if entity == *player_entity { // If cursed, can't remove!
if beatitude.buc == BUC::Cursed {
can_remove = false;
gamelog::Logger::new() gamelog::Logger::new()
.append("You unequip the") .append("You can't remove the")
.colour(item_colour(to_remove.item, &beatitudes, &dm))
.append_n( .append_n(
obfuscate_name( obfuscate_name(
to_remove.item, to_remove.item,
@ -54,7 +58,34 @@ impl<'a> System<'a> for ItemRemoveSystem {
) )
.0, .0,
) )
.colour(WHITE)
.append("!")
.log();
}
}
if !can_remove {
continue;
}
// If not cursed, remove it
equipped.remove(to_remove.item);
if let Some(_) = names.get(to_remove.item) {
if entity == *player_entity {
gamelog::Logger::new()
.append("You unequip the")
.colour(item_colour(to_remove.item, &beatitudes, &dm)) .colour(item_colour(to_remove.item, &beatitudes, &dm))
.append_n(
obfuscate_name(
to_remove.item,
&names,
&magic_items,
&obfuscated_names,
&beatitudes,
&dm,
None,
)
.0,
)
.colour(WHITE)
.period() .period()
.log(); .log();
} }

View file

@ -22,7 +22,6 @@ pub struct Name {
#[derive(Deserialize, Debug)] #[derive(Deserialize, Debug)]
pub struct Equippable { pub struct Equippable {
pub slot: String,
pub flag: String, pub flag: String,
pub damage: String, pub damage: String,
pub to_hit: Option<i32>, pub to_hit: Option<i32>,

View file

@ -659,6 +659,7 @@ fn find_slot_for_equippable_item(tag: &str, raws: &RawMaster) -> EquipmentSlot {
if let Some(flags) = &item.flags { if let Some(flags) = &item.flags {
for flag in flags { for flag in flags {
match flag.as_str() { match flag.as_str() {
"EQUIP_MELEE" => return EquipmentSlot::Melee,
"EQUIP_SHIELD" => return EquipmentSlot::Shield, "EQUIP_SHIELD" => return EquipmentSlot::Shield,
"EQUIP_BODY" => return EquipmentSlot::Body, "EQUIP_BODY" => return EquipmentSlot::Body,
"EQUIP_HEAD" => return EquipmentSlot::Head, "EQUIP_HEAD" => return EquipmentSlot::Head,
@ -670,12 +671,6 @@ fn find_slot_for_equippable_item(tag: &str, raws: &RawMaster) -> EquipmentSlot {
} }
} }
} }
if let Some(equip) = &item.equip {
match equip.slot.as_str() {
"EQUIP_MELEE" => return EquipmentSlot::Melee,
_ => {}
}
}
panic!("Trying to equip {}, but it has no slot tag.", tag); panic!("Trying to equip {}, but it has no slot tag.", tag);
} }