RegenSystem{} for health regen (mana NYI)
This commit is contained in:
parent
6cef899ef6
commit
0169a88091
8 changed files with 86 additions and 16 deletions
|
|
@ -27,9 +27,13 @@ impl<'a> System<'a> for EnergySystem {
|
|||
if *runstate != RunState::Ticking {
|
||||
return;
|
||||
}
|
||||
for (_entity, _clock, energy) in (&entities, &clock, &mut energies).join() {
|
||||
// Clear TakingTurn{} from every entity.
|
||||
turns.clear();
|
||||
// TURN COUNTER
|
||||
for (entity, _clock, energy) in (&entities, &clock, &mut energies).join() {
|
||||
energy.current += NORMAL_SPEED;
|
||||
if energy.current >= TURN_COST {
|
||||
turns.insert(entity, TakingTurn {}).expect("Unable to insert turn for turn counter.");
|
||||
energy.current -= TURN_COST;
|
||||
crate::gamelog::record_event("turns", 1);
|
||||
// Handle spawning mobs each turn
|
||||
|
|
@ -38,8 +42,7 @@ impl<'a> System<'a> for EnergySystem {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Clear TakingTurn{} from every entity.
|
||||
turns.clear();
|
||||
// EVERYTHING ELSE
|
||||
for (entity, energy, _pos) in (&entities, &mut energies, &positions).join() {
|
||||
// Every entity has a POTENTIAL equal to their speed.
|
||||
let mut energy_potential: i32 = energy.speed;
|
||||
|
|
|
|||
|
|
@ -4,3 +4,5 @@ mod turn_status_system;
|
|||
pub use turn_status_system::TurnStatusSystem;
|
||||
mod quip_system;
|
||||
pub use quip_system::QuipSystem;
|
||||
mod regen_system;
|
||||
pub use regen_system::RegenSystem;
|
||||
|
|
|
|||
61
src/ai/regen_system.rs
Normal file
61
src/ai/regen_system.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use crate::{gamelog, Clock, Player, Pools, Position, RunState, TakingTurn};
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct RegenSystem {}
|
||||
|
||||
const MONSTER_HP_REGEN_TURN: i32 = 20;
|
||||
const MONSTER_HP_REGEN_PER_TICK: i32 = 1;
|
||||
|
||||
impl<'a> System<'a> for RegenSystem {
|
||||
#[allow(clippy::type_complexity)]
|
||||
type SystemData = (
|
||||
ReadStorage<'a, Clock>,
|
||||
Entities<'a>,
|
||||
ReadExpect<'a, RunState>,
|
||||
ReadStorage<'a, Position>,
|
||||
WriteStorage<'a, Pools>,
|
||||
ReadStorage<'a, TakingTurn>,
|
||||
ReadStorage<'a, Player>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (clock, entities, runstate, positions, mut pools, turns, player) = data;
|
||||
if *runstate != RunState::Ticking {
|
||||
return;
|
||||
}
|
||||
for (_e, _c, _t) in (&entities, &clock, &turns).join() {
|
||||
let current_turn = gamelog::get_event_count("turns") + 1;
|
||||
if current_turn % MONSTER_HP_REGEN_TURN == 0 {
|
||||
for (_e, _p, pool, _player) in (&entities, &positions, &mut pools, !&player).join() {
|
||||
try_hp_regen_tick(pool, MONSTER_HP_REGEN_PER_TICK);
|
||||
}
|
||||
}
|
||||
let level = gamelog::get_event_count("player_level");
|
||||
if current_turn % get_player_hp_regen_turn(level) == 0 {
|
||||
for (_e, _p, pool, _player) in (&entities, &positions, &mut pools, &player).join() {
|
||||
try_hp_regen_tick(pool, get_player_hp_regen_per_tick(level));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_player_hp_regen_turn(level: i32) -> i32 {
|
||||
if level < 10 {
|
||||
return (42 / (level + 2)) + 1;
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
fn get_player_hp_regen_per_tick(level: i32) -> i32 {
|
||||
if level < 10 {
|
||||
return 1;
|
||||
} else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
fn try_hp_regen_tick(pool: &mut Pools, amount: i32) {
|
||||
pool.hit_points.current = i32::min(pool.hit_points.current + amount, pool.hit_points.max);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue