Esempio n. 1
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 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);
        }
        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));
        }