Closed atkdefender closed 3 years ago
No, it is not safe, and it is against rules. If you need to link entities - make aIdComponent
with unique int number in it, and made it PrimaryEntityIndex, then you can save Id in arrays and take entities by it with stateContext.GetEntityWithId
.
[State]
public sealed class IdComponent : IComponent {
[PrimaryEntityIndex] public int Value;
public override string ToString() => $"Id[{Value}]";
}
Regarding the problem, that you have. Mark each partner with PartnerComponent, and enemies with EnemyComponent, make a component - BattleOrderComponent - that will have int order value with EntityIndexAttribute (or PrimaryEntityIndex), that represent the order of fight. In one system calculate order and assign it to units.
Now you have entities with order of fight and distinct relationships with each other.
No, it is not safe, and it is against rules. If you need to link entities - make a
IdComponent
with unique int number in it, and made it PrimaryEntityIndex, then you can save Id in arrays and take entities by it withstateContext.GetEntityWithId
.[State] public sealed class IdComponent : IComponent { [PrimaryEntityIndex] public int Value; public override string ToString() => $"Id[{Value}]"; }
Regarding the problem, that you have. Mark each partner with PartnerComponent, and enemies with EnemyComponent, make a component - BattleOrderComponent - that will have int order value with EntityIndexAttribute (or PrimaryEntityIndex), that represent the order of fight. In one system calculate order and assign it to units.
Now you have entities with order of fight and distinct relationships with each other.
If putting a BattleOrderComponent on partner/enemy, to GetNextPartnerEnemy() must contexts.GetGroup(GameMatcher.BattleOrder), then sort the entities by battleOrder everytime.
Maybe List
Players and Monsters must fight each other in order. I wonder if I write it right. And in what situation this will go wrong.