Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

As the title suggests, my question is how to abstract the concept of 'attacking' using an ECS (entity component system). The "game" I'm working on is a roguelike in real-time, where all enemies/NPCs/player is an Entity (just an Id) with components.

I read this link and it helped clarify some things about an attack system, but I'm still confused how to implement this with an ECS.

share|improve this question
    
I might be underthinking this, but isn't writing and giving each (attackable) entity an health component and an attack component enough? –  Qqwy Jan 12 '13 at 21:43
1  
At first it may seem like that, but other things come into effect, such as: How does an entity attack? Which animation does it go to? How to "activate" an attack (either from keyboard input or from AI)? It's these questions that confuse me when trying to design this. –  Mohammed Hossain Jan 12 '13 at 23:02
2  
None of those things really have anything to do with component systems, though. That's just.. y'know.. garden variety programming, right? –  Trevor Powell Jan 12 '13 at 23:41

1 Answer 1

up vote 1 down vote accepted

Whether your game uses an Entity-Component model, Inheritence Hierarchy, or some mixin of both strategies, it doesn't dictate what a combat system is within the scope of a game.

As Qqwy points out, we're discussing the notion of some damage modifier applied to health. The damage modifier can also affect the durability of the attacked entity's gear with time too, making it less useful with every attack made. You may need to factor in resistences, temporary stat modifiers too which could make an entity more powerful or more susceptable to damage.

My advice is design your combat system very high-level like. Consider what you want your combat system to involve and how it will behave. Once you have this guideline, you'll quickly notice what makes sense to be components.

One obvious idea would be to just create a CombatStatComponent that has all your stats. This could include the base stats an avatar can have, the extra stats they can acquire possibly from gear, resistence levels the avatar presently has. The combat system uses this components data to measure the damage possible between two entities when an attack is made. When the attack occurs, an event gets sent to the damaged entity with the damage done. It simply modifies it's health component's value.

But keep in mind, all the ECS does in this scenario is describe how you organize the code that makes up this combat system. But the internal steps the system must perform to apply some damage remains the same from a generalistic point of view regardless of how you manage entities as a whole.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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