Core/Quests: ported quest flag and visbility update changes from master branch

This commit is contained in:
Ovahlord committed 2023-07-11 15:21:09 +02:00
1 parent 833b77c05e
commit a3dd0d75cf
16 files changed
+282 -278

No files matched your search

+101 -58
View File
@@ -1342,6 +1342,9 @@ void Player::setDeathState(DeathState s)
// passive spell
if (!ressSpellId)
ressSpellId = GetResurrectionSpellId();
FailQuestsWithFlag(QUEST_FLAGS_COMPLETION_NO_DEATH);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DEATH_AT_MAP, 1);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DEATH, 1);
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DEATH_IN_DUNGEON, 1);
@@ -13705,9 +13708,9 @@ void Player::PrepareQuestMenu(ObjectGuid guid)
if (!CanTakeQuest(quest, false))
continue;
if (quest->IsAutoComplete() && (!quest->IsRepeatable() || quest->IsDaily() || quest->IsWeekly() || quest->IsMonthly()))
if (quest->IsTurnIn() && (!quest->IsRepeatable() || quest->IsDaily() || quest->IsWeekly() || quest->IsMonthly()))
qm.AddMenuItem(quest_id, 0);
else if (quest->IsAutoComplete())
else if (quest->IsTurnIn())
qm.AddMenuItem(quest_id, 4);
else if (GetQuestStatus(quest_id) == QUEST_STATUS_NONE)
qm.AddMenuItem(quest_id, 2);
@@ -13745,7 +13748,7 @@ void Player::SendPreparedQuest(ObjectGuid guid)
if (quest->IsAutoAccept() && CanAddQuest(quest, true) && CanTakeQuest(quest, true))
AddQuestAndCheckCompletion(quest, object);
if (quest->IsAutoComplete() && quest->IsRepeatable() && !quest->IsDailyOrWeekly())
if (quest->IsTurnIn() && quest->IsRepeatable() && !quest->IsDailyOrWeekly())
PlayerTalkClass->SendQuestGiverRequestItems(quest, guid, CanCompleteRepeatableQuest(quest), true);
else
{
@@ -13808,48 +13811,30 @@ bool Player::IsActiveQuest(uint32 quest_id) const
return m_QuestStatus.find(quest_id) != m_QuestStatus.end();
}
Quest const* Player::GetNextQuest(ObjectGuid guid, Quest const* quest) const
Quest const* Player::GetNextQuest(Object const* questGiver, Quest const* quest) const
{
QuestRelationResult quests;
uint32 nextQuestID = quest->GetNextQuestInChain();
if (!nextQuestID)
return nullptr;
switch (guid.GetHigh())
if (questGiver == this)
{
case HighGuid::Player:
ASSERT(quest->HasFlag(QUEST_FLAGS_AUTOCOMPLETE));
return sObjectMgr->GetQuestTemplate(nextQuestID);
case HighGuid::Unit:
case HighGuid::Pet:
case HighGuid::Vehicle:
{
if (Creature* creature = ObjectAccessor::GetCreatureOrPetOrVehicle(*this, guid))
quests = sObjectMgr->GetCreatureQuestRelations(creature->GetEntry());
else
return nullptr;
break;
}
case HighGuid::GameObject:
{
//we should obtain map pointer from GetMap() in 99% of cases. Special case
//only for quests which cast teleport spells on player
Map* _map = IsInWorld() ? GetMap() : sMapMgr->FindMap(GetMapId(), GetInstanceId());
ASSERT(_map);
if (GameObject* gameObject = _map->GetGameObject(guid))
quests = sObjectMgr->GetGOQuestRelations(gameObject->GetEntry());
else
return nullptr;
break;
}
default:
if (!quest->HasFlag(QUEST_FLAGS_AUTO_COMPLETE))
return nullptr;
return sObjectMgr->GetQuestTemplate(nextQuestID);
}
// for unit and go state
if (nextQuestID)
if (quests.HasQuest(nextQuestID))
return sObjectMgr->GetQuestTemplate(nextQuestID);
//we should obtain map pointer from GetMap() in 99% of cases. Special case
//only for quests which cast teleport spells on player
if (WorldObject const* worldObjectQuestGiver = dynamic_cast<WorldObject const*>(questGiver))
if (!IsInMap(worldObjectQuestGiver))
return nullptr;
return nullptr;
if (questGiver && !questGiver->hasQuest(nextQuestID))
return nullptr;
return sObjectMgr->GetQuestTemplate(nextQuestID);
}
bool Player::CanSeeStartQuest(Quest const* quest) const
@@ -13914,7 +13899,7 @@ bool Player::CanCompleteQuest(uint32 quest_id)
return false; // not allow re-complete quest
// auto complete quest
if (qInfo->IsAutoComplete() && CanTakeQuest(qInfo, false))
if (qInfo->IsTurnIn() && CanTakeQuest(qInfo, false))
return true;
QuestStatusMap::iterator itr = m_QuestStatus.find(quest_id);
@@ -13934,7 +13919,7 @@ bool Player::CanCompleteQuest(uint32 quest_id)
}
}
if (qInfo->HasSpecialFlag(QUEST_SPECIAL_FLAGS_KILL | QUEST_SPECIAL_FLAGS_CAST | QUEST_SPECIAL_FLAGS_SPEAKTO))
if (qInfo->HasSpecialFlag(QuestSpecialFlags(QUEST_SPECIAL_FLAGS_KILL | QUEST_SPECIAL_FLAGS_CAST | QUEST_SPECIAL_FLAGS_SPEAKTO)))
{
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
{
@@ -13950,7 +13935,7 @@ bool Player::CanCompleteQuest(uint32 quest_id)
if (qInfo->GetPlayersSlain() != 0 && q_status.PlayerCount < qInfo->GetPlayersSlain())
return false;
if (qInfo->HasSpecialFlag(QUEST_SPECIAL_FLAGS_EXPLORATION_OR_EVENT) && !q_status.Explored)
if ((qInfo->HasFlag(QUEST_FLAGS_COMPLETION_EVENT) || qInfo->HasFlag(QUEST_FLAGS_COMPLETION_AREA_TRIGGER)) && !q_status.Explored)
return false;
if (qInfo->HasSpecialFlag(QUEST_SPECIAL_FLAGS_TIMED) && q_status.Timer == 0)
@@ -13994,7 +13979,7 @@ bool Player::CanCompleteRepeatableQuest(Quest const* quest)
bool Player::CanRewardQuest(Quest const* quest, bool msg)
{
// not auto complete quest and not completed quest (only cheating case, then ignore without message)
if (!quest->IsDFQuest() && !quest->IsAutoComplete() && GetQuestStatus(quest->GetQuestId()) != QUEST_STATUS_COMPLETE)
if (!quest->IsDFQuest() && !quest->IsTurnIn() && GetQuestStatus(quest->GetQuestId()) != QUEST_STATUS_COMPLETE)
return false;
// daily quest can't be rewarded (25 daily quest already completed)
@@ -14156,7 +14141,7 @@ void Player::AddQuest(Quest const* quest, Object* questGiver)
questStatusData.ItemCount[i] = 0;
}
if (quest->HasSpecialFlag(QUEST_SPECIAL_FLAGS_KILL | QUEST_SPECIAL_FLAGS_CAST | QUEST_SPECIAL_FLAGS_SPEAKTO))
if (quest->HasSpecialFlag(QuestSpecialFlags(QUEST_SPECIAL_FLAGS_KILL | QUEST_SPECIAL_FLAGS_CAST | QUEST_SPECIAL_FLAGS_SPEAKTO)))
{
for (uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
questStatusData.CreatureOrGOCount[i] = 0;
@@ -14198,6 +14183,17 @@ void Player::AddQuest(Quest const* quest, Object* questGiver)
UpdatePvPState();
}
if (quest->GetSrcSpell() > 0)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(quest->GetSrcSpell());
Unit* caster = this;
if (questGiver && questGiver->isType(TYPEMASK_UNIT) && !quest->HasFlag(QUEST_FLAGS_PLAYER_CAST_ACCEPT) && !spellInfo->HasTargetType(TARGET_UNIT_CASTER) && !spellInfo->HasTargetType(TARGET_DEST_CASTER_SUMMON))
if (Unit* unit = questGiver->ToUnit())
caster = unit;
caster->CastSpell(this, spellInfo->Id, CastSpellExtraArgs(TRIGGERED_FULL_MASK));
}
SetQuestSlot(log_slot, quest_id, qtime);
m_QuestStatusSave[quest_id] = QUEST_DEFAULT_SAVE_TYPE;
@@ -14235,7 +14231,7 @@ void Player::CompleteQuest(uint32 quest_id)
SetQuestSlotState(log_slot, QUEST_STATE_COMPLETE);
if (Quest const* qInfo = sObjectMgr->GetQuestTemplate(quest_id))
if (qInfo->HasFlag(QUEST_FLAGS_TRACKING))
if (qInfo->HasFlag(QUEST_FLAGS_TRACKING_EVENT))
RewardQuest(qInfo, 0, this, false);
}
@@ -14273,14 +14269,16 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
for (uint8 i = 0; i < QUEST_ITEM_OBJECTIVES_COUNT; ++i)
{
if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(quest->RequiredItemId[i]))
if (quest->RequiredItemId[i])
{
if (quest->RequiredItemCount[i] > 0 && itemTemplate->GetBonding() == BIND_QUEST && !quest->IsRepeatable() && !HasQuestForItem(quest->RequiredItemId[i], quest_id, true))
DestroyItemCount(quest->RequiredItemId[i], 9999, true);
else
DestroyItemCount(quest->RequiredItemId[i], quest->RequiredItemCount[i], true);
uint32 amountToDestroy = quest->RequiredItemCount[i];
if (quest->HasFlag(QUEST_FLAGS_REMOVE_SURPLUS_ITEMS))
amountToDestroy = std::numeric_limits<uint32>::max();
DestroyItemCount(quest->RequiredItemId[i], amountToDestroy, true);
}
}
for (uint8 i = 0; i < QUEST_REQUIRED_CURRENCY_COUNT; ++i)
if (quest->RequiredCurrencyId[i])
ModifyCurrency(quest->RequiredCurrencyId[i], -int32(quest->RequiredCurrencyCount[i]));
@@ -14445,7 +14443,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
if (quest->GetRewSpellCast() > 0)
{
SpellInfo const* spellInfo = ASSERT_NOTNULL(sSpellMgr->GetSpellInfo(quest->GetRewSpellCast()));
if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast() && !quest->HasFlag(QUEST_FLAGS_PLAYER_CAST_ON_COMPLETE))
if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast() && !quest->HasFlag(QUEST_FLAGS_PLAYER_CAST_COMPLETE))
{
if (Creature* creature = GetMap()->GetCreature(questGiver->GetGUID()))
creature->CastSpell(this, quest->GetRewSpellCast(), true);
@@ -14456,7 +14454,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
else if (quest->GetRewSpell() > 0)
{
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(quest->GetRewSpell());
if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast() && !quest->HasFlag(QUEST_FLAGS_PLAYER_CAST_ON_COMPLETE))
if (questGiver->isType(TYPEMASK_UNIT) && !spellInfo->HasEffect(SPELL_EFFECT_LEARN_SPELL) && !spellInfo->HasEffect(SPELL_EFFECT_CREATE_ITEM) && !spellInfo->IsSelfCast() && !quest->HasFlag(QUEST_FLAGS_PLAYER_CAST_COMPLETE))
{
if (Creature* creature = GetMap()->GetCreature(questGiver->GetGUID()))
creature->CastSpell(this, quest->GetRewSpell(), true);
@@ -14481,13 +14479,43 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
SendQuestUpdate(quest_id);
bool updateVisibility = false;
if (quest->HasFlag(QUEST_FLAGS_UPDATE_PHASESHIFT))
updateVisibility = PhasingHandler::OnConditionChange(this, false);
//Update QuestGivers
SendQuestGiverStatusMultiple();
//lets remove flag for delayed teleports
SetCanDelayTeleport(false);
if (questGiver && questGiver->isType(TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT))
{
//For AutoSubmition was added plr case there as it almost same exclute AI script cases.
// Send next quest
if (Quest const* nextQuest = GetNextQuest(questGiver, quest))
{
// 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();
if (Creature* creatureQGiver = questGiver->ToCreature())
creatureQGiver->AI()->QuestReward(this, quest, reward);
else if (GameObject* goQGiver = questGiver->ToGameObject())
goQGiver->AI()->QuestReward(this, quest, reward);
}
sScriptMgr->OnQuestStatusChange(this, quest_id);
if (updateVisibility)
UpdateObjectVisibility();
}
void Player::SetRewardedQuest(uint32 quest_id)
@@ -14545,6 +14573,21 @@ void Player::FailQuest(uint32 questId)
}
}
void Player::FailQuestsWithFlag(QuestFlags flag)
{
for (uint16 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot)
{
uint32 questId = GetQuestSlotQuestId(slot);
if (!questId)
continue;
if (Quest const* quest = sObjectMgr->GetQuestTemplate(questId))
if (quest->HasFlag(flag))
FailQuest(questId);
}
}
void Player::AbandonQuest(uint32 questId)
{
if (Quest const* quest = sObjectMgr->GetQuestTemplate(questId))
@@ -15133,7 +15176,7 @@ void Player::SetQuestStatus(uint32 questId, QuestStatus status, bool update /*=
{
m_QuestStatus[questId].Status = status;
if (!quest->IsAutoComplete())
if (!quest->IsTurnIn())
m_QuestStatusSave[questId] = QUEST_DEFAULT_SAVE_TYPE;
}
@@ -15230,7 +15273,6 @@ void Player::SendQuestUpdate(uint32 questId)
}
UpdateVisibleGameobjectsOrSpellClicks();
PhasingHandler::OnConditionChange(this);
}
bool Player::SatisfyFirstLFGReward(uint32 dungeonId, uint8 maxRewCount) const
@@ -15294,7 +15336,7 @@ QuestGiverStatus Player::GetQuestDialogStatus(Object* questgiver)
else if (status == QUEST_STATUS_INCOMPLETE)
result2 = DIALOG_STATUS_INCOMPLETE;
if (quest->IsAutoComplete() && CanTakeQuest(quest, false) && quest->IsRepeatable() && !quest->IsDailyOrWeekly())
if (quest->IsTurnIn() && CanTakeQuest(quest, false) && quest->IsRepeatable() && !quest->IsDailyOrWeekly())
result2 = DIALOG_STATUS_REWARD_REP;
if (result2 > result)
@@ -15335,7 +15377,7 @@ QuestGiverStatus Player::GetQuestDialogStatus(Object* questgiver)
else
result2 = DIALOG_STATUS_LOW_LEVEL_AVAILABLE;
}
else if (quest->IsAutoComplete())
else if (quest->IsTurnIn())
{
if (isNotLowLevelQuest)
result2 = DIALOG_STATUS_REWARD_REP;
@@ -15804,7 +15846,7 @@ void Player::TalkedToCreature(uint32 entry, ObjectGuid guid)
if (q_status.Status == QUEST_STATUS_INCOMPLETE)
{
if (qInfo->HasSpecialFlag(QUEST_SPECIAL_FLAGS_KILL | QUEST_SPECIAL_FLAGS_CAST | QUEST_SPECIAL_FLAGS_SPEAKTO))
if (qInfo->HasSpecialFlag(QuestSpecialFlags(QUEST_SPECIAL_FLAGS_KILL | QUEST_SPECIAL_FLAGS_CAST | QUEST_SPECIAL_FLAGS_SPEAKTO)))
{
for (uint8 j = 0; j < QUEST_OBJECTIVES_COUNT; ++j)
{
@@ -16022,9 +16064,10 @@ void Player::SendQuestReward(Quest const* quest, Creature const* questGiver, uin
if (questGiver)
{
if (questGiver->IsGossip() && quest->HasFlag(QUEST_FLAGS_LAUNCH_GOSSIP_COMPLETE))
packet.LaunchGossip = true;
else if (quest->GetNextQuestInChain() && !quest->HasFlag(QUEST_FLAGS_AUTOCOMPLETE))
if (questGiver->IsGossip())
packet.LaunchGossip = quest->HasFlag(QUEST_FLAGS_LAUNCH_GOSSIP_COMPLETE);
else if (quest->GetNextQuestInChain() && !quest->HasFlag(QUEST_FLAGS_AUTO_COMPLETE))
if (Quest const* rewardQuest = sObjectMgr->GetQuestTemplate(quest->GetNextQuestInChain()))
packet.UseQuestReward = CanTakeQuest(rewardQuest, false);
}