Exemplo n.º 1
0
 private void EndRound(Room room,bool isBotMode)
 {
     try
     {
         room.swapRound = true;
         if (room.room_type == (byte)7 || room.room_type == (byte)12)
         {
             if (room.rodada == 1)
             {
                 room.rodada = 2;
                 for (int index = 0; index < 16; ++index)
                 {
                     SLOT slot = room._slots[index];
                     if (slot.state == SLOT_STATE.BATTLE)
                     {
                         slot.killsOnLife     = 0;
                         slot.lastKillState   = 0;
                         slot.repeatLastState = false;
                     }
                 }
                 List <int> dinossaurs = AllUtils.getDinossaurs(room,true,-2);
                 using (BATTLE_ROUND_WINNER_PAK battleRoundWinnerPak = new BATTLE_ROUND_WINNER_PAK(room,2,RoundEndType.TimeOut))
                 {
                     using (BATTLE_ROUND_RESTART_PAK battleRoundRestartPak = new BATTLE_ROUND_RESTART_PAK(room,dinossaurs,isBotMode))
                         room.SendPacketToPlayers((SendPacket)battleRoundWinnerPak,(SendPacket)battleRoundRestartPak,SLOT_STATE.BATTLE,0);
                 }
                 room.round.StartJob(5250,(TimerCallback)(callbackState =>
                 {
                     if (room._state == RoomState.Battle)
                     {
                         room.BattleStart = DateTime.Now.AddSeconds(5.0);
                         using (BATTLE_TIMERSYNC_PAK battleTimersyncPak = new BATTLE_TIMERSYNC_PAK(room))
                             room.SendPacketToPlayers((SendPacket)battleTimersyncPak,SLOT_STATE.BATTLE,0);
                     }
                     room.swapRound = false;
                     lock (callbackState)
                         room.round.Timer = (Timer)null;
                 }));
             }
             else
             {
                 if (room.rodada != 2)
                 {
                     return;
                 }
                 AllUtils.EndBattle(room,isBotMode);
             }
         }
         else if (room.thisModeHaveRounds())
         {
             int winner = 1;
             if (room.room_type != (byte)3)
             {
                 ++room.blue_rounds;
             }
             else if (room.Bar1 > room.Bar2)
             {
                 ++room.red_rounds;
                 winner = 0;
             }
             else if (room.Bar1 < room.Bar2)
             {
                 ++room.blue_rounds;
             }
             else
             {
                 winner = 2;
             }
             AllUtils.BattleEndRound(room,winner,RoundEndType.TimeOut);
         }
         else
         {
             List <Account> allPlayers = room.getAllPlayers(SLOT_STATE.READY,1);
             if (allPlayers.Count != 0)
             {
                 TeamResultType winnerTeam = AllUtils.GetWinnerTeam(room);
                 room.CalculateResult(winnerTeam,isBotMode);
                 using (BATTLE_ROUND_WINNER_PAK battleRoundWinnerPak = new BATTLE_ROUND_WINNER_PAK(room,winnerTeam,RoundEndType.TimeOut))
                 {
                     ushort result1;
                     ushort result2;
                     byte[] data;
                     AllUtils.getBattleResult(room,out result1,out result2,out data);
                     byte[] completeBytes = battleRoundWinnerPak.GetCompleteBytes("BATTLE_TIMERSYNC_REC");
                     foreach (Account p in allPlayers)
                     {
                         if (room._slots[p._slotId].state == SLOT_STATE.BATTLE)
                         {
                             p.SendCompletePacket(completeBytes);
                         }
                         p.SendPacket((SendPacket) new BATTLE_ENDBATTLE_PAK(p,winnerTeam,result2,result1,isBotMode,data));
                     }
                 }
             }
             AllUtils.resetBattleInfo(room);
         }
     }
     catch (Exception ex)
     {
         if (room != null)
         {
             Logger.error("[!] Crash no BATTLE_TIMERSYNC_REC, Sala: " + (object)room._roomId + ";" + (object)room._channelId + ";" + (object)room.room_type);
         }
         Logger.error("[BATTLE_TIMERSYNC_REC2] " + ex.ToString());
     }
 }
        private void EndRound(Room room,bool isBotMode)
        {
            try
            {
                room.swapRound = true;
                if (room.room_type == 7 || room.room_type == 12)
                {
                    if (room.rodada == 1)
                    {
                        room.rodada = 2;
                        for (int i = 0; i < 16; i++)
                        {
                            SLOT slot = room._slots[i];
                            if (slot.state == SLOT_STATE.BATTLE)
                            {
                                slot.killsOnLife     = 0;
                                slot.lastKillState   = 0;
                                slot.repeatLastState = false;
                            }
                        }
                        List <int> dinos = AllUtils.getDinossaurs(room,true,-2);
                        using (BATTLE_ROUND_WINNER_PAK packet = new BATTLE_ROUND_WINNER_PAK(room,2,RoundEndType.TimeOut))
                            using (BATTLE_ROUND_RESTART_PAK packet2 = new BATTLE_ROUND_RESTART_PAK(room,dinos,isBotMode))
                                room.SendPacketToPlayers(packet,packet2,SLOT_STATE.BATTLE,0);

                        room.round.StartJob(5250,(callbackState) =>
                        {
                            if (room._state == RoomState.Battle)
                            {
                                room.BattleStart = DateTime.Now.AddSeconds(5);
                                using (BATTLE_TIMERSYNC_PAK packet = new BATTLE_TIMERSYNC_PAK(room))
                                    room.SendPacketToPlayers(packet,SLOT_STATE.BATTLE,0);
                            }
                            room.swapRound = false;
                            lock (callbackState)
                            { room.round.Timer = null; }
                        });
                    }
                    else if (room.rodada == 2)
                    {
                        AllUtils.EndBattle(room,isBotMode);
                    }
                }
                else if (room.thisModeHaveRounds())
                {
                    int winner = 1;
                    if (room.room_type != 3)
                    {
                        room.blue_rounds++;
                    }
                    else
                    {
                        if (room.Bar1 > room.Bar2)
                        {
                            room.red_rounds++;
                            winner = 0;
                        }
                        else if (room.Bar1 < room.Bar2)
                        {
                            room.blue_rounds++;
                        }
                        else
                        {
                            winner = 2;
                        }
                    }
                    AllUtils.BattleEndRound(room,winner,RoundEndType.TimeOut);
                }
                else
                {
                    List <Account> players = room.getAllPlayers(SLOT_STATE.READY,1);
                    if (players.Count == 0)
                    {
                        goto EndLabel;
                    }
                    TeamResultType winnerTeam = AllUtils.GetWinnerTeam(room);
                    room.CalculateResult(winnerTeam,isBotMode);
                    using (BATTLE_ROUND_WINNER_PAK packet = new BATTLE_ROUND_WINNER_PAK(room,winnerTeam,RoundEndType.TimeOut))
                    {
                        ushort inBattle,missionCompletes;
                        byte[] a1;
                        AllUtils.getBattleResult(room,out missionCompletes,out inBattle,out a1);
                        byte[] data = packet.GetCompleteBytes();
                        foreach (Account pR in players)
                        {
                            if (room._slots[pR._slotId].state == SLOT_STATE.BATTLE)
                            {
                                pR.SendCompletePacket(data);
                            }
                            pR.SendPacket(new BATTLE_ENDBATTLE_PAK(pR,winnerTeam,inBattle,missionCompletes,isBotMode,a1));
                        }
                    }
EndLabel:
                    AllUtils.resetBattleInfo(room);
                }
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[BATTLE_TIMERSYNC_REC2.EndRound] Erro fatal!");
                if (room != null)
                {
                    SaveLog.fatal("[!] Crash no BATTLE_TIMERSYNC_REC, Sala: " + room._roomId + ";" + room._channelId + ";" + room.room_type);
                }
            }
        }