Implementing elemental interactions

Started by
1 comment, last by LorenzoGatti 1 year, 2 months ago

Hello,
I'm working on a RPG game with elemental trait interactions similar to pokemon. Currently I can only think of a CheckInteraction() function everytime there is an attack or interaction, an a bunch of switch statement to calculate the damage output. Is there a “cleaner” way to do this?
I'm only doing 5 elements (or rather, agents, they are strictly not elements, I'm only calling them elements to simplify the idea) based on the Chinese Traditional thinking system: wood, fire, earth, water, and metal. All of them will have interactions with others like so. I'll take Fire for example:

  • Being supported: Fire is supported by Wood:
    • When attacking each other, damage output of both is reduced.
    • When combined as one attack, damage output of both is increased.
  • Neutral: Fire is neutral againts Fire:
    • When attacking each other, damage output of both is unchanged.
    • When combined, damage output of both is increased.
  • Being contrasted: Fire is contrasted by Water:
    • When attacking each other, damage output of Water is increased, damage output of Fire is decreased.
    • When combining, damage output of both is decreased.
  • Support: Fire supports Earth:
    • When attacking each other, damage output of both is reduced.
    • When combined, damage output of both is increased
  • Contrast: Fire contrasts Metal:
    • When attacking each other, damage output of Fire is increased, damage output of Metal is decreased.
    • When combining, damage output of both is decreased.

There will be other interactions as well, such as when one heals other, stats bonuses when 2 supporting elements goes together in a pair. But all of them falls on the above idea.

Everthing can be sumarized by the chart below:

Thank you very much in advance. I know this sounds like homework, but it is really just my hobby project to understand how games with element like pokemon works.

Advertisement

If the interaction is only based on the relative distance of the other element in the green circle, then you can give each element a number (0 to 4), and compute the relative (positive) distance with (DEST - SOURCE + 5) MOD 5 . The +5 ensure the result is always positive.

Say wood=0, fire=1, etc, So from wood to metal = (metal - wood + 5) MOD 5 = (3 - 0 + 5) MOD 5 = 3

From water to wood = (wood - water + 5) MOD 5 = (0 - 4 + 5) MOD 5 = 1

Handling your interactions as lookup tables seems suitable. For every pair of elements A and B you need a few numbers to use in your formulas:

  • damage increase or decrease when A attacks B
  • damage increase or decrease when you combine some B with a mainly A attack

If you treat elements as indices (e.g. fire=2) you can simply put these numbers in arrays and access them directly, no need for functions and switch statements.

Alberth's suggestions represent a way to handle lookup tables without redundancy in the likely case that the five elements are completely symmetrical, when you don't need 25 distinct values for each parameter but only 5: the same element, green arrow in and out, red arrow in and out.

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement