Пример #1
0
        /// <summary>
        /// Applies the effects of this round of combat, such as damage taken, weapon uses, exp gain, etc.
        /// </summary>
        /// <param name="immediate_level">Immediately applies level ups from exp gain, instead of letting the combat routine detect a level up is needed and display it.
        /// Used for battles during skipped AI turns.</param>
        /// <param name="skip_exp">Skips exp and wexp gain for this round. Used by the arena.</param>
        public virtual void apply_combat(bool immediate_level = false, bool skip_exp = false)
        {
            // Prevents data from being applied multiple times
            if (Applied)
            {
                return;
            }
            Applied = true;

            Game_Unit battler_1    = Global.game_map.units[Battler_1_Id];
            Game_Unit battler_2    = Battler_2_Id == null ? null : Global.game_map.units[(int)Battler_2_Id];
            int       battler_1_hp = battler_1.hp;
            int       battler_2_hp = battler_2 != null ? battler_2.hp : -1;

            for (int i = 0; i < Data.Count; i++)
            {
                Combat_Round_Data data = Data[i].Key;
                data.cause_damage();
            }

            // shouldn't really use 'this is' //Yeti
            Global.game_state.add_combat_metric(
                this is Staff_Data ?
                Metrics.CombatTypes.Staff :
                Metrics.CombatTypes.Battle,
                Battler_1_Id, Battler_2_Id, battler_1_hp, battler_2_hp, Weapon_1_Id, Weapon_2_Id,
                Data.Where(x => x.Key.Attacker == 1).Count(), Data.Where(x => x.Key.Attacker != 1).Count());

            // Charge Masteries
            if (Attacked_1 && battler_2 != null && battler_2.different_team(battler_1))
            {
                battler_1.charge_masteries(Game_Unit.MASTERY_RATE_BATTLE_END);
            }
            if (Attacked_2 && battler_2 != null && battler_2.different_team(battler_1))
            {
                battler_2.charge_masteries(Game_Unit.MASTERY_RATE_BATTLE_END);
            }

            use_weapons(battler_1, battler_2);

            battler_1.actor.clear_added_attacks();
            if (battler_2 != null)
            {
                battler_2.actor.clear_added_attacks();
            }

            if (skip_exp)
            {
                //Exp_Gain1 = 0; //Debug
                //Exp_Gain2 = 0;
            }
            else
            {
                exp_gain(battler_1.actor, Exp_Gain1);
                if (battler_2 != null)
                {
                    exp_gain(battler_2.actor, Exp_Gain2);
                }

                // Increase exp amounts given out from each unit
                if (Exp_Gain2 > 0 && exp_gain_cap(battler_1))
                {
                    battler_1.add_exp_given(Exp_Gain2);
                }
                if (battler_2 != null && Exp_Gain1 > 0 && exp_gain_cap(battler_2))
                {
                    battler_2.add_exp_given(Exp_Gain1);
                }

                if (battler_1.is_player_team)
                {
                    if (Global.game_state.is_battle_map && !Global.game_system.In_Arena)
                    {
                        Global.game_system.chapter_exp_gain += Exp_Gain1;
                    }
                }
                if (battler_2 != null && battler_2.is_player_team)
                {
                    if (Global.game_state.is_battle_map && !Global.game_system.In_Arena)
                    {
                        Global.game_system.chapter_exp_gain += Exp_Gain2;
                    }
                }
            }
            if (!skip_exp)
            {
                if (Wexp1 > 0)
                {
                    WeaponType type = battler_1.actor.valid_weapon_type_of(Global.data_weapons[Weapon_1_Id]);
                    battler_1.actor.wexp_gain(type, Wexp1);
                }
                if (Wexp2 > 0)
                {
                    WeaponType type = battler_2.actor.valid_weapon_type_of(Global.data_weapons[(int)Weapon_2_Id]);
                    battler_2.actor.wexp_gain(type, Wexp2);
                }
            }
            if (immediate_level)
            {
                if (battler_1.actor.needed_levels > 0)
                {
                    battler_1.actor.level_up();
                }
                battler_1.actor.clear_wlvl_up();
                if (battler_2 != null)
                {
                    if (battler_2.actor.needed_levels > 0)
                    {
                        battler_2.actor.level_up();
                    }
                    battler_2.actor.clear_wlvl_up();
                }
            }
        }