more interactions for the curse component

This commit is contained in:
Llywelwyn 2023-07-10 09:09:53 +01:00
parent e8eaa69909
commit 491581c848
2 changed files with 41 additions and 16 deletions

View file

@ -1,6 +1,6 @@
use super::{ use super::{
gamelog::GameLog, CombatStats, Confusion, Consumable, Cursed, Destructible, InBackpack, InflictsDamage, 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, WantsToPickupItem, WantsToUseItem, AOE, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME,
}; };
use specs::prelude::*; use specs::prelude::*;
@ -89,13 +89,15 @@ impl<'a> System<'a> for ItemUseSystem {
let is_cursed = cursed_items.get(wants_to_use.item); let is_cursed = cursed_items.get(wants_to_use.item);
gamelog.entries.push(format!("You use the {}.", item_being_used.name));
// TARGETING // TARGETING
let mut targets: Vec<Entity> = Vec::new(); let mut targets: Vec<Entity> = Vec::new();
match wants_to_use.target { match wants_to_use.target {
None => { None => {
targets.push(*player_entity); targets.push(*player_entity);
} }
Some(target) => { Some(mut target) => {
let area_effect = aoe.get(wants_to_use.item); let area_effect = aoe.get(wants_to_use.item);
match area_effect { match area_effect {
None => { None => {
@ -106,6 +108,18 @@ impl<'a> System<'a> for ItemUseSystem {
} }
} }
Some(area_effect) => { 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
aoe_item = true; aoe_item = true;
let mut blast_tiles = rltk::field_of_view(target, area_effect.radius, &*map); 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 // HEALING ITEM
let item_heals = provides_healing.get(wants_to_use.item); let item_heals = provides_healing.get(wants_to_use.item);
match item_heals { match item_heals {
None => { 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));
}
Some(heal) => { Some(heal) => {
for target in targets.iter() { for target in targets.iter() {
let stats = combat_stats.get_mut(*target); let stats = combat_stats.get_mut(*target);
if let Some(stats) = stats { if let Some(stats) = stats {
stats.hp = i32::min(stats.max_hp, stats.hp + heal.amount); stats.hp = i32::min(stats.max_hp, stats.hp + heal.amount);
if entity == *player_entity { if entity == *player_entity {
gamelog.entries.push(format!( gamelog.entries.push(format!("Quaffing, you heal {} hp.", heal.amount));
"You quaff the {}, and heal {} hp.",
item_being_used.name, heal.amount
));
} }
let pos = positions.get(entity); let pos = positions.get(entity);
if let Some(pos) = pos { if let Some(pos) = pos {

View file

@ -115,6 +115,7 @@ pub fn spawn_room(ecs: &mut World, room: &Rect, map_depth: i32) {
"health potion" => health_potion(ecs, x, y), "health potion" => health_potion(ecs, x, y),
// Scrolls // Scrolls
"fireball scroll" => fireball_scroll(ecs, x, y), "fireball scroll" => fireball_scroll(ecs, x, y),
"cursed fireball scroll" => cursed_fireball_scroll(ecs, x, y),
"confusion scroll" => confusion_scroll(ecs, x, y), "confusion scroll" => confusion_scroll(ecs, x, y),
"magic missile scroll" => magic_missile_scroll(ecs, x, y), "magic missile scroll" => magic_missile_scroll(ecs, x, y),
"magic map scroll" => magic_map_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) .add("health potion", 1 + map_depth)
// Scrolls // Scrolls
.add("fireball scroll", 1 + map_depth) .add("fireball scroll", 1 + map_depth)
.add("cursed fireball scroll", 1)
.add("confusion scroll", 1) .add("confusion scroll", 1)
.add("magic missile scroll", 4) .add("magic missile scroll", 4)
.add("magic map scroll", 1) .add("magic map scroll", 1)
@ -238,6 +240,27 @@ fn fireball_scroll(ecs: &mut World, x: i32, y: i32) {
.build(); .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::<SimpleMarker<SerializeMe>>()
.build();
}
fn confusion_scroll(ecs: &mut World, x: i32, y: i32) { fn confusion_scroll(ecs: &mut World, x: i32, y: i32) {
ecs.create_entity() ecs.create_entity()
.with(Position { x, y }) .with(Position { x, y })