Ejemplo n.º 1
0
        void HandleQuestgiverChooseReward(QuestGiverChooseReward packet)
        {
            Quest quest = Global.ObjectMgr.GetQuestTemplate(packet.QuestID);

            if (quest == null)
            {
                return;
            }

            if (packet.Choice.Item.ItemID != 0)
            {
                switch (packet.Choice.LootItemType)
                {
                case LootItemType.Item:
                    ItemTemplate rewardProto = Global.ObjectMgr.GetItemTemplate(packet.Choice.Item.ItemID);
                    if (rewardProto == null)
                    {
                        Log.outError(LogFilter.Network, "Error in CMSG_QUESTGIVER_CHOOSE_REWARD: player {0} ({1}) tried to get invalid reward item (Item Entry: {2}) for quest {3} (possible packet-hacking detected)", GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), packet.Choice.Item.ItemID, packet.QuestID);
                        return;
                    }

                    bool itemValid = false;
                    for (uint i = 0; i < quest.GetRewChoiceItemsCount(); ++i)
                    {
                        if (quest.RewardChoiceItemId[i] != 0 && quest.RewardChoiceItemType[i] == LootItemType.Item && quest.RewardChoiceItemId[i] == packet.Choice.Item.ItemID)
                        {
                            itemValid = true;
                            break;
                        }
                    }

                    if (!itemValid && quest.PackageID != 0)
                    {
                        var questPackageItems = Global.DB2Mgr.GetQuestPackageItems(quest.PackageID);
                        if (questPackageItems != null)
                        {
                            foreach (var questPackageItem in questPackageItems)
                            {
                                if (questPackageItem.ItemID != packet.Choice.Item.ItemID)
                                {
                                    continue;
                                }

                                if (_player.CanSelectQuestPackageItem(questPackageItem))
                                {
                                    itemValid = true;
                                    break;
                                }
                            }
                        }

                        if (!itemValid)
                        {
                            var questPackageItems1 = Global.DB2Mgr.GetQuestPackageItemsFallback(quest.PackageID);
                            if (questPackageItems1 != null)
                            {
                                foreach (var questPackageItem in questPackageItems1)
                                {
                                    if (questPackageItem.ItemID != packet.Choice.Item.ItemID)
                                    {
                                        continue;
                                    }

                                    itemValid = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!itemValid)
                    {
                        Log.outError(LogFilter.Network, "Error in CMSG_QUESTGIVER_CHOOSE_REWARD: player {0} ({1}) tried to get reward item (Item Entry: {2}) wich is not a reward for quest {3} (possible packet-hacking detected)", GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), packet.Choice.Item.ItemID, packet.QuestID);
                        return;
                    }
                    break;

                case LootItemType.Currency:
                    if (!CliDB.CurrencyTypesStorage.HasRecord(packet.Choice.Item.ItemID))
                    {
                        Log.outError(LogFilter.Player, $"Error in CMSG_QUESTGIVER_CHOOSE_REWARD: player {_player.GetName()} ({_player.GetGUID()}) tried to get invalid reward currency (Currency ID: {packet.Choice.Item.ItemID}) for quest {packet.QuestID} (possible packet-hacking detected)");
                        return;
                    }

                    bool currencyValid = false;
                    for (uint i = 0; i < quest.GetRewChoiceItemsCount(); ++i)
                    {
                        if (quest.RewardChoiceItemId[i] != 0 && quest.RewardChoiceItemType[i] == LootItemType.Currency && quest.RewardChoiceItemId[i] == packet.Choice.Item.ItemID)
                        {
                            currencyValid = true;
                            break;
                        }
                    }
                    if (!currencyValid)
                    {
                        Log.outError(LogFilter.Player, $"Error in CMSG_QUESTGIVER_CHOOSE_REWARD: player {_player.GetName()} ({_player.GetGUID()}) tried to get reward currency (Currency ID: {packet.Choice.Item.ItemID}) wich is not a reward for quest {packet.QuestID} (possible packet-hacking detected)");
                        return;
                    }
                    break;
                }
            }

            WorldObject obj = GetPlayer();

            if (!quest.HasFlag(QuestFlags.AutoComplete))
            {
                obj = Global.ObjAccessor.GetObjectByTypeMask(GetPlayer(), packet.QuestGiverGUID, TypeMask.Unit | TypeMask.GameObject);
                if (!obj || !obj.HasInvolvedQuest(packet.QuestID))
                {
                    return;
                }

                // some kind of WPE protection
                if (!GetPlayer().CanInteractWithQuestGiver(obj))
                {
                    return;
                }
            }

            if ((!GetPlayer().CanSeeStartQuest(quest) && GetPlayer().GetQuestStatus(packet.QuestID) == QuestStatus.None) ||
                (GetPlayer().GetQuestStatus(packet.QuestID) != QuestStatus.Complete && !quest.IsAutoComplete()))
            {
                Log.outError(LogFilter.Network, "Error in QuestStatus.Complete: player {0} ({1}) tried to complete quest {2}, but is not allowed to do so (possible packet-hacking or high latency)",
                             GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), packet.QuestID);
                return;
            }

            if (GetPlayer().CanRewardQuest(quest, packet.Choice.LootItemType, packet.Choice.Item.ItemID, true))
            {
                GetPlayer().RewardQuest(quest, packet.Choice.LootItemType, packet.Choice.Item.ItemID, obj);

                switch (obj.GetTypeId())
                {
                case TypeId.Unit:
                case TypeId.Player:
                {
                    //For AutoSubmition was added plr case there as it almost same exclute AI script cases.
                    Unit unitQGiver = obj.ToUnit();
                    // Send next quest
                    Quest nextQuest = _player.GetNextQuest(packet.QuestGiverGUID, quest);
                    if (nextQuest != null)
                    {
                        // Only send the quest to the player if the conditions are met
                        if (_player.CanTakeQuest(nextQuest, false))
                        {
                            if (nextQuest.IsAutoAccept() && _player.CanAddQuest(nextQuest, true))
                            {
                                _player.AddQuestAndCheckCompletion(nextQuest, obj);
                            }

                            _player.PlayerTalkClass.SendQuestGiverQuestDetails(nextQuest, packet.QuestGiverGUID, true, false);
                        }
                    }

                    _player.PlayerTalkClass.ClearMenus();
                    var qGiverAI = unitQGiver.GetAI();
                    if (qGiverAI != null)
                    {
                        qGiverAI.QuestReward(_player, quest, packet.Choice.LootItemType, packet.Choice.Item.ItemID);
                    }
                    break;
                }

                case TypeId.GameObject:
                {
                    GameObject questGiver = obj.ToGameObject();
                    // Send next quest
                    Quest nextQuest = _player.GetNextQuest(packet.QuestGiverGUID, quest);
                    if (nextQuest != null)
                    {
                        // Only send the quest to the player if the conditions are met
                        if (_player.CanTakeQuest(nextQuest, false))
                        {
                            if (nextQuest.IsAutoAccept() && _player.CanAddQuest(nextQuest, true))
                            {
                                _player.AddQuestAndCheckCompletion(nextQuest, obj);
                            }

                            _player.PlayerTalkClass.SendQuestGiverQuestDetails(nextQuest, packet.QuestGiverGUID, true, false);
                        }
                    }

                    _player.PlayerTalkClass.ClearMenus();
                    questGiver.GetAI().QuestReward(_player, quest, packet.Choice.LootItemType, packet.Choice.Item.ItemID);
                    break;
                }

                default:
                    break;
                }
            }
            else
            {
                GetPlayer().PlayerTalkClass.SendQuestGiverOfferReward(quest, packet.QuestGiverGUID, true);
            }
        }