Esempio n. 1
0
 public override void run()
 {
     try
     {
         if (this._client == null)
         {
             return;
         }
         Account player = this._client._player;
         Room    room   = player == null ? (Room)null : player._room;
         if (room != null && room.isPreparing())
         {
             bool isBotMode = room.isBotMode();
             SLOT slot1     = room.getSlot(player._slotId);
             if (slot1 == null)
             {
                 return;
             }
             if (slot1.state == SLOT_STATE.PRESTART)
             {
                 room.changeSlotState(slot1,SLOT_STATE.BATTLE_READY,true);
                 slot1.StopTiming();
                 if (isBotMode)
                 {
                     this._client.SendPacket((SendPacket) new BATTLE_CHANGE_DIFFICULTY_LEVEL_PAK(room));
                 }
                 this._client.SendPacket((SendPacket) new BATTLE_ROOM_INFO_PAK(room,isBotMode));
                 int num1 = 0;
                 int num2 = 0;
                 int num3 = 0;
                 int num4 = 0;
                 int num5 = 0;
                 for (int index = 0; index < 16; ++index)
                 {
                     SLOT slot2 = room._slots[index];
                     if (slot2.state >= SLOT_STATE.LOAD)
                     {
                         ++num3;
                         if (slot2._team == 0)
                         {
                             ++num4;
                         }
                         else
                         {
                             ++num5;
                         }
                         if (slot2.state >= SLOT_STATE.BATTLE_READY)
                         {
                             if (slot2._team == 0)
                             {
                                 ++num2;
                             }
                             else
                             {
                                 ++num1;
                             }
                         }
                     }
                 }
                 if (room._state != RoomState.Battle && (!(room._slots[room._leader].state >= SLOT_STATE.BATTLE_READY & isBotMode) || (room._leader % 2 != 0 || num2 <= num4 / 2) && (room._leader % 2 != 1 || num1 <= num5 / 2)) && (room._slots[room._leader].state < SLOT_STATE.BATTLE_READY || (ConfigGS.isTestMode && ConfigGS.udpType == SERVER_UDP_STATE.RELAY || (num1 <= num5 / 2 || num2 <= num4 / 2)) && (!ConfigGS.isTestMode || ConfigGS.udpType != SERVER_UDP_STATE.RELAY)))
                 {
                     return;
                 }
                 room.SpawnReadyPlayers(isBotMode);
             }
             else
             {
                 this._client.SendPacket((SendPacket) new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_Hole));
                 this._client.SendPacket((SendPacket) new BATTLE_LEAVEP2PSERVER_PAK(player,0));
                 room.changeSlotState(slot1,SLOT_STATE.NORMAL,true);
                 AllUtils.BattleEndPlayersCount(room,isBotMode);
             }
         }
         else
         {
             this._client.SendPacket((SendPacket) new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_Hole));
             this._client.SendPacket((SendPacket) new BATTLE_STARTBATTLE_PAK());
             room.changeSlotState(player._slotId,SLOT_STATE.NORMAL,true);
             if (room != null || player == null)
             {
                 return;
             }
             this._client.SendPacket((SendPacket) new LOBBY_ENTER_PAK());
         }
     }
     catch (Exception ex)
     {
         Logger.warning("[BATTLE_STARTBATTLE_REC] " + ex.ToString());
     }
 }
Esempio n. 2
0
        public override void run()
        {
            try
            {
                if (_client == null)
                {
                    return;
                }
                Account player = _client._player;
                Room    room   = player == null ? null : player._room;
                if (room != null && room.isPreparing())
                {
                    bool isBotMode = room.isBotMode();
                    SLOT slot      = room.getSlot(player._slotId);
                    if (slot == null)
                    {
                        return;
                    }
                    if (slot.state == SLOT_STATE.PRESTART)
                    {
                        room.changeSlotState(slot,SLOT_STATE.BATTLE_READY,true);
                        slot.StopTiming();
                        if (isBotMode)
                        {
                            _client.SendPacket(new BATTLE_CHANGE_DIFFICULTY_LEVEL_PAK(room));
                        }
                        _client.SendPacket(new BATTLE_ROOM_INFO_PAK(room,isBotMode));  //?
                    }
                    else
                    {
                        _client.SendPacket(new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_Hole));
                        _client.SendPacket(new BATTLE_LEAVEP2PSERVER_PAK(player,0));
                        room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                        AllUtils.BattleEndPlayersCount(room,isBotMode);
                        return;
                    }
                    int blue12 = 0,red12 = 0,total = 0,red9 = 0,blue9 = 0;
                    for (int i = 0; i < 16; i++)
                    {
                        SLOT slotR = room._slots[i];
                        if ((int)slotR.state >= 9)
                        {
                            total++;
                            if (slotR._team == 0)
                            {
                                red9++;
                            }
                            else
                            {
                                blue9++;
                            }
                            if ((int)slotR.state >= 12)
                            {
                                if (slotR._team == 0)
                                {
                                    red12++;
                                }
                                else
                                {
                                    blue12++;
                                }
                            }
                        }
                    }

                    // [test]
                    /* Pode ser removido */
                    /* Exibe mensagem na sala quando o player entra */
                    /**/
                    /**/ string txt = Translation.GetLabel("PlayerReady",player.player_name,(red12 + blue12),total);
                    /**/ using (SERVER_MESSAGE_ANNOUNCE_PAK packet = new SERVER_MESSAGE_ANNOUNCE_PAK(txt))
                        room.SendPacketToPlayers(packet,SLOT_STATE.RENDEZVOUS,1);
                    /* */


                    if ((int)room._state == 5 ||
                        (int)room._slots[room._leader].state >= 12 && isBotMode &&
                        (room._leader % 2 == 0 && red12 > red9 / 2 || room._leader % 2 == 1 && blue12 > blue9 / 2) ||

                        (int)room._slots[room._leader].state >= 12 &&

                        ((!ConfigGS.isTestMode || (int)ConfigGS.udpType != 3) &&
                         blue12 > blue9 / 2 && red12 > red9 / 2 ||
                         ConfigGS.isTestMode && (int)ConfigGS.udpType == 3))
                    {
                        room.SpawnReadyPlayers(isBotMode);
                    }
                }
                else
                {
                    _client.SendPacket(new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_Hole));
                    _client.SendPacket(new BATTLE_STARTBATTLE_PAK());
                    if (room != null)
                    {
                        room.changeSlotState(player._slotId,SLOT_STATE.NORMAL,true);
                    }
                    if (room == null && player != null)
                    {
                        _client.SendPacket(new LOBBY_ENTER_PAK());
                    }
                }
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[BATTLE_STARTBATTLE_REC.run] Erro fatal!");
            }
        }
        public override void run()
        {
            try
            {
                if (_client == null)
                {
                    return;
                }
                Account p    = _client._player;
                Room    room = p == null ? null : p._room;
                if (room != null && (room.stage4v4 == stage4v4 && room.room_type == room_type && room.mapId == mapId))
                {
                    SLOT slot = room._slots[p._slotId];
                    if (room.isPreparing() && room.UDPServer != null && (int)slot.state >= 9)
                    {
                        Account leader = room.getLeader();
                        if (leader != null)
                        {
                            if (p.LocalIP == new byte[4] || string.IsNullOrEmpty(p.PublicIP.ToString()))
                            {
                                _client.SendPacket(new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_No_Real_IP));
                                _client.SendPacket(new BATTLE_LEAVEP2PSERVER_PAK(p,0));
                                room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                                AllUtils.BattleEndPlayersCount(room,room.isBotMode());
                                slot.StopTiming();
                                return;
                            }
                            int gen2 = genValor(room.mapId,room.room_type);
                            if (slot._id == room._leader)
                            {
                                room._state = RoomState.PreBattle;
                                room.updateRoomInfo();
                                //room.LoadHitParts();
                            }
                            slot.preStartDate = DateTime.Now;
                            room.StartCounter(1,p,slot);
                            room.changeSlotState(slot,SLOT_STATE.PRESTART,true);
                            _client.SendPacket(new BATTLE_PRESTARTBATTLE_PAK(p,leader,true,gen2));
                            if (slot._id != room._leader)
                            {
                                leader.SendPacket(new BATTLE_PRESTARTBATTLE_PAK(p,leader,false,gen2));
                            }

                            //slot.state = SLOT_STATE.BATTLE;
                            //room.updateSlotsInfo();
                        }
                        else
                        {
                            _client.SendPacket(new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_Hole));
                            _client.SendPacket(new BATTLE_LEAVEP2PSERVER_PAK(p,0));
                            room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                            AllUtils.BattleEndPlayersCount(room,room.isBotMode());
                            slot.StopTiming();
                        }
                    }
                    else
                    {
                        room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                        _client.SendPacket(new BATTLE_STARTBATTLE_PAK());
                        AllUtils.BattleEndPlayersCount(room,room.isBotMode());
                        slot.StopTiming();
                    }
                }
                else
                {
                    _client.SendPacket(new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_MainLoad));
                    _client.SendPacket(new BATTLE_PRESTARTBATTLE_PAK());
                    if (room != null)
                    {
                        room.changeSlotState(p._slotId, SLOT_STATE.NORMAL, true);
                        AllUtils.BattleEndPlayersCount(room, room.isBotMode());
                    }
                    else
                    {
                        _client.SendPacket(new LOBBY_ENTER_PAK());
                    }
                }
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[BATTLE_PRESTARTBATTLE_REC.run] Erro fatal!");
            }
        }
Esempio n. 4
0
 public override void run()
 {
     try
     {
         if (this._client == null)
         {
             return;
         }
         Account player = this._client._player;
         Room    room   = player == null ? (Room)null : player._room;
         if (room != null && (int)room.stage4v4 == this.stage4v4 && ((int)room.room_type == this.room_type && room.mapId == this.mapId))
         {
             SLOT slot = room._slots[player._slotId];
             if (room.isPreparing() && room.UDPServer != null && slot.state >= SLOT_STATE.LOAD)
             {
                 Account leader = room.getLeader();
                 if (leader != null)
                 {
                     if (player.LocalIP == new byte[4] || string.IsNullOrEmpty(player.PublicIP.ToString()))
                     {
                         this._client.SendPacket((SendPacket) new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_No_Real_IP));
                         this._client.SendPacket((SendPacket) new BATTLE_LEAVEP2PSERVER_PAK(player,0));
                         room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                         AllUtils.BattleEndPlayersCount(room,room.isBotMode());
                         slot.StopTiming();
                     }
                     else
                     {
                         int gen2 = this.genValor(room.mapId,(int)room.room_type);
                         if (slot._id == room._leader)
                         {
                             room._state = RoomState.PreBattle;
                             room.updateRoomInfo();
                         }
                         slot.preStartDate = DateTime.Now;
                         room.StartCounter(1,player,slot);
                         room.changeSlotState(slot,SLOT_STATE.PRESTART,true);
                         this._client.SendPacket((SendPacket) new BATTLE_PRESTARTBATTLE_PAK(player,leader,true,gen2));
                         if (slot._id == room._leader)
                         {
                             return;
                         }
                         leader.SendPacket((SendPacket) new BATTLE_PRESTARTBATTLE_PAK(player,leader,false,gen2));
                     }
                 }
                 else
                 {
                     this._client.SendPacket((SendPacket) new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_Hole));
                     this._client.SendPacket((SendPacket) new BATTLE_LEAVEP2PSERVER_PAK(player,0));
                     room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                     AllUtils.BattleEndPlayersCount(room,room.isBotMode());
                     slot.StopTiming();
                 }
             }
             else
             {
                 room.changeSlotState(slot,SLOT_STATE.NORMAL,true);
                 this._client.SendPacket((SendPacket) new BATTLE_STARTBATTLE_PAK());
                 AllUtils.BattleEndPlayersCount(room,room.isBotMode());
                 slot.StopTiming();
             }
         }
         else
         {
             this._client.SendPacket((SendPacket) new SERVER_MESSAGE_KICK_BATTLE_PLAYER_PAK(EventErrorEnum.Battle_First_MainLoad));
             this._client.SendPacket((SendPacket) new BATTLE_PRESTARTBATTLE_PAK());
             if (room != null)
             {
                 room.changeSlotState(player._slotId, SLOT_STATE.NORMAL, true);
                 AllUtils.BattleEndPlayersCount(room, room.isBotMode());
             }
             else
             {
                 this._client.SendPacket((SendPacket) new LOBBY_ENTER_PAK());
             }
         }
     }
     catch (Exception ex)
     {
         Logger.info("BATTLE_PRESTARTBATTLE_REC: " + ex.ToString());
     }
 }