This commit is contained in:
ntr 2019-03-15 19:31:43 +11:00
parent 5d76593901
commit 9df24a8f07
8 changed files with 65 additions and 103 deletions

View File

@ -55,7 +55,7 @@ class StatSheet extends Phaser.Scene {
this.cryp = cryp;
const del = this.add.existing(new DeleteHitBox(this, X + WIDTH * 0.7, Y + HEIGHT * 0.6));
this.add.text(del.getCenter().x, del.getCenter().y, 'Unlearn', TEXT.HEADER)
this.add.text(del.getCenter().x, del.getCenter().y, 'unequip', TEXT.HEADER)
.setOrigin(0.5, 0.5);
this.add.text(X, Y, cryp.name, TEXT.HEADER);

View File

@ -9,10 +9,7 @@ use postgres::transaction::Transaction;
use rpc::{AccountCreateParams, AccountLoginParams};
use cryp::{Cryp, CrypRecover, cryp_write, cryp_recover};
use game::Game;
// use zone::{Zone, zone_delete};
use skill::{Skill};
use cryp::{Cryp, cryp_recover};
use player::{Player, player_delete};
use failure::Error;
@ -180,61 +177,6 @@ pub fn account_cryps(tx: &mut Transaction, account: &Account) -> Result<Vec<Cryp
return Ok(cryps);
}
pub fn account_game_history(tx: &mut Transaction, account: &Account) -> Result<Vec<Game>, Error> {
let query = "
SELECT games.data
FROM players join games
ON (players.game = games.id)
WHERE account = $1;
";
let result = tx
.query(query, &[&account.id])?;
let games: Result<Vec<Game>, _> = result.iter().map(|row| {
let cryp_bytes: Vec<u8> = row.get(0);
from_slice::<Game>(&cryp_bytes)
}).collect();
// catch any errors
if games.is_err() {
return Err(err_msg("could not deserialize a game"));
}
// now unwrap is safe
return Ok(games.unwrap());
}
// pub fn account_zone(tx: &mut Transaction, account: &Account) -> Result<Zone, Error> {
// let query = "
// SELECT *
// FROM zones
// WHERE account = $1
// AND active = true;
// ";
// let result = tx
// .query(query, &[&account.id])?;
// let returned = match result.iter().next() {
// Some(row) => row,
// None => return Err(err_msg("no active zone")),
// };
// // tells from_slice to cast into a cryp
// let bytes: Vec<u8> = returned.get("data");
// let zone = match from_slice::<Zone>(&bytes) {
// Ok(z) => z,
// Err(_) => {
// zone_delete(tx, returned.get("id"))?;
// return Err(err_msg("invalid zone removed"))
// },
// };
// return Ok(zone);
// }
pub fn account_players(tx: &mut Transaction, account: &Account) -> Result<Vec<Player>, Error> {
let query = "
SELECT data, id

View File

@ -8,7 +8,7 @@ use failure::Error;
use failure::err_msg;
use account::{Account};
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams, CrypUnspecParams};
use rpc::{CrypSpawnParams};
use skill::{Skill, Cooldown, Effect, Cast, Category, Immunity, Disable, ResolutionResult};
use spec::{Spec};
use game::{Log};
@ -185,7 +185,7 @@ impl Cryp {
self
}
pub fn forget(mut self, skill: Skill) -> Result<Cryp, Error> {
pub fn forget(&mut self, skill: Skill) -> Result<&mut Cryp, Error> {
match self.skills.iter().position(|s| s.skill == skill) {
Some(i) => {
self.skills.remove(i);
@ -646,31 +646,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)?;
return cryp_write(cryp, tx);
}
pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> {
let cryp_bytes = to_vec(&cryp)?;

View File

@ -134,10 +134,6 @@ impl Game {
self
}
fn already_joined(&self, team_id: Uuid) -> bool {
self.teams.iter().any(|t| t.id == team_id)
}
pub fn team_add(&mut self, team: Team) -> Result<&mut Game, Error> {
if self.teams.len() == self.team_num {
return Err(err_msg("maximum number of teams"));

View File

@ -11,7 +11,7 @@ use account::Account;
use cryp::{Cryp, cryp_get};
use vbox::{Vbox};
use rpc::{PlayerStateParams, PlayerCrypsSetParams};
use instance::{Instance, instance_get, instance_update};
use instance::{instance_get, instance_update};
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct Score {

View File

@ -23,7 +23,7 @@ use skill::{Skill};
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, vbox_unequip};
pub struct Rpc;
@ -84,9 +84,10 @@ impl Rpc {
"player_cryps_set" => Rpc::player_cryps_set(data, &mut tx, account.unwrap(), client),
"player_vbox_accept" => Rpc::player_vbox_accept(data, &mut tx, account.unwrap(), client),
"player_vbox_apply" => Rpc::player_vbox_apply(data, &mut tx, account.unwrap(), client),
"player_vbox_reclaim" => Rpc::player_vbox_reclaim(data, &mut tx, account.unwrap(), client),
"player_vbox_combine" => Rpc::player_vbox_combine(data, &mut tx, account.unwrap(), client),
"player_vbox_discard" => Rpc::player_vbox_discard(data, &mut tx, account.unwrap(), client),
"player_vbox_reclaim" => Rpc::player_vbox_reclaim(data, &mut tx, account.unwrap(), client),
"player_vbox_unequip" => Rpc::player_vbox_unequip(data, &mut tx, account.unwrap(), client),
_ => Err(format_err!("unknown method - {:?}", v.method)),
};
@ -365,6 +366,23 @@ impl Rpc {
return Ok(response);
}
fn player_vbox_unequip(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<VboxUnequipMsg>(&data).or(Err(err_msg("invalid params")))?;
let response = RpcResponse {
method: "player_state".to_string(),
params: RpcResult::PlayerState(vbox_unequip(msg.params, tx, &account)?)
};
Rpc::send_msg(client, RpcResponse {
method: "account_cryps".to_string(),
params: RpcResult::CrypList(account_cryps(tx, &account)?)
})?;
return Ok(response);
}
}
#[derive(Debug,Clone,Serialize,Deserialize)]
@ -632,6 +650,19 @@ pub struct VboxApplyParams {
pub index: usize,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct VboxUnequipMsg {
method: String,
params: VboxUnequipParams,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct VboxUnequipParams {
pub instance_id: Uuid,
pub cryp_id: Uuid,
pub var: Var,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct VboxReclaimMsg {
method: String,

View File

@ -46,12 +46,6 @@ pub struct Immunity {
pub effects: Vec<Effect>
}
impl Immunity {
fn new() -> Immunity {
Immunity { immune: false, effects: vec![] }
}
}
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct Disable {
pub disabled: bool,
@ -837,7 +831,7 @@ fn siphon_tick(cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -
resolution.results.push(siphon_damage.clone());
match siphon_damage {
ResolutionResult::Damage { amount, mitigation, category: _, immunity } => {
ResolutionResult::Damage { amount, mitigation: _, category: _, immunity } => {
if !immunity.immune {
resolution.results.push(cryp.heal(Skill::Heal, amount));
}
@ -899,7 +893,7 @@ fn banish(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Re
}
fn strike(cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let amount = cryp.red_damage();
let _amount = cryp.red_damage();
resolution.results.push(target.deal_red_damage(Skill::Attack, u64::max_value()));
return resolution;
}

View File

@ -12,7 +12,7 @@ use failure::Error;
use failure::err_msg;
use account::Account;
use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxReclaimParams};
use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxReclaimParams, VboxUnequipParams};
use skill::{Skill};
use spec::{Spec};
use player::{Player, player_get, player_update};
@ -486,6 +486,30 @@ pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Accou
return player_update(tx, player, false);
}
pub fn vbox_unequip(params: VboxUnequipParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
let mut player = player_get(tx, account.id, params.instance_id)?;
if player.vbox.bound.len() >= 9 {
return Err(err_msg("too many vars bound"));
}
match params.var.effect() {
Some(VarEffect::Skill) => {
let skill = params.var.into_skill().ok_or(format_err!("var {:?} has no associated skill", params.var))?;
let cryp = player.cryp_get(params.cryp_id)?;
cryp.forget(skill)?;
},
Some(VarEffect::Spec) => {
let spec = params.var.into_spec().ok_or(format_err!("var {:?} has no associated spec", params.var))?;
let cryp = player.cryp_get(params.cryp_id)?;
cryp.spec_remove(spec)?;
},
None => return Err(err_msg("var has no effect on cryps")),
}
player.vbox.bound.push(params.var);
return player_update(tx, player, false);
}
#[cfg(test)]
mod tests {