3 ms·
What's the gist of the setup for how a complex RPG rule system gets coded up? Like in D&D or a Diablo-like, you have base stats, equipment or classes modify tho
by tgb 6y ago
What's the gist of the setup for how a complex RPG rule system gets coded up? Like in D&D or a Diablo-like, you have base stats, equipment or classes modify those stats, sometimes the modifiers depend upon the circumstances, and maybe the modifiers get modified. So clearly you don't want to have a Belt of +4 Strength just do wearer.strength += 4 since at some point you'll have to take off the belt or are in an anti-magic field, etc. But what's a good and/or standard design for encoding all that kind of logic?
- formalsystem 6y agoThere's a combination of patterns. IMO the best way to learn how this stuff works is to look at the code of a production level MMO/MOBA/RTS. Here is a really good one https://assetstore.unity.com/packages/templates/systems/ummorpg-51212 https://assetstore.unity.com/packages/templates/systems/ummo... Worth every penny.
- MrStonedOne 6y agoYou have calculate it on read based on the user's state at that time. getStr() { output = this.str;foreach (equip) output += equip.getStrMod() }
- munificent 6y agoI've run into this exact issue in my roguelike [1]. I don't think I have a fully baked solution yet, but the direction I'm going [2] is a combination of the Observer pattern and caching. For derived stats, it's not enough to just always recalculate its value from scratch every time you access it. At least in my game, I also want to tell the user when the value of a derived stat changes. If you equip a piece of armor that raises your strength, I want the game to tell you "You feel stronger!". So each derived stat stores its current value and then has a refresh() function to recalculate itself. The stat is refreshed at the end of each turn. It recalculates the value and then compares its previously cached one. If the value changed, it logs the result and then updates the cache. [1]: https://github.com/munificent/hauberk https://github.com/munificent/hauberk [2]: https://github.com/munificent/hauberk/blob/master/lib/src/engine/hero/stat.dart https://github.com/munificent/hauberk/blob/master/lib/src/en...