scores
This commit is contained in:
parent
cd26efb42d
commit
4b848f1e02
@ -41,6 +41,10 @@ function registerEvents(registry, events, tutorial) {
|
|||||||
registry.set('vbox', items);
|
registry.set('vbox', items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setScores(scores) {
|
||||||
|
registry.set('scores', scores);
|
||||||
|
}
|
||||||
|
|
||||||
function setPlayerList(list) {
|
function setPlayerList(list) {
|
||||||
registry.set('playerList', list);
|
registry.set('playerList', list);
|
||||||
registry.set('homeInstances', true);
|
registry.set('homeInstances', true);
|
||||||
@ -208,6 +212,7 @@ function registerEvents(registry, events, tutorial) {
|
|||||||
setWs,
|
setWs,
|
||||||
setGameList,
|
setGameList,
|
||||||
setZone,
|
setZone,
|
||||||
|
setScores,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@ class HomeRankings extends Phaser.Scene {
|
|||||||
this.registry.get('ws').sendInstanceReady(player.instance);
|
this.registry.get('ws').sendInstanceReady(player.instance);
|
||||||
} else {
|
} else {
|
||||||
this.game.events.emit('SET_PLAYER', player);
|
this.game.events.emit('SET_PLAYER', player);
|
||||||
|
this.registry.get('ws').sendInstanceScores(player.instance);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const name = player.instance === NULL_UUID ? 'Normal Mode' : `${player.instance.substring(0, 5)}`;
|
const name = player.instance === NULL_UUID ? 'Normal Mode' : `${player.instance.substring(0, 5)}`;
|
||||||
|
|||||||
@ -131,7 +131,7 @@ class ItemList extends Phaser.Scene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateData(parent, key, data) {
|
updateData(parent, key, data) {
|
||||||
if (key === 'player') {
|
if (key === 'player' || key === 'scores') {
|
||||||
this.registry.events.off('changedata', this.updateData, this);
|
this.registry.events.off('changedata', this.updateData, this);
|
||||||
this.registry.events.off('setdata', this.updateData, this);
|
this.registry.events.off('setdata', this.updateData, this);
|
||||||
this.scene.restart();
|
this.scene.restart();
|
||||||
@ -140,6 +140,7 @@ class ItemList extends Phaser.Scene {
|
|||||||
|
|
||||||
create() {
|
create() {
|
||||||
const player = this.registry.get('player');
|
const player = this.registry.get('player');
|
||||||
|
const scores = this.registry.get('scores') || [];
|
||||||
if (!player) return false;
|
if (!player) return false;
|
||||||
const { vbox } = player;
|
const { vbox } = player;
|
||||||
this.registry.events.on('changedata', this.updateData, this);
|
this.registry.events.on('changedata', this.updateData, this);
|
||||||
@ -256,6 +257,14 @@ class ItemList extends Phaser.Scene {
|
|||||||
} return false;
|
} return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.add.text(ITEM_WIDTH * 11, ITEM_HEIGHT * 1.1, `Scoreboard`, TEXT.HEADER);
|
||||||
|
scores.forEach(([name, score], i) => {
|
||||||
|
console.log(name);
|
||||||
|
const SCORE_X = ITEM_WIDTH * 11;
|
||||||
|
const SCORE_Y = ITEM_HEIGHT * 1.1 * (i + 2);
|
||||||
|
this.add.text(SCORE_X, SCORE_Y, `${name} | ${score.wins} - ${score.losses}`, TEXT.NORMAL);
|
||||||
|
});
|
||||||
|
|
||||||
// Add Handlers
|
// Add Handlers
|
||||||
this.input.on('dragstart', (pointer, item) => {
|
this.input.on('dragstart', (pointer, item) => {
|
||||||
if (!(item instanceof Item)) return false;
|
if (!(item instanceof Item)) return false;
|
||||||
|
|||||||
@ -152,6 +152,11 @@ function createSocket(events) {
|
|||||||
send({ method: 'instance_ready', params: { instance_id: instanceId } });
|
send({ method: 'instance_ready', params: { instance_id: instanceId } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendInstanceScores(instanceId) {
|
||||||
|
send({ method: 'instance_scores', params: { instance_id: instanceId } });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------
|
// -------------
|
||||||
// Incoming
|
// Incoming
|
||||||
// -------------
|
// -------------
|
||||||
@ -196,6 +201,11 @@ function createSocket(events) {
|
|||||||
events.setPlayer(player);
|
events.setPlayer(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function instanceScores(response) {
|
||||||
|
const [structName, scores] = response;
|
||||||
|
events.setScores(scores);
|
||||||
|
}
|
||||||
|
|
||||||
// -------------
|
// -------------
|
||||||
// Setup
|
// Setup
|
||||||
// -------------
|
// -------------
|
||||||
@ -212,6 +222,7 @@ function createSocket(events) {
|
|||||||
account_create: accountLogin,
|
account_create: accountLogin,
|
||||||
account_cryps: accountCryps,
|
account_cryps: accountCryps,
|
||||||
account_players: accountPlayerList,
|
account_players: accountPlayerList,
|
||||||
|
instance_scores: instanceScores,
|
||||||
zone_create: res => console.log(res),
|
zone_create: res => console.log(res),
|
||||||
zone_state: zoneState,
|
zone_state: zoneState,
|
||||||
zone_close: res => console.log(res),
|
zone_close: res => console.log(res),
|
||||||
@ -308,6 +319,7 @@ function createSocket(events) {
|
|||||||
sendZoneClose,
|
sendZoneClose,
|
||||||
sendInstanceJoin,
|
sendInstanceJoin,
|
||||||
sendInstanceReady,
|
sendInstanceReady,
|
||||||
|
sendInstanceScores,
|
||||||
sendPlayerCrypsSet,
|
sendPlayerCrypsSet,
|
||||||
sendPlayerState,
|
sendPlayerState,
|
||||||
sendVboxAccept,
|
sendVboxAccept,
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use std::iter;
|
|||||||
|
|
||||||
use rpc::{InstanceJoinParams, InstanceReadyParams};
|
use rpc::{InstanceJoinParams, InstanceReadyParams};
|
||||||
use account::Account;
|
use account::Account;
|
||||||
use player::{Player, player_create, player_get, player_update};
|
use player::{Player, Score, player_create, player_get, player_update};
|
||||||
use cryp::{Cryp, cryp_get};
|
use cryp::{Cryp, cryp_get};
|
||||||
use mob::{instance_mobs};
|
use mob::{instance_mobs};
|
||||||
use game::{Game, Team, game_get, game_write, game_instance_new, game_instance_join, game_global_get, game_global_set};
|
use game::{Game, Team, game_get, game_write, game_instance_new, game_instance_join, game_global_get, game_global_set};
|
||||||
@ -307,6 +307,16 @@ impl Instance {
|
|||||||
|
|
||||||
current_round
|
current_round
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn scores(&self) -> Vec<(String, Score)> {
|
||||||
|
let mut scores = self.players.iter()
|
||||||
|
.map(|p| (p.name.clone(), p.score))
|
||||||
|
.collect::<Vec<(String, Score)>>();
|
||||||
|
scores.sort_unstable_by_key(|s| s.1.wins);
|
||||||
|
scores.reverse();
|
||||||
|
|
||||||
|
scores
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance_create(tx: &mut Transaction, instance: Instance) -> Result<Instance, Error> {
|
pub fn instance_create(tx: &mut Transaction, instance: Instance) -> Result<Instance, Error> {
|
||||||
@ -445,8 +455,9 @@ pub fn instance_ready_global(tx: &mut Transaction, _account: &Account, player: P
|
|||||||
Ok(game)
|
Ok(game)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance_score(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Instance, Error> {
|
pub fn instance_scores(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Vec<(String, Score)>, Error> {
|
||||||
instance_get(tx, params.instance_id)
|
let scores = instance_get(tx, params.instance_id)?.scores();
|
||||||
|
Ok(scores)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
||||||
|
|||||||
@ -13,10 +13,10 @@ use vbox::{Vbox};
|
|||||||
use rpc::{PlayerStateParams, PlayerCrypsSetParams};
|
use rpc::{PlayerStateParams, PlayerCrypsSetParams};
|
||||||
use instance::{instance_get, instance_update};
|
use instance::{instance_get, instance_update};
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,Serialize,Deserialize)]
|
||||||
pub struct Score {
|
pub struct Score {
|
||||||
wins: u8,
|
pub wins: u8,
|
||||||
losses: u8,
|
pub losses: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
|||||||
@ -21,8 +21,8 @@ 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 player::{player_state, player_cryps_set, Player};
|
use player::{Score, player_state, player_cryps_set, Player};
|
||||||
use instance::{Instance, instance_join, instance_ready, instance_score};
|
use instance::{instance_join, instance_ready, instance_scores};
|
||||||
use vbox::{Var, vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
use vbox::{Var, vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||||
|
|
||||||
pub struct Rpc;
|
pub struct Rpc;
|
||||||
@ -79,7 +79,7 @@ impl Rpc {
|
|||||||
|
|
||||||
"instance_join" => Rpc::instance_join(data, &mut tx, account.unwrap(), client),
|
"instance_join" => Rpc::instance_join(data, &mut tx, account.unwrap(), client),
|
||||||
"instance_ready" => Rpc::instance_ready(data, &mut tx, account.unwrap(), client),
|
"instance_ready" => Rpc::instance_ready(data, &mut tx, account.unwrap(), client),
|
||||||
"instance_score" => Rpc::instance_score(data, &mut tx, account.unwrap(), client),
|
"instance_scores" => Rpc::instance_scores(data, &mut tx, account.unwrap(), client),
|
||||||
|
|
||||||
"player_state" => Rpc::player_state(data, &mut tx, account.unwrap(), client),
|
"player_state" => Rpc::player_state(data, &mut tx, account.unwrap(), client),
|
||||||
"player_cryps_set" => Rpc::player_cryps_set(data, &mut tx, account.unwrap(), client),
|
"player_cryps_set" => Rpc::player_cryps_set(data, &mut tx, account.unwrap(), client),
|
||||||
@ -283,12 +283,12 @@ impl Rpc {
|
|||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn instance_score(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn instance_scores(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
let msg = from_slice::<InstanceReadyMsg>(&data).or(Err(err_msg("invalid params")))?;
|
let msg = from_slice::<InstanceReadyMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||||
|
|
||||||
let response = RpcResponse {
|
let response = RpcResponse {
|
||||||
method: "instance_score".to_string(),
|
method: "instance_scores".to_string(),
|
||||||
params: RpcResult::InstanceScore(instance_score(msg.params, tx, &account)?)
|
params: RpcResult::InstanceScores(instance_scores(msg.params, tx, &account)?)
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
@ -413,7 +413,7 @@ pub enum RpcResult {
|
|||||||
Account(Account),
|
Account(Account),
|
||||||
CrypList(Vec<Cryp>),
|
CrypList(Vec<Cryp>),
|
||||||
GameState(Game),
|
GameState(Game),
|
||||||
InstanceScore(Instance),
|
InstanceScores(Vec<(String, Score)>),
|
||||||
// ZoneState(Zone),
|
// ZoneState(Zone),
|
||||||
// ZoneClose(()),
|
// ZoneClose(()),
|
||||||
|
|
||||||
|
|||||||
@ -63,17 +63,19 @@ impl Spec {
|
|||||||
if team_colours.red >= 20 { pct += 20 };
|
if team_colours.red >= 20 { pct += 20 };
|
||||||
base.pct(pct)
|
base.pct(pct)
|
||||||
},
|
},
|
||||||
Spec::GreenDamageI => modified + match team_colours.green {
|
Spec::GreenDamageI => modified + {
|
||||||
0...5 => base.pct(5),
|
let mut pct = 5;
|
||||||
6...10 => base.pct(10),
|
if team_colours.green >= 5 { pct += 5 };
|
||||||
11...15 => base.pct(15),
|
if team_colours.green >= 10 { pct += 10 };
|
||||||
_ => base.pct(20)
|
if team_colours.green >= 20 { pct += 20 };
|
||||||
|
base.pct(pct)
|
||||||
},
|
},
|
||||||
Spec::BlueDamageI => modified + match team_colours.blue {
|
Spec::BlueDamageI => modified + {
|
||||||
0...5 => base.pct(5),
|
let mut pct = 5;
|
||||||
6...10 => base.pct(10),
|
if team_colours.blue >= 5 { pct += 10 };
|
||||||
11...15 => base.pct(15),
|
if team_colours.blue >= 10 { pct += 20 };
|
||||||
_ => base.pct(20)
|
if team_colours.blue >= 20 { pct += 30 };
|
||||||
|
base.pct(pct)
|
||||||
},
|
},
|
||||||
|
|
||||||
Spec::SpeedI => modified + base.pct(5),
|
Spec::SpeedI => modified + base.pct(5),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user