Example #1
0
        private void add_attacks(
            Game_Unit battler_1, Combat_Map_Object battler_2, int i)
        {
            Game_Unit         attacker = battler_1;
            Combat_Map_Object target   = battler_2;

            if (i == 2)
            {
                if (!battler_2.is_unit())
                {
                    return;
                }
                attacker = battler_2 as Game_Unit;
                target   = battler_1;
            }

            bool cont = false;

            while (!cont)
            {
                int  attacker_index = 0;
                bool attack_occurs  = attackable(attacker, target);
                if (attack_occurs)
                {
                    attacker_index = i;
                    if (Skip_Attack.Contains(attacker_index))
                    {
                        attacker_index = 0;
                        Skip_Attack.pop();
                    }
                }
                if (attacker_index > 0)
                {
                    if (battler_2 == null)
                    {
                        add_solo_attack(battler_1, attacker_index);
                    }
                    else if (battler_2.is_unit())
                    {
                        add_attack(battler_1, battler_2 as Game_Unit, attacker_index);
                    }
                    else
                    {
                        add_attack(battler_1, battler_2 as Combat_Map_Object, attacker_index);
                    }
                }

                cont = true;
                // If an added attack is buffered
                if (Add_Attack.Count > 0)
                {
                    attacker_index = Add_Attack.pop();
                    cont           = false;
                }
            }
        }
Example #2
0
        private void add_attacks(
            Game_Unit battler_1, Combat_Map_Object battler_2,
            int i, Data_Weapon weapon)
        {
#if DEBUG
            System.Diagnostics.Debug.Assert(i == 1 || i == 2);
#endif
            Game_Unit         attacker = i == 2 ? battler_2 as Game_Unit : battler_1;
            Combat_Map_Object target   = i == 2 ? battler_1 : battler_2;

            int num_hits = 1;
            if (!attacker.is_brave_blocked())
            {
                // If only single hits against terrain
                if (!(target != null && !target.is_unit() &&
                      Constants.Combat.BRAVE_BLOCKED_AGAINST_DESTROYABLE))
                {
                    num_hits = weapon.HitsPerAttack;
                }
            }
            for (int j = 0; j < num_hits; j++)
            {
                add_attacks(battler_1, battler_2, i);
            }
        }
Example #3
0
        protected void process_attacks(Game_Unit battler_1, Combat_Map_Object battler_2, int targetId)
        {
            battler_1.start_attack(-1, battler_2);
            if (battler_2 is Game_Unit)
            {
                (battler_2 as Game_Unit).start_attack(-1, battler_1);
            }

            bool ambush = battler_2 != null && battler_2.is_unit() &&
                          Global.game_map.units[targetId].counters_first(Global.game_map.units[Battler_1_Id]);

            int num_attacks1, num_attacks2;

            for (int i = 0; i < combat_attacks(
                     battler_1, battler_2, out num_attacks1, out num_attacks2); i++)
            {
                if (ambush)
                {
                    if (battler_2 != null && battler_2.is_unit() &&
                        i < num_attacks2 && this.weapon2 != null)
                    {
                        add_attacks(battler_1, battler_2, 2, this.weapon2);
                    }
                }
                // Add hits for battler_1 in this attack
                if (i < num_attacks1)
                {
                    if (i < num_attacks1)
                    {
                        add_attacks(battler_1, battler_2, 1, this.weapon1);
                    }
                }
                if (!ambush)
                {
                    if (battler_2 != null && battler_2.is_unit() &&
                        i < num_attacks2 && this.weapon2 != null)
                    {
                        add_attacks(battler_1, battler_2, 2, this.weapon2);
                    }
                }
            }
        }
Example #4
0
 protected virtual int combat_attacks(Game_Unit battler_1, Combat_Map_Object battler_2,
                                      out int numAttacks1, out int numAttacks2)
 {
     numAttacks1 = battler_1.attacks_per_round(battler_2, Distance);
     numAttacks2 = 0;
     if (battler_2 != null && battler_2.is_unit())
     {
         numAttacks2 = (battler_2 as Game_Unit).attacks_per_round(battler_1, Distance);
     }
     return(Math.Max(numAttacks1, numAttacks2));
 }
Example #5
0
 protected override int combat_attacks(Game_Unit battler_1, Combat_Map_Object battler_2,
                                       out int numAttacks1, out int numAttacks2)
 {
     // No double casting
     numAttacks1 = 1;
     numAttacks2 = 0;
     if (battler_2 != null && battler_2.is_unit())
     {
         numAttacks2 = 1;
     }
     return(Math.Max(numAttacks1, numAttacks2));
 }
Example #6
0
        public int get_multi(Game_Unit unit, Combat_Map_Object target, TactileLibrary.Data_Weapon weapon, int distance)
        {
            int multi = 0;

            if (!target.is_unit())
            {
                return(0);
            }
            if (weapon.Brave() && !unit.is_brave_blocked())
            {
                multi += 4;
            }
            if (unit.can_double_attack(target, distance))
            {
                multi += 2;
            }
            return(multi / 2);
        }
Example #7
0
        public static void SetWeaponTriangle(
            Weapon_Triangle_Arrow wta1,
            Weapon_Triangle_Arrow wta2,
            Game_Unit attacker,
            Combat_Map_Object target,
            TactileLibrary.Data_Weapon weapon1,
            TactileLibrary.Data_Weapon weapon2,
            int distance)
        {
            //@Yeti: use in all the places weapon triangle arrow is used
            Game_Unit targetUnit = null;

            if (target.is_unit())
            {
                targetUnit = target as Game_Unit;
            }

            ResetWeaponTriangle(wta1, wta2);
            WeaponTriangle tri = WeaponTriangle.Nothing;

            if (targetUnit != null)
            {
                tri = Combat.weapon_triangle(attacker, targetUnit, weapon1, weapon2, distance);
            }
            if (tri != WeaponTriangle.Nothing)
            {
                wta1.value = tri;
                if (wta2 != null && weapon2 != null)
                {
                    wta2.value = Combat.reverse_wta(tri);
                }
            }

            float effectiveness = weapon1.effective_multiplier(attacker, targetUnit, false);

            wta1.set_effectiveness((int)effectiveness,
                                   targetUnit != null && targetUnit.halve_effectiveness());

            if (wta2 != null && weapon2 != null)
            {
                effectiveness = weapon2.effective_multiplier(targetUnit, attacker, false);
                wta2.set_effectiveness((int)effectiveness, attacker.halve_effectiveness());
            }
        }
Example #8
0
        private void process_scripted_attacks(Game_Unit battler_1, Combat_Map_Object battler_2, Scripted_Combat_Script script)
        {
            battler_1.start_attack(-1, battler_2);
            if (battler_2 is Game_Unit)
            {
                (battler_2 as Game_Unit).start_attack(-1, battler_1);
            }

            for (int i = 0; i < script.Stats.Count; i++)
            {
                if (script.Stats[i].Result != Attack_Results.End)
                {
                    bool cont = false;
                    while (!cont)
                    {
                        cont = true;
                        int attacker = script.Stats[i].Attacker;
                        if (attacker > 0)
                        {
                            if (battler_2 == null)
                            {
                                add_solo_attack(battler_1, attacker);
                            }
                            else if (battler_2.is_unit())
                            {
                                add_attack(battler_1, battler_2 as Game_Unit, script.Stats[i]);
                            }
                            else
                            {
                                add_attack(battler_1, battler_2 as Combat_Map_Object, attacker);
                            }
                        }
                    }
                }
            }
            Kill = script.kill;
        }
Example #9
0
        protected virtual bool attackable(Game_Unit attacker, Combat_Map_Object target)
        {
            // If target doesn't exist because it's a flare use/etc
            if (target == null)
            {
                return(true);
            }

            // If attacker is dead return
            //@Debug: make sure units who are out of hp but technically aren't
            // dead for whatever reason will stop
            if (attacker.hp <= 0) //@Debug: .is_dead)
            {
                return(false);
            }

            bool is_target_unit = false;

            // If the target is already dead, stop attacking
            if (target.hp <= 0)
            {
                // Don't return if either battler wants the attacks to continue
                if (!attacker.continue_attacking() &&
                    !(target.is_unit() && (target as Game_Unit).continue_attacking()))
                {
                    return(false);
                }
            }
            Game_Unit target_unit = null;

            if (target.is_unit())
            {
                is_target_unit = true;
                target_unit    = (Game_Unit)target;
            }

            var weapon = attacker.id == Battler_1_Id ? this.weapon1 : this.weapon2;

            if (weapon == null)
            {
                return(false);
            }

            // If target is berserk ally and attacker isn't berserk, don't hurt your friend >:
            if (is_target_unit && attacker.id != Battler_1_Id &&
                !attacker.is_attackable_team(target_unit) && !can_counter_ally(attacker))
            {
                return(false);
            }

            int hit, uses;

            if (attacker.id == Battler_1_Id)
            {
                List <int?> ary = Combat.combat_stats(attacker.id, target.id, Distance);
                hit  = 100;
                uses = Weapon_1_Uses;
                if (ary[0] == null && !weapon.is_staff())
                {
                    return(false); // This is newly added to account for the attacker being put to sleep, did any other cases make hit null?
                }
                if (ary[0] != null)
                {
                    hit = (int)ary[0];
                }
            }
            else
            {
                List <int?> ary = Combat.combat_stats(target.id, attacker.id, Distance);
                if (ary[4] == null)
                {
                    return(false);
                }
                hit  = (int)ary[4];
                uses = Weapon_2_Uses;
            }

            // Breaks if the attacker can't fight/broke their weapon
            if (hit < 0 || attacker.is_weapon_broke(uses))
            {
                return(false);
            }

            return(true);
        }