From 119d4d8c9a8300ab0ec14f517d2440ffa85256f7 Mon Sep 17 00:00:00 2001 From: Mashy Date: Sun, 30 Dec 2018 14:25:22 +1000 Subject: [PATCH] zone mission update --- client/src/events.js | 1 - client/src/scenes/menu.game.list.js | 2 +- client/src/scenes/missions.controls.js | 5 ++++- client/src/scenes/missions.js | 17 ++++++++++------- client/src/socket.js | 12 ++++++++++++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/client/src/events.js b/client/src/events.js index e07868f6..c8d6819b 100644 --- a/client/src/events.js +++ b/client/src/events.js @@ -36,7 +36,6 @@ function registerEvents(registry, events, tutorial) { registry.set('zone', zone); } - function setGameList(gameList) { registry.set('gameList', gameList); } diff --git a/client/src/scenes/menu.game.list.js b/client/src/scenes/menu.game.list.js index 1ef465c2..e04c1640 100644 --- a/client/src/scenes/menu.game.list.js +++ b/client/src/scenes/menu.game.list.js @@ -124,7 +124,7 @@ class MenuGameList extends Phaser.Scene { zones.on('pointerdown', () => { this.scene.add('Missions', Missions, true); - return ws.sendAccountZone(); + return ws.sendZoneCreate(); }); diff --git a/client/src/scenes/missions.controls.js b/client/src/scenes/missions.controls.js index 4388e07d..4131d015 100644 --- a/client/src/scenes/missions.controls.js +++ b/client/src/scenes/missions.controls.js @@ -1,5 +1,4 @@ const Phaser = require('phaser'); -const MenuGameList = require('./menu.game.list'); const { TEXT, @@ -12,6 +11,9 @@ class MissionsControls extends Phaser.Scene { } create() { + this.ws = this.registry.get('ws'); + this.zone = this.registry.get('zone'); + console.log(this.registry.get('account')); const WIDTH = Math.floor(GAME_LIST.width() / 2); const HEIGHT = GAME_LIST.height(); @@ -26,6 +28,7 @@ class MissionsControls extends Phaser.Scene { menu.on('pointerdown', () => { this.scene.get('Missions').cleanUp(); + this.ws.sendZoneClose(this.zone.id); this.cleanUp(); }); diff --git a/client/src/scenes/missions.js b/client/src/scenes/missions.js index 4aff968a..daacbb37 100644 --- a/client/src/scenes/missions.js +++ b/client/src/scenes/missions.js @@ -18,11 +18,12 @@ class Missions extends Phaser.Scene { create() { const zone = this.registry.get('zone'); if (!zone) return false; + console.log(zone); this.scene.manager.add('MissionControls', MissionControls, true); this.graphics = this.add.graphics(); const nodeData = zone.graph.nodes; - this.edgeData = zone.graph.edges.map(x => x.map(y => nodeData[y])); + this.edgeData = zone.graph.edges; this.cameras.main.setViewport(COMBAT.width() * 0.2, COMBAT.y(), COMBAT.width() * 0.8, COMBAT.height()); this.addNodes(nodeData); @@ -35,8 +36,8 @@ class Missions extends Phaser.Scene { addNodes(nodeData) { this.nodes = []; nodeData.forEach((n, i) => { - this.nodes[n.id] = this.add.existing( - new Node(this, 500, 850 + i * -100, n.id, n.success, n.tag) + this.nodes[i] = this.add.existing( + new Node(this, 500, 850 + i * -100, i, n.success, n.tag) ).setInteractive(); }); } @@ -76,8 +77,10 @@ class Missions extends Phaser.Scene { const team = this.registry.get('cryps').filter(c => c.active).map(c => c.id); if (team.length === 0) return false; + const zone = this.registry.get('zone'); // 'Boss' to be replaced with node id for RPC call - this.registry.get('ws').sendGamePve(team, 'Boss'); + if (gameObjects[0].success) return false; + this.registry.get('ws').sendZoneJoin(zone.id, gameObjects[0].id, team); this.cleanUp(); } @@ -97,11 +100,11 @@ class Missions extends Phaser.Scene { }, 0, this); } - drawEdges(nodeData) { + drawEdges() { this.graphics.clear(); this.edgeData.forEach((e) => { - const drawEdge = nodeData.filter(n => ( - e[0].id === n.id || e[1].id === n.id + const drawEdge = this.nodes.filter(n => ( + e[0] === n.id || e[1] === n.id )); if (drawEdge[0].success && drawEdge[1].success) { this.graphics.lineStyle(10, 0xfff00f, 0.2); diff --git a/client/src/socket.js b/client/src/socket.js index fa2a562b..26accfb6 100644 --- a/client/src/socket.js +++ b/client/src/socket.js @@ -108,6 +108,14 @@ function createSocket(events) { send({ method: 'zone_create', params: {} }); } + function sendZoneJoin(zoneId, nodeId, crypIds) { + send({ method: 'zone_join', params: { zone_id: zoneId, node_id: nodeId, cryp_ids: crypIds } }); + } + + function sendZoneClose(zoneId) { + send({ method: 'zone_close', params: { zone_id: zoneId } }); + } + // ------------- // Incoming @@ -173,6 +181,8 @@ function createSocket(events) { account_items: accountItems, zone_create: res => console.log(res), zone_state: zoneState, + zone_close: res => console.log(res), + }; // decodes the cbor and @@ -250,6 +260,8 @@ function createSocket(events) { sendCrypForget, sendItemUse, sendZoneCreate, + sendZoneJoin, + sendZoneClose, connect, }; }