1
\$\begingroup\$

I'm trying my hand at an action RPG kind of game and using a modified version of entityx from alecthomas, which is basically an Entity Component System. I have really big troubles with some of the stuff I want to implement, because I don't know how to put it in terms of Components. Here are some of the things I can't figure out:

  1. Let's say I have entities that are supposed to represent actors and they have things like Health, Stamina, Mana, Attributes... How would I implement a timed buff/debuff system, without defeating the purpose of ECS? Each actor can be affected by multiple buffs at a time and the buffs could influence anything about them. A component can only hold so much data and I can't introduce a new component for each buff that needs to save different data.

  2. If I had a Chain Lightning skill that I cast with an actor and it selects and damages enemy actors at random immediately, the game-logic processor would just dish out the damage and create an entity for the Lightning Effect with a RenderComponent. But the RenderComponent will only tell the render processor that it is Lightning, where does the data go that describes which enemies were hit? Most skill effects have some kind of parameter for their renderable parts like Source, Target, Intensity...

Both questions are based on the same problem: How do I represent things that can have diverse parameters in as few components as possible?

\$\endgroup\$
1
\$\begingroup\$

Your first problem - why not have a component for each buff? They do similar things, sure, but many buffs might operate quite differently. For example, the simplest would be to increase the player's health by some amount. However, you may have a more complex debuff that say damages allies that are near the player every x seconds.

If you don't want to create a new component for each type of buff, then you could use the Decorator pattern. Decorators allow you to add functionality to a class without affecting other instances of that class. It works by essentially wrapping an instance of a class into a subclass of it, however it is done at run-time rather than compile-time like inheritance.

For your second problem it seems like you almost answer it yourself. It sounds like you will need Source, Target and Intensity components and your Chain Lightning skill when spawning the Lightning Effect should have those components. How that data is passed between systems is a design choice you will need to make for your ECS, perhaps through a message system. This means that components or entities should be able to send and receive data to and from one another.

The Lightning Effect entity could push a message up into your game loop like "Source:Player, Target:Enemy5, Intensity:10" which could be read by other entities, and processed if the message was meant for them.

\$\endgroup\$
  • \$\begingroup\$ For the first point, yes you definitely want different Buff component classes for Buffs that perform different actions (self value change, AOE aura, etc.) but there's no reason the same type of buff class couldn't be used on different resource (health, mana, etc.) All the component needs is to store a reference to a resource's Component type (HealthComponent, ManaComponent, etc.) and apply the effect to that target component. \$\endgroup\$ – Zepee Feb 23 '15 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.