public void AbandonQuest(ushort questID)
        {
            Character_quest quest = GetQuest(questID);

            if (quest == null)
            {
                return;
            }

            Quests.Remove(quest.QuestID);
            SendQuestState(quest.Quest, QuestCompletion.QUESTCOMPLETION_ABANDONED);
            CharMgr.Database.DeleteObject(quest);

            // This will make objects unlootable if they were lootable because of a quest.
            UpdateObjects();

            // Update quest givers around
            foreach (Object obj in _Owner.ObjectsInRange)
            {
                if (obj.IsCreature())
                {
                    obj.GetCreature().SendMeTo(_Owner.GetPlayer());
                }
            }

            _Owner.EvtInterface.Notify(EventName.OnAcceptQuest, _Owner, quest);
        }
Beispiel #2
0
        public bool CreatureHasQuestToAchieve(Player Plr)
        {
            if (Entry == 0)
            {
                return(false);
            }

            List <Quest> Finisher = WorldMgr.GetFinishersQuests(Entry);

            if (Finisher == null)
            {
                return(false);
            }

            foreach (Quest Q in Finisher)
            {
                Character_quest CQ = Plr.QtsInterface.GetQuest(Q.Entry);
                if (CQ != null && !CQ.Done && CQ.IsDone())
                {
                    return(true);
                }
            }

            return(false);
        }
        public void SelectRewards(ushort questID, byte num)
        {
            Character_quest quest = GetQuest(questID);

            if (quest == null || !quest.IsDone())
            {
                return;
            }

            if ((num & 1) > 0)
            {
                quest.SelectedRewards.Add(0);
            }
            if ((num & 2) > 0)
            {
                quest.SelectedRewards.Add(1);
            }
            if ((num & 4) > 0)
            {
                quest.SelectedRewards.Add(2);
            }
            if ((num & 8) > 0)
            {
                quest.SelectedRewards.Add(3);
            }
        }
Beispiel #4
0
        public void DeclineQuest(UInt16 QuestID)
        {
            Character_quest Quest = GetQuest(QuestID);

            if (Quest == null)
            {
                return;
            }

            _Quests.Remove(Quest.QuestID);
            SendQuestState(Quest.Quest, QuestCompletion.QUESTCOMPLETION_ABANDONED);
            CharMgr.Database.DeleteObject(Quest);

            // This will make objects unlootable if they were lootable because of a quest.
            updateObjects();

            // Update quest givers around
            foreach (Object Obj in _Owner._ObjectRanged)
            {
                if (Obj.IsCreature())
                {
                    Obj.GetCreature().SendMeTo(_Owner.GetPlayer());
                }
            }

            _Owner.EvtInterface.Notify(EventName.ON_ACCEPT_QUEST, _Owner, Quest);
        }
        public bool CreatureHasQuestToAchieve(Player plr)
        {
            if (Entry == 0)
            {
                return(false);
            }

            List <Quest> finisher = QuestService.GetFinishersQuests(Entry);

            if (finisher == null)
            {
                return(false);
            }

            foreach (Quest q in finisher)
            {
                Character_quest cq = plr.QtsInterface.GetQuest(q.Entry);
                if (cq != null && !cq.IsDone())
                {
                    return(true);
                }
            }

            return(false);
        }
        public bool AcceptQuest(Quest Quest)
        {
            if (Quest == null)
            {
                return(false);
            }

            if (!CanStartQuest(Quest))
            {
                return(false);
            }

            Character_quest CQuest = new Character_quest();

            CQuest.QuestID     = Quest.Entry;
            CQuest.Done        = false;
            CQuest.CharacterID = GetPlayer().CharacterId;
            CQuest.Quest       = Quest;

            foreach (Quest_Objectives QObj in Quest.Objectives)
            {
                Character_Objectives CObj = new Character_Objectives();
                CObj.Count       = 0;
                CObj.Objective   = QObj;
                CObj.ObjectiveID = QObj.Guid;
                CQuest._Objectives.Add(CObj);
            }

            _Quests.Add(Quest.Entry, CQuest);
            CharMgr.Database.AddObject(CQuest);

            SendQuestState(Quest, QuestCompletion.QUESTCOMPLETION_OFFER);
            return(true);
        }
Beispiel #7
0
        public bool DoneQuest(UInt16 QuestID)
        {
            Character_quest Quest = GetQuest(QuestID);

            if (Quest == null || !Quest.IsDone())
            {
                return(false);
            }

            Player Plr = GetPlayer();

            Dictionary <Item_Info, uint> Choices = GenerateRewards(Quest.Quest, Plr);

            UInt16 FreeSlots = Plr.ItmInterface.GetTotalFreeInventorySlot();

            if (FreeSlots < Quest.SelectedRewards.Count)
            {
                Plr.SendLocalizeString("", Localized_text.TEXT_OVERAGE_CANT_SALVAGE);
                return(false);
            }

            foreach (Quest_Objectives Obj in Quest.Quest.Objectives)
            {
                if ((Objective_Type)Obj.ObjType == Objective_Type.QUEST_GET_ITEM)
                {
                    if (Obj.Item != null)
                    {
                        Plr.ItmInterface.RemoveAllItems(Obj.Item.Entry);
                    }
                }
            }

            byte num = 0;

            foreach (KeyValuePair <Item_Info, uint> Kp in Choices)
            {
                if (Quest.SelectedRewards.Contains(num))
                {
                    Plr.ItmInterface.CreateItem(Kp.Key, (ushort)Kp.Value);
                }
                ++num;
            }

            Plr.AddXp(Quest.Quest.Xp);
            Plr.AddMoney(Quest.Quest.Gold);

            Quest.Done  = true;
            Quest.Dirty = true;
            Quest.SelectedRewards.Clear();

            SendQuestState(Quest.Quest, QuestCompletion.QUESTCOMPLETION_DONE);
            CharMgr.Database.SaveObject(Quest);

            _Owner.EvtInterface.Notify(EventName.ON_DONE_QUEST, _Owner, Quest);
            return(true);
        }
Beispiel #8
0
        public bool AcceptQuest(Quest Quest)
        {
            if (Quest == null)
            {
                return(false);
            }

            if (!CanStartQuest(Quest))
            {
                return(false);
            }

            Character_quest CQuest = new Character_quest();

            CQuest.QuestID     = Quest.Entry;
            CQuest.Done        = false;
            CQuest.CharacterID = GetPlayer().CharacterId;
            CQuest.Quest       = Quest;

            // F_QUEST_LIST Quests not done
            Character_quest_inprogress IQuest = new Character_quest_inprogress();

            IQuest.QuestID     = Quest.Entry;
            IQuest.CharacterID = GetPlayer().CharacterId;
            IQuest.Quest       = Quest;

            foreach (Quest_Objectives QObj in Quest.Objectives)
            {
                Character_Objectives CObj = new Character_Objectives();
                CObj.Count       = 0;
                CObj.Objective   = QObj;
                CObj.ObjectiveID = QObj.Guid;
                CQuest._Objectives.Add(CObj);

                // F_QUEST_LIST Quests not done.
                Character_InProgressObjectives IObj = new Character_InProgressObjectives();
                IObj.Count       = 0;
                IObj.Objective   = QObj;
                IObj.ObjectiveID = QObj.Guid;
                IQuest._InProgressObjectives.Add(IObj);
            }

            _Quests.Add(Quest.Entry, CQuest);
            CharMgr.Database.AddObject(CQuest);

            // Add Quests into character_quest_inprogress Table.
            _InProgressQuests.Add(Quest.Entry, IQuest);
            CharMgr.Database.AddObject(IQuest);

            SendQuestState(Quest, QuestCompletion.QUESTCOMPLETION_OFFER);
            return(true);
        }
        public bool AcceptQuest(Quest quest)
        {
            if (quest == null)
            {
                return(false);
            }

            if (!CanStartQuest(quest))
            {
                return(false);
            }

            int activeQuestCount = Quests.Values.Count(q => !q.Done);

            if (activeQuestCount >= MAX_ACTIVE_QUESTS)
            {
                GetPlayer().SendClientMessage("Too many quests", ChatLogFilters.CHATLOGFILTERS_C_ABILITY_ERROR);
                GetPlayer().SendClientMessage("You have too many quests. Please abandon some of them first.");
                return(false);
            }

            Character_quest cQuest = new Character_quest();

            cQuest.QuestID     = quest.Entry;
            cQuest.Done        = false;
            cQuest.CharacterId = GetPlayer().CharacterId;
            cQuest.Quest       = quest;

            foreach (Quest_Objectives qObj in quest.Objectives)
            {
                Character_Objectives cObj = new Character_Objectives();
                cObj.Quest       = cQuest;
                cObj._Count      = 0;
                cObj.Objective   = qObj;
                cObj.ObjectiveID = qObj.Guid;
                cQuest._Objectives.Add(cObj);
            }

            CharMgr.Database.AddObject(cQuest);
            Quests.Add(quest.Entry, cQuest);

            SendQuestState(quest, QuestCompletion.QUESTCOMPLETION_OFFER);

            // This will make objects lootable if they contain a quest object.
            UpdateObjects();

            _Owner.EvtInterface.Notify(EventName.OnAcceptQuest, _Owner, cQuest);
            return(true);
        }
Beispiel #10
0
        public bool DoneQuest(UInt16 QuestID)
        {
            Character_quest            Quest  = GetQuest(QuestID);
            Character_quest_inprogress IQuest = GetQuestInProgress(QuestID);

            if (Quest == null || !Quest.IsDone())
            {
                return(false);
            }

            Player Plr = GetPlayer();

            Dictionary <Item_Info, uint> Choices = GenerateRewards(Quest.Quest, Plr);

            UInt16 FreeSlots = Plr.ItmInterface.GetTotalFreeInventorySlot();

            if (FreeSlots < Quest.SelectedRewards.Count)
            {
                Plr.SendLocalizeString("", Localized_text.TEXT_OVERAGE_CANT_SALVAGE);
                return(false);
            }

            byte num = 0;

            foreach (KeyValuePair <Item_Info, uint> Kp in Choices)
            {
                if (Quest.SelectedRewards.Contains(num))
                {
                    Plr.ItmInterface.CreateItem(Kp.Key, (ushort)Kp.Value);
                }
                ++num;
            }

            Plr.AddXp(Quest.Quest.Xp);
            Plr.AddMoney(Quest.Quest.Gold);

            Quest.Done  = true;
            Quest.Dirty = true;
            Quest.SelectedRewards.Clear();

            SendQuestState(Quest.Quest, QuestCompletion.QUESTCOMPLETION_DONE);

            CharMgr.Database.SaveObject(Quest);

            // When you done the quest, delete the entry, to not display in the list (F_QUEST_LIST)
            CharMgr.Database.DeleteObject(IQuest);

            return(true);
        }
        public void SendQuest(Character_quest cQuest)
        {
            if (cQuest == null)
            {
                Log.Error("QuestsInterface", "SendQuest CQuest == null");
                return;
            }

            PacketOut packet = new PacketOut((byte)Opcodes.F_QUEST_INFO);

            packet.WriteUInt16(cQuest.QuestID);
            packet.WriteByte(cQuest.Quest.Type); // Quest Type (database is wrong)
            BuildQuestHeader(packet, GetPlayer(), cQuest.Quest, true);

            Dictionary <Item_Info, uint> rewards = GenerateRewards(cQuest.Quest, GetPlayer());

            packet.WriteByte(cQuest.Quest.ChoiceCount);
            packet.WriteByte(0);
            packet.WriteByte((byte)rewards.Count);

            foreach (KeyValuePair <Item_Info, uint> kp in rewards)
            {
                Item.BuildItem(ref packet, null, kp.Key, null, 0, (ushort)kp.Value);
            }

            packet.WriteByte(0);

            BuildObjectives(packet, cQuest._Objectives);

            List <Quest_Map> SortedMaps = cQuest.Quest.Maps.OrderBy(x => x.Entry).ThenByDescending(x => x.Id).ToList();

            foreach (Quest_Map map in SortedMaps)
            {
                packet.WriteByte(map.Id);
                packet.WritePascalString(map.Name);
                packet.WritePascalString(map.Description);
                packet.WriteUInt16(map.ZoneId);
                packet.WriteUInt16(map.Icon);
                packet.WriteUInt16(map.X);
                packet.WriteUInt16(map.Y);
                packet.WriteUInt16(map.Unk);
                packet.WriteByte(map.When);
            }

            packet.WriteByte(0);

            GetPlayer().SendPacket(packet);
        }
Beispiel #12
0
        public void SendQuestUpdate(Character_quest Quest, Character_Objectives Obj)
        {
            if (GetPlayer() == null)
            {
                return;
            }

            PacketOut Out = new PacketOut((byte)Opcodes.F_QUEST_UPDATE);

            Out.WriteUInt16(Quest.QuestID);
            Out.WriteByte(Convert.ToByte(Quest.IsDone()));
            Out.WriteByte(Obj.Objective.num);
            Out.WriteByte((byte)Obj.Count);
            Out.WriteUInt16(0);
            GetPlayer().SendPacket(Out);
        }
Beispiel #13
0
        public void SelectRewards(UInt16 QuestID, byte num)
        {
            Character_quest Quest = GetQuest(QuestID);

            if (Quest == null || !Quest.IsDone())
            {
                return;
            }

            if (num > 0)
            {
                --num;
            }

            Log.Info("SelectRewards", "Selection de la recompence : " + num);
            Quest.SelectedRewards.Add(num);
        }
Beispiel #14
0
        public void SendQuest(Character_quest CQuest)
        {
            if (CQuest == null)
            {
                Log.Error("QuestsInterface", "SendQuest CQuest == null");
                return;
            }

            PacketOut Packet = new PacketOut((byte)Opcodes.F_QUEST_INFO);

            Packet.WriteUInt16(CQuest.QuestID);
            Packet.WriteByte(0); // Quest Type (database is wrong)
            BuildQuestHeader(Packet, CQuest.Quest, true);

            Dictionary <Item_Info, uint> Rewards = GenerateRewards(CQuest.Quest, GetPlayer());

            Packet.WriteByte(CQuest.Quest.ChoiceCount);
            Packet.WriteByte(0);
            Packet.WriteByte((byte)Rewards.Count);

            foreach (KeyValuePair <Item_Info, uint> Kp in Rewards)
            {
                Item.BuildItem(ref Packet, null, Kp.Key, 0, (ushort)Kp.Value);
            }

            Packet.WriteByte(0);

            BuildObjectives(Packet, CQuest._Objectives);

            foreach (Quest_Map Map in CQuest.Quest.Maps)
            {
                Packet.WriteByte(Map.Id);
                Packet.WritePascalString(Map.Name);
                Packet.WritePascalString(Map.Description);
                Packet.WriteUInt16(Map.ZoneId);
                Packet.WriteUInt16(Map.Icon);
                Packet.WriteUInt16(Map.X);
                Packet.WriteUInt16(Map.Y);
                Packet.WriteUInt16(Map.Unk);
                Packet.WriteByte(Map.When);
            }

            Packet.WriteByte(0);

            GetPlayer().SendPacket(Packet);
        }
Beispiel #15
0
        public void SendQuest(Character_quest CQuest)
        {
            if (CQuest == null)
            {
                Log.Error("QuestsInterface", "SendQuest CQuest == null");
                return;
            }

            PacketOut Packet = new PacketOut((byte)Opcodes.F_QUEST_INFO);

            Packet.WriteUInt16(CQuest.QuestID);
            Packet.WriteByte(0);
            BuildQuestHeader(Packet, CQuest.Quest, true);

            Dictionary <Item_Info, uint> Rewards = GenerateRewards(CQuest.Quest, GetPlayer());

            Packet.WriteByte(CQuest.Quest.ChoiceCount);
            Packet.WriteByte(0);
            Packet.WriteByte((byte)Rewards.Count);

            foreach (KeyValuePair <Item_Info, uint> Kp in Rewards)
            {
                Item.BuildItem(ref Packet, null, Kp.Key, 0, (ushort)Kp.Value);
            }

            Packet.WriteByte(0);

            BuildObjectives(Packet, CQuest._Objectives);

            Packet.WriteByte(1);

            Packet.WritePascalString(CQuest.Quest.Name);
            Packet.WritePascalString("Return to your giver");

            Packet.WriteUInt16(0x006A);
            Packet.WriteUInt16(0x046D);
            Packet.WriteUInt16(0x4D9E);
            Packet.WriteUInt16(0xCB65);

            Packet.Fill(0, 18);

            GetPlayer().SendPacket(Packet);
        }
        public void SendQuestUpdate(Character_quest quest)
        {
            if (GetPlayer() == null)
            {
                return;
            }

            PacketOut Out = new PacketOut((byte)Opcodes.F_QUEST_UPDATE, 6 + quest._Objectives.Count);

            Out.WriteUInt16(quest.QuestID);
            Out.WriteByte(Convert.ToByte(quest.IsDone()));
            Out.WriteByte((byte)quest._Objectives.Count);
            foreach (Character_Objectives obj in quest._Objectives)
            {
                Out.WriteByte((byte)obj.Count);
            }
            Out.WriteUInt16(0);
            GetPlayer().SendPacket(Out);
        }
Beispiel #17
0
        public void SendQuestInProgressInfo(Player Plr, UInt16 QuestID)
        {
            Character_quest Quest = Plr.QtsInterface.GetQuest(QuestID);

            if (Quest == null)
            {
                return;
            }

            PacketOut Out = new PacketOut((byte)Opcodes.F_INTERACT_RESPONSE);

            Out.WriteByte(2);
            Out.WriteByte(1);

            BuildQuestInteract(Out, Quest.QuestID, _Owner.Oid, Plr.Oid);

            BuildQuestInProgress(Out, Quest.Quest, false);

            Plr.SendPacket(Out);
        }
Beispiel #18
0
        public bool AcceptQuest(Quest Quest)
        {
            if (Quest == null)
            {
                return(false);
            }

            if (!CanStartQuest(Quest))
            {
                return(false);
            }

            Character_quest CQuest = new Character_quest();

            CQuest.QuestID     = Quest.Entry;
            CQuest.Done        = false;
            CQuest.CharacterId = GetPlayer().CharacterId;
            CQuest.Quest       = Quest;

            foreach (Quest_Objectives QObj in Quest.Objectives)
            {
                Character_Objectives CObj = new Character_Objectives();
                CObj.Quest       = CQuest;
                CObj._Count      = 0;
                CObj.Objective   = QObj;
                CObj.ObjectiveID = QObj.Guid;
                CQuest._Objectives.Add(CObj);
            }

            CharMgr.Database.AddObject(CQuest);
            _Quests.Add(Quest.Entry, CQuest);

            SendQuestState(Quest, QuestCompletion.QUESTCOMPLETION_OFFER);

            // This will make objects lootable if they contain a quest object.
            updateObjects();

            _Owner.EvtInterface.Notify(EventName.ON_ACCEPT_QUEST, _Owner, CQuest);
            return(true);
        }
Beispiel #19
0
        public void SendQuestDoneInfo(Player Plr, UInt16 QuestID)
        {
            Character_quest Quest = Plr.QtsInterface.GetQuest(QuestID);

            if (Quest == null)
            {
                return;
            }

            PacketOut Out = new PacketOut((byte)Opcodes.F_INTERACT_RESPONSE);

            Out.WriteByte(3);
            Out.WriteByte(0);

            BuildQuestInteract(Out, Quest.QuestID, Obj.Oid, Plr.Oid);

            BuildQuestComplete(Out, Quest.Quest, false);

            BuildQuestRewards(Out, Plr, Quest.Quest);

            Plr.SendPacket(Out);
        }
        public void SendQuestDoneInfo(Player plr, ushort questID)
        {
            Character_quest quest = plr.QtsInterface.GetQuest(questID);

            if (quest == null)
            {
                return;
            }

            PacketOut Out = new PacketOut((byte)Opcodes.F_INTERACT_RESPONSE, 12 + 13 + quest.Quest.Name.Length + quest.Quest.Description.Length);

            Out.WriteByte(3);
            Out.WriteByte(0);

            BuildQuestInteract(Out, quest.QuestID, _Owner.Oid, plr.Oid); // 10

            BuildQuestComplete(Out, quest.Quest, false);

            BuildQuestRewards(Out, plr, quest.Quest);

            plr.SendPacket(Out);
        }
Beispiel #21
0
        public void SendQuest(ushort QuestID)
        {
            Character_quest CQuest = GetQuest(QuestID);

            SendQuest(CQuest);
        }
Beispiel #22
0
        /*private const float DROP_BONUS_CHAMP = 0.2f;
         * private const float DROP_BONUS_HERO = 0.04f;
         *
         * private const float RARITY_COMMON_GEAR = 20f;
         *
         * private static readonly float[] RARITIES = { 5f, 0.4f, 0.02f };
         *
         * private const byte MAX_EASE_IN_LEVEL = 7;*/

        public static LootContainer GenerateLoot(Unit corpse, Unit looter, float dropMod)
        {
            // Declare kill event constants for bitfields
            const byte KILL_EVENT_SCENARIO = 1;
            const byte KILL_EVENT_RVR      = 2;
            const byte KILL_EVENT_PVE      = 4;

            // If the killer isn't a player or a pet, don't bother looting.
            Player player = null;

            if (looter == null)
            {
                return(null);
            }

            if (looter.IsPet())
            {
                player = (looter as Pet).Owner;
            }
            else if (looter.IsPlayer())
            {
                player = looter as Player;
            }

            if (player == null)
            {
                return(null);
            }

            // Initialize lootgroups we'll be searching through
            List <Loot_Group> lootGroups;

            Player deadPlayer = corpse as Player;

            // If the corpse is a player, and you've made it this far, this was a PVP kill
            if (deadPlayer != null)
            {
                List <LootInfo> lootList = new List <LootInfo>();

                uint corpseCareer = (uint)Math.Pow(2, deadPlayer.Info.CareerLine - 1);
                uint corpseLevel  = deadPlayer.AdjustedLevel;
                uint corpseRenown = deadPlayer.AdjustedRenown;

                // Scenario zones all have a war_world.zone_infos.type value of 1.
                // Note - if "1" refers to "instance" instead of "scenario", there could be problems
                // with players receiving scenario-restricted loot for a PVP kill made in an instance
                lootGroups = CreatureService.GetLootGroupsByEvent(deadPlayer.Zone.Info.Type == 1 ? KILL_EVENT_SCENARIO : KILL_EVENT_RVR);

                // This will be our narrowed down list of loot groups that are relevant to the kill in question.
                List <Loot_Group> candidateLootGroups = new List <Loot_Group>();

                // Whittle down the loot groups into a new candidate list, based on the killed player's career,
                // and whether the kill occurred in the correct zone (if any) and whether the player has the required quest (if any)
                foreach (Loot_Group lg in lootGroups)
                {
                    if (lg == null)
                    {
                        continue;
                    }

                    if (lg.ReqActiveQuest > 0)
                    {
                        Character_quest quest = player.QtsInterface.GetQuest(lg.ReqActiveQuest);
                        if (quest == null || quest.IsDone())
                        {
                            continue;
                        }
                    }

                    if ((corpseCareer & lg.CreatureID) != corpseCareer)
                    {
                        continue;
                    }

                    if (lg.SpecificZone != 0 && deadPlayer.Zone.Info.ZoneId != lg.SpecificZone)
                    {
                        continue;
                    }

                    candidateLootGroups.Add(lg);
                }

                // Generate items from remaining loot groups
                foreach (Loot_Group lg in candidateLootGroups)
                {
                    if (lg == null)
                    {
                        continue;
                    }
                    // roll for drops.
                    for (int groupIndex = 0; groupIndex < lg.DropCount; groupIndex++)
                    {
                        float roll = (float)StaticRandom.Instance.Next(0, 10000) / 10000;

                        if (roll <= lg.DropChance)
                        {
                            // Assemble valid drops from the group
                            List <Loot_Group_Item> candidateItems = new List <Loot_Group_Item>();

                            // This whole if is horrible spaghetti, we need to add each new medallion type here
                            if (Constants.DoomsdaySwitch > 0 && lg.Entry == 1 && WorldMgr.WorldSettingsMgr.GetMedallionsSetting() == 1 && looter.GetPlayer().ScnInterface.Scenario == null && deadPlayer.Level > 15)
                            {
                                foreach (Loot_Group_Item lgi in lg.LootGroupItems)
                                {
                                    if (lgi == null)
                                    {
                                        continue;
                                    }
                                    if (deadPlayer.Level < 41 && deadPlayer.RenownRank < 41 && corpseRenown < looter.GetPlayer().RenownRank&& looter.RenownRank > 40)
                                    {
                                        if (lgi.ItemID == 208470 || lgi.ItemID == 208470 || lgi.ItemID == 208470)
                                        {
                                            candidateItems.Add(lgi);
                                        }
                                    }
                                    else
                                    {
                                        if (corpseLevel < lgi.MinRank || corpseLevel > lgi.MaxRank)
                                        {
                                            continue;
                                        }

                                        if (corpseRenown < lgi.MinRenown || corpseRenown > lgi.MaxRenown)
                                        {
                                            continue;
                                        }

                                        Item_Info itemDef = ItemService.GetItem_Info(lgi.ItemID);

                                        if (itemDef.Realm != 0 && itemDef.Realm != (byte)player.Realm)
                                        {
                                            continue;
                                        }

                                        candidateItems.Add(lgi);
                                    }
                                }
                            }
                            else
                            {
                                foreach (Loot_Group_Item lgi in lg.LootGroupItems)
                                {
                                    if (lgi == null)
                                    {
                                        continue;
                                    }

                                    if (corpseLevel < lgi.MinRank || corpseLevel > lgi.MaxRank)
                                    {
                                        continue;
                                    }

                                    if (corpseRenown < lgi.MinRenown || corpseRenown > lgi.MaxRenown)
                                    {
                                        continue;
                                    }

                                    Item_Info itemDef = ItemService.GetItem_Info(lgi.ItemID);

                                    if (itemDef.Realm != 0 && itemDef.Realm != (byte)player.Realm)
                                    {
                                        continue;
                                    }

                                    candidateItems.Add(lgi);
                                }
                            }

                            // If the loot group requires that the dropped loot be usable by a member of
                            // the killer's party, then remove non-compatible loot from the candidate list.
                            if (lg.ReqGroupUsable)
                            {
                                List <Player> members;

                                if (player.PriorityGroup != null)
                                {
                                    members = player.PriorityGroup.GetPlayerListCopy();
                                }
                                else
                                {
                                    members = new List <Player> {
                                        player
                                    };
                                }
                                for (int itemIndex = 0; itemIndex < candidateItems.Count; ++itemIndex)
                                {
                                    bool valid = false;

                                    Item_Info curItem = ItemService.GetItem_Info(candidateItems[itemIndex].ItemID);

                                    foreach (Player member in members)
                                    {
                                        if (!ItemsInterface.CanUse(curItem, member, true, false))
                                        {
                                            continue;
                                        }

                                        // Usable by at least one member
                                        valid = true;
                                        break;
                                    }

                                    if (!valid)
                                    {
                                        candidateItems.RemoveAt(itemIndex);
                                        --itemIndex;
                                    }
                                }
                            }

                            // Now roll for an item from the candidate item list, and add it to the loots.
                            if (candidateItems.Count > 0)
                            {
                                Item_Info winningItem = ItemService.GetItem_Info(candidateItems[StaticRandom.Instance.Next(0, candidateItems.Count)].ItemID);
                                lootList.Add(new LootInfo(winningItem));
                            }
                        }
                    }
                }

                // Generate money as normal, and pass the generated loot back to the system.
                uint money = corpseLevel * 5 + corpseRenown * 5;

                if (lootList.Count > 0 || money > 0)
                {
                    LootContainer lt = new LootContainer
                    {
                        Money    = money,
                        LootInfo = lootList
                    };
                    //corpse.EvtInterface.Notify(EventName.ON_GENERATE_LOOT, looter, Lt);
                    return(lt);
                }
            }

            else if (corpse.IsCreature())
            {
                Creature        deadCreature = corpse.GetCreature();
                List <LootInfo> Loots        = new List <LootInfo>();

                // All creatures are by definition PVE kills
                lootGroups = CreatureService.GetLootGroupsByEvent(KILL_EVENT_PVE);

                // This will be our narrowed down list of loot groups that are relevant to the kill in question.
                List <Loot_Group> candidateLootGroups = new List <Loot_Group>();

                // Whittle down the loot groups into a new candidate list, based on the killed creature's ID,
                // or the CreatureSubType if the loot group's CreatureID is 0.
                foreach (Loot_Group lg in lootGroups)
                {
                    if (lg == null)
                    {
                        continue;
                    }

                    if (lg.ReqActiveQuest != 0 && !player.QtsInterface.HasQuest(lg.ReqActiveQuest))
                    {
                        continue;
                    }
                    if (lg.SpecificZone != 0 && deadCreature.Zone.Info.ZoneId != lg.SpecificZone)
                    {
                        continue;
                    }

                    if (lg.CreatureID != 0)
                    {
                        if (deadCreature.Entry == lg.CreatureID)
                        {
                            candidateLootGroups.Add(lg);
                        }
                    }
                    else
                    {
                        if (lg.CreatureSubType == 0 || CreatureService.GetCreatureProto(deadCreature.Entry).CreatureSubType == lg.CreatureSubType)
                        {
                            candidateLootGroups.Add(lg);
                        }
                    }
                }



                // Generate items from remaining loot groups
                foreach (Loot_Group lg in candidateLootGroups)
                {
                    try
                    {
                        if (lg == null)
                        {
                            continue;
                        }
                        // roll for drops.
                        for (int groupIndex = 0; groupIndex < lg.DropCount; groupIndex++)
                        {
                            float roll = (float)StaticRandom.Instance.Next(0, 10000) / 10000;

                            if (roll <= lg.DropChance)
                            {
                                // Assemble valid drops from the group
                                List <Loot_Group_Item> candidateItems = new List <Loot_Group_Item>();

                                int effectiveLevel = Math.Min(Program.Config.RankCap, deadCreature.Level);

                                if (lg.LootGroupItems != null)
                                {
                                    foreach (Loot_Group_Item lgi in lg.LootGroupItems)
                                    {
                                        try
                                        {
                                            if (lgi == null)
                                            {
                                                continue;
                                            }

                                            if (effectiveLevel < lgi.MinRank || effectiveLevel > lgi.MaxRank)
                                            {
                                                continue;
                                            }

                                            Item_Info itemDef = ItemService.GetItem_Info(lgi.ItemID);

                                            if (itemDef.Realm != 0 && itemDef.Realm != (byte)player.Realm)
                                            {
                                                continue;
                                            }

                                            candidateItems.Add(lgi);
                                        }
                                        catch
                                        {
                                            continue;
                                        }
                                    }
                                }

                                // If the loot group requires that the dropped loot be usable by a member of
                                // the killer's party, then remove non-compatible loot from the candidate list.
                                if (lg.ReqGroupUsable)
                                {
                                    List <Player> members;

                                    if (player.PriorityGroup != null)
                                    {
                                        members = player.PriorityGroup.GetPlayerListCopy();
                                    }
                                    else
                                    {
                                        members = new List <Player> {
                                            player
                                        }
                                    };


                                    for (int itemIndex = 0; itemIndex < candidateItems.Count; ++itemIndex)
                                    {
                                        bool valid = false;

                                        Item_Info curItem = ItemService.GetItem_Info(candidateItems[itemIndex].ItemID);

                                        foreach (Player member in members)
                                        {
                                            if (!ItemsInterface.CanUse(curItem, member, true, false))
                                            {
                                                continue;
                                            }

                                            valid = true;
                                            break;
                                        }

                                        if (!valid)
                                        {
                                            candidateItems.RemoveAt(itemIndex);
                                            --itemIndex;
                                        }
                                    }
                                }

                                // Now roll for an item from the candidate item list, and add it to the loots.
                                if (candidateItems.Count > 0)
                                {
                                    Item_Info winningItem = ItemService.GetItem_Info(candidateItems[StaticRandom.Instance.Next(0, candidateItems.Count)].ItemID);
                                    Loots.Add(new LootInfo(winningItem));
                                }
                            }
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }

                // Generate money as normal, and pass the generated loot back to the system.
                uint money = corpse.Level * (uint)7 + corpse.Rank * (uint)50;

                if (Loots.Count > 0 || money > 0)
                {
                    LootContainer lt = new LootContainer
                    {
                        Money    = money,
                        LootInfo = Loots
                    };
                    //corpse.EvtInterface.Notify(EventName.ON_GENERATE_LOOT, looter, Lt);
                    return(lt);
                }
            }

            else if (corpse.IsGameObject())
            {
                // This will generate gameobject loot. Currently this only shows loot
                // if a player needs an item it holds for a quest. If an object has
                // been looted already or has no loot this will return null.
                // Todo: Currently object loot always is 100%. Make this support non quest related loot.

                GameObject             gameObj         = corpse.GetGameObject();
                List <GameObject_loot> gameObjectLoots = GameObjectService.GetGameObjectLoots(gameObj.Spawn.Entry);
                if (gameObjectLoots.Count <= 0 || gameObj.Looted)
                {
                    return(null);
                }

                QuestsInterface Interface = looter.QtsInterface;

                if (Interface == null)
                {
                    return(null);
                }

                List <LootInfo> lootInfo = new List <LootInfo>();

                foreach (GameObject_loot loot in gameObjectLoots)
                {
                    foreach (KeyValuePair <ushort, Character_quest> kp in Interface.Quests)
                    {
                        if (kp.Value.Done || kp.Value.IsDone())
                        {
                            continue;
                        }

                        foreach (Character_Objectives obj in kp.Value._Objectives)
                        {
                            if (obj.IsDone() || obj.Objective.Item == null || obj.Objective.Item.Entry != loot.ItemId)
                            {
                                continue;
                            }

                            lootInfo.Add(new LootInfo(loot.Info));
                            break;
                        }
                    }
                }

                LootContainer lt = new LootContainer
                {
                    Money    = 0,
                    LootInfo = lootInfo
                };
                return(lt);
            }

            return(null);
        }
Beispiel #23
0
        public static LootContainer GetScenarioLoot(Player player, int scenTier, ZoneMgr zone)
        {
            List <LootInfo> lootList = new List <LootInfo>();

            int corpseLevel  = scenTier * 10;
            int corpseRenown = scenTier * 10;

            // Scenario zones all have a war_world.zone_infos.type value of 1.
            // Note - if "1" refers to "instance" instead of "scenario", there could be problems
            // with players receiving scenario-restricted loot for a PVP kill made in an instance
            List <Loot_Group> lootGroups = CreatureService.GetLootGroupsByEvent(1);

            // This will be our narrowed down list of loot groups that are relevant to the kill in question.
            List <Loot_Group> candidateLootGroups = new List <Loot_Group>();

            // Whittle down the loot groups into a new candidate list, based on the killed player's career,
            // and whether the kill occurred in the correct zone (if any) and whether the player has the required quest (if any)
            foreach (Loot_Group lg in lootGroups)
            {
                if (lg == null)
                {
                    continue;
                }

                if (lg.ReqActiveQuest > 0)
                {
                    Character_quest quest = player.QtsInterface.GetQuest(lg.ReqActiveQuest);
                    if (quest == null || quest.IsDone())
                    {
                        continue;
                    }
                }

                if (lg.SpecificZone != 0 && zone.Info.ZoneId != lg.SpecificZone)
                {
                    continue;
                }

                candidateLootGroups.Add(lg);
            }

            // Generate items from remaining loot groups
            foreach (Loot_Group lg in candidateLootGroups)
            {
                if (lg == null)
                {
                    continue;
                }
                // roll for drops.
                for (int groupIndex = 0; groupIndex < lg.DropCount; groupIndex++)
                {
                    float roll = (float)StaticRandom.Instance.Next(0, 10000) / 10000;

                    if (roll <= lg.DropChance)
                    {
                        // Assemble valid drops from the group
                        List <Loot_Group_Item> candidateItems = new List <Loot_Group_Item>();

                        foreach (Loot_Group_Item lgi in lg.LootGroupItems)
                        {
                            if (lgi == null)
                            {
                                continue;
                            }

                            if (corpseLevel < lgi.MinRank || corpseLevel > lgi.MaxRank)
                            {
                                continue;
                            }

                            if (corpseRenown < lgi.MinRenown || corpseRenown > lgi.MaxRenown)
                            {
                                continue;
                            }

                            Item_Info itemDef = ItemService.GetItem_Info(lgi.ItemID);

                            if (itemDef.Realm != 0 && itemDef.Realm != (byte)player.Realm)
                            {
                                continue;
                            }

                            candidateItems.Add(lgi);
                        }

                        // If the loot group requires that the dropped loot be usable by a member of
                        // the killer's party, then remove non-compatible loot from the candidate list.
                        if (lg.ReqGroupUsable)
                        {
                            List <Player> members;

                            if (player.PriorityGroup != null)
                            {
                                members = player.PriorityGroup.GetPlayerListCopy();
                            }
                            else
                            {
                                members = new List <Player> {
                                    player
                                };
                            }
                            for (int itemIndex = 0; itemIndex < candidateItems.Count; ++itemIndex)
                            {
                                bool valid = false;

                                Item_Info curItem = ItemService.GetItem_Info(candidateItems[itemIndex].ItemID);

                                foreach (Player member in members)
                                {
                                    if (!ItemsInterface.CanUse(curItem, member, true, false))
                                    {
                                        continue;
                                    }

                                    // Usable by at least one member
                                    valid = true;
                                    break;
                                }

                                if (!valid)
                                {
                                    candidateItems.RemoveAt(itemIndex);
                                    --itemIndex;
                                }
                            }
                        }

                        // Now roll for an item from the candidate item list, and add it to the loots.
                        if (candidateItems.Count > 0)
                        {
                            Item_Info winningItem = ItemService.GetItem_Info(candidateItems[StaticRandom.Instance.Next(0, candidateItems.Count)].ItemID);
                            lootList.Add(new LootInfo(winningItem));
                        }
                    }
                }
            }

            return(lootList.Count <= 0 ? null : new LootContainer {
                LootInfo = lootList
            });
        }
        public void SendQuest(ushort questID)
        {
            Character_quest cQuest = GetQuest(questID);

            SendQuest(cQuest);
        }
        public bool DoneQuest(ushort questID)
        {
            Character_quest quest = GetQuest(questID);
            bool            save  = true;

            if (quest == null || !quest.IsDone() || quest.Done)
            {
                return(false);
            }

            Player plr = GetPlayer();

            Dictionary <Item_Info, uint> choices = GenerateRewards(quest.Quest, plr);

            if (quest.Quest.Choice != null && quest.Quest.Choice.Length > 0 && quest.SelectedRewards.Count == 0)
            {
                return(false);
            }

            ushort freeSlots = plr.ItmInterface.GetTotalFreeInventorySlot();

            if (freeSlots < quest.SelectedRewards.Count)
            {
                plr.SendLocalizeString("", ChatLogFilters.CHATLOGFILTERS_USER_ERROR, Localized_text.TEXT_OVERAGE_CANT_SALVAGE);
                return(false);
            }

            foreach (Quest_Objectives obj in quest.Quest.Objectives)
            {
                if ((Objective_Type)obj.ObjType == Objective_Type.QUEST_GET_ITEM ||
                    (Objective_Type)obj.ObjType == Objective_Type.QUEST_USE_ITEM)
                {
                    if (obj.Item != null)
                    {
                        plr.ItmInterface.RemoveQuestItems(obj.Item.Entry);
                    }
                }
                if (quest.Quest.Repeatable)
                {
                    save = false;
                    Quests.Remove(quest.QuestID);
                    SendQuestState(quest.Quest, QuestCompletion.QUESTCOMPLETION_ABANDONED);
                    CharMgr.Database.DeleteObject(quest);

                    // This will make objects unlootable if they were lootable because of a quest.
                    UpdateObjects();

                    // Update quest givers around
                    foreach (Object obje in _Owner.ObjectsInRange)
                    {
                        if (obje.IsCreature())
                        {
                            obje.GetCreature().SendMeTo(_Owner.GetPlayer());
                        }
                    }

                    _Owner.EvtInterface.Notify(EventName.OnAcceptQuest, _Owner, quest);
                }
            }

            byte num = 0;

            foreach (KeyValuePair <Item_Info, uint> kp in choices)
            {
                if (quest.SelectedRewards.Contains(num))
                {
                    plr.ItmInterface.CreateItem(kp.Key, (ushort)kp.Value);
                }
                ++num;
            }

            plr.AddXp(quest.Quest.Xp, false, false);
            plr.AddMoney(quest.Quest.Gold);

            quest.Done  = true;
            quest.Dirty = true;
            quest.SelectedRewards.Clear();
            SendQuestState(quest.Quest, QuestCompletion.QUESTCOMPLETION_DONE);

            if (save)
            {
                CharMgr.Database.SaveObject(quest);
            }


            _Owner.EvtInterface.Notify(EventName.OnDoneQuest, _Owner, quest);
            return(true);
        }
Beispiel #26
0
        public void FinishQuestAndTeleportOutside(ushort Quest)
        {
            foreach (Object inRange in stuffInRange)
            {
                if (inRange != null)
                {
                    Player player = inRange as Player;
                    if (player != null && player.IsPlayer() && player.CbtInterface.IsInCombat)
                    {
                        if (player.QtsInterface.GetQuest(Quest) != null)
                        {
                            Character_quest quest = player.QtsInterface.GetQuest(Quest);

                            foreach (KeyValuePair <ushort, Character_quest> questKp in player.QtsInterface.Quests)
                            {
                                if (questKp.Value == quest)
                                {
                                    foreach (Character_Objectives objective in questKp.Value._Objectives)
                                    {
                                        if (objective.Objective == null)
                                        {
                                            continue;
                                        }

                                        objective.Count     = 1;
                                        questKp.Value.Dirty = true;
                                        player.QtsInterface.SendQuestUpdate(questKp.Value);
                                        CharMgr.Database.SaveObject(questKp.Value);

                                        if (objective.IsDone())
                                        {
                                            Creature finisher;

                                            foreach (Object obj in player.ObjectsInRange)
                                            {
                                                if (obj.IsCreature())
                                                {
                                                    finisher = obj.GetCreature();
                                                    if (QuestService.HasQuestToFinish(finisher.Entry, questKp.Value.Quest.Entry))
                                                    {
                                                        finisher.SendMeTo(player.GetPlayer());
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        var prms = new List <object>()
                        {
                            player
                        };
                        if (!player.IsInvulnerable)
                        {
                            player.EvtInterface.AddEvent(KickPlayerOutside, 1500, 1, prms);
                        }
                    }
                }
            }
        }