rename ability to skill

This commit is contained in:
ntr 2018-10-21 12:05:07 +11:00
parent 3a4c9e4971
commit c3d20e888b
7 changed files with 85 additions and 83 deletions

View File

@ -5,15 +5,15 @@ const Game = require('./game');
const addState = connect( const addState = connect(
function receiveState(state) { function receiveState(state) {
const { ws, game, account } = state; const { ws, game, account } = state;
function sendGameAbility(crypId, targetTeamId, ability) { function sendGameSkill(crypId, targetTeamId, skill) {
return ws.sendGameAbility(game.id, crypId, targetTeamId, ability); return ws.sendGameSkill(game.id, crypId, targetTeamId, skill);
} }
function sendGameTarget(crypId, abilityId) { function sendGameTarget(crypId, skillId) {
return ws.sendGameTarget(game.id, crypId, abilityId); return ws.sendGameTarget(game.id, crypId, skillId);
} }
return { game, account, sendGameAbility, sendGameTarget }; return { game, account, sendGameSkill, sendGameTarget };
} }
); );

View File

@ -1,6 +1,6 @@
const preact = require('preact'); const preact = require('preact');
function GamePanel({ game, sendGameAbility, sendGameTarget, account }) { function GamePanel({ game, sendGameSkill, sendGameTarget, account }) {
if (!game) return <div>...</div>; if (!game) return <div>...</div>;
const otherTeams = game.teams.filter(t => t.id !== account.id); const otherTeams = game.teams.filter(t => t.id !== account.id);
@ -23,7 +23,7 @@ function GamePanel({ game, sendGameAbility, sendGameTarget, account }) {
<button <button
className="button is-dark is-fullwidth" className="button is-dark is-fullwidth"
type="submit" type="submit"
onClick={() => sendGameAbility(c.id, otherTeams[0].id, 'Attack')}> onClick={() => sendGameSkill(c.id, otherTeams[0].id, 'Attack')}>
Attack Attack
</button> </button>
</div> </div>

View File

@ -113,12 +113,12 @@ function createSocket(store) {
send({ method: 'game_pve', params: { id } }); send({ method: 'game_pve', params: { id } });
} }
function sendGameAbility(gameId, crypId, targetTeamId, ability) { function sendGameSkill(gameId, crypId, targetTeamId, skill) {
send({ method: 'game_ability', params: { game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, ability } }); send({ method: 'game_skill', params: { game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, skill } });
} }
function sendGameTarget(gameId, crypId, abilityId) { function sendGameTarget(gameId, crypId, skillId) {
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, ability_id: abilityId } }); send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, skill_id: skillId } });
} }
function sendItemUse(item, target) { function sendItemUse(item, target) {
@ -162,7 +162,7 @@ function createSocket(store) {
sendAccountLogin, sendAccountLogin,
sendAccountRegister, sendAccountRegister,
sendGamePve, sendGamePve,
sendGameAbility, sendGameSkill,
sendGameTarget, sendGameTarget,
sendCrypSpawn, sendCrypSpawn,
sendItemUse, sendItemUse,

View File

@ -26,8 +26,10 @@
* skills * skills
* offensive -> choose target ✔ * offensive -> choose target ✔
* check for cryp ability already used * teach cyps skills
* check for cryp ability ownership * fetch existing battles
* check for cryp skill already used
* check for cryp skill ownership
* check for game participation * check for game participation
* write players row for every team+cryp added * write players row for every team+cryp added
@ -91,7 +93,7 @@ gem td style attr combinations
* 4: Make use of piggybacking * 4: Make use of piggybacking
* 5: Don't confuse "interesting" with "fun" * 5: Don't confuse "interesting" with "fun"
* 6: Understand what emotion your game is trying to evoke * 6: Understand what emotion your game is trying to evoke
* 7: Allow the players the ability to make the game personal * 7: Allow the players the skill to make the game personal
* 8: The details are where the players fall in love with your game * 8: The details are where the players fall in love with your game
* 9: Allow your players to have a sense of ownership * 9: Allow your players to have a sense of ownership
* 10: Leave room for the player to explore * 10: Leave room for the player to explore

View File

@ -229,7 +229,7 @@ pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp
pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> { pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Account) -> Result<Cryp, Error> {
let cryp = Cryp::new() let cryp = Cryp::new()
.named(&params.name) .named(&params.name)
.level(1) .level(10)
.set_account(account.id) .set_account(account.id)
.create(); .create();

View File

@ -8,7 +8,7 @@ use failure::Error;
use failure::err_msg; use failure::err_msg;
use account::Account; use account::Account;
use rpc::{GameAbilityParams, GamePveParams, GameTargetParams}; use rpc::{GameSkillParams, GamePveParams, GameTargetParams};
use cryp::{Cryp, CrypStat, Stat}; use cryp::{Cryp, CrypStat, Stat};
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
@ -18,31 +18,31 @@ pub struct Roll {
} }
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Ability { pub enum Skill {
Attack, Attack,
Block, Block,
Heal, Heal,
} }
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub struct GameAbility { pub struct GameSkill {
id: Uuid, id: Uuid,
ability: Ability, skill: Skill,
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 GameAbility { impl GameSkill {
pub fn new(cryp_id: Uuid, target_team_id: Uuid, ability: Ability) -> GameAbility { pub fn new(cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> GameSkill {
return GameAbility { return GameSkill {
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,
ability, skill,
}; };
} }
@ -50,10 +50,10 @@ impl GameAbility {
let mut rng = thread_rng(); let mut rng = thread_rng();
let base: u64 = rng.gen(); let base: u64 = rng.gen();
let stat = match self.ability { let stat = match self.skill {
Ability::Attack => &c.str, Skill::Attack => &c.str,
Ability::Block => &c.str, Skill::Block => &c.str,
Ability::Heal => &c.int, Skill::Heal => &c.int,
}; };
let mut roll = Roll { base, result: base }; let mut roll = Roll { base, result: base };
@ -72,7 +72,7 @@ impl GameAbility {
return roll; return roll;
} }
pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut GameAbility { pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut GameSkill {
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 GameAbility {
self self
} }
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut GameAbility { pub fn set_target(&mut self, cryp_id: Uuid) -> &mut GameSkill {
self.target_cryp_id = Some(cryp_id); self.target_cryp_id = Some(cryp_id);
self self
} }
@ -90,8 +90,8 @@ impl GameAbility {
pub struct Team { pub struct Team {
id: Uuid, id: Uuid,
cryps: Vec<Cryp>, cryps: Vec<Cryp>,
abilities: Vec<GameAbility>, skills: Vec<GameSkill>,
incoming: Vec<GameAbility>, incoming: Vec<GameSkill>,
} }
impl Team { impl Team {
@ -99,7 +99,7 @@ impl Team {
return Team { return Team {
id: account, id: account,
cryps: vec![], cryps: vec![],
abilities: vec![], skills: vec![],
incoming: vec![], incoming: vec![],
}; };
} }
@ -113,7 +113,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 GameAbility { pub fn skill_by_id(&mut self, id: Uuid) -> &mut GameSkill {
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"),
@ -124,7 +124,7 @@ impl Team {
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)] #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
pub enum Phase { pub enum Phase {
Start, Start,
Ability, Skill,
Target, Target,
Damage, Damage,
Finish, Finish,
@ -207,29 +207,29 @@ impl Game {
} }
pub fn start(&mut self) -> &mut Game { pub fn start(&mut self) -> &mut Game {
self.ability_phase_start(); self.skill_phase_start();
self self
} }
pub fn ability_phase_start(&mut self) -> &mut Game { pub fn skill_phase_start(&mut self) -> &mut Game {
if ![Phase::Start, Phase::Damage].contains(&self.phase) { if ![Phase::Start, Phase::Damage].contains(&self.phase) {
panic!("game not in damage or start phase"); panic!("game not in damage or start phase");
} }
self.phase = Phase::Ability; self.phase = Phase::Skill;
for team in self.teams.iter_mut() { for team in self.teams.iter_mut() {
team.abilities.clear(); team.skills.clear();
team.incoming.clear(); team.incoming.clear();
} }
if self.is_pve { if self.is_pve {
self.pve_add_abilities(); self.pve_add_skills();
} }
self self
} }
fn pve_add_abilities(&mut self) -> &mut Game { fn pve_add_skills(&mut self) -> &mut Game {
{ {
let mob_team_id = Uuid::nil(); let mob_team_id = Uuid::nil();
let teams = self.teams.clone(); let teams = self.teams.clone();
@ -237,16 +237,16 @@ impl Game {
// TODO attack multiple players based on some criteria // TODO attack multiple players based on some criteria
let player_team = teams.iter().find(|t| t.id != mob_team_id).unwrap(); let player_team = teams.iter().find(|t| t.id != mob_team_id).unwrap();
for mob in &mobs.cryps { for mob in &mobs.cryps {
self.add_ability(mob_team_id, mob.id, player_team.id, Ability::Attack); self.add_skill(mob_team_id, mob.id, player_team.id, Skill::Attack);
} }
} }
self self
} }
// abilities can target any team, but we have to check if the caller is the owner of the cryp // skills 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 skill they are trying to add
pub fn add_ability(&mut self, team_id: Uuid, cryp_id: Uuid, target_team_id: Uuid, ability: Ability) -> Uuid { pub fn add_skill(&mut self, team_id: Uuid, cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> 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,
@ -254,22 +254,22 @@ impl Game {
}; };
// TODO check cryp ownership // TODO check cryp ownership
// TODO check cryp ability already used // TODO check cryp skill already used
// TODO check cryp has ability // TODO check cryp has skill
let ability = GameAbility::new(cryp_id, target_team_id, ability); let skill = GameSkill::new(cryp_id, target_team_id, skill);
team.abilities.push(ability); team.skills.push(skill);
return ability.id; return skill.id;
} }
pub fn ability_phase_finished(&self) -> bool { pub fn skill_phase_finished(&self) -> bool {
self.teams.iter().all(|t| t.abilities.len() == self.team_size) self.teams.iter().all(|t| t.skills.len() == self.team_size)
} }
// move all abilities into their target team's targets list // move all skills into their target team's targets list
pub fn target_phase_start(&mut self) -> &mut Game { pub fn target_phase_start(&mut self) -> &mut Game {
if self.phase != Phase::Ability { if self.phase != Phase::Skill {
panic!("game not in ability phase"); panic!("game not in skill phase");
} }
self.phase = Phase::Target; self.phase = Phase::Target;
@ -278,9 +278,9 @@ impl Game {
let teams = self.teams.clone(); let teams = self.teams.clone();
for mut team in teams { for mut team in teams {
for ability in team.abilities.iter_mut() { for skill in team.skills.iter_mut() {
let target_team = self.team_by_id(ability.target_team_id); let target_team = self.team_by_id(skill.target_team_id);
target_team.incoming.push(*ability); target_team.incoming.push(*skill);
} }
} }
@ -306,7 +306,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 GameAbility { pub fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, skill_id: Uuid) -> &mut GameSkill {
// whose team is this? // whose team is this?
let team = self.team_by_id(team_id); let team = self.team_by_id(team_id);
@ -317,8 +317,8 @@ impl Game {
}; };
// set the target // set the target
let ability = team.ability_by_id(ability_id); let skill = team.skill_by_id(skill_id);
ability.set_target(cryp_id) skill.set_target(cryp_id)
} }
pub fn target_phase_finished(&self) -> bool { pub fn target_phase_finished(&self) -> bool {
@ -334,18 +334,18 @@ impl Game {
self.phase = Phase::Damage; self.phase = Phase::Damage;
self.resolve_abilities(); self.resolve_skills();
if self.is_finished() { if self.is_finished() {
return self.finish() return self.finish()
} }
self.ability_phase_start(); self.skill_phase_start();
self self
} }
fn resolve_abilities(&mut self) -> &mut Game { fn resolve_skills(&mut self) -> &mut Game {
if self.phase != Phase::Damage { if self.phase != Phase::Damage {
panic!("game not in damage phase"); panic!("game not in damage phase");
} }
@ -371,7 +371,7 @@ impl Game {
self.phase = Phase::Finish; self.phase = Phase::Finish;
for team in self.teams.iter_mut() { for team in self.teams.iter_mut() {
team.abilities.clear(); team.skills.clear();
team.incoming.clear(); team.incoming.clear();
} }
@ -379,7 +379,7 @@ impl Game {
} }
} }
pub fn game_ability(params: GameAbilityParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> { pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let query = " let query = "
SELECT * SELECT *
FROM games FROM games
@ -398,9 +398,9 @@ 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.ability); game.add_skill(account.id, params.cryp_id, params.target_team_id, params.skill);
if game.ability_phase_finished() { if game.skill_phase_finished() {
game.target_phase_start(); game.target_phase_start();
} }
@ -426,7 +426,7 @@ pub fn game_target(params: GameTargetParams, tx: &mut Transaction, account: &Acc
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_target(account.id, params.cryp_id, params.ability_id); game.add_target(account.id, params.cryp_id, params.skill_id);
if game.target_phase_finished() { if game.target_phase_finished() {
game.damage_phase_start(); game.damage_phase_start();
@ -617,10 +617,10 @@ mod tests {
game.start(); game.start();
let x_attack_id = game.add_ability(x_team_id, x_id, y_team_id, Ability::Attack); let x_attack_id = game.add_skill(x_team_id, x_id, y_team_id, Skill::Attack);
let y_attack_id = game.add_ability(y_team_id, y_id, x_team_id, Ability::Attack); let y_attack_id = game.add_skill(y_team_id, y_id, x_team_id, Skill::Attack);
assert!(game.ability_phase_finished()); assert!(game.skill_phase_finished());
game.target_phase_start(); game.target_phase_start();
@ -633,7 +633,7 @@ mod tests {
game.damage_phase_start(); game.damage_phase_start();
assert!([Phase::Ability, Phase::Finish].contains(&game.phase)); assert!([Phase::Skill, Phase::Finish].contains(&game.phase));
println!("{:?}", game); println!("{:?}", game);

View File

@ -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, Ability, game_pve, game_ability, game_target}; use game::{Game, Skill, game_pve, game_skill, game_target};
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};
@ -39,7 +39,7 @@ impl Rpc {
let response = match v.method.as_ref() { let response = match v.method.as_ref() {
"cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account, client), "cryp_spawn" => Rpc::cryp_spawn(data, &mut tx, account, client),
"game_pve" => Rpc::game_pve(data, &mut tx, account, client), "game_pve" => Rpc::game_pve(data, &mut tx, account, client),
"game_ability" => Rpc::game_ability(data, &mut tx, account, client), "game_skill" => Rpc::game_skill(data, &mut tx, account, client),
"game_target" => Rpc::game_target(data, &mut tx, account, client), "game_target" => Rpc::game_target(data, &mut tx, account, client),
"account_create" => Rpc::account_create(data, &mut tx, account, client), "account_create" => Rpc::account_create(data, &mut tx, account, client),
"account_login" => Rpc::account_login(data, &mut tx, account, client), "account_login" => Rpc::account_login(data, &mut tx, account, client),
@ -87,17 +87,17 @@ impl Rpc {
return Ok(game_response); return Ok(game_response);
} }
fn game_ability(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> { fn game_skill(data: Vec<u8>, tx: &mut Transaction, account: Option<Account>, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let a = match account { let a = match account {
Some(a) => a, Some(a) => a,
None => return Err(err_msg("auth required")), None => return Err(err_msg("auth required")),
}; };
let msg = from_slice::<GameAbilityMsg>(&data).or(Err(err_msg("invalid params")))?; let msg = from_slice::<GameSkillMsg>(&data).or(Err(err_msg("invalid params")))?;
let game_response = RpcResponse { let game_response = RpcResponse {
method: "game_state".to_string(), method: "game_state".to_string(),
params: RpcResult::GameState(game_ability(msg.params, tx, &a)?) params: RpcResult::GameState(game_skill(msg.params, tx, &a)?)
}; };
// Rpc::send_msg(client, RpcResponse { // Rpc::send_msg(client, RpcResponse {
@ -260,21 +260,21 @@ struct GameTargetMsg {
pub struct GameTargetParams { pub struct GameTargetParams {
pub game_id: Uuid, pub game_id: Uuid,
pub cryp_id: Uuid, pub cryp_id: Uuid,
pub ability_id: Uuid, pub skill_id: Uuid,
} }
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]
struct GameAbilityMsg { struct GameSkillMsg {
method: String, method: String,
params: GameAbilityParams, params: GameSkillParams,
} }
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]
pub struct GameAbilityParams { pub struct GameSkillParams {
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 ability: Ability, pub skill: Skill,
} }
#[derive(Debug,Clone,Serialize,Deserialize)] #[derive(Debug,Clone,Serialize,Deserialize)]