Thursday, March 8, 2018

architecture - OOP implementation of BUFFS and Stats. Suggestion


I am developing an MMORPG server using NodeJS.


I am not sure how to implement Buffs, i mean, equipped objects or used skills have effects on the Player() which has many Stats(), some of them have a max cap...


Effects can change the Stat value, increasing or decreasing it by a value, a percentage or completly rewrite the value of the stat.


After a while I have decided to create a base class for buffs, which can be hidden (if they are casted from an equipped object) or shown if they came from an ability (Spell).


Anyway I need suggestion how to implement it, use an array for all active buffs for a stat and have a function calculate the value of the stat affected by buffs each time I need the value of the stat or...? Other more OOP's ways to do it?


I have read this What's a way to implement a flexible buff/debuff system? but this implements only a percentage system, which buffs can only say "+10%, +20%, etc...", but I would love to have an hybrid system, which can have percentage values or static values (like WoW does), and using modifiers it's hard to implement, because modifiers refers to the current value of stat :/


Thanks for suggestions :)



Answer



Just some short ideas:





  1. Only re-calculate the Player's stats when buffs/debuffs occure, not when you need the value. Much likely to what Sequel-based Databases do with indicies (MySQL for example updates the index cache on each write execution providing a verry fast interface for reading data).




  2. When you have multiple Types of values, you need to think of a formula or a hirachy. EvE online for example uses mostly percentage values with a stacking penalty. You take each percentage value into an array, sort it so the highest value comes in first, then for each percentage value in the array the following recieves a higher penalty. This is basicly a formula instead of a hierachy. Ragnarok Online did something simillar, there you had fixed values and percentages, you first took all your fixed + and - modifiers, added them to your base value, then added all the percentages onto that value.




its really up to your game design, everyone does it diferently.


for the OOP question:



I would highly recommend looking into entity systems, using effects as baseclass for buffs, debuffs, item boni, etc and stack them all into one array, or remove them when their timer runns out or whatever you like.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...