diff --git a/client/src/components/game.container.js b/client/src/components/game.container.js index a76f91a1..a61292e1 100644 --- a/client/src/components/game.container.js +++ b/client/src/components/game.container.js @@ -4,7 +4,7 @@ const Game = require('./game'); const addState = connect( function receiveState(state) { - const { game } = state; + const { game, account } = state; // function sendCombatPve(crypId) { // return ws.sendCombatPve(crypId); // } diff --git a/client/src/components/game.jsx b/client/src/components/game.jsx index b0de4346..8e3af7c1 100644 --- a/client/src/components/game.jsx +++ b/client/src/components/game.jsx @@ -1,9 +1,17 @@ const preact = require('preact'); -function GamePanel({ game }) { +function GamePanel({ game, sendGameAbility, account }) { if (!game) return
...
; return ( -
{JSON.stringify(game)}
+
+
{JSON.stringify(game)}
+ +
) // return ( //
diff --git a/ops/migrations/20181020104420_games.js b/ops/migrations/20181020104420_games.js index 5658bc09..b31fb6b8 100644 --- a/ops/migrations/20181020104420_games.js +++ b/ops/migrations/20181020104420_games.js @@ -6,7 +6,7 @@ exports.up = async knex => { table.index('id'); }); - knex.schema.createTable('combatants', table => { + knex.schema.createTable('players', table => { table.uuid('id').primary(); table.index('id'); diff --git a/server/src/game.rs b/server/src/game.rs index 654feab5..0d274add 100755 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -18,31 +18,31 @@ pub struct Roll { } #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] -pub enum AbilityKind { +pub enum Ability { Attack, Block, Heal, } #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] -pub struct Ability { +pub struct GameAbility { id: Uuid, - kind: AbilityKind, + ability: Ability, cryp_id: Uuid, roll: Option, target_cryp_id: Option, target_team_id: Uuid, } -impl Ability { - pub fn new(cryp_id: Uuid, target_team_id: Uuid, kind: AbilityKind) -> Ability { - return Ability { +impl GameAbility { + pub fn new(cryp_id: Uuid, target_team_id: Uuid, ability: Ability) -> GameAbility { + return GameAbility { id: Uuid::new_v4(), cryp_id, target_cryp_id: None, target_team_id, roll: None, - kind, + ability, }; } @@ -50,10 +50,10 @@ impl Ability { let mut rng = thread_rng(); let base: u64 = rng.gen(); - let stat = match self.kind { - AbilityKind::Attack => &c.str, - AbilityKind::Block => &c.str, - AbilityKind::Heal => &c.int, + let stat = match self.ability { + Ability::Attack => &c.str, + Ability::Block => &c.str, + Ability::Heal => &c.int, }; let mut roll = Roll { base, result: base }; @@ -72,7 +72,7 @@ impl Ability { return roll; } - pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Ability { + pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut GameAbility { let roll = self.roll(&cryp); println!("{:?} gettin clapped for {:?}", target.name, roll.result); @@ -80,7 +80,7 @@ impl Ability { self } - pub fn set_target(&mut self, cryp_id: Uuid) -> &mut Ability { + pub fn set_target(&mut self, cryp_id: Uuid) -> &mut GameAbility { self.target_cryp_id = Some(cryp_id); self } @@ -89,7 +89,7 @@ impl Ability { #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] pub enum Phase { Start, - Ability, + GameAbility, Target, Damage, Finish, @@ -99,8 +99,8 @@ pub enum Phase { pub struct Team { id: Uuid, cryps: Vec, - abilities: Vec, - incoming: Vec, + abilities: Vec, + incoming: Vec, } impl Team { @@ -122,7 +122,7 @@ impl Team { self.cryps.iter_mut().find(|c| c.id == id) } - pub fn ability_by_id(&mut self, id: Uuid) -> &mut Ability { + pub fn ability_by_id(&mut self, id: Uuid) -> &mut GameAbility { match self.incoming.iter_mut().find(|a| a.id == id) { Some(a) => a, None => panic!("abiltity not in game"), @@ -216,7 +216,7 @@ impl Game { panic!("game not in damage or start phase"); } - self.phase = Phase::Ability; + self.phase = Phase::GameAbility; for team in self.teams.iter_mut() { team.abilities.clear(); team.incoming.clear(); @@ -226,14 +226,15 @@ impl Game { // abilities can target any team, but we have to check if the caller is the owner of the cryp // and that the cryp has the ability they are trying to add - pub fn add_ability(&mut self, team_id: Uuid, cryp_id: Uuid, target_team_id: Uuid, kind: AbilityKind) -> Uuid { + pub fn add_ability(&mut self, team_id: Uuid, cryp_id: Uuid, target_team_id: Uuid, ability: Ability) -> Uuid { let team = self.team_by_id(team_id); match team.cryp_by_id(cryp_id) { Some(c) => c, None => panic!("cryp not in team"), }; - let ability = Ability::new(cryp_id, target_team_id, kind); + // TODO check cryp has ability + let ability = GameAbility::new(cryp_id, target_team_id, ability); team.abilities.push(ability); return ability.id; @@ -245,7 +246,7 @@ impl Game { // move all abilities into their target team's targets list pub fn targets_phase_start(&mut self) -> &mut Game { - if self.phase != Phase::Ability { + if self.phase != Phase::GameAbility { panic!("game not in ability phase"); } @@ -265,7 +266,7 @@ impl Game { } // targets can only be added by the owner of the team - pub fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, ability_id: Uuid) -> &mut Ability { + pub fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, ability_id: Uuid) -> &mut GameAbility { // whose team is this? let team = self.team_by_id(team_id); @@ -352,7 +353,7 @@ pub fn game_ability(params: GameAbilityParams, tx: &mut Transaction, account: &A let game_bytes: Vec = returned.get("data"); let mut game = from_slice::(&game_bytes)?; - game.add_ability(account.id, params.cryp_id, params.target_team_id, params.kind); + game.add_ability(account.id, params.cryp_id, params.target_team_id, params.ability); return game_write(game, tx); } @@ -508,8 +509,8 @@ mod tests { game.start(); - let x_attack_id = game.add_ability(x_team_id, x_id, y_team_id, AbilityKind::Attack); - let y_attack_id = game.add_ability(y_team_id, y_id, x_team_id, AbilityKind::Attack); + let x_attack_id = game.add_ability(x_team_id, x_id, y_team_id, Ability::Attack); + let y_attack_id = game.add_ability(y_team_id, y_id, x_team_id, Ability::Attack); assert!(game.ability_phase_finished()); @@ -524,7 +525,7 @@ mod tests { game.damage_phase_start(); - assert!([Phase::Ability, Phase::Finish].contains(&game.phase)); + assert!([Phase::GameAbility, Phase::Finish].contains(&game.phase)); println!("{:?}", game); diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 63a49cf4..65fa4dbe 100755 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -11,7 +11,7 @@ use failure::err_msg; use net::Db; use cryp::{Cryp, cryp_spawn}; -use game::{Game, AbilityKind, game_pve, game_ability}; +use game::{Game, Ability, game_pve, game_ability}; use account::{Account, account_create, account_login, account_from_token, account_cryps}; use item::{Item, items_list, item_use}; @@ -238,7 +238,7 @@ pub struct GameAbilityParams { pub game_id: Uuid, pub cryp_id: Uuid, pub target_team_id: Uuid, - pub kind: AbilityKind, + pub ability: Ability, } #[derive(Debug,Clone,Serialize,Deserialize)]