moved cryp health changes into async loop
This commit is contained in:
parent
60c85285b7
commit
83eb2733ad
@ -4,7 +4,7 @@ const anime = require('animejs').default;
|
||||
|
||||
const actions = require('./actions');
|
||||
const { TIMES } = require('./constants');
|
||||
const { getCombatSequence } = require('./utils');
|
||||
const { getCombatSequence, resoCrypHealth } = require('./utils');
|
||||
|
||||
function registerEvents(store) {
|
||||
|
||||
@ -70,7 +70,11 @@ function registerEvents(store) {
|
||||
if (skip) return sCb();
|
||||
const stagedR = Object.create(r);
|
||||
stagedR.stage = stage;
|
||||
|
||||
// Apply damage for each cryp
|
||||
if (stage === 'POST_SKILL') resoCrypHealth(stagedR, currentGame);
|
||||
store.dispatch(actions.setResolution(stagedR));
|
||||
|
||||
return setTimeout(sCb, TIMES[stage]);
|
||||
}, err => {
|
||||
if (err) return console.error(err);
|
||||
|
||||
@ -108,6 +108,40 @@ const COLOUR_ICONS = {
|
||||
green: { colour: 'green', caption: 'green', svg: shapes.square },
|
||||
};
|
||||
|
||||
function resoCrypHealth(resolution, currentGame) {
|
||||
if (!resolution) return false;
|
||||
|
||||
const modifyHealth = cryp => {
|
||||
if (cryp.id !== resolution.target.id) return false; // not target
|
||||
const [type, event] = resolution.event;
|
||||
if (type === 'Damage') {
|
||||
const { amount, mitigation, colour } = event;
|
||||
cryp.green_life.value -= amount;
|
||||
if (colour === 'RedDamage') {
|
||||
cryp.red_life.value -= mitigation;
|
||||
}
|
||||
if (colour === 'BlueDamage') {
|
||||
cryp.blue_life.value -= mitigation;
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'Healing') {
|
||||
const { amount } = event;
|
||||
cryp.green_life.value += amount;
|
||||
}
|
||||
|
||||
if (type === 'Recharge') {
|
||||
const { red, blue } = event;
|
||||
cryp.red_life.value += red;
|
||||
cryp.blue_life.value += blue;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
currentGame.players.forEach(player => player.cryps.forEach(modifyHealth));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function eventClasses(resolution, cryp) {
|
||||
if (!resolution) return '';
|
||||
const startSkill = resolution.stage === 'START_SKILL';
|
||||
@ -115,7 +149,6 @@ function eventClasses(resolution, cryp) {
|
||||
const postSkill = resolution.stage === 'POST_SKILL';
|
||||
const source = cryp.id === resolution.source.id;
|
||||
const target = cryp.id === resolution.target.id;
|
||||
|
||||
// not involved at all. blur them
|
||||
if (!(source || target)) return 'unfocus';
|
||||
|
||||
@ -148,13 +181,10 @@ function eventClasses(resolution, cryp) {
|
||||
|
||||
// Deal damage to cryp and return effect
|
||||
if (target && postSkill) {
|
||||
cryp.green_life.value -= amount;
|
||||
if (colour === 'RedDamage') {
|
||||
cryp.red_life.value -= mitigation;
|
||||
return 'red-damage';
|
||||
}
|
||||
if (colour === 'BlueDamage') {
|
||||
cryp.blue_life.value -= mitigation;
|
||||
return 'blue-damage';
|
||||
}
|
||||
if (colour === 'GreenDamage') return 'green-damage';
|
||||
@ -167,7 +197,6 @@ function eventClasses(resolution, cryp) {
|
||||
if (source && startSkill) return 'active-skill';
|
||||
if (target && endSkill) return 'active-skill';
|
||||
if (target && postSkill) {
|
||||
cryp.green_life.value += amount;
|
||||
return 'green-damage';
|
||||
}
|
||||
}
|
||||
@ -202,8 +231,6 @@ function eventClasses(resolution, cryp) {
|
||||
if (source && startSkill) return 'active-skill';
|
||||
if (target && endSkill) return 'active-skill';
|
||||
if (target && postSkill) {
|
||||
cryp.red_life.value += red;
|
||||
cryp.blue_life.value += blue;
|
||||
if (red > 0 && blue > 0) return 'purple-damage';
|
||||
if (red > 0) return 'red-damage';
|
||||
if (blue > 0) return 'blue-damage';
|
||||
@ -371,6 +398,7 @@ module.exports = {
|
||||
eventClasses,
|
||||
getCombatSequence,
|
||||
getCombatText,
|
||||
resoCrypHealth,
|
||||
NULL_UUID,
|
||||
STATS,
|
||||
SPECS,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user