Merge branch 'zones' of ssh://cryps.gg:40022/~/cryps into zones
This commit is contained in:
commit
c46c74cb7e
@ -3,6 +3,7 @@ const Phaser = require('phaser');
|
|||||||
const Header = require('./header');
|
const Header = require('./header');
|
||||||
const Menu = require('./menu');
|
const Menu = require('./menu');
|
||||||
const Combat = require('./combat');
|
const Combat = require('./combat');
|
||||||
|
const Missions = require('./missions');
|
||||||
|
|
||||||
function renderCryps() {
|
function renderCryps() {
|
||||||
const config = {
|
const config = {
|
||||||
@ -35,6 +36,11 @@ function renderCryps() {
|
|||||||
if (!data || game.registry.get('inGame')) return false;
|
if (!data || game.registry.get('inGame')) return false;
|
||||||
return game.scene.add('Combat', Combat, true);
|
return game.scene.add('Combat', Combat, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (key === 'zone') {
|
||||||
|
return game.scene.add('Missions', Missions, true, data);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
const Phaser = require('phaser');
|
const Phaser = require('phaser');
|
||||||
const Missions = require('./missions');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
TEXT,
|
TEXT,
|
||||||
@ -123,8 +122,8 @@ class MenuGameList extends Phaser.Scene {
|
|||||||
});
|
});
|
||||||
|
|
||||||
zones.on('pointerdown', () => {
|
zones.on('pointerdown', () => {
|
||||||
this.scene.add('Missions', Missions, true);
|
if (this.scene.get('Missions')) return false;
|
||||||
return ws.sendZoneCreate();
|
return ws.sendAccountZone();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,7 @@ class Missions extends Phaser.Scene {
|
|||||||
this.load.image('eye', 'https://labs.phaser.io/assets/particles/green-orb.png');
|
this.load.image('eye', 'https://labs.phaser.io/assets/particles/green-orb.png');
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create(zone) {
|
||||||
const zone = this.registry.get('zone');
|
|
||||||
if (!zone) return false;
|
if (!zone) return false;
|
||||||
console.log(zone);
|
console.log(zone);
|
||||||
|
|
||||||
|
|||||||
@ -195,6 +195,7 @@ function createSocket(events) {
|
|||||||
console.log(res);
|
console.log(res);
|
||||||
|
|
||||||
// check for error and split into response type and data
|
// check for error and split into response type and data
|
||||||
|
if (res.err === 'no active zone') sendZoneCreate();
|
||||||
if (res.err) return errorToast(res.err);
|
if (res.err) return errorToast(res.err);
|
||||||
const { method, params } = res;
|
const { method, params } = res;
|
||||||
if (!handlers[method]) return errorToast(`${method} handler missing`);
|
if (!handlers[method]) return errorToast(`${method} handler missing`);
|
||||||
|
|||||||
@ -139,6 +139,10 @@ pub fn zone_update(zone: &Zone, tx: &mut Transaction) -> Result<(), Error> {
|
|||||||
pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
|
||||||
let mut zone = zone_get(tx, params.zone_id)?;
|
let mut zone = zone_get(tx, params.zone_id)?;
|
||||||
|
|
||||||
|
if !node_joinable(&zone.graph, NodeIndex::from(params.node_id)) {
|
||||||
|
return Err(err_msg("not not joinable"));
|
||||||
|
}
|
||||||
|
|
||||||
let mut game = game_pve_new(params.cryp_ids, PveMode::Normal, tx, account)?;
|
let mut game = game_pve_new(params.cryp_ids, PveMode::Normal, tx, account)?;
|
||||||
game.set_zone(zone.id, params.node_id);
|
game.set_zone(zone.id, params.node_id);
|
||||||
|
|
||||||
@ -159,7 +163,7 @@ pub fn zone_join(params: ZoneJoinParams, tx: &mut Transaction, account: &Account
|
|||||||
return Ok(game);
|
return Ok(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn zone_close(params: ZoneCloseParams, tx: &mut Transaction, account: &Account) -> Result<(), Error> {
|
pub fn zone_close(params: ZoneCloseParams, tx: &mut Transaction, _account: &Account) -> Result<(), Error> {
|
||||||
let mut zone = zone_get(tx, params.zone_id)?;
|
let mut zone = zone_get(tx, params.zone_id)?;
|
||||||
zone.active = false;
|
zone.active = false;
|
||||||
zone_update(&zone, tx)?;
|
zone_update(&zone, tx)?;
|
||||||
@ -191,7 +195,7 @@ pub fn create_zone_graph() -> ZoneGraph {
|
|||||||
return gr;
|
return gr;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn node_joinable(graph: &mut ZoneGraph, target_index: NodeIndex) -> bool {
|
pub fn node_joinable(graph: &ZoneGraph, target_index: NodeIndex) -> bool {
|
||||||
// early return for already attempted
|
// early return for already attempted
|
||||||
{
|
{
|
||||||
let target_encounter = match graph.node_weight(target_index) {
|
let target_encounter = match graph.node_weight(target_index) {
|
||||||
@ -199,29 +203,22 @@ pub fn node_joinable(graph: &mut ZoneGraph, target_index: NodeIndex) -> bool {
|
|||||||
None => panic!("{:?} has no weight for {:?}", graph, target_index),
|
None => panic!("{:?} has no weight for {:?}", graph, target_index),
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("{:?}", target_encounter);
|
|
||||||
|
|
||||||
if target_encounter.game_id.is_some() {
|
if target_encounter.game_id.is_some() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now check the graph for connectedness
|
let success_indices = graph.node_indices().filter(|i| {
|
||||||
// get all the nodes that have been successfully completed
|
match graph.node_weight(*i) {
|
||||||
let mut filtered = graph.clone();
|
|
||||||
filtered.retain_nodes(|g, i| {
|
|
||||||
match g.node_weight(i) {
|
|
||||||
Some(encounter) => encounter.success,
|
Some(encounter) => encounter.success,
|
||||||
None => panic!("no weight for {:?}", i),
|
None => panic!("no weight for {:?}", i),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("{:?}", filtered);
|
|
||||||
|
|
||||||
// if a node is a neighbour of that graph
|
// if a node is a neighbour of that graph
|
||||||
// and hasn't been attempted
|
// and hasn't been attempted
|
||||||
// it is joinable
|
// it is joinable
|
||||||
for i in filtered.node_indices() {
|
for i in success_indices {
|
||||||
match graph.neighbors(i).find(|n| *n == target_index) {
|
match graph.neighbors(i).find(|n| *n == target_index) {
|
||||||
Some(_n) => return true,
|
Some(_n) => return true,
|
||||||
None => continue,
|
None => continue,
|
||||||
@ -248,8 +245,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn zone_joinable_test() {
|
fn zone_joinable_test() {
|
||||||
let mut graph = create_zone_graph();
|
let graph = create_zone_graph();
|
||||||
assert!(node_joinable(&mut graph, NodeIndex::from(1)));
|
assert!(node_joinable(&graph, NodeIndex::from(1)));
|
||||||
assert!(!node_joinable(&mut graph, NodeIndex::from(2)));
|
assert!(!node_joinable(&graph, NodeIndex::from(2)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user