int GetId(ComponentManager cm, ArmComponent arm) { int freeID = 0; foreach (var playerEntity in cm.GetComponentsOfType <PlayerControlComponent>()) { if (armID != playerEntity.Key) { freeID = playerEntity.Key; } } armID = freeID; return(freeID); }
public void Update(GameTime gameTime) { ComponentManager cm = ComponentManager.GetInstance(); foreach (var entity in cm.GetComponentsOfType <ArmComponent>()) { ArmComponent armComp = (ArmComponent)entity.Value; MoveComponent moveComp = cm.GetComponentForEntity <MoveComponent>(armComp.playerID); AnimationGroupComponent armAnimation = cm.GetComponentForEntity <AnimationGroupComponent>(entity.Key); KnockbackComponent knockbackComp = cm.GetComponentForEntity <KnockbackComponent>(armComp.playerID); if (knockbackComp != null && knockbackComp.KnockbackActive) { return; } if (!cm.HasEntityComponent <AnimationGroupComponent>(armComp.playerID)) { return; } AnimationGroupComponent playerAnimation = cm.GetComponentForEntity <AnimationGroupComponent>(armComp.playerID); int animation = GetAnimationRow(moveComp.Direction); int walking = cm.GetComponentForEntity <MoveComponent>(armComp.playerID).Velocity != new Vector2(0.0f, 0.0f) ? 4 : 0; int attacking = cm.GetComponentForEntity <AttackComponent>(armComp.playerID).AttackCooldown > 0.0f ? 4 : 0; if (playerAnimation.ActiveAnimation != animation + walking) { playerAnimation.ActiveAnimation = animation + walking; } if (armAnimation.ActiveAnimation != animation + attacking) { armAnimation.ActiveAnimation = animation + attacking; } if (cm.HasEntityComponent <InventoryComponent>(armComp.playerID)) { InventoryComponent invenComp = cm.GetComponentForEntity <InventoryComponent>(armComp.playerID); ChangeEquipmentDirection(cm, ref invenComp, 0, animation + attacking); ChangeEquipmentDirection(cm, ref invenComp, 1, animation + walking); ChangeEquipmentDirection(cm, ref invenComp, 2, animation + walking); } } }