diff --git a/server/WORKLOG.md b/server/WORKLOG.md index 2f0df686..5d661969 100644 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -14,7 +14,6 @@ strangle * zones * open w/ item? * close - * check node joinable * update on game finish ## SOON diff --git a/server/src/game.rs b/server/src/game.rs index fae2b833..7e61ae8a 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -15,6 +15,7 @@ use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameTa use cryp::{Cryp, cryp_get}; use skill::{Skill, Cast, ResolutionResult}; use item::{item_drop}; +use zone::{node_finish}; pub type Log = Vec; @@ -26,7 +27,7 @@ pub enum PveMode { #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Team { - id: Uuid, + pub id: Uuid, cryps: Vec, } @@ -563,7 +564,7 @@ impl Game { self.teams.iter().any(|t| t.cryps.iter().all(|c| c.is_ko())) } - fn winner(&self) -> Option<&Team> { + pub fn winner(&self) -> Option<&Team> { self.teams.iter().find(|t| t.cryps.iter().any(|c| !c.is_ko())) } @@ -734,6 +735,12 @@ pub fn game_update(game: &Game, tx: &mut Transaction) -> Result<(), Error> { item_drop(tx, t.id)?; } } + + // check for zone update + if let Some((z, i)) = game.zone { + node_finish(game, z, i, tx)?; + } + } return Ok(()); diff --git a/server/src/zone.rs b/server/src/zone.rs index 3c7c4ae1..0106043e 100644 --- a/server/src/zone.rs +++ b/server/src/zone.rs @@ -15,6 +15,7 @@ use rpc::{ZoneJoinParams, ZoneCloseParams}; #[derive(Debug,Clone,Serialize,Deserialize)] pub struct Zone { id: Uuid, + account: Uuid, active: bool, graph: UnGraph, } @@ -98,6 +99,7 @@ pub fn zone_create(tx: &mut Transaction, account: &Account) -> Result bool { return false; } +pub fn node_finish(game: &Game, zone_id: Uuid, node_index: u32, tx: &mut Transaction) -> Result { + let mut zone = zone_get(tx, zone_id)?; + + let winner_id = match game.winner() { + Some(w) => w.id, + None => return Ok(zone), + }; + + if zone.account == winner_id { + { + let encounter = zone.graph + .node_weight_mut(NodeIndex::from(node_index)) + .ok_or(err_msg("encounter not found for game zone update"))?; + + encounter.success = true; + } + zone_update(&zone, tx)?; + } + + Ok(zone) +} + #[cfg(test)] mod tests { use zone::*;