drop and apply
This commit is contained in:
parent
1beb53ec51
commit
53a54c2123
@ -21,7 +21,7 @@ use account::{Account, account_create, account_login, account_from_token, accoun
|
|||||||
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};
|
use spec::{Spec};
|
||||||
use vbox::{Vbox, vbox_state, vbox_accept, vbox_apply, vbox_discard, vbox_combine};
|
use vbox::{Vbox, vbox_state, vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_drop};
|
||||||
|
|
||||||
pub struct Rpc;
|
pub struct Rpc;
|
||||||
|
|
||||||
@ -80,7 +80,8 @@ impl Rpc {
|
|||||||
|
|
||||||
"vbox_state" => Rpc::vbox_state(data, &mut tx, account.unwrap(), client),
|
"vbox_state" => Rpc::vbox_state(data, &mut tx, account.unwrap(), client),
|
||||||
"vbox_accept" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
|
"vbox_accept" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
|
||||||
"vbox_apply" => Rpc::vbox_accept(data, &mut tx, account.unwrap(), client),
|
"vbox_apply" => Rpc::vbox_apply(data, &mut tx, account.unwrap(), client),
|
||||||
|
"vbox_drop" => Rpc::vbox_drop(data, &mut tx, account.unwrap(), client),
|
||||||
"vbox_combine" => Rpc::vbox_combine(data, &mut tx, account.unwrap(), client),
|
"vbox_combine" => Rpc::vbox_combine(data, &mut tx, account.unwrap(), client),
|
||||||
"vbox_discard" => Rpc::vbox_discard(data, &mut tx, account.unwrap(), client),
|
"vbox_discard" => Rpc::vbox_discard(data, &mut tx, account.unwrap(), client),
|
||||||
|
|
||||||
@ -415,7 +416,16 @@ impl Rpc {
|
|||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn vbox_drop(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
|
let msg = from_slice::<VboxDropMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||||
|
|
||||||
|
let response = RpcResponse {
|
||||||
|
method: "vbox_state".to_string(),
|
||||||
|
params: RpcResult::VboxState(vbox_drop(msg.params, tx, &account)?)
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
@ -690,6 +700,18 @@ pub struct VboxApplyParams {
|
|||||||
pub index: usize,
|
pub index: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
struct VboxDropMsg {
|
||||||
|
method: String,
|
||||||
|
params: VboxDropParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
pub struct VboxDropParams {
|
||||||
|
pub game_id: Uuid,
|
||||||
|
pub index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
// #[cfg(test)]
|
// #[cfg(test)]
|
||||||
// mod tests {
|
// mod tests {
|
||||||
// use super::*;
|
// use super::*;
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use failure::Error;
|
|||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use account::Account;
|
use account::Account;
|
||||||
use rpc::{VboxStateParams, VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams};
|
use rpc::{VboxStateParams, VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxDropParams};
|
||||||
use skill::{Skill};
|
use skill::{Skill};
|
||||||
use cryp::{cryp_get, cryp_write};
|
use cryp::{cryp_get, cryp_write};
|
||||||
|
|
||||||
@ -51,17 +51,17 @@ impl Var {
|
|||||||
|
|
||||||
fn skill(&self) -> Result<Skill, Error> {
|
fn skill(&self) -> Result<Skill, Error> {
|
||||||
match self {
|
match self {
|
||||||
Attack => Ok(Skill::Attack),
|
Var::Attack => Ok(Skill::Attack),
|
||||||
Block => Ok(Skill::Attack),
|
Var::Block => Ok(Skill::Attack),
|
||||||
Stun => Ok(Skill::Attack),
|
Var::Stun => Ok(Skill::Attack),
|
||||||
Buff => Ok(Skill::Attack),
|
Var::Buff => Ok(Skill::Attack),
|
||||||
Debuff => Ok(Skill::Attack),
|
Var::Debuff => Ok(Skill::Attack),
|
||||||
|
|
||||||
Strike => Ok(Skill::Attack),
|
Var::Strike => Ok(Skill::Attack),
|
||||||
Blast => Ok(Skill::Blast),
|
Var::Blast => Ok(Skill::Blast),
|
||||||
Heal => Ok(Skill::Heal),
|
Var::Heal => Ok(Skill::Heal),
|
||||||
Throw => Ok(Skill::Throw),
|
Var::Throw => Ok(Skill::Throw),
|
||||||
Hex => Ok(Skill::Hex),
|
Var::Hex => Ok(Skill::Hex),
|
||||||
_ => Err(err_msg("not a usable var"))
|
_ => Err(err_msg("not a usable var"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,6 +128,13 @@ impl Vbox {
|
|||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn drop(&mut self, i: usize) -> Result<&mut Vbox, Error> {
|
||||||
|
self.free.get(i).ok_or(format_err!("no var at index {:?}", i))?;
|
||||||
|
self.free.remove(i);
|
||||||
|
// balance update
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn combine(&mut self, mut indices: Vec<usize>) -> Result<&mut Vbox, Error> {
|
pub fn combine(&mut self, mut indices: Vec<usize>) -> Result<&mut Vbox, Error> {
|
||||||
if indices.len() != 3 {
|
if indices.len() != 3 {
|
||||||
return Err(err_msg("exactly 3 indices required"));
|
return Err(err_msg("exactly 3 indices required"));
|
||||||
@ -323,6 +330,12 @@ pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &A
|
|||||||
return vbox_write(vbox, tx);
|
return vbox_write(vbox, tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn vbox_drop(params: VboxDropParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||||
|
let mut vbox = vbox_get(tx, params.game_id, account)?;
|
||||||
|
vbox.drop(params.index)?;
|
||||||
|
return vbox_write(vbox, tx);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||||
let mut vbox = vbox_get(tx, params.game_id, account)?;
|
let mut vbox = vbox_get(tx, params.game_id, account)?;
|
||||||
let mut cryp = cryp_get(tx, params.cryp_id, account.id)?;
|
let mut cryp = cryp_get(tx, params.cryp_id, account.id)?;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user