I am making a game in which the player character can gain traits that change how their character behaves in my world model or add functionality to it. For example, the character might gain the "feather" trait that changes how fall damage is calculated or the "strong" trait that means the player can now pick up items that were previously just part of the scenery.  I have been hard coding traits in their relevant classes and switching a boolean to change behavior when they come into play, but it is getting rather unmanageable as my trait list grows.(I am also missing out on a lot of the emergence I was hoping to get) There must be a more scalable and decoupled way of doing this.  How would you code such a feature where code behavior changes or expands at runtime? If you are not inclined to do my work for me, which programming patterns would you use to achieve this kind of behavior?
Overview:  Lots of games with RPG-like statistics allow for character "buffs", ranging from simple "Deal 25% extra damage" to more complicated things like "Deal 15 damage back to attackers when hit."  The specifics of each type of buff aren't really relevant.  I'm looking for a (presumably object-oriented) way to handle arbitrary buffs.  Details:  In my particular case, I have multiple characters in a turn-based battle environment, so I envisioned buffs being tied to events like "OnTurnStart", "OnReceiveDamage", etc.  Perhaps each buff is a subclass of a main Buff abstract class, where only the relevant events are overloaded.  Then each character could have a vector of buffs currently applied.  Does this solution make sense?  I can certainly see dozens of event types being necessary, it feels like making a new subclass for each buff is overkill, and it doesn't seem to allow for any buff "interactions".  That is, if I wanted to implement a cap on damage boosts so that even if you had 10 different buffs which all give 25% extra damage, you only do 100% extra instead of 250% extra.  And there's more complicated situations that ideally I could control.  I'm sure everyone can come up with examples of how more sophisticated buffs can potentially interact with each other in a way that as a game developer I may not want.  As a relatively inexperienced C++ programmer (I generally have used C in embedded systems), I feel like my solution is simplistic and probably doesn't take full advantage of the object-oriented language.  Thoughts?  Has anyone here designed a fairly robust buff system before?  Edit: Regarding Answer(s):  I selected an answer primarily based on good detail and a solid answer to the question I asked, but reading the responses gave me some more insight.  Perhaps unsurprisingly, the different systems or tweaked systems seem to apply better to certain situations.  What system works best for my game will depend on the types, variance, and number of buffs I intend to be able to apply.  For a game like Diablo 3 (mentioned below), where nearly any bit of equipment can change a buff's strength, the buffs are just character stats system seems like a good idea whenever possible.  For the turn-based situation I'm in, the event-based approach may be more suitable.  In any case, I'm still hoping someone comes along with a fancy "OO" magic bullet which will allow for me to apply a +2 move distance per turn buff, a deal 50% of damage taken back to the attacker buff, and a automatically teleport to a nearby tile when attacked from 3 or more tiles away buff in a single system without turning a +5 strength buff into its own subclass.  I think the closest thing is the answer I marked, but the floor is still open.  Thanks to everyone for the input.
What are the alternative Android app markets? How many competing Android markets (other than the Play Store itself) are there and are they any good?  Which ones do you use and why? How do I simulate flip of biased coin? In unbiased coin flip H or T occurs 50% of times.  But I want to simulate coin which gives H  with probability 'p' and T with probability '(1-p)'.  something like this:  def flip(p):    '''this function return H with probability p'''    # do something    return result  &gt;&gt; [flip(0.8) for i in xrange(10)] [H,H,T,H,H,H,T,H,H,H] Isomorphism equivalence implies fundamental group is abelian How to cut holes in an object using another object? I'm trying to model a M16 but I have a problem with cutting the holes on top of the handguard of the weapon.     As you can see in the picture above, I have tried to cut holes into the handguard (The marked mesh in edit mode) with the object above it (The multiple cylinder one). But I simply can't. I have tried the Boolean modifier but the handguard just disappears and doesn't make any holes. Same with the Knife Project thing. Nothing works, it won't make a hole in it. I also installed the BoolTool 0.2 but that didn't work either...The multiple cylinder object goes invisible and doesn't make any cuts.    In the picture above you can see how I want the cuts to be made. I want the holes of the multiple cylinder object to be there on the handguard when I take it away. Nothing works. The 3 methods I tried with worked on other parts of this model but not on the handguard. It should be the handguards mesh's fault but I can do nothing about it. Is there any solution? I've just answered .  After accepting the answer, the OP then changed his question to another problem - which I know I shouldn't have answered (I should have requested as new question) but I updated my answer anyway.  The OP has now edited his question to remove the essence of either the original or new problem, and instead has a statement saying that the problem has been fixed.  What is the correct thing to do here?  Roll the question back so it's in its original state? Roll it back to the "new problem" state? Leave it and let him continue to get downvoted and/or closed by people who didn't see the original question? How to do research in two very different fields? Using "of" or apostrophe, which is more common? When I use the MouseUp event, I can get it to fire with a mouse right-click. But MouseLeftButtonUp won't fire with either click!  &lt;Button MouseLeftButtonUp="btnNewConfig_MouseUp"  Name="btnNewConfig"&gt;     &lt;StackPanel Orientation="Horizontal"&gt;         &lt;Image Source="Icons\new.ico" Height="24" Width="24" Margin="5"/&gt;         &lt;TextBlock VerticalAlignment="Center"&gt;New&lt;/TextBlock&gt;     &lt;/StackPanel&gt; &lt;/Button&gt;   I know this is most likely something simple. Thanks for the help! Could someone please explain the differences between the 3 fitting methods, method = c("CSS-ML", "ML", "CSS"), in Arima?  If I run the code below I get an error message, but if I specify method="ML" in Arima it runs fine.  So I was curious what the difference was between the 3 fitting methods.  Code with error:  library("fpp")  tsTrain &lt;- window(hsales,end=1989.99)  pvar&lt;-1:10 dvar&lt;-1:2 qvar&lt;-1:7  OrderGrid&lt;-expand.grid(pvar,dvar,qvar)  n &lt;- function(a,b,c) {Arima(tsTrain, order=c(a,b,c))} ModFit &lt;- do.call(Vectorize(n, SIMPLIFY=FALSE), unname(OrderGrid))   Fixed Code:  library("fpp")  tsTrain &lt;- window(hsales,end=1989.99)  pvar&lt;-1:10 dvar&lt;-1:2 qvar&lt;-1:7  OrderGrid&lt;-expand.grid(pvar,dvar,qvar)  n &lt;- function(a,b,c) {Arima(tsTrain, order=c(a,b,c),method="ML")} ModFit &lt;- do.call(Vectorize(n, SIMPLIFY=FALSE), unname(OrderGrid)) Consequences of overstaying Schengen visa for 6 months I know I need to have (although I don't know why) a GROUP BY clause on the end of a SQL query that uses any aggregate functions like count, sum, avg, etc:  SELECT count(userID), userName FROM users GROUP BY userName   When else would GROUP BY be useful, and what are the performance ramifications? How do I align the viewport to a face normal? I would like to align the view straight on to a face, perpendicular to the normal. How do I align the 3D viewport to the face of a mesh? putExtra treeMap returns HashMap cannot be cast to TreeMap android What exactly did mv /tmp/folder/* /* do to my filesystem? It's hard to search for special characters on google, which is why I'm posting this here.  I recently ran (as root) a mv /tmp/folder/* /* when I meant to run mv /tmp/folder/* ./ Big mistake!  Things broke! A lot of files got mixed up and placed into strange places, none of the normal unix commands worked (ls, dir, cat, etc) and once you logged off, you couldn't ssh back in -- it would give you a prompt, but not accept the old passwords.  Running ls /* shows me that it performs ls on every directory in /. If I tried to draw a parallel, then mv should have simply moved (or copied?) the files to every directory in /. Instead, really weird things happened, and I was just curious what exactly was going on.  More info: The files in /tmp/folder had been transferred from a windows machine, and had been named file (#).txt, where (#) is a number up to two digits, with a space between file and the parenthesis. There were ~40 of these text files. Understanding Join Attributes by Location in QGIS? I wonder if there is somewhere an explanation for the parameters that can be set when running the Algorithm "Join Attributes by Location" in QGIS 2.18.  I had a look here:       but there is no explanation. Any hints? How to use java.util.Scanner to correctly read user input from System.in and act on it? how can I add the charge and the counter ions to my complex? I'm using chemfig.  \schemestart \chemname{\chemleft[\chemfig{Ni (&lt;:[1]OH_2) (-[2]OH_2) (&lt;:[3]OH_2) (&lt;[5]OH_2) (-[6]OH_2) (&lt;[7]OH_2) }\chemright]}{\ce{[Ni(OH2)6]Cl2}} \schemestop     Thanks! Quad tree vs Grid based collision detection Analytics search keywords are unreliable How do you empty the buffers and cache on a Linux system? Prior to doing some benchmarking work how would one free up the memory (RAM) that the Linux Kernel is consuming for its buffers and cache?    Note that this is mostly useful for benchmarking. Emptying the buffers and cache reduces performance! If you're here because you thought that freeing buffers and cache was a positive thing, go and read . The short story: free memory is unused memory is wasted memory.