fixerup
This commit is contained in:
parent
e48031a2a5
commit
8dfc9c8bbf
@ -1,5 +1,6 @@
|
||||
# FIXME
|
||||
|
||||
game ready not auto starting resolve phase
|
||||
remove immunity
|
||||
banish dmg
|
||||
aoe event
|
||||
|
||||
@ -57,9 +57,9 @@ pub struct Game {
|
||||
pub stack: Vec<Cast>,
|
||||
pub events: Vec<Vec<Event>>,
|
||||
pub instance: Option<Uuid>,
|
||||
time_control: TimeControl,
|
||||
phase_start: DateTime<Utc>,
|
||||
phase_end: Option<DateTime<Utc>>,
|
||||
pub time_control: TimeControl,
|
||||
pub phase_start: DateTime<Utc>,
|
||||
pub phase_end: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
@ -285,7 +285,7 @@ impl Game {
|
||||
self
|
||||
}
|
||||
|
||||
fn add_skill(&mut self, player_id: Uuid, source: Uuid, target: Uuid, skill: Skill) -> Result<&mut Game, Error> {
|
||||
pub fn add_skill(&mut self, player_id: Uuid, source: Uuid, target: Uuid, skill: Skill) -> Result<&mut Game, Error> {
|
||||
// check player in game
|
||||
self.player_by_id(player_id)?;
|
||||
|
||||
@ -343,7 +343,7 @@ impl Game {
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
fn offer_draw(mut self, player_id: Uuid) -> Result<Game, Error> {
|
||||
pub fn offer_draw(mut self, player_id: Uuid) -> Result<Game, Error> {
|
||||
if self.phase != Phase::Skill {
|
||||
return Err(err_msg("game not in skill phase"));
|
||||
}
|
||||
@ -367,7 +367,7 @@ impl Game {
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
fn concede(mut self, player_id: Uuid) -> Result<Game, Error> {
|
||||
pub fn concede(mut self, player_id: Uuid) -> Result<Game, Error> {
|
||||
if self.phase != Phase::Skill {
|
||||
return Err(err_msg("game not in skill phase"));
|
||||
}
|
||||
@ -379,7 +379,7 @@ impl Game {
|
||||
}
|
||||
|
||||
|
||||
fn clear_skill(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
|
||||
pub fn clear_skill(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
|
||||
self.player_by_id(player_id)?;
|
||||
if self.phase != Phase::Skill {
|
||||
return Err(err_msg("game not in skill phase"));
|
||||
@ -390,7 +390,7 @@ impl Game {
|
||||
return Ok(self);
|
||||
}
|
||||
|
||||
fn player_ready(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
|
||||
pub fn player_ready(&mut self, player_id: Uuid) -> Result<&mut Game, Error> {
|
||||
if self.phase != Phase::Skill {
|
||||
return Err(err_msg("game not in skill phase"));
|
||||
}
|
||||
@ -401,7 +401,7 @@ impl Game {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn skill_phase_finished(&self) -> bool {
|
||||
pub fn skill_phase_finished(&self) -> bool {
|
||||
self.players.iter().all(|t| t.ready)
|
||||
// self.players.iter()
|
||||
// // for every player
|
||||
@ -413,7 +413,7 @@ impl Game {
|
||||
// )
|
||||
}
|
||||
|
||||
fn resolve_phase_start(mut self) -> Game {
|
||||
pub fn resolve_phase_start(mut self) -> Game {
|
||||
if self.phase != Phase::Skill {
|
||||
panic!("game not in skill phase");
|
||||
}
|
||||
@ -722,11 +722,11 @@ mod tests {
|
||||
|
||||
let x_player_id = Uuid::new_v4();
|
||||
x.account = x_player_id;
|
||||
let x_player = Player::new(x_player_id, &"ntr".to_string(), vec![x]);
|
||||
let x_player = Player::new(x_player_id, None, &"ntr".to_string(), vec![x]);
|
||||
|
||||
let y_player_id = Uuid::new_v4();
|
||||
y.account = y_player_id;
|
||||
let y_player = Player::new(y_player_id, &"mash".to_string(), vec![y]);
|
||||
let y_player = Player::new(y_player_id, None, &"mash".to_string(), vec![y]);
|
||||
|
||||
game
|
||||
.player_add(x_player).unwrap()
|
||||
@ -767,12 +767,12 @@ mod tests {
|
||||
let i_player_id = Uuid::new_v4();
|
||||
i.account = i_player_id;
|
||||
j.account = i_player_id;
|
||||
let i_player = Player::new(i_player_id, &"ntr".to_string(), vec![i, j]);
|
||||
let i_player = Player::new(i_player_id, None, &"ntr".to_string(), vec![i, j]);
|
||||
|
||||
let x_player_id = Uuid::new_v4();
|
||||
x.account = x_player_id;
|
||||
y.account = x_player_id;
|
||||
let x_player = Player::new(x_player_id, &"mashy".to_string(), vec![x, y]);
|
||||
let x_player = Player::new(x_player_id, None, &"mashy".to_string(), vec![x, y]);
|
||||
|
||||
game
|
||||
.player_add(i_player).unwrap()
|
||||
|
||||
@ -99,14 +99,14 @@ pub struct Instance {
|
||||
time_control: TimeControl,
|
||||
|
||||
phase: InstancePhase,
|
||||
phase_end: Option<DateTime<Utc>>,
|
||||
phase_start: DateTime<Utc>,
|
||||
pub phase_end: Option<DateTime<Utc>>,
|
||||
pub phase_start: DateTime<Utc>,
|
||||
|
||||
winner: Option<Uuid>,
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
fn new() -> Instance {
|
||||
pub fn new() -> Instance {
|
||||
Instance {
|
||||
id: Uuid::new_v4(),
|
||||
players: vec![],
|
||||
@ -170,7 +170,7 @@ impl Instance {
|
||||
(self, new_game)
|
||||
}
|
||||
|
||||
fn set_name(mut self, name: String) -> Result<Instance, Error> {
|
||||
pub fn set_name(mut self, name: String) -> Result<Instance, Error> {
|
||||
if name.len() == 0 {
|
||||
return Err(err_msg("name must have a length"));
|
||||
}
|
||||
@ -179,12 +179,12 @@ impl Instance {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn set_time_control(mut self, tc: TimeControl) -> Instance {
|
||||
pub fn set_time_control(mut self, tc: TimeControl) -> Instance {
|
||||
self.time_control = tc;
|
||||
self
|
||||
}
|
||||
|
||||
fn add_player(&mut self, player: Player) -> Result<&mut Instance, Error> {
|
||||
pub fn add_player(&mut self, player: Player) -> Result<&mut Instance, Error> {
|
||||
if self.players.len() >= self.max_players {
|
||||
return Err(err_msg("game full"))
|
||||
}
|
||||
@ -198,7 +198,7 @@ impl Instance {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
fn player_ready(&mut self, player_id: Uuid) -> Result<Option<Game>, Error> {
|
||||
pub fn player_ready(&mut self, player_id: Uuid) -> Result<Option<Game>, Error> {
|
||||
if ![InstancePhase::InProgress, InstancePhase::Lobby].contains(&self.phase) {
|
||||
return Err(err_msg("instance not in start or vbox phase"));
|
||||
}
|
||||
@ -300,7 +300,7 @@ impl Instance {
|
||||
self.next_round()
|
||||
}
|
||||
|
||||
fn next_round(&mut self) -> &mut Instance {
|
||||
pub fn next_round(&mut self) -> &mut Instance {
|
||||
if self.finish_condition() {
|
||||
return self.finish();
|
||||
}
|
||||
@ -342,7 +342,7 @@ impl Instance {
|
||||
self
|
||||
}
|
||||
|
||||
fn finished(&self) -> bool {
|
||||
pub fn finished(&self) -> bool {
|
||||
self.phase == InstancePhase::Finished
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ impl Instance {
|
||||
self
|
||||
}
|
||||
|
||||
fn current_game_id(&self) -> Option<Uuid> {
|
||||
pub fn current_game_id(&self) -> Option<Uuid> {
|
||||
if self.phase != InstancePhase::InProgress {
|
||||
return None;
|
||||
}
|
||||
@ -386,7 +386,7 @@ impl Instance {
|
||||
return current_round.game_id;
|
||||
}
|
||||
|
||||
fn game_finished(&mut self, game: &Game) -> Result<&mut Instance, Error> {
|
||||
pub fn game_finished(&mut self, game: &Game) -> Result<&mut Instance, Error> {
|
||||
{
|
||||
let current_round = self.rounds
|
||||
.iter_mut()
|
||||
@ -428,14 +428,14 @@ impl Instance {
|
||||
}
|
||||
|
||||
// PLAYER ACTIONS
|
||||
fn account_player(&mut self, account: Uuid) -> Result<&mut Player, Error> {
|
||||
pub fn account_player(&mut self, account: Uuid) -> Result<&mut Player, Error> {
|
||||
self.players
|
||||
.iter_mut()
|
||||
.find(|p| p.id == account)
|
||||
.ok_or(err_msg("account not in instance"))
|
||||
}
|
||||
|
||||
fn account_opponent(&mut self, account: Uuid) -> Result<&mut Player, Error> {
|
||||
pub fn account_opponent(&mut self, account: Uuid) -> Result<&mut Player, Error> {
|
||||
self.players
|
||||
.iter_mut()
|
||||
.find(|p| p.id != account)
|
||||
@ -529,7 +529,7 @@ mod tests {
|
||||
let _instance = Instance::new();
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let _player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let _player = Player::new(player_account, None, &"test".to_string(), constructs).set_bot(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -540,7 +540,7 @@ mod tests {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let player = Player::new(player_account, None, &"a".to_string(), constructs);
|
||||
let a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
@ -548,7 +548,7 @@ mod tests {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"b".to_string(), constructs);
|
||||
let player = Player::new(player_account, None, &"b".to_string(), constructs);
|
||||
let b_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
@ -577,7 +577,7 @@ mod tests {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let player = Player::new(player_account, None, &"a".to_string(), constructs);
|
||||
let a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
@ -585,7 +585,7 @@ mod tests {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"b".to_string(), constructs);
|
||||
let player = Player::new(player_account, None, &"b".to_string(), constructs);
|
||||
let b_id = player.id;
|
||||
instance.add_player(player).expect("could not add player");
|
||||
|
||||
@ -617,7 +617,7 @@ mod tests {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let player = Player::new(player_account, None, &"a".to_string(), constructs);
|
||||
let _a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
|
||||
@ -25,6 +25,6 @@ pub fn instance_mobs(player_id: Uuid) -> Vec<Construct> {
|
||||
pub fn bot_player() -> Player {
|
||||
let bot_id = Uuid::new_v4();
|
||||
let constructs = instance_mobs(bot_id);
|
||||
Player::new(bot_id, &name(), constructs).set_bot(true)
|
||||
Player::new(bot_id, None, &name(), constructs).set_bot(true)
|
||||
}
|
||||
|
||||
|
||||
@ -66,10 +66,10 @@ pub struct Player {
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new(account: Uuid, name: &String, constructs: Vec<Construct>) -> Player {
|
||||
pub fn new(account: Uuid, img: Option<Uuid>, name: &String, constructs: Vec<Construct>) -> Player {
|
||||
Player {
|
||||
id: account,
|
||||
img: Some(account),
|
||||
img,
|
||||
name: name.clone(),
|
||||
vbox: Vbox::new(),
|
||||
constructs,
|
||||
@ -401,7 +401,7 @@ mod tests {
|
||||
fn player_bot_vbox_test() {
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let mut player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let mut player = Player::new(player_account, None, &"test".to_string(), constructs).set_bot(true);
|
||||
|
||||
player.vbox.fill();
|
||||
player.autobuy();
|
||||
@ -413,7 +413,7 @@ mod tests {
|
||||
fn player_score_test() {
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let mut player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let mut player = Player::new(player_account, None, &"test".to_string(), constructs).set_bot(true);
|
||||
|
||||
player.score = player.score.add_win(&Score::Zero);
|
||||
player.score = player.score.add_win(&Score::Zero);
|
||||
|
||||
@ -13,7 +13,7 @@ use failure::{err_msg, format_err};
|
||||
|
||||
use mnml_core::construct::{Construct, ConstructSkeleton};
|
||||
use mnml_core::instance::{Instance};
|
||||
use mnml_core::instance;
|
||||
use mnml_core::player::{Player};
|
||||
|
||||
use http::MnmlHttpError;
|
||||
use names::{name as generate_name};
|
||||
@ -33,6 +33,19 @@ pub struct Account {
|
||||
pub subscribed: bool,
|
||||
}
|
||||
|
||||
impl Account {
|
||||
pub fn to_player(&self, tx: &mut Transaction) -> Result<Player, Error> {
|
||||
let constructs = team(tx, self)?;
|
||||
|
||||
let img = match self.subscribed {
|
||||
true => Some(self.img),
|
||||
false => None,
|
||||
};
|
||||
|
||||
Ok(Player::new(self.id, Some(self.img), &self.name, constructs))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<postgres::rows::Row<'a>> for Account {
|
||||
type Error = Error;
|
||||
|
||||
|
||||
@ -679,7 +679,7 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result<Inst
|
||||
.set_time_control(TimeControl::Practice)
|
||||
.set_name(bot.name.clone())?;
|
||||
|
||||
let player = Player::from_account(tx, account)?;
|
||||
let player = account.to_player(tx)?;
|
||||
|
||||
instance.add_player(player.clone())?;
|
||||
instance.add_player(bot)?;
|
||||
@ -702,7 +702,7 @@ pub fn pvp(tx: &mut Transaction, a: &Account, b: &Account) -> Result<Instance, E
|
||||
instance = instance_create(tx, instance)?;
|
||||
|
||||
for account in [a, b].iter() {
|
||||
let acc_p = Player::from_account(tx, &account)?;
|
||||
let acc_p = account.to_player(tx)?;
|
||||
let player = player_create(tx, acc_p, instance.id, account)?;
|
||||
instance.add_player(player)?;
|
||||
}
|
||||
@ -795,7 +795,7 @@ pub fn bot_instance() -> Instance {
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"test".to_string(), constructs).set_bot(true);
|
||||
let player = Player::new(player_account, None, &"test".to_string(), constructs).set_bot(true);
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
instance.player_ready(player_account).unwrap();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user