cooldowns and linting
This commit is contained in:
parent
8be14ac546
commit
e192edfc26
@ -33,6 +33,8 @@ module.exports = {
|
|||||||
'no-plusplus': [0],
|
'no-plusplus': [0],
|
||||||
'no-await-in-loop': [0],
|
'no-await-in-loop': [0],
|
||||||
'indent': ['error', 4],
|
'indent': ['error', 4],
|
||||||
|
'keyword-spacing': ['error'],
|
||||||
|
'key-spacing': ['error'],
|
||||||
|
|
||||||
// for preact
|
// for preact
|
||||||
"react/react-in-jsx-scope": [0],
|
"react/react-in-jsx-scope": [0],
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "parcel index.html --port 40080",
|
"start": "parcel index.html --port 40080",
|
||||||
"build": "rm -rf dist && parcel build index.html",
|
"build": "rm -rf dist && parcel build index.html",
|
||||||
"lint": "eslint --fix src/",
|
"lint": "eslint --fix --ext .jsx src/",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
* skills
|
* skills
|
||||||
* offensive -> choose target ✔
|
* offensive -> choose target ✔
|
||||||
|
* private fields for opponents
|
||||||
* teach cyps skills
|
* teach cyps skills
|
||||||
* can you attack yourself?
|
* can you attack yourself?
|
||||||
* fetch existing battles
|
* fetch existing battles
|
||||||
|
|||||||
@ -9,8 +9,31 @@ use failure::err_msg;
|
|||||||
|
|
||||||
use account::Account;
|
use account::Account;
|
||||||
use rpc::{CrypSpawnParams};
|
use rpc::{CrypSpawnParams};
|
||||||
use game::Skill;
|
use skill::{Skill};
|
||||||
// use skill::{Skill};
|
|
||||||
|
type Cooldown = Option<u8>;
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
|
pub struct CrypSkill {
|
||||||
|
skill: Skill,
|
||||||
|
cd: Cooldown,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CrypSkill {
|
||||||
|
pub fn new(skill: Skill) -> CrypSkill {
|
||||||
|
let turns = match skill {
|
||||||
|
Skill::Attack => None,
|
||||||
|
Skill::Block => Some(1),
|
||||||
|
Skill::Heal => Some(2),
|
||||||
|
};
|
||||||
|
|
||||||
|
CrypSkill {
|
||||||
|
skill,
|
||||||
|
cd: turns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum Stat {
|
pub enum Stat {
|
||||||
@ -86,7 +109,7 @@ pub struct Cryp {
|
|||||||
pub hp: CrypStat,
|
pub hp: CrypStat,
|
||||||
pub xp: u64,
|
pub xp: u64,
|
||||||
pub lvl: u8,
|
pub lvl: u8,
|
||||||
pub skills: Vec<Skill>,
|
pub skills: Vec<CrypSkill>,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +131,7 @@ impl Cryp {
|
|||||||
hp: CrypStat { value: 0, stat: Stat::Hp },
|
hp: CrypStat { value: 0, stat: Stat::Hp },
|
||||||
lvl: 0,
|
lvl: 0,
|
||||||
xp: 0,
|
xp: 0,
|
||||||
skills: vec![Skill::Attack],
|
skills: vec![CrypSkill::new(Skill::Attack)],
|
||||||
name: String::new()
|
name: String::new()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -130,7 +153,7 @@ impl Cryp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn learn(mut self, s: Skill) -> Cryp {
|
pub fn learn(mut self, s: Skill) -> Cryp {
|
||||||
self.skills.push(s);
|
self.skills.push(CrypSkill::new(s));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,15 +170,6 @@ impl Cryp {
|
|||||||
self.create()
|
self.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
// pub fn turn(&self) -> Turn {
|
|
||||||
// let mut log = vec![format!("{:?}'s turn:", self.name)];
|
|
||||||
|
|
||||||
// let str = self.str.roll(self, &mut log);
|
|
||||||
// let agi = self.agi.roll(self, &mut log);
|
|
||||||
|
|
||||||
// return Turn { str, agi, log }
|
|
||||||
// }
|
|
||||||
|
|
||||||
pub fn create(mut self) -> Cryp {
|
pub fn create(mut self) -> Cryp {
|
||||||
let mut rng = thread_rng();
|
let mut rng = thread_rng();
|
||||||
let max = match self.lvl == 64 {
|
let max = match self.lvl == 64 {
|
||||||
@ -170,6 +184,7 @@ impl Cryp {
|
|||||||
self.int.set(rng.gen_range(1, max));
|
self.int.set(rng.gen_range(1, max));
|
||||||
self.stam.set(rng.gen_range(1, max));
|
self.stam.set(rng.gen_range(1, max));
|
||||||
self.hp.set(self.stam.value);
|
self.hp.set(self.stam.value);
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,11 +216,18 @@ impl Cryp {
|
|||||||
self.hp.value == 0
|
self.hp.value == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn knows(&self, skill: Skill) -> bool {
|
||||||
|
self.skills.iter().any(|s| s.skill == skill)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn has_cooldown(&self, skill: Skill) -> bool {
|
||||||
|
self.skills.iter().any(|s| s.skill == skill && s.cd.is_some())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rez(&mut self) -> &mut Cryp {
|
pub fn rez(&mut self) -> &mut Cryp {
|
||||||
self.hp.set(self.stam.value);
|
self.hp.set(self.stam.value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp, Error> {
|
pub fn cryp_get(tx: &mut Transaction, id: Uuid, account_id: Uuid) -> Result<Cryp, Error> {
|
||||||
@ -230,6 +252,8 @@ pub fn cryp_spawn(params: CrypSpawnParams, tx: &mut Transaction, account: &Accou
|
|||||||
let cryp = Cryp::new()
|
let cryp = Cryp::new()
|
||||||
.named(¶ms.name)
|
.named(¶ms.name)
|
||||||
.level(10)
|
.level(10)
|
||||||
|
.learn(Skill::Block)
|
||||||
|
.learn(Skill::Heal)
|
||||||
.set_account(account.id)
|
.set_account(account.id)
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
|
|||||||
@ -10,89 +10,14 @@ use failure::err_msg;
|
|||||||
use account::Account;
|
use account::Account;
|
||||||
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameTargetParams, GameJoinParams};
|
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameTargetParams, GameJoinParams};
|
||||||
use cryp::{Cryp, cryp_get};
|
use cryp::{Cryp, cryp_get};
|
||||||
|
use skill::{Skill, Turn};
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
|
||||||
pub struct Roll {
|
|
||||||
pub base: u64,
|
|
||||||
pub result: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
|
||||||
pub enum Skill {
|
|
||||||
Attack,
|
|
||||||
Block,
|
|
||||||
Heal,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
|
||||||
pub struct GameSkill {
|
|
||||||
id: Uuid,
|
|
||||||
skill: Skill,
|
|
||||||
cryp_id: Uuid,
|
|
||||||
roll: Option<Roll>,
|
|
||||||
target_cryp_id: Option<Uuid>,
|
|
||||||
target_team_id: Uuid,
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
skill,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn roll(&self, c: &Cryp) -> Roll {
|
|
||||||
let mut rng = thread_rng();
|
|
||||||
let base: u64 = rng.gen();
|
|
||||||
|
|
||||||
let stat = match self.skill {
|
|
||||||
Skill::Attack => &c.str,
|
|
||||||
Skill::Block => &c.str,
|
|
||||||
Skill::Heal => &c.int,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut roll = Roll { base, result: base };
|
|
||||||
|
|
||||||
// // apply skills
|
|
||||||
// roll = c.skills.iter().fold(roll, |roll, s| s.apply(roll));
|
|
||||||
|
|
||||||
// finally combine with stat
|
|
||||||
println!("{:?}'s stats", c.name);
|
|
||||||
println!("{:064b} <- finalised", roll.result);
|
|
||||||
roll.result = roll.result & stat.value;
|
|
||||||
|
|
||||||
println!("{:064b} & <- attribute roll", stat.value);
|
|
||||||
println!("{:064b} = {:?}", roll.result, roll.result);
|
|
||||||
println!("");
|
|
||||||
|
|
||||||
return roll;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
target.hp.reduce(roll.result);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut GameSkill {
|
|
||||||
self.target_cryp_id = Some(cryp_id);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Team {
|
pub struct Team {
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
cryps: Vec<Cryp>,
|
cryps: Vec<Cryp>,
|
||||||
skills: Vec<GameSkill>,
|
skills: Vec<Turn>,
|
||||||
incoming: Vec<GameSkill>,
|
incoming: Vec<Turn>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Team {
|
impl Team {
|
||||||
@ -114,7 +39,7 @@ impl Team {
|
|||||||
self.cryps.iter_mut().find(|c| c.id == id)
|
self.cryps.iter_mut().find(|c| c.id == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn skill_by_id(&mut self, id: Uuid) -> &mut GameSkill {
|
pub fn turn_by_id(&mut self, id: Uuid) -> &mut Turn {
|
||||||
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"),
|
||||||
@ -278,9 +203,13 @@ impl Game {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// check the cryp has the skill
|
// check the cryp has the skill
|
||||||
if !cryp.skills.contains(&skill) {
|
if !cryp.knows(skill) {
|
||||||
return Err(err_msg("cryp does not have that skill"));
|
return Err(err_msg("cryp does not have that skill"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cryp.has_cooldown(skill) {
|
||||||
|
return Err(err_msg("abiltity on cooldown"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace cryp skill
|
// replace cryp skill
|
||||||
@ -288,7 +217,7 @@ impl Game {
|
|||||||
team.skills.remove(s);
|
team.skills.remove(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
let skill = GameSkill::new(cryp_id, target_team_id, skill);
|
let skill = Turn::new(cryp_id, target_team_id, skill);
|
||||||
team.skills.push(skill);
|
team.skills.push(skill);
|
||||||
|
|
||||||
return Ok(skill.id);
|
return Ok(skill.id);
|
||||||
@ -338,7 +267,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
|
||||||
fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, skill_id: Uuid) -> Result<&mut GameSkill, Error> {
|
fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, skill_id: Uuid) -> Result<&mut Turn, Error> {
|
||||||
// whose team is this?
|
// whose team is this?
|
||||||
let team = self.team_by_id(team_id);
|
let team = self.team_by_id(team_id);
|
||||||
|
|
||||||
@ -349,8 +278,8 @@ impl Game {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// set the target
|
// set the target
|
||||||
let skill = team.skill_by_id(skill_id);
|
let turn = team.turn_by_id(skill_id);
|
||||||
Ok(skill.set_target(cryp_id))
|
Ok(turn.set_target(cryp_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_phase_finished(&self) -> bool {
|
fn target_phase_finished(&self) -> bool {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ extern crate serde_derive;
|
|||||||
mod cryp;
|
mod cryp;
|
||||||
mod game;
|
mod game;
|
||||||
mod net;
|
mod net;
|
||||||
// mod skill;
|
mod skill;
|
||||||
mod rpc;
|
mod rpc;
|
||||||
mod account;
|
mod account;
|
||||||
mod item;
|
mod item;
|
||||||
|
|||||||
@ -11,9 +11,10 @@ use failure::err_msg;
|
|||||||
|
|
||||||
use net::Db;
|
use net::Db;
|
||||||
use cryp::{Cryp, cryp_spawn};
|
use cryp::{Cryp, cryp_spawn};
|
||||||
use game::{Game, Skill, game_state, game_pve, game_pvp, game_join, game_skill, game_target};
|
use game::{Game, game_state, game_pve, game_pvp, game_join, 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};
|
||||||
|
use skill::{Skill};
|
||||||
|
|
||||||
pub struct Rpc;
|
pub struct Rpc;
|
||||||
|
|
||||||
|
|||||||
@ -1,40 +1,120 @@
|
|||||||
use cryp::{StatKind, Roll};
|
use rand::prelude::*;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use cryp::{Cryp};
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
|
pub struct Roll {
|
||||||
|
pub base: u64,
|
||||||
|
pub result: u64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum Skill {
|
pub enum Skill {
|
||||||
Stoney,
|
Attack,
|
||||||
Evasive,
|
Block,
|
||||||
|
Heal,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Skill {
|
|
||||||
pub fn apply(&self, roll: Roll) -> Roll {
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
match self {
|
pub struct Turn {
|
||||||
Skill::Stoney => stoney(self, roll),
|
pub id: Uuid,
|
||||||
Skill::Evasive => evasive(self, roll),
|
pub skill: Skill,
|
||||||
|
pub cryp_id: Uuid,
|
||||||
|
pub roll: Option<Roll>,
|
||||||
|
pub target_cryp_id: Option<Uuid>,
|
||||||
|
pub target_team_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Turn {
|
||||||
|
pub fn new(cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> Turn {
|
||||||
|
return Turn {
|
||||||
|
id: Uuid::new_v4(),
|
||||||
|
cryp_id,
|
||||||
|
target_cryp_id: None,
|
||||||
|
target_team_id,
|
||||||
|
roll: None,
|
||||||
|
skill,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn roll(&self, c: &Cryp) -> Roll {
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
let base: u64 = rng.gen();
|
||||||
|
|
||||||
|
let stat = match self.skill {
|
||||||
|
Skill::Attack => &c.str,
|
||||||
|
Skill::Block => &c.str,
|
||||||
|
Skill::Heal => &c.int,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut roll = Roll { base, result: base };
|
||||||
|
|
||||||
|
// // apply skills
|
||||||
|
// roll = c.skills.iter().fold(roll, |roll, s| s.apply(roll));
|
||||||
|
|
||||||
|
// finally combine with stat
|
||||||
|
println!("{:?}'s stats", c.name);
|
||||||
|
println!("{:064b} <- finalised", roll.result);
|
||||||
|
roll.result = roll.result & stat.value;
|
||||||
|
|
||||||
|
println!("{:064b} & <- attribute roll", stat.value);
|
||||||
|
println!("{:064b} = {:?}", roll.result, roll.result);
|
||||||
|
println!("");
|
||||||
|
|
||||||
|
return roll;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Turn {
|
||||||
|
let roll = self.roll(&cryp);
|
||||||
|
|
||||||
|
println!("{:?} gettin clapped for {:?}", target.name, roll.result);
|
||||||
|
target.hp.reduce(roll.result);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut Turn {
|
||||||
|
self.target_cryp_id = Some(cryp_id);
|
||||||
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stoney(_s: &Skill, mut roll: Roll) -> Roll {
|
// #[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
let effect = 0b11110000;
|
// pub enum Skill {
|
||||||
match roll.kind {
|
// Stoney,
|
||||||
StatKind::Def => {
|
// Evasive,
|
||||||
// println!("{:064b} | <- {:?}", effect, s);
|
// }
|
||||||
roll.result = roll.result | effect;
|
|
||||||
roll
|
|
||||||
},
|
|
||||||
_ => roll,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn evasive(_s: &Skill, mut roll: Roll) -> Roll {
|
// impl Skill {
|
||||||
match roll.kind {
|
// pub fn apply(&self, roll: Roll) -> Roll {
|
||||||
StatKind::Def => {
|
// match self {
|
||||||
if roll.result.is_power_of_two() {
|
// Skill::Stoney => stoney(self, roll),
|
||||||
roll.result = u64::max_value()
|
// Skill::Evasive => evasive(self, roll),
|
||||||
}
|
// }
|
||||||
roll
|
// }
|
||||||
},
|
// }
|
||||||
_ => roll,
|
|
||||||
}
|
// fn stoney(_s: &Skill, mut roll: Roll) -> Roll {
|
||||||
}
|
// let effect = 0b11110000;
|
||||||
|
// match roll.kind {
|
||||||
|
// StatKind::Def => {
|
||||||
|
// // println!("{:064b} | <- {:?}", effect, s);
|
||||||
|
// roll.result = roll.result | effect;
|
||||||
|
// roll
|
||||||
|
// },
|
||||||
|
// _ => roll,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn evasive(_s: &Skill, mut roll: Roll) -> Roll {
|
||||||
|
// match roll.kind {
|
||||||
|
// StatKind::Def => {
|
||||||
|
// if roll.result.is_power_of_two() {
|
||||||
|
// roll.result = u64::max_value()
|
||||||
|
// }
|
||||||
|
// roll
|
||||||
|
// },
|
||||||
|
// _ => roll,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
Loading…
x
Reference in New Issue
Block a user