roll specs into vars

This commit is contained in:
ntr
2019-03-15 17:49:24 +11:00
parent 037da44852
commit 0dad45ccb0
6 changed files with 74 additions and 117 deletions
+11 -29
View File
@@ -10,8 +10,8 @@ use failure::err_msg;
use account::{Account};
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams};
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
use spec::{Spec};
use game::{Log};
use vbox::{Var};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub struct CrypSkill {
@@ -64,17 +64,17 @@ pub struct CrypStat {
}
impl CrypStat {
pub fn set(&mut self, v: u64, specs: &Vec<Spec>) -> &mut CrypStat {
pub fn set(&mut self, v: u64, specs: &Vec<Var>) -> &mut CrypStat {
self.base = v;
self.recalculate(specs)
}
pub fn recalculate(&mut self, specs: &Vec<Spec>) -> &mut CrypStat {
pub fn recalculate(&mut self, specs: &Vec<Var>) -> &mut CrypStat {
let specs = specs
.iter()
.filter(|s| s.affects().contains(&self.stat))
.map(|s| *s)
.collect::<Vec<Spec>>();
.collect::<Vec<Var>>();
// applied with fold because it can be zeroed or multiplied
// but still needs access to the base amount
@@ -127,7 +127,7 @@ pub struct Cryp {
pub lvl: u8,
pub skills: Vec<CrypSkill>,
pub effects: Vec<CrypEffect>,
pub specs: Vec<Spec>,
pub specs: Vec<Var>,
pub name: String,
pub ko_logged: bool,
}
@@ -250,18 +250,20 @@ impl Cryp {
self
}
pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
pub fn spec_add(&mut self, spec: Var) -> Result<&mut Cryp, Error> {
self.specs.push(spec);
return Ok(self.recalculate_stats());
}
pub fn spec_remove(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
match self.specs.iter().position(|s| *s == spec) {
pub fn spec_remove(&mut self, spec: Var) -> Result<Var, Error> {
let spec = match self.specs.iter().position(|s| *s == spec) {
Some(p) => self.specs.remove(p),
None => return Err(err_msg("spec not found")),
};
Ok(self.recalculate_stats())
self.recalculate_stats();
Ok(spec)
}
@@ -623,7 +625,6 @@ pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp
pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
let cryp = Cryp::new()
.named(&params.name)
.learn(Skill::Attack)
.level(1)
.set_account(account.id)
.create();
@@ -646,25 +647,6 @@ pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Accou
return Ok(cryp);
}
pub fn cryp_learn(params: CrypLearnParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
let mut cryp = cryp_get(tx, params.id, account.id)?;
// done here because i teach them a tonne of skills for tests
let max_skills = 4;
if cryp.skills.len() >= max_skills {
return Err(format_err!("cryp at max skills ({:?})", max_skills));
}
cryp = cryp.learn(params.skill);
return cryp_write(cryp, tx);
}
pub fn cryp_forget(params: CrypForgetParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
let mut cryp = cryp_get(tx, params.id, account.id)?;
cryp = cryp.forget(params.skill)?;
return cryp_write(cryp, tx);
}
pub fn cryp_unspec(params: CrypUnspecParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
let mut cryp = cryp_get(tx, params.id, account.id)?;
cryp.spec_remove(params.spec)?;
-1
View File
@@ -22,7 +22,6 @@ mod cryp;
mod game;
mod net;
mod skill;
mod spec;
// mod passives;
mod rpc;
mod account;
+2 -3
View File
@@ -20,10 +20,9 @@ use game::{Game, game_state, game_pve, game_skill};
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_players};
use skill::{Skill};
// use zone::{Zone, zone_create, zone_join, zone_close};
use spec::{Spec};
use player::{player_state, player_cryps_set, Player};
use instance::{instance_join, instance_ready};
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim};
use vbox::{Var, vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim};
pub struct Rpc;
@@ -433,7 +432,7 @@ struct CrypForgetMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypUnspecParams {
pub id: Uuid,
pub spec: Spec,
pub spec: Var,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
-64
View File
@@ -1,64 +0,0 @@
use rand::prelude::*;
use cryp::{Stat};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
pub enum Spec {
SpeedI,
// Pure redShield has to come first as it applies the base amount
// that is multiplied
LifeI,
RedShieldI,
BlueShieldI,
LRSI,
LBSI,
RBSI,
RedDamageI,
GreenDamageI,
BlueDamageI,
}
impl Spec {
pub fn affects(&self) -> Vec<Stat> {
match *self {
Spec::RedDamageI => vec![Stat::RedDamage],
Spec::GreenDamageI => vec![Stat::GreenDamage],
Spec::BlueDamageI => vec![Stat::BlueDamage],
Spec::SpeedI => vec![Stat::Speed],
Spec::RedShieldI => vec![Stat::RedShield],
Spec::BlueShieldI => vec![Stat::BlueShield],
Spec::LifeI => vec![Stat::Hp],
Spec::LRSI => vec![Stat::Hp, Stat::RedShield],
Spec::LBSI => vec![Stat::Hp, Stat::BlueShield],
Spec::RBSI => vec![Stat::BlueShield, Stat::RedShield],
}
}
pub fn apply(&self, modified: u64, base: u64) -> u64 {
let mut rng = thread_rng();
let i_min = 32;
let i_max = 64;
match *self {
Spec::RedDamageI => modified + (base * 5 / 100),
Spec::GreenDamageI => modified + (base * 5 / 100),
Spec::BlueDamageI => modified + (base * 5 / 100),
Spec::SpeedI => modified + (base * 5 / 100),
Spec::LifeI => modified + (base * 5 / 100),
Spec::RedShieldI => modified + rng.gen_range(i_min, i_max),
Spec::BlueShieldI => modified + rng.gen_range(i_min, i_max),
Spec::LRSI => modified + (base * 5 / 100),
Spec::LBSI => modified + (base * 5 / 100),
Spec::RBSI => modified + (base * 5 / 100),
}
}
}
+56 -16
View File
@@ -14,8 +14,8 @@ use failure::err_msg;
use account::Account;
use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxReclaimParams};
use skill::{Skill};
use spec::{Spec};
use player::{Player, player_get, player_update};
use cryp::{Stat};
#[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq,PartialOrd,Ord,Eq)]
pub enum Var {
@@ -110,7 +110,7 @@ impl Var {
if let Some(_skill) = self.skill() {
return Some(VarEffect::Skill);
}
if let Some(_spec) = self.spec() {
if self.spec() {
return Some(VarEffect::Spec);
}
return None;
@@ -147,22 +147,63 @@ impl Var {
}
}
fn spec(&self) -> Option<Spec> {
fn spec(&self) -> bool {
match *self {
Var::Speed => Some(Spec::SpeedI),
Var::Speed => true,
Var::RedDamageI => Some(Spec::RedDamageI),
Var::BlueDamageI => Some(Spec::BlueDamageI),
Var::GreenDamageI => Some(Spec::GreenDamageI),
Var::RedDamageI => true,
Var::BlueDamageI => true,
Var::GreenDamageI => true,
Var::LifeI => Some(Spec::LifeI),
Var::LRSI => Some(Spec::LRSI),
Var::LBSI => Some(Spec::LBSI),
Var::RBSI => Some(Spec::RBSI),
Var::RedShieldI => Some(Spec::RedShieldI),
Var::BlueShieldI => Some(Spec::BlueShieldI),
Var::LifeI => true,
Var::LRSI => true,
Var::LBSI => true,
Var::RBSI => true,
Var::RedShieldI => true,
Var::BlueShieldI => true,
_ => None,
_ => false,
}
}
pub fn affects(&self) -> Vec<Stat> {
match self {
Var::RedDamageI => vec![Stat::RedDamage],
Var::GreenDamageI => vec![Stat::GreenDamage],
Var::BlueDamageI => vec![Stat::BlueDamage],
Var::Speed => vec![Stat::Speed],
Var::RedShieldI => vec![Stat::RedShield],
Var::BlueShieldI => vec![Stat::BlueShield],
Var::LifeI => vec![Stat::Hp],
Var::LRSI => vec![Stat::Hp, Stat::RedShield],
Var::LBSI => vec![Stat::Hp, Stat::BlueShield],
Var::RBSI => vec![Stat::BlueShield, Stat::RedShield],
_ => panic!("{:?} is not a spec item", self),
}
}
pub fn apply(&self, modified: u64, base: u64) -> u64 {
let mut rng = thread_rng();
let i_min = 32;
let i_max = 64;
match self {
Var::RedDamageI => modified + (base * 5 / 100),
Var::GreenDamageI => modified + (base * 5 / 100),
Var::BlueDamageI => modified + (base * 5 / 100),
Var::Speed => modified + (base * 5 / 100),
Var::LifeI => modified + (base * 5 / 100),
Var::RedShieldI => modified + rng.gen_range(i_min, i_max),
Var::BlueShieldI => modified + rng.gen_range(i_min, i_max),
Var::LRSI => modified + (base * 5 / 100),
Var::LBSI => modified + (base * 5 / 100),
Var::RBSI => modified + (base * 5 / 100),
_ => panic!("{:?} is not a spec item", self),
}
}
}
@@ -425,9 +466,8 @@ pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Accou
cryp.learn_mut(skill);
},
Some(VarEffect::Spec) => {
let spec = var.spec().ok_or(format_err!("var {:?} has no associated spec", var))?;
let cryp = player.cryp_get(params.cryp_id)?;
cryp.spec_add(spec)?;
cryp.spec_add(var)?;
},
None => return Err(err_msg("var has no effect on cryps")),