This commit is contained in:
ntr 2019-06-01 16:01:42 +10:00
parent 67d8ae5e65
commit 47b216cb11
2 changed files with 10 additions and 102 deletions

View File

@ -86,7 +86,7 @@ impl Game {
player.forfeit(); player.forfeit();
} }
let player_description = player.constructs.iter().map(|c| c.name.clone()).collect::<Vec<String>>().join(", "); // let player_description = player.constructs.iter().map(|c| c.name.clone()).collect::<Vec<String>>().join(", ");
// self.log.push(format!("{:} has joined the game. [{:}]", player.name, player_description)); // self.log.push(format!("{:} has joined the game. [{:}]", player.name, player_description));
player.constructs.sort_unstable_by_key(|c| c.id); player.constructs.sort_unstable_by_key(|c| c.id);
@ -138,10 +138,10 @@ impl Game {
&& self.players.iter().all(|t| t.constructs.len() == self.player_constructs) && self.players.iter().all(|t| t.constructs.len() == self.player_constructs)
} }
pub fn start(mut self) -> Game { pub fn start(self) -> Game {
// self.log.push("Game starting...".to_string()); // self.log.push("Game starting...".to_string());
// forfeit // both forfeit ddue to no skills
if self.finished() { if self.finished() {
return self.finish(); return self.finish();
} }
@ -828,97 +828,6 @@ pub fn game_ready(params: GameStateParams, tx: &mut Transaction, account: &Accou
Ok(game) Ok(game)
} }
// pub fn game_pve_new(construct_ids: Vec<Uuid>, mode: GameMode, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
// if construct_ids.len() == 0 {
// return Err(err_msg("no constructs selected"));
// }
// let constructs = construct_ids
// .iter()
// .map(|id| construct_get(tx, *id, account.id))
// .collect::<Result<Vec<Construct>, Error>>()?;
// if constructs.len() > 3 {
// return Err(err_msg("player size too large (3 max)"));
// }
// // create the game
// let mut game = Game::new();
// // let game_id = game.id;
// game;
// .set_player_num(2)
// .set_player_constructs(constructs.len())
// .set_mode(mode);
// // create the mob player
// let mob_player = generate_mob_player(mode, &constructs);
// // add the players
// let mut plr_player = Player::new(account.id);
// plr_player
// .set_constructs(constructs);
// game
// .player_add(plr_player)?
// .player_add(mob_player)?;
// game.start();
// return Ok(game);
// }
// pub fn game_pve(params: GamePveParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
// let game = game_pve_new(params.construct_ids, GameMode::Normal, tx, account)?;
// // persist
// game_write(tx, &game)?;
// Ok(game)
// }
pub fn game_instance_new(tx: &mut Transaction, players: Vec<Player>, game_id: Uuid, instance_id: Uuid) -> Result<Game, Error> {
// create the game
let mut game = Game::new();
game.id = game_id;
game
.set_player_num(2)
.set_player_constructs(3)
.set_instance(instance_id);
// create the initiators player
for player in players {
game.player_add(player)?;
}
if game.can_start() {
game = game.start();
}
// persist
game_write(tx, &game)?;
Ok(game)
}
// pub fn game_instance_join(tx: &mut Transaction, player: Player, game_id: Uuid) -> Result<Game, Error> {
// let mut game = game_get(tx, game_id)?;
// game.player_add(player)?;
// if game.can_start() {
// game = game.start();
// }
// info!("{:?} game joined", game.id);
// game_update(tx, &game)?;
// Ok(game)
// }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use game::*; use game::*;

View File

@ -384,10 +384,11 @@ impl Cast {
pub type Disable = Vec<Effect>; pub type Disable = Vec<Effect>;
pub type Immunity = Vec<Effect>; pub type Immunity = Vec<Effect>;
// used to show the progress of a construct
// while the resolutions are animating
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct LogConstruct { pub struct EventConstruct {
pub id: Uuid, pub id: Uuid,
pub name: String,
pub red: u64, pub red: u64,
pub green: u64, pub green: u64,
pub blue: u64, pub blue: u64,
@ -407,8 +408,8 @@ pub enum LogStages {
#[derive(Debug,Clone,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,PartialEq,Serialize,Deserialize)]
pub struct Resolution { pub struct Resolution {
pub source: LogConstruct, pub source: EventConstruct,
pub target: LogConstruct, pub target: EventConstruct,
pub event: Event, pub event: Event,
pub stages: u8, pub stages: u8,
} }
@ -416,16 +417,14 @@ pub struct Resolution {
impl Resolution { impl Resolution {
fn new(source: &Construct, target: &Construct) -> Resolution { fn new(source: &Construct, target: &Construct) -> Resolution {
Resolution { Resolution {
source: LogConstruct { source: EventConstruct {
id: source.id, id: source.id,
name: source.name.clone(),
red: source.red_life(), red: source.red_life(),
green: source.green_life(), green: source.green_life(),
blue: source.blue_life(), blue: source.blue_life(),
}, },
target: LogConstruct { target: EventConstruct {
id: target.id, id: target.id,
name: target.name.clone(),
red: target.red_life(), red: target.red_life(),
green: target.green_life(), green: target.green_life(),
blue: target.blue_life(), blue: target.blue_life(),