direct action

This commit is contained in:
ntr 2018-12-31 16:58:35 +11:00
parent 2492e76ca1
commit 19c23c4f97
8 changed files with 1478 additions and 291 deletions

View File

@ -6,23 +6,6 @@ const CRYP_WIDTH = COMBAT.width() * 0.2;
const TEAM_MARGIN = COMBAT.width() * 0.775;
const Y_PADDING = COMBAT.height() * 0.1;
class TeamHitBox extends Phaser.GameObjects.Rectangle {
constructor(scene, size, team, cback) {
const height = CRYP_HEIGHT * (size) + (Y_PADDING * 0.5) * (size - 1);
super(scene, TEAM_MARGIN * team, Y_PADDING, CRYP_WIDTH, height, 0x222222);
this.setOrigin(0);
this.clickHandler = () => cback();
}
select() {
this.setFillStyle(0x003300);
}
deselect() {
this.setFillStyle(0x222222);
}
}
class CrypHitBox extends Phaser.GameObjects.Rectangle {
constructor(scene, iter, team, cback) {
const y = Y_PADDING + iter * (CRYP_HEIGHT + (Y_PADDING * 0.5));
@ -71,47 +54,30 @@ class CombatHitBox extends Phaser.Scene {
const game = this.registry.get('game');
this.teams = game.teams.length;
if (phase === 'Skill') return this.skillHitBox(game);
if (phase === 'Target') return this.targetHitBox(game);
return false;
}
skillHitBox(game) {
const account = this.registry.get('account');
game.teams.forEach((t) => {
const cback = () => {
const skillScene = this.scene.get('CombatSkills');
const { activeSkill } = skillScene;
if (activeSkill) {
activeSkill.activate();
skillScene.activeSkill = null;
this.game.events.emit('SEND_SKILL', game.id, activeSkill.cryp.id,
t.id, activeSkill.skill.skill);
}
};
const team = t.id === account.id ? 0 : 1;
const size = t.cryps.length;
this.add.existing(new TeamHitBox(this, size, team, cback));
});
this.scene.sendToBack();
}
targetHitBox(game) {
const account = this.registry.get('account');
const group = this.scene.get('CombatCryps').cryps;
const skillScene = this.scene.get('CombatSkills');
game.teams.find(t => t.id === account.id).cryps.forEach((c) => {
const cback = () => {
const { activeTarget } = skillScene;
if (activeTarget) {
activeTarget.activate();
skillScene.activeTarget = null;
this.game.events.emit('SEND_TARGET', game.id, c.id, activeTarget.skill);
}
};
game.teams.forEach((t) => {
t.cryps.forEach((c) => {
const cback = () => {
const { activeSkill } = skillScene;
console.log(activeSkill);
if (activeSkill) {
activeSkill.activate();
skillScene.activeSkill = null;
this.game.events.emit('SEND_SKILL', game.id, activeSkill.cryp.id, c.id, activeSkill.skill.skill);
}
};
const crypSpawn = group.children.entries.find(s => s.cryp.id === c.id);
const team = c.account === account.id ? 0 : 1;
this.add.existing(new CrypHitBox(this, crypSpawn.iter, team, cback));
const crypSpawn = group.children.entries.find(s => s.cryp.id === c.id);
const team = c.account === account.id ? 0 : 1;
console.log(crypSpawn);
this.add.existing(new CrypHitBox(this, crypSpawn.iter, team, cback));
});
});
this.scene.sendToBack();
}

View File

@ -59,7 +59,6 @@ class CrypSkill extends Phaser.GameObjects.Container {
clickHandler() {
if (this.scene.phase === 'Skill') this.scene.activeSkill = this;
if (this.scene.phase === 'Target') this.scene.activeTarget = this;
this.select();
}
@ -135,8 +134,6 @@ class CombatSkills extends Phaser.Scene {
renderSkills(game, phase) {
if (phase === 'Skill') return this.renderSkillPhase(game);
if (phase === 'Target') return this.renderTargetPhase(game);
return false;
}
@ -183,6 +180,8 @@ class CombatSkills extends Phaser.Scene {
return true;
}
// FIXME
// needs to send crypId not team
mapSkillKeys(skillButtons, gameId, crypId, alliesId, enemyId, i) {
const { keyboard } = this.input;

View File

@ -24,7 +24,8 @@ function renderCryps() {
scene: [
Background,
Header,
], };
],
};
const game = new Phaser.Game(config);

View File

@ -85,11 +85,11 @@ function createSocket(events) {
}
function sendGameSkill(gameId, crypId, targetTeamId, skill) {
function sendGameSkill(gameId, crypId, targetCrypId, skill) {
send({
method: 'game_skill',
params: {
game_id: gameId, cryp_id: crypId, target_team_id: targetTeamId, skill,
game_id: gameId, cryp_id: crypId, target_cryp_id: targetCrypId, skill,
},
});
events.setActiveSkill(null);

View File

@ -11,7 +11,7 @@ use failure::Error;
use failure::err_msg;
use account::Account;
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameTargetParams, GameJoinParams};
use rpc::{GameStateParams, GameSkillParams, GamePveParams, GamePvpParams, GameJoinParams};
use cryp::{Cryp, cryp_get};
use skill::{Skill, Cast, ResolutionResult};
use item::{item_drop};
@ -148,11 +148,9 @@ impl Game {
fn cryp_by_id(&mut self, id: Uuid) -> Option<&mut Cryp> {
match self.teams.iter_mut().find(|t| t.cryps.iter().any(|c| c.id == id)) {
Some(team) => {
return team.cryps.iter_mut().find(|c| c.id == id);
},
None => panic!("cryp not in game"),
};
Some(team) => team.cryps.iter_mut().find(|c| c.id == id),
None => None,
}
}
fn all_cryps(&self) -> Vec<Cryp> {
@ -217,25 +215,44 @@ impl Game {
let mobs = self.team_by_id(mob_team_id).clone();
// TODO attack multiple players based on some criteria
let player_team_id = self.teams.iter().find(|t| t.id != mob_team_id).unwrap().id;
for mob in &mobs.cryps {
let player_team = self.teams.iter().find(|t| t.id != mob_team_id).unwrap().clone();
let player_len = player_team.cryps.len();
for (i, mob) in mobs.cryps.iter().enumerate() {
// doesn't matter if the cryp can't cast
self.add_skill(mob_team_id, mob.id, Some(player_team_id), Skill::Attack).ok();
self.add_skill(mob_team_id, mob.id, Some(player_team.cryps[player_len % (i + 1)].id), Skill::Attack).ok();
}
}
self
}
fn add_skill(&mut self, team_id: Uuid, source_cryp_id: Uuid, target_team_id: Option<Uuid>, skill: Skill) -> Result<Uuid, Error> {
fn add_skill(&mut self, team_id: Uuid, source_cryp_id: Uuid, target_cryp_id: Option<Uuid>, skill: Skill) -> Result<Uuid, Error> {
if self.phase != Phase::Skill {
return Err(err_msg("game not in skill phase"));
}
let final_target_id = match skill.self_targeting() {
true => source_cryp_id,
false => match target_cryp_id {
Some(t) => t,
None => return Err(err_msg("skill requires a target")),
}
};
// target checks
{
let _target = match self.cryp_by_id(final_target_id) {
Some(c) => c,
None => return Err(err_msg("target cryp not in game")),
};
}
// cryp checks
{
let cryp = match self.cryp_by_id(source_cryp_id) {
Some(c) => c,
None => return Err(err_msg("cryp not in team")),
None => return Err(err_msg("cryp not in game")),
};
if cryp.is_ko() {
@ -251,28 +268,25 @@ impl Game {
return Err(err_msg("abiltity on cooldown"));
}
// if skill.self_targeting() && target_team_id.is_some() {
// return Err(err_msg("skill is self targeting"));
// }
if !skill.self_targeting() && target_team_id.is_none() {
return Err(err_msg("skill requires a target"));
}
// check here as well so uncastable spells don't go on the stack
let check = cryp.disabled(skill);
if check.disabled {
return Err(err_msg("cryp cannot cast that skill"));
return Err(format_err!("cryp cannot cast that skill ({:?})", check.effects));
}
}
// FIXME
// let (target_cryp_id, target_team_id) = match skill.self_targeting() {
// true => (Some(source_cryp_id), source_team_id),
// false => (None, target_team_id.unwrap())
// };
// replace cryp skill
if let Some(s) = self.stack.iter_mut().position(|s| s.source_cryp_id == source_cryp_id) {
self.stack.remove(s);
}
let skill = Cast::new(source_cryp_id, team_id, target_team_id, skill);
let skill = Cast::new(source_cryp_id, team_id, final_target_id, skill);
let skill_id = skill.id;
self.stack.push(skill);
@ -290,54 +304,54 @@ impl Game {
)
}
fn target_phase_start(&mut self) -> &mut Game {
assert!(self.skill_phase_finished());
self.log.push("<Target Phase>".to_string());
// fn target_phase_start(&mut self) -> &mut Game {
// assert!(self.skill_phase_finished());
// self.log.push("<Target Phase>".to_string());
if self.phase != Phase::Skill {
panic!("game not in skill phase");
}
// if self.phase != Phase::Skill {
// panic!("game not in skill phase");
// }
self.phase = Phase::Target;
// self.phase = Phase::Target;
if self.is_pve {
self.pve_add_targets();
}
// if self.is_pve {
// self.pve_add_targets();
// }
// all cryps are stunned or otherwise inactive
if self.target_phase_finished() {
self.resolve_phase_start();
}
// // all cryps are stunned or otherwise inactive
// if self.target_phase_finished() {
// self.resolve_phase_start();
// }
self
}
// self
// }
fn pve_add_targets(&mut self) -> &mut Game {
{
let mob_team_id = Uuid::nil();
let mobs = self.team_by_id(mob_team_id).clone();
// fn pve_add_targets(&mut self) -> &mut Game {
// {
// let mob_team_id = Uuid::nil();
// let mobs = self.team_by_id(mob_team_id).clone();
// TODO attack multiple players based on some criteria
for (i, incoming_skill_id) in self.stack.clone().iter()
.filter(|s| s.target_cryp_id.is_none() && s.target_team_id == mob_team_id)
.enumerate()
.map(|(i, s)| (i, s.id)) {
let targets = mobs.cryps
.iter()
.filter(|c| self.cryp_targetable(mob_team_id, c.id).is_ok())
.collect::<Vec<&Cryp>>();
// // TODO attack multiple players based on some criteria
// for (i, incoming_skill_id) in self.stack.clone().iter()
// .filter(|s| s.target_cryp_id.is_none() && s.target_team_id == mob_team_id)
// .enumerate()
// .map(|(i, s)| (i, s.id)) {
// let targets = mobs.cryps
// .iter()
// .filter(|c| self.cryp_targetable(mob_team_id, c.id).is_ok())
// .collect::<Vec<&Cryp>>();
if targets.len() == 0 {
panic!("could not find a targetable pve cryp");
}
// if targets.len() == 0 {
// panic!("could not find a targetable pve cryp");
// }
let target_id = targets[i % targets.len()].id;
self.add_target(mob_team_id, target_id, incoming_skill_id).unwrap();
}
}
// let target_id = targets[i % targets.len()].id;
// self.add_target(mob_team_id, target_id, incoming_skill_id).unwrap();
// }
// }
self
}
// self
// }
// each cryp can be the target of
// incomingSkills / activeCryps rounded up
@ -385,41 +399,41 @@ impl Game {
}
// 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 Cast, Error> {
if self.phase != Phase::Target {
return Err(err_msg("game not in target phase"));
}
// fn add_target(&mut self, team_id: Uuid, cryp_id: Uuid, skill_id: Uuid) -> Result<&mut Cast, Error> {
// if self.phase != Phase::Target {
// return Err(err_msg("game not in target phase"));
// }
self.cryp_targetable(team_id, cryp_id)?;
// self.cryp_targetable(team_id, cryp_id)?;
// set the target
let cast = match self.stack.iter_mut().find(|s| s.id == skill_id) {
Some(c) => c,
None => return Err(err_msg("skill_id not found")),
};
// // set the target
// let cast = match self.stack.iter_mut().find(|s| s.id == skill_id) {
// Some(c) => c,
// None => return Err(err_msg("skill_id not found")),
// };
if cast.skill.self_targeting() {
return Err(err_msg("skill is self targeting"));
}
// if cast.skill.self_targeting() {
// return Err(err_msg("skill is self targeting"));
// }
if cast.target_team_id != team_id {
return Err(err_msg("you cannot target that skill"));
}
// if cast.target_team_id != team_id {
// return Err(err_msg("you cannot target that skill"));
// }
Ok(cast.set_target(cryp_id))
}
// Ok(cast.set_target(cryp_id))
// }
fn target_phase_finished(&self) -> bool {
self.stack.iter().all(|s| s.target_cryp_id.is_some())
}
// fn target_phase_finished(&self) -> bool {
// self.stack.iter().all(|s| s.target_cryp_id.is_some())
// }
// requires no input
// just do it
fn resolve_phase_start(&mut self) -> &mut Game {
if self.phase != Phase::Target {
panic!("game not in target phase");
if self.phase != Phase::Skill {
panic!("game not in skill phase");
}
assert!(self.target_phase_finished());
assert!(self.skill_phase_finished());
self.phase = Phase::Resolve;
self.log.push("<Resolve Phase>".to_string());
@ -493,7 +507,7 @@ impl Game {
self.stack = self.stack.clone().iter_mut().map(|skill| {
// println!("{:} resolving ", skill);
let mut source = self.cryp_by_id(skill.source_cryp_id).unwrap().clone();
let mut target = self.cryp_by_id(skill.target_cryp_id.unwrap()).unwrap().clone();
let mut target = self.cryp_by_id(skill.target_cryp_id).unwrap().clone();
skill.set_resolution(&mut source, &mut target);
@ -608,39 +622,9 @@ pub fn game_skill(params: GameSkillParams, tx: &mut Transaction, account: &Accou
return Err(err_msg("game not in skill phase"))
}
game.add_skill(account.id, params.cryp_id, params.target_team_id, params.skill)?;
game.add_skill(account.id, params.cryp_id, params.target_cryp_id, params.skill)?;
if game.skill_phase_finished() {
game.target_phase_start();
}
game_update(&game, tx)?;
Ok(game)
}
pub fn game_target(params: GameTargetParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
let query = "
SELECT *
FROM games
WHERE id = $1
";
let result = tx
.query(query, &[&params.game_id])?;
let returned = match result.iter().next() {
Some(row) => row,
None => return Err(err_msg("game not found")),
};
// tells from_slice to cast into a cryp
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.skill_id)?;
if game.target_phase_finished() {
game.resolve_phase_start();
}
@ -649,6 +633,36 @@ pub fn game_target(params: GameTargetParams, tx: &mut Transaction, account: &Acc
Ok(game)
}
// pub fn game_target(params: GameTargetParams, tx: &mut Transaction, account: &Account) -> Result<Game, Error> {
// let query = "
// SELECT *
// FROM games
// WHERE id = $1
// ";
// let result = tx
// .query(query, &[&params.game_id])?;
// let returned = match result.iter().next() {
// Some(row) => row,
// None => return Err(err_msg("game not found")),
// };
// // tells from_slice to cast into a cryp
// 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.skill_id)?;
// if game.target_phase_finished() {
// game.resolve_phase_start();
// }
// game_update(&game, tx)?;
// Ok(game)
// }
pub fn game_write(game: &Game, tx: &mut Transaction) -> Result<(), Error> {
let game_bytes = to_vec(&game)?;
@ -1046,18 +1060,11 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let x_attack_id = game.add_skill(x_team.id, x_cryp.id, Some(y_team.id), Skill::Attack).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::Attack).unwrap();
game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::Attack).unwrap();
game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap();
assert!(game.skill_phase_finished());
game.target_phase_start();
game.add_target(x_team.id, x_cryp.id, y_attack_id).unwrap();
game.add_target(y_team.id, y_cryp.id, x_attack_id).unwrap();
assert!(game.target_phase_finished());
game.resolve_phase_start();
assert!([Phase::Skill, Phase::Finish].contains(&game.phase));
@ -1075,16 +1082,10 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_team.id), Skill::TestStun).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
let _x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestStun).unwrap();
game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
assert!(game.skill_phase_finished());
game.target_phase_start();
game.add_target(x_team.id, x_cryp.id, y_attack_id).unwrap();
game.add_target(y_team.id, y_cryp.id, x_stun_id).unwrap();
assert!(game.target_phase_finished());
game.resolve_phase_start();
// should auto progress back to skill phase
@ -1106,16 +1107,10 @@ mod tests {
game.team_by_id(y_team.id).cryp_by_id(y_cryp.id).unwrap().phys_dmg.set(u64::max_value());
let x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_team.id), Skill::TestStun).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::Attack).unwrap();
let _x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestStun).unwrap();
game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::Attack).unwrap();
assert!(game.skill_phase_finished());
game.target_phase_start();
game.add_target(x_team.id, x_cryp.id, y_attack_id).unwrap();
game.add_target(y_team.id, y_cryp.id, x_stun_id).unwrap();
assert!(game.target_phase_finished());
game.resolve_phase_start();
// resolution should have been prevented by KO
@ -1134,19 +1129,14 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_team.id), Skill::TestTouch).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
game.target_phase_start();
game.add_target(x_team.id, x_cryp.id, y_attack_id).unwrap();
game.add_target(y_team.id, y_cryp.id, x_stun_id).unwrap();
let _x_stun_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.resolve_phase_start();
// should auto progress back to skill phase
assert!(game.phase == Phase::Skill);
// after 1 turn block should be off cooldown
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Block).is_none());
assert!(game.team_by_id(y_team.id).cryps[0].skill_on_cd(Skill::Empower).is_some());
@ -1155,11 +1145,7 @@ mod tests {
// second round
// now we block and it should go back on cd
let _x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::Block).unwrap();
let y_touch_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
game.target_phase_start();
game.add_target(x_team.id, x_cryp.id, y_touch_id).unwrap();
let _y_touch_id = game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.resolve_phase_start();
@ -1178,14 +1164,7 @@ mod tests {
let y_cryp = y_team.cryps[0].clone();
let _x_block_id = game.add_skill(x_team.id, x_cryp.id, None, Skill::TestParry).unwrap();
let y_attack_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestStun).unwrap();
game.target_phase_start();
// ensure you can't target another team's skills
assert!(game.add_target(x_team.id, y_cryp.id, y_attack_id).is_err());
game.add_target(x_team.id, x_cryp.id, y_attack_id).unwrap();
game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::TestStun).unwrap();
game.resolve_phase_start();
@ -1203,20 +1182,15 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = y_team.cryps[0].clone();
let x_drain_id = game.add_skill(x_team.id, x_cryp.id, Some(y_team.id), Skill::TestDrain).unwrap();
let y_touch_id = game.add_skill(y_team.id, y_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
game.target_phase_start();
game.add_target(x_team.id, x_cryp.id, y_touch_id).unwrap();
game.add_target(y_team.id, y_cryp.id, x_drain_id).unwrap();
let _x_drain_id = game.add_skill(x_team.id, x_cryp.id, Some(y_cryp.id), Skill::TestDrain).unwrap();
let _y_touch_id = game.add_skill(y_team.id, y_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.resolve_phase_start();
game.add_skill(x_team.id, x_cryp.id, None, Skill::TestBlock).unwrap();
game.add_skill(y_team.id, y_cryp.id, None, Skill::TestBlock).unwrap();
game.target_phase_start();
game.resolve_phase_start();
assert!(game.resolved.iter().any(|r| r.skill == Skill::DrainTick));
}
@ -1233,23 +1207,12 @@ mod tests {
let x_cryp = x_team.cryps[0].clone();
let y_cryp = x_team.cryps[1].clone();
let i_attack_id = game.add_skill(i_team.id, i_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
let j_attack_id = game.add_skill(i_team.id, j_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
let x_attack_id = game.add_skill(x_team.id, x_cryp.id, Some(i_team.id), Skill::TestTouch).unwrap();
let y_attack_id = game.add_skill(x_team.id, y_cryp.id, Some(i_team.id), Skill::TestTouch).unwrap();
game.add_skill(i_team.id, i_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(i_team.id, j_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_team.id, x_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_team.id, y_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
assert!(game.skill_phase_finished());
game.target_phase_start();
game.add_target(i_team.id, i_cryp.id, x_attack_id).unwrap();
game.add_target(i_team.id, j_cryp.id, y_attack_id).unwrap();
game.add_target(x_team.id, x_cryp.id, i_attack_id).unwrap();
game.add_target(x_team.id, y_cryp.id, j_attack_id).unwrap();
assert!(game.target_phase_finished());
game.resolve_phase_start();
assert!([Phase::Skill, Phase::Finish].contains(&game.phase));
@ -1258,24 +1221,17 @@ mod tests {
game.team_by_id(i_team.id).cryp_by_id(i_cryp.id).unwrap().hp.reduce(u64::max_value());
// add some more skills
let j_attack_id = game.add_skill(i_team.id, j_cryp.id, Some(x_team.id), Skill::TestTouch).unwrap();
let x_attack_id = game.add_skill(x_team.id, x_cryp.id, Some(i_team.id), Skill::TestTouch).unwrap();
let y_attack_id = game.add_skill(x_team.id, y_cryp.id, Some(i_team.id), Skill::TestTouch).unwrap();
game.add_skill(i_team.id, j_cryp.id, Some(x_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_team.id, x_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
game.add_skill(x_team.id, y_cryp.id, Some(i_cryp.id), Skill::TestTouch).unwrap();
assert!(game.skill_phase_finished());
game.target_phase_start();
game.resolve_phase_start();
assert!(game.team_by_id(i_team.id).skills_required() == 1);
assert!(game.cryp_targetable(i_team.id, i_cryp.id).is_err());
assert!(game.cryp_targetable(i_team.id, j_cryp.id).is_ok());
game.add_target(i_team.id, j_cryp.id, x_attack_id).unwrap();
game.add_target(i_team.id, j_cryp.id, y_attack_id).unwrap();
game.add_target(x_team.id, x_cryp.id, j_attack_id).unwrap();
game.add_target(x_team.id, y_cryp.id, j_attack_id).unwrap();
assert!(game.target_phase_finished());
return;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ use failure::err_msg;
use net::Db;
use cryp::{Cryp, cryp_spawn, cryp_learn, cryp_forget};
use game::{Game, PveMode, game_state, game_pve, game_pvp, game_join, game_joinable_list, game_skill, game_target};
use game::{Game, PveMode, game_state, game_pve, game_pvp, game_join, game_joinable_list, game_skill};
use account::{Account, account_create, account_login, account_from_token, account_cryps, account_zone};
use item::{Item, items_list, item_use};
use skill::{Skill};
@ -69,7 +69,7 @@ impl Rpc {
"game_join" => Rpc::game_join(data, &mut tx, account.unwrap(), client),
"game_joinable_list" => Rpc::game_joinable_list(data, &mut tx, account.unwrap(), client),
"game_skill" => Rpc::game_skill(data, &mut tx, account.unwrap(), client),
"game_target" => Rpc::game_target(data, &mut tx, account.unwrap(), client),
// "game_target" => Rpc::game_target(data, &mut tx, account.unwrap(), client),
"zone_create" => Rpc::zone_create(data, &mut tx, account.unwrap(), client),
"zone_join" => Rpc::zone_join(data, &mut tx, account.unwrap(), client),
"zone_close" => Rpc::zone_close(data, &mut tx, account.unwrap(), client),
@ -172,17 +172,16 @@ impl Rpc {
return Ok(game_response);
}
fn game_target(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<GameTargetMsg>(&data).or(Err(err_msg("invalid params")))?;
// fn game_target(data: Vec<u8>, tx: &mut Transaction, account: Account, _client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
// let msg = from_slice::<GameTargetMsg>(&data).or(Err(err_msg("invalid params")))?;
let game_response = RpcResponse {
method: "game_state".to_string(),
params: RpcResult::GameState(game_target(msg.params, tx, &account)?)
};
return Ok(game_response);
}
// let game_response = RpcResponse {
// method: "game_state".to_string(),
// params: RpcResult::GameState(game_target(msg.params, tx, &account)?)
// };
// return Ok(game_response);
// }
fn cryp_spawn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
let msg = from_slice::<CrypSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
@ -475,18 +474,18 @@ struct GameJoinableListMsg {
params: (),
}
#[derive(Debug,Clone,Serialize,Deserialize)]
struct GameTargetMsg {
method: String,
params: GameTargetParams,
}
// #[derive(Debug,Clone,Serialize,Deserialize)]
// struct GameTargetMsg {
// method: String,
// params: GameTargetParams,
// }
#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct GameTargetParams {
pub game_id: Uuid,
pub cryp_id: Uuid,
pub skill_id: Uuid,
}
// #[derive(Debug,Clone,Serialize,Deserialize)]
// pub struct GameTargetParams {
// pub game_id: Uuid,
// pub cryp_id: Uuid,
// pub skill_id: Uuid,
// }
#[derive(Debug,Clone,Serialize,Deserialize)]
struct GameSkillMsg {
@ -498,7 +497,7 @@ struct GameSkillMsg {
pub struct GameSkillParams {
pub game_id: Uuid,
pub cryp_id: Uuid,
pub target_team_id: Option<Uuid>,
pub target_cryp_id: Option<Uuid>,
pub skill: Skill,
}

View File

@ -9,34 +9,24 @@ pub struct Cast {
pub skill: Skill,
pub source_team_id: Uuid,
pub source_cryp_id: Uuid,
pub target_cryp_id: Option<Uuid>,
pub target_team_id: Uuid,
pub target_cryp_id: Uuid,
pub resolution: Resolution,
}
impl Cast {
pub fn new(source_cryp_id: Uuid, source_team_id: Uuid, target_team_id: Option<Uuid>, skill: Skill) -> Cast {
let (target_cryp_id, target_team_id) = match skill.self_targeting() {
true => (Some(source_cryp_id), source_team_id),
false => (None, target_team_id.unwrap())
};
pub fn new(source_cryp_id: Uuid, source_team_id: Uuid, target_cryp_id: Uuid, skill: Skill) -> Cast {
return Cast {
id: Uuid::new_v4(),
source_cryp_id,
source_team_id,
target_cryp_id,
target_team_id,
skill,
resolution: Resolution::new(skill),
};
}
pub fn new_tick(source: &mut Cryp, target: &mut Cryp, skill: Skill) -> Cast {
let mut cast = Cast::new(source.id, source.account, Some(target.account), skill);
cast.set_target(target.id);
return cast;
Cast::new(source.id, source.account, target.id, skill)
}
pub fn set_resolution(&mut self, cryp: &mut Cryp, target: &mut Cryp) -> &mut Cast {
@ -44,11 +34,6 @@ impl Cast {
self
}
pub fn set_target(&mut self, cryp_id: Uuid) -> &mut Cast {
self.target_cryp_id = Some(cryp_id);
self
}
pub fn used_cooldown(&self) -> bool {
return self.skill.base_cd().is_some();
}