rename ability to skill
This commit is contained in:
parent
3a4c9e4971
commit
c3d20e888b
@ -5,15 +5,15 @@ const Game = require('./game');
|
||||
const addState = connect(
|
||||
function receiveState(state) {
|
||||
const { ws, game, account } = state;
|
||||
function sendGameAbility(crypId, targetTeamId, ability) {
|
||||
return ws.sendGameAbility(game.id, crypId, targetTeamId, ability);
|
||||
function sendGameSkill(crypId, targetTeamId, skill) {
|
||||
return ws.sendGameSkill(game.id, crypId, targetTeamId, skill);
|
||||
}
|
||||
|
||||
function sendGameTarget(crypId, abilityId) {
|
||||
return ws.sendGameTarget(game.id, crypId, abilityId);
|
||||
function sendGameTarget(crypId, skillId) {
|
||||
return ws.sendGameTarget(game.id, crypId, skillId);
|
||||
}
|
||||
|
||||
return { game, account, sendGameAbility, sendGameTarget };
|
||||
return { game, account, sendGameSkill, sendGameTarget };
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
const preact = require('preact');
|
||||
|
||||
function GamePanel({ game, sendGameAbility, sendGameTarget, account }) {
|
||||
function GamePanel({ game, sendGameSkill, sendGameTarget, account }) {
|
||||
if (!game) return <div>...</div>;
|
||||
|
||||
const otherTeams = game.teams.filter(t => t.id !== account.id);
|
||||
@ -23,7 +23,7 @@ function GamePanel({ game, sendGameAbility, sendGameTarget, account }) {
|
||||
<button
|
||||
className="button is-dark is-fullwidth"
|
||||
type="submit"
|
||||
onClick={() => sendGameAbility(c.id, otherTeams[0].id, 'Attack')}>
|
||||
onClick={() => sendGameSkill(c.id, otherTeams[0].id, 'Attack')}>
|
||||
Attack
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@ -113,12 +113,12 @@ function createSocket(store) {
|
||||
send({ method: 'game_pve', params: { id } });
|
||||
}
|
||||
|
||||
function sendGameAbility(gameId, crypId, targetTeamId, ability) {
|
||||
send({ method: 'game_ability', params: { game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, ability } });
|
||||
function sendGameSkill(gameId, crypId, targetTeamId, skill) {
|
||||
send({ method: 'game_skill', params: { game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, skill } });
|
||||
}
|
||||
|
||||
function sendGameTarget(gameId, crypId, abilityId) {
|
||||
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, ability_id: abilityId } });
|
||||
function sendGameTarget(gameId, crypId, skillId) {
|
||||
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, skill_id: skillId } });
|
||||
}
|
||||
|
||||
function sendItemUse(item, target) {
|
||||
@ -162,7 +162,7 @@ function createSocket(store) {
|
||||
sendAccountLogin,
|
||||
sendAccountRegister,
|
||||
sendGamePve,
|
||||
sendGameAbility,
|
||||
sendGameSkill,
|
||||
sendGameTarget,
|
||||
sendCrypSpawn,
|
||||
sendItemUse,
|
||||
|
||||
@ -26,8 +26,10 @@
|
||||
|
||||
* skills
|
||||
* offensive -> choose target ✔
|
||||
* check for cryp ability already used
|
||||
* check for cryp ability ownership
|
||||
* teach cyps skills
|
||||
* fetch existing battles
|
||||
* check for cryp skill already used
|
||||
* check for cryp skill ownership
|
||||
* check for game participation
|
||||
* write players row for every team+cryp added
|
||||
|
||||
@ -91,7 +93,7 @@ gem td style attr combinations
|
||||
* 4: Make use of piggybacking
|
||||
* 5: Don't confuse "interesting" with "fun"
|
||||
* 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
|
||||
* 9: Allow your players to have a sense of ownership
|
||||
* 10: Leave room for the player to explore
|
||||
|
||||
@ -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> {
|
||||
let cryp = Cryp::new()
|
||||
.named(¶ms.name)
|
||||
.level(1)
|
||||
.level(10)
|
||||
.set_account(account.id)
|
||||
.create();
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ use failure::Error;
|
||||
use failure::err_msg;
|
||||
|
||||
use account::Account;
|
||||
use rpc::{GameAbilityParams, GamePveParams, GameTargetParams};
|
||||
use rpc::{GameSkillParams, GamePveParams, GameTargetParams};
|
||||
use cryp::{Cryp, CrypStat, Stat};
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
@ -18,31 +18,31 @@ pub struct Roll {
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
pub enum Ability {
|
||||
pub enum Skill {
|
||||
Attack,
|
||||
Block,
|
||||
Heal,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
pub struct GameAbility {
|
||||
pub struct GameSkill {
|
||||
id: Uuid,
|
||||
ability: Ability,
|
||||
skill: Skill,
|
||||
cryp_id: Uuid,
|
||||
roll: Option<Roll>,
|
||||
target_cryp_id: Option<Uuid>,
|
||||
target_team_id: Uuid,
|
||||
}
|
||||
|
||||
impl GameAbility {
|
||||
pub fn new(cryp_id: Uuid, target_team_id: Uuid, ability: Ability) -> GameAbility {
|
||||
return GameAbility {
|
||||
impl GameSkill {
|
||||
pub fn new(cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> GameSkill {
|
||||
return GameSkill {
|
||||
id: Uuid::new_v4(),
|
||||
cryp_id,
|
||||
target_cryp_id: None,
|
||||
target_team_id,
|
||||
roll: None,
|
||||
ability,
|
||||
skill,
|
||||
};
|
||||
}
|
||||
|
||||
@ -50,10 +50,10 @@ impl GameAbility {
|
||||
let mut rng = thread_rng();
|
||||
let base: u64 = rng.gen();
|
||||
|
||||
let stat = match self.ability {
|
||||
Ability::Attack => &c.str,
|
||||
Ability::Block => &c.str,
|
||||
Ability::Heal => &c.int,
|
||||
let stat = match self.skill {
|
||||
Skill::Attack => &c.str,
|
||||
Skill::Block => &c.str,
|
||||
Skill::Heal => &c.int,
|
||||
};
|
||||
|
||||
let mut roll = Roll { base, result: base };
|
||||
@ -72,7 +72,7 @@ impl GameAbility {
|
||||
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);
|
||||
|
||||
println!("{:?} gettin clapped for {:?}", target.name, roll.result);
|
||||
@ -80,7 +80,7 @@ impl GameAbility {
|
||||
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
|
||||
}
|
||||
@ -90,8 +90,8 @@ impl GameAbility {
|
||||
pub struct Team {
|
||||
id: Uuid,
|
||||
cryps: Vec<Cryp>,
|
||||
abilities: Vec<GameAbility>,
|
||||
incoming: Vec<GameAbility>,
|
||||
skills: Vec<GameSkill>,
|
||||
incoming: Vec<GameSkill>,
|
||||
}
|
||||
|
||||
impl Team {
|
||||
@ -99,7 +99,7 @@ impl Team {
|
||||
return Team {
|
||||
id: account,
|
||||
cryps: vec![],
|
||||
abilities: vec![],
|
||||
skills: vec![],
|
||||
incoming: vec![],
|
||||
};
|
||||
}
|
||||
@ -113,7 +113,7 @@ impl Team {
|
||||
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) {
|
||||
Some(a) => a,
|
||||
None => panic!("abiltity not in game"),
|
||||
@ -124,7 +124,7 @@ impl Team {
|
||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||
pub enum Phase {
|
||||
Start,
|
||||
Ability,
|
||||
Skill,
|
||||
Target,
|
||||
Damage,
|
||||
Finish,
|
||||
@ -207,29 +207,29 @@ impl Game {
|
||||
}
|
||||
|
||||
pub fn start(&mut self) -> &mut Game {
|
||||
self.ability_phase_start();
|
||||
self.skill_phase_start();
|
||||
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) {
|
||||
panic!("game not in damage or start phase");
|
||||
}
|
||||
|
||||
self.phase = Phase::Ability;
|
||||
self.phase = Phase::Skill;
|
||||
for team in self.teams.iter_mut() {
|
||||
team.abilities.clear();
|
||||
team.skills.clear();
|
||||
team.incoming.clear();
|
||||
}
|
||||
|
||||
if self.is_pve {
|
||||
self.pve_add_abilities();
|
||||
self.pve_add_skills();
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn pve_add_abilities(&mut self) -> &mut Game {
|
||||
fn pve_add_skills(&mut self) -> &mut Game {
|
||||
{
|
||||
let mob_team_id = Uuid::nil();
|
||||
let teams = self.teams.clone();
|
||||
@ -237,16 +237,16 @@ impl Game {
|
||||
// TODO attack multiple players based on some criteria
|
||||
let player_team = teams.iter().find(|t| t.id != mob_team_id).unwrap();
|
||||
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
|
||||
}
|
||||
|
||||
// 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, ability: Ability) -> Uuid {
|
||||
// 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 skill they are trying to add
|
||||
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);
|
||||
match team.cryp_by_id(cryp_id) {
|
||||
Some(c) => c,
|
||||
@ -254,22 +254,22 @@ impl Game {
|
||||
};
|
||||
|
||||
// TODO check cryp ownership
|
||||
// TODO check cryp ability already used
|
||||
// TODO check cryp has ability
|
||||
let ability = GameAbility::new(cryp_id, target_team_id, ability);
|
||||
team.abilities.push(ability);
|
||||
// TODO check cryp skill already used
|
||||
// TODO check cryp has skill
|
||||
let skill = GameSkill::new(cryp_id, target_team_id, skill);
|
||||
team.skills.push(skill);
|
||||
|
||||
return ability.id;
|
||||
return skill.id;
|
||||
}
|
||||
|
||||
pub fn ability_phase_finished(&self) -> bool {
|
||||
self.teams.iter().all(|t| t.abilities.len() == self.team_size)
|
||||
pub fn skill_phase_finished(&self) -> bool {
|
||||
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 {
|
||||
if self.phase != Phase::Ability {
|
||||
panic!("game not in ability phase");
|
||||
if self.phase != Phase::Skill {
|
||||
panic!("game not in skill phase");
|
||||
}
|
||||
|
||||
self.phase = Phase::Target;
|
||||
@ -278,9 +278,9 @@ impl Game {
|
||||
let teams = self.teams.clone();
|
||||
|
||||
for mut team in teams {
|
||||
for ability in team.abilities.iter_mut() {
|
||||
let target_team = self.team_by_id(ability.target_team_id);
|
||||
target_team.incoming.push(*ability);
|
||||
for skill in team.skills.iter_mut() {
|
||||
let target_team = self.team_by_id(skill.target_team_id);
|
||||
target_team.incoming.push(*skill);
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,7 +306,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 GameAbility {
|
||||
pub fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, skill_id: Uuid) -> &mut GameSkill {
|
||||
// whose team is this?
|
||||
let team = self.team_by_id(team_id);
|
||||
|
||||
@ -317,8 +317,8 @@ impl Game {
|
||||
};
|
||||
|
||||
// set the target
|
||||
let ability = team.ability_by_id(ability_id);
|
||||
ability.set_target(cryp_id)
|
||||
let skill = team.skill_by_id(skill_id);
|
||||
skill.set_target(cryp_id)
|
||||
}
|
||||
|
||||
pub fn target_phase_finished(&self) -> bool {
|
||||
@ -334,18 +334,18 @@ impl Game {
|
||||
|
||||
self.phase = Phase::Damage;
|
||||
|
||||
self.resolve_abilities();
|
||||
self.resolve_skills();
|
||||
|
||||
if self.is_finished() {
|
||||
return self.finish()
|
||||
}
|
||||
|
||||
self.ability_phase_start();
|
||||
self.skill_phase_start();
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
fn resolve_abilities(&mut self) -> &mut Game {
|
||||
fn resolve_skills(&mut self) -> &mut Game {
|
||||
if self.phase != Phase::Damage {
|
||||
panic!("game not in damage phase");
|
||||
}
|
||||
@ -371,7 +371,7 @@ impl Game {
|
||||
self.phase = Phase::Finish;
|
||||
|
||||
for team in self.teams.iter_mut() {
|
||||
team.abilities.clear();
|
||||
team.skills.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 = "
|
||||
SELECT *
|
||||
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 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();
|
||||
}
|
||||
|
||||
@ -426,7 +426,7 @@ pub fn game_target(params: GameTargetParams, tx: &mut Transaction, account: &Acc
|
||||
let game_bytes: Vec<u8> = returned.get("data");
|
||||
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() {
|
||||
game.damage_phase_start();
|
||||
@ -617,10 +617,10 @@ mod tests {
|
||||
|
||||
game.start();
|
||||
|
||||
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);
|
||||
let x_attack_id = game.add_skill(x_team_id, x_id, y_team_id, Skill::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();
|
||||
|
||||
@ -633,7 +633,7 @@ mod tests {
|
||||
|
||||
game.damage_phase_start();
|
||||
|
||||
assert!([Phase::Ability, Phase::Finish].contains(&game.phase));
|
||||
assert!([Phase::Skill, Phase::Finish].contains(&game.phase));
|
||||
|
||||
println!("{:?}", game);
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ use failure::err_msg;
|
||||
|
||||
use net::Db;
|
||||
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 item::{Item, items_list, item_use};
|
||||
|
||||
@ -39,7 +39,7 @@ impl Rpc {
|
||||
let response = match v.method.as_ref() {
|
||||
"cryp_spawn" => Rpc::cryp_spawn(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),
|
||||
"account_create" => Rpc::account_create(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);
|
||||
}
|
||||
|
||||
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 {
|
||||
Some(a) => a,
|
||||
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 {
|
||||
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 {
|
||||
@ -260,21 +260,21 @@ struct GameTargetMsg {
|
||||
pub struct GameTargetParams {
|
||||
pub game_id: Uuid,
|
||||
pub cryp_id: Uuid,
|
||||
pub ability_id: Uuid,
|
||||
pub skill_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct GameAbilityMsg {
|
||||
struct GameSkillMsg {
|
||||
method: String,
|
||||
params: GameAbilityParams,
|
||||
params: GameSkillParams,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
pub struct GameAbilityParams {
|
||||
pub struct GameSkillParams {
|
||||
pub game_id: Uuid,
|
||||
pub cryp_id: Uuid,
|
||||
pub target_team_id: Uuid,
|
||||
pub ability: Ability,
|
||||
pub skill: Skill,
|
||||
}
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user