Allow restoring of mana
This commit is contained in:
parent
ad92dc34db
commit
868bbade36
@ -423,3 +423,8 @@ pub struct WantsToCastSpell {
|
||||
pub spell: Entity,
|
||||
pub target: Option<Point>,
|
||||
}
|
||||
|
||||
#[derive(Component, Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ProvidesMana {
|
||||
pub mana_amount: i32,
|
||||
}
|
||||
|
@ -42,6 +42,9 @@ pub enum EffectType {
|
||||
Healing {
|
||||
amount: i32,
|
||||
},
|
||||
Mana {
|
||||
amount: i32,
|
||||
},
|
||||
Confusion {
|
||||
turns: i32,
|
||||
},
|
||||
@ -128,6 +131,7 @@ fn tile_effect_hits_entities(effect: &EffectType) -> bool {
|
||||
| EffectType::Confusion { .. }
|
||||
| EffectType::TeleportTo { .. }
|
||||
| EffectType::AttributeEffect { .. }
|
||||
| EffectType::Mana { .. }
|
||||
)
|
||||
}
|
||||
|
||||
@ -161,6 +165,7 @@ fn affect_entity(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
|
||||
}
|
||||
EffectType::WellFed => hunger::well_fed(ecs, effect, target),
|
||||
EffectType::Healing { .. } => damage::heal_damage(ecs, effect, target),
|
||||
EffectType::Mana { .. } => damage::restore_mana(ecs, effect, target),
|
||||
EffectType::Confusion { .. } => damage::add_confusion(ecs, effect, target),
|
||||
EffectType::TeleportTo { .. } => movement::apply_teleport(ecs, effect, target),
|
||||
EffectType::AttributeEffect { .. } => damage::attribute_effect(ecs, effect, target),
|
||||
|
@ -129,6 +129,25 @@ pub fn heal_damage(ecs: &mut World, heal: &EffectSpawner, target: Entity) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn restore_mana(ecs: &mut World, mana: &EffectSpawner, target: Entity) {
|
||||
let mut pools = ecs.write_storage::<Pools>();
|
||||
if let Some(pool) = pools.get_mut(target) {
|
||||
if let EffectType::Mana { amount } = mana.effect_type {
|
||||
pool.hit_points.current = i32::min(pool.mana.max, pool.mana.current + amount);
|
||||
add_effect(
|
||||
None,
|
||||
EffectType::Particle {
|
||||
glyph: ::rltk::to_cp437('‼'),
|
||||
fg: colors::BLUE,
|
||||
bg: colors::BLACK,
|
||||
lifespan: 200.0,
|
||||
},
|
||||
Targets::Single { target },
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_confusion(ecs: &mut World, effect: &EffectSpawner, target: Entity) {
|
||||
if let EffectType::Confusion { turns } = &effect.effect_type {
|
||||
ecs.create_entity()
|
||||
|
@ -3,8 +3,9 @@ use ::specs::prelude::*;
|
||||
use super::{add_effect, EffectType, Targets};
|
||||
use crate::components::{
|
||||
AttributeBonus, Confusion, Consumable, Duration, Hidden, InflictsDamage, MagicMapper, Name,
|
||||
Pools, ProvidesFood, ProvidesHealing, ProvidesRemoveCurse, SingleActivation,
|
||||
SpawnParticleBurst, SpawnParticleLine, SpellTemplate, TeleportTo, TownPortal,
|
||||
Pools, ProvidesFood, ProvidesHealing, ProvidesIdentification, ProvidesMana,
|
||||
ProvidesRemoveCurse, SingleActivation, SpawnParticleBurst, SpawnParticleLine, SpellTemplate,
|
||||
TeleportTo, TownPortal,
|
||||
};
|
||||
use crate::effects::{entity_position, targeting};
|
||||
use crate::{colors, GameLog, Map, RunState};
|
||||
@ -153,6 +154,18 @@ fn event_trigger(
|
||||
did_something = true;
|
||||
}
|
||||
|
||||
// Identify Item
|
||||
if ecs
|
||||
.read_storage::<ProvidesIdentification>()
|
||||
.get(entity)
|
||||
.is_some()
|
||||
{
|
||||
let mut runstate = ecs.fetch_mut::<RunState>();
|
||||
*runstate = RunState::ShowIdentify;
|
||||
|
||||
did_something = true;
|
||||
}
|
||||
|
||||
// Town Portal
|
||||
if ecs.read_storage::<TownPortal>().get(entity).is_some() {
|
||||
let map = ecs.fetch::<Map>();
|
||||
@ -180,6 +193,19 @@ fn event_trigger(
|
||||
did_something = true;
|
||||
}
|
||||
|
||||
// Mana
|
||||
if let Some(mana) = ecs.read_storage::<ProvidesMana>().get(entity) {
|
||||
add_effect(
|
||||
creator,
|
||||
EffectType::Mana {
|
||||
amount: mana.mana_amount,
|
||||
},
|
||||
targets.clone(),
|
||||
);
|
||||
|
||||
did_something = true;
|
||||
}
|
||||
|
||||
// Damage
|
||||
if let Some(damage) = ecs.read_storage::<InflictsDamage>().get(entity) {
|
||||
add_effect(
|
||||
|
@ -127,6 +127,7 @@ fn init_state() -> State {
|
||||
ProvidesFood,
|
||||
ProvidesHealing,
|
||||
ProvidesIdentification,
|
||||
ProvidesMana,
|
||||
ProvidesRemoveCurse,
|
||||
Quips,
|
||||
Ranged,
|
||||
|
@ -249,6 +249,11 @@ fn skip_turn(ecs: &mut World) -> RunState {
|
||||
let mut health_components = ecs.write_storage::<Pools>();
|
||||
let pools = health_components.get_mut(*player_entity).unwrap();
|
||||
pools.hit_points.current = i32::min(pools.hit_points.current + 1, pools.hit_points.max);
|
||||
|
||||
let mut rng = ecs.fetch_mut::<::rltk::RandomNumberGenerator>();
|
||||
if rng.roll_dice(1, 6) == 1 {
|
||||
pools.mana.current = i32::min(pools.mana.current + 1, pools.mana.max);
|
||||
}
|
||||
}
|
||||
|
||||
RunState::Ticking
|
||||
|
@ -288,6 +288,11 @@ macro_rules! apply_effects {
|
||||
heal_amount: effect.1.parse::<i32>().unwrap(),
|
||||
});
|
||||
}
|
||||
"provides_mana" => {
|
||||
$eb = $eb.with(ProvidesMana {
|
||||
mana_amount: effect.1.parse::<i32>().unwrap(),
|
||||
})
|
||||
}
|
||||
"ranged" => {
|
||||
$eb = $eb.with(Ranged {
|
||||
range: effect.1.parse::<i32>().unwrap(),
|
||||
@ -316,9 +321,10 @@ macro_rules! apply_effects {
|
||||
"particle_line" => $eb = $eb.with(parse_particle_line(&effect.1)),
|
||||
"particle" => $eb = $eb.with(parse_particle(&effect.1)),
|
||||
"remove_curse" => $eb = $eb.with(ProvidesRemoveCurse {}),
|
||||
"identify" => $eb = $eb.with(ProvidesIdentification {}),
|
||||
_ => {
|
||||
console::log(format!(
|
||||
"Warning: consumable effect '{}' not implemented.",
|
||||
"WARNING: consumable effect '{}' not implemented.",
|
||||
effect_name
|
||||
));
|
||||
}
|
||||
|
@ -106,6 +106,7 @@ pub fn save_game(ecs: &mut World) {
|
||||
ProvidesFood,
|
||||
ProvidesHealing,
|
||||
ProvidesIdentification,
|
||||
ProvidesMana,
|
||||
ProvidesRemoveCurse,
|
||||
Quips,
|
||||
Ranged,
|
||||
@ -232,6 +233,7 @@ pub fn load_game(ecs: &mut World) {
|
||||
ProvidesFood,
|
||||
ProvidesHealing,
|
||||
ProvidesIdentification,
|
||||
ProvidesMana,
|
||||
ProvidesRemoveCurse,
|
||||
Quips,
|
||||
Ranged,
|
||||
|
@ -201,20 +201,20 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) {
|
||||
}
|
||||
|
||||
let (idx, name) = *spawn;
|
||||
if name == "None" || name.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let x = (*idx % width) as i32;
|
||||
let y = (*idx / width) as i32;
|
||||
|
||||
let item_result = spawn_named_entity(
|
||||
&RAWS.lock().unwrap(),
|
||||
ecs,
|
||||
name,
|
||||
SpawnType::AtPosition { x, y },
|
||||
);
|
||||
if item_result.is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
if !name.is_empty() {
|
||||
if item_result.is_none() {
|
||||
::rltk::console::log(format!("WARNING: We don't know how to spawn [{}]!", name));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user