update zone node on game finish
This commit is contained in:
parent
3f208bb29c
commit
b92a88280f
@ -14,7 +14,6 @@ strangle
|
||||
* zones
|
||||
* open w/ item?
|
||||
* close
|
||||
* check node joinable
|
||||
* update on game finish
|
||||
|
||||
## SOON
|
||||
|
||||
@ -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<String>;
|
||||
|
||||
@ -26,7 +27,7 @@ pub enum PveMode {
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Team {
|
||||
id: Uuid,
|
||||
pub id: Uuid,
|
||||
cryps: Vec<Cryp>,
|
||||
}
|
||||
|
||||
@ -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(());
|
||||
|
||||
@ -15,6 +15,7 @@ use rpc::{ZoneJoinParams, ZoneCloseParams};
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct Zone {
|
||||
id: Uuid,
|
||||
account: Uuid,
|
||||
active: bool,
|
||||
graph: UnGraph<Encounter, ()>,
|
||||
}
|
||||
@ -98,6 +99,7 @@ pub fn zone_create(tx: &mut Transaction, account: &Account) -> Result<Zone, Erro
|
||||
|
||||
let zone = Zone {
|
||||
id,
|
||||
account: account.id,
|
||||
graph,
|
||||
active: true,
|
||||
};
|
||||
@ -228,6 +230,28 @@ pub fn node_joinable(graph: &ZoneGraph, target_index: NodeIndex) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn node_finish(game: &Game, zone_id: Uuid, node_index: u32, tx: &mut Transaction) -> Result<Zone, Error> {
|
||||
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::*;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user