move healing and spell damage calculations into cryp"
git push "
This commit is contained in:
parent
971c0dd03d
commit
ecabde3389
@ -49,7 +49,7 @@ pub enum Stat {
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
pub struct CrypStat {
|
||||
pub value: u64,
|
||||
value: u64,
|
||||
pub stat: Stat,
|
||||
}
|
||||
|
||||
@ -119,7 +119,6 @@ impl Cryp {
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
pub fn level(mut self, lvl: u8) -> Cryp {
|
||||
self.lvl = check_lvl(lvl);
|
||||
self
|
||||
@ -236,6 +235,47 @@ impl Cryp {
|
||||
self.hp.set(self.stamina.value);
|
||||
self
|
||||
}
|
||||
|
||||
// Stats
|
||||
pub fn phys_dmg(&self) -> u64 {
|
||||
self.phys_dmg.value
|
||||
}
|
||||
|
||||
pub fn spell_dmg(&self) -> u64 {
|
||||
self.spell_dmg.value
|
||||
}
|
||||
|
||||
pub fn hp(&self) -> u64 {
|
||||
self.hp.value
|
||||
}
|
||||
|
||||
pub fn stamina(&self) -> u64 {
|
||||
self.stamina.value
|
||||
}
|
||||
|
||||
// Stat modifications
|
||||
pub fn heal(&mut self, amount: u64) -> (u64, u64) {
|
||||
let current_hp = self.hp();
|
||||
let new_hp = *[
|
||||
self.hp().saturating_add(amount),
|
||||
self.stamina()
|
||||
].iter().min().unwrap();
|
||||
|
||||
let healing = new_hp - current_hp;
|
||||
let overhealing = amount - healing;
|
||||
return (healing, overhealing);
|
||||
}
|
||||
|
||||
pub fn deal_phys_dmg(&mut self, amount: u64) -> (u64, u64) {
|
||||
self.hp.reduce(amount);
|
||||
return (amount, 0);
|
||||
}
|
||||
|
||||
pub fn deal_spell_dmg(&mut self, amount: u64) -> (u64, u64) {
|
||||
self.hp.reduce(amount);
|
||||
return (amount, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp, Error> {
|
||||
|
||||
@ -618,7 +618,7 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
|
||||
let plr: Cryp = from_slice::<Cryp>(&cryp_bytes)?;
|
||||
|
||||
// TEMP
|
||||
if plr.hp.value == 0 {
|
||||
if plr.is_ko() {
|
||||
return Err(err_msg("cryp is ko"));
|
||||
// plr.rez();
|
||||
}
|
||||
|
||||
@ -470,9 +470,9 @@ impl Skill {
|
||||
|
||||
// println!("{:?}'s stats", self.name);
|
||||
// println!("{:064b} <- finalised", roll.result);
|
||||
// roll.result = roll.result & stat.value;
|
||||
// roll.result = roll.result & stat();
|
||||
|
||||
// println!("{:064b} & <- attribute roll", stat.value);
|
||||
// println!("{:064b} & <- attribute roll", stat());
|
||||
// println!("{:064b} = {:?}", roll.result, roll.result);
|
||||
// println!("");
|
||||
|
||||
@ -589,8 +589,8 @@ impl Skill {
|
||||
}
|
||||
|
||||
fn attack(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
target.deal_phys_dmg(cryp.phys_dmg());
|
||||
log.push(format!("{:?} -> {:?} | Attack for {:?}", cryp.name, target.name, cryp.phys_dmg));
|
||||
target.hp.reduce(cryp.phys_dmg.value);
|
||||
}
|
||||
|
||||
fn stun(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
@ -630,14 +630,7 @@ fn snare(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
}
|
||||
|
||||
fn heal(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
let new_hp = *[
|
||||
target.hp.value.saturating_add(cryp.spell_dmg.value),
|
||||
target.stamina.value
|
||||
].iter().min().unwrap();
|
||||
|
||||
let healing = new_hp.saturating_sub(target.hp.value);
|
||||
let overhealing = target.hp.value.saturating_add(cryp.phys_dmg.value).saturating_sub(target.stamina.value);
|
||||
target.hp.value = new_hp;
|
||||
let (healing, overhealing) = target.heal(cryp.phys_dmg());
|
||||
log.push(format!("{:?} -> {:?} | Heal for {:?} ({:?} OH)", cryp.name, target.name, healing, overhealing));
|
||||
}
|
||||
|
||||
@ -652,22 +645,15 @@ fn triage(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
}
|
||||
|
||||
fn triage_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
let new_hp = *[
|
||||
target.hp.value.saturating_add(cryp.spell_dmg.value),
|
||||
target.stamina.value
|
||||
].iter().min().unwrap();
|
||||
|
||||
let healing = new_hp.saturating_sub(target.hp.value);
|
||||
let overhealing = target.hp.value.saturating_add(cryp.phys_dmg.value).saturating_sub(target.stamina.value);
|
||||
target.hp.value = new_hp;
|
||||
let amount = cryp.spell_dmg().wrapping_div(2);
|
||||
let (healing, overhealing) = target.heal(amount);
|
||||
log.push(format!("{:?} -> {:?} | Triage for {:?} ({:?} OH)", cryp.name, target.name, healing, overhealing));
|
||||
target.hp.value = new_hp;
|
||||
}
|
||||
|
||||
fn blast(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
let amount = cryp.spell_dmg.value;
|
||||
let amount = cryp.spell_dmg();
|
||||
log.push(format!("{:?} -> {:?} | Blast for {:?}", cryp.name, target.name, amount));
|
||||
target.hp.reduce(amount);
|
||||
target.deal_spell_dmg(amount);
|
||||
}
|
||||
|
||||
fn amplify(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
@ -687,9 +673,9 @@ fn decay(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
}
|
||||
|
||||
fn decay_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
let amount = cryp.spell_dmg.value;
|
||||
let amount = cryp.spell_dmg();
|
||||
log.push(format!("{:?} -> {:?} | Decay for {:?}", cryp.name, target.name, amount));
|
||||
target.hp.reduce(amount);
|
||||
target.deal_spell_dmg(amount);
|
||||
}
|
||||
|
||||
fn hex(_cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
@ -716,19 +702,10 @@ fn drain(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
|
||||
fn drain_tick(cryp: &mut Cryp, target: &mut Cryp, log: &mut Log) {
|
||||
// damage part
|
||||
let damage = cryp.spell_dmg.value;
|
||||
target.hp.reduce(damage);
|
||||
let (damage, _) = target.deal_spell_dmg(cryp.spell_dmg().wrapping_div(2));
|
||||
log.push(format!("{:?} | Drain damage {:?}", target.name, damage));
|
||||
|
||||
// healing part
|
||||
let new_hp = *[
|
||||
cryp.hp.value.saturating_add(damage),
|
||||
cryp.stamina.value
|
||||
].iter().min().unwrap();
|
||||
|
||||
cryp.hp.value = new_hp;
|
||||
let healing = new_hp.saturating_sub(cryp.hp.value);
|
||||
let overhealing = cryp.hp.value + damage - cryp.stamina.value;
|
||||
let (healing, overhealing) = target.heal(damage);
|
||||
log.push(format!("{:?} | Drain healing {:?} ({:?} OH)", cryp.name, healing, overhealing));
|
||||
}
|
||||
|
||||
@ -763,7 +740,7 @@ mod tests {
|
||||
.learn(Skill::Heal)
|
||||
.create();
|
||||
|
||||
x.hp.reduce(5);
|
||||
x.deal_phys_dmg(5);
|
||||
|
||||
let mut log = vec![];
|
||||
heal(&mut y, &mut x, &mut log);
|
||||
@ -788,7 +765,7 @@ mod tests {
|
||||
|
||||
y.reduce_effect_durations(&mut log);
|
||||
let decay = y.effects.iter().find(|e| e.effect == Effect::Decay);
|
||||
// assert!(y.hp.value == y.stamina.value.saturating_sub(decay.unwrap().tick.unwrap().amount));
|
||||
// assert!(y.hp() == y.stamina().saturating_sub(decay.unwrap().tick.unwrap().amount));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -806,17 +783,17 @@ mod tests {
|
||||
let mut log = vec![];
|
||||
|
||||
// ensure it doesn't have 0 sd
|
||||
x.spell_dmg.value = 50;
|
||||
y.hp.reduce(5);
|
||||
x.spell_dmg.set(50);
|
||||
y.deal_phys_dmg(5);
|
||||
|
||||
let prev_hp = y.hp.value;
|
||||
let prev_hp = y.hp();
|
||||
|
||||
triage(&mut x, &mut y, &mut log);
|
||||
|
||||
assert!(y.effects.iter().any(|e| e.effect == Effect::Triage));
|
||||
|
||||
// y.reduce_effect_durations(&mut log);
|
||||
// assert!(y.hp.value > prev_hp);
|
||||
// assert!(y.hp() > prev_hp);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user