public TargettedSkill Act(GameState state, ItemResolver <Character> c)
        {
            Behavior behavior = Behaviors [c.Item.CharacterClass];

            foreach (BehaviorSkill behaviorSkill in behavior.Skills.Where(x => x.OverrideCondition != GameCondition.None))
            {
                if (ConditionFinder.IsConditionTrue(behaviorSkill.OverrideCondition, state, c))
                {
                    TargettedSkill targettedSkill = ConsiderSkill(behaviorSkill.SkillName, state, c);
                    if (targettedSkill != null)
                    {
                        return(targettedSkill);
                    }
                }
            }

            foreach (BehaviorSkill behaviorSkill in behavior.Skills)
            {
                TargettedSkill targettedSkill = ConsiderSkill(behaviorSkill.SkillName, state, c);
                if (targettedSkill != null)
                {
                    return(targettedSkill);
                }
            }
            return(null);
        }
        static GameState ExtendEffect(string effectName, int power, ItemResolver <Character> character, GameState state)
        {
            DelayedAction removalAction = state.DelayedActions.First(x => {
                bool isRemoval             = x.TargetAction.Action.Type == ActionType.RemoveEffect;
                bool removingCorrectEffect = x.TargetAction.Action.EffectName == effectName;
                bool correctCharacter      = x.TargetAction.TargetInfo.TargetID == character.Item.ID;
                return(isRemoval && removingCorrectEffect && correctCharacter);
            });

            return(state.ExtendDelayedAction(removalAction, power));
        }
        static GameState AddNewEffect(string effectName, int power, ItemResolver <Character> character, GameState state)
        {
            state = state.UpdateCharacter(character.Item.AddStatusEffect(new StatusEffect(effectName)));
            character.Update(state);

            Action          removeAction          = new Action(ActionType.RemoveEffect, 0, effectName);
            TargettedAction removeActionTargetted = new TargettedAction(removeAction, TargettingInfo.Self(character));
            DelayedAction   removeEffectAction    = DelayedAction.Create(removeActionTargetted, Time.ActionAmount - power);

            return(state.AddDelayedAction(removeEffectAction));
        }
        TargettedSkill ConsiderSkill(string skillName, GameState state, ItemResolver <Character> c)
        {
            Skill skill = c.Item.SkillWithName(skillName);

            if (skill != null && skill.Available)
            {
                TargettingInfo targetting = SelectTarget(skill, state, c);
                if (targetting != TargettingInfo.Empty)
                {
                    return(new TargettedSkill(skill, targetting));
                }
            }
            return(null);
        }
        public static bool IsConditionTrue(GameCondition condition, GameState state, ItemResolver <Character> c)
        {
            switch (condition)
            {
            case GameCondition.EnemyHealthLow:
                return(state.GetOpponents(c).Any(x => x.Health.IsLow));

            case GameCondition.PartyHealthLow:
                return(state.GetTeammates(c).Any(x => x.Health.IsLow));

            default:
                throw new NotImplementedException($"{condition} in ConditionFinder.IsConditionTrue");
            }
        }
        public TargettingInfo SelectTarget(Skill skill, GameState state, ItemResolver <Character> c)
        {
            bool isEnemy = state.Enemies.Contains(c.Item);
            ImmutableArray <Character> team         = isEnemy ? state.Enemies : state.Party;
            ImmutableArray <Character> opposingTeam = isEnemy ? state.Party : state.Enemies;

            // This logic is very greedy, and doesn't consider anything but % health
            if (skill.Action.Type.HasFlag(ActionType.Heal))
            {
                return(ConditionFinder.FindBestHealingTarget(state, c));
            }

            if (skill.Action.Type.HasFlag(ActionType.Damage))
            {
                return(ConditionFinder.FindBestDamageTarget(state, c));
            }

            return(TargettingInfo.Empty);
        }
示例#7
0
 public GameState Wait(ItemResolver <Character> c, GameState state)
 {
     return(state.UpdateCharacter(Time.SpendAction(c)));
 }
        public static TargettingInfo FindBestDamageTarget(GameState state, ItemResolver <Character> c)
        {
            Character lowestHealth = state.GetOpponents(c).OrderBy(x => x.Health.Current / (double)x.Health.Max).First();

            return(TargettingInfo.From(c.Item.ID, lowestHealth.ID));
        }
        GameState ApplyDamage(int power, ItemResolver <Character> character, GameState state)
        {
            int amount = CalculateDamageAmount(power);

            return(state.UpdateCharacter(character.Item.WithDeltaCurrentHealth(amount)));
        }