Esempio n. 1
0
        public Task <ICombatAction> GetNextActionAsync(IEncounter encounter)
        {
            var defaultAttack = new GridTargetAction()
            {
                Id = _defaultAction.Id, Name = _defaultAction.Name, Element = _defaultAction.Element, TargetType = _defaultAction.TargetType, Modifiers = _defaultAction.Modifiers.Select(m => (IActionModifier) new GridActionModifier()
                {
                    Name = m.Name, TargetType = m.TargetType, ModifierType = m.ModifierType, Min = m.Min, Max = m.Max
                }).ToList()
            };

            // no intelligence right now..just set a command to find any enemy and dmg the health

            // mod this with stats eventually

            return(Task.FromResult((ICombatAction)defaultAttack));
        }
        public Task <ICombatAction> GetNextActionAsync(IEncounter encounter)
        {
            GridTargetAction selectedAction = null;


            // what do we want to know in our generic intel?


            // randomly cast a buff? keeping it simple for now just healing and dmg

            // healing

            var hpstat = Entity.Stats.FirstOrDefault(s => s.Name == "health");

            if (hpstat != null)
            {
                if (hpstat.Value < hpstat.Base / 2)
                {
                    var potentialActions = _actionsHeal.Where(action => Entity.CurrentStatsAtLeast(action.Modifiers.Where(m => m.TargetType == ModifierTargetTypes.Caster && m.Min < 0))).ToList();


                    if (potentialActions.Count() > 0)
                    {
                        // how much hp do we need? find the closest heal ...add some factoring of heal to mana cost effeciency later

                        var hpNeeded    = hpstat.Base - hpstat.Value;
                        var differences = potentialActions.Select(action => new { Action = action, Difference = Math.Abs(hpNeeded - action.Modifiers.FirstOrDefault(m => m.Name == "health").Value) });
                        selectedAction = differences.OrderBy(d => d.Difference).FirstOrDefault().Action;
                    }
                }
            }

            // damage
            if (selectedAction == null)
            {
                // pick the hardest hitting health stat we can afford to cast
                // AI cheat boost here by knowing the randomization result of the modifier..
                var potentialActions = _actionsDmg.OrderByDescending(action => Math.Abs(action.Modifiers.FirstOrDefault(m => m.Name == "health").Value));
                foreach (var action in potentialActions)
                {
                    if (_random.Next(1, 101) > 50)
                    {
                        continue;
                    }


                    var consumerMods = action.Modifiers.Where(m => m.TargetType == ModifierTargetTypes.Caster && m.Min < 0).ToList();
                    // can we meet all requirements?

                    var affordable = Entity.CurrentStatsAtLeast(consumerMods);
                    if (affordable)
                    {
                        selectedAction = action;
                        break;
                    }
                }
            }

            // randomly skip the ability altogether to add some feel of variety
            if (_random.Next(1, 101) > 50)
            {
                selectedAction = null;
            }


            if (selectedAction == null && Entity.CurrentStatsAtLeast(_defaultAction.Modifiers.Where(m => m.TargetType == ModifierTargetTypes.Caster)))
            {
                selectedAction = _defaultAction;
            }

            if (selectedAction == null)
            {
                return(Task.FromResult((ICombatAction)null));
            }

            var actionCopy = new GridTargetAction()
            {
                Element = selectedAction.Element, Modifiers = selectedAction.Modifiers.Select(m => (IActionModifier) new GridActionModifier()
                {
                    Name = m.Name, TargetType = m.TargetType, ModifierType = m.ModifierType, Min = m.Min, Max = m.Max
                }).ToList(), Id = selectedAction.Id, Name = selectedAction.Name, TargetType = selectedAction.TargetType
            };


            return(Task.FromResult((ICombatAction)actionCopy));
        }
Esempio n. 3
0
 public PlayerIntelligence(GridTargetAction defaultAction)
 {
     _defaultAction = defaultAction;
 }
 public GenericEntityIntelligence(List <ICombatAction> actions, ICombatAction defaultAction)
 {
     _actions       = actions.Select(a => (GridTargetAction)a).ToList();
     _defaultAction = (GridTargetAction)defaultAction;
 }