calculate direction server side
This commit is contained in:
parent
a6f654fac1
commit
261ab1d48b
@ -1,52 +1,30 @@
|
|||||||
const direction = (game, account, source, target) => {
|
function getAnimSource(resolution, account) {
|
||||||
const playerTeam = game.players.find(t => t.id === account.id);
|
const { player } = resolution.cast;
|
||||||
const playerTeamIds = playerTeam.constructs.map(c => c.id);
|
const { x, y, target } = resolution.variant[1];
|
||||||
const otherTeam = game.players.find(t => t.id !== account.id);
|
const animY = y && player === account.id ? -1 : y;
|
||||||
const otherTeamIds = otherTeam.constructs.map(c => c.id);
|
|
||||||
const sourceIsPlayer = playerTeamIds.includes(source);
|
|
||||||
const targetIsPlayer = playerTeamIds.includes(target);
|
|
||||||
|
|
||||||
const sameTeam = (sourceIsPlayer && targetIsPlayer) || (!sourceIsPlayer && !targetIsPlayer);
|
return {
|
||||||
let y = 0;
|
|
||||||
if (!sameTeam) y = targetIsPlayer ? 1 : -1;
|
|
||||||
|
|
||||||
const i = sourceIsPlayer
|
|
||||||
? playerTeamIds.findIndex(c => c === source)
|
|
||||||
: otherTeamIds.findIndex(c => c === source);
|
|
||||||
|
|
||||||
const j = targetIsPlayer
|
|
||||||
? playerTeamIds.findIndex(c => c === target)
|
|
||||||
: otherTeamIds.findIndex(c => c === target);
|
|
||||||
const x = j - i;
|
|
||||||
return { x, y };
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
function getAnimSource(resolution, game, account) {
|
|
||||||
const { source, target } = resolution.cast;
|
|
||||||
const animSource = {
|
|
||||||
animation: 'sourceCast',
|
animation: 'sourceCast',
|
||||||
constructId: source,
|
constructId: target,
|
||||||
direction: direction(game, account, source, target),
|
direction: { x, y: animY },
|
||||||
};
|
};
|
||||||
return animSource;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAnimTarget(resolution, game, account) {
|
function getAnimTarget(resolution, account) {
|
||||||
const { source, target, skill } = resolution.cast;
|
const { player, skill } = resolution.cast;
|
||||||
const player = resolution.cast.player === account;
|
const { x, y, target } = resolution.variant[1];
|
||||||
const animTarget = {
|
const animY = y && player === account.id ? -1 : y;
|
||||||
constructId: resolution.cast.target,
|
const isPlayer = player === account.id;
|
||||||
player,
|
return {
|
||||||
direction: direction(game, account, source, target),
|
constructId: target,
|
||||||
|
player: isPlayer,
|
||||||
skill,
|
skill,
|
||||||
|
direction: { x, y: animY },
|
||||||
};
|
};
|
||||||
|
|
||||||
return animTarget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFocusTargets(resolution, game, account) {
|
function getFocusTargets(resolution, game, account) {
|
||||||
if (resolution.variant[1] === 'AoeHit') {
|
if (resolution.variant[1] === 'HitAoe') {
|
||||||
const playerTeam = game.players.find(t => t.id === account.id);
|
const playerTeam = game.players.find(t => t.id === account.id);
|
||||||
const playerTeamIds = playerTeam.constructs.map(c => c.id);
|
const playerTeamIds = playerTeam.constructs.map(c => c.id);
|
||||||
const otherTeam = game.players.find(t => t.id !== account.id);
|
const otherTeam = game.players.find(t => t.id !== account.id);
|
||||||
|
|||||||
@ -94,12 +94,12 @@ function registerEvents(store) {
|
|||||||
store.dispatch(actions.setAnimFocus(focusTargets));
|
store.dispatch(actions.setAnimFocus(focusTargets));
|
||||||
|
|
||||||
if (r.variant[0] === 'Cast') {
|
if (r.variant[0] === 'Cast') {
|
||||||
const animSource = getAnimSource(r, game, account);
|
const animSource = getAnimSource(r, account);
|
||||||
store.dispatch(actions.setAnimSource(animSource));
|
store.dispatch(actions.setAnimSource(animSource));
|
||||||
store.dispatch(actions.setAnimText(null));
|
store.dispatch(actions.setAnimText(null));
|
||||||
setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
|
setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
|
||||||
} else if (r.variant[0].includes('Hit')) {
|
} else if (r.variant[0].includes('Hit')) {
|
||||||
const animTarget = getAnimTarget(r, game, account);
|
const animTarget = getAnimTarget(r, account);
|
||||||
store.dispatch(actions.setAnimTarget(animTarget));
|
store.dispatch(actions.setAnimTarget(animTarget));
|
||||||
store.dispatch(actions.setAnimText(null));
|
store.dispatch(actions.setAnimText(null));
|
||||||
setTimeout(() => store.dispatch(actions.setAnimTarget(null)), TIMES.TARGET_DURATION_MS);
|
setTimeout(() => store.dispatch(actions.setAnimTarget(null)), TIMES.TARGET_DURATION_MS);
|
||||||
|
|||||||
@ -517,13 +517,40 @@ impl Game {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn direction(&mut self, cast: Cast) -> (i8, i8) {
|
||||||
|
let i = self.players.iter()
|
||||||
|
.find(|t| t.constructs.iter().any(|c| c.id == cast.source))
|
||||||
|
.unwrap().constructs
|
||||||
|
.iter()
|
||||||
|
.position(|c| c.id == cast.source)
|
||||||
|
.unwrap() as i8;
|
||||||
|
|
||||||
|
let j = self.players.iter()
|
||||||
|
.find(|t| t.constructs.iter().any(|c| c.id == cast.target))
|
||||||
|
.unwrap().constructs
|
||||||
|
.iter()
|
||||||
|
.position(|c| c.id == cast.target)
|
||||||
|
.unwrap() as i8;
|
||||||
|
let x = j - i;
|
||||||
|
|
||||||
|
let target = self.construct_by_id(cast.target).unwrap();
|
||||||
|
// is the caster player account same as target player account side of screen
|
||||||
|
let y = match cast.player == target.account {
|
||||||
|
true => 0,
|
||||||
|
false => 1
|
||||||
|
};
|
||||||
|
(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
fn cast(&mut self, cast: Cast) -> &mut Game {
|
fn cast(&mut self, cast: Cast) -> &mut Game {
|
||||||
self.event_add(vec![EventVariant::Cast()], cast);
|
let (x, y) = self.direction(cast);
|
||||||
|
self.event_add(vec![EventVariant::Cast { target: cast.source, x, y, player: cast.player }], cast);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hit(&mut self, cast: Cast) -> &mut Game {
|
fn hit(&mut self, cast: Cast) -> &mut Game {
|
||||||
self.event_add(vec![EventVariant::Hit()], cast);
|
let (x, y) = self.direction(cast);
|
||||||
|
self.event_add(vec![EventVariant::Hit { target: cast.target, x, y, player: cast.player }], cast);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -237,9 +237,9 @@ pub struct Event {
|
|||||||
|
|
||||||
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
#[derive(Debug,Clone,Copy,PartialEq,Serialize,Deserialize)]
|
||||||
pub enum EventVariant {
|
pub enum EventVariant {
|
||||||
Cast (),
|
Cast { target: Uuid, player: Uuid, x: i8, y: i8 },
|
||||||
Hit (),
|
Hit { target: Uuid, player: Uuid, x: i8, y: i8 },
|
||||||
HitAoe (),
|
HitAoe { target: Uuid },
|
||||||
|
|
||||||
Damage { target: Uuid, amount: usize, mitigation: usize, colour: Colour, display: EventConstruct },
|
Damage { target: Uuid, amount: usize, mitigation: usize, colour: Colour, display: EventConstruct },
|
||||||
Effect { target: Uuid, effect: Effect, duration: u8, display: EventConstruct },
|
Effect { target: Uuid, effect: Effect, duration: u8, display: EventConstruct },
|
||||||
@ -265,8 +265,9 @@ impl EventVariant {
|
|||||||
let combat_text_overlap = 600; // overlap between animation and combat text
|
let combat_text_overlap = 600; // overlap between animation and combat text
|
||||||
|
|
||||||
match self {
|
match self {
|
||||||
EventVariant::Hit() => target_duration - combat_text_overlap,
|
EventVariant::Cast { target: _, x: _, y: _, player: _ } => target_delay,
|
||||||
EventVariant::Cast() => target_delay,
|
EventVariant::Hit { target: _, x: _, y: _, player: _ } |
|
||||||
|
EventVariant::HitAoe { target: _ } => target_duration - combat_text_overlap,
|
||||||
_ => combat_text_delay,
|
_ => combat_text_delay,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user