Esempio n. 1
0
        public bool ShouldApply(IHasDataId ownerContext, IUtilityVariables utilityVariables)
        {
            var unitsCaughtInShape = GetMaxSurroundingUnits(ownerContext as Unit);

            _cachedMax = unitsCaughtInShape;
            return(_cachedMax > 1);
        }
Esempio n. 2
0
        public UnitAbility GetAbilityToUse(Unit unit, IUtilityVariables variables)
        {
            var abilityUtility = variables
                                 .GetRelatedUtilities(UtilityVariableTypes.IsAbilityDamaging)
                                 .OrderByDescending(x => x.Value)
                                 .First();

            return(unit.GetAbility(abilityUtility.Key.RelatedId));
        }
        public static int GetBestRelatedIdFor(this IUtilityVariables variables, params int[] utilityIds)
        {
            var entries = GetRelatedScoresFor(variables, utilityIds).ToArray();

            if (entries.Length > 0)
            {
                return(entries[0].Key);
            }
            return(-1);
        }
        public Unit GetBestTarget(IHasDataId context, IUtilityVariables variables)
        {
            var targetUtility = variables
                                .GetRelatedUtilities(UtilityVariableTypes.PartyLowHealth)
                                .OrderByDescending(x => x.Value)
                                .FirstOrDefault();

            if (targetUtility.Key.UtilityId == 0)
            {
                return(null);
            }

            return(Level.GameUnits.Single(x => x.Unit.Id == targetUtility.Key.RelatedId).Unit);
        }
Esempio n. 5
0
        public AbilityWithTarget GetBestTarget(IHasDataId context, IUtilityVariables variables)
        {
            try
            {
                var unit         = (context as Unit);
                var abilityToUse = GetAbilityToUse(unit, variables);

                if (abilityToUse.Shape.Equals(ShapePresets.Empty))
                {
                    var nonShapedTargetId = GetBestTargetForNonShapedAttack(variables);
                    return(new AbilityWithTarget(nonShapedTargetId, abilityToUse.Id));
                }

                var shapedTargetId = GetBestTargetForShapedAttack(unit, abilityToUse, variables);
                return(new AbilityWithTarget(shapedTargetId, abilityToUse.Id));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
        public object GetBestLocation(IHasDataId context, IUtilityVariables variables)
        {
            var ownerUnit     = (context as Unit);
            var targetUtility = variables
                                .GetRelatedUtilities(UtilityVariableTypes.IsADanger)
                                .OrderByDescending(x => x.Value)
                                .FirstOrDefault();

            if (targetUtility.Key.UtilityId == 0)
            {
                return(MovementAdvisor.GetBestMovementAwayFromLocation(ownerUnit, ownerUnit.Position));
            }

            var targetUnit = Level.GameUnits.FirstOrDefault(x => x.Agent.OwnerContext.Id == targetUtility.Key.RelatedId);

            if (targetUnit == null)
            {
                return(MovementAdvisor.GetBestMovementAwayFromLocation(ownerUnit, ownerUnit.Position));
            }

            return(MovementAdvisor.GetBestMovementAwayFromTarget(ownerUnit, targetUnit.Unit));
        }
        public static IEnumerable <KeyValuePair <int, float> > GetRelatedScoresFor(this IUtilityVariables variables, params int[] utilityIds)
        {
            var cache = new Dictionary <int, List <float> >();

            foreach (var utilityId in utilityIds)
            {
                var relatedUtilities = variables.GetRelatedUtilities(utilityId);
                foreach (var relatedUtility in relatedUtilities)
                {
                    if (cache.ContainsKey(relatedUtility.Key.RelatedId))
                    {
                        cache[relatedUtility.Key.RelatedId].Add(relatedUtility.Value);
                        continue;
                    }

                    cache.Add(relatedUtility.Key.RelatedId, new List <float> {
                        relatedUtility.Value
                    });
                }
            }

            return(cache.Select(x => new KeyValuePair <int, float>(x.Key, x.Value.Sum())).OrderByDescending(x => x.Value));
        }
Esempio n. 8
0
        public int GetBestTargetForShapedAttack(Unit unit, UnitAbility ability, IUtilityVariables variables)
        {
            var scoredEnemyDistances = variables.GetRelatedScoresFor(UtilityVariableTypes.EnemyDistance);

            var shapeLayouts = new[]
            {
                ability.Shape,
                ability.Shape.Rotate90(),
                ability.Shape.Rotate180(),
                ability.Shape.RotateN90()
            };

            var maxUnitsToHit  = ability.Shape.ActiveCellCount();
            var bestEnemiesHit = 0;
            var bestEnemyId    = 0;

            foreach (var enemyDistance in scoredEnemyDistances)
            {
                var enemy = Level.GetUnitById(enemyDistance.Key);
                foreach (var shape in shapeLayouts)
                {
                    var unitsHit = Level.GetAllUnitsInShape(enemy.Position, shape).Count();
                    if (unitsHit >= maxUnitsToHit)
                    {
                        return(enemy.Id);
                    }

                    if (unitsHit > bestEnemiesHit)
                    {
                        bestEnemiesHit = unitsHit;
                        bestEnemyId    = enemy.Id;
                    }
                }
            }

            return(bestEnemyId);
        }
Esempio n. 9
0
 public int GetBestTargetForNonShapedAttack(IUtilityVariables variables)
 {
     return(variables.GetBestRelatedIdFor(
                UtilityVariableTypes.EnemyDistance,
                UtilityVariableTypes.EnemyLowHealth));
 }
Esempio n. 10
0
 public float ModifyValue(float currentValue, IHasDataId ownerContext, IUtilityVariables utilityVariables)
 {
     return(currentValue * _cachedMax);
 }
 public float ModifyValue(float currentValue, IHasDataId ownerContext, IUtilityVariables utilityVariables)
 {
     return(currentValue + AdditiveValue);
 }
 public bool ShouldApply(IHasDataId ownerContext, IUtilityVariables utilityVariables) => true;