Decorator pattern, part 2

While working on wsilent, I quickly realized that the decorator pattern was ideal for weapon powerups. A ship object contains a weapon subobject (built using the template method, as described in an earlier article), and the weapon subobject can be decorated with powerups. These powerups can do things like cloning the bullets for a spread shot, or cutting energy / reload times for a rapid shot. The powerups can also be combined to form a rapid spread shot, and can be added and removed dynamically and independently of one another.

All of these requirements clearly fit the decorator pattern, but I had never used that pattern before and was unsure of how to do simple things, like remove a decoration without affecting anything but the decoration being removed. I did some test work on a small sample, and figured out a way to do it. I'm not entirely thrilled with it, since certain parts do things in ungood ways, but it works. In particular, I don't like how I had to split the decorator logic between the Paragraph object and the Decorator objects.

Based on my work here, I'll be able to move forward on wsilent and get the powerups using the decorator pattern, which will be much more flexible for what I plan to do in the future. Then I can get to work on that pesky websocket problem that seemingly broke the whole game.

Here is my sample of using the decorator pattern: http://pastebin.com/t48a2BSs