unspec method

This commit is contained in:
ntr 2019-01-17 14:02:12 +11:00
parent d833b10ded
commit 65c7d86da2
5 changed files with 69 additions and 12 deletions

View File

@ -33,12 +33,9 @@ strangle
## NOW ## NOW
* check zone completion * check zone completion
* recalc evasion rating
* serialize modified stats * serialize modified stats
* items add specs
* add effects to spec
* remove spec from cryp * remove spec from cryp
* spec limits per category * dupe rare specs check
## SOON ## SOON
* clean up categories * clean up categories

View File

@ -8,7 +8,7 @@ use failure::Error;
use failure::err_msg; use failure::err_msg;
use account::Account; use account::Account;
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams}; use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams};
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult}; use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
use spec::{Spec, SpecLevel}; use spec::{Spec, SpecLevel};
use game::{Log}; use game::{Log};
@ -270,7 +270,7 @@ impl Cryp {
self self
} }
pub fn spec_apply(&mut self, spec: Spec) -> Result<&mut Cryp, Error> { pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
let max_common = 20; let max_common = 20;
let max_uncommon = 10; let max_uncommon = 10;
let max_rare = 5; let max_rare = 5;
@ -303,6 +303,28 @@ impl Cryp {
return Ok(self.recalculate_stats()); return Ok(self.recalculate_stats());
} }
pub fn spec_remove(mut self, spec: Spec) -> Result<Cryp, Error> {
let find_spec = |spec_v: &Vec<Spec>| spec_v.iter().position(|s| s.spec == spec.spec);
match spec.level {
SpecLevel::Common => match find_spec(&self.specs.common) {
Some(p) => self.specs.common.remove(p),
None => return Err(err_msg("spec not found")),
},
SpecLevel::Uncommon => match find_spec(&self.specs.uncommon) {
Some(p) => self.specs.uncommon.remove(p),
None => return Err(err_msg("spec not found")),
},
SpecLevel::Rare => match find_spec(&self.specs.rare) {
Some(p) => self.specs.rare.remove(p),
None => return Err(err_msg("spec not found")),
},
};
Ok(self)
}
fn recalculate_stats(&mut self) -> &mut Cryp { fn recalculate_stats(&mut self) -> &mut Cryp {
self.stamina.recalculate(&self.specs); self.stamina.recalculate(&self.specs);
self.hp.recalculate(&self.specs); self.hp.recalculate(&self.specs);
@ -707,6 +729,12 @@ pub fn cryp_forget(params: CrypForgetParams, tx: &mut Transaction, account: &Acc
return cryp_write(cryp, tx); 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 = cryp.spec_remove(params.spec)?;
return cryp_write(cryp, tx);
}
pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> { pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> {
let cryp_bytes = to_vec(&cryp)?; let cryp_bytes = to_vec(&cryp)?;

View File

@ -56,16 +56,16 @@ impl Item {
ItemAction::RerollSpellShield => reroll(self, tx, target, Stat::SpellShield), ItemAction::RerollSpellShield => reroll(self, tx, target, Stat::SpellShield),
ItemAction::RerollEvasion => reroll(self, tx, target, Stat::Evasion), ItemAction::RerollEvasion => reroll(self, tx, target, Stat::Evasion),
ItemAction::SpecPhysDmg5 => spec_apply(self, tx, target, SpecType::PhysDamage5), ItemAction::SpecPhysDmg5 => spec_add(self, tx, target, SpecType::PhysDamage5),
ItemAction::SpecSpellDmg5 => spec_apply(self, tx, target, SpecType::SpellDamage5), ItemAction::SpecSpellDmg5 => spec_add(self, tx, target, SpecType::SpellDamage5),
} }
} }
} }
fn spec_apply(item: &mut Item, tx: &mut Transaction, target: Uuid, spec_type: SpecType) -> Result<(), Error> { fn spec_add(item: &mut Item, tx: &mut Transaction, target: Uuid, spec_type: SpecType) -> Result<(), Error> {
let mut cryp = cryp_get(tx, target, item.account)?; let mut cryp = cryp_get(tx, target, item.account)?;
let spec = Spec::new(spec_type); let spec = Spec::new(spec_type);
cryp.spec_apply(spec)?; cryp.spec_add(spec)?;
cryp_write(cryp, tx)?; cryp_write(cryp, tx)?;
return Ok(()); return Ok(());
} }

View File

@ -15,12 +15,13 @@ use failure::Error;
use failure::err_msg; use failure::err_msg;
use net::Db; use net::Db;
use cryp::{Cryp, cryp_spawn, cryp_learn, cryp_forget}; use cryp::{Cryp, cryp_spawn, cryp_learn, cryp_forget, cryp_unspec};
use game::{Game, game_state, game_pve, game_pvp, game_join, game_joinable_list, game_skill}; use game::{Game, game_state, game_pve, game_pvp, game_join, game_joinable_list, game_skill};
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_zone}; use account::{Account, account_create, account_login, account_from_token, account_cryps, account_zone};
use item::{Item, ItemAction, items_list, item_use, item_create}; use item::{Item, ItemAction, items_list, item_use, item_create};
use skill::{Skill}; use skill::{Skill};
use zone::{Zone, zone_create, zone_join, zone_close}; use zone::{Zone, zone_create, zone_join, zone_close};
use spec::{Spec};
pub struct Rpc; pub struct Rpc;
@ -63,6 +64,7 @@ impl Rpc {
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client), "cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account.unwrap(), client),
"cryp_learn" => Rpc::cryp_learn(data, &mut tx, account.unwrap(), client), "cryp_learn" => Rpc::cryp_learn(data, &mut tx, account.unwrap(), client),
"cryp_forget" => Rpc::cryp_forget(data, &mut tx, account.unwrap(), client), "cryp_forget" => Rpc::cryp_forget(data, &mut tx, account.unwrap(), client),
"cryp_unspec" => Rpc::cryp_unspec(data, &mut tx, account.unwrap(), client),
"game_state" => Rpc::game_state(data, &mut tx, account.unwrap(), client), "game_state" => Rpc::game_state(data, &mut tx, account.unwrap(), client),
"game_pve" => Rpc::game_pve(data, &mut tx, account.unwrap(), client), "game_pve" => Rpc::game_pve(data, &mut tx, account.unwrap(), client),
"game_pvp" => Rpc::game_pvp(data, &mut tx, account.unwrap(), client), "game_pvp" => Rpc::game_pvp(data, &mut tx, account.unwrap(), client),
@ -233,6 +235,23 @@ impl Rpc {
Ok(cryp_list) Ok(cryp_list)
} }
fn cryp_unspec(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<CrypUnspecMsg>(&data).or(Err(err_msg("invalid params")))?;
Rpc::send_msg(client, RpcResponse {
method: "cryp_unspec".to_string(),
params: RpcResult::CrypUnspec(cryp_unspec(msg.params, tx, &account)?)
})?;
let cryp_list = RpcResponse {
method: "account_cryps".to_string(),
params: RpcResult::CrypList(account_cryps(tx, &account)?)
};
Ok(cryp_list)
}
fn account_create(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> { fn account_create(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
match from_slice::<AccountCreateMsg>(&data) { match from_slice::<AccountCreateMsg>(&data) {
@ -398,6 +417,7 @@ pub enum RpcResult {
CrypSpawn(Cryp), CrypSpawn(Cryp),
CrypForget(Cryp), CrypForget(Cryp),
CrypLearn(Cryp), CrypLearn(Cryp),
CrypUnspec(Cryp),
Account(Account), Account(Account),
CrypList(Vec<Cryp>), CrypList(Vec<Cryp>),
GameState(Game), GameState(Game),
@ -449,6 +469,18 @@ struct CrypForgetMsg {
params: CrypForgetParams, params: CrypForgetParams,
} }
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct CrypUnspecParams {
pub id: Uuid,
pub spec: Spec,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct CrypUnspecMsg {
method: String,
params: CrypUnspecParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]
struct GameStateMsg { struct GameStateMsg {
method: String, method: String,

View File

@ -31,7 +31,7 @@ impl Spec {
} }
} }
#[derive(Debug,Copy,Clone,Serialize,Deserialize)] #[derive(Debug,Copy,Clone,Serialize,Deserialize,PartialEq)]
pub enum SpecType { pub enum SpecType {
PhysDamage5, PhysDamage5,
SpellDamage5, SpellDamage5,