From 69a413006c18e19307b9c5139252b41a6d6e1a6b Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 30 Jan 2023 10:14:03 -0500 Subject: [PATCH] Core/Quests: Dont immediately update object visibility at PhaseShift and wait for the AI Hooks to be called in Player::RewardQuest Port From (https://github.com/TrinityCore/TrinityCore/commit/b5886f6a2d1756357a9240703306e9efc82771d7) --- Source/Game/Entities/Player/Player.Quest.cs | 65 ++++++++++++++++++++- Source/Game/Handlers/QuestHandler.cs | 51 ---------------- Source/Game/Phasing/PhasingHandler.cs | 5 +- 3 files changed, 65 insertions(+), 56 deletions(-) diff --git a/Source/Game/Entities/Player/Player.Quest.cs b/Source/Game/Entities/Player/Player.Quest.cs index bf102d9f2..0b79f8ab7 100644 --- a/Source/Game/Entities/Player/Player.Quest.cs +++ b/Source/Game/Entities/Player/Player.Quest.cs @@ -1182,14 +1182,73 @@ namespace Game.Entities UpdatePvPState(); } - SendQuestUpdate(questId); SendQuestGiverStatusMultiple(); + bool conditionChanged = SendQuestUpdate(questId, false); + //lets remove flag for delayed teleports SetCanDelayTeleport(false); + bool canHaveNextQuest = !quest.HasFlag(QuestFlags.AutoComplete) ? !questGiver.IsPlayer() : true; + if (canHaveNextQuest) + { + switch (questGiver.GetTypeId()) + { + case TypeId.Unit: + case TypeId.Player: + { + //For AutoSubmition was added plr case there as it almost same exclute AI script cases. + // Send next quest + Quest nextQuest = GetNextQuest(questGiver.GetGUID(), quest); + if (nextQuest != null) + { + // Only send the quest to the player if the conditions are met + if (CanTakeQuest(nextQuest, false)) + { + if (nextQuest.IsAutoAccept() && CanAddQuest(nextQuest, true)) + AddQuestAndCheckCompletion(nextQuest, questGiver); + + PlayerTalkClass.SendQuestGiverQuestDetails(nextQuest, questGiver.GetGUID(), true, false); + } + } + + PlayerTalkClass.ClearMenus(); + Creature creatureQGiver = questGiver.ToCreature(); + if (creatureQGiver != null) + creatureQGiver.GetAI().OnQuestReward(this, quest, rewardType, rewardId); + break; + } + case TypeId.GameObject: + { + GameObject questGiverGob = questGiver.ToGameObject(); + // Send next quest + Quest nextQuest = GetNextQuest(questGiverGob.GetGUID(), quest); + if (nextQuest != null) + { + // Only send the quest to the player if the conditions are met + if (CanTakeQuest(nextQuest, false)) + { + if (nextQuest.IsAutoAccept() && CanAddQuest(nextQuest, true)) + AddQuestAndCheckCompletion(nextQuest, questGiver); + + PlayerTalkClass.SendQuestGiverQuestDetails(nextQuest, questGiverGob.GetGUID(), true, false); + } + } + + PlayerTalkClass.ClearMenus(); + questGiverGob.GetAI().OnQuestReward(this, quest, rewardType, rewardId); + break; + } + default: + break; + } + } + Global.ScriptMgr.OnQuestStatusChange(this, questId); Global.ScriptMgr.OnQuestStatusChange(this, quest, oldStatus, QuestStatus.Rewarded); + + if (conditionChanged) + UpdateObjectVisibility(); } public void SetRewardedQuest(uint quest_id) @@ -1878,7 +1937,7 @@ namespace Game.Entities SendQuestUpdate(questId); } - void SendQuestUpdate(uint questId) + bool SendQuestUpdate(uint questId, bool updateVisiblity = true) { var saBounds = Global.SpellMgr.GetSpellAreaForQuestMapBounds(questId); if (!saBounds.Empty()) @@ -1926,7 +1985,7 @@ namespace Game.Entities } UpdateVisibleGameobjectsOrSpellClicks(); - PhasingHandler.OnConditionChange(this); + return PhasingHandler.OnConditionChange(this, updateVisiblity); } public QuestGiverStatus GetQuestDialogStatus(WorldObject questgiver) diff --git a/Source/Game/Handlers/QuestHandler.cs b/Source/Game/Handlers/QuestHandler.cs index 4c1150e6b..8d9b84d3f 100644 --- a/Source/Game/Handlers/QuestHandler.cs +++ b/Source/Game/Handlers/QuestHandler.cs @@ -347,57 +347,6 @@ namespace Game bg.HandleQuestComplete(packet.QuestID, _player); 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. - // 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(); - Creature creatureQGiver = obj.ToCreature(); - if (creatureQGiver != null) - creatureQGiver.GetAI().OnQuestReward(_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().OnQuestReward(_player, quest, packet.Choice.LootItemType, packet.Choice.Item.ItemID); - break; - } - default: - break; - } } } else diff --git a/Source/Game/Phasing/PhasingHandler.cs b/Source/Game/Phasing/PhasingHandler.cs index 320c56a95..ac8d19fee 100644 --- a/Source/Game/Phasing/PhasingHandler.cs +++ b/Source/Game/Phasing/PhasingHandler.cs @@ -353,7 +353,7 @@ namespace Game UpdateVisibilityIfNeeded(obj, true, changed); } - public static void OnConditionChange(WorldObject obj) + public static bool OnConditionChange(WorldObject obj, bool updateVisibility = true) { PhaseShift phaseShift = obj.GetPhaseShift(); PhaseShift suppressedPhaseShift = obj.GetSuppressedPhaseShift(); @@ -457,7 +457,8 @@ namespace Game unit.RemoveNotOwnSingleTargetAuras(true); } - UpdateVisibilityIfNeeded(obj, true, changed); + UpdateVisibilityIfNeeded(obj, updateVisibility, changed); + return changed; } public static void SendToPlayer(Player player, PhaseShift phaseShift)