Core/Conditions: Added stringid condition type

This commit is contained in:
Shauren
2024-01-12 12:40:20 +01:00
parent 0b5406dd88
commit 151dd67e2e
3 changed files with 89 additions and 64 deletions

View File

@@ -0,0 +1,3 @@
ALTER TABLE `conditions` DROP PRIMARY KEY;
ALTER TABLE `conditions` ADD `ConditionStringValue1` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' AFTER `ConditionValue3`;
ALTER TABLE `conditions` ADD PRIMARY KEY (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ConditionStringValue1`);

View File

@@ -97,63 +97,64 @@ char const* const ConditionMgr::StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX_D
ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[CONDITION_MAX] = ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[CONDITION_MAX] =
{ {
{ "None", false, false, false }, { "None", false, false, false, false },
{ "Aura", true, true, true }, { "Aura", true, true, true, false },
{ "Item Stored", true, true, true }, { "Item Stored", true, true, true, false },
{ "Item Equipped", true, false, false }, { "Item Equipped", true, false, false, false },
{ "Zone", true, false, false }, { "Zone", true, false, false, false },
{ "Reputation", true, true, false }, { "Reputation", true, true, false, false },
{ "Team", true, false, false }, { "Team", true, false, false, false },
{ "Skill", true, true, false }, { "Skill", true, true, false, false },
{ "Quest Rewarded", true, false, false }, { "Quest Rewarded", true, false, false, false },
{ "Quest Taken", true, false, false }, { "Quest Taken", true, false, false, false },
{ "Drunken", true, false, false }, { "Drunken", true, false, false, false },
{ "WorldState", true, true, false }, { "WorldState", true, true, false, false },
{ "Active Event", true, false, false }, { "Active Event", true, false, false, false },
{ "Instance Info", true, true, true }, { "Instance Info", true, true, true, false },
{ "Quest None", true, false, false }, { "Quest None", true, false, false, false },
{ "Class", true, false, false }, { "Class", true, false, false, false },
{ "Race", true, false, false }, { "Race", true, false, false, false },
{ "Achievement", true, false, false }, { "Achievement", true, false, false, false },
{ "Title", true, false, false }, { "Title", true, false, false, false },
{ "SpawnMask", true, false, false }, { "SpawnMask", true, false, false, false },
{ "Gender", true, false, false }, { "Gender", true, false, false, false },
{ "Unit State", true, false, false }, { "Unit State", true, false, false, false },
{ "Map", true, false, false }, { "Map", true, false, false, false },
{ "Area", true, false, false }, { "Area", true, false, false, false },
{ "CreatureType", true, false, false }, { "CreatureType", true, false, false, false },
{ "Spell Known", true, false, false }, { "Spell Known", true, false, false, false },
{ "Phase", true, false, false }, { "Phase", true, false, false, false },
{ "Level", true, true, false }, { "Level", true, true, false, false },
{ "Quest Completed", true, false, false }, { "Quest Completed", true, false, false, false },
{ "Near Creature", true, true, true }, { "Near Creature", true, true, true, false },
{ "Near GameObject", true, true, false }, { "Near GameObject", true, true, false, false },
{ "Object Entry or Guid", true, true, true }, { "Object Entry or Guid", true, true, true, false },
{ "Object TypeMask", true, false, false }, { "Object TypeMask", true, false, false, false },
{ "Relation", true, true, false }, { "Relation", true, true, false, false },
{ "Reaction", true, true, false }, { "Reaction", true, true, false, false },
{ "Distance", true, true, true }, { "Distance", true, true, true, false },
{ "Alive", false, false, false }, { "Alive", false, false, false, false },
{ "Health Value", true, true, false }, { "Health Value", true, true, false, false },
{ "Health Pct", true, true, false }, { "Health Pct", true, true, false, false },
{ "Realm Achievement", true, false, false }, { "Realm Achievement", true, false, false, false },
{ "In Water", false, false, false }, { "In Water", false, false, false, false },
{ "Terrain Swap", true, false, false }, { "Terrain Swap", true, false, false, false },
{ "Sit/stand state", true, true, false }, { "Sit/stand state", true, true, false, false },
{ "Daily Quest Completed", true, false, false }, { "Daily Quest Completed", true, false, false, false },
{ "Charmed", false, false, false }, { "Charmed", false, false, false, false },
{ "Pet type", true, false, false }, { "Pet type", true, false, false, false },
{ "On Taxi", false, false, false }, { "On Taxi", false, false, false, false },
{ "Quest state mask", true, true, false }, { "Quest state mask", true, true, false, false },
{ "Quest objective progress", true, false, true }, { "Quest objective progress", true, false, true, false },
{ "Map Difficulty", true, false, false }, { "Map Difficulty", true, false, false, false },
{ "Is Gamemaster", true, false, false }, { "Is Gamemaster", true, false, false, false },
{ "Object Entry or Guid", true, true, true }, { "Object Entry or Guid", true, true, true, false },
{ "Object TypeMask", true, false, false }, { "Object TypeMask", true, false, false, false },
{ "BattlePet Species Learned", true, true, true }, { "BattlePet Species Learned", true, true, true, false },
{ "On Scenario Step", true, false, false }, { "On Scenario Step", true, false, false, false },
{ "Scene In Progress", true, false, false }, { "Scene In Progress", true, false, false, false },
{ "Player Condition", true, false, false }, { "Player Condition", true, false, false, false },
{ "String ID", false, false, false, true }
}; };
ConditionSourceInfo::ConditionSourceInfo(WorldObject const* target0, WorldObject const* target1, WorldObject const* target2) ConditionSourceInfo::ConditionSourceInfo(WorldObject const* target0, WorldObject const* target1, WorldObject const* target2)
@@ -665,6 +666,14 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) const
condMeets = !object->GetPrivateObjectOwner().IsEmpty(); condMeets = !object->GetPrivateObjectOwner().IsEmpty();
break; break;
} }
case CONDITION_STRING_ID:
{
if (Creature const* creature = object->ToCreature())
condMeets = creature->HasStringId(ConditionStringValue1);
else if (GameObject const* go = object->ToGameObject())
condMeets = go->HasStringId(ConditionStringValue1);
break;
}
default: default:
break; break;
} }
@@ -1259,7 +1268,8 @@ void ConditionMgr::LoadConditions(bool isReload)
} }
QueryResult result = WorldDatabase.Query("SELECT SourceTypeOrReferenceId, SourceGroup, SourceEntry, SourceId, ElseGroup, ConditionTypeOrReference, ConditionTarget, " QueryResult result = WorldDatabase.Query("SELECT SourceTypeOrReferenceId, SourceGroup, SourceEntry, SourceId, ElseGroup, ConditionTypeOrReference, ConditionTarget, "
" ConditionValue1, ConditionValue2, ConditionValue3, NegativeCondition, ErrorType, ErrorTextId, ScriptName FROM conditions"); "ConditionValue1, ConditionValue2, ConditionValue3, ConditionStringValue1, "
"NegativeCondition, ErrorType, ErrorTextId, ScriptName FROM conditions");
if (!result) if (!result)
{ {
@@ -1292,10 +1302,11 @@ void ConditionMgr::LoadConditions(bool isReload)
cond.ConditionValue1 = fields[7].GetUInt32(); cond.ConditionValue1 = fields[7].GetUInt32();
cond.ConditionValue2 = fields[8].GetUInt32(); cond.ConditionValue2 = fields[8].GetUInt32();
cond.ConditionValue3 = fields[9].GetUInt32(); cond.ConditionValue3 = fields[9].GetUInt32();
cond.NegativeCondition = fields[10].GetBool(); cond.ConditionStringValue1 = fields[10].GetString();
cond.ErrorType = fields[11].GetUInt32(); cond.NegativeCondition = fields[11].GetBool();
cond.ErrorTextId = fields[12].GetUInt32(); cond.ErrorType = fields[12].GetUInt32();
cond.ScriptId = sObjectMgr->GetScriptId(fields[13].GetString()); cond.ErrorTextId = fields[13].GetUInt32();
cond.ScriptId = sObjectMgr->GetScriptId(fields[14].GetString());
if (iConditionTypeOrReference >= 0) if (iConditionTypeOrReference >= 0)
cond.ConditionType = ConditionTypes(iConditionTypeOrReference); cond.ConditionType = ConditionTypes(iConditionTypeOrReference);
@@ -2692,15 +2703,22 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) const
LogUselessConditionValue(cond, 2, cond->ConditionValue2); LogUselessConditionValue(cond, 2, cond->ConditionValue2);
if (cond->ConditionValue3 && !StaticConditionTypeData[cond->ConditionType].HasConditionValue3) if (cond->ConditionValue3 && !StaticConditionTypeData[cond->ConditionType].HasConditionValue3)
LogUselessConditionValue(cond, 3, cond->ConditionValue3); LogUselessConditionValue(cond, 3, cond->ConditionValue3);
if (!cond->ConditionStringValue1.empty() && !StaticConditionTypeData[cond->ConditionType].HasConditionStringValue1)
LogUselessConditionValue(cond, 1, cond->ConditionStringValue1);
return true; return true;
} }
void ConditionMgr::LogUselessConditionValue(Condition* cond, uint8 index, uint32 value) void ConditionMgr::LogUselessConditionValue(Condition const* cond, uint8 index, uint32 value)
{ {
TC_LOG_ERROR("sql.sql", "{} has useless data in ConditionValue{} ({})!", cond->ToString(true), index, value); TC_LOG_ERROR("sql.sql", "{} has useless data in ConditionValue{} ({})!", cond->ToString(true), index, value);
} }
void ConditionMgr::LogUselessConditionValue(Condition const* cond, uint8 index, std::string_view value)
{
TC_LOG_ERROR("sql.sql", "{} has useless data in ConditionStringValue{} ({})!", cond->ToString(true), index, value);
}
void ConditionMgr::Clean() void ConditionMgr::Clean()
{ {
for (std::unordered_map<ConditionId, std::shared_ptr<std::vector<Condition>>>& conditionsMap : ConditionStore) for (std::unordered_map<ConditionId, std::shared_ptr<std::vector<Condition>>>& conditionsMap : ConditionStore)

View File

@@ -116,6 +116,7 @@ enum ConditionTypes
CONDITION_SCENE_IN_PROGRESS = 55, // SceneScriptPackageId 0 0 true if player is playing a scene with ScriptPackageId equal to given value CONDITION_SCENE_IN_PROGRESS = 55, // SceneScriptPackageId 0 0 true if player is playing a scene with ScriptPackageId equal to given value
CONDITION_PLAYER_CONDITION = 56, // PlayerConditionId 0 0 true if player satisfies PlayerCondition CONDITION_PLAYER_CONDITION = 56, // PlayerConditionId 0 0 true if player satisfies PlayerCondition
CONDITION_PRIVATE_OBJECT = 57, // 0 0 0 true if entity is private object CONDITION_PRIVATE_OBJECT = 57, // 0 0 0 true if entity is private object
CONDITION_STRING_ID = 58,
CONDITION_MAX CONDITION_MAX
}; };
@@ -251,6 +252,7 @@ struct TC_GAME_API Condition
uint32 ConditionValue1; uint32 ConditionValue1;
uint32 ConditionValue2; uint32 ConditionValue2;
uint32 ConditionValue3; uint32 ConditionValue3;
std::string ConditionStringValue1;
uint32 ErrorType; uint32 ErrorType;
uint32 ErrorTextId; uint32 ErrorTextId;
uint32 ReferenceId; uint32 ReferenceId;
@@ -335,6 +337,7 @@ class TC_GAME_API ConditionMgr
bool HasConditionValue1; bool HasConditionValue1;
bool HasConditionValue2; bool HasConditionValue2;
bool HasConditionValue3; bool HasConditionValue3;
bool HasConditionStringValue1;
}; };
static char const* const StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX_DB_ALLOWED]; static char const* const StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX_DB_ALLOWED];
static ConditionTypeInfo const StaticConditionTypeData[CONDITION_MAX]; static ConditionTypeInfo const StaticConditionTypeData[CONDITION_MAX];
@@ -349,7 +352,8 @@ class TC_GAME_API ConditionMgr
void addToGraveyardData(ConditionId const& id, std::shared_ptr<std::vector<Condition>> conditions) const; void addToGraveyardData(ConditionId const& id, std::shared_ptr<std::vector<Condition>> conditions) const;
bool IsObjectMeetToConditionList(ConditionSourceInfo& sourceInfo, ConditionContainer const& conditions) const; bool IsObjectMeetToConditionList(ConditionSourceInfo& sourceInfo, ConditionContainer const& conditions) const;
static void LogUselessConditionValue(Condition* cond, uint8 index, uint32 value); static void LogUselessConditionValue(Condition const* cond, uint8 index, uint32 value);
static void LogUselessConditionValue(Condition const* cond, uint8 index, std::string_view value);
void Clean(); // free up resources void Clean(); // free up resources