public AbilityEvent(Ability ability, AbilityModifiers modifiers, Combatant source, Combatant[] targets)
            : base(source, modifiers.ResetTurnTimer)
        {
            Hits = new bool[ability.Hits];
            Steals = new string[modifiers.StealAsWell ? targets.Count() : 0];
            TargetHitFlags = new bool[targets.Count()];
            Targets = targets;
            Ability = ability;
            Modifiers = modifiers;

            if (modifiers.StealAsWell)
            {
                if (!(source is Ally))
                {
                    throw new GameDataException("Non-Ally source '{0}' attempted to steal.", source.Name);
                }
                else if (targets.Any(x => !(x is Enemy)))
                {
                    throw new GameDataException("Source '{0}' attempted to steal from a non-Enemy target using ability '{1}'.", source.Name, ability.Name);
                }
            }
        }
Exemple #2
0
        public bool[] Cast(Combatant source, Combatant[] targets, AbilityModifiers modifiers)
        {
            if (RandomTarget && targets.Count() > 1)
            {
                int index = source.CurrentBattle.Random.Next(targets.Count());
                Combatant newTarget = targets.ToList()[index];
                targets = new Combatant[] { newTarget };
            }

            bool[] hits = new bool[targets.Length];

            for (int i = 0; i < targets.Length; i++)
            {
                Combatant target = targets[i];

                bool hit = HitFormula(source, target, modifiers);

                // We can still miss if each of the status changes misses
                bool actuallyHit = false;

                if (hit)
                {
                    if (Power > 0)
                    {
                        int dam = DamageFormula(source, target, modifiers);

                        dam = RunElementalChecks(dam, target, Elements);
                        //dam = LowerSanityCkeck(dam); // not required as per the guides (besides, negative damage is OK (think cure)
                        dam = UpperSanityCheck(dam);

                        if (target.Peerless || target.Petrify)
                        {
                            dam = 0;
                        }

                        target.AcceptDamage(source, dam, Type);

                        actuallyHit = true;
                    }

                    foreach (StatusChange statusChange in Statuses)
                    {
                        if (statusChange.Hits(source, target, modifiers))
                        {
                            switch (statusChange.ChangeType)
                            {
                                case StatusChange.Effect.Cure:

                                    foreach (Status status in statusChange.Statuses)
                                    {
                                        target.GetType().GetMethod("Cure" + status).Invoke(target, new object[] { source });
                                    }

                                    break;

                                case StatusChange.Effect.Inflict:

                                    foreach (Status status in statusChange.Statuses)
                                    {
                                        target.GetType().GetMethod("Inflict" + status).Invoke(target, new object[] { source });
                                    }

                                    break;

                                case StatusChange.Effect.Toggle:

                                    foreach (Status status in statusChange.Statuses)
                                    {
                                        if ((bool)target.GetType().GetProperty(status.ToString()).GetValue(target, null))
                                        {
                                            target.GetType().GetMethod("Cure" + status).Invoke(target, new object[] { source });
                                        }
                                        else
                                        {
                                            target.GetType().GetMethod("Inflict" + status).Invoke(target, new object[] { source });
                                        }
                                    }

                                    break;
                            }

                            actuallyHit = true;
                        }
                    }

                    hits[i] = true;
                }

                if (!actuallyHit)
                {
                    source.CurrentBattle.AddMissIcon(target);
                }
            }

            return hits;
        }