stuns and statuses
This commit is contained in:
parent
7ff281c140
commit
89445a0b65
@ -55,6 +55,12 @@ function GamePanel(props) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const statuses = cryp.statuses.map((status, i) => {
|
||||||
|
return (
|
||||||
|
<div key={i}>{status} for {status.turns}T</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
if (activeIncoming) console.log('should be a pointer');
|
if (activeIncoming) console.log('should be a pointer');
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@ -81,6 +87,7 @@ function GamePanel(props) {
|
|||||||
<div className="has-text-centered">{cryp.xp} / {Math.pow(2,cryp.lvl+1)} XP </div>
|
<div className="has-text-centered">{cryp.xp} / {Math.pow(2,cryp.lvl+1)} XP </div>
|
||||||
<progress className="progress is-dark" value={cryp.xp} max={Math.pow(2,cryp.lvl+1)}></progress>
|
<progress className="progress is-dark" value={cryp.xp} max={Math.pow(2,cryp.lvl+1)}></progress>
|
||||||
</div>
|
</div>
|
||||||
|
{statuses}
|
||||||
{skills}
|
{skills}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -97,6 +104,12 @@ function GamePanel(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function OpponentCrypCard(cryp) {
|
function OpponentCrypCard(cryp) {
|
||||||
|
const statuses = cryp.statuses.map((status, i) => {
|
||||||
|
return (
|
||||||
|
<div key={i}>{status.status} for {status.turns}T</div>
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={cryp.id} className="tile is-vertical">
|
<div key={cryp.id} className="tile is-vertical">
|
||||||
<div className="tile is-child">
|
<div className="tile is-child">
|
||||||
@ -119,6 +132,7 @@ function GamePanel(props) {
|
|||||||
<progress className="progress is-dark" value={cryp.xp} max={Math.pow(2,cryp.lvl+1)}></progress>
|
<progress className="progress is-dark" value={cryp.xp} max={Math.pow(2,cryp.lvl+1)}></progress>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
{statuses}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,7 +140,7 @@ function createSocket(store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendGameTarget(gameId, crypId, skillId) {
|
function sendGameTarget(gameId, crypId, skillId) {
|
||||||
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, skill_id: skillId } });
|
send({ method: 'game_target', params: { game_id: gameId, cryp_id: crypId, cast_id: skillId } });
|
||||||
store.dispatch(actions.setActiveIncoming(null));
|
store.dispatch(actions.setActiveIncoming(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use failure::err_msg;
|
|||||||
|
|
||||||
use account::Account;
|
use account::Account;
|
||||||
use rpc::{CrypSpawnParams};
|
use rpc::{CrypSpawnParams};
|
||||||
use skill::{Skill};
|
use skill::{Skill, Roll};
|
||||||
|
|
||||||
type Cooldown = Option<u8>;
|
type Cooldown = Option<u8>;
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ impl CrypSkill {
|
|||||||
Skill::Block => Some(1),
|
Skill::Block => Some(1),
|
||||||
Skill::Dodge => Some(1),
|
Skill::Dodge => Some(1),
|
||||||
Skill::Heal => Some(2),
|
Skill::Heal => Some(2),
|
||||||
Skill::Stun => Some(2),
|
Skill::Stun => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
CrypSkill {
|
CrypSkill {
|
||||||
@ -35,7 +35,10 @@ impl CrypSkill {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_usable(&self, cryp: &Cryp) -> bool {
|
fn can_cast(&self, cryp: &Cryp) -> bool {
|
||||||
|
if cryp.is_stunned() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,7 +55,6 @@ pub struct CrypStatus {
|
|||||||
turns: u8,
|
turns: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum Stat {
|
pub enum Stat {
|
||||||
Str,
|
Str,
|
||||||
@ -62,13 +64,6 @@ pub enum Stat {
|
|||||||
Stam,
|
Stam,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
|
||||||
pub struct Roll {
|
|
||||||
pub base: u64,
|
|
||||||
pub result: u64,
|
|
||||||
pub kind: Stat,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub struct CrypStat {
|
pub struct CrypStat {
|
||||||
pub value: u64,
|
pub value: u64,
|
||||||
@ -87,12 +82,6 @@ impl CrypStat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Turn {
|
|
||||||
pub str: Roll,
|
|
||||||
pub agi: Roll,
|
|
||||||
pub log: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
pub struct Cryp {
|
pub struct Cryp {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
@ -189,22 +178,70 @@ impl Cryp {
|
|||||||
self.hp.value == 0
|
self.hp.value == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_stunned(&self) -> bool {
|
||||||
|
self.statuses.iter().any(|s| s.status == Status::Stunned)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn available_skills(&self) -> Vec<&CrypSkill> {
|
pub fn available_skills(&self) -> Vec<&CrypSkill> {
|
||||||
self.skills.iter().filter(|s| s.is_usable(self)).collect()
|
self.skills.iter().filter(|s| s.can_cast(self)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn knows(&self, skill: Skill) -> bool {
|
pub fn knows(&self, skill: Skill) -> bool {
|
||||||
self.skills.iter().any(|s| s.skill == skill)
|
self.skills.iter().any(|s| s.skill == skill)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_cooldown(&self, skill: Skill) -> bool {
|
pub fn skill_on_cd(&self, skill: Skill) -> bool {
|
||||||
self.skills.iter().any(|s| s.skill == skill && s.cd.is_some())
|
self.skills.iter().any(|s| s.skill == skill && s.cd.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn skill_can_cast(&self, skill: Skill) -> bool {
|
||||||
|
self.skills.iter().any(|s| s.skill == skill && !s.can_cast(self))
|
||||||
|
}
|
||||||
|
|
||||||
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 roll(&self, skill: Skill) -> Roll {
|
||||||
|
let mut rng = thread_rng();
|
||||||
|
let base: u64 = rng.gen();
|
||||||
|
|
||||||
|
let stat = match skill {
|
||||||
|
Skill::Attack => self.str,
|
||||||
|
Skill::Block => self.str,
|
||||||
|
Skill::Stun => self.str,
|
||||||
|
Skill::Dodge => self.agi,
|
||||||
|
Skill::Heal => self.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", self.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 stun(&mut self, roll: Roll) -> &mut Cryp {
|
||||||
|
self.statuses.push(CrypStatus { status: Status::Stunned, turns: 1 });
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn attack(&mut self, roll: Roll) -> &mut Cryp {
|
||||||
|
self.hp.reduce(roll.result);
|
||||||
|
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> {
|
||||||
@ -229,8 +266,7 @@ 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::Stun)
|
||||||
.learn(Skill::Heal)
|
|
||||||
.set_account(account.id)
|
.set_account(account.id)
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
|
|||||||
@ -10,14 +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};
|
use skill::{Skill, Cast};
|
||||||
|
|
||||||
#[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<Turn>,
|
skills: Vec<Cast>,
|
||||||
incoming: Vec<Turn>,
|
incoming: Vec<Cast>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Team {
|
impl Team {
|
||||||
@ -31,7 +31,9 @@ impl Team {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn skills_required(&self) -> usize {
|
fn skills_required(&self) -> usize {
|
||||||
self.cryps.iter().filter(|c| c.available_skills().len() > 0).collect::<Vec<&Cryp>>().len()
|
let required = self.cryps.iter().filter(|c| c.available_skills().len() > 0).collect::<Vec<&Cryp>>().len();
|
||||||
|
println!("{:?} requires {:?} skills this turn", self.id, required);
|
||||||
|
return required;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_cryps(&mut self, cryps: Vec<Cryp>) -> &mut Team {
|
pub fn set_cryps(&mut self, cryps: Vec<Cryp>) -> &mut Team {
|
||||||
@ -43,7 +45,7 @@ impl Team {
|
|||||||
self.cryps.iter_mut().find(|c| c.id == id)
|
self.cryps.iter_mut().find(|c| c.id == id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn turn_by_id(&mut self, id: Uuid) -> &mut Turn {
|
pub fn cast_by_id(&mut self, id: Uuid) -> &mut Cast {
|
||||||
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"),
|
||||||
@ -184,7 +186,8 @@ 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_skill(mob_team_id, mob.id, player_team.id, Skill::Attack).unwrap();
|
// doesn't matter if the cryp can't cast
|
||||||
|
self.add_skill(mob_team_id, mob.id, player_team.id, Skill::Attack).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,9 +214,13 @@ impl Game {
|
|||||||
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) {
|
if cryp.skill_on_cd(skill) {
|
||||||
return Err(err_msg("abiltity on cooldown"));
|
return Err(err_msg("abiltity on cooldown"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cryp.skill_can_cast(skill) {
|
||||||
|
return Err(err_msg("cryp cannot cast spell"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace cryp skill
|
// replace cryp skill
|
||||||
@ -221,7 +228,7 @@ impl Game {
|
|||||||
team.skills.remove(s);
|
team.skills.remove(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
let skill = Turn::new(cryp_id, target_team_id, skill);
|
let skill = Cast::new(cryp_id, target_team_id, skill);
|
||||||
team.skills.push(skill);
|
team.skills.push(skill);
|
||||||
|
|
||||||
return Ok(skill.id);
|
return Ok(skill.id);
|
||||||
@ -253,6 +260,11 @@ impl Game {
|
|||||||
self.pve_add_targets();
|
self.pve_add_targets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// all cryps are stunned or otherwise inactive
|
||||||
|
if self.target_phase_finished() {
|
||||||
|
self.damage_phase_start();
|
||||||
|
}
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +283,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 Turn, Error> {
|
fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, cast_id: Uuid) -> Result<&mut Cast, 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);
|
||||||
|
|
||||||
@ -282,8 +294,8 @@ impl Game {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// set the target
|
// set the target
|
||||||
let turn = team.turn_by_id(skill_id);
|
let cast = team.cast_by_id(cast_id);
|
||||||
Ok(turn.set_target(cryp_id))
|
Ok(cast.set_target(cryp_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn target_phase_finished(&self) -> bool {
|
fn target_phase_finished(&self) -> bool {
|
||||||
@ -394,7 +406,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.skill_id)?;
|
game.add_target(account.id, params.cryp_id, params.cast_id)?;
|
||||||
|
|
||||||
if game.target_phase_finished() {
|
if game.target_phase_finished() {
|
||||||
game.damage_phase_start();
|
game.damage_phase_start();
|
||||||
|
|||||||
@ -355,7 +355,7 @@ 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 skill_id: Uuid,
|
pub cast_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||||
|
|||||||
@ -20,65 +20,38 @@ pub enum Skill {
|
|||||||
|
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub struct Turn {
|
pub struct Cast {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub skill: Skill,
|
pub skill: Skill,
|
||||||
pub cryp_id: Uuid,
|
pub cryp_id: Uuid,
|
||||||
pub roll: Option<Roll>,
|
|
||||||
pub target_cryp_id: Option<Uuid>,
|
pub target_cryp_id: Option<Uuid>,
|
||||||
pub target_team_id: Uuid,
|
pub target_team_id: Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Turn {
|
impl Cast {
|
||||||
pub fn new(cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> Turn {
|
pub fn new(cryp_id: Uuid, target_team_id: Uuid, skill: Skill) -> Cast {
|
||||||
return Turn {
|
return Cast {
|
||||||
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,
|
|
||||||
skill,
|
skill,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn roll(&self, c: &Cryp) -> Roll {
|
pub fn resolve(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Cast {
|
||||||
let mut rng = thread_rng();
|
let roll = cryp.roll(self.skill);
|
||||||
let base: u64 = rng.gen();
|
|
||||||
|
|
||||||
let stat = match self.skill {
|
match self.skill {
|
||||||
Skill::Attack => &c.str,
|
Skill::Stun => target.stun(roll),
|
||||||
Skill::Block => &c.str,
|
_ => target.attack(roll),
|
||||||
Skill::Stun => &c.str,
|
|
||||||
Skill::Dodge => &c.agi,
|
|
||||||
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);
|
println!("{:?} gettin clapped for {:?}", target.name, roll.result);
|
||||||
target.hp.reduce(roll.result);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut Turn {
|
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut Cast {
|
||||||
self.target_cryp_id = Some(cryp_id);
|
self.target_cryp_id = Some(cryp_id);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user