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 Menu = require('./menu');
|
||||
const Combat = require('./combat');
|
||||
const Missions = require('./missions');
|
||||
|
||||
function renderCryps() {
|
||||
const config = {
|
||||
@ -35,6 +36,11 @@ function renderCryps() {
|
||||
if (!data || game.registry.get('inGame')) return false;
|
||||
return game.scene.add('Combat', Combat, true);
|
||||
}
|
||||
|
||||
if (key === 'zone') {
|
||||
return game.scene.add('Missions', Missions, true, data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
const Phaser = require('phaser');
|
||||
const Missions = require('./missions');
|
||||
|
||||
const {
|
||||
TEXT,
|
||||
@ -123,8 +122,8 @@ class MenuGameList extends Phaser.Scene {
|
||||
});
|
||||
|
||||
zones.on('pointerdown', () => {
|
||||
this.scene.add('Missions', Missions, true);
|
||||
return ws.sendZoneCreate();
|
||||
if (this.scene.get('Missions')) return false;
|
||||
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');
|
||||
}
|
||||
|
||||
create() {
|
||||
const zone = this.registry.get('zone');
|
||||
create(zone) {
|
||||
if (!zone) return false;
|
||||
console.log(zone);
|
||||
|
||||
|
||||
@ -195,6 +195,7 @@ function createSocket(events) {
|
||||
console.log(res);
|
||||
|
||||
// check for error and split into response type and data
|
||||
if (res.err === 'no active zone') sendZoneCreate();
|
||||
if (res.err) return errorToast(res.err);
|
||||
const { method, params } = res;
|
||||
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> {
|
||||
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)?;
|
||||
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);
|
||||
}
|
||||
|
||||
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)?;
|
||||
zone.active = false;
|
||||
zone_update(&zone, tx)?;
|
||||
@ -191,7 +195,7 @@ pub fn create_zone_graph() -> ZoneGraph {
|
||||
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
|
||||
{
|
||||
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),
|
||||
};
|
||||
|
||||
println!("{:?}", target_encounter);
|
||||
|
||||
if target_encounter.game_id.is_some() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// now check the graph for connectedness
|
||||
// get all the nodes that have been successfully completed
|
||||
let mut filtered = graph.clone();
|
||||
filtered.retain_nodes(|g, i| {
|
||||
match g.node_weight(i) {
|
||||
let success_indices = graph.node_indices().filter(|i| {
|
||||
match graph.node_weight(*i) {
|
||||
Some(encounter) => encounter.success,
|
||||
None => panic!("no weight for {:?}", i),
|
||||
}
|
||||
});
|
||||
|
||||
println!("{:?}", filtered);
|
||||
|
||||
// if a node is a neighbour of that graph
|
||||
// and hasn't been attempted
|
||||
// it is joinable
|
||||
for i in filtered.node_indices() {
|
||||
for i in success_indices {
|
||||
match graph.neighbors(i).find(|n| *n == target_index) {
|
||||
Some(_n) => return true,
|
||||
None => continue,
|
||||
@ -248,8 +245,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn zone_joinable_test() {
|
||||
let mut graph = create_zone_graph();
|
||||
assert!(node_joinable(&mut graph, NodeIndex::from(1)));
|
||||
assert!(!node_joinable(&mut graph, NodeIndex::from(2)));
|
||||
let graph = create_zone_graph();
|
||||
assert!(node_joinable(&graph, NodeIndex::from(1)));
|
||||
assert!(!node_joinable(&graph, NodeIndex::from(2)));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user