Original Post
I'm currently writing code for a game that has some basic spell effects and attacks. In the course of prototyping up some of the classes, I've come to realize that I'm spending an inordinate amount of time because I don't have a good system for keeping track of effects that have a time duration. I'm not doing anything fancy, it's very much in the vein of most RPGs, such as World of Warcraft with their buff/debuff system.
For example, right now, I have an ability that can be applied to multiple people within a certain radius of the player. When they receive the effect, they retain that effect for 5 seconds. Not too hard. But say now I want to prevent the attack from stacking, but if someone else applies the effect again, the effect simply lasts longer.
These are relatively simple things for me to describe, but I've found to be very difficult to get the code just right for all cases as the number of effects like these grows. My scheme for these effects has basically been explicitly coding the start and end times and doing everything based off of that. This is just not scalable for me in terms of programmer time as the number of effects grow (and as the effects themselves grow in complexity).
So the question:
What other ways are there to implement these time based effects?
I've given it some thought and I know that just about all of the effects I can think of can be described as some interval on a number line, so I could build some system that utilizes that to help me figure out all the effects that are currently active at any given time. My issue with this is that the number line is just way too simple, in my opinion, to help me figure out these effects in some complicated situations. I could easily end up with doing O(n^2) operations to make sure no effect stomps some other effect. I could minimize this by binning effects to avoid comparing effects that have no relation with each other. But I'm not convinced this solution is the best.
Any others out there? Performance, although important, is not the top priority. Ease of programming (both of the system itself and programming the effects so that they achieve their correct intended behavior) and iteration speed is top goal here.
For example, right now, I have an ability that can be applied to multiple people within a certain radius of the player. When they receive the effect, they retain that effect for 5 seconds. Not too hard. But say now I want to prevent the attack from stacking, but if someone else applies the effect again, the effect simply lasts longer.
These are relatively simple things for me to describe, but I've found to be very difficult to get the code just right for all cases as the number of effects like these grows. My scheme for these effects has basically been explicitly coding the start and end times and doing everything based off of that. This is just not scalable for me in terms of programmer time as the number of effects grow (and as the effects themselves grow in complexity).
So the question:
What other ways are there to implement these time based effects?
I've given it some thought and I know that just about all of the effects I can think of can be described as some interval on a number line, so I could build some system that utilizes that to help me figure out all the effects that are currently active at any given time. My issue with this is that the number line is just way too simple, in my opinion, to help me figure out these effects in some complicated situations. I could easily end up with doing O(n^2) operations to make sure no effect stomps some other effect. I could minimize this by binning effects to avoid comparing effects that have no relation with each other. But I'm not convinced this solution is the best.
Any others out there? Performance, although important, is not the top priority. Ease of programming (both of the system itself and programming the effects so that they achieve their correct intended behavior) and iteration speed is top goal here.