obfuscates names of unidentified items

This commit is contained in:
Llywelwyn 2023-08-13 20:16:24 +01:00
parent 7795044d36
commit 9e768c5f73
9 changed files with 166 additions and 29 deletions

View file

@ -10,6 +10,7 @@ pub struct Item {
pub value: Option<f32>,
pub flags: Option<Vec<String>>,
pub effects: Option<HashMap<String, String>>,
pub magic: Option<MagicItem>,
}
#[derive(Deserialize, Debug)]
@ -25,3 +26,9 @@ pub struct Renderable {
pub bg: String,
pub order: i32,
}
#[derive(Deserialize, Debug)]
pub struct MagicItem {
pub class: String,
pub naming: String,
}

View file

@ -111,6 +111,7 @@ pub fn spawn_named_entity(
pub fn spawn_named_item(raws: &RawMaster, ecs: &mut World, key: &str, pos: SpawnType) -> Option<Entity> {
if raws.item_index.contains_key(key) {
let item_template = &raws.raws.items[raws.item_index[key]];
let scroll_names = ecs.fetch::<crate::map::MasterDungeonMap>().scroll_map.clone();
let mut eb = ecs.create_entity().marked::<SimpleMarker<SerializeMe>>();
eb = eb.with(Name { name: item_template.name.name.clone(), plural: item_template.name.plural.clone() });
@ -146,7 +147,6 @@ pub fn spawn_named_item(raws: &RawMaster, ecs: &mut World, key: &str, pos: Spawn
}
}
}
let mut base_damage = "1d4";
let mut hit_bonus = 0;
@ -168,6 +168,27 @@ pub fn spawn_named_item(raws: &RawMaster, ecs: &mut World, key: &str, pos: Spawn
}
}
}
if let Some(magic_item) = &item_template.magic {
let item_class = match magic_item.class.as_str() {
"common" => MagicItemClass::Common,
"uncommon" => MagicItemClass::Uncommon,
"rare" => MagicItemClass::Rare,
"veryrare" => MagicItemClass::VeryRare,
_ => MagicItemClass::Legendary,
};
eb = eb.with(MagicItem { class: item_class });
#[allow(clippy::single_match)]
match magic_item.naming.as_str() {
"scroll" => {
eb = eb.with(ObfuscatedName {
name: scroll_names[&item_template.name.name].0.clone(),
plural: scroll_names[&item_template.name.name].1.clone(),
})
}
_ => {}
}
}
if weapon_type != -1 {
let (n_dice, die_type, bonus) = parse_dice_string(base_damage);
@ -621,3 +642,16 @@ pub fn get_mob_spawn_amount(rng: &mut RandomNumberGenerator, spawn_type: &Spawns
_ => return roll,
};
}
pub fn get_scroll_tags() -> Vec<String> {
let raws = &super::RAWS.lock().unwrap();
let mut result = Vec::new();
for item in raws.raws.items.iter() {
if let Some(magic) = &item.magic {
if &magic.naming == "scroll" {
result.push(item.name.name.clone());
}
}
}
return result;
}