Exemplo n.º 1
0
        public override void RunImpl()
        {
            Room   room   = getClient().getPlayer().getRoom();
            Player player = getClient().getPlayer();

            if (room != null && player != null)
            {
                SLOT killer = room.getRoomSlot(fragInfos.getKiller());
                for (int i = 1; i <= fragInfos.getKillsCount(); i++)
                {
                    Frag frag = fragInfos.getFrag(i);
                    if (frag != null)
                    {
                        bool suicide = frag.getDeatSlot() == fragInfos.getKiller();
                        SLOT death   = room.getRoomSlot(frag.getDeatSlot());

                        if (!suicide)
                        {
                            killer.setAllKills(killer.getAllKills() + 1);

                            /* Подсчет опыта и очков */
                            killer.setAllExp(killer.getAllExp() + 9); //сохраняем опыт
                            killer.setAllGP(killer.getAllGp() + 5);   //сохраняем очки

                            killer.setOneTimeKills(killer.getOneTimeKills() + 1);
                            int weaponHeadNum = fragInfos.getWeaponHeadNum();
                            killer.setKillMessage(0);
                            if (fragInfos.getKillsCount() > 1)
                            {
                                if ((weaponHeadNum == 8030) || (weaponHeadNum == 9030))
                                {
                                    killer.setKillMessage(2);
                                }
                                else
                                {
                                    killer.setKillMessage(1);
                                }
                            }
                            else
                            {
                                int killMessage = 0;
                                if (frag.getDeathMask() >> 4 == 3)
                                { //TODO:: понять что это и всунуть в Frag!
                                    killMessage = 4;
                                }
                                else if ((frag.getDeathMask() >> 4 == 1) && (frag.getDeathMask() >> 2 == 1) && (weaponHeadNum == 7020))
                                {
                                    killMessage = 6;
                                }

                                if (killMessage > 0)
                                {
                                    int lastMessage = killer.lastKillState >> 12;

                                    if (killMessage == 4)
                                    {
                                        if (lastMessage != 4)
                                        {
                                            killer.repeatLastState = false;
                                            //killer.setOneTimeKills(0);
                                        }

                                        killer.setOneTimeKills(killer.getOneTimeKills() + 1);
                                        killer.lastKillState = killMessage << 12 | killer.getOneTimeKills();

                                        int countedKill = killer.lastKillState & 0xF;

                                        if (killer.repeatLastState)
                                        {
                                            if (countedKill > 1)
                                            {
                                                killer.setKillMessage(5);
                                            }
                                            else
                                            {
                                                killer.setKillMessage(4);
                                            }
                                        }
                                        else
                                        {
                                            killer.setKillMessage(4);
                                            killer.repeatLastState = true;
                                        }
                                    }
                                    else if (killMessage == 6)
                                    {
                                        if (lastMessage != 6)
                                        {
                                            killer.repeatLastState = false;
                                            // killer.setOneTimeKills(0);
                                        }

                                        killer.setOneTimeKills(killer.getOneTimeKills() + 1);
                                        killer.lastKillState = killMessage << 12 | killer.getOneTimeKills();

                                        int countedKill = killer.lastKillState & 0xF;

                                        if (killer.repeatLastState)
                                        {
                                            if (countedKill > 1)
                                            {
                                                killer.setKillMessage(6);
                                            }
                                        }
                                        else
                                        {
                                            killer.repeatLastState = true;
                                        }
                                    }
                                }
                                else
                                {
                                    killer.lastKillState   = 0;
                                    killer.repeatLastState = false;
                                }
                            }
                            //
                        }
                        //Добавляем общий счет команде
                        if (frag.getDeatSlot() % 2 == 0)
                        {    // Если помер красный
                            room.setBlueKills(room.getBlueKills() + 1);
                            room.setRedDeaths(room.getRedDeaths() + 1);
                        }
                        else
                        {
                            room.setRedKills(room.getRedKills() + 1);
                            room.setBlueDeaths(room.getBlueDeaths() + 1);
                        }
                        death.setOneTimeKills(0);
                        death.setKillMessage(0);
                        death.setLastKillMessage(0);
                        death.lastKillState = 0;

                        death.setAllDeahts(death.getAllDeath() + 1);
                        //Добавляем очки в бою с ботами
                        if (room.getSpecial() == 6)
                        {
                            SLOT slot    = room.getRoomSlot(fragInfos.getKiller());
                            int  AILevel = room.getRoomSlotByPlayer(room.getLeader()).getId() % 2 == 0 ? room.getAiLevel() + room.getBlueDeaths() / 20 : room.getAiLevel() + room.getRedDeaths() / 20;
                            int  AIScore = 10 + room.getRoomSlot(fragInfos.getKiller()).getOneTimeKills() * AILevel;
                            slot.setBotScore(slot.getBotScore() + AIScore);
                        }

                        /* Миссии */
                        if (room.getSpecial() != 6)
                        {
                            SLOT killer2 = room.getRoomSlot(fragInfos.getKiller());

                            if (getClient().getPlayer() == killer2.getPlayer())
                            {
                                for (int count = 0; count < fragInfos.getKillsCount(); count++)
                                {
                                    getClient().SendPacket(new PROTOCOL_BASE_MISSION_COMPLETE_ACK(242, 1));//убийство
                                }

                                if (killer2.getKillMessage() == 8)
                                {
                                    getClient().SendPacket(new PROTOCOL_BASE_MISSION_COMPLETE_ACK(244, 1));//хедшот
                                }

                                if (killer2.getKillMessage() == 9)
                                {
                                    getClient().SendPacket(new PROTOCOL_BASE_MISSION_COMPLETE_ACK(244, 1));//тож хедшот
                                }
                            }

                            if (death == room.getRoomSlotByPlayer(getClient().getPlayer()))
                            {
                                getClient().SendPacket(new PROTOCOL_BASE_MISSION_COMPLETE_ACK(241, 1));//смерть
                            }
                        }

                        if (room.getType() == 2)
                        {
                            if (room.getBlueKills() == room.redTeamCount)
                            {
                                TeamWin = 1;
                            }
                            else if (room.getRedKills() == room.blueTeamCount)
                            {
                                TeamWin = 0;
                            }
                        }
                        /* Уничтожение */
                        if (room.getType() == 4)
                        {
                            if (room.getBlueKills() == room.redTeamCount)
                            {
                                TeamWin = 1;
                            }
                            else if (room.getRedKills() == room.blueTeamCount)
                            {
                                TeamWin = 0;
                            }
                        }
                    }
                }
                foreach (Player member in getClient().getPlayer().getRoom().getPlayers().Values)
                {
                    if (SLOT_STATE.SLOT_STATE_BATTLE == room.getRoomSlotByPlayer(member).getState())
                    {
                        member.getClient().SendPacket(new PROTOCOL_BATTLE_FRAG_INFO_ACK(room, fragInfos));
                    }
                }
                if (TeamWin >= 0)
                {
                    //TeamWin = -1;
                    if (!(TeamWin == 1 && room.getBombState() == 1))
                    {
                        room.setRedKills(0);
                        room.setBlueKills(0);
                        if (TeamWin == 1)
                        {
                            room.setBlueWinRounds(room.getBlueWinRounds() + 1);
                        }
                        else
                        {
                            room.setRedWinRounds(room.getRedWinRounds() + 1);
                        }
                        if ((TeamWin == 1 ? room.getBlueWinRounds() : room.getRedWinRounds()) == room.getKillsByMask())
                        {
                            foreach (Player member in getClient().getPlayer().getRoom().getPlayers().Values)
                            {
                                SLOT slot = room.getRoomSlotByPlayer(member);
                                member.getClient().SendPacket(new PROTOCOL_BATTLE_END_ACK(member,room));
                                slot.setKillMessage(0);
                                slot.setLastKillMessage(0);
                                slot.setOneTimeKills(0);
                                slot.setAllKills(0);
                                slot.setAllDeahts(0);
                            }
                            room.setRedKills(0);
                            room.setRedDeaths(0);
                            room.setBlueKills(0);
                            room.setBlueDeaths(0);
                            room.setFigth(0);
                            room.setBlueWinRounds(0);
                            room.setRedWinRounds(0);
                            room.setBombState(0);
                        }
                        else
                        {
                            foreach (Player member in getClient().getPlayer().getRoom().getPlayers().Values)
                            {
                                SLOT slot = room.getRoomSlotByPlayer(member);
                                slot.setKillMessage(0);
                                slot.setLastKillMessage(0);
                                slot.setOneTimeKills(0);
                                slot.lastKillState = 0;
                                room.setRedKills(0);
                                room.setRedDeaths(0);
                                room.setBlueKills(0);
                                room.setBlueDeaths(0);
                                room.setBombState(0);
                                member.getClient().SendPacket(new PROTOCOL_BATTLE_ROUND_END_ACK(TeamWin,4,getClient().getPlayer().getRoom()));
                            }
                            Thread.Sleep(8000);
                            foreach (Player member in getClient().getPlayer().getRoom().getPlayers().Values)
                            {
                                member.getClient().SendPacket(new opcode_3865_ACK());
                                member.getClient().SendPacket(new PROTOCOL_BATTLE_ROUND_START(member.getRoom()));
                            }
                        }
                        //TeamWin = -1;
                    }
                    TeamWin = -1;
                }
            }
        }
        public override void WriteImpl()
        {
            SLOT slotByPlayer = room.getRoomSlotByPlayer(player);

            clan = player.Clan;

            level = LevelUpParser._levels[player.getRank()];
            stats = PlayersStatsTable.statistics[player.PlayerID];

            /* Левел ап */
            if (player.getRank() < 52)
            {
                if (player.getExp() >= level.getOnAllExp())
                {
                    player.setRank(player.getRank() + 1);
                    PlayersTable.UpdateRank(player.PlayerID,player.getRank());
                    player.setGp(player.getGp() + LevelUpParser._levels[player.getRank()].getOnGPUp());
                    PlayersTable.UpdateGP_Exp(player.PlayerID,player.getGp() + level.getOnGPUp(),player.getExp());

                    player.getClient().SendPacket(new PACKET_LEVEL_UP_ACK(player.getRank()));
                }
            }

            WriteH(0xD08);
            if (room.getType() == 1)
            {
                if (room.getBlueKills() > room.getRedKills())
                {
                    WriteC(1);
                }
                if (room.getRedKills() > room.getBlueKills())
                {
                    WriteC(0);
                }
                if (room.getRedKills() == room.getBlueKills())
                {
                    WriteC(2);
                }
            }
            if (room.getType() == 2)
            {
                if (room.getBlueWinRounds() > room.getRedWinRounds())
                {
                    WriteC(1);
                }
                if (room.getRedWinRounds() > room.getBlueWinRounds())
                {
                    WriteC(0);
                }
                if (room.getRedWinRounds() == room.getBlueWinRounds())
                {
                    WriteC(2);
                }
            }
            if (room.getType() == 4)
            {
                if (room.getBlueWinRounds() > room.getRedWinRounds())
                {
                    WriteC(1);
                }
                if (room.getRedWinRounds() > room.getBlueWinRounds())
                {
                    WriteC(0);
                }
                if (room.getRedWinRounds() == room.getBlueWinRounds())
                {
                    WriteC(2);
                }
            }
            WriteH(3); // что это???
            WriteH(2); // что это???

            int GP,Exp;

            // Опыт
            for (int i = 0; i < 16; i++)
            {
                SLOT slot = room.getRoomSlot(i);
                if (room.getSpecial() == 6)
                {
                    WriteH((short)slot.getAllExp());
                    player.setExp(player.getExp() + slot.getAllExp());
                }
                else
                {
                    WriteH((short)slot.getAllExp());
                    player.setExp(player.getExp() + slot.getAllExp());
                }
            }

            // Очки
            for (int i = 0; i < 16; i++)
            {
                SLOT slot = room.getRoomSlot(i);
                if (room.getSpecial() == 6)
                {
                    WriteH((short)slot.getAllGp());
                    player.setExp(player.getExp() + slot.getAllExp());
                }
                else
                {
                    WriteH((short)slot.getAllGp());
                    player.setExp(player.getExp() + slot.getAllExp());
                }
            }

            /* Записываем в базу данных */
            Exp = player.getExp();
            GP  = player.getGp();
            PlayersTable.UpdateGP_Exp(player.PlayerID,GP,Exp);

            //Очки за ботов
            for (int i = 0; i < 16; i++)
            {
                WriteH(0);
            }

            WriteB(new byte[] {
                //Рейты по 2 байта на слот
                //В скобках|Иконка
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
                0x08,0x00,
            });
            WriteB(new byte[] {
                //Иконки Ivent/PC_Cafe/Item
                0xFF,0x00,
                0xFF,0x00,
                0xFF,0x00,
                0xFF,0x00,
                0xFF,0x00,
                0xFF,0x00,
                0xFF,0x00,
                0xFF,0x00,
            });

            WriteS(player.getName(),Player.MAX_NAME_SIZE);     // Имя перса
            WriteD(player.getExp());                           // опыт
            WriteD(player.getRank());                          // ранк (0-54)
            WriteD(player.getRank());                          // фейк-ранг для купона скрытия ранга
            WriteD(player.getGp());                            // ГП
            WriteD(player.getMoney());                         // Рублики

            WriteD(player == null ? (int)clan.Id : (int)0);    // ClanID
            WriteD(player == null ? (int)clan.Color : (int)0); // ClanNameColor

            WriteD(0);                                         // Unk
            WriteC(0);                                         // Unk
            WriteD(player.getPCCafe());                        //pc cafe
            WriteH((short)player.getEmblem());                 //Лычка поидеи

            WriteS("",17);
            WriteC(0); //unk

            WriteH(clan != null ? (short)clan.Rank : (short)0);
            WriteC(Convert.ToByte(((this.player == null) || (clan == null)) ? 0xff : clan.getLogo1()));
            WriteC(Convert.ToByte(((this.player == null) || (clan == null)) ? 0xff : clan.getLogo2()));
            WriteC(Convert.ToByte(((this.player == null) || (clan == null)) ? 0xff : clan.getLogo3()));
            WriteC(Convert.ToByte(((this.player == null) || (clan == null)) ? 0xff : clan.getLogo4()));
            WriteH(0);

            WriteD(0);  // Непонятно разделитель

            WriteB(new byte[8] {
                0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01
            });

            /* Статистика */
            WriteD(stats.getFights());          //всего боев
            WriteD(stats.getWins());            //всего побед
            WriteD(stats.getLosts());           //всего поражений
            WriteD(0);                          // unk
            WriteD(stats.getKills());           //кол-во убийств
            WriteD(stats.getHeadshots());       //кол-во хедшотов
            WriteD(stats.getDeaths());          //кол-во смертей
            WriteD(0);                          // unk
            WriteD(stats.getKills());           //опять килы о.о
            WriteD(stats.getEscapes());         //всего ливнул
            WriteD(stats.getSeasonFights());    //всего боев за сезон
            WriteD(stats.getSeasonWins());      //всего побед за сезон
            WriteD(stats.getSeasonLosts());     //всего поражений за сезон
            WriteD(0);                          // unk
            WriteD(stats.getSeasonKills());     //киллы сезон по идее
            WriteD(stats.getSeasonHeadshots()); //хеды сезон по идее
            WriteD(stats.getSeasonDeaths());    //смерти сезон по идее
            WriteD(0);                          // unk
            WriteD(stats.getSeasonKills());     //опять килы,хз зачем
            WriteD(stats.getSeasonEscapes());   //сколько ливнул за сезон

            WriteH((short)room.getRedWinRounds());
            WriteH((short)room.getBlueWinRounds());
            WriteB(new byte[49]);
        }