From 17bfcb77dc0503794c7c2f029d4971c92ffc1041 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Sat, 14 Nov 2020 16:37:18 +0100 Subject: [PATCH] fix(Core/Condition): Implement CONDITION_QUESTSTATE (#3049) --- src/server/game/Conditions/ConditionMgr.cpp | 33 ++++++++++++++++++++- src/server/game/Conditions/ConditionMgr.h | 2 +- src/server/game/Quests/QuestDef.h | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index f41c3d21b..a71b8b050 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -361,6 +361,24 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) condMeets = unit->IsInWater(); break; } + case CONDITION_QUESTSTATE: + { + if (Player* player = object->ToPlayer()) + { + uint32 queststateConditionValue1 = player->GetQuestStatus(ConditionValue1); + if ( + ((ConditionValue2 & (1 << QUEST_STATUS_NONE)) && (queststateConditionValue1 == QUEST_STATUS_NONE)) || + ((ConditionValue2 & (1 << QUEST_STATUS_COMPLETE)) && (queststateConditionValue1 == QUEST_STATUS_COMPLETE)) || + ((ConditionValue2 & (1 << QUEST_STATUS_INCOMPLETE)) && (queststateConditionValue1 == QUEST_STATUS_INCOMPLETE)) || + ((ConditionValue2 & (1 << QUEST_STATUS_FAILED)) && (queststateConditionValue1 == QUEST_STATUS_FAILED)) || + ((ConditionValue2 & (1 << QUEST_STATUS_REWARDED)) && player->GetQuestRewardStatus(ConditionValue1)) + ) + { + condMeets = true; + } + } + break; + } case CONDITION_DAILY_QUEST_DONE: { if (Player* player = object->ToPlayer()) @@ -561,6 +579,9 @@ uint32 Condition::GetSearcherTypeMaskForCondition() case CONDITION_IN_WATER: mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER; break; + case CONDITION_QUESTSTATE: + mask |= GRID_MAP_TYPE_MASK_PLAYER; + break; case CONDITION_DAILY_QUEST_DONE: mask |= GRID_MAP_TYPE_MASK_PLAYER; break; @@ -1633,7 +1654,6 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) case CONDITION_CHARMED: case CONDITION_PET_TYPE: case CONDITION_TAXI: - case CONDITION_QUESTSTATE: sLog->outErrorDb("SourceEntry %u in `condition` table has a ConditionType that is not yet supported on AzerothCore (%u), ignoring.", cond->SourceEntry, uint32(cond->ConditionType)); return false; @@ -1776,11 +1796,22 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) } if (cond->ConditionValue2 > 1) + { sLog->outErrorDb("Quest condition has useless data in value2 (%u)!", cond->ConditionValue2); + } if (cond->ConditionValue3) + { sLog->outErrorDb("Quest condition has useless data in value3 (%u)!", cond->ConditionValue3); + } break; } + case CONDITION_QUESTSTATE: + if (cond->ConditionValue2 >= (1 << MAX_QUEST_STATUS)) + { + sLog->outErrorDb("ConditionType (%u) has invalid state mask (%u), skipped.", cond->ConditionType, cond->ConditionValue2); + return false; + } + break; case CONDITION_ACTIVE_EVENT: { GameEventMgr::GameEventDataMap const& events = sGameEventMgr->GetEventMap(); diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h index 3935260e3..7802240c8 100644 --- a/src/server/game/Conditions/ConditionMgr.h +++ b/src/server/game/Conditions/ConditionMgr.h @@ -68,7 +68,7 @@ enum ConditionTypes CONDITION_CHARMED = 44, // TODO: NOT SUPPORTED YET CONDITION_PET_TYPE = 45, // TODO: NOT SUPPORTED YET CONDITION_TAXI = 46, // TODO: NOT SUPPORTED YET - CONDITION_QUESTSTATE = 47, // TODO: NOT SUPPORTED YET + CONDITION_QUESTSTATE = 47, // quest_id state_mask 0 true if player is in any of the provided quest states for the quest (1 = not taken, 2 = completed, 8 = in progress, 32 = failed, 64 = rewarded) CONDITION_QUEST_OBJECTIVE_PROGRESS = 48, // quest_id objectiveIndex objectiveCount true if player has reached the specified objectiveCount quest progress for the objectiveIndex for the specified quest CONDITION_DIFFICULTY_ID = 49, // don't use on 3.3.5a CONDITION_TC_END = 50, // placeholder diff --git a/src/server/game/Quests/QuestDef.h b/src/server/game/Quests/QuestDef.h index 7e29c7164..a17100848 100644 --- a/src/server/game/Quests/QuestDef.h +++ b/src/server/game/Quests/QuestDef.h @@ -83,7 +83,7 @@ enum QuestTradeSkill QUEST_TRSKILL_JEWELCRAFTING = 14, }; -enum QuestStatus +enum QuestStatus : uint8 { QUEST_STATUS_NONE = 0, QUEST_STATUS_COMPLETE = 1,