在视频游戏中实现传播的统计数据有三个答案:
(1) 这将满足您将制作的任何业余爱好者游戏(以及几乎所有职业游戏):
character.GetStrength() {
foreach(item in character.items)
strFromItems += item.GetStrengthBonusForItems();
foreach(buff in character.buffs)
strFromBuffs += buff.GetStrengthBonusForBuffs();
...
return character.baseStrength + strFromItems + ...;
}
(注意不同的 GetStrength*() 函数彼此无关)
(2) 这将满足所有标题中没有“暗黑破坏神”一词的游戏:
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
(3) 其他
// 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
}
老实说(3)可能是矫枉过正。