players on join
This commit is contained in:
parent
d5d6254daf
commit
e8fa2aec30
@ -160,7 +160,7 @@ class ItemList extends Phaser.Scene {
|
||||
.rectangle(WIDTH * 0.01, Y + HEIGHT * 0.775, ITEM_WIDTH * 1.25, ITEM_HEIGHT * 1.25, 0x222222)
|
||||
.setInteractive()
|
||||
.setOrigin(0)
|
||||
.on('pointerdown', () => this.registry.get('ws').sendVboxDiscard(vbox.game));
|
||||
.on('pointerdown', () => this.registry.get('ws').sendVboxDiscard(vbox.instance));
|
||||
this.add.text(reroll.getCenter().x, reroll.getCenter().y, 'Reroll', TEXT.HEADER)
|
||||
.setOrigin(0.5, 0.5);
|
||||
|
||||
@ -169,7 +169,7 @@ class ItemList extends Phaser.Scene {
|
||||
.setInteractive()
|
||||
.setOrigin(0)
|
||||
.on('pointerdown', () => {
|
||||
ws.sendVboxCombine(vbox.game, this.combinerItems);
|
||||
ws.sendVboxCombine(vbox.instance, this.combinerItems);
|
||||
this.combinerItems = [-1, -1, -1];
|
||||
this.children.list.filter(obj => obj instanceof CombinerHitBox).forEach(cBox => cBox.deallocate());
|
||||
});
|
||||
@ -201,7 +201,7 @@ class ItemList extends Phaser.Scene {
|
||||
itemBox
|
||||
.setInteractive()
|
||||
.on('pointerdown', () => {
|
||||
ws.sendVboxAccept(vbox.game, i);
|
||||
ws.sendVboxAccept(vbox.instance, i);
|
||||
});
|
||||
this.add.existing(itemBox);
|
||||
});
|
||||
@ -277,8 +277,8 @@ class ItemList extends Phaser.Scene {
|
||||
return true;
|
||||
}
|
||||
// Allocate to cryp hitbox
|
||||
if (hitBox instanceof DeleteHitBox) ws.sendVboxDrop(vbox.game, item.index);
|
||||
else ws.sendVboxApply(vbox.game, hitBox.cryp.id, item.index);
|
||||
if (hitBox instanceof DeleteHitBox) ws.sendVboxDrop(vbox.instance, item.index);
|
||||
else ws.sendVboxApply(vbox.instance, hitBox.cryp.id, item.index);
|
||||
}
|
||||
// If the item hasn't been allocated deallocate the item
|
||||
// Scene will restart if there is vbox change
|
||||
|
||||
@ -38,7 +38,7 @@ class Menu extends Phaser.Scene {
|
||||
|
||||
// When we load the menu request the latest items
|
||||
// Item list will restart when the data comes in
|
||||
this.registry.get('ws').sendVboxState(NULL_UUID);
|
||||
this.registry.get('ws').sendPlayerState(NULL_UUID);
|
||||
|
||||
this.scene.manager.add('MenuCrypList', MenuCrypList, true);
|
||||
this.scene.manager.add('MenuNavigation', MenuNavigation, true);
|
||||
|
||||
@ -85,29 +85,29 @@ function createSocket(events) {
|
||||
send({ method: 'cryp_unspec', params: { id, spec } });
|
||||
}
|
||||
|
||||
function sendVboxState(gameId) {
|
||||
send({ method: 'vbox_state', params: { game_id: gameId } });
|
||||
function sendPlayerState(instanceId) {
|
||||
send({ method: 'player_state', params: { instance_id: instanceId } });
|
||||
}
|
||||
|
||||
function sendVboxAccept(gameId, i) {
|
||||
send({ method: 'vbox_accept', params: { game_id: gameId, index: i } });
|
||||
function sendVboxAccept(instanceId, i) {
|
||||
send({ method: 'player_vbox_accept', params: { instance_id: instanceId, index: i } });
|
||||
}
|
||||
|
||||
function sendVboxApply(gameId, crypId, index) {
|
||||
send({ method: 'vbox_apply', params: { game_id: gameId, cryp_id: crypId, index } });
|
||||
function sendVboxApply(instanceId, crypId, index) {
|
||||
send({ method: 'player_vbox_apply', params: { instance_id: instanceId, cryp_id: crypId, index } });
|
||||
}
|
||||
|
||||
function sendVboxDiscard(gameId) {
|
||||
send({ method: 'vbox_discard', params: { game_id: gameId } });
|
||||
function sendVboxDiscard(instanceId) {
|
||||
send({ method: 'player_vbox_discard', params: { instance_id: instanceId } });
|
||||
}
|
||||
|
||||
function sendVboxCombine(gameId, indices) {
|
||||
send({ method: 'vbox_combine', params: { game_id: gameId, indices } });
|
||||
function sendVboxCombine(instanceId, indices) {
|
||||
send({ method: 'player_vbox_combine', params: { instance_id: instanceId, indices } });
|
||||
}
|
||||
|
||||
|
||||
function sendVboxDrop(gameId, index) {
|
||||
send({ method: 'vbox_drop', params: { game_id: gameId, index } });
|
||||
function sendVboxDrop(instanceId, index) {
|
||||
send({ method: 'player_vbox_drop', params: { instance_id: instanceId, index } });
|
||||
}
|
||||
|
||||
|
||||
@ -185,10 +185,9 @@ function createSocket(events) {
|
||||
events.setZone(zone);
|
||||
}
|
||||
|
||||
function vboxState(response) {
|
||||
const [structName, vbox] = response;
|
||||
console.log(vbox);
|
||||
events.setVbox(vbox);
|
||||
function playerState(response) {
|
||||
const [structName, player] = response;
|
||||
events.setVbox(player.vbox);
|
||||
}
|
||||
|
||||
// -------------
|
||||
@ -210,7 +209,7 @@ function createSocket(events) {
|
||||
zone_create: res => console.log(res),
|
||||
zone_state: zoneState,
|
||||
zone_close: res => console.log(res),
|
||||
vbox_state: vboxState,
|
||||
player_state: playerState,
|
||||
};
|
||||
|
||||
function errHandler(error) {
|
||||
@ -301,7 +300,7 @@ function createSocket(events) {
|
||||
sendZoneCreate,
|
||||
sendZoneJoin,
|
||||
sendZoneClose,
|
||||
sendVboxState,
|
||||
sendPlayerState,
|
||||
sendVboxAccept,
|
||||
sendVboxApply,
|
||||
sendVboxDrop,
|
||||
|
||||
@ -8,7 +8,7 @@ exports.up = async knex => {
|
||||
table.binary('data').notNullable();
|
||||
});
|
||||
|
||||
await knex.schema.createTable('instances', table => {
|
||||
await knex.schema.createTable('instances', async table => {
|
||||
table.uuid('id').primary();
|
||||
table.index('id');
|
||||
table.timestamps();
|
||||
@ -17,16 +17,18 @@ exports.up = async knex => {
|
||||
table.boolean('open')
|
||||
.defaultTo(true)
|
||||
.notNullable();
|
||||
});
|
||||
|
||||
await knex.schema.raw(
|
||||
// eslint-disable-next-line max-len
|
||||
'CREATE UNIQUE INDEX instances_joinable ON instances WHERE open = true;'
|
||||
'CREATE UNIQUE INDEX instances_open ON instances (open) WHERE open = true;'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
await knex.schema.createTable('players', table => {
|
||||
table.uuid('id').primary();
|
||||
table.index('id');
|
||||
table.binary('data').notNullable();
|
||||
|
||||
// the instance
|
||||
table.uuid('instance').notNullable()
|
||||
@ -52,7 +54,7 @@ exports.up = async knex => {
|
||||
await knex('instances').insert({
|
||||
id: NULL_UUID,
|
||||
data: 'INVALID',
|
||||
joinable: false,
|
||||
open: false,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -56,7 +56,7 @@ pub fn player_get(tx: &mut Transaction, account_id: Uuid, instance_id: Uuid) ->
|
||||
|
||||
let returned = match result.iter().next() {
|
||||
Some(row) => row,
|
||||
None => return Err(err_msg("instance not found")),
|
||||
None => return Err(err_msg("player not found")),
|
||||
};
|
||||
|
||||
// tells from_slice to cast into a cryp
|
||||
@ -104,5 +104,5 @@ pub fn player_update(tx: &mut Transaction, player: Player) -> Result<Player, Err
|
||||
}
|
||||
|
||||
pub fn player_state(params: PlayerStateParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
player_get(tx, params.instance_id, account.id)
|
||||
player_get(tx, account.id, params.instance_id)
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ use account::{Account, account_create, account_login, account_from_token, accoun
|
||||
use skill::{Skill};
|
||||
use zone::{Zone, zone_create, zone_join, zone_close};
|
||||
use spec::{Spec};
|
||||
use player::{player_state, Player};
|
||||
use player::{player_state, player_create, Player};
|
||||
use instance::{instance_join};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_drop};
|
||||
|
||||
@ -158,13 +158,16 @@ impl Rpc {
|
||||
}
|
||||
|
||||
fn account_create(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
match from_slice::<AccountCreateMsg>(&data) {
|
||||
Ok(v) => Ok(RpcResponse {
|
||||
method: v.method,
|
||||
params: RpcResult::Account(account_create(v.params, tx)?)
|
||||
}),
|
||||
Err(_e) => Err(err_msg("invalid params")),
|
||||
}
|
||||
let msg = from_slice::<AccountCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
let account = account_create(msg.params, tx)?;
|
||||
let player = Player::new(account.id, Uuid::nil(), vec![]);
|
||||
player_create(tx, &player, &account)?;
|
||||
|
||||
Ok(RpcResponse {
|
||||
method: "account_create".to_string(),
|
||||
params: RpcResult::Account(account)
|
||||
})
|
||||
}
|
||||
|
||||
fn account_login(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
|
||||
@ -277,31 +277,31 @@ impl Vbox {
|
||||
}
|
||||
|
||||
pub fn vbox_discard(params: VboxDiscardParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
let mut player = player_get(tx, params.instance_id, account.id)?;
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
player.vbox.fill();
|
||||
return player_update(tx, player);
|
||||
}
|
||||
|
||||
pub fn vbox_accept(params: VboxAcceptParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
let mut player = player_get(tx, params.instance_id, account.id)?;
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
player.vbox.accept(params.index)?;
|
||||
return player_update(tx, player);
|
||||
}
|
||||
|
||||
pub fn vbox_combine(params: VboxCombineParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
let mut player = player_get(tx, params.instance_id, account.id)?;
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
player.vbox.combine(params.indices)?;
|
||||
return player_update(tx, player);
|
||||
}
|
||||
|
||||
pub fn vbox_drop(params: VboxDropParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
let mut player = player_get(tx, params.instance_id, account.id)?;
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
player.vbox.drop(params.index)?;
|
||||
return player_update(tx, player);
|
||||
}
|
||||
|
||||
pub fn vbox_apply(params: VboxApplyParams, tx: &mut Transaction, account: &Account) -> Result<Player, Error> {
|
||||
let mut player = player_get(tx, params.instance_id, account.id)?;
|
||||
let mut player = player_get(tx, account.id, params.instance_id)?;
|
||||
let mut cryp = cryp_get(tx, params.cryp_id, account.id)?;
|
||||
|
||||
let var = player.vbox.bound.remove(params.index);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user