Core/Quest: improve source item deletion logic for items that give quests
Port From (https://github.com/TrinityCore/TrinityCore/commit/558772a0bc7e0d8b768a5b1778a9d598a2288f6f)
This commit is contained in:
@@ -700,7 +700,9 @@ namespace Game.Entities
|
|||||||
Item item = (Item)questGiver;
|
Item item = (Item)questGiver;
|
||||||
Global.ScriptMgr.OnQuestAccept(this, item, quest);
|
Global.ScriptMgr.OnQuestAccept(this, item, quest);
|
||||||
|
|
||||||
// destroy not required for quest finish quest starting item
|
// There are two cases where the source item is not destroyed when the quest is accepted:
|
||||||
|
// - It is required to finish the quest, and is an unique item
|
||||||
|
// - It is the same item present in the source item field (item that would be given on quest accept)
|
||||||
bool destroyItem = true;
|
bool destroyItem = true;
|
||||||
foreach (QuestObjective obj in quest.Objectives)
|
foreach (QuestObjective obj in quest.Objectives)
|
||||||
{
|
{
|
||||||
@@ -711,6 +713,9 @@ namespace Game.Entities
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (quest.SourceItemId == item.GetEntry())
|
||||||
|
destroyItem = false;
|
||||||
|
|
||||||
if (destroyItem)
|
if (destroyItem)
|
||||||
DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
|
DestroyItem(item.GetBagSlot(), item.GetSlot(), true);
|
||||||
|
|
||||||
@@ -1693,6 +1698,11 @@ namespace Game.Entities
|
|||||||
uint srcitem = quest.SourceItemId;
|
uint srcitem = quest.SourceItemId;
|
||||||
if (srcitem > 0)
|
if (srcitem > 0)
|
||||||
{
|
{
|
||||||
|
// Don't give source item if it is the same item used to start the quest
|
||||||
|
ItemTemplate itemTemplate = Global.ObjectMgr.GetItemTemplate(srcitem);
|
||||||
|
if (quest.Id == itemTemplate.GetStartQuest())
|
||||||
|
return true;
|
||||||
|
|
||||||
uint count = quest.SourceItemIdCount;
|
uint count = quest.SourceItemIdCount;
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
count = 1;
|
count = 1;
|
||||||
@@ -1730,10 +1740,9 @@ namespace Game.Entities
|
|||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
count = 1;
|
count = 1;
|
||||||
|
|
||||||
// exist two cases when destroy source quest item not possible:
|
// There are two cases where the source item is not destroyed:
|
||||||
// a) non un-equippable item (equipped non-empty bag, for example)
|
// - Item cannot be unequipped (example: non-empty bags)
|
||||||
// b) when quest is started from an item and item also is needed in
|
// - The source item is the item that started the quest, so the player is supposed to keep it (otherwise it was already destroyed in AddQuestAndCheckCompletion())
|
||||||
// the end as RequiredItemId
|
|
||||||
InventoryResult res = CanUnequipItems(srcItemId, count);
|
InventoryResult res = CanUnequipItems(srcItemId, count);
|
||||||
if (res != InventoryResult.Ok)
|
if (res != InventoryResult.Ok)
|
||||||
{
|
{
|
||||||
@@ -1742,15 +1751,7 @@ namespace Game.Entities
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool destroyItem = true;
|
if (item.GetStartQuest() != questId)
|
||||||
if (item.GetStartQuest() == questId)
|
|
||||||
{
|
|
||||||
foreach (QuestObjective obj in quest.Objectives)
|
|
||||||
if (obj.Type == QuestObjectiveType.Item && srcItemId == obj.ObjectID)
|
|
||||||
destroyItem = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (destroyItem)
|
|
||||||
DestroyItemCount(srcItemId, count, true, true);
|
DestroyItemCount(srcItemId, count, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user