diff --git a/server/src/cryp.rs b/server/src/cryp.rs index 4c77fbb5..20bcd313 100644 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -167,8 +167,9 @@ impl Cryp { self.create() } - pub fn create(mut self) -> Cryp { + pub fn roll_stat(&mut self, stat: Stat) -> &mut Cryp { let mut rng = thread_rng(); + let stam_max = match self.lvl == 64 { true => u64::max_value(), false => 2_u64.pow(self.lvl.into()), @@ -189,12 +190,30 @@ impl Cryp { false => 2_u64.pow(self.lvl.saturating_sub(2).into()), }; - self.xp = stam_max; + match stat { + Stat::PhysicalDamage => self.phys_dmg.set(rng.gen_range(other_min, other_max)), + Stat::SpellDamage => self.spell_dmg.set(rng.gen_range(other_min, other_max)), + Stat::Stamina => { + self.stamina.set(rng.gen_range(stam_min, stam_max)); + self.hp.set(self.stamina.base) + }, + _ => panic!("{:?} not a rollable stat", stat), + }; - self.phys_dmg.set(rng.gen_range(other_min, other_max)); - self.spell_dmg.set(rng.gen_range(other_min, other_max)); - self.stamina.set(rng.gen_range(stam_min, stam_max)); - self.hp.set(self.stamina.base); + self + } + + pub fn create(mut self) -> Cryp { + let xp = match self.lvl == 64 { + true => u64::max_value(), + false => 2_u64.pow(self.lvl.into()), + }; + + self.xp = xp; + + self.roll_stat(Stat::PhysicalDamage); + self.roll_stat(Stat::SpellDamage); + self.roll_stat(Stat::Stamina); self } @@ -288,7 +307,7 @@ impl Cryp { self } - pub fn reduce_effect_durations(&mut self, log: &mut Log) -> &mut Cryp { + pub fn reduce_effect_durations(&mut self, _log: &mut Log) -> &mut Cryp { self.effects = self.effects.clone().into_iter().filter_map(|mut effect| { effect.duration = effect.duration.saturating_sub(1); @@ -303,10 +322,10 @@ impl Cryp { self } - pub fn rez(&mut self) -> &mut Cryp { - self.hp.set(self.stamina.base); - self - } + // pub fn rez(&mut self) -> &mut Cryp { + // self.hp.set(self.stamina.base); + // self + // } // Stats pub fn phys_dmg(&self) -> u64 { diff --git a/server/src/item.rs b/server/src/item.rs index 36046178..6fbe908d 100644 --- a/server/src/item.rs +++ b/server/src/item.rs @@ -6,13 +6,12 @@ use failure::Error; // drops use rand::prelude::*; -use rand::{thread_rng, Rng}; +use rand::{thread_rng}; use rand::distributions::{WeightedIndex}; use account::Account; use rpc::{ItemUseParams}; -use cryp::{cryp_get, cryp_write}; - +use cryp::{Stat, cryp_get, cryp_write}; #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] pub enum ItemAction { @@ -41,16 +40,23 @@ impl Item { fn apply(&mut self, tx: &mut Transaction, target: Uuid) -> Result<(), Error> { match self.action { - ItemAction::RerollStamina => revive(self, tx, target), - ItemAction::RerollPhysDamage => revive(self, tx, target), - ItemAction::RerollSpellDamage => revive(self, tx, target), + ItemAction::RerollStamina => reroll(self, tx, target, Stat::Stamina), + ItemAction::RerollPhysDamage => reroll(self, tx, target, Stat::PhysicalDamage), + ItemAction::RerollSpellDamage => reroll(self, tx, target, Stat::SpellDamage), } } } -fn revive(item: &mut Item, tx: &mut Transaction, target: Uuid) -> Result<(), Error> { +// fn revive(item: &mut Item, tx: &mut Transaction, target: Uuid) -> Result<(), Error> { +// let mut cryp = cryp_get(tx, target, item.account)?; +// cryp.rez(); +// cryp_write(cryp, tx)?; +// return Ok(()); +// } + +fn reroll(item: &mut Item, tx: &mut Transaction, target: Uuid, stat: Stat) -> Result<(), Error> { let mut cryp = cryp_get(tx, target, item.account)?; - cryp.rez(); + cryp.roll_stat(stat); cryp_write(cryp, tx)?; return Ok(()); }