add joinable check to zone
This commit is contained in:
parent
28bda483f1
commit
79f96a2ee0
@ -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,8 +203,6 @@ 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;
|
||||||
}
|
}
|
||||||
@ -216,8 +218,6 @@ pub fn node_joinable(graph: &mut ZoneGraph, target_index: NodeIndex) -> bool {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
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
|
||||||
@ -248,8 +248,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