Merge branch 'master' of ssh://mnml.gg:40022/~/mnml
This commit is contained in:
commit
9e32822036
@ -40,7 +40,6 @@ hatred maybe
|
||||
|
||||
reconnect based on time delta
|
||||
|
||||
remove rounds
|
||||
consolidate game and instance
|
||||
|
||||
do not allow vbox actions for finished instances
|
||||
|
||||
@ -46,7 +46,7 @@ function TeamFooter(args) {
|
||||
<button
|
||||
disabled={team.some(c => !c)}
|
||||
onClick={() => navToList()}>
|
||||
Join Instance
|
||||
Confirm
|
||||
</button>
|
||||
</footer>
|
||||
);
|
||||
|
||||
@ -204,7 +204,7 @@ pub struct Construct {
|
||||
pub green_power: ConstructStat,
|
||||
pub speed: ConstructStat,
|
||||
pub green_life: ConstructStat,
|
||||
pub evasion: ConstructStat,
|
||||
// pub evasion: ConstructStat,
|
||||
pub skills: Vec<ConstructSkill>,
|
||||
pub effects: Vec<ConstructEffect>,
|
||||
pub specs: Vec<Spec>,
|
||||
@ -225,7 +225,7 @@ impl Construct {
|
||||
green_power: ConstructStat { base: 256, value: 256, max: 256, stat: Stat::GreenPower },
|
||||
green_life: ConstructStat { base: 1024, value: 1024, max: 1024, stat: Stat::GreenLife },
|
||||
speed: ConstructStat { base: 128, value: 128, max: 128, stat: Stat::Speed },
|
||||
evasion: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::Evasion },
|
||||
// evasion: ConstructStat { base: 0, value: 0, max: 0, stat: Stat::Evasion },
|
||||
skills: vec![],
|
||||
effects: vec![],
|
||||
specs: vec![],
|
||||
@ -295,7 +295,7 @@ impl Construct {
|
||||
self.red_life.recalculate(&self.specs, &self.colours, player_colours);
|
||||
self.blue_power.recalculate(&self.specs, &self.colours, player_colours);
|
||||
self.blue_life.recalculate(&self.specs, &self.colours, player_colours);
|
||||
self.evasion.recalculate(&self.specs, &self.colours, player_colours);
|
||||
// self.evasion.recalculate(&self.specs, &self.colours, player_colours);
|
||||
self.speed.recalculate(&self.specs, &self.colours, player_colours);
|
||||
self.green_power.recalculate(&self.specs, &self.colours, player_colours);
|
||||
self.green_life.recalculate(&self.specs, &self.colours, player_colours);
|
||||
@ -799,6 +799,26 @@ impl Construct {
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn construct_delete(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<(), Error> {
|
||||
let query = "
|
||||
DELETE
|
||||
FROM constructs
|
||||
WHERE id = $1;
|
||||
and account = $2;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
.execute(query, &[&id, &account_id])?;
|
||||
|
||||
if result != 1 {
|
||||
return Err(format_err!("unable to delete construct {:?}", id));
|
||||
}
|
||||
|
||||
info!("construct deleted {:?}", id);
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn construct_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Construct, Error> {
|
||||
let query = "
|
||||
SELECT data
|
||||
|
||||
@ -80,9 +80,10 @@ impl Instance {
|
||||
max_rounds: 5,
|
||||
name: String::new(),
|
||||
password: None,
|
||||
phase_end: Utc::now(),
|
||||
phase_start: Utc::now(),
|
||||
|
||||
phase_end: Utc::now()
|
||||
.checked_add_signed(Duration::minutes(5))
|
||||
.expect("could not set phase end"),
|
||||
format: Format::Standard,
|
||||
}
|
||||
}
|
||||
@ -118,6 +119,12 @@ impl Instance {
|
||||
}
|
||||
|
||||
pub fn upkeep(mut self) -> (Instance, Vec<Game>) {
|
||||
// time out lobbies that have been open too long
|
||||
if self.phase == InstancePhase::Lobby && self.phase_timed_out() {
|
||||
self.finish();
|
||||
return (self, vec![]);
|
||||
}
|
||||
|
||||
if self.phase != InstancePhase::InProgress {
|
||||
return (self, vec![]);
|
||||
}
|
||||
@ -562,7 +569,8 @@ pub fn instance_list(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
let query = "
|
||||
SELECT data, id
|
||||
FROM instances
|
||||
WHERE open = true;
|
||||
WHERE open = true
|
||||
AND finished = false;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
@ -590,7 +598,6 @@ pub fn instances_need_upkeep(tx: &mut Transaction) -> Result<Vec<Instance>, Erro
|
||||
SELECT data, id
|
||||
FROM instances
|
||||
WHERE finished = false
|
||||
AND open = false
|
||||
AND upkeep < now()
|
||||
FOR UPDATE;
|
||||
";
|
||||
@ -664,6 +671,8 @@ pub fn instance_ready(params: InstanceReadyParams, tx: &mut Transaction, account
|
||||
pub fn instance_state(params: InstanceStateParams, tx: &mut Transaction, _account: &Account) -> Result<RpcResult, Error> {
|
||||
let instance = instance_get(tx, params.instance_id)?;
|
||||
|
||||
println!("{:#?}", instance);
|
||||
|
||||
if let Some(game_id) = instance.current_game_id() {
|
||||
let game = game_get(tx, game_id)?;
|
||||
|
||||
@ -793,4 +802,22 @@ mod tests {
|
||||
|
||||
// info!("{:#?}", instance);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instance_upkeep_idle_lobby_test() {
|
||||
let mut instance = Instance::new();
|
||||
|
||||
let player_account = Uuid::new_v4();
|
||||
let constructs = instance_mobs(player_account);
|
||||
let player = Player::new(player_account, &"a".to_string(), constructs);
|
||||
let _a_id = player.id;
|
||||
|
||||
instance.add_player(player).expect("could not add player");
|
||||
assert!(!instance.can_start());
|
||||
|
||||
instance.phase_end = Utc::now().checked_sub_signed(Duration::minutes(61)).unwrap();
|
||||
let (instance, _new_games) = instance.upkeep();
|
||||
|
||||
assert!(instance.finished());
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,6 +175,20 @@ impl Rpc {
|
||||
Ok(construct_list)
|
||||
}
|
||||
|
||||
fn construct_delete(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<ConstructDeleteMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
construct_delete(msg.params.id, tx, &account)?;
|
||||
|
||||
let construct_list = RpcResponse {
|
||||
method: "account_constructs".to_string(),
|
||||
params: RpcResult::ConstructList(account_constructs(tx, &account)?)
|
||||
};
|
||||
|
||||
Ok(construct_list)
|
||||
}
|
||||
|
||||
|
||||
fn account_create(data: Vec<u8>, tx: &mut Transaction, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<AccountCreateMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
@ -413,39 +427,14 @@ pub struct ConstructSpawnParams {
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct ConstructLearnMsg {
|
||||
struct ConstructDeleteMsg {
|
||||
method: String,
|
||||
params: ConstructLearnParams,
|
||||
params: ConstructDeleteParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct ConstructLearnParams {
|
||||
pub struct ConstructDeleteParams {
|
||||
pub id: Uuid,
|
||||
pub skill: Skill,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct ConstructForgetParams {
|
||||
pub id: Uuid,
|
||||
pub skill: Skill,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct ConstructForgetMsg {
|
||||
method: String,
|
||||
params: ConstructForgetParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct ConstructUnspecParams {
|
||||
pub id: Uuid,
|
||||
pub spec: Spec,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct ConstructUnspecMsg {
|
||||
method: String,
|
||||
params: ConstructUnspecParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
@ -459,17 +448,6 @@ pub struct GameStateParams {
|
||||
pub id: Uuid,
|
||||
}
|
||||
|
||||
// #[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
// struct GamePveMsg {
|
||||
// method: String,
|
||||
// params: GamePveParams,
|
||||
// }
|
||||
|
||||
// #[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
// pub struct GamePveParams {
|
||||
// pub construct_ids: Vec<Uuid>,
|
||||
// }
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct GameSkillMsg {
|
||||
method: String,
|
||||
@ -562,17 +540,6 @@ pub struct InstanceStateParams {
|
||||
pub instance_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct PlayerConstructsSetMsg {
|
||||
method: String,
|
||||
params: PlayerConstructsSetParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct PlayerConstructsSetParams {
|
||||
pub construct_ids: Vec<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct VboxAcceptMsg {
|
||||
method: String,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user