Skip to content

Commit 4fd3669

Browse files
committed
Core/Conditions: Added stringid condition type
(cherry picked from commit 151dd67e2eb22e49ce84c2eb28b08985bcce7602)
1 parent 9e89a4d commit 4fd3669

File tree

3 files changed

+92
-60
lines changed

3 files changed

+92
-60
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE `conditions` DROP PRIMARY KEY;
2+
ALTER TABLE `conditions` ADD `ConditionStringValue1` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' AFTER `ConditionValue3`;
3+
ALTER TABLE `conditions` ADD PRIMARY KEY (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ConditionStringValue1`);

src/server/game/Conditions/ConditionMgr.cpp

Lines changed: 82 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -67,59 +67,65 @@ char const* const ConditionMgr::StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX]
6767

6868
ConditionMgr::ConditionTypeInfo const ConditionMgr::StaticConditionTypeData[CONDITION_MAX] =
6969
{
70-
{ "None", false, false, false },
71-
{ "Aura", true, true, true },
72-
{ "Item Stored", true, true, true },
73-
{ "Item Equipped", true, false, false },
74-
{ "Zone", true, false, false },
75-
{ "Reputation", true, true, false },
76-
{ "Team", true, false, false },
77-
{ "Skill", true, true, false },
78-
{ "Quest Rewarded", true, false, false },
79-
{ "Quest Taken", true, false, false },
80-
{ "Drunken", true, false, false },
81-
{ "WorldState", true, true, false },
82-
{ "Active Event", true, false, false },
83-
{ "Instance Info", true, true, true },
84-
{ "Quest None", true, false, false },
85-
{ "Class", true, false, false },
86-
{ "Race", true, false, false },
87-
{ "Achievement", true, false, false },
88-
{ "Title", true, false, false },
89-
{ "SpawnMask", true, false, false },
90-
{ "Gender", true, false, false },
91-
{ "Unit State", true, false, false },
92-
{ "Map", true, false, false },
93-
{ "Area", true, false, false },
94-
{ "CreatureType", true, false, false },
95-
{ "Spell Known", true, false, false },
96-
{ "PhaseMask", true, false, false },
97-
{ "Level", true, true, false },
98-
{ "Quest Completed", true, false, false },
99-
{ "Near Creature", true, true, true },
100-
{ "Near GameObject", true, true, false },
101-
{ "Object Entry or Guid", true, true, true },
102-
{ "Object TypeMask", true, false, false },
103-
{ "Relation", true, true, false },
104-
{ "Reaction", true, true, false },
105-
{ "Distance", true, true, true },
106-
{ "Alive", false, false, false },
107-
{ "Health Value", true, true, false },
108-
{ "Health Pct", true, true, false },
109-
{ "Realm Achievement", true, false, false },
110-
{ "In Water", false, false, false },
111-
{ "Terrain Swap", false, false, false },
112-
{ "Sit/stand state", true, true, false },
113-
{ "Daily Quest Completed", true, false, false },
114-
{ "Charmed", false, false, false },
115-
{ "Pet type", true, false, false },
116-
{ "On Taxi", false, false, false },
117-
{ "Quest state mask", true, true, false },
118-
{ "Quest objective progress", true, true, true },
119-
{ "Map difficulty", true, false, false },
120-
{ "Is Gamemaster", true, false, false },
121-
{ "Object Entry or Guid", true, true, true },
122-
{ "Object TypeMask", true, false, false }
70+
{ "None", false, false, false, false },
71+
{ "Aura", true, true, true, false },
72+
{ "Item Stored", true, true, true, false },
73+
{ "Item Equipped", true, false, false, false },
74+
{ "Zone", true, false, false, false },
75+
{ "Reputation", true, true, false, false },
76+
{ "Team", true, false, false, false },
77+
{ "Skill", true, true, false, false },
78+
{ "Quest Rewarded", true, false, false, false },
79+
{ "Quest Taken", true, false, false, false },
80+
{ "Drunken", true, false, false, false },
81+
{ "WorldState", true, true, false, false },
82+
{ "Active Event", true, false, false, false },
83+
{ "Instance Info", true, true, true, false },
84+
{ "Quest None", true, false, false, false },
85+
{ "Class", true, false, false, false },
86+
{ "Race", true, false, false, false },
87+
{ "Achievement", true, false, false, false },
88+
{ "Title", true, false, false, false },
89+
{ "SpawnMask", true, false, false, false },
90+
{ "Gender", true, false, false, false },
91+
{ "Unit State", true, false, false, false },
92+
{ "Map", true, false, false, false },
93+
{ "Area", true, false, false, false },
94+
{ "CreatureType", true, false, false, false },
95+
{ "Spell Known", true, false, false, false },
96+
{ "PhaseMask", true, false, false, false },
97+
{ "Level", true, true, false, false },
98+
{ "Quest Completed", true, false, false, false },
99+
{ "Near Creature", true, true, true, false },
100+
{ "Near GameObject", true, true, false, false },
101+
{ "Object Entry or Guid", true, true, true, false },
102+
{ "Object TypeMask", true, false, false, false },
103+
{ "Relation", true, true, false, false },
104+
{ "Reaction", true, true, false, false },
105+
{ "Distance", true, true, true, false },
106+
{ "Alive", false, false, false, false },
107+
{ "Health Value", true, true, false, false },
108+
{ "Health Pct", true, true, false, false },
109+
{ "Realm Achievement", true, false, false, false },
110+
{ "In Water", false, false, false, false },
111+
{ "Terrain Swap", false, false, false, false },
112+
{ "Sit/stand state", true, true, false, false },
113+
{ "Daily Quest Completed", true, false, false, false },
114+
{ "Charmed", false, false, false, false },
115+
{ "Pet type", true, false, false, false },
116+
{ "On Taxi", false, false, false, false },
117+
{ "Quest state mask", true, true, false, false },
118+
{ "Quest objective progress", true, true, true, false },
119+
{ "Map Difficulty", true, false, false, false },
120+
{ "Is Gamemaster", true, false, false, false },
121+
{ "Object Entry or Guid", true, true, true, false },
122+
{ "Object TypeMask", true, false, false, false },
123+
{ "BattlePet Species Learned", true, true, true, false },
124+
{ "On Scenario Step", true, false, false, false },
125+
{ "Scene In Progress", true, false, false, false },
126+
{ "Player Condition", true, false, false, false },
127+
{ "String ID", false, false, false, true },
128+
{ "Label", false, false, false, false },
123129
};
124130

125131
// Checks if object meets the condition
@@ -533,6 +539,14 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo) const
533539
}
534540
break;
535541
}
542+
case CONDITION_STRING_ID:
543+
{
544+
if (Creature const* creature = object->ToCreature())
545+
condMeets = creature->HasStringId(ConditionStringValue1);
546+
else if (GameObject const* go = object->ToGameObject())
547+
condMeets = go->HasStringId(ConditionStringValue1);
548+
break;
549+
}
536550
default:
537551
condMeets = false;
538552
break;
@@ -1079,7 +1093,8 @@ void ConditionMgr::LoadConditions(bool isReload)
10791093
}
10801094

10811095
QueryResult result = WorldDatabase.Query("SELECT SourceTypeOrReferenceId, SourceGroup, SourceEntry, SourceId, ElseGroup, ConditionTypeOrReference, ConditionTarget, "
1082-
" ConditionValue1, ConditionValue2, ConditionValue3, NegativeCondition, ErrorType, ErrorTextId, ScriptName FROM conditions");
1096+
"ConditionValue1, ConditionValue2, ConditionValue3, ConditionStringValue1, "
1097+
"NegativeCondition, ErrorType, ErrorTextId, ScriptName FROM conditions");
10831098

10841099
if (!result)
10851100
{
@@ -1104,10 +1119,11 @@ void ConditionMgr::LoadConditions(bool isReload)
11041119
cond->ConditionValue1 = fields[7].GetUInt32();
11051120
cond->ConditionValue2 = fields[8].GetUInt32();
11061121
cond->ConditionValue3 = fields[9].GetUInt32();
1107-
cond->NegativeCondition = fields[10].GetBool();
1108-
cond->ErrorType = fields[11].GetUInt32();
1109-
cond->ErrorTextId = fields[12].GetUInt32();
1110-
cond->ScriptId = sObjectMgr->GetScriptId(fields[13].GetString());
1122+
cond->ConditionStringValue1 = fields[10].GetString();
1123+
cond->NegativeCondition = fields[11].GetBool();
1124+
cond->ErrorType = fields[12].GetUInt32();
1125+
cond->ErrorTextId = fields[13].GetUInt32();
1126+
cond->ScriptId = sObjectMgr->GetScriptId(fields[14].GetString());
11111127

11121128
if (iConditionTypeOrReference >= 0)
11131129
cond->ConditionType = ConditionTypes(iConditionTypeOrReference);
@@ -2392,15 +2408,22 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond) const
23922408
LogUselessConditionValue(cond, 2, cond->ConditionValue2);
23932409
if (cond->ConditionValue3 && !StaticConditionTypeData[cond->ConditionType].HasConditionValue3)
23942410
LogUselessConditionValue(cond, 3, cond->ConditionValue3);
2411+
if (!cond->ConditionStringValue1.empty() && !StaticConditionTypeData[cond->ConditionType].HasConditionStringValue1)
2412+
LogUselessConditionValue(cond, 1, cond->ConditionStringValue1);
23952413

23962414
return true;
23972415
}
23982416

2399-
void ConditionMgr::LogUselessConditionValue(Condition* cond, uint8 index, uint32 value)
2417+
void ConditionMgr::LogUselessConditionValue(Condition const* cond, uint8 index, uint32 value)
24002418
{
24012419
TC_LOG_ERROR("sql.sql", "{} has useless data in ConditionValue{} ({})!", cond->ToString(true), index, value);
24022420
}
24032421

2422+
void ConditionMgr::LogUselessConditionValue(Condition const* cond, uint8 index, std::string_view value)
2423+
{
2424+
TC_LOG_ERROR("sql.sql", "{} has useless data in ConditionStringValue{} ({})!", cond->ToString(true), index, value);
2425+
}
2426+
24042427
void ConditionMgr::Clean()
24052428
{
24062429
for (ConditionReferenceContainer::iterator itr = ConditionReferenceStore.begin(); itr != ConditionReferenceStore.end(); ++itr)

src/server/game/Conditions/ConditionMgr.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ enum ConditionTypes
9292
CONDITION_SCENARIO_STEP = 54, // ScenarioStepId 0 0 true if player is at scenario with current step equal to ScenarioStepID
9393
CONDITION_SCENE_IN_PROGRESS = 55, // SceneScriptPackageId 0 0 true if player is playing a scene with ScriptPackageId equal to given value
9494
CONDITION_PLAYER_CONDITION = 56, // PlayerConditionId 0 0 true if player satisfies PlayerCondition
95+
CONDITION_PRIVATE_OBJECT = 57, // 0 0 0 true if entity is private object
96+
CONDITION_STRING_ID = 58,
97+
CONDITION_LABEL = 59, // only for master branch
9598
CONDITION_MAX
9699
};
97100

@@ -209,6 +212,7 @@ struct TC_GAME_API Condition
209212
uint32 ConditionValue1;
210213
uint32 ConditionValue2;
211214
uint32 ConditionValue3;
215+
std::string ConditionStringValue1;
212216
uint32 ErrorType;
213217
uint32 ErrorTextId;
214218
uint32 ReferenceId;
@@ -285,6 +289,7 @@ class TC_GAME_API ConditionMgr
285289
bool HasConditionValue1;
286290
bool HasConditionValue2;
287291
bool HasConditionValue3;
292+
bool HasConditionStringValue1;
288293
};
289294
static char const* const StaticSourceTypeData[CONDITION_SOURCE_TYPE_MAX];
290295
static ConditionTypeInfo const StaticConditionTypeData[CONDITION_MAX];
@@ -297,7 +302,8 @@ class TC_GAME_API ConditionMgr
297302
bool addToSpellImplicitTargetConditions(Condition* cond) const;
298303
bool IsObjectMeetToConditionList(ConditionSourceInfo& sourceInfo, ConditionContainer const& conditions) const;
299304

300-
static void LogUselessConditionValue(Condition* cond, uint8 index, uint32 value);
305+
static void LogUselessConditionValue(Condition const* cond, uint8 index, uint32 value);
306+
static void LogUselessConditionValue(Condition const* cond, uint8 index, std::string_view value);
301307

302308
void Clean(); // free up resources
303309
std::vector<Condition*> AllocatedMemoryStore; // some garbage collection :)

0 commit comments

Comments
 (0)