calculate direction server side
This commit is contained in:
@@ -1,52 +1,30 @@
|
||||
const direction = (game, account, source, target) => {
|
||||
const playerTeam = game.players.find(t => t.id === account.id);
|
||||
const playerTeamIds = playerTeam.constructs.map(c => c.id);
|
||||
const otherTeam = game.players.find(t => t.id !== account.id);
|
||||
const otherTeamIds = otherTeam.constructs.map(c => c.id);
|
||||
const sourceIsPlayer = playerTeamIds.includes(source);
|
||||
const targetIsPlayer = playerTeamIds.includes(target);
|
||||
function getAnimSource(resolution, account) {
|
||||
const { player } = resolution.cast;
|
||||
const { x, y, target } = resolution.variant[1];
|
||||
const animY = y && player === account.id ? -1 : y;
|
||||
|
||||
const sameTeam = (sourceIsPlayer && targetIsPlayer) || (!sourceIsPlayer && !targetIsPlayer);
|
||||
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 = {
|
||||
return {
|
||||
animation: 'sourceCast',
|
||||
constructId: source,
|
||||
direction: direction(game, account, source, target),
|
||||
constructId: target,
|
||||
direction: { x, y: animY },
|
||||
};
|
||||
return animSource;
|
||||
}
|
||||
|
||||
function getAnimTarget(resolution, game, account) {
|
||||
const { source, target, skill } = resolution.cast;
|
||||
const player = resolution.cast.player === account;
|
||||
const animTarget = {
|
||||
constructId: resolution.cast.target,
|
||||
player,
|
||||
direction: direction(game, account, source, target),
|
||||
function getAnimTarget(resolution, account) {
|
||||
const { player, skill } = resolution.cast;
|
||||
const { x, y, target } = resolution.variant[1];
|
||||
const animY = y && player === account.id ? -1 : y;
|
||||
const isPlayer = player === account.id;
|
||||
return {
|
||||
constructId: target,
|
||||
player: isPlayer,
|
||||
skill,
|
||||
direction: { x, y: animY },
|
||||
};
|
||||
|
||||
return animTarget;
|
||||
}
|
||||
|
||||
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 playerTeamIds = playerTeam.constructs.map(c => c.id);
|
||||
const otherTeam = game.players.find(t => t.id !== account.id);
|
||||
|
||||
@@ -94,12 +94,12 @@ function registerEvents(store) {
|
||||
store.dispatch(actions.setAnimFocus(focusTargets));
|
||||
|
||||
if (r.variant[0] === 'Cast') {
|
||||
const animSource = getAnimSource(r, game, account);
|
||||
const animSource = getAnimSource(r, account);
|
||||
store.dispatch(actions.setAnimSource(animSource));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
|
||||
} 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.setAnimText(null));
|
||||
setTimeout(() => store.dispatch(actions.setAnimTarget(null)), TIMES.TARGET_DURATION_MS);
|
||||
|
||||
Reference in New Issue
Block a user