This commit is contained in:
ntr 2019-03-03 13:06:32 +11:00
parent 813972efb6
commit 9dcb21eefa
4 changed files with 47 additions and 20 deletions

View File

@ -20,7 +20,6 @@ pub type Log = Vec<String>;
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]
pub struct Team { pub struct Team {
pub id: Uuid, pub id: Uuid,
pub player: Option<Uuid>,
pub bot: bool, pub bot: bool,
cryps: Vec<Cryp>, cryps: Vec<Cryp>,
} }
@ -31,15 +30,9 @@ impl Team {
id: account, id: account,
cryps: vec![], cryps: vec![],
bot: false, bot: false,
player: None,
}; };
} }
pub fn set_player(&mut self, id: Uuid) -> &mut Team {
self.player = Some(id);
self
}
pub fn set_bot(&mut self) -> &mut Team { pub fn set_bot(&mut self) -> &mut Team {
self.bot = true; self.bot = true;
self self

View File

@ -238,7 +238,18 @@ impl Instance {
game.start(); game.start();
assert!(game.finished()); assert!(game.finished());
let winner = game.winner().unwrap();
round.finished = true; round.finished = true;
for team in game.teams.iter() {
let mut player = self.players.iter_mut().find(|p| p.id == team.id).unwrap();
match team.id == winner.id {
true => player.add_win(),
false => player.add_loss(),
};
}
} }
} }
} }
@ -444,9 +455,20 @@ pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uu
// update scores // update scores
let winner = game.winner().ok_or(err_msg("game not finished"))?; let winner = game.winner().ok_or(err_msg("game not finished"))?;
for team in game.teams.iter() for team in game.teams.iter() {
.filter(|t| !t.bot) match team.bot {
.filter(|t| t.player.is_some()) { true => {
let mut instance = instance_get(tx, instance_id)?;
{
let mut player = instance.players.iter_mut().find(|p| p.account == team.id).unwrap();
match team.id == winner.id {
true => player.add_win(),
false => player.add_loss(),
};
}
instance_update(tx, instance)?;
},
false => {
let mut player = player_get(tx, team.id, instance_id)?; let mut player = player_get(tx, team.id, instance_id)?;
match team.id == winner.id { match team.id == winner.id {
true => player.add_win(), true => player.add_win(),
@ -454,6 +476,8 @@ pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uu
}; };
println!("{:?}", player); println!("{:?}", player);
player_update(tx, player)?; player_update(tx, player)?;
},
}
} }
// update instance and persist // update instance and persist
@ -505,7 +529,7 @@ mod tests {
assert!(instance.vbox_phase_finished()); assert!(instance.vbox_phase_finished());
instance.games_phase_start(); instance.games_phase_start();
println!("{:?}", instance.rounds); println!("{:#?}", instance);
assert!(instance.games_phase_finished()); assert!(instance.games_phase_finished());
} }

View File

@ -325,7 +325,7 @@ pub enum Skill {
Paralyse, Paralyse,
Strangle, // physical dot and disable Strangle, // physical dot and disable
Strike,
Stun, Stun,
// Evade, // actively evade // Evade, // actively evade
@ -401,6 +401,7 @@ impl Skill {
pub fn base_cd(&self) -> Cooldown { pub fn base_cd(&self) -> Cooldown {
match self { match self {
Skill::Attack => None, Skill::Attack => None,
Skill::Strike => None,
// ----------------- // -----------------
// Nature // Nature
@ -486,6 +487,7 @@ impl Skill {
pub fn category(&self) -> Category { pub fn category(&self) -> Category {
match self { match self {
Skill::Attack => Category::Red, Skill::Attack => Category::Red,
Skill::Strike => Category::Red,
// ----------------- // -----------------
// Nature // Nature
@ -590,6 +592,7 @@ impl Skill {
// fast phys combat // fast phys combat
Skill::Attack => 5, Skill::Attack => 5,
Skill::Strike => 10,
Skill::Paralyse => 5, Skill::Paralyse => 5,
Skill::Strangle => 5, Skill::Strangle => 5,
Skill::Banish => 5, Skill::Banish => 5,
@ -679,6 +682,7 @@ impl Skill {
// ----------------- // -----------------
// Nature // Nature
// ----------------- // -----------------
Skill::Strike => strike(source, target, resolution),
Skill::Block => block(source, target, resolution), Skill::Block => block(source, target, resolution),
Skill::Parry => parry(source, target, resolution), Skill::Parry => parry(source, target, resolution),
Skill::Snare => snare(source, target, resolution), // TODO prevent physical moves Skill::Snare => snare(source, target, resolution), // TODO prevent physical moves
@ -992,6 +996,12 @@ fn banish(_cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Re
return resolution; return resolution;
} }
fn strike(cryp: &mut Cryp, target: &mut Cryp, mut resolution: Resolution) -> Resolution {
let amount = cryp.red_damage();
resolution.results.push(target.deal_red_damage(Skill::Attack, u64::max_value()));
return resolution;
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

View File

@ -90,7 +90,7 @@ impl Var {
Var::Slow => Ok(Skill::Slow), Var::Slow => Ok(Skill::Slow),
Var::Snare => Ok(Skill::Snare), Var::Snare => Ok(Skill::Snare),
Var::Strangle => Ok(Skill::Strangle), Var::Strangle => Ok(Skill::Strangle),
// Var::Strike => Ok(Skill::Strike), Var::Strike => Ok(Skill::Strike),
// Var::Clutch => Ok(Skill::Clutch), // Var::Clutch => Ok(Skill::Clutch),
// Var::Taunt => Ok(Skill::Taunt), // Var::Taunt => Ok(Skill::Taunt),
Var::Throw => Ok(Skill::Throw), Var::Throw => Ok(Skill::Throw),