pve and pvp back

This commit is contained in:
ntr 2018-11-21 16:32:39 +11:00
parent 4d648c8fe7
commit 41c7c790f2
5 changed files with 52 additions and 49 deletions

View File

@ -17,6 +17,8 @@ class Lobbies extends Phaser.GameObjects.Group {
super(list);
this.keyboard = list.input.keyboard;
const ws = list.registry.get('ws');
const X_POS = ROW_WIDTH + 50;
const pvp = list.add
@ -36,11 +38,13 @@ class Lobbies extends Phaser.GameObjects.Group {
.add(list.add.text(pve.getCenter().x, pve.getCenter().y, 'PVE', TEXT.HEADER));
pvp.on('pointerdown', () => {
console.log(cryps.filter(c => c.active));
const team = cryps.filter(c => c.active).map(c => c.id);
return ws.sendGamePvp(team);
});
pve.on('pointerdown', () => {
console.log(cryps.filter(c => c.active));
const team = cryps.filter(c => c.active).map(c => c.id);
return ws.sendGamePve(team);
});
this.add(pve);

View File

@ -128,8 +128,8 @@ function createSocket(store) {
send({ method: 'game_state', params: { id } });
}
function sendGamePve(id) {
send({ method: 'game_pve', params: { id } });
function sendGamePve(crypIds) {
send({ method: 'game_pve', params: { cryp_ids: crypIds } });
}
function sendGamePvp(crypIds) {

View File

@ -5,7 +5,6 @@
# WORK WORK
* move rpc functions out
* unwrap account for all functions except list
* handle unserializable cryps
@ -16,25 +15,23 @@
* Scrabble grid
* skills
* offensive -> choose target ✔
* handle setting account better maybe?
* ensure cryp untargetable and doesn't resolve when KO
* calculate
* hp increase/decrease
* spell/phys dmg
* private fields for opponents
* cooldowns reduce each turn ✔
* statuses reduce each turn
* teach cyps skills ✔
* attack
* can you attack yourself?
* fetch existing battles
* check for game participation
* write players row for every team+cryp added
* return results<>
* defensive
* Cryp Generation
*
* Items
* rez ✔
* unselect item with esc + button
* Grid reroll
* Colour scheme
@ -43,9 +40,14 @@
* Bosses
* Cryp Generation
*
* rez ✔
* move rpc functions out ✔
* cooldowns reduce each turn ✔
* statuses reduce each turn ✔
* teach cyps skills ✔
* spell/phys dmg ✔
* offensive -> choose target ✔
* ws reconnect ✔
* Levelling ✔
* Logins ✔️
@ -65,6 +67,7 @@
# Art Styles
* Aztec
* youkai
* Pixel
* Industrial

View File

@ -1,6 +1,8 @@
use uuid::Uuid;
use rand::prelude::*;
use std::iter;
// Db Commons
use serde_cbor::{from_slice, to_vec};
use postgres::transaction::Transaction;
@ -581,13 +583,13 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
return Ok(());
}
fn generate_mob(plr: &Cryp) -> Cryp {
fn generate_mob(lvl: u8) -> Cryp {
let mut rng = thread_rng();
// rng panics on min == max
let mob_lvl: u8 = match plr.lvl {
let mob_lvl: u8 = match lvl {
1 => 1,
_ => rng.gen_range(plr.lvl.saturating_sub(2), plr.lvl)
_ => rng.gen_range(lvl.saturating_sub(2), lvl)
};
return Cryp::new()
@ -598,48 +600,38 @@ fn generate_mob(plr: &Cryp) -> Cryp {
}
pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let query = "
SELECT *
FROM cryps
WHERE id = $1
AND account = $2;
";
let cryps = params.cryp_ids
.iter()
.map(|id| cryp_get(tx, *id, account.id))
.collect::<Result<Vec<Cryp>, Error>>()?;
let result = tx
.query(query, &[&params.id, &account.id])?;
let returned = match result.iter().next() {
Some(row) => row,
None => return Err(err_msg("cryp not found")),
};
// tells from_slice to cast into a cryp
let cryp_bytes: Vec<u8> = returned.get("data");
let plr: Cryp = from_slice::<Cryp>(&cryp_bytes)?;
// TEMP
if plr.is_ko() {
return Err(err_msg("cryp is ko"));
// plr.rez();
if cryps.len() > 3 {
return Err(err_msg("team size too large (3 max)"));
}
let mob = generate_mob(&plr);
// create the game
let mut game = Game::new();
let game_id = game.id;
// let game_id = game.id;
game
.set_pve(true)
.set_team_num(2)
.set_team_size(1);
.set_team_size(cryps.len());
// create the mob team
let mut mob_team = Team::new(Uuid::nil());
let mob_lvl = cryps.iter().max_by_key(|c| c.lvl).unwrap().lvl;
let mobs = iter::repeat_with(|| generate_mob(mob_lvl).set_account(Uuid::nil()))
.take(cryps.len())
.collect::<Vec<Cryp>>();
// add the players
let mut plr_team = Team::new(account.id);
plr_team
.set_cryps(vec![plr]);
.set_cryps(cryps);
let mut mob_team = Team::new(Uuid::nil());
mob_team
.set_cryps(vec![mob]);
.set_cryps(mobs);
game
.add_team(plr_team)?
@ -649,7 +641,7 @@ pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account)
// persist
game_new(&game, tx)?;
players_write(&game.team_by_id(account.id), game_id, tx)?;
// players_write(&game.team_by_id(account.id), game_id, tx)?;
Ok(game)
}
@ -691,6 +683,10 @@ pub fn game_join(params: GameJoinParams, tx: &mut Transaction, account: &Account
.map(|id| cryp_get(tx, *id, account.id))
.collect::<Result<Vec<Cryp>, Error>>()?;
if cryps.len() != game.team_size {
return Err(format_err!("incorrect team size. ({:?})", game.team_size));
}
let mut team = Team::new(account.id);
team.set_cryps(cryps);

View File

@ -390,7 +390,7 @@ struct GamePveMsg {
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct GamePveParams {
pub id: Uuid,
pub cryp_ids: Vec<Uuid>,
}
#[derive(Debug,Clone,Serialize,Deserialize)]