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)
This commit is contained in:
hondacrx
2023-01-30 10:14:03 -05:00
parent 5c2fae99dd
commit 69a413006c
3 changed files with 65 additions and 56 deletions
+62 -3
View File
@@ -1182,14 +1182,73 @@ namespace Game.Entities
UpdatePvPState(); UpdatePvPState();
} }
SendQuestUpdate(questId);
SendQuestGiverStatusMultiple(); SendQuestGiverStatusMultiple();
bool conditionChanged = SendQuestUpdate(questId, false);
//lets remove flag for delayed teleports //lets remove flag for delayed teleports
SetCanDelayTeleport(false); 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, questId);
Global.ScriptMgr.OnQuestStatusChange(this, quest, oldStatus, QuestStatus.Rewarded); Global.ScriptMgr.OnQuestStatusChange(this, quest, oldStatus, QuestStatus.Rewarded);
if (conditionChanged)
UpdateObjectVisibility();
} }
public void SetRewardedQuest(uint quest_id) public void SetRewardedQuest(uint quest_id)
@@ -1878,7 +1937,7 @@ namespace Game.Entities
SendQuestUpdate(questId); SendQuestUpdate(questId);
} }
void SendQuestUpdate(uint questId) bool SendQuestUpdate(uint questId, bool updateVisiblity = true)
{ {
var saBounds = Global.SpellMgr.GetSpellAreaForQuestMapBounds(questId); var saBounds = Global.SpellMgr.GetSpellAreaForQuestMapBounds(questId);
if (!saBounds.Empty()) if (!saBounds.Empty())
@@ -1926,7 +1985,7 @@ namespace Game.Entities
} }
UpdateVisibleGameobjectsOrSpellClicks(); UpdateVisibleGameobjectsOrSpellClicks();
PhasingHandler.OnConditionChange(this); return PhasingHandler.OnConditionChange(this, updateVisiblity);
} }
public QuestGiverStatus GetQuestDialogStatus(WorldObject questgiver) public QuestGiverStatus GetQuestDialogStatus(WorldObject questgiver)
-51
View File
@@ -347,57 +347,6 @@ namespace Game
bg.HandleQuestComplete(packet.QuestID, _player); bg.HandleQuestComplete(packet.QuestID, _player);
GetPlayer().RewardQuest(quest, packet.Choice.LootItemType, packet.Choice.Item.ItemID, obj); 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 else
+3 -2
View File
@@ -353,7 +353,7 @@ namespace Game
UpdateVisibilityIfNeeded(obj, true, changed); UpdateVisibilityIfNeeded(obj, true, changed);
} }
public static void OnConditionChange(WorldObject obj) public static bool OnConditionChange(WorldObject obj, bool updateVisibility = true)
{ {
PhaseShift phaseShift = obj.GetPhaseShift(); PhaseShift phaseShift = obj.GetPhaseShift();
PhaseShift suppressedPhaseShift = obj.GetSuppressedPhaseShift(); PhaseShift suppressedPhaseShift = obj.GetSuppressedPhaseShift();
@@ -457,7 +457,8 @@ namespace Game
unit.RemoveNotOwnSingleTargetAuras(true); unit.RemoveNotOwnSingleTargetAuras(true);
} }
UpdateVisibilityIfNeeded(obj, true, changed); UpdateVisibilityIfNeeded(obj, updateVisibility, changed);
return changed;
} }
public static void SendToPlayer(Player player, PhaseShift phaseShift) public static void SendToPlayer(Player player, PhaseShift phaseShift)