send cast in event, split up cast and hit
This commit is contained in:
@@ -1,71 +1,66 @@
|
||||
function getObjects(resolution, game, account) {
|
||||
const [type, event] = resolution.variant;
|
||||
|
||||
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(event.source);
|
||||
const targetIsPlayer = playerTeamIds.includes(resolution.target);
|
||||
|
||||
const targetting = () => {
|
||||
if (type === 'AoeSkill') {
|
||||
if (targetIsPlayer) return playerTeamIds;
|
||||
return otherTeamIds;
|
||||
}
|
||||
return [resolution.target];
|
||||
};
|
||||
const sourceIsPlayer = playerTeamIds.includes(source);
|
||||
const targetIsPlayer = playerTeamIds.includes(target);
|
||||
|
||||
const sameTeam = (sourceIsPlayer && targetIsPlayer) || (!sourceIsPlayer && !targetIsPlayer);
|
||||
let y = 0;
|
||||
if (!sameTeam) y = targetIsPlayer ? 1 : -1;
|
||||
|
||||
const i = sourceIsPlayer
|
||||
? playerTeamIds.findIndex(c => c === event.source)
|
||||
: otherTeamIds.findIndex(c => c === event.source);
|
||||
? playerTeamIds.findIndex(c => c === source)
|
||||
: otherTeamIds.findIndex(c => c === source);
|
||||
|
||||
const j = targetIsPlayer
|
||||
? playerTeamIds.findIndex(c => c === resolution.target)
|
||||
: otherTeamIds.findIndex(c => c === resolution.target);
|
||||
? playerTeamIds.findIndex(c => c === target)
|
||||
: otherTeamIds.findIndex(c => c === target);
|
||||
const x = j - i;
|
||||
const direction = { x, y };
|
||||
// const targetTeam = targetIsPlayer ? playerTeamIds : otherTeamIds;
|
||||
return { x, y };
|
||||
};
|
||||
|
||||
const getFocusTargets = () => {
|
||||
if (type === 'HitCast') {
|
||||
const { source } = event;
|
||||
const { target } = resolution;
|
||||
if (source !== target) return [source, target];
|
||||
return [target];
|
||||
}
|
||||
if (type === 'AoeSkill') {
|
||||
if (targetIsPlayer) return playerTeamIds;
|
||||
return otherTeamIds;
|
||||
}
|
||||
return [resolution.target];
|
||||
};
|
||||
|
||||
function getAnimSource(resolution, game, account) {
|
||||
const { source, target } = resolution.cast;
|
||||
const animSource = {
|
||||
animation: 'sourceCast',
|
||||
constructId: event.source,
|
||||
direction,
|
||||
constructId: source,
|
||||
direction: direction(game, account, source, target),
|
||||
};
|
||||
return animSource;
|
||||
}
|
||||
|
||||
function getAnimTarget(resolution, game, account) {
|
||||
const { source, target, skill } = resolution.cast;
|
||||
const player = resolution.cast.player === account;
|
||||
const animTarget = {
|
||||
skill: event.skill,
|
||||
constructId: targetting(),
|
||||
player: playerTeamIds.includes(resolution.target),
|
||||
direction,
|
||||
constructId: resolution.cast.target,
|
||||
player,
|
||||
direction: direction(game, account, source, target),
|
||||
skill,
|
||||
};
|
||||
|
||||
return {
|
||||
animSource,
|
||||
animTarget,
|
||||
focusTargets: getFocusTargets(),
|
||||
skill: event.skill,
|
||||
};
|
||||
return animTarget;
|
||||
}
|
||||
|
||||
function getFocusTargets(resolution, game, account) {
|
||||
if (resolution.variant[1] === 'AoeHit') {
|
||||
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);
|
||||
if (resolution.cast.player === account) return playerTeamIds;
|
||||
return otherTeamIds;
|
||||
}
|
||||
|
||||
const { source, target } = resolution.cast;
|
||||
return [source, target];
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getObjects,
|
||||
getAnimSource,
|
||||
getAnimTarget,
|
||||
getFocusTargets,
|
||||
};
|
||||
|
||||
@@ -46,8 +46,8 @@ class Attack extends Component {
|
||||
y: [400, 200],
|
||||
height: [100, 10, 0],
|
||||
width: [12, 5, 0],
|
||||
delay: () => anime.random(TIMES.TARGET_DELAY_MS, TIMES.TARGET_DELAY_MS + TIMES.TARGET_DURATION_MS / 2),
|
||||
duration: TIMES.TARGET_DURATION_MS,
|
||||
delay: () => anime.random(0, TIMES.TARGET_DURATION_MS / 4),
|
||||
duration: TIMES.TARGET_DURATION_MS * 5 / 4,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -59,9 +59,7 @@ class Attack extends Component {
|
||||
for (let i = this.animations.length - 1; i >= 0; i--) {
|
||||
this.animations[i].reset();
|
||||
}
|
||||
this.props.animCb && this.props.animCb();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = addState(Attack);
|
||||
|
||||
@@ -7,7 +7,7 @@ const shapes = require('./shapes');
|
||||
const { removeTier } = require('../utils');
|
||||
const { TIMES } = require('./../constants');
|
||||
|
||||
const addState = connect(({ animText, animSkill, itemInfo }) => ({ animText, animSkill, itemInfo }));
|
||||
const addState = connect(({ animText, itemInfo }) => ({ animText, itemInfo }));
|
||||
|
||||
class AnimText extends preact.Component {
|
||||
shouldComponentUpdate(newProps) {
|
||||
@@ -17,7 +17,7 @@ class AnimText extends preact.Component {
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { animText, construct } = this.props;
|
||||
if (animText && animText !== prevProps.animText && animText.target === construct.id) {
|
||||
if (animText && animText !== prevProps.animText && animText.variant[1].target === construct.id) {
|
||||
anime({
|
||||
targets: '.combat-text',
|
||||
top: '40%',
|
||||
@@ -28,10 +28,10 @@ class AnimText extends preact.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { construct, animText, animSkill, itemInfo } = this.props;
|
||||
if (animText && animText.target === construct.id) {
|
||||
const { construct, animText, itemInfo } = this.props;
|
||||
if (animText && animText.variant[1].target === construct.id) {
|
||||
const itemSourceDescription = () => {
|
||||
const itemSource = itemInfo.combos.filter(c => c.item === removeTier(animSkill));
|
||||
const itemSource = itemInfo.combos.filter(c => c.item === removeTier(animText.cast.skill));
|
||||
const itemSourceInfo = itemSource.length
|
||||
? `${itemSource[0].components[0]} ${itemSource[0].components[1]} ${itemSource[0].components[2]}`
|
||||
: false;
|
||||
@@ -82,7 +82,7 @@ class AnimText extends preact.Component {
|
||||
|
||||
return (
|
||||
<div class="combat-text">
|
||||
<h2><span>{animSkill}</span></h2>
|
||||
<h2><span>{animText.cast.skill}</span></h2>
|
||||
<span>{itemSourceDescription()}</span>
|
||||
{generateAnimText()}
|
||||
</div>
|
||||
|
||||
@@ -21,11 +21,10 @@ const addState = connect(
|
||||
|
||||
class GameConstructEffects extends preact.Component {
|
||||
shouldComponentUpdate(newProps) {
|
||||
if (newProps.animText !== this.props.animText) {
|
||||
if (newProps.animText && newProps.animText.constructId === this.props.construct.id) {
|
||||
const [type] = newProps.animText.variant;
|
||||
if (type === 'Effect' || type === 'Removal') return true;
|
||||
}
|
||||
if (newProps.animText && newProps.animText !== this.props.animText) {
|
||||
const [type, info] = newProps.animText.variant;
|
||||
if (info.target === this.props.construct.id
|
||||
&& (type === 'Effect' || type === 'Removal')) return true;
|
||||
}
|
||||
if (newProps.construct !== this.props.construct) return true;
|
||||
return false;
|
||||
|
||||
@@ -7,11 +7,10 @@ const addState = connect(({ animText }) => ({ animText }));
|
||||
|
||||
class GameConstructLife extends preact.Component {
|
||||
shouldComponentUpdate(newProps) {
|
||||
if (newProps.animText !== this.props.animText) {
|
||||
if (newProps.animText && newProps.animText.target === this.props.construct.id) {
|
||||
const [type] = newProps.animText.variant;
|
||||
if (type === 'Damage' || type === 'Healing' || type === 'Recharge') return true;
|
||||
}
|
||||
if (newProps.animText && newProps.animText !== this.props.animText) {
|
||||
const [type, info] = newProps.animText.variant;
|
||||
if (info.target === this.props.construct.id
|
||||
&& (type === 'Damage' || type === 'Healing' || type === 'Recharge')) return true;
|
||||
}
|
||||
if (newProps.construct !== this.props.construct) return true;
|
||||
return false;
|
||||
|
||||
+12
-17
@@ -5,7 +5,7 @@ const eachSeries = require('async/eachSeries');
|
||||
const sample = require('lodash/sample');
|
||||
|
||||
const actions = require('./actions');
|
||||
const animations = require('./animations.utils');
|
||||
const { getAnimSource, getAnimTarget, getFocusTargets } = require('./animations.utils');
|
||||
const { infoToast, errorToast } = require('./utils');
|
||||
const { tutorialVbox } = require('./tutorial.utils');
|
||||
const { TIMES } = require('./constants');
|
||||
@@ -90,24 +90,19 @@ function registerEvents(store) {
|
||||
const newRes = game.events[currentGame.events.length];
|
||||
return eachSeries(newRes, (r, cb) => {
|
||||
const timeout = r.delay;
|
||||
const focusTargets = getFocusTargets(r, game, account);
|
||||
store.dispatch(actions.setAnimFocus(focusTargets));
|
||||
|
||||
if (r.variant[0].includes('Hit')) {
|
||||
let animTimeOut = TIMES.TARGET_DURATION_MS;
|
||||
const anims = animations.getObjects(r, game, account);
|
||||
|
||||
if (r.variant[0] === 'HitCast') {
|
||||
animTimeOut += TIMES.TARGET_DELAY_MS;
|
||||
store.dispatch(actions.setAnimSource(anims.animSource));
|
||||
}
|
||||
|
||||
store.dispatch(actions.setAnimFocus(anims.focusTargets));
|
||||
store.dispatch(actions.setAnimSkill(anims.skill));
|
||||
store.dispatch(actions.setAnimTarget(anims.animTarget));
|
||||
if (r.variant[0] === 'Cast') {
|
||||
const animSource = getAnimSource(r, game, account);
|
||||
store.dispatch(actions.setAnimSource(animSource));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
setTimeout(() => {
|
||||
store.dispatch(actions.setAnimSource(null));
|
||||
store.dispatch(actions.setAnimTarget(null));
|
||||
}, animTimeOut);
|
||||
setTimeout(() => store.dispatch(actions.setAnimSource(null)), TIMES.SOURCE_DURATION_MS);
|
||||
} else if (r.variant[0].includes('Hit')) {
|
||||
const animTarget = getAnimTarget(r, game, account);
|
||||
store.dispatch(actions.setAnimTarget(animTarget));
|
||||
store.dispatch(actions.setAnimText(null));
|
||||
setTimeout(() => store.dispatch(actions.setAnimTarget(null)), TIMES.TARGET_DURATION_MS);
|
||||
} else {
|
||||
store.dispatch(actions.setAnimText(r));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user