diff --git a/client/src/scenes/combat.render.resolutions.js b/client/src/scenes/combat.render.resolutions.js index ff2b6fd1..aafc9c79 100644 --- a/client/src/scenes/combat.render.resolutions.js +++ b/client/src/scenes/combat.render.resolutions.js @@ -44,8 +44,6 @@ function calculateTweenParams(sourceSpawn, targetSpawn, account) { } function animatePhase(scene, game, resolution, cb) { - - console.log(resolution); // return early for disabled skills if (resolution.resolution.disable.disabled) return cb(); const group = scene.scene.get('CombatCryps').cryps; @@ -73,7 +71,7 @@ function animatePhase(scene, game, resolution, cb) { if (moveSourceBattle) scene.tweens.add(moveSourceBattle); scene.tweens.add(moveTargetBattle); - scene.time.delayedCall(MOVE_CREEP, () => { + return scene.time.delayedCall(MOVE_CREEP, () => { const isAlly = resolution.target_team_id !== account.id; // animate animation const workingSkills = ['Heal', 'Block']; diff --git a/client/src/scenes/menu.game.list.js b/client/src/scenes/menu.game.list.js old mode 100644 new mode 100755 index 4482eabb..e04c1640 --- a/client/src/scenes/menu.game.list.js +++ b/client/src/scenes/menu.game.list.js @@ -65,13 +65,13 @@ class MenuGameList extends Phaser.Scene { .text(pve.getCenter().x, pve.getCenter().y, 'new PVE\ngame', TEXT.HEADER) .setOrigin(0.5, 0.5)); - const boss = this.add + const zones = this.add .rectangle(X + WIDTH * 2, GAME_LIST.y(0), WIDTH, HEIGHT, 0x222222) .setInteractive() .setOrigin(0); this.gameList.add(this.add - .text(boss.getCenter().x, boss.getCenter().y, 'MISSIONS\n', TEXT.HEADER) + .text(zones.getCenter().x, zones.getCenter().y, 'Zones\n', TEXT.HEADER) .setOrigin(0.5, 0.5)); @@ -122,9 +122,9 @@ class MenuGameList extends Phaser.Scene { return ws.sendGamePve(team, 'Normal'); }); - boss.on('pointerdown', () => { - const team = cryps.filter(c => c.active).map(c => c.id); + zones.on('pointerdown', () => { this.scene.add('Missions', Missions, true); + return ws.sendZoneCreate(); }); diff --git a/client/src/socket.js b/client/src/socket.js index 402069a1..8224ae62 100644 --- a/client/src/socket.js +++ b/client/src/socket.js @@ -100,6 +100,11 @@ function createSocket(events) { send({ method: 'item_use', params: { item, target } }); } + function sendZoneCreate() { + send({ method: 'zone_create', params: {} }); + } + + // ------------- // Incoming // ------------- @@ -157,6 +162,7 @@ function createSocket(events) { account_create: accountLogin, account_cryps: accountCryps, account_items: accountItems, + zone_create: res => console.log(res), }; // decodes the cbor and @@ -232,6 +238,7 @@ function createSocket(events) { sendCrypLearn, sendCrypForget, sendItemUse, + sendZoneCreate, connect, }; } diff --git a/server/Cargo.toml b/server/Cargo.toml index e3edacc1..a59216f9 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,7 +12,7 @@ serde_cbor = "0.9" tungstenite = "0.6" bcrypt = "0.2" -petgraph = "0.4" +petgraph = { version = "0.4", features = ["serde-1"] } dotenv = "0.9.0" env_logger = "*" diff --git a/server/src/main.rs b/server/src/main.rs index 0176a073..e5601c00 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -26,6 +26,7 @@ mod passives; mod rpc; mod account; mod item; +mod zone; use dotenv::dotenv; use net::{start}; diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 0a731452..5a2b0443 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -20,6 +20,7 @@ use game::{Game, PveMode, game_state, game_pve, game_pvp, game_join, game_joinab use account::{Account, account_create, account_login, account_from_token, account_cryps}; use item::{Item, items_list, item_use}; use skill::{Skill}; +use zone::{Zone, zone_create}; pub struct Rpc; @@ -69,6 +70,7 @@ impl Rpc { "game_joinable_list" => Rpc::game_joinable_list(data, &mut tx, account.unwrap(), client), "game_skill" => Rpc::game_skill(data, &mut tx, account.unwrap(), client), "game_target" => Rpc::game_target(data, &mut tx, account.unwrap(), client), + "zone_create" => Rpc::zone_create(data, &mut tx, account.unwrap(), client), "account_cryps" => Rpc::account_cryps(data, &mut tx, account.unwrap(), client), "account_items" => Rpc::account_items(data, &mut tx, account.unwrap(), client), "item_use" => Rpc::item_use(data, &mut tx, account.unwrap(), client), @@ -314,6 +316,18 @@ impl Rpc { return Ok(cryps_list); } + fn zone_create(data: Vec, tx: &mut Transaction, account: Account, _client: &mut WebSocket) -> Result { + // let _msg = from_slice::(&data).or(Err(err_msg("invalid params")))?; + + let response = RpcResponse { + method: "zone_state".to_string(), + params: RpcResult::ZoneState(zone_create(tx, &account)?) + }; + + return Ok(response); + } + + } @@ -334,6 +348,7 @@ pub enum RpcResult { GameJoinableList(Vec), ItemList(Vec), ItemUse(()), + ZoneState(Zone), } #[derive(Debug,Clone,Serialize,Deserialize)] @@ -504,6 +519,18 @@ pub struct ItemUseParams { pub target: Uuid, } +#[derive(Debug,Clone,Serialize,Deserialize)] +struct ZoneCreateMsg { + method: String, + params: (), +} + +// #[derive(Debug,Clone,Serialize,Deserialize)] +// pub struct ZoneCreateParams { + +// } + + // #[cfg(test)] // mod tests { // use super::*; diff --git a/server/src/zone.rs b/server/src/zone.rs new file mode 100644 index 00000000..1aca45f1 --- /dev/null +++ b/server/src/zone.rs @@ -0,0 +1,136 @@ +use uuid::Uuid; +use petgraph::graph::{Graph, UnGraph, NodeIndex}; +use petgraph::dot::{Dot, Config}; + +// Db Commons +use account::Account; +use serde_cbor::{from_slice, to_vec}; +use postgres::transaction::Transaction; +use failure::Error; +use failure::err_msg; + +use game::Game; + +pub type Zone = UnGraph; + +#[derive(Debug,Clone,PartialEq,Eq,Hash,PartialOrd,Ord,Serialize,Deserialize)] +pub struct Encounter { + tag: String, + id: Uuid, + game_id: Option, + success: bool, +} + +impl Encounter { + fn new(tag: &'static str) -> Encounter { + return Encounter { + tag: tag.to_string(), + id: Uuid::new_v4(), + success: false, + game_id: None, + }; + } +} + +pub fn create_zone_graph() -> UnGraph { + let mut gr = Graph::new_undirected(); + + let mut last = gr.add_node(Encounter::new("ZONE0")); + let mut next; + + next = gr.add_node(Encounter::new("ZONE1")); + gr.add_edge(last, next, ()); + last = next; + + next = gr.add_node(Encounter::new("ZONE2")); + gr.add_edge(last, next, ()); + last = next; + + next = gr.add_node(Encounter::new("ZONE3")); + gr.add_edge(last, next, ()); + last = next; + + next = gr.add_node(Encounter::new("BOSS")); + gr.add_edge(last, next, ()); + // last = next; + + return gr; +} + +// pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account) -> Result, Error> { +// let cryps = params.cryp_ids +// .iter() +// .map(|id| cryp_get(tx, *id, account.id)) +// .collect::, Error>>()?; + +// if cryps.len() > 3 { +// return Err(err_msg("team size too large (3 max)")); +// } + +// // create the game +// let mut game = Game::new(); +// // let game_id = game.id; + +// game +// .set_pve(true) +// .set_team_num(2) +// .set_team_size(cryps.len()); + +// // create the mob team +// let mob_team = generate_mob_team(params.mode, &cryps); + +// // add the players +// let mut plr_team = Team::new(account.id); +// plr_team +// .set_cryps(cryps); + + +// game +// .team_add(plr_team)? +// .team_add(mob_team)?; + +// game.start(); + +// // persist +// game_new(&game, tx)?; + +// Ok(game) +// } + +pub fn zone_create(tx: &mut Transaction, account: &Account) -> Result, Error> { + let id = Uuid::new_v4(); + let zone = create_zone_graph(); + + return Ok(zone); + + let bytes = to_vec(&zone)?; + + let query = " + INSERT INTO zones (id, data, account) + VALUES ($1, $2, $3) + RETURNING id; + "; + + let result = tx + .query(query, &[&id, &bytes, &account.id])?; + + result.iter().next().ok_or(format_err!("no zone written"))?; + + return Ok(zone); +} + +#[cfg(test)] +mod tests { + use zone::*; + + #[test] + fn create_zone_test() { + let _graph = create_zone_graph(); + // good shit; + // let nodes = graph.node_indices().collect::>(); + // println!("{:?}", nodes[0]); + // println!("{:?}", graph.node_weight(nodes[0])); + + // println!("{:?}", Dot::with_config(&graph, &[Config::EdgeNoLabel])); + } +}