diff options
author | ModoX <moardox@gmail.com> | 2022-01-12 21:54:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-12 21:54:03 +0100 |
commit | b987a8968b45b8d5c86ab7e66d3910d2ecfe0963 (patch) | |
tree | 0d6a7abd5f06ff5a79775540793c55248c796704 /src/server/game/Conditions/ConditionMgr.cpp | |
parent | 80014010e7523db33aa561e71e5b483b732160fb (diff) |
Core/Conditions: Added conditions for object visibility (#27565)
Diffstat (limited to 'src/server/game/Conditions/ConditionMgr.cpp')
-rw-r--r-- | src/server/game/Conditions/ConditionMgr.cpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index d9a67f3bcf7..ed23050f57c 100644 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -82,7 +82,8 @@ char const* const ConditionMgr::StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX] "AreaTrigger", "ConversationLine", "AreaTrigger Client Triggered", - "Trainer Spell" + "Trainer Spell", + "Object Visibility (by ID)" }; ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[CONDITION_MAX] = @@ -954,7 +955,8 @@ bool ConditionMgr::CanHaveSourceGroupSet(ConditionSourceType sourceType) sourceType == CONDITION_SOURCE_TYPE_NPC_VENDOR || sourceType == CONDITION_SOURCE_TYPE_PHASE || sourceType == CONDITION_SOURCE_TYPE_AREATRIGGER || - sourceType == CONDITION_SOURCE_TYPE_TRAINER_SPELL); + sourceType == CONDITION_SOURCE_TYPE_TRAINER_SPELL || + sourceType == CONDITION_SOURCE_TYPE_OBJECT_ID_VISIBILITY); } bool ConditionMgr::CanHaveSourceIdSet(ConditionSourceType sourceType) @@ -1096,6 +1098,16 @@ bool ConditionMgr::IsObjectMeetingTrainerSpellConditions(uint32 trainerId, uint3 return true; } +bool ConditionMgr::IsObjectMeetingVisibilityByObjectIdConditions(uint32 objectType, uint32 entry, WorldObject* seer) const +{ + if (ConditionContainer const* conditions = Trinity::Containers::MapGetValuePtr(ObjectVisibilityConditionStore, { objectType, entry })) + { + TC_LOG_DEBUG("condition", "IsObjectMeetingVisibilityByObjectIdConditions: found conditions for objectType %u entry %u", objectType, entry); + return IsObjectMeetToConditions(seer, *conditions); + } + return true; +} + ConditionMgr* ConditionMgr::instance() { static ConditionMgr instance; @@ -1348,6 +1360,13 @@ void ConditionMgr::LoadConditions(bool isReload) ++count; continue; } + case CONDITION_SOURCE_TYPE_OBJECT_ID_VISIBILITY: + { + ObjectVisibilityConditionStore[{ cond->SourceGroup, uint32(cond->SourceEntry) }].push_back(cond); + valid = true; + ++count; + continue; + } default: break; } @@ -1992,6 +2011,37 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond) const } break; } + case CONDITION_SOURCE_TYPE_OBJECT_ID_VISIBILITY: + { + if (cond->SourceGroup <= 0 || cond->SourceGroup >= NUM_CLIENT_OBJECT_TYPES) + { + TC_LOG_ERROR("sql.sql", "%s SourceGroup in `condition` table, is no valid object type, ignoring.", cond->ToString().c_str()); + return false; + } + + if (cond->SourceGroup == TYPEID_UNIT) + { + if (!sObjectMgr->GetCreatureTemplate(cond->SourceEntry)) + { + TC_LOG_ERROR("sql.sql", "%s SourceEntry in `condition` table, does not exist in `creature_template`, ignoring.", cond->ToString().c_str()); + return false; + } + } + else if (cond->SourceGroup == TYPEID_GAMEOBJECT) + { + if (!sObjectMgr->GetGameObjectTemplate(cond->SourceEntry)) + { + TC_LOG_ERROR("sql.sql", "%s SourceEntry in `condition` table, does not exist in `gameobject_template`, ignoring.", cond->ToString().c_str()); + return false; + } + } + else + { + TC_LOG_ERROR("sql.sql", "%s SourceGroup in `condition` table, uses unchecked type id, ignoring.", cond->ToString().c_str()); + return false; + } + break; + } default: TC_LOG_ERROR("sql.sql", "%s Invalid ConditionSourceType in `condition` table, ignoring.", cond->ToString().c_str()); return false; @@ -2585,6 +2635,12 @@ void ConditionMgr::Clean() TrainerSpellConditionContainerStore.clear(); + for (auto&& [_, conditions] : ObjectVisibilityConditionStore) + for (Condition* condition : conditions) + delete condition; + + ObjectVisibilityConditionStore.clear(); + // this is a BIG hack, feel free to fix it if you can figure out the ConditionMgr ;) for (std::vector<Condition*>::const_iterator itr = AllocatedMemoryStore.begin(); itr != AllocatedMemoryStore.end(); ++itr) delete *itr; |