243 lines
7.2 KiB
JavaScript
243 lines
7.2 KiB
JavaScript
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 genAvatar = name => {
|
|
let hash = 0;
|
|
if (name.length === 0) return hash;
|
|
// Probs don't need to hash using the whole string
|
|
for (let i = 0; i < name.length; i += 1) {
|
|
const chr = name.charCodeAt(i);
|
|
hash = ((hash << 5) - hash) + chr;
|
|
hash = hash & 10000; // We have avatars named 0-19
|
|
}
|
|
return `sprite${hash}`;
|
|
};
|
|
|
|
function requestAvatar(name) {
|
|
const id = genAvatar(name);
|
|
const req = new Request(`/assets/molecules/${id}.svg`);
|
|
return fetch(req)
|
|
.then(res => res.text())
|
|
.then(svg => svg);
|
|
}
|
|
|
|
const NULL_UUID = '00000000-0000-0000-0000-000000000000';
|
|
|
|
const STATS = {
|
|
speed: { stat: 'speed', colour: 'white', svg: shapes.triangle },
|
|
redDamage: { stat: 'red_damage', colour: 'red', svg: shapes.circle },
|
|
greenDamage: { stat: 'green_damage', colour: 'green', svg: shapes.circle },
|
|
blueDamage: { stat: 'blue_damage', colour: 'blue', svg: shapes.circle },
|
|
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 },
|
|
};
|
|
|
|
const SPECS = {
|
|
Life: { colour: 'white', caption: 'Life', svg: shapes.square },
|
|
GreenLifeI: { colour: 'green', caption: 'Life', svg: shapes.square },
|
|
RedLifeI: { colour: 'red', caption: 'Life', svg: shapes.square },
|
|
BlueLifeI: { colour: 'blue', caption: 'Life', svg: shapes.square },
|
|
GRLI: { colour: 'yellow', caption: 'Life', svg: shapes.square },
|
|
GBLI: { colour: 'cyan', caption: 'Life', svg: shapes.square },
|
|
RBLI: { colour: 'purple', caption: 'Life', svg: shapes.square },
|
|
|
|
Damage: { colour: 'white', caption: 'Damage', svg: shapes.circle },
|
|
RedDamageI: { colour: 'red', caption: 'DamageI', svg: shapes.circle },
|
|
BlueDamageI: { colour: 'blue', caption: 'DamageI', svg: shapes.circle },
|
|
GreenDamageI: { colour: 'green', caption: 'DamageI', svg: shapes.circle },
|
|
GRDI: { colour: 'yellow', caption: 'DamageI', svg: shapes.circle },
|
|
GBDI: { colour: 'cyan', caption: 'DamageI', svg: shapes.circle },
|
|
RBDI: { colour: 'purple', caption: 'DamageI', svg: shapes.circle },
|
|
|
|
Speed: { colour: 'white', caption: 'Speed', svg: shapes.triangle },
|
|
RedSpeed: { colour: 'red', caption: 'Speed', svg: shapes.triangle },
|
|
BlueSpeedI: { colour: 'blue', caption: 'Speed', svg: shapes.triangle },
|
|
GreenSpeedI: { colour: 'green', caption: 'Speed', svg: shapes.triangle },
|
|
GRSpeedI: { colour: 'yellow', caption: 'Speed', svg: shapes.triangle },
|
|
GBSpeedI: { colour: 'cyan', caption: 'Speed', svg: shapes.triangle },
|
|
RBSpeedI: { colour: 'purple', caption: 'Speed', svg: shapes.triangle },
|
|
|
|
};
|
|
|
|
const COLOUR_ICONS = {
|
|
red: { colour: 'red', caption: 'red', svg: shapes.square },
|
|
blue: { colour: 'blue', caption: 'blue', svg: shapes.square },
|
|
green: { colour: 'green', caption: 'green', svg: shapes.square },
|
|
};
|
|
|
|
function eventClasses(resolution, cryp) {
|
|
if (!resolution) return '';
|
|
|
|
// not involved at all. blur them
|
|
if (cryp.id !== resolution.source.id && cryp.id !== resolution.target.id) return 'unfocus';
|
|
|
|
// not the target. just ignore for now
|
|
if (cryp.id !== resolution.target.id) return '';
|
|
|
|
const [type, event] = resolution.event;
|
|
|
|
if (type === 'Ko') {
|
|
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;
|
|
if (colour === 'RedDamage' && resolution.stage === 'POST_SKILL') return 'red-damage';
|
|
if (colour === 'BlueDamage' && resolution.stage === 'POST_SKILL') return 'blue-damage';
|
|
if (colour === 'GreenDamage' && resolution.stage === 'POST_SKILL') return 'green-damage';
|
|
}
|
|
|
|
if (type === 'Healing') {
|
|
const { skill, amount, overhealing } = event;
|
|
}
|
|
|
|
if (type === 'Inversion') {
|
|
const { skill } = event;
|
|
}
|
|
|
|
if (type === 'Reflection') {
|
|
const { skill } = event;
|
|
}
|
|
|
|
if (type === 'Effect') {
|
|
const { skill, effect, duration } = event;
|
|
}
|
|
|
|
if (type === 'Removal') {
|
|
const { effect } = event;
|
|
}
|
|
|
|
if (type === 'Recharge') {
|
|
const { skill, red, blue } = event;
|
|
}
|
|
|
|
if (type === 'Evasion') {
|
|
const { skill, evasion_rating } = event;
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
function getCombatText(cryp, resolution) {
|
|
if (!resolution) return '';
|
|
|
|
const [type, event] = resolution.event;
|
|
const source = cryp.id === resolution.source.id;
|
|
const target = cryp.id === resolution.target.id;
|
|
const startSkill = resolution.stage === 'START_SKILL';
|
|
const endSkill = resolution.stage === 'END_SKILL';
|
|
const postSkill = resolution.stage === 'POST_SKILL';
|
|
|
|
if (type === 'Ko') {
|
|
if (postSkill && target) return 'KO!';
|
|
}
|
|
|
|
if (type === 'Disable') {
|
|
const { skill, disable } = event;
|
|
}
|
|
|
|
if (type === 'Immunity') {
|
|
const { skill, immunity } = event;
|
|
if (postSkill && target) return 'IMMUNE';
|
|
}
|
|
|
|
if (type === 'TargetKo') {
|
|
const { skill } = event;
|
|
}
|
|
|
|
if (type === 'Damage') {
|
|
const { skill, amount, mitigation, colour } = event;
|
|
const mitigationText = mitigation
|
|
? `(${mitigation})`
|
|
: '';
|
|
if (startSkill && source) return `${skill}`;
|
|
if (endSkill && target) return `${skill}`;
|
|
if (postSkill && target) return `${amount} ${mitigationText}`;
|
|
}
|
|
|
|
if (type === 'Healing') {
|
|
const { skill, amount, overhealing } = event;
|
|
if (postSkill && target) return `${amount} (${overhealing}OH)`;
|
|
}
|
|
|
|
if (type === 'Inversion') {
|
|
const { skill } = event;
|
|
if (postSkill && target) return 'INVERT';
|
|
}
|
|
|
|
if (type === 'Reflection') {
|
|
const { skill } = event;
|
|
if (postSkill && target) return 'REFLECT';
|
|
}
|
|
|
|
if (type === 'Effect') {
|
|
const { skill, effect, duration } = event;
|
|
if (postSkill && target) return `+ ${effect} ${duration}T`;
|
|
}
|
|
|
|
if (type === 'Removal') {
|
|
const { effect } = event;
|
|
if (postSkill && target) return `- ${effect}`;
|
|
}
|
|
|
|
|
|
return '';
|
|
}
|
|
|
|
module.exports = {
|
|
stringSort,
|
|
numSort,
|
|
genAvatar,
|
|
requestAvatar,
|
|
eventClasses,
|
|
getCombatText,
|
|
NULL_UUID,
|
|
STATS,
|
|
SPECS,
|
|
COLOUR_ICONS,
|
|
};
|