Esempio n. 1
0
        public static bool TryAssignAttackUnit(bool replace, Unit owner,
                                               PositionedObjectList <Unit> allUnits, float aggroRadius)
        {
            bool didAssignAttack = false;

            float aggroSquared        = aggroRadius * aggroRadius;
            bool  isTargetAnEnemyUnit = !owner.UnitData.IsEnemy;

            var foundUnit = allUnits.FirstOrDefault(item =>
                                                    (item.Position - owner.Position).LengthSquared() < aggroSquared &&
                                                    item.UnitData.IsEnemy == isTargetAnEnemyUnit &&
                                                    item.CurrentHealth > 0
                                                    );

            if (foundUnit != null)
            {
                owner.AssignAttackGoal(foundUnit, replace);
                didAssignAttack = true;
            }

            return(didAssignAttack);
        }