removed life conditional checks, assign reso life to state construct
This commit is contained in:
parent
0601006504
commit
6d9e13598c
@ -3,7 +3,7 @@ const preact = require('preact');
|
||||
const range = require('lodash/range');
|
||||
|
||||
const actions = require('../actions');
|
||||
const { STATS, eventClasses, getCombatText, ConstructAvatar, constructHealth } = require('../utils');
|
||||
const { STATS, eventClasses, getCombatText, ConstructAvatar } = require('../utils');
|
||||
const { animationDivs } = require('../animations');
|
||||
const shapes = require('./shapes');
|
||||
|
||||
@ -56,12 +56,11 @@ function GameConstruct(props) {
|
||||
const ko = construct.green_life.value === 0 ? 'ko' : '';
|
||||
const classes = eventClasses(resolution, construct);
|
||||
|
||||
const life = constructHealth(resolution, construct);
|
||||
const stats = ['RedLife', 'GreenLife', 'BlueLife'].map((s, j) => (
|
||||
<div key={j} alt={STATS[s].stat}>
|
||||
{shapes[s]()}
|
||||
<div className="max" >{life[s]} / {construct[STATS[s].stat].max}</div>
|
||||
<div className="value" >{life[s]}</div>
|
||||
<div className="max" >{construct[STATS[s].stat].value} / {construct[STATS[s].stat].max}</div>
|
||||
<div className="value" >{construct[STATS[s].stat].value}</div>
|
||||
</div>
|
||||
));
|
||||
|
||||
|
||||
@ -157,74 +157,6 @@ const STATS = {
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
function constructHealth(resolution, construct) {
|
||||
if (!resolution) {
|
||||
return {
|
||||
RedLife: construct.red_life.value,
|
||||
GreenLife: construct.green_life.value,
|
||||
BlueLife: construct.blue_life.value,
|
||||
};
|
||||
}
|
||||
const [type, event] = resolution.event;
|
||||
|
||||
|
||||
if (construct.id !== resolution.target.id) {
|
||||
if (construct.id === resolution.source.id) {
|
||||
return {
|
||||
RedLife: resolution.source.red,
|
||||
GreenLife: resolution.source.green,
|
||||
BlueLife: resolution.source.blue,
|
||||
};
|
||||
}
|
||||
return {
|
||||
RedLife: construct.red_life.value,
|
||||
GreenLife: construct.green_life.value,
|
||||
BlueLife: construct.blue_life.value,
|
||||
};
|
||||
}
|
||||
|
||||
let RedLife = resolution.target.red;
|
||||
let BlueLife = resolution.target.blue;
|
||||
let GreenLife = resolution.target.green;
|
||||
|
||||
if (resolution.stage === 'POST_SKILL') {
|
||||
return { RedLife, GreenLife, BlueLife };
|
||||
}
|
||||
|
||||
if (type === 'Damage') {
|
||||
const { amount, mitigation, colour } = event;
|
||||
|
||||
GreenLife = construct.green_life.max < GreenLife + amount
|
||||
? construct.green_life.max
|
||||
: GreenLife + amount;
|
||||
|
||||
if (colour === 'Red') {
|
||||
RedLife = construct.red_life.max < RedLife + mitigation
|
||||
? construct.red_life.max
|
||||
: RedLife + mitigation;
|
||||
}
|
||||
if (colour === 'Blue') {
|
||||
BlueLife = construct.blue_life.max < BlueLife + mitigation
|
||||
? construct.blue_life.max
|
||||
: BlueLife + mitigation;
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'Healing') {
|
||||
const { amount } = event;
|
||||
GreenLife = GreenLife - amount < 0 ? 0 : GreenLife - amount;
|
||||
}
|
||||
|
||||
if (type === 'Recharge') {
|
||||
const { red, blue } = event;
|
||||
RedLife = RedLife - red < 0 ? 0 : RedLife - red;
|
||||
BlueLife = BlueLife - red < 0 ? 0 : BlueLife - blue;
|
||||
}
|
||||
|
||||
return { RedLife, GreenLife, BlueLife };
|
||||
}
|
||||
|
||||
function eventClasses(resolution, construct) {
|
||||
if (!resolution) return '';
|
||||
const startSkill = resolution.stage === 'START_SKILL';
|
||||
@ -264,15 +196,16 @@ function eventClasses(resolution, construct) {
|
||||
|
||||
// Deal damage to construct and return effect
|
||||
if (target && postSkill) {
|
||||
construct.green_life.value = resolution.target.green;
|
||||
if (colour === 'Red') {
|
||||
construct.red_life.value = resolution.target.red;
|
||||
return 'red-damage';
|
||||
}
|
||||
if (colour === 'Blue') {
|
||||
construct.blue_life.value = resolution.target.blue;
|
||||
return 'blue-damage';
|
||||
}
|
||||
if (colour === 'Green') return 'green-damage';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (type === 'Healing') {
|
||||
@ -280,7 +213,9 @@ function eventClasses(resolution, construct) {
|
||||
if (source && startSkill) return 'active-skill';
|
||||
if (target && endSkill) return 'active-skill';
|
||||
if (target && postSkill) {
|
||||
construct.green_life.value = resolution.target.green;
|
||||
return 'green-damage';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,9 +249,19 @@ function eventClasses(resolution, construct) {
|
||||
if (source && startSkill) return 'active-skill';
|
||||
if (target && endSkill) return 'active-skill';
|
||||
if (target && postSkill) {
|
||||
if (red > 0 && blue > 0) return 'purple-damage';
|
||||
if (red > 0) return 'red-damage';
|
||||
if (blue > 0) return 'blue-damage';
|
||||
if (red > 0 && blue > 0) {
|
||||
construct.red_life.value = resolution.target.red;
|
||||
construct.blue_life.value = resolution.target.blue;
|
||||
return 'purple-damage';
|
||||
}
|
||||
if (red > 0) {
|
||||
construct.red_life.value = resolution.target.red;
|
||||
return 'red-damage';
|
||||
}
|
||||
if (blue > 0) {
|
||||
construct.blue_life.value = resolution.target.blue;
|
||||
return 'blue-damage';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -488,7 +433,6 @@ module.exports = {
|
||||
eventClasses,
|
||||
getCombatSequence,
|
||||
getCombatText,
|
||||
constructHealth,
|
||||
NULL_UUID,
|
||||
STATS,
|
||||
COLOURS,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user