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 actions = require('./actions');
|
||||||
const { TIMES } = require('./constants');
|
const { TIMES } = require('./constants');
|
||||||
const { getCombatSequence } = require('./utils');
|
const { getCombatSequence, resoCrypHealth } = require('./utils');
|
||||||
|
|
||||||
function registerEvents(store) {
|
function registerEvents(store) {
|
||||||
|
|
||||||
@ -70,7 +70,11 @@ function registerEvents(store) {
|
|||||||
if (skip) return sCb();
|
if (skip) return sCb();
|
||||||
const stagedR = Object.create(r);
|
const stagedR = Object.create(r);
|
||||||
stagedR.stage = stage;
|
stagedR.stage = stage;
|
||||||
|
|
||||||
|
// Apply damage for each cryp
|
||||||
|
if (stage === 'POST_SKILL') resoCrypHealth(stagedR, currentGame);
|
||||||
store.dispatch(actions.setResolution(stagedR));
|
store.dispatch(actions.setResolution(stagedR));
|
||||||
|
|
||||||
return setTimeout(sCb, TIMES[stage]);
|
return setTimeout(sCb, TIMES[stage]);
|
||||||
}, err => {
|
}, err => {
|
||||||
if (err) return console.error(err);
|
if (err) return console.error(err);
|
||||||
|
|||||||
@ -108,6 +108,40 @@ const COLOUR_ICONS = {
|
|||||||
green: { colour: 'green', caption: 'green', svg: shapes.square },
|
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) {
|
function eventClasses(resolution, cryp) {
|
||||||
if (!resolution) return '';
|
if (!resolution) return '';
|
||||||
const startSkill = resolution.stage === 'START_SKILL';
|
const startSkill = resolution.stage === 'START_SKILL';
|
||||||
@ -115,7 +149,6 @@ function eventClasses(resolution, cryp) {
|
|||||||
const postSkill = resolution.stage === 'POST_SKILL';
|
const postSkill = resolution.stage === 'POST_SKILL';
|
||||||
const source = cryp.id === resolution.source.id;
|
const source = cryp.id === resolution.source.id;
|
||||||
const target = cryp.id === resolution.target.id;
|
const target = cryp.id === resolution.target.id;
|
||||||
|
|
||||||
// not involved at all. blur them
|
// not involved at all. blur them
|
||||||
if (!(source || target)) return 'unfocus';
|
if (!(source || target)) return 'unfocus';
|
||||||
|
|
||||||
@ -148,13 +181,10 @@ function eventClasses(resolution, cryp) {
|
|||||||
|
|
||||||
// Deal damage to cryp and return effect
|
// Deal damage to cryp and return effect
|
||||||
if (target && postSkill) {
|
if (target && postSkill) {
|
||||||
cryp.green_life.value -= amount;
|
|
||||||
if (colour === 'RedDamage') {
|
if (colour === 'RedDamage') {
|
||||||
cryp.red_life.value -= mitigation;
|
|
||||||
return 'red-damage';
|
return 'red-damage';
|
||||||
}
|
}
|
||||||
if (colour === 'BlueDamage') {
|
if (colour === 'BlueDamage') {
|
||||||
cryp.blue_life.value -= mitigation;
|
|
||||||
return 'blue-damage';
|
return 'blue-damage';
|
||||||
}
|
}
|
||||||
if (colour === 'GreenDamage') return 'green-damage';
|
if (colour === 'GreenDamage') return 'green-damage';
|
||||||
@ -167,7 +197,6 @@ function eventClasses(resolution, cryp) {
|
|||||||
if (source && startSkill) return 'active-skill';
|
if (source && startSkill) return 'active-skill';
|
||||||
if (target && endSkill) return 'active-skill';
|
if (target && endSkill) return 'active-skill';
|
||||||
if (target && postSkill) {
|
if (target && postSkill) {
|
||||||
cryp.green_life.value += amount;
|
|
||||||
return 'green-damage';
|
return 'green-damage';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,8 +231,6 @@ function eventClasses(resolution, cryp) {
|
|||||||
if (source && startSkill) return 'active-skill';
|
if (source && startSkill) return 'active-skill';
|
||||||
if (target && endSkill) return 'active-skill';
|
if (target && endSkill) return 'active-skill';
|
||||||
if (target && postSkill) {
|
if (target && postSkill) {
|
||||||
cryp.red_life.value += red;
|
|
||||||
cryp.blue_life.value += blue;
|
|
||||||
if (red > 0 && blue > 0) return 'purple-damage';
|
if (red > 0 && blue > 0) return 'purple-damage';
|
||||||
if (red > 0) return 'red-damage';
|
if (red > 0) return 'red-damage';
|
||||||
if (blue > 0) return 'blue-damage';
|
if (blue > 0) return 'blue-damage';
|
||||||
@ -371,6 +398,7 @@ module.exports = {
|
|||||||
eventClasses,
|
eventClasses,
|
||||||
getCombatSequence,
|
getCombatSequence,
|
||||||
getCombatText,
|
getCombatText,
|
||||||
|
resoCrypHealth,
|
||||||
NULL_UUID,
|
NULL_UUID,
|
||||||
STATS,
|
STATS,
|
||||||
SPECS,
|
SPECS,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user