Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are three answers to implementing propegated stats in a video game:</p> <p>(1) this will satisfy any hobbist-game you will ever make (and pretty much every professional game as well):</p> <pre><code>character.GetStrength() { foreach(item in character.items) strFromItems += item.GetStrengthBonusForItems(); foreach(buff in character.buffs) strFromBuffs += buff.GetStrengthBonusForBuffs(); ... return character.baseStrength + strFromItems + ...; } </code></pre> <p>(note the different GetStrength*() functions have nothing to do with each other)</p> <p>(2) this will satisfy all games that don't have the word 'diablo' in the title:</p> <pre><code> character.GetStr() { ... // same as above, strength is rarely queried } character.GetMaxHP() { if (character._maxHPDirty) RecalcMaxHP(); return character.cachedMaxHP; } // repeat for damage, and your probably done, but profile to figure out // exactly which stats are important to your game </code></pre> <p>(3) else</p> <pre><code> // changes in diablo happen very infrequently compared to queries, // so up propegate to optimize queries. Moreover, 10 people edit // the stat calculation formulas so having the up propegation match // the caculation w/o writing code is pretty important for robustness. character.OnEquip(item) { statList.merge(item.statlist); } character.GetStrength() { statList.getStat(STRENGTH); } statlist.getStat(id) { if (IS_FAST_STAT(id)) return cachedFastStats[id]; return cachedStats.lookup(id); } statlist.merge(statlist) { // left for an exercise for the reader } </code></pre> <p>And honestly (3) was probably overkill.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload