Merge and refactor
This commit is contained in:
commit
6c04a03145
82
client/src/scenes/constants.js
Normal file
82
client/src/scenes/constants.js
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
module.exports = {
|
||||||
|
TEXT: {
|
||||||
|
NORMAL: { fontFamily: 'monospace', fontSize: 16, color: '#ffffff' },
|
||||||
|
HEADER: { fontFamily: 'monospace', fontSize: 24, color: '#ffffff', fontStyle: 'bold' },
|
||||||
|
},
|
||||||
|
|
||||||
|
SKILLS: {
|
||||||
|
LEARNABLE: [
|
||||||
|
'Attack',
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// Nature
|
||||||
|
// -----------------
|
||||||
|
'Block', // reduce dmg
|
||||||
|
'Parry', // avoid all dmg
|
||||||
|
'Snare',
|
||||||
|
|
||||||
|
// 'Paralyse',
|
||||||
|
|
||||||
|
'Strangle', // physical dot and disable
|
||||||
|
|
||||||
|
'Stun',
|
||||||
|
'Evade', // actively evade
|
||||||
|
'Evasion', // adds evasion to cryp
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// Technology
|
||||||
|
// -----------------
|
||||||
|
// 'Replicate',
|
||||||
|
// 'Swarm',
|
||||||
|
// 'Orbit',
|
||||||
|
// 'Repair',
|
||||||
|
// 'Scan', // track?
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// Nonviolence
|
||||||
|
// -----------------
|
||||||
|
'Heal',
|
||||||
|
'Triage', // hot
|
||||||
|
// 'TriageTick',
|
||||||
|
'Throw', // no dmg stun', adds vulnerable
|
||||||
|
'Charm',
|
||||||
|
'Calm',
|
||||||
|
'Rez',
|
||||||
|
|
||||||
|
// -------------------
|
||||||
|
// Destruction
|
||||||
|
// -------------------
|
||||||
|
'Blast',
|
||||||
|
'Amplify',
|
||||||
|
'Decay', // dot
|
||||||
|
// 'DecayTick', // dot
|
||||||
|
'Drain',
|
||||||
|
// 'DrainTick',
|
||||||
|
'Curse',
|
||||||
|
'Plague', // aoe dot
|
||||||
|
'Ruin', // aoe
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// Purity
|
||||||
|
// -----------------
|
||||||
|
'Empower',
|
||||||
|
'Slay',
|
||||||
|
'Shield',
|
||||||
|
'Silence',
|
||||||
|
'Inquiry',
|
||||||
|
'Purify',
|
||||||
|
'Purge',
|
||||||
|
// '// Precision',
|
||||||
|
|
||||||
|
// -----------------
|
||||||
|
// Chaos
|
||||||
|
// -----------------
|
||||||
|
'Banish',
|
||||||
|
'Hex',
|
||||||
|
'Fear',
|
||||||
|
'Taunt',
|
||||||
|
'Pause', // speed slow
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
@ -11,29 +11,32 @@ class CrypList extends Phaser.Scene {
|
|||||||
create() {
|
create() {
|
||||||
this.registry.events.on('changedata', this.updateData, this);
|
this.registry.events.on('changedata', this.updateData, this);
|
||||||
this.input.on('gameobjectup', this.clickHandler, this);
|
this.input.on('gameobjectup', this.clickHandler, this);
|
||||||
this.CrypPage = null;
|
|
||||||
console.log('creating');
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateData(parent, key, data) {
|
updateData(parent, key, data) {
|
||||||
if (key === 'cryps') {
|
if (key === 'cryps') {
|
||||||
this.clearCryps();
|
if (this.CrypRow) this.CrypRow.destroy(true);
|
||||||
this.CrypRow = new CrypRow(this, data);
|
this.CrypRow = new CrypRow(this, data);
|
||||||
|
if (this.CrypPage) {
|
||||||
|
const cryp = data.find(c => c.id === this.CrypPage.id);
|
||||||
|
this.displaySkills(cryp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.redraw = this.clearCryps.bind(this);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearCryps() {
|
displaySkills(cryp) {
|
||||||
if (this.CrypRow) this.CrypRow.destroy(true);
|
if (cryp) {
|
||||||
}
|
|
||||||
|
|
||||||
clickHandler(pointer, crypBox) {
|
|
||||||
if (this.CrypPage) {
|
if (this.CrypPage) {
|
||||||
this.CrypPage.destroy(true);
|
this.CrypPage.destroy(true);
|
||||||
}
|
}
|
||||||
this.CrypPage = new CrypPage(this, crypBox.cryp);
|
this.CrypPage = new CrypPage(this, cryp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clickHandler(pointer, crypBox) {
|
||||||
|
this.displaySkills(crypBox.cryp);
|
||||||
return true;
|
return true;
|
||||||
// this.registry.get('ws').sendGamePve(crypBox.cryp.id);
|
// this.registry.get('ws').sendGamePve(crypBox.cryp.id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
|
|
||||||
|
const { TEXT, SKILLS } = require('./constants');
|
||||||
|
|
||||||
const ROW_WIDTH = 400;
|
const ROW_WIDTH = 400;
|
||||||
const ROW_HEIGHT = 200;
|
const ROW_HEIGHT = 200;
|
||||||
const ROW_FILL = 0x888888;
|
const ROW_FILL = 0x888888;
|
||||||
@ -14,14 +16,34 @@ const yPos = i => (i * ROW_HEIGHT + ROW_MARGIN) + TOP_MARGIN;
|
|||||||
class CrypPage extends Phaser.GameObjects.Group {
|
class CrypPage extends Phaser.GameObjects.Group {
|
||||||
constructor(scene, cryp) {
|
constructor(scene, cryp) {
|
||||||
super(scene);
|
super(scene);
|
||||||
this.add(scene.add.text(500, 500, cryp.name, {
|
this.id = cryp.id;
|
||||||
fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold',
|
this.scene = scene;
|
||||||
}));
|
this.ws = scene.registry.get('ws');
|
||||||
cryp.skills.forEach((skill, i) => this.add(
|
this.add(scene.add.text(500, 500, cryp.name, TEXT.HEADER));
|
||||||
scene.add.text(500, 500 + (TEXT_MARGIN * (i + 1)), skill.skill, {
|
|
||||||
fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold',
|
const knownSkill = (skill, i) => {
|
||||||
})
|
const text = scene.add.text(500, 500 + (TEXT_MARGIN * (i + 1)), skill.skill, TEXT.NORMAL)
|
||||||
));
|
.setInteractive();
|
||||||
|
|
||||||
|
text.on('pointerdown', () => {
|
||||||
|
this.ws.sendCrypForget(cryp.id, skill.skill);
|
||||||
|
});
|
||||||
|
this.add(text);
|
||||||
|
};
|
||||||
|
|
||||||
|
const learnable = (skill, i) => {
|
||||||
|
const text = scene.add.text(600, 0 + (TEXT_MARGIN * (i + 1)), skill, TEXT.NORMAL)
|
||||||
|
.setInteractive();
|
||||||
|
|
||||||
|
text.on('pointerdown', () => {
|
||||||
|
this.ws.sendCrypLearn(cryp.id, skill);
|
||||||
|
});
|
||||||
|
this.add(text);
|
||||||
|
text.cryp = cryp;
|
||||||
|
};
|
||||||
|
|
||||||
|
cryp.skills.forEach(knownSkill);
|
||||||
|
SKILLS.LEARNABLE.forEach(learnable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
|
|
||||||
|
const { TEXT } = require('./constants');
|
||||||
|
|
||||||
const ROW_WIDTH = 400;
|
const ROW_WIDTH = 400;
|
||||||
const ROW_HEIGHT = 200;
|
const ROW_HEIGHT = 200;
|
||||||
const ROW_FILL = 0x888888;
|
const ROW_FILL = 0x888888;
|
||||||
@ -23,8 +25,8 @@ class CrypRow extends Phaser.GameObjects.Group {
|
|||||||
|
|
||||||
row.cryp = cryp;
|
row.cryp = cryp;
|
||||||
this.add(row);
|
this.add(row);
|
||||||
this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 0), cryp.name, { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }));
|
this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 0), cryp.name, TEXT.HEADER));
|
||||||
this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 1), cryp.stamina.base, { fontFamily: 'Arial', fontSize: 24, color: '#ffffff', fontStyle: 'bold' }));
|
this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 1), cryp.stamina.base, TEXT.NORMAL));
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
|
|
||||||
const CrypList = require('./cryp.list');
|
const CrypList = require('./cryp.list');
|
||||||
const CrypPage = require('./cryp.page');
|
|
||||||
const Menu = require('./menu');
|
const Menu = require('./menu');
|
||||||
// const Passives = require('./passives');
|
// const Passives = require('./passives');
|
||||||
|
|
||||||
function renderCryps(store) {
|
function renderCryps(store, socket) {
|
||||||
const config = {
|
const config = {
|
||||||
type: Phaser.AUTO,
|
type: Phaser.AUTO,
|
||||||
// parent: 'cryps',
|
// parent: 'cryps',
|
||||||
@ -23,7 +22,6 @@ function renderCryps(store) {
|
|||||||
scene: [
|
scene: [
|
||||||
Menu,
|
Menu,
|
||||||
CrypList,
|
CrypList,
|
||||||
// Passives,
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,18 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
|
|
||||||
|
const { TEXT } = require('./constants');
|
||||||
|
|
||||||
class Menu extends Phaser.Scene {
|
class Menu extends Phaser.Scene {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super({ key: 'Menu', active: true });
|
super({ key: 'Menu', active: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
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);
|
||||||
|
this.scene.sleep('Passives');
|
||||||
|
this.input.keyboard.on('keydown_F', () => {
|
||||||
|
this.scene.wake('Passives');
|
||||||
|
}, 0, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -116,6 +116,14 @@ function createSocket(store) {
|
|||||||
send({ method: 'cryp_spawn', params: { name } });
|
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) {
|
function sendGameState(id) {
|
||||||
send({ method: 'game_state', params: { id } });
|
send({ method: 'game_state', params: { id } });
|
||||||
}
|
}
|
||||||
@ -203,6 +211,8 @@ function createSocket(store) {
|
|||||||
sendGameSkill,
|
sendGameSkill,
|
||||||
sendGameTarget,
|
sendGameTarget,
|
||||||
sendCrypSpawn,
|
sendCrypSpawn,
|
||||||
|
sendCrypLearn,
|
||||||
|
sendCrypForget,
|
||||||
sendItemUse,
|
sendItemUse,
|
||||||
connect,
|
connect,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@ use failure::Error;
|
|||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use account::Account;
|
use account::Account;
|
||||||
use rpc::{CrypSpawnParams};
|
use rpc::{CrypSpawnParams, CrypLearnParams, CrypForgetParams};
|
||||||
use skill::{Skill, Cooldown, Effect, Cast, Source};
|
use skill::{Skill, Cooldown, Effect, Cast, Source};
|
||||||
use game::{Log};
|
use game::{Log};
|
||||||
|
|
||||||
@ -129,6 +129,16 @@ impl Cryp {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn forget(mut self, skill: Skill) -> Result<Cryp, Error> {
|
||||||
|
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 {
|
pub fn add_xp(mut self) -> Cryp {
|
||||||
self.xp = self.xp.saturating_add(1);
|
self.xp = self.xp.saturating_add(1);
|
||||||
if self.xp.is_power_of_two() {
|
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()
|
let cryp = Cryp::new()
|
||||||
.named(¶ms.name)
|
.named(¶ms.name)
|
||||||
.level(10)
|
.level(10)
|
||||||
.learn(Skill::Stun)
|
|
||||||
.learn(Skill::Block)
|
|
||||||
.set_account(account.id)
|
.set_account(account.id)
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
@ -349,6 +357,18 @@ pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Accou
|
|||||||
return Ok(cryp);
|
return Ok(cryp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cryp_learn(params: CrypLearnParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
|
||||||
|
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<Cryp, Error> {
|
||||||
|
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<Cryp, Error> {
|
pub fn cryp_write(cryp: Cryp, tx: &mut Transaction) -> Result<Cryp, Error> {
|
||||||
let cryp_bytes = to_vec(&cryp)?;
|
let cryp_bytes = to_vec(&cryp)?;
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ use failure::Error;
|
|||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use net::Db;
|
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 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 account::{Account, account_create, account_login, account_from_token, account_cryps};
|
||||||
use item::{Item, items_list, item_use};
|
use item::{Item, items_list, item_use};
|
||||||
@ -39,6 +39,8 @@ impl Rpc {
|
|||||||
// match on that to determine what fn to call
|
// match on that to determine what fn to call
|
||||||
let response = match v.method.as_ref() {
|
let response = match v.method.as_ref() {
|
||||||
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account, client),
|
"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_state" => Rpc::game_state(data, &mut tx, account, client),
|
||||||
"game_pve" => Rpc::game_pve(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),
|
"game_pvp" => Rpc::game_pvp(data, &mut tx, account, client),
|
||||||
@ -206,6 +208,49 @@ impl Rpc {
|
|||||||
Ok(cryp_list)
|
Ok(cryp_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cryp_learn(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
|
let a = match account {
|
||||||
|
Some(a) => a,
|
||||||
|
None => return Err(err_msg("auth required")),
|
||||||
|
};
|
||||||
|
|
||||||
|
let msg = from_slice::<CrypLearnMsg>(&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<u8>, tx: &mut Transaction, account: Option<Account>, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
|
let a = match account {
|
||||||
|
Some(a) => a,
|
||||||
|
None => return Err(err_msg("auth required")),
|
||||||
|
};
|
||||||
|
|
||||||
|
let msg = from_slice::<CrypForgetMsg>(&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<u8>, tx: &mut Transaction, _account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
fn account_create(data: Vec<u8>, tx: &mut Transaction, _account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||||
match from_slice::<AccountCreateMsg>(&data) {
|
match from_slice::<AccountCreateMsg>(&data) {
|
||||||
Ok(v) => Ok(RpcResponse {
|
Ok(v) => Ok(RpcResponse {
|
||||||
@ -276,6 +321,8 @@ pub struct RpcResponse {
|
|||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub enum RpcResult {
|
pub enum RpcResult {
|
||||||
CrypSpawn(Cryp),
|
CrypSpawn(Cryp),
|
||||||
|
CrypForget(Cryp),
|
||||||
|
CrypLearn(Cryp),
|
||||||
Account(Account),
|
Account(Account),
|
||||||
CrypList(Vec<Cryp>),
|
CrypList(Vec<Cryp>),
|
||||||
GameState(Game),
|
GameState(Game),
|
||||||
@ -300,6 +347,30 @@ pub struct CrypSpawnParams {
|
|||||||
pub name: String,
|
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)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
struct GameStateMsg {
|
struct GameStateMsg {
|
||||||
method: String,
|
method: String,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user