xonecas.ioDon't click! Sean Caetano Martin Sign in
tiny-adventure / web / js / traits.js 30 lines1.4 kB Raw
1const TYPES = ['poison', 'fire', 'frost', 'lightning', 'holy', 'shadow'];
2const cap = (w) => w[0].toUpperCase() + w.slice(1);
3
4const TRAITS = {
5  lifesteal: ['Lifesteal', 'heals 30% of damage dealt'],
6  first: ['First strike', 'acts first, opening blow +50%'],
7  sweep: ['Sweep', 'single hits splash a second foe for half'],
8  pierce: ['Pierce', 'ignores defense and armor'],
9  thorns: ['Thorns', 'melee attackers take 25% back'],
10  armored: ['Armored', 'defense +3, pierce cuts through'],
11  swarm: ['Swarm', 'more of them, each weaker'],
12  ...Object.fromEntries(TYPES.map((t) => [t, [cap(t), `physical abilities deal ${t} damage`]])),
13  ...Object.fromEntries(TYPES.map((t) => [`guard-${t}`, [`${cap(t)} guard`, `defense also cuts ${t} damage, and ${t} hazards are spared`]])),
14};
15
16export const traitName = (t) => TRAITS[t]?.[0] || t;
17export const traitText = (t) => (TRAITS[t] ? `${TRAITS[t][0]}: ${TRAITS[t][1]}` : t);
18
19export function heroTraits(u) {
20  const out = [...(u.traits || [])];
21  for (const it of Object.values(u.gear || {})) if (it?.trait && !out.includes(it.trait)) out.push(it.trait);
22  return out;
23}
24
25export function nature(foes) {
26  const traits = [...new Set(foes.flatMap((e) => e.traits || []))];
27  const weak = [...new Set(foes.flatMap((e) => e.weak || []))];
28  const resist = [...new Set(foes.flatMap((e) => e.resist || []))];
29  return { traits, weak, resist };
30}