From ab0aebc49f285e1f0a71035790e3089eadce25f2 Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 20 Nov 2018 00:36:37 +1000 Subject: [PATCH 1/3] Added back my passives, f to show g to hide --- client/src/scenes/cryp.list.js | 9 +++++---- client/src/scenes/cryp.row.js | 1 - client/src/scenes/cryps.js | 5 ++++- client/src/scenes/menu.js | 4 ++++ client/src/scenes/passives.js | 9 ++++----- 5 files changed, 17 insertions(+), 11 deletions(-) mode change 100644 => 100755 client/src/scenes/cryp.list.js mode change 100644 => 100755 client/src/scenes/cryp.row.js mode change 100644 => 100755 client/src/scenes/cryps.js mode change 100644 => 100755 client/src/scenes/menu.js diff --git a/client/src/scenes/cryp.list.js b/client/src/scenes/cryp.list.js old mode 100644 new mode 100755 index b7aa761c..8950a7db --- a/client/src/scenes/cryp.list.js +++ b/client/src/scenes/cryp.list.js @@ -10,6 +10,7 @@ class CrypList extends Phaser.Scene { create() { this.registry.events.on('changedata', this.updateData, this); this.input.on('gameobjectup', this.clickHandler, this); + this.CrypPage = this.scene.get('CrypPage'); console.log('creating'); return true; } @@ -29,8 +30,8 @@ class CrypList extends Phaser.Scene { renderCryps(cryps) { if (!cryps) return true; - console.log(JSON.stringify(this.children.list)); - console.log(this.children.length); + // console.log(JSON.stringify(this.children.list)); + // console.log(this.children.length); this.redraw(); cryps.forEach((cryp, i) => { @@ -42,8 +43,8 @@ class CrypList extends Phaser.Scene { } clickHandler(pointer, crypBox) { - console.log(crypBox); - this.registry.set('activeCryp', Object.create(crypBox.cryp)); + this.CrypPage.redraw(); + this.CrypPage.renderCryp(crypBox.cryp); } } diff --git a/client/src/scenes/cryp.row.js b/client/src/scenes/cryp.row.js old mode 100644 new mode 100755 index d8e3b77b..360d9887 --- a/client/src/scenes/cryp.row.js +++ b/client/src/scenes/cryp.row.js @@ -12,7 +12,6 @@ const xPos = i => 0; const yPos = i => (i * ROW_HEIGHT + ROW_MARGIN) + TOP_MARGIN; function crypRow(list, cryp, i) { - console.log(i); const X_ORIGIN = xPos(i); const Y_ORIGIN = yPos(i); diff --git a/client/src/scenes/cryps.js b/client/src/scenes/cryps.js old mode 100644 new mode 100755 index 224b50dd..12946e41 --- a/client/src/scenes/cryps.js +++ b/client/src/scenes/cryps.js @@ -3,6 +3,7 @@ const Phaser = require('phaser'); const CrypList = require('./cryp.list'); const CrypPage = require('./cryp.page'); const Menu = require('./menu'); +const Passives = require('./passives'); // const Passives = require('./passives'); function renderCryps(store) { @@ -24,6 +25,7 @@ function renderCryps(store) { Menu, CrypList, CrypPage, + Passives, ], }; @@ -33,7 +35,8 @@ function renderCryps(store) { const state = store.getState(); game.registry.set('cryps', state.cryps); }); - + window.addEventListener('mouseup', () => game.registry.set('pan', false)); + window.addEventListener('mousedown', () => game.registry.set('pan', true)); window.addEventListener('resize', () => game.resize(window.innerWidth, window.innerHeight), false); return game; diff --git a/client/src/scenes/menu.js b/client/src/scenes/menu.js old mode 100644 new mode 100755 index 0012d59e..46b9f020 --- a/client/src/scenes/menu.js +++ b/client/src/scenes/menu.js @@ -6,7 +6,11 @@ class Menu extends Phaser.Scene { } create() { + this.scene.sleep('Passives'); this.add.text(0, 0, 'cryps.gg', { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); + this.input.keyboard.on('keydown_F', () => { + this.scene.wake('Passives'); + }, 0, this); } } diff --git a/client/src/scenes/passives.js b/client/src/scenes/passives.js index 6d4bade1..94fffeb0 100755 --- a/client/src/scenes/passives.js +++ b/client/src/scenes/passives.js @@ -9,7 +9,7 @@ const passiveDataEdge = require('./passive.data.edge'); class PhaserPassives extends Phaser.Scene { constructor() { - super('passives'); + super({ key: 'Passives', active: true }); } preload() { @@ -73,7 +73,7 @@ class PhaserPassives extends Phaser.Scene { }); this.input.on('pointermove', (pointer) => { const zoomFactor = 2 / this.cameras.main.zoom; - if (this.pan) { + if (this.registry.get('pan')) { const points = pointer.getInterpolatedPosition(2); this.cameras.main.scrollX -= zoomFactor * (points[1].x - points[0].x); this.cameras.main.scrollY -= zoomFactor * (points[1].y - points[0].y); @@ -82,8 +82,8 @@ class PhaserPassives extends Phaser.Scene { this.input.keyboard.on('keydown_A', () => { this.updatePassives(); // Will update nodes from state }, 0, this); - this.input.keyboard.on('keydown_S', () => { - this.scene.switch('combat'); + this.input.keyboard.on('keydown_G', () => { + this.scene.sleep('Passives'); }, 0, this); } @@ -98,7 +98,6 @@ class PhaserPassives extends Phaser.Scene { } else { this.graphics.lineStyle(2, 0xffffff, 0.2); } - // console.log(drawEdge); this.graphics.lineBetween(drawEdge[0].x, drawEdge[0].y, drawEdge[1].x, drawEdge[1].y); }); } From 3e4cb096a5b07a3484832fbb6d109003c7764571 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 20 Nov 2018 14:33:40 +1100 Subject: [PATCH 2/3] forget and learn --- client/src/scenes/cryp.list.js | 4 -- client/src/scenes/cryp.page.js | 42 ++++++++++++++----- client/src/scenes/cryp.row.js | 6 ++- client/src/scenes/cryps.js | 3 +- client/src/scenes/menu.js | 4 +- client/src/socket.jsx | 10 +++++ server/src/cryp.rs | 26 ++++++++++-- server/src/rpc.rs | 73 +++++++++++++++++++++++++++++++++- 8 files changed, 147 insertions(+), 21 deletions(-) diff --git a/client/src/scenes/cryp.list.js b/client/src/scenes/cryp.list.js index b7aa761c..6eb901cd 100644 --- a/client/src/scenes/cryp.list.js +++ b/client/src/scenes/cryp.list.js @@ -10,7 +10,6 @@ class CrypList extends Phaser.Scene { create() { this.registry.events.on('changedata', this.updateData, this); this.input.on('gameobjectup', this.clickHandler, this); - console.log('creating'); return true; } @@ -29,8 +28,6 @@ class CrypList extends Phaser.Scene { renderCryps(cryps) { if (!cryps) return true; - console.log(JSON.stringify(this.children.list)); - console.log(this.children.length); this.redraw(); cryps.forEach((cryp, i) => { @@ -42,7 +39,6 @@ class CrypList extends Phaser.Scene { } clickHandler(pointer, crypBox) { - console.log(crypBox); this.registry.set('activeCryp', Object.create(crypBox.cryp)); } } diff --git a/client/src/scenes/cryp.page.js b/client/src/scenes/cryp.page.js index b18443b6..27f78ae0 100644 --- a/client/src/scenes/cryp.page.js +++ b/client/src/scenes/cryp.page.js @@ -1,5 +1,7 @@ const Phaser = require('phaser'); +const { TEXT, SKILLS } = require('./constants'); + const ROW_WIDTH = 400; const ROW_HEIGHT = 200; const ROW_FILL = 0x888888; @@ -11,26 +13,27 @@ const TEXT_MARGIN = 24; const xPos = i => 0; const yPos = i => (i * ROW_HEIGHT + ROW_MARGIN) + TOP_MARGIN; -function crypSkill(scene, skill, i) { - scene.add.text(500, 500 + (TEXT_MARGIN * (i + 1)), skill.skill, { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); - return true; -} - - class CrypPage extends Phaser.Scene { - constructor() { + constructor(args) { super({ key: 'CrypPage', active: true }); } create() { this.registry.events.on('changedata', this.updateData, this); + this.ws = this.registry.get('ws'); return true; } updateData(parent, key, data) { if (key === 'activeCryp') { + console.log(data); this.renderCryp(data); } + + if (key === 'ws') { + this.ws = this.registry.get('ws'); + } + return true; } @@ -44,8 +47,29 @@ class CrypPage extends Phaser.Scene { if (!cryp) return true; this.redraw(); - this.add.text(500, 500, cryp.name, { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); - cryp.skills.forEach((skill, i) => crypSkill(this, skill, i)); + this.add.text(500, 500, cryp.name, TEXT.HEADER); + + const knownSkill = (skill, i) => { + const text = this.add.text(500, 500 + (TEXT_MARGIN * (i + 1)), skill.skill, TEXT.NORMAL) + .setInteractive(); + + text.on('pointerdown', () => { + this.ws.sendCrypForget(cryp.id, skill.skill); + }); + + }; + + const learnable = (skill, i) => { + const text = this.add.text(600, 0 + (TEXT_MARGIN * (i + 1)), skill, TEXT.NORMAL) + .setInteractive(); + + text.on('pointerdown', () => { + this.ws.sendCrypLearn(cryp.id, skill); + }); + }; + + cryp.skills.forEach(knownSkill); + SKILLS.LEARNABLE.forEach(learnable); return true; } diff --git a/client/src/scenes/cryp.row.js b/client/src/scenes/cryp.row.js index d8e3b77b..e35320f2 100644 --- a/client/src/scenes/cryp.row.js +++ b/client/src/scenes/cryp.row.js @@ -1,5 +1,7 @@ const Phaser = require('phaser'); +const { TEXT } = require('./constants'); + const ROW_WIDTH = 400; const ROW_HEIGHT = 200; const ROW_FILL = 0x888888; @@ -21,8 +23,8 @@ function crypRow(list, cryp, i) { .setOrigin(0); row.cryp = cryp; - list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 0), cryp.name, { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); - list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 1), cryp.stamina.base, { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); + list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 0), cryp.name, TEXT.HEADER); + list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 1), cryp.stamina.base, TEXT.NORMAL); return true; } diff --git a/client/src/scenes/cryps.js b/client/src/scenes/cryps.js index 224b50dd..b62173bb 100644 --- a/client/src/scenes/cryps.js +++ b/client/src/scenes/cryps.js @@ -5,7 +5,7 @@ const CrypPage = require('./cryp.page'); const Menu = require('./menu'); // const Passives = require('./passives'); -function renderCryps(store) { +function renderCryps(store, socket) { const config = { type: Phaser.AUTO, // parent: 'cryps', @@ -32,6 +32,7 @@ function renderCryps(store) { store.subscribe(() => { const state = store.getState(); game.registry.set('cryps', state.cryps); + game.registry.set('ws', state.ws); }); window.addEventListener('resize', () => game.resize(window.innerWidth, window.innerHeight), false); diff --git a/client/src/scenes/menu.js b/client/src/scenes/menu.js index 0012d59e..beaf4fc2 100644 --- a/client/src/scenes/menu.js +++ b/client/src/scenes/menu.js @@ -1,12 +1,14 @@ const Phaser = require('phaser'); +const { TEXT } = require('./constants'); + class Menu extends Phaser.Scene { constructor(props) { super({ key: 'Menu', active: true }); } create() { - this.add.text(0, 0, 'cryps.gg', { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); + this.add.text(0, 0, 'cryps.gg', TEXT.HEADER); } } diff --git a/client/src/socket.jsx b/client/src/socket.jsx index 91fe55b3..9ee64e0c 100755 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -116,6 +116,14 @@ function createSocket(store) { send({ method: 'cryp_spawn', params: { name } }); } + function sendCrypLearn(id, skill) { + send({ method: 'cryp_learn', params: { id, skill } }); + } + + function sendCrypForget(id, skill) { + send({ method: 'cryp_forget', params: { id, skill } }); + } + function sendGameState(id) { send({ method: 'game_state', params: { id } }); } @@ -203,6 +211,8 @@ function createSocket(store) { sendGameSkill, sendGameTarget, sendCrypSpawn, + sendCrypLearn, + sendCrypForget, sendItemUse, connect, }; diff --git a/server/src/cryp.rs b/server/src/cryp.rs index 7a782ccf..f14860e0 100755 --- a/server/src/cryp.rs +++ b/server/src/cryp.rs @@ -8,7 +8,7 @@ use failure::Error; use failure::err_msg; use account::Account; -use rpc::{CrypSpawnParams}; +use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams}; use skill::{Skill, Cooldown, Effect, Cast, Source}; use game::{Log}; @@ -129,6 +129,16 @@ impl Cryp { self } + pub fn forget(mut self, skill: Skill) -> Result { + match self.skills.iter().position(|s| s.skill == skill) { + Some(i) => { + self.skills.remove(i); + return Ok(self); + }, + None => Err(format_err!("{:?} does not know {:?}", self.name, skill)), + } + } + pub fn add_xp(mut self) -> Cryp { self.xp = self.xp.saturating_add(1); if self.xp.is_power_of_two() { @@ -326,8 +336,6 @@ pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Accou let cryp = Cryp::new() .named(¶ms.name) .level(10) - .learn(Skill::Stun) - .learn(Skill::Block) .set_account(account.id) .create(); @@ -349,6 +357,18 @@ pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Accou return Ok(cryp); } +pub fn cryp_learn(params: CrypLearnParams, tx: &mut Transaction, account: &Account) -> Result { + let mut cryp = cryp_get(tx, params.id, account.id)?; + cryp = cryp.learn(params.skill); + return cryp_write(cryp, tx); +} + +pub fn cryp_forget(params: CrypForgetParams, tx: &mut Transaction, account: &Account) -> Result { + let mut cryp = cryp_get(tx, params.id, account.id)?; + cryp = cryp.forget(params.skill)?; + return cryp_write(cryp, tx); +} + pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result { let cryp_bytes = to_vec(&cryp)?; diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 2bf60067..b9503126 100755 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -10,7 +10,7 @@ use failure::Error; use failure::err_msg; use net::Db; -use cryp::{Cryp, cryp_spawn}; +use cryp::{Cryp, cryp_spawn, cryp_learn, cryp_forget}; use game::{Game, game_state, game_pve, game_pvp, game_join, game_skill, game_target}; use account::{Account, account_create, account_login, account_from_token, account_cryps}; use item::{Item, items_list, item_use}; @@ -39,6 +39,8 @@ impl Rpc { // match on that to determine what fn to call let response = match v.method.as_ref() { "cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account, client), + "cryp_learn" => Rpc::cryp_learn(data, &mut tx, account, client), + "cryp_forget" => Rpc::cryp_forget(data, &mut tx, account, client), "game_state" => Rpc::game_state(data, &mut tx, account, client), "game_pve" => Rpc::game_pve(data, &mut tx, account, client), "game_pvp" => Rpc::game_pvp(data, &mut tx, account, client), @@ -206,6 +208,49 @@ impl Rpc { Ok(cryp_list) } + fn cryp_learn(data: Vec, tx: &mut Transaction, account: Option, client: &mut WebSocket) -> Result { + let a = match account { + Some(a) => a, + None => return Err(err_msg("auth required")), + }; + + let msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; + + Rpc::send_msg(client, RpcResponse { + method: "cryp_learn".to_string(), + params: RpcResult::CrypLearn(cryp_learn(msg.params, tx, &a)?) + })?; + + let cryp_list = RpcResponse { + method: "account_cryps".to_string(), + params: RpcResult::CrypList(account_cryps(tx, &a)?) + }; + + Ok(cryp_list) + } + + fn cryp_forget(data: Vec, tx: &mut Transaction, account: Option, client: &mut WebSocket) -> Result { + let a = match account { + Some(a) => a, + None => return Err(err_msg("auth required")), + }; + + let msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; + + Rpc::send_msg(client, RpcResponse { + method: "cryp_forget".to_string(), + params: RpcResult::CrypForget(cryp_forget(msg.params, tx, &a)?) + })?; + + let cryp_list = RpcResponse { + method: "account_cryps".to_string(), + params: RpcResult::CrypList(account_cryps(tx, &a)?) + }; + + Ok(cryp_list) + } + + fn account_create(data: Vec, tx: &mut Transaction, _account: Option, _client: &mut WebSocket) -> Result { match from_slice::(&data) { Ok(v) => Ok(RpcResponse { @@ -276,6 +321,8 @@ pub struct RpcResponse { #[derive(Debug,Clone,Serialize,Deserialize)] pub enum RpcResult { CrypSpawn(Cryp), + CrypForget(Cryp), + CrypLearn(Cryp), Account(Account), CrypList(Vec), GameState(Game), @@ -300,6 +347,30 @@ pub struct CrypSpawnParams { pub name: String, } +#[derive(Debug,Clone,Serialize,Deserialize)] +struct CrypLearnMsg { + method: String, + params: CrypLearnParams, +} + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct CrypLearnParams { + pub id: Uuid, + pub skill: Skill, +} + +#[derive(Debug,Clone,Serialize,Deserialize)] +pub struct CrypForgetParams { + pub id: Uuid, + pub skill: Skill, +} + +#[derive(Debug,Clone,Serialize,Deserialize)] +struct CrypForgetMsg { + method: String, + params: CrypForgetParams, +} + #[derive(Debug,Clone,Serialize,Deserialize)] struct GameStateMsg { method: String, From 70eca5580d04c20fa768bb673004fc125c11630e Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 20 Nov 2018 15:36:41 +1100 Subject: [PATCH 3/3] merge --- client/src/scenes/menu.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/src/scenes/menu.js b/client/src/scenes/menu.js index fa84c9b1..be909914 100755 --- a/client/src/scenes/menu.js +++ b/client/src/scenes/menu.js @@ -8,15 +8,12 @@ class Menu extends Phaser.Scene { } create() { -<<<<<<< HEAD this.add.text(0, 0, 'cryps.gg', TEXT.HEADER); -======= + this.scene.sleep('Passives'); - this.add.text(0, 0, 'cryps.gg', { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }); this.input.keyboard.on('keydown_F', () => { this.scene.wake('Passives'); }, 0, this); ->>>>>>> ab0aebc49f285e1f0a71035790e3089eadce25f2 } }