Merge branch 'master' of ssh://cryps.gg:40022/~/cryps

This commit is contained in:
Mashy 2019-03-03 17:33:59 +10:00
commit 2eb8318ae1
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)]
pub struct Team {
pub id: Uuid,
pub player: Option<Uuid>,
pub bot: bool,
cryps: Vec<Cryp>,
}
@ -31,15 +30,9 @@ impl Team {
id: account,
cryps: vec![],
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 {
self.bot = true;
self

View File

@ -238,7 +238,18 @@ impl Instance {
game.start();
assert!(game.finished());
let winner = game.winner().unwrap();
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
let winner = game.winner().ok_or(err_msg("game not finished"))?;
for team in game.teams.iter()
.filter(|t| !t.bot)
.filter(|t| t.player.is_some()) {
for team in game.teams.iter() {
match team.bot {
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)?;
match team.id == winner.id {
true => player.add_win(),
@ -454,6 +476,8 @@ pub fn instance_game_finished(tx: &mut Transaction, game: &Game, instance_id: Uu
};
println!("{:?}", player);
player_update(tx, player)?;
},
}
}
// update instance and persist
@ -505,7 +529,7 @@ mod tests {
assert!(instance.vbox_phase_finished());
instance.games_phase_start();
println!("{:?}", instance.rounds);
println!("{:#?}", instance);
assert!(instance.games_phase_finished());
}

View File

@ -325,7 +325,7 @@ pub enum Skill {
Paralyse,
Strangle, // physical dot and disable
Strike,
Stun,
// Evade, // actively evade
@ -401,6 +401,7 @@ impl Skill {
pub fn base_cd(&self) -> Cooldown {
match self {
Skill::Attack => None,
Skill::Strike => None,
// -----------------
// Nature
@ -486,6 +487,7 @@ impl Skill {
pub fn category(&self) -> Category {
match self {
Skill::Attack => Category::Red,
Skill::Strike => Category::Red,
// -----------------
// Nature
@ -590,6 +592,7 @@ impl Skill {
// fast phys combat
Skill::Attack => 5,
Skill::Strike => 10,
Skill::Paralyse => 5,
Skill::Strangle => 5,
Skill::Banish => 5,
@ -679,6 +682,7 @@ impl Skill {
// -----------------
// Nature
// -----------------
Skill::Strike => strike(source, target, resolution),
Skill::Block => block(source, target, resolution),
Skill::Parry => parry(source, target, resolution),
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;
}
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)]
mod tests {

View File

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