Ejemplo n.º 1
0
        protected void update_aoe_map_battle()
        {
            Game_Unit Battler_1 = null, Battler_2 = null;

            if (Battler_1_Id > -1)
            {
                Battler_1 = Units[Battler_1_Id];
            }
            Scene_Map scene_map = get_scene_map();

            if (scene_map == null)
            {
                return;
            }
            bool cont = false;

            while (!cont)
            {
                cont = true;
                switch (Combat_Phase)
                {
                case 0:
                    if (Combat_Timer == 0)
                    {
                        Global.scene.suspend();
                        Combat_Phase++;
                    }
                    break;

                    #region 1: Battle Setup
                case 1:
                    if (!any_behaviors)
                    {
                        add_behavior(camera_to_aoe_attacker());
                        add_behavior(aoe_wait_for_setup_ready());
                        add_behavior(setup_aoe());
                        add_behavior(check_aoe_talk());
                        add_behavior(wait_behavior(10));
                        add_behavior(open_aoe_hud());
                        add_behavior(wait_behavior(12));
                        add_behavior(end_aoe_phase_1());
                    }
                    apply_behaviors();
                    break;

                    #endregion
                    #region 2: Combat Processing
                case 2:
                    switch (Combat_Action)
                    {
                    case 0:
                        bool attack_cont = false;
                        while (!attack_cont)
                        {
                            Battler_2_Id = Aoe_Targets[Attack_Id];
                            Battler_2    = Units[Battler_2_Id];
                            attack_cont  = true;
                            bool      no_attack = false;
                            Game_Unit battler_1 = null, battler_2 = null;
                            if (Map_Combat_Data.Data[Attack_Id].Key.Attacker == 1)
                            {
                                battler_1 = Battler_1;
                                battler_2 = Battler_2;
                            }
                            else if (Map_Combat_Data.Data[Attack_Id].Key.Attacker == 2)
                            {
                                battler_1 = Battler_2;
                                battler_2 = Battler_1;
                            }
                            else
                            {
                                no_attack     = true;
                                Combat_Action = 1;
                            }
                            if (!no_attack)
                            {
                                bool next_attack;
                                if (In_Staff_Use)
                                {
                                    next_attack = staff_use(battler_1, battler_2);
                                }
                                else
                                {
                                    next_attack = attack(battler_1, battler_2);
                                }
                                Battler_1.update_attack_graphics();
                                Battler_2.update_attack_graphics();
                                if (next_attack)
                                {
                                    Combat_Timer = 0;
                                    Attack_Id++;
                                    if (Attack_Id >= Map_Combat_Data.Data.Count)
                                    {
                                        // Reset stats for battle ending
                                        for (int i = 0; i < Map_Combat_Data.Data[Map_Combat_Data.Data.Count - 1].Value.Count; i++)
                                        {
                                            Combat_Action_Data data = Map_Combat_Data.Data[Map_Combat_Data.Data.Count - 1].Value[i];
                                            if (data.Trigger == (int)Combat_Action_Triggers.End)
                                            {
                                                get_scene_map().set_hud_action_id(i);
                                                get_scene_map().refresh_hud();
                                            }
                                        }
                                        Combat_Action = 1;
                                        Map_Combat_Data.apply_combat();
                                        Attack_Id    = 0;
                                        Aoe_Battlers = new List <int> {
                                            battler_1_id
                                        };
                                        Aoe_Battlers.AddRange(Aoe_Targets);
                                        Battler_2_Id = -1;
                                    }
                                    else
                                    {
                                        set_attack_index(Attack_Id);
                                        Battler_2_Id = Aoe_Targets[Attack_Id];
                                        attack_cont  = false;
                                        refresh_stats(Battler_2.id);
                                        Skip_Attack_Anim = true;
                                    }
                                }
                            }
                        }
                        break;

                    // Post Battle Cleanup
                    case 1:
                        Game_Unit battler = null;
                        if (Aoe_Battlers.Count > 0)
                        {
                            battler = Units[Aoe_Battlers[0]];
                        }
                        switch (Combat_Timer)
                        {
                        // Does death quotes if needed
                        case 0:
                            if (battler.is_dead)
                            {
                                Global.player.force_loc(battler.loc);
                                get_scene_map().clear_combat();
                                Global.game_temp.dying_unit_id = battler.id;
                                if (Global.game_state.get_death_quote(Global.game_temp.dying_unit_id).Length > 0)
                                {
                                    Global.game_temp.message_text = Global.death_quotes[Global.game_state.get_death_quote(Global.game_temp.dying_unit_id)];
                                    Global.scene.new_message_window();
                                    if (Battler_1.is_opposition ^ Battler_1_Id == battler.id)
                                    {
                                        Global.scene.message_reverse();
                                    }
                                }
                                cont = true;
                            }
                            else
                            {
                                cont = false;
                            }
                            Combat_Timer++;
                            break;

                        // Waits for death quote
                        case 1:
                            if (!scene_map.is_message_window_active && !Scrolling)
                            {
                                if (battler.is_dead)
                                {
                                    Global.game_map.add_dying_unit_animation(battler);
                                    Dying = true;
                                }
                                battler.actor.staff_fix();
                                cont = false;
                                Combat_Timer++;
                            }
                            break;

                        // Waits for dead guys to disappear, then clears HP window
                        case 2:
                            if (Dying)
                            {
                                battler.update_attack_graphics();
                                if (!battler.changing_opacity())
                                {
                                    if (battler.is_dead)
                                    {
                                        battler.kill();
                                    }
                                    Dying = false;
                                    Aoe_Battlers.RemoveAt(0);
                                    if (Aoe_Battlers.Count > 0)
                                    {
                                        Combat_Timer = 0;
                                    }
                                    else
                                    {
                                        Aoe_Battlers.Clear();
                                        Combat_Timer++;
                                    }
                                }
                            }
                            else
                            {
                                Aoe_Battlers.RemoveAt(0);
                                if (Aoe_Battlers.Count > 0)
                                {
                                    Combat_Timer = 0;
                                }
                                else
                                {
                                    Aoe_Battlers.Clear();
                                    scene_map.clear_combat();
                                    Combat_Timer++;
                                }
                            }
                            break;

                        // Sets up exp window
                        case 3:
                            exp_gauge_gain = 0;
                            int exp_id = 0;
                            // Exp gain
                            if (Battler_1.is_ally && !Battler_1.is_dead && Battler_1.actor.can_level())
                            {
                                exp_id         = 1;
                                exp_gauge_gain = Map_Combat_Data.Exp_Gain1;
                            }
                            if (exp_gauge_gain > 0)
                            {
                                get_scene_map().create_exp_gauge(exp_id == 1 ? Map_Combat_Data.Exp1 : Map_Combat_Data.Exp2);
                                Combat_Timer++;
                            }
                            else
                            {
                                Combat_Action = 2;
                                Combat_Timer  = 0;
                            }
                            break;

                        // Waits
                        case 4:
                        case 5:
                        case 6:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 14:
                        case 15:
                        case 16:
                        case 17:
                        case 18:
                        case 19:
                        case 20:
                        case 21:
                        case 22:
                        case 23:
                        case 24:
                        case 25:
                        case 26:
                        case 27:
                        case 28:
                        case 29:
                        case 30:
                            Combat_Timer++;
                            break;

                        // Unit gains exp
                        case 31:
                            if (Global.game_state.process_exp_gain())             //Combat_Timer++; //Debug
                            {
                                Global.game_state.cancel_exp_sound();
                                Global.game_system.cancel_sound();
                                Combat_Timer++;
                            }
                            break;

                        // Waits
                        case 32:
                        case 33:
                        case 34:
                        case 35:
                        case 36:
                        case 37:
                        case 38:
                        case 39:
                        case 40:
                        case 41:
                        case 42:
                        case 43:
                        case 44:
                        case 45:
                        case 46:
                        case 47:
                        case 48:
                        case 49:
                        case 50:
                            Combat_Timer++;
                            break;

                        // Clears exp window, continues
                        case 51:
                            get_scene_map().clear_exp();
                            Combat_Action = 2;
                            Combat_Timer  = 0;
                            break;

                        default:
                            Combat_Timer++;
                            break;
                        }
                        break;

                    // Discern Cleanup Actions
                    case 2:
                        switch (Combat_Timer)
                        {
                        case 27:
                            // If Promotion
                            // If Level Up
                            if (Battler_1.actor.needed_levels > 0)
                            {
                                Cleanup_Action.Add(new List <int> {
                                    (int)Cleanup_Actions.Level_Up, 1
                                });
                            }
                            // If WLvl Up
                            if (Battler_1.actor.wlvl_up())
                            {
                                Cleanup_Action.Add(new List <int> {
                                    (int)Cleanup_Actions.WLvl_Up, 1
                                });
                            }
                            // If Weapon Break
                            if (Map_Combat_Data.weapon_1_broke)
                            {
                                Cleanup_Action.Add(new List <int> {
                                    (int)Cleanup_Actions.Weapon_Break, 1
                                });
                            }
                            // If Item Gain
                            bool attacker_killed = Battler_1.is_dead;
                            if (Map_Combat_Data.has_item_drop)
                            {
                                if (attacker_killed)
                                {
                                    for (int i = 0; i < Aoe_Targets.Count; i++)
                                    {
                                        Battler_2 = Units[Aoe_Targets[i]];
                                        if (!Battler_2.is_dead && Battler_1.drops_item)
                                        {
                                            Cleanup_Action.Add(new List <int> {
                                                (int)Cleanup_Actions.Item_Gain, 2, -i
                                            });
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0; i < Aoe_Targets.Count; i++)
                                    {
                                        Battler_2 = Units[Aoe_Targets[i]];
                                        if (Battler_2.is_dead && Battler_2.drops_item)
                                        {
                                            Cleanup_Action.Add(new List <int> {
                                                (int)Cleanup_Actions.Item_Gain, 1, i
                                            });
                                        }
                                    }
                                }
                            }
                            cont          = false;
                            Combat_Timer  = 0;
                            Combat_Action = 3;
                            break;

                        default:
                            Combat_Timer++;
                            break;
                        }
                        break;

                    // Act on Cleanup Actions
                    case 3:
                        if (Cleanup_Action.Count == 0)
                        {
                            cont          = false;
                            Combat_Timer  = 0;
                            Combat_Action = 0;
                            Combat_Phase  = 3;
                        }
                        else
                        {
                            cont = update_aoe_cleanup_actions(Battler_1);
                        }
                        break;
                    }
                    break;

                    #endregion
                    #region 3: Post Battle
                case 3:
                    switch (Combat_Timer)
                    {
                    case 0:
                        Battler_1.end_battle();
                        foreach (int battler_2_id in Aoe_Targets)
                        {
                            Units[battler_2_id].end_battle();
                        }
                        //end battle calls used to be here, testing below to let Trample lead to attack canto //Debug
                        // Move this up from below, because it needs to kill the target before testing if canto is possible
                        Battler_1.queue_move_range_update();
                        foreach (int battler_2_id in Aoe_Targets)
                        {
                            Units[battler_2_id].queue_move_range_update();
                        }
                        Combat_Timer++;
                        break;

                    case 1:
                        // Attack Canto
                        if (Battler_1.has_attack_canto() && !Battler_1.full_move() && !Battler_1.is_dead)
                        {
                            Battler_1.cantoing = true;
                            if (Battler_1.is_active_player_team && !Battler_1.berserk)         //Multi
                            {
                                Global.player.loc                   = Battler_1.loc;
                                Global.player.instant_move          = true;
                                Global.game_system.Selected_Unit_Id = Battler_1_Id;
                                Battler_1.open_move_range();
                            }
                        }
                        else
                        {
                            Battler_1.start_wait(false);
                        }
                        Battler_1.battling = false;
                        foreach (int battler_2_id in Aoe_Targets)
                        {
                            Units[battler_2_id].battling = false;
                        }
                        get_scene_map().update_map_sprite_status(Battler_1_Id);
                        foreach (int battler_2_id in Aoe_Targets)
                        {
                            get_scene_map().update_map_sprite_status(battler_2_id);
                        }
                        Battler_1_Id = -1;
                        Aoe_Targets.Clear();
                        Weapon1         = null;
                        Map_Combat_Data = null;
                        Attack_Id       = -1;

                        refresh_move_ranges();
                        Combat_Timer++;
                        break;

                    case 2:
                        if (!Global.game_system.is_interpreter_running && !Global.scene.is_message_window_active)
                        {
                            Combat_Phase = 4;
                            Combat_Timer = 0;
                        }
                        break;
                    }
                    break;

                    #endregion
                    #region Allows suspend to complete, when post-battle suspends are used
                default:
                    end_battle();
                    In_Aoe = false;
                    break;
                    #endregion
                }
                if (!In_Battle || scene_map.suspend_calling)
                {
                    break;
                }
            }
        }