I use Artemis entity system framework, C# port. I have problem with figuring out a good way to handle items and using them.
Game is AI driven mostly, so it's not the player that is interacting, but AI. AI is basically Entity with
AIBehaviorComponent that is ran by
AISystem. AI has helper functions that allows it to find all items (ie. Entities with
InteractiveComponent) and then it can pathfind to it and use that item. AI is using
BehaviorTree that is stored in it's component.
InteractiveComponentthat allows player and AI to
Use entity. I have this thing working, but it looks a bit dirty solution.
Use method is interface that is implemented by Item object that is tied to that component. This way i can have item made with:
new InteractiveComponent(new AwesomeItem());
Use requires me to:
- Get entity ref
- Find component 'InteractiveComponent`
me is (this) Entity. The AI entity that is calling the use. I am passing entity to
Use method, because using something can alter the entity. It could add component to it, check if it has certain component and then modify the data or remove components, it could even remove the entity.
So, I'm bit lost here. This works, so it's "ok" i guess, but it looks very dirty. I have not found a way to allow somekind of
InteractiveSystem to take care of item using without adding huge complexity issues ( Those arise quickly when you try to force Entity system to do something it does not easily allow ).
So, question is:
How to decouple this so, that i don't have to pass Entity to component?
I just don't feel good about the current code but so far it's the best solution we have come up with.