const preact = require('preact'); const get = require('lodash/get'); const shapes = require('./components/shapes'); const stringSort = (k, desc) => { if (desc) { return (a, b) => { if (!get(a, k)) return 1; if (!get(b, k)) return -1; return get(b, k).localeCompare(get(a, k)); }; } return (a, b) => { if (!get(a, k)) return 1; if (!get(b, k)) return -1; return get(a, k).localeCompare(get(b, k)); }; }; const numSort = (k, desc) => { if (desc) { return (a, b) => { if (!get(a, k)) return 1; if (!get(b, k)) return -1; return get(b, k) - get(a, k); }; } return (a, b) => { if (!get(a, k)) return 1; if (!get(b, k)) return -1; return get(a, k) - get(b, k); }; }; const NULL_UUID = '00000000-0000-0000-0000-000000000000'; const STATS = { RedPower: { stat: 'red_power', colour: 'red', svg: shapes.circle, }, GreenPower: { stat: 'green_power', colour: 'green', svg: shapes.circle, }, BluePower: { stat: 'blue_power', colour: 'blue', svg: shapes.circle, }, Speed: { stat: 'speed', colour: 'white', svg: shapes.triangle, }, RedLife: { stat: 'red_life', colour: 'red', svg: shapes.square, }, GreenLife: { stat: 'green_life', colour: 'green', svg: shapes.square, }, BlueLife: { stat: 'blue_life', colour: 'blue', svg: shapes.square, }, }; function eventClasses(resolution, construct) { if (!resolution) return ''; const postSkill = resolution.stages.includes('POST_SKILL'); const source = construct.id === resolution.source.id; const target = construct.id === resolution.target.id; // not involved at all. blur them if (!(source || target)) return 'unfocus'; // not the target. just ignore for now // if (construct.id !== resolution.target.id) return ''; const [type, event] = resolution.event; if (type === 'Ko') { if (target) return 'ko'; } if (type === 'Disable') { const { skill, disable } = event; } if (type === 'Immunity') { const { skill, immunity } = event; } if (type === 'TargetKo') { const { skill } = event; } if (type === 'Damage') { const { skill, amount, mitigation, colour } = event; // Highlight the flow of damage from source -> target // 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') { construct.green_life.value = resolution.target.green; return 'green-damage'; } } } if (type === 'Healing') { const { skill, amount, overhealing } = event; if (target && postSkill) { construct.green_life.value = resolution.target.green; return 'green-damage'; } } if (type === 'Inversion') { const { skill } = event; } if (type === 'Reflection') { const { skill } = event; } if (type === 'Effect') { const { skill, effect, duration, construct_effects: constructEffects } = event; if (target && postSkill) construct.effects = constructEffects; } if (type === 'Skill') { const { skill } = event; // Highlight the flow of damage from source -> target } if (type === 'Removal') { const { effect, construct_effects: constructEffects } = event; if (target && postSkill) construct.effects = constructEffects; } if (type === 'Recharge') { const { skill, red, blue } = event; if (target && postSkill) { 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'; } } } if (type === 'Evasion') { const { skill, evasion_rating } = event; } return ''; } function getCombatSequence(resolution) { if (!resolution.event) return false; if (resolution.event[0] === 'Inversion') return false; if (resolution.event[0] === 'Skill') return [['START_SKILL', 'END_SKILL']]; if (resolution.event[0] === 'Ko') return [['POST_SKILL']]; switch (resolution.stages) { case 1: return [['START_SKILL', 'END_SKILL']]; case 2: return [['START_SKILL'], ['POST_SKILL']]; case 3: return [['START_SKILL']]; case 4: return [['END_SKILL'], ['POST_SKILL']]; case 5: return [['END_SKILL']]; case 6: return [['POST_SKILL']]; case 7: return false; default: return [['START_SKILL', 'END_SKILL'], ['POST_SKILL']]; } } function getCombatText(resolution, construct) { if (!resolution) return false; if (!resolution.stages.includes('POST_SKILL')) return false; if (construct.id !== resolution.target.id) return false; const [type, event] = resolution.event; if (type === 'Ko') { return 'KO!'; } if (type === 'Disable') { const { disable } = event; return `${disable}`; } if (type === 'Immunity') { return 'IMMUNE'; } if (type === 'Damage') { const { mitigation, colour } = event; let { amount } = event; if (colour === 'Green') amount *= -1; const mitigationText = mitigation ? `(${mitigation})` : ''; return `${amount} ${mitigationText}`; } if (type === 'Healing') { const { amount, overhealing } = event; return `${amount} (${overhealing} OH)`; } if (type === 'Inversion') { return 'INVERT'; } if (type === 'Reflection') { return 'REFLECT'; } if (type === 'Effect') { const { effect, duration } = event; return `+ ${effect} ${duration}T`; } if (type === 'Recharge') { const { red, blue } = event; return [`+${red}R ${blue}B`, '']; } if (type === 'Removal') { const { effect } = event; return `-${effect}`; } return false; } function convertItem(v) { if (['Red', 'Green', 'Blue'].includes(v)) { return ( shapes.vboxColour(v.toLowerCase()) ); } return v || ; // uncomment for double borders in vbox; // if (v) { // return