rename ability
This commit is contained in:
parent
110616c22a
commit
f8361de6df
@ -4,7 +4,7 @@ const Game = require('./game');
|
|||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
function receiveState(state) {
|
function receiveState(state) {
|
||||||
const { game } = state;
|
const { game, account } = state;
|
||||||
// function sendCombatPve(crypId) {
|
// function sendCombatPve(crypId) {
|
||||||
// return ws.sendCombatPve(crypId);
|
// return ws.sendCombatPve(crypId);
|
||||||
// }
|
// }
|
||||||
|
|||||||
@ -1,9 +1,17 @@
|
|||||||
const preact = require('preact');
|
const preact = require('preact');
|
||||||
|
|
||||||
function GamePanel({ game }) {
|
function GamePanel({ game, sendGameAbility, account }) {
|
||||||
if (!game) return <div>...</div>;
|
if (!game) return <div>...</div>;
|
||||||
return (
|
return (
|
||||||
|
<div>
|
||||||
<div>{JSON.stringify(game)}</div>
|
<div>{JSON.stringify(game)}</div>
|
||||||
|
<button
|
||||||
|
className="button is-dark is-fullwidth"
|
||||||
|
type="submit"
|
||||||
|
onClick={() => sendCrypSpawn(name)}>
|
||||||
|
Spawn 👾
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
// return (
|
// return (
|
||||||
// <div className="">
|
// <div className="">
|
||||||
|
|||||||
@ -6,7 +6,7 @@ exports.up = async knex => {
|
|||||||
table.index('id');
|
table.index('id');
|
||||||
});
|
});
|
||||||
|
|
||||||
knex.schema.createTable('combatants', table => {
|
knex.schema.createTable('players', table => {
|
||||||
table.uuid('id').primary();
|
table.uuid('id').primary();
|
||||||
table.index('id');
|
table.index('id');
|
||||||
|
|
||||||
|
|||||||
@ -18,31 +18,31 @@ pub struct Roll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum AbilityKind {
|
pub enum Ability {
|
||||||
Attack,
|
Attack,
|
||||||
Block,
|
Block,
|
||||||
Heal,
|
Heal,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub struct Ability {
|
pub struct GameAbility {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
kind: AbilityKind,
|
ability: Ability,
|
||||||
cryp_id: Uuid,
|
cryp_id: Uuid,
|
||||||
roll: Option<Roll>,
|
roll: Option<Roll>,
|
||||||
target_cryp_id: Option<Uuid>,
|
target_cryp_id: Option<Uuid>,
|
||||||
target_team_id: Uuid,
|
target_team_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ability {
|
impl GameAbility {
|
||||||
pub fn new(cryp_id: Uuid, target_team_id: Uuid, kind: AbilityKind) -> Ability {
|
pub fn new(cryp_id: Uuid, target_team_id: Uuid, ability: Ability) -> GameAbility {
|
||||||
return Ability {
|
return GameAbility {
|
||||||
id: Uuid::new_v4(),
|
id: Uuid::new_v4(),
|
||||||
cryp_id,
|
cryp_id,
|
||||||
target_cryp_id: None,
|
target_cryp_id: None,
|
||||||
target_team_id,
|
target_team_id,
|
||||||
roll: None,
|
roll: None,
|
||||||
kind,
|
ability,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,10 +50,10 @@ impl Ability {
|
|||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
let base: u64 = rng.gen();
|
let base: u64 = rng.gen();
|
||||||
|
|
||||||
let stat = match self.kind {
|
let stat = match self.ability {
|
||||||
AbilityKind::Attack => &c.str,
|
Ability::Attack => &c.str,
|
||||||
AbilityKind::Block => &c.str,
|
Ability::Block => &c.str,
|
||||||
AbilityKind::Heal => &c.int,
|
Ability::Heal => &c.int,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut roll = Roll { base, result: base };
|
let mut roll = Roll { base, result: base };
|
||||||
@ -72,7 +72,7 @@ impl Ability {
|
|||||||
return roll;
|
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);
|
let roll = self.roll(&cryp);
|
||||||
|
|
||||||
println!("{:?} gettin clapped for {:?}", target.name, roll.result);
|
println!("{:?} gettin clapped for {:?}", target.name, roll.result);
|
||||||
@ -80,7 +80,7 @@ impl Ability {
|
|||||||
self
|
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.target_cryp_id = Some(cryp_id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ impl Ability {
|
|||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum Phase {
|
pub enum Phase {
|
||||||
Start,
|
Start,
|
||||||
Ability,
|
GameAbility,
|
||||||
Target,
|
Target,
|
||||||
Damage,
|
Damage,
|
||||||
Finish,
|
Finish,
|
||||||
@ -99,8 +99,8 @@ pub enum Phase {
|
|||||||
pub struct Team {
|
pub struct Team {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
cryps: Vec<Cryp>,
|
cryps: Vec<Cryp>,
|
||||||
abilities: Vec<Ability>,
|
abilities: Vec<GameAbility>,
|
||||||
incoming: Vec<Ability>,
|
incoming: Vec<GameAbility>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Team {
|
impl Team {
|
||||||
@ -122,7 +122,7 @@ impl Team {
|
|||||||
self.cryps.iter_mut().find(|c| c.id == id)
|
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) {
|
match self.incoming.iter_mut().find(|a| a.id == id) {
|
||||||
Some(a) => a,
|
Some(a) => a,
|
||||||
None => panic!("abiltity not in game"),
|
None => panic!("abiltity not in game"),
|
||||||
@ -216,7 +216,7 @@ impl Game {
|
|||||||
panic!("game not in damage or start phase");
|
panic!("game not in damage or start phase");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.phase = Phase::Ability;
|
self.phase = Phase::GameAbility;
|
||||||
for team in self.teams.iter_mut() {
|
for team in self.teams.iter_mut() {
|
||||||
team.abilities.clear();
|
team.abilities.clear();
|
||||||
team.incoming.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
|
// 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
|
// 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);
|
let team = self.team_by_id(team_id);
|
||||||
match team.cryp_by_id(cryp_id) {
|
match team.cryp_by_id(cryp_id) {
|
||||||
Some(c) => c,
|
Some(c) => c,
|
||||||
None => panic!("cryp not in team"),
|
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);
|
team.abilities.push(ability);
|
||||||
|
|
||||||
return ability.id;
|
return ability.id;
|
||||||
@ -245,7 +246,7 @@ impl Game {
|
|||||||
|
|
||||||
// move all abilities into their target team's targets list
|
// move all abilities into their target team's targets list
|
||||||
pub fn targets_phase_start(&mut self) -> &mut Game {
|
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");
|
panic!("game not in ability phase");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +266,7 @@ impl Game {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// targets can only be added by the owner of the team
|
// 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?
|
// whose team is this?
|
||||||
let team = self.team_by_id(team_id);
|
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<u8> = returned.get("data");
|
let game_bytes: Vec<u8> = returned.get("data");
|
||||||
let mut game = from_slice::<Game>(&game_bytes)?;
|
let mut game = from_slice::<Game>(&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);
|
return game_write(game, tx);
|
||||||
}
|
}
|
||||||
@ -508,8 +509,8 @@ mod tests {
|
|||||||
|
|
||||||
game.start();
|
game.start();
|
||||||
|
|
||||||
let x_attack_id = game.add_ability(x_team_id, x_id, y_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, AbilityKind::Attack);
|
let y_attack_id = game.add_ability(y_team_id, y_id, x_team_id, Ability::Attack);
|
||||||
|
|
||||||
assert!(game.ability_phase_finished());
|
assert!(game.ability_phase_finished());
|
||||||
|
|
||||||
@ -524,7 +525,7 @@ mod tests {
|
|||||||
|
|
||||||
game.damage_phase_start();
|
game.damage_phase_start();
|
||||||
|
|
||||||
assert!([Phase::Ability, Phase::Finish].contains(&game.phase));
|
assert!([Phase::GameAbility, Phase::Finish].contains(&game.phase));
|
||||||
|
|
||||||
println!("{:?}", game);
|
println!("{:?}", game);
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ use failure::err_msg;
|
|||||||
|
|
||||||
use net::Db;
|
use net::Db;
|
||||||
use cryp::{Cryp, cryp_spawn};
|
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 account::{Account, account_create, account_login, account_from_token, account_cryps};
|
||||||
use item::{Item, items_list, item_use};
|
use item::{Item, items_list, item_use};
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ pub struct GameAbilityParams {
|
|||||||
pub game_id: Uuid,
|
pub game_id: Uuid,
|
||||||
pub cryp_id: Uuid,
|
pub cryp_id: Uuid,
|
||||||
pub target_team_id: Uuid,
|
pub target_team_id: Uuid,
|
||||||
pub kind: AbilityKind,
|
pub ability: Ability,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user