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