mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add energy comsumption on rolling and charging, and accelerating
regeneration when idle.
This commit is contained in:
parent
df26a24eaa
commit
b4337e57aa
@ -5,6 +5,7 @@ use specs_idvs::IDVStorage;
|
|||||||
pub struct Energy {
|
pub struct Energy {
|
||||||
current: u32,
|
current: u32,
|
||||||
maximum: u32,
|
maximum: u32,
|
||||||
|
pub regen_rate: i32,
|
||||||
pub last_change: Option<(i32, f64, EnergySource)>,
|
pub last_change: Option<(i32, f64, EnergySource)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ pub struct Energy {
|
|||||||
pub enum EnergySource {
|
pub enum EnergySource {
|
||||||
CastSpell,
|
CastSpell,
|
||||||
LevelUp,
|
LevelUp,
|
||||||
|
Regen,
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +22,7 @@ impl Energy {
|
|||||||
Energy {
|
Energy {
|
||||||
current: amount,
|
current: amount,
|
||||||
maximum: amount,
|
maximum: amount,
|
||||||
|
regen_rate: 0,
|
||||||
last_change: None,
|
last_change: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ pub use controller::{
|
|||||||
ControlEvent, Controller, ControllerInputs, Input, InputState, InventoryManip, MountState,
|
ControlEvent, Controller, ControllerInputs, Input, InputState, InventoryManip, MountState,
|
||||||
Mounting,
|
Mounting,
|
||||||
};
|
};
|
||||||
pub use energy::Energy;
|
pub use energy::{Energy, EnergySource};
|
||||||
pub use inputs::CanBuild;
|
pub use inputs::CanBuild;
|
||||||
pub use inventory::{item, Inventory, InventoryUpdate, Item, ItemKind};
|
pub use inventory::{item, Inventory, InventoryUpdate, Item, ItemKind};
|
||||||
pub use last::Last;
|
pub use last::Last;
|
||||||
|
@ -164,10 +164,7 @@ impl Stats {
|
|||||||
current: 0,
|
current: 0,
|
||||||
maximum: 50,
|
maximum: 50,
|
||||||
},
|
},
|
||||||
equipment: Equipment {
|
equipment: Equipment { main, alt: None },
|
||||||
main: main,
|
|
||||||
alt: None,
|
|
||||||
},
|
|
||||||
is_dead: false,
|
is_dead: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
comp::{HealthSource, Stats},
|
comp::{ActionState, CharacterState, Energy, EnergySource, HealthSource, Stats},
|
||||||
event::{EventBus, ServerEvent},
|
event::{EventBus, ServerEvent},
|
||||||
state::DeltaTime,
|
state::DeltaTime,
|
||||||
};
|
};
|
||||||
use specs::{Entities, Join, Read, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
|
||||||
|
|
||||||
|
const ENERGY_REGEN_ACCEL: i32 = 1;
|
||||||
|
const BLOCK_COST: i32 = 50;
|
||||||
|
const ROLL_CHARGE_COST: i32 = 200;
|
||||||
|
|
||||||
/// This system kills players
|
/// This system kills players
|
||||||
/// and handles players levelling up
|
/// and handles players levelling up
|
||||||
@ -13,10 +17,15 @@ impl<'a> System<'a> for Sys {
|
|||||||
Entities<'a>,
|
Entities<'a>,
|
||||||
Read<'a, DeltaTime>,
|
Read<'a, DeltaTime>,
|
||||||
Read<'a, EventBus<ServerEvent>>,
|
Read<'a, EventBus<ServerEvent>>,
|
||||||
|
ReadStorage<'a, CharacterState>,
|
||||||
WriteStorage<'a, Stats>,
|
WriteStorage<'a, Stats>,
|
||||||
|
WriteStorage<'a, Energy>,
|
||||||
);
|
);
|
||||||
|
|
||||||
fn run(&mut self, (entities, dt, server_event_bus, mut stats): Self::SystemData) {
|
fn run(
|
||||||
|
&mut self,
|
||||||
|
(entities, dt, server_event_bus, character_states, mut stats,mut energies): Self::SystemData,
|
||||||
|
) {
|
||||||
let mut server_event_emitter = server_event_bus.emitter();
|
let mut server_event_emitter = server_event_bus.emitter();
|
||||||
|
|
||||||
// Increment last change timer
|
// Increment last change timer
|
||||||
@ -27,7 +36,14 @@ impl<'a> System<'a> for Sys {
|
|||||||
stats.set_event_emission(true);
|
stats.set_event_emission(true);
|
||||||
|
|
||||||
// Mutates all stats every tick causing the server to resend this component for every entity every tick
|
// Mutates all stats every tick causing the server to resend this component for every entity every tick
|
||||||
for (entity, mut stats) in (&entities, &mut stats.restrict_mut()).join() {
|
for (entity, character_state, mut stats, energy) in (
|
||||||
|
&entities,
|
||||||
|
&character_states,
|
||||||
|
&mut stats.restrict_mut(),
|
||||||
|
&mut energies,
|
||||||
|
)
|
||||||
|
.join()
|
||||||
|
{
|
||||||
let (set_dead, level_up) = {
|
let (set_dead, level_up) = {
|
||||||
let stat = stats.get_unchecked();
|
let stat = stats.get_unchecked();
|
||||||
(
|
(
|
||||||
@ -58,6 +74,26 @@ impl<'a> System<'a> for Sys {
|
|||||||
stat.health
|
stat.health
|
||||||
.set_to(stat.health.maximum(), HealthSource::LevelUp)
|
.set_to(stat.health.maximum(), HealthSource::LevelUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recharge energy if not wielding, and accelerate.
|
||||||
|
match character_state.action {
|
||||||
|
ActionState::Wield { .. } | ActionState::Attack { .. } => energy.regen_rate = 0,
|
||||||
|
ActionState::Block { .. } => {
|
||||||
|
energy.change_by(framerate_dt(-BLOCK_COST, dt.0), EnergySource::CastSpell)
|
||||||
|
}
|
||||||
|
ActionState::Roll { .. } | ActionState::Charge { .. } => energy.change_by(
|
||||||
|
framerate_dt(-ROLL_CHARGE_COST, dt.0),
|
||||||
|
EnergySource::CastSpell,
|
||||||
|
),
|
||||||
|
ActionState::Idle => {
|
||||||
|
energy.regen_rate += ENERGY_REGEN_ACCEL;
|
||||||
|
energy.change_by(energy.regen_rate, EnergySource::Regen);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Convience method to scale an integer by dt
|
||||||
|
fn framerate_dt(a: i32, dt: f32) -> i32 {
|
||||||
|
(a as f32 * (dt)) as i32
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user