2021-01-04 17:16:42 +00:00
|
|
|
use crate::comp::Body;
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-01-07 20:25:12 +00:00
|
|
|
use specs::{Component, DerefFlaggedStorage};
|
2020-07-06 05:56:02 +00:00
|
|
|
use specs_idvs::IdvStorage;
|
2020-01-12 16:43:25 +00:00
|
|
|
|
2020-07-06 05:56:02 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
2020-01-12 16:43:25 +00:00
|
|
|
pub struct Energy {
|
|
|
|
current: u32,
|
|
|
|
maximum: u32,
|
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
bracket bulldozing, boldly
hopefully this should be good?
need to rebase real quick
please let me be done
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
hopefully this should be good?
cargo clippy fmt stuff
deleted an extraneous file?? how did that even...?
2021-01-26 22:47:55 +00:00
|
|
|
base_max: u32,
|
|
|
|
last_max: u32,
|
2019-11-22 00:53:28 +00:00
|
|
|
pub regen_rate: f32,
|
2020-01-12 16:43:25 +00:00
|
|
|
pub last_change: Option<(i32, f64, EnergySource)>,
|
|
|
|
}
|
|
|
|
|
2020-07-06 05:56:02 +00:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
2020-01-12 16:43:25 +00:00
|
|
|
pub enum EnergySource {
|
2020-03-17 14:01:41 +00:00
|
|
|
Ability,
|
2020-02-13 07:30:32 +00:00
|
|
|
Climb,
|
2020-01-12 16:43:25 +00:00
|
|
|
LevelUp,
|
2020-03-10 17:54:59 +00:00
|
|
|
HitEnemy,
|
2019-11-20 18:31:36 +00:00
|
|
|
Regen,
|
2020-01-18 14:00:59 +00:00
|
|
|
Revive,
|
2020-01-12 16:43:25 +00:00
|
|
|
Unknown,
|
|
|
|
}
|
|
|
|
|
2019-11-22 00:53:28 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum StatChangeError {
|
|
|
|
Underflow,
|
|
|
|
Overflow,
|
|
|
|
}
|
|
|
|
|
2020-01-12 16:43:25 +00:00
|
|
|
impl Energy {
|
2021-01-04 17:16:42 +00:00
|
|
|
pub fn new(body: Body, level: u16) -> Energy {
|
|
|
|
let mut energy = Energy::empty();
|
|
|
|
|
|
|
|
energy.update_max_energy(Some(body), level);
|
|
|
|
energy.set_to(energy.maximum(), EnergySource::Revive);
|
|
|
|
|
|
|
|
energy
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn empty() -> Self {
|
2020-01-12 16:43:25 +00:00
|
|
|
Energy {
|
2021-01-04 17:16:42 +00:00
|
|
|
current: 0,
|
|
|
|
maximum: 0,
|
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
bracket bulldozing, boldly
hopefully this should be good?
need to rebase real quick
please let me be done
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
hopefully this should be good?
cargo clippy fmt stuff
deleted an extraneous file?? how did that even...?
2021-01-26 22:47:55 +00:00
|
|
|
base_max: 0,
|
|
|
|
last_max: 0,
|
2019-11-22 00:53:28 +00:00
|
|
|
regen_rate: 0.0,
|
2020-01-12 16:43:25 +00:00
|
|
|
last_change: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn current(&self) -> u32 { self.current }
|
2020-01-12 16:43:25 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn maximum(&self) -> u32 { self.maximum }
|
2020-01-12 16:43:25 +00:00
|
|
|
|
|
|
|
pub fn set_to(&mut self, amount: u32, cause: EnergySource) {
|
|
|
|
let amount = amount.min(self.maximum);
|
|
|
|
self.last_change = Some((amount as i32 - self.current as i32, 0.0, cause));
|
|
|
|
self.current = amount;
|
|
|
|
}
|
|
|
|
|
2020-10-30 21:49:58 +00:00
|
|
|
pub fn change_by(&mut self, change: EnergyChange) {
|
|
|
|
self.current = ((self.current as i32 + change.amount).max(0) as u32).min(self.maximum);
|
|
|
|
self.last_change = Some((change.amount, 0.0, change.source));
|
2020-01-12 16:43:25 +00:00
|
|
|
}
|
|
|
|
|
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
bracket bulldozing, boldly
hopefully this should be good?
need to rebase real quick
please let me be done
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
hopefully this should be good?
cargo clippy fmt stuff
deleted an extraneous file?? how did that even...?
2021-01-26 22:47:55 +00:00
|
|
|
// This function changes the modified max energy value, not the base energy
|
|
|
|
// value. The modified energy value takes into account buffs and other temporary
|
|
|
|
// changes to max energy.
|
|
|
|
pub fn set_maximum(&mut self, amount: u32) {
|
|
|
|
self.maximum = amount;
|
|
|
|
self.current = self.current.min(self.maximum);
|
|
|
|
}
|
|
|
|
|
2019-11-22 00:53:28 +00:00
|
|
|
pub fn try_change_by(
|
|
|
|
&mut self,
|
|
|
|
amount: i32,
|
|
|
|
cause: EnergySource,
|
|
|
|
) -> Result<(), StatChangeError> {
|
|
|
|
if self.current as i32 + amount < 0 {
|
|
|
|
Err(StatChangeError::Underflow)
|
|
|
|
} else if self.current as i32 + amount > self.maximum as i32 {
|
|
|
|
Err(StatChangeError::Overflow)
|
|
|
|
} else {
|
2020-10-30 21:49:58 +00:00
|
|
|
self.change_by(EnergyChange {
|
|
|
|
amount,
|
|
|
|
source: cause,
|
|
|
|
});
|
2019-11-22 00:53:28 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
bracket bulldozing, boldly
hopefully this should be good?
need to rebase real quick
please let me be done
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
hopefully this should be good?
cargo clippy fmt stuff
deleted an extraneous file?? how did that even...?
2021-01-26 22:47:55 +00:00
|
|
|
//sets last_max to base HP, then if the current is more than your base_max
|
|
|
|
// it'll set it to base max
|
|
|
|
pub fn last_set(&mut self) { self.last_max = self.maximum }
|
2021-01-04 17:16:42 +00:00
|
|
|
|
|
|
|
pub fn update_max_energy(&mut self, body: Option<Body>, level: u16) {
|
|
|
|
if let Some(body) = body {
|
2021-01-27 02:25:00 +00:00
|
|
|
self.set_base_max(body.base_energy() + 50 * level as u32);
|
2021-01-04 17:16:42 +00:00
|
|
|
self.set_maximum(body.base_energy() + 50 * level as u32);
|
2021-01-27 02:25:00 +00:00
|
|
|
self.change_by(EnergyChange {
|
|
|
|
amount: 50,
|
|
|
|
source: EnergySource::LevelUp,
|
|
|
|
});
|
2021-01-04 17:16:42 +00:00
|
|
|
}
|
|
|
|
}
|
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
bracket bulldozing, boldly
hopefully this should be good?
need to rebase real quick
please let me be done
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
hopefully this should be good?
cargo clippy fmt stuff
deleted an extraneous file?? how did that even...?
2021-01-26 22:47:55 +00:00
|
|
|
|
|
|
|
pub fn reset_max(&mut self) {
|
|
|
|
self.maximum = self.base_max;
|
|
|
|
if self.current > self.last_max {
|
|
|
|
self.current = self.last_max;
|
|
|
|
self.last_max = self.base_max;
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 02:25:00 +00:00
|
|
|
|
|
|
|
// This is private because max energy is based on the level
|
|
|
|
fn set_base_max(&mut self, amount: u32) {
|
|
|
|
self.base_max = amount;
|
|
|
|
self.current = self.current.min(self.maximum);
|
|
|
|
}
|
2020-01-12 16:43:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-30 21:49:58 +00:00
|
|
|
pub struct EnergyChange {
|
|
|
|
pub amount: i32,
|
|
|
|
pub source: EnergySource,
|
|
|
|
}
|
|
|
|
|
2020-01-12 16:43:25 +00:00
|
|
|
impl Component for Energy {
|
2021-01-07 20:25:12 +00:00
|
|
|
type Storage = DerefFlaggedStorage<Self, IdvStorage<Self>>;
|
2020-01-12 16:43:25 +00:00
|
|
|
}
|