drop -> reclaim
This commit is contained in:
parent
629c5f373e
commit
037da44852
@ -158,12 +158,12 @@ class ItemList extends Phaser.Scene {
|
||||
this.add.text(X + ITEM_WIDTH * 0.5, Y + ITEM_HEIGHT * 23, `Wins: ${player.score.wins}`, TEXT.HEADER);
|
||||
this.add.text(X + ITEM_WIDTH * 0.5, Y + ITEM_HEIGHT * 24, `Losses: ${player.score.losses}`, TEXT.HEADER);
|
||||
|
||||
const reroll = this.add
|
||||
const discard = this.add
|
||||
.rectangle(X + ITEM_WIDTH * 0.4, Y + ITEM_HEIGHT * 1.5, ITEM_WIDTH * 3.4, ITEM_HEIGHT * 1.25, 0x444444)
|
||||
.setInteractive()
|
||||
.setOrigin(0)
|
||||
.on('pointerdown', () => this.registry.get('ws').sendVboxDiscard(vbox.instance));
|
||||
this.add.text(reroll.getCenter().x, reroll.getCenter().y, 'Reroll - $0 cost', TEXT.HEADER)
|
||||
this.add.text(discard.getCenter().x, discard.getCenter().y, 'discard - 5b', TEXT.HEADER)
|
||||
.setOrigin(0.5, 0.5);
|
||||
|
||||
const combine = this.add
|
||||
@ -175,7 +175,7 @@ class ItemList extends Phaser.Scene {
|
||||
this.combinerItems = [-1, -1, -1];
|
||||
this.children.list.filter(obj => obj instanceof CombinerHitBox).forEach(cBox => cBox.deallocate());
|
||||
});
|
||||
this.add.text(combine.getCenter().x, combine.getCenter().y, 'Combine', TEXT.HEADER)
|
||||
this.add.text(combine.getCenter().x, combine.getCenter().y, 'combine', TEXT.HEADER)
|
||||
.setOrigin(0.5, 0.5);
|
||||
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
@ -184,7 +184,7 @@ class ItemList extends Phaser.Scene {
|
||||
this.add.existing(new CombinerHitBox(this, ITEM_X, ITEM_Y, i));
|
||||
}
|
||||
const del = this.add.existing(new DeleteHitBox(this, X + ITEM_WIDTH * 0.4, Y + ITEM_HEIGHT * 15.5));
|
||||
this.add.text(del.getCenter().x, del.getCenter().y, 'Sell', TEXT.HEADER)
|
||||
this.add.text(del.getCenter().x, del.getCenter().y, 'drop', TEXT.HEADER)
|
||||
.setOrigin(0.5, 0.5);
|
||||
|
||||
// Generate Items
|
||||
@ -275,7 +275,7 @@ class ItemList extends Phaser.Scene {
|
||||
if (hitBox.item === item) deallocate(item);
|
||||
else allocate(item, hitBox);
|
||||
} else if (hitBox instanceof DeleteHitBox) {
|
||||
ws.sendVboxDrop(vbox.instance, item.index);
|
||||
ws.sendVboxReclaim(vbox.instance, item.index);
|
||||
} else {
|
||||
ws.sendVboxApply(vbox.instance, hitBox.cryp.id, item.index);
|
||||
deallocate(item);
|
||||
|
||||
@ -109,8 +109,8 @@ function createSocket(events) {
|
||||
send({ method: 'player_vbox_combine', params: { instance_id: instanceId, indices } });
|
||||
}
|
||||
|
||||
function sendVboxDrop(instanceId, index) {
|
||||
send({ method: 'player_vbox_drop', params: { instance_id: instanceId, index } });
|
||||
function sendVboxReclaim(instanceId, index) {
|
||||
send({ method: 'player_vbox_reclaim', params: { instance_id: instanceId, index } });
|
||||
}
|
||||
|
||||
function sendGameSkill(gameId, crypId, targetCrypId, skill) {
|
||||
@ -308,7 +308,7 @@ function createSocket(events) {
|
||||
sendPlayerState,
|
||||
sendVboxAccept,
|
||||
sendVboxApply,
|
||||
sendVboxDrop,
|
||||
sendVboxReclaim,
|
||||
sendVboxCombine,
|
||||
sendVboxDiscard,
|
||||
connect,
|
||||
|
||||
@ -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_drop};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim};
|
||||
|
||||
pub struct Rpc;
|
||||
|
||||
@ -84,7 +84,7 @@ 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_drop" => Rpc::player_vbox_drop(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),
|
||||
|
||||
@ -354,12 +354,12 @@ impl Rpc {
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
fn player_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")))?;
|
||||
fn player_vbox_reclaim(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<VboxReclaimMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let response = RpcResponse {
|
||||
method: "player_state".to_string(),
|
||||
params: RpcResult::PlayerState(vbox_drop(msg.params, tx, &account)?)
|
||||
params: RpcResult::PlayerState(vbox_reclaim(msg.params, tx, &account)?)
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
@ -633,13 +633,13 @@ pub struct VboxApplyParams {
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct VboxDropMsg {
|
||||
struct VboxReclaimMsg {
|
||||
method: String,
|
||||
params: VboxDropParams,
|
||||
params: VboxReclaimParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct VboxDropParams {
|
||||
pub struct VboxReclaimParams {
|
||||
pub instance_id: Uuid,
|
||||
pub index: usize,
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::iter;
|
||||
use uuid::Uuid;
|
||||
|
||||
// drops
|
||||
// reclaims
|
||||
use rand::prelude::*;
|
||||
use rand::{thread_rng};
|
||||
use rand::distributions::{WeightedIndex};
|
||||
@ -12,7 +12,7 @@ use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
use account::Account;
|
||||
use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxDropParams};
|
||||
use rpc::{VboxAcceptParams, VboxDiscardParams, VboxCombineParams, VboxApplyParams, VboxReclaimParams};
|
||||
use skill::{Skill};
|
||||
use spec::{Spec};
|
||||
use player::{Player, player_get, player_update};
|
||||
@ -340,11 +340,11 @@ impl Vbox {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn drop(&mut self, i: usize) -> Result<&mut Vbox, Error> {
|
||||
pub fn reclaim(&mut self, i: usize) -> Result<&mut Vbox, Error> {
|
||||
self.bound.get(i).ok_or(format_err!("no var at index {:?}", i))?;
|
||||
let dropped = self.bound.remove(i);
|
||||
let refund = dropped.cost();
|
||||
println!("refunding {:?} for {:?}", refund, dropped);
|
||||
let reclaimed = self.bound.remove(i);
|
||||
let refund = reclaimed.cost();
|
||||
println!("reclaiming {:?} for {:?}", refund, reclaimed);
|
||||
self.balance_add(refund);
|
||||
Ok(self)
|
||||
}
|
||||
@ -402,9 +402,9 @@ pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &A
|
||||
return player_update(tx, player, false);
|
||||
}
|
||||
|
||||
pub fn vbox_drop(params: VboxDropParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
pub fn vbox_reclaim(params: VboxReclaimParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
player.vbox.drop(params.index)?;
|
||||
player.vbox.reclaim(params.index)?;
|
||||
return player_update(tx, player, false);
|
||||
}
|
||||
|
||||
@ -462,10 +462,10 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drop_test() {
|
||||
fn reclaim_test() {
|
||||
let mut vbox = Vbox::new(Uuid::new_v4(), Uuid::new_v4());
|
||||
vbox.bound = vec![Var::Strike];
|
||||
vbox.drop(0).unwrap();
|
||||
vbox.reclaim(0).unwrap();
|
||||
assert_eq!(vbox.bits, 22);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user