From 491581c848b873f44583b8e3bd0298a5811f3e04 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 10 Jul 2023 09:09:53 +0100 Subject: [PATCH] more interactions for the curse component --- src/inventory_system.rs | 34 ++++++++++++++++++---------------- src/spawner.rs | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/inventory_system.rs b/src/inventory_system.rs index 102205f..b516a25 100644 --- a/src/inventory_system.rs +++ b/src/inventory_system.rs @@ -1,6 +1,6 @@ use super::{ gamelog::GameLog, CombatStats, Confusion, Consumable, Cursed, Destructible, InBackpack, InflictsDamage, - MagicMapper, Map, Name, ParticleBuilder, Position, ProvidesHealing, RunState, SufferDamage, WantsToDropItem, + MagicMapper, Map, Name, ParticleBuilder, Point, Position, ProvidesHealing, RunState, SufferDamage, WantsToDropItem, WantsToPickupItem, WantsToUseItem, AOE, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME, }; use specs::prelude::*; @@ -89,13 +89,15 @@ impl<'a> System<'a> for ItemUseSystem { let is_cursed = cursed_items.get(wants_to_use.item); + gamelog.entries.push(format!("You use the {}.", item_being_used.name)); + // TARGETING let mut targets: Vec = Vec::new(); match wants_to_use.target { None => { targets.push(*player_entity); } - Some(target) => { + Some(mut target) => { let area_effect = aoe.get(wants_to_use.item); match area_effect { None => { @@ -106,6 +108,18 @@ impl<'a> System<'a> for ItemUseSystem { } } Some(area_effect) => { + // If item with a targeted AOE is cursed, get the position + // of the player and set them to be the new target. + match is_cursed { + None => {} + Some(_) => { + let pos = positions.get(*player_entity); + if let Some(pos) = pos { + target = Point::new(pos.x, pos.y); + } + gamelog.entries.push(format!("The {} disobeys!", item_being_used.name)); + } + } // AOE aoe_item = true; let mut blast_tiles = rltk::field_of_view(target, area_effect.radius, &*map); @@ -132,26 +146,14 @@ impl<'a> System<'a> for ItemUseSystem { // HEALING ITEM let item_heals = provides_healing.get(wants_to_use.item); match item_heals { - None => { - // This is here because the two are mutually exclusive as of now. Later, - // if more items are added (AOE healing scroll?), this'll need to be - // brought out of here. - // - // Ideally, replace it with something that picks the correct verb for - // whatever the item is being used, probably tied to a component. - // i.e. quaffs, uses, reads - gamelog.entries.push(format!("You use the {}.", item_being_used.name)); - } + None => {} Some(heal) => { for target in targets.iter() { let stats = combat_stats.get_mut(*target); if let Some(stats) = stats { stats.hp = i32::min(stats.max_hp, stats.hp + heal.amount); if entity == *player_entity { - gamelog.entries.push(format!( - "You quaff the {}, and heal {} hp.", - item_being_used.name, heal.amount - )); + gamelog.entries.push(format!("Quaffing, you heal {} hp.", heal.amount)); } let pos = positions.get(entity); if let Some(pos) = pos { diff --git a/src/spawner.rs b/src/spawner.rs index bd18e10..09ae288 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -115,6 +115,7 @@ pub fn spawn_room(ecs: &mut World, room: &Rect, map_depth: i32) { "health potion" => health_potion(ecs, x, y), // Scrolls "fireball scroll" => fireball_scroll(ecs, x, y), + "cursed fireball scroll" => cursed_fireball_scroll(ecs, x, y), "confusion scroll" => confusion_scroll(ecs, x, y), "magic missile scroll" => magic_missile_scroll(ecs, x, y), "magic map scroll" => magic_map_scroll(ecs, x, y), @@ -135,6 +136,7 @@ fn room_table(map_depth: i32) -> RandomTable { .add("health potion", 1 + map_depth) // Scrolls .add("fireball scroll", 1 + map_depth) + .add("cursed fireball scroll", 1) .add("confusion scroll", 1) .add("magic missile scroll", 4) .add("magic map scroll", 1) @@ -238,6 +240,27 @@ fn fireball_scroll(ecs: &mut World, x: i32, y: i32) { .build(); } +fn cursed_fireball_scroll(ecs: &mut World, x: i32, y: i32) { + ecs.create_entity() + .with(Position { x, y }) + .with(Renderable { + glyph: rltk::to_cp437(')'), + fg: RGB::named(rltk::ORANGE), + bg: RGB::named(rltk::BLACK), + render_order: 2, + }) + .with(Name { name: "cursed scroll of fireball".to_string() }) + .with(Item {}) + .with(Cursed {}) + .with(Consumable {}) + .with(Destructible {}) + .with(Ranged { range: 10 }) + .with(InflictsDamage { amount: 20 }) + .with(AOE { radius: 3 }) + .marked::>() + .build(); +} + fn confusion_scroll(ecs: &mut World, x: i32, y: i32) { ecs.create_entity() .with(Position { x, y })