remove item from server
This commit is contained in:
parent
d0525a56bd
commit
01468c7081
@ -11,7 +11,6 @@ use account::Account;
|
|||||||
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameJoinParams};
|
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameJoinParams};
|
||||||
use cryp::{Cryp, cryp_get};
|
use cryp::{Cryp, cryp_get};
|
||||||
use skill::{Skill, Cast, ResolutionResult};
|
use skill::{Skill, Cast, ResolutionResult};
|
||||||
use item::{item_drop};
|
|
||||||
use zone::{node_finish};
|
use zone::{node_finish};
|
||||||
use mob::{generate_mob_team};
|
use mob::{generate_mob_team};
|
||||||
|
|
||||||
@ -685,12 +684,6 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
|
|||||||
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
||||||
|
|
||||||
if game.finished() {
|
if game.finished() {
|
||||||
if let Some(t) = game.winner() {
|
|
||||||
if !t.id.is_nil() {
|
|
||||||
item_drop(tx, t.id, game.mode)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for zone update
|
// check for zone update
|
||||||
if let Some((z, i)) = game.zone {
|
if let Some((z, i)) = game.zone {
|
||||||
node_finish(game, z, i, tx)?;
|
node_finish(game, z, i, tx)?;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ mod spec;
|
|||||||
// mod passives;
|
// mod passives;
|
||||||
mod rpc;
|
mod rpc;
|
||||||
mod account;
|
mod account;
|
||||||
mod item;
|
// mod item;
|
||||||
mod zone;
|
mod zone;
|
||||||
mod mob;
|
mod mob;
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,10 @@ use net::Db;
|
|||||||
use cryp::{Cryp, cryp_spawn, cryp_learn, cryp_forget, cryp_unspec};
|
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 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_combine};
|
use vbox::{Vbox, vbox_state, vbox_accept, vbox_discard, vbox_combine};
|
||||||
|
|
||||||
pub struct Rpc;
|
pub struct Rpc;
|
||||||
|
|
||||||
@ -77,16 +76,13 @@ impl Rpc {
|
|||||||
"zone_join" => Rpc::zone_join(data, &mut tx, account.unwrap(), client),
|
"zone_join" => Rpc::zone_join(data, &mut tx, account.unwrap(), client),
|
||||||
"zone_close" => Rpc::zone_close(data, &mut tx, account.unwrap(), client),
|
"zone_close" => Rpc::zone_close(data, &mut tx, account.unwrap(), client),
|
||||||
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
|
"account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client),
|
||||||
"account_items" => Rpc::account_items(data, &mut tx, account.unwrap(), client),
|
|
||||||
"account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
|
"account_zone" => Rpc::account_zone(data, &mut tx, account.unwrap(), client),
|
||||||
"item_use" => Rpc::item_use(data, &mut tx, account.unwrap(), client),
|
|
||||||
|
|
||||||
"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_discard" => Rpc::vbox_accept(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),
|
||||||
|
|
||||||
"press_r" => Rpc::press_r(data, &mut tx, account.unwrap(), client),
|
|
||||||
|
|
||||||
_ => Err(format_err!("unknown method - {:?}", v.method)),
|
_ => Err(format_err!("unknown method - {:?}", v.method)),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -317,13 +313,6 @@ impl Rpc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn account_items(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
|
||||||
Ok(RpcResponse {
|
|
||||||
method: "account_items".to_string(),
|
|
||||||
params: RpcResult::ItemList(items_list(tx, &account)?)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn account_zone(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn account_zone(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
Ok(RpcResponse {
|
Ok(RpcResponse {
|
||||||
method: "zone_state".to_string(),
|
method: "zone_state".to_string(),
|
||||||
@ -331,49 +320,6 @@ impl Rpc {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn press_r(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
|
||||||
for action in [
|
|
||||||
ItemAction::RerollRedDamage,
|
|
||||||
ItemAction::RerollBlueDamage,
|
|
||||||
ItemAction::RerollSpeed,
|
|
||||||
ItemAction::RerollStamina,
|
|
||||||
ItemAction::RerollRedShield,
|
|
||||||
ItemAction::RerollBlueShield,
|
|
||||||
ItemAction::RerollEvasion,
|
|
||||||
ItemAction::SpecRedDamage5,
|
|
||||||
ItemAction::SpecBlueDamage5,
|
|
||||||
].into_iter() {
|
|
||||||
let item = Item::new(*action, account.id);
|
|
||||||
item_create(item, tx, account.id)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = RpcResponse {
|
|
||||||
method: "account_items".to_string(),
|
|
||||||
params: RpcResult::ItemList(items_list(tx, &account)?)
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn item_use(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
|
||||||
let msg = from_slice::<ItemUseMsg>(&data).or(Err(err_msg("invalid params")))?;
|
|
||||||
|
|
||||||
item_use(msg.params, tx, &account)?;
|
|
||||||
|
|
||||||
Rpc::send_msg(client, RpcResponse {
|
|
||||||
method: "account_items".to_string(),
|
|
||||||
params: RpcResult::ItemList(items_list(tx, &account)?)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let cryps_list = RpcResponse {
|
|
||||||
method: "account_cryps".to_string(),
|
|
||||||
params: RpcResult::CrypList(account_cryps(tx, &account)?)
|
|
||||||
};
|
|
||||||
|
|
||||||
return Ok(cryps_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn zone_create(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn zone_create(_data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
// let _msg = from_slice::<ZoneCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
// let _msg = from_slice::<ZoneCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||||
|
|
||||||
@ -419,7 +365,7 @@ impl Rpc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn vbox_accept(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn vbox_accept(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
let msg = from_slice::<VboxBuyMsg>(&data).or(Err(err_msg("invalid params")))?;
|
let msg = from_slice::<VboxAcceptMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||||
|
|
||||||
let response = RpcResponse {
|
let response = RpcResponse {
|
||||||
method: "vbox_state".to_string(),
|
method: "vbox_state".to_string(),
|
||||||
@ -429,6 +375,18 @@ impl Rpc {
|
|||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn vbox_discard(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
|
let msg = from_slice::<VboxDiscardMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||||
|
|
||||||
|
let response = RpcResponse {
|
||||||
|
method: "vbox_state".to_string(),
|
||||||
|
params: RpcResult::VboxState(vbox_discard(msg.params, tx, &account)?)
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn vbox_combine(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn vbox_combine(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
let msg = from_slice::<VboxCombineMsg>(&data).or(Err(err_msg("invalid params")))?;
|
let msg = from_slice::<VboxCombineMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||||
|
|
||||||
@ -458,8 +416,6 @@ pub enum RpcResult {
|
|||||||
CrypList(Vec<Cryp>),
|
CrypList(Vec<Cryp>),
|
||||||
GameState(Game),
|
GameState(Game),
|
||||||
GameJoinableList(Vec<Game>),
|
GameJoinableList(Vec<Game>),
|
||||||
ItemList(Vec<Item>),
|
|
||||||
ItemUse(()),
|
|
||||||
ZoneState(Zone),
|
ZoneState(Zone),
|
||||||
ZoneClose(()),
|
ZoneClose(()),
|
||||||
|
|
||||||
@ -627,24 +583,6 @@ struct AccountCrypsMsg {
|
|||||||
params: (),
|
params: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
|
||||||
struct ItemListMsg {
|
|
||||||
method: String,
|
|
||||||
params: (),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
|
||||||
struct ItemUseMsg {
|
|
||||||
method: String,
|
|
||||||
params: ItemUseParams,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
|
||||||
pub struct ItemUseParams {
|
|
||||||
pub item: Uuid,
|
|
||||||
pub target: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
struct ZoneCreateMsg {
|
struct ZoneCreateMsg {
|
||||||
method: String,
|
method: String,
|
||||||
@ -687,17 +625,28 @@ pub struct VboxStateParams {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
struct VboxBuyMsg {
|
struct VboxAcceptMsg {
|
||||||
method: String,
|
method: String,
|
||||||
params: VboxBuyParams,
|
params: VboxAcceptParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct VboxBuyParams {
|
pub struct VboxAcceptParams {
|
||||||
pub game_id: Uuid,
|
pub game_id: Uuid,
|
||||||
pub index: u8,
|
pub index: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
struct VboxDiscardMsg {
|
||||||
|
method: String,
|
||||||
|
params: VboxDiscardParams,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
pub struct VboxDiscardParams {
|
||||||
|
pub game_id: Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
struct VboxCombineMsg {
|
struct VboxCombineMsg {
|
||||||
method: String,
|
method: String,
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
|
use std::iter;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
// drops
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
use rand::{thread_rng};
|
||||||
|
use rand::distributions::{LogNormal,WeightedIndex};
|
||||||
|
|
||||||
use serde_cbor::{from_slice, to_vec};
|
use serde_cbor::{from_slice, to_vec};
|
||||||
|
|
||||||
use postgres::transaction::Transaction;
|
use postgres::transaction::Transaction;
|
||||||
@ -8,15 +14,21 @@ use failure::Error;
|
|||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use account::Account;
|
use account::Account;
|
||||||
use rpc::{VboxStateParams, VboxBuyParams, VboxCombineParams};
|
use rpc::{VboxStateParams, VboxAcceptParams, VboxDiscardParams, VboxCombineParams};
|
||||||
use item::{Item};
|
|
||||||
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
|
pub enum Var {
|
||||||
|
Red,
|
||||||
|
Green,
|
||||||
|
Blue,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Vbox {
|
pub struct Vbox {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub balance: u16,
|
pub balance: u16,
|
||||||
pub free: Vec<Item>,
|
pub free: Vec<Var>,
|
||||||
pub bound: Vec<Item>,
|
pub bound: Vec<Var>,
|
||||||
pub game: Uuid,
|
pub game: Uuid,
|
||||||
pub account: Uuid,
|
pub account: Uuid,
|
||||||
}
|
}
|
||||||
@ -32,6 +44,25 @@ impl Vbox {
|
|||||||
balance: 0,
|
balance: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fill(mut self: Vbox) -> Vbox {
|
||||||
|
let vars = vec![
|
||||||
|
(Var::Red, 1),
|
||||||
|
(Var::Green, 1),
|
||||||
|
(Var::Blue, 1),
|
||||||
|
];
|
||||||
|
|
||||||
|
self.free = iter::
|
||||||
|
repeat_with(|| {
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
let dist = WeightedIndex::new(vars.iter().map(|item| item.1)).unwrap();
|
||||||
|
return vars[dist.sample(&mut rng)].0;
|
||||||
|
})
|
||||||
|
.take(8)
|
||||||
|
.collect::<Vec<Var>>();
|
||||||
|
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_write(vbox: Vbox, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
pub fn vbox_write(vbox: Vbox, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||||
@ -81,37 +112,21 @@ pub fn vbox_state(params: VboxStateParams, tx: &mut Transaction, account: &Accou
|
|||||||
Ok(v) => Ok(v),
|
Ok(v) => Ok(v),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{:?}", e);
|
println!("{:?}", e);
|
||||||
vbox_write(Vbox::new(account.id, params.game_id), tx, account)
|
vbox_write(Vbox::new(account.id, params.game_id).fill(), tx, account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_accept(params: VboxBuyParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
pub fn vbox_discard(params: VboxDiscardParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||||
return vbox_get(tx, params.game_id, account)
|
let vbox = vbox_get(tx, params.game_id, account)?;
|
||||||
|
return vbox_write(vbox.fill(), tx, account);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn vbox_accept(params: VboxAcceptParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||||
|
let vbox = vbox_get(tx, params.game_id, account)?;
|
||||||
|
return Ok(vbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &Account) -> Result<Vbox, Error> {
|
||||||
return vbox_get(tx, params.game_id, account)
|
return vbox_get(tx, params.game_id, account)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// pub fn item_drop(tx: &mut Transaction, account_id: Uuid, mode: GameMode) -> Result<(), Error> {
|
|
||||||
// let mut rng = thread_rng();
|
|
||||||
|
|
||||||
// let log_normal = LogNormal::new(1.0, 1.0);
|
|
||||||
// let num_drops = log_normal.sample(&mut rng).floor() as u16;
|
|
||||||
|
|
||||||
// let actions = mode_drops(mode);
|
|
||||||
// println!("{:?} drops", num_drops);
|
|
||||||
|
|
||||||
// for _i in 0..num_drops {
|
|
||||||
// let dist = WeightedIndex::new(actions.iter().map(|item| item.1)).unwrap();
|
|
||||||
// let kind = actions[dist.sample(&mut rng)].0;
|
|
||||||
// let item = Item::new(kind, account_id);
|
|
||||||
|
|
||||||
// println!("{:?} dropped {:?}", account_id, item);
|
|
||||||
// item_create(item, tx, account_id)?;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Ok(())
|
|
||||||
// }
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user