aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQAston <qaston@gmail.com>2012-02-11 15:16:18 +0100
committerQAston <qaston@gmail.com>2012-02-11 15:17:33 +0100
commit784d58c02370ca69764c54a1fdf438ca59e4917a (patch)
tree99dcd9bf1cc942c9ce09cfe066bc7acb44607ab8
parent53458b4508c48a4d3c09950a468401541d1139a3 (diff)
Core/Db/Conditions: Add new condition types:
- CONDITION_OBJECT_ENTRY - CONDITION_TYPE_MASK - CONDITION_RELATION_TO - CONDITION_REACTION_TO - CONDITION_DISTANCE_TO - CONDITION_ALIVE - CONDITION_HP_VAL - CONDITION_HP_PCT
-rwxr-xr-xsrc/server/game/Conditions/ConditionMgr.cpp368
-rwxr-xr-xsrc/server/game/Conditions/ConditionMgr.h121
-rwxr-xr-xsrc/server/game/Entities/Object/Object.h2
3 files changed, 317 insertions, 174 deletions
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp
index 8b785ebaa26..0e8e999bcac 100755
--- a/src/server/game/Conditions/ConditionMgr.cpp
+++ b/src/server/game/Conditions/ConditionMgr.cpp
@@ -217,26 +217,7 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
case CONDITION_LEVEL:
{
if (Unit* unit = object->ToUnit())
- {
- switch (mConditionValue2)
- {
- case LVL_COND_EQ:
- condMeets = unit->getLevel() == mConditionValue1;
- break;
- case LVL_COND_HIGH:
- condMeets = unit->getLevel() > mConditionValue1;
- break;
- case LVL_COND_LOW:
- condMeets = unit->getLevel() < mConditionValue1;
- break;
- case LVL_COND_HIGH_EQ:
- condMeets = unit->getLevel() >= mConditionValue1;
- break;
- case LVL_COND_LOW_EQ:
- condMeets = unit->getLevel() <= mConditionValue1;
- break;
- }
- }
+ condMeets = CompareValues(static_cast<ComparisionType>(mConditionValue2), static_cast<uint32>(unit->getLevel()), mConditionValue1);
break;
}
case CONDITION_DRUNKENSTATE:
@@ -255,6 +236,82 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
condMeets = GetClosestGameObjectWithEntry(object, mConditionValue1, (float)mConditionValue2) ? true : false;
break;
}
+ case CONDITION_OBJECT_ENTRY:
+ {
+ if (object->GetTypeId() == mConditionValue1)
+ condMeets = (!mConditionValue2) || (object->GetEntry() == mConditionValue2);
+ break;
+ }
+ case CONDITION_TYPE_MASK:
+ {
+ condMeets = object->isType(mConditionValue1);
+ break;
+ }
+ case CONDITION_RELATION_TO:
+ {
+ if (WorldObject* toObject = sourceInfo.mConditionTargets[mConditionValue1])
+ {
+ Unit* toUnit = toObject->ToUnit();
+ Unit* unit = object->ToUnit();
+ if (toUnit && unit)
+ {
+ switch (mConditionValue2)
+ {
+ case RELATION_SELF:
+ condMeets = unit == toUnit;
+ break;
+ case RELATION_IN_PARTY:
+ condMeets = unit->IsInPartyWith(toUnit);
+ break;
+ case RELATION_IN_RAID_OR_PARTY:
+ condMeets = unit->IsInRaidWith(toUnit);
+ break;
+ case RELATION_OWNED_BY:
+ condMeets = unit->GetOwnerGUID() == toUnit->GetGUID();
+ break;
+ case RELATION_PASSENGER_OF:
+ condMeets = unit->IsOnVehicle(toUnit);
+ break;
+ }
+ }
+ }
+ break;
+ }
+ case CONDITION_REACTION_TO:
+ {
+ if (WorldObject* toObject = sourceInfo.mConditionTargets[mConditionValue1])
+ {
+ Unit* toUnit = toObject->ToUnit();
+ Unit* unit = object->ToUnit();
+ if (toUnit && unit)
+ condMeets = (1 << unit->GetReactionTo(toUnit)) & mConditionValue2;
+ }
+ break;
+ }
+ case CONDITION_DISTANCE_TO:
+ {
+ if (WorldObject* toObject = sourceInfo.mConditionTargets[mConditionValue1])
+ condMeets = CompareValues(static_cast<ComparisionType>(mConditionValue3), object->GetDistance(toObject), static_cast<float>(mConditionValue2));
+ break;
+ }
+ case CONDITION_ALIVE:
+ {
+ if (Unit* unit = object->ToUnit())
+ condMeets = unit->isAlive();
+ break;
+ }
+ case CONDITION_HP_VAL:
+ {
+ if (Unit* unit = object->ToUnit())
+ condMeets = CompareValues(static_cast<ComparisionType>(mConditionValue2), unit->GetHealth(), static_cast<uint32>(mConditionValue1));
+ break;
+ }
+ case CONDITION_HP_PCT:
+ {
+ if (Unit* unit = object->ToUnit())
+ condMeets = CompareValues(static_cast<ComparisionType>(mConditionValue2), unit->GetHealthPct(), static_cast<float>(mConditionValue1));
+ break;
+ }
default:
condMeets = false;
break;
@@ -270,6 +327,18 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
return condMeets && script;
}
+uint32 Condition::GetMaxAvailableConditionTargets()
+{
+ // returns number of targets which are available for given source type
+ switch(mSourceType)
+ {
+ case CONDITION_SOURCE_TYPE_SPELL:
+ return 2;
+ default:
+ return 1;
+ }
+}
+
ConditionMgr::ConditionMgr()
{
}
@@ -733,12 +802,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_DISENCHANT_LOOT_TEMPLATE:
@@ -756,12 +819,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_FISHING_LOOT_TEMPLATE:
@@ -779,12 +836,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_GAMEOBJECT_LOOT_TEMPLATE:
@@ -802,12 +853,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_ITEM_LOOT_TEMPLATE:
@@ -825,12 +870,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_MAIL_LOOT_TEMPLATE:
@@ -848,12 +887,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_MILLING_LOOT_TEMPLATE:
@@ -871,12 +904,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_PICKPOCKETING_LOOT_TEMPLATE:
@@ -894,12 +921,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_PROSPECTING_LOOT_TEMPLATE:
@@ -917,12 +938,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_REFERENCE_LOOT_TEMPLATE:
@@ -940,12 +955,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_SKINNING_LOOT_TEMPLATE:
@@ -963,12 +972,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_SPELL_LOOT_TEMPLATE:
@@ -986,12 +989,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, does not exist in `item_template`, ignoring.", cond->mSourceType, cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_SPELL_SCRIPT_TARGET:
@@ -1061,12 +1058,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `creature_template`, ignoring.", cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_SPELL:
@@ -1077,12 +1068,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `spell.dbc`, ignoring.", cond->mSourceEntry);
return false;
}
-
- if (cond->mConditionTarget > 2)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_ITEM_REQUIRED_TARGET:
@@ -1127,12 +1112,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
", or the spells are already listed in CONDITION_SOURCE_TYPE_SPELL_SCRIPT_TARGET conditions.", cond->mSourceEntry);
break;
}
-
- if (cond->mConditionTarget > 2)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
}
case CONDITION_SOURCE_TYPE_QUEST_ACCEPT:
@@ -1141,11 +1120,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("CONDITION_SOURCE_TYPE_QUEST_ACCEPT specifies non-existing quest (%u), skipped", cond->mSourceEntry);
return false;
}
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
case CONDITION_SOURCE_TYPE_QUEST_SHOW_MARK:
if (!sObjectMgr->GetQuestTemplate(cond->mSourceEntry))
@@ -1153,11 +1127,6 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("CONDITION_SOURCE_TYPE_QUEST_SHOW_MARK specifies non-existing quest (%u), skipped", cond->mSourceEntry);
return false;
}
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
case CONDITION_SOURCE_TYPE_VEHICLE_SPELL:
if (!sObjectMgr->GetCreatureTemplate(cond->mSourceGroup))
@@ -1171,21 +1140,10 @@ bool ConditionMgr::isSourceTypeValid(Condition* cond)
sLog->outErrorDb("SourceEntry %u in `condition` table, does not exist in `spell.dbc`, ignoring.", cond->mSourceEntry);
return false;
}
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
break;
case CONDITION_SOURCE_TYPE_GOSSIP_MENU:
case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION:
case CONDITION_SOURCE_TYPE_SMART_EVENT:
- if (cond->mConditionTarget)
- {
- sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
- return false;
- }
- break;
case CONDITION_SOURCE_TYPE_NONE:
default:
break;
@@ -1201,6 +1159,12 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond)
return false;
}
+ if (cond->mConditionTarget >= cond->GetMaxAvailableConditionTargets())
+ {
+ sLog->outErrorDb("SourceType %u, SourceEntry %u in `condition` table, has incorrect ConditionTarget set, ignoring.", cond->mSourceType, cond->mSourceEntry);
+ return false;
+ }
+
switch (cond->mConditionType)
{
case CONDITION_AURA:
@@ -1517,7 +1481,7 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond)
}
case CONDITION_LEVEL:
{
- if (cond->mConditionValue2 >= LVL_COND_MAX)
+ if (cond->mConditionValue2 >= COMP_TYPE_MAX)
{
sLog->outErrorDb("Level condition has invalid option (%u), skipped", cond->mConditionValue2);
return false;
@@ -1564,6 +1528,146 @@ bool ConditionMgr::isConditionTypeValid(Condition* cond)
sLog->outErrorDb("NearGameObject condition has useless data in value3 (%u)!", cond->mConditionValue3);
break;
}
+ case CONDITION_OBJECT_ENTRY:
+ {
+ switch (cond->mConditionValue1)
+ {
+ case TYPEID_UNIT:
+ if (cond->mConditionValue2 && !sObjectMgr->GetCreatureTemplate(cond->mConditionValue2))
+ {
+ sLog->outErrorDb("ObjectEntry condition has non existing creature template entry (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ break;
+ case TYPEID_GAMEOBJECT:
+ if (cond->mConditionValue2 && !sObjectMgr->GetGameObjectTemplate(cond->mConditionValue2))
+ {
+ sLog->outErrorDb("ObjectEntry condition has non existing game object template entry (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ break;
+ case TYPEID_PLAYER:
+ case TYPEID_CORPSE:
+ if (cond->mConditionValue2)
+ sLog->outErrorDb("ObjectEntry condition has useless data in value2 (%u)!", cond->mConditionValue2);
+ break;
+ default:
+ sLog->outErrorDb("ObjectEntry condition has wrong typeid set (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue3)
+ sLog->outErrorDb("ObjectEntry condition has useless data in value3 (%u)!", cond->mConditionValue3);
+ break;
+ }
+ case CONDITION_TYPE_MASK:
+ {
+ if (!cond->mConditionValue1 || (cond->mConditionValue1 & ~(TYPEMASK_UNIT | TYPEMASK_PLAYER | TYPEMASK_GAMEOBJECT | TYPEMASK_CORPSE)))
+ {
+ sLog->outErrorDb("TypeMask condition has invalid typemask set (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ if (cond->mConditionValue2)
+ sLog->outErrorDb("TypeMask condition has useless data in value2 (%u)!", cond->mConditionValue2);
+ if (cond->mConditionValue3)
+ sLog->outErrorDb("TypeMask condition has useless data in value3 (%u)!", cond->mConditionValue3);
+ break;
+ }
+ case CONDITION_RELATION_TO:
+ {
+ if (cond->mConditionValue1 >= cond->GetMaxAvailableConditionTargets())
+ {
+ sLog->outErrorDb("RelationTo condition has invalid ConditionValue1(ConditionTarget selection) (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue1 == cond->mConditionTarget)
+ {
+ sLog->outErrorDb("RelationTo condition has ConditionValue1(ConditionTarget selection) set to self (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue2 >= RELATION_MAX)
+ {
+ sLog->outErrorDb("RelationTo condition has invalid ConditionValue2(RelationType) (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ if (cond->mConditionValue3)
+ sLog->outErrorDb("RelationTo condition has useless data in value3 (%u)!", cond->mConditionValue3);
+ break;
+ }
+ case CONDITION_REACTION_TO:
+ {
+ if (cond->mConditionValue1 >= cond->GetMaxAvailableConditionTargets())
+ {
+ sLog->outErrorDb("ReactionTo condition has invalid ConditionValue1(ConditionTarget selection) (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue1 == cond->mConditionTarget)
+ {
+ sLog->outErrorDb("ReactionTo condition has ConditionValue1(ConditionTarget selection) set to self (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (!cond->mConditionValue2)
+ {
+ sLog->outErrorDb("mConditionValue2 condition has invalid ConditionValue2(rankMask) (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ break;
+ }
+ case CONDITION_DISTANCE_TO:
+ {
+ if (cond->mConditionValue1 >= cond->GetMaxAvailableConditionTargets())
+ {
+ sLog->outErrorDb("DistanceTo condition has invalid ConditionValue1(ConditionTarget selection) (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue1 == cond->mConditionTarget)
+ {
+ sLog->outErrorDb("DistanceTo condition has ConditionValue1(ConditionTarget selection) set to self (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue3 >= COMP_TYPE_MAX)
+ {
+ sLog->outErrorDb("DistanceTo condition has invalid ComparisionType (%u), skipped", cond->mConditionValue3);
+ return false;
+ }
+ break;
+ }
+ case CONDITION_ALIVE:
+ {
+ if (cond->mConditionValue1)
+ sLog->outErrorDb("Alive condition has useless data in value1 (%u)!", cond->mConditionValue1);
+ if (cond->mConditionValue2)
+ sLog->outErrorDb("Alive condition has useless data in value2 (%u)!", cond->mConditionValue2);
+ if (cond->mConditionValue3)
+ sLog->outErrorDb("Alive condition has useless data in value3 (%u)!", cond->mConditionValue3);
+ break;
+ }
+ case CONDITION_HP_VAL:
+ {
+ if (cond->mConditionValue2 >= COMP_TYPE_MAX)
+ {
+ sLog->outErrorDb("HpVal condition has invalid ComparisionType (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ if (cond->mConditionValue3)
+ sLog->outErrorDb("HpVal condition has useless data in value3 (%u)!", cond->mConditionValue3);
+ break;
+ }
+ case CONDITION_HP_PCT:
+ {
+ if (cond->mConditionValue1 > 100)
+ {
+ sLog->outErrorDb("HpPct condition has too big percent value (%u), skipped", cond->mConditionValue1);
+ return false;
+ }
+ if (cond->mConditionValue2 >= COMP_TYPE_MAX)
+ {
+ sLog->outErrorDb("HpPct condition has invalid ComparisionType (%u), skipped", cond->mConditionValue2);
+ return false;
+ }
+ if (cond->mConditionValue3)
+ sLog->outErrorDb("HpPct condition has useless data in value3 (%u)!", cond->mConditionValue3);
+ break;
+ }
case CONDITION_AREAID:
case CONDITION_INSTANCE_DATA:
break;
diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h
index aca666c55de..8e133d31a82 100755
--- a/src/server/game/Conditions/ConditionMgr.h
+++ b/src/server/game/Conditions/ConditionMgr.h
@@ -29,49 +29,47 @@ class LootTemplate;
struct Condition;
enum ConditionType
-{ // value1 value2 value3
- CONDITION_NONE = 0, // 0 0 0 always true
- CONDITION_AURA = 1, // spell_id effindex use target? true if player (or target, if value3) has aura of spell_id with effect effindex
- CONDITION_ITEM = 2, // item_id count bank true if has #count of item_ids (if 'bank' is set it searches in bank slots too)
- CONDITION_ITEM_EQUIPPED = 3, // item_id 0 0 true if has item_id equipped
- CONDITION_ZONEID = 4, // zone_id 0 0 true if in zone_id
- CONDITION_REPUTATION_RANK = 5, // faction_id min_rank 0 true if has min_rank for faction_id
- CONDITION_TEAM = 6, // player_team 0, 0 469 - Alliance, 67 - Horde)
- CONDITION_SKILL = 7, // skill_id skill_value 0 true if has skill_value for skill_id
- CONDITION_QUESTREWARDED = 8, // quest_id 0 0 true if quest_id was rewarded before
- CONDITION_QUESTTAKEN = 9, // quest_id 0, 0 true while quest active
- CONDITION_DRUNKENSTATE = 10, // DrunkenState 0, 0 true if player is drunk enough
+{ // value1 value2 value3
+ CONDITION_NONE = 0, // 0 0 0 always true
+ CONDITION_AURA = 1, // spell_id effindex use target? true if player (or target, if value3) has aura of spell_id with effect effindex
+ CONDITION_ITEM = 2, // item_id count bank true if has #count of item_ids (if 'bank' is set it searches in bank slots too)
+ CONDITION_ITEM_EQUIPPED = 3, // item_id 0 0 true if has item_id equipped
+ CONDITION_ZONEID = 4, // zone_id 0 0 true if in zone_id
+ CONDITION_REPUTATION_RANK = 5, // faction_id rankMask 0 true if has min_rank for faction_id
+ CONDITION_TEAM = 6, // player_team 0, 0 469 - Alliance, 67 - Horde)
+ CONDITION_SKILL = 7, // skill_id skill_value 0 true if has skill_value for skill_id
+ CONDITION_QUESTREWARDED = 8, // quest_id 0 0 true if quest_id was rewarded before
+ CONDITION_QUESTTAKEN = 9, // quest_id 0, 0 true while quest active
+ CONDITION_DRUNKENSTATE = 10, // DrunkenState 0, 0 true if player is drunk enough
CONDITION_UNUSED_11 = 11,
- CONDITION_ACTIVE_EVENT = 12, // event_id 0 0 true if event is active
- CONDITION_INSTANCE_DATA = 13, // entry data 0 true if data is set in current instance
- CONDITION_QUEST_NONE = 14, // quest_id 0 0 true if doesn't have quest saved
- CONDITION_CLASS = 15, // class 0 0 true if player's class is equal to class
- CONDITION_RACE = 16, // race 0 0 true if player's race is equal to race
- CONDITION_ACHIEVEMENT = 17, // achievement_id 0 0 true if achievement is complete
+ CONDITION_ACTIVE_EVENT = 12, // event_id 0 0 true if event is active
+ CONDITION_INSTANCE_DATA = 13, // entry data 0 true if data is set in current instance
+ CONDITION_QUEST_NONE = 14, // quest_id 0 0 true if doesn't have quest saved
+ CONDITION_CLASS = 15, // class 0 0 true if player's class is equal to class
+ CONDITION_RACE = 16, // race 0 0 true if player's race is equal to race
+ CONDITION_ACHIEVEMENT = 17, // achievement_id 0 0 true if achievement is complete
CONDITION_SPELL_SCRIPT_TARGET = 18, // SpellScriptTargetType, TargetEntry, 0
- CONDITION_CREATURE_TARGET = 19, // creature entry 0 0 true if current target is creature with value1 entry
- CONDITION_TARGET_HEALTH_BELOW_PCT = 20, // 0-100 0 0 true if target's health is below value1 percent, false if over or no target
- CONDITION_TARGET_RANGE = 21, // minDistance maxDist 0 true if target is closer then minDist and further then maxDist or if max is 0 then max dist is infinit
- CONDITION_MAPID = 22, // map_id 0 0 true if in map_id
- CONDITION_AREAID = 23, // area_id 0 0 true if in area_id
- CONDITION_ITEM_TARGET = 24, // ItemRequiredTargetType, TargetEntry, 0
- CONDITION_SPELL = 25, // spell_id 0 0 true if player has learned spell
+ CONDITION_CREATURE_TARGET = 19, // creature entry 0 0 true if current target is creature with value1 entry
+ CONDITION_TARGET_HEALTH_BELOW_PCT = 20, // 0-100 0 0 true if target's health is below value1 percent, false if over or no target
+ CONDITION_TARGET_RANGE = 21, // minDistance maxDist 0 true if target is closer then minDist and further then maxDist or if max is 0 then max dist is infinit
+ CONDITION_MAPID = 22, // map_id 0 0 true if in map_id
+ CONDITION_AREAID = 23, // area_id 0 0 true if in area_id
+ CONDITION_ITEM_TARGET = 24, // ItemRequiredTargetType, TargetEntry, 0
+ CONDITION_SPELL = 25, // spell_id 0 0 true if player has learned spell
CONDITION_UNUSED_26 = 26,
- CONDITION_LEVEL = 27, // level opt 0 true if unit's level is equal to param1 (param2 can modify the statement)
- CONDITION_QUEST_COMPLETE = 28, // quest_id 0 0 true if player has quest_id with all objectives complete, but not yet rewarded
- CONDITION_NEAR_CREATURE = 29, // creature entry distance 0 true if there is a creature of entry in range
- CONDITION_NEAR_GAMEOBJECT = 30, // gameobject entry distance 0 true if there is a gameobject of entry in range
- CONDITION_MAX = 31 // MAX
-};
-
-enum LevelConditionType
-{
- LVL_COND_EQ,
- LVL_COND_HIGH,
- LVL_COND_LOW,
- LVL_COND_HIGH_EQ,
- LVL_COND_LOW_EQ,
- LVL_COND_MAX
+ CONDITION_LEVEL = 27, // level ComparisonType 0 true if unit's level is equal to param1 (param2 can modify the statement)
+ CONDITION_QUEST_COMPLETE = 28, // quest_id 0 0 true if player has quest_id with all objectives complete, but not yet rewarded
+ CONDITION_NEAR_CREATURE = 29, // creature entry distance 0 true if there is a creature of entry in range
+ CONDITION_NEAR_GAMEOBJECT = 30, // gameobject entry distance 0 true if there is a gameobject of entry in range
+ CONDITION_OBJECT_ENTRY = 31, // TypeID entry 0 true if object is type TypeID and the entry is 0 or matches entry of the object
+ CONDITION_TYPE_MASK = 32, // TypeMask 0 0 true if object is type object's TypeMask matches provided TypeMask
+ CONDITION_RELATION_TO = 33, // ConditionTarget RelationType 0 true if object is in given relation with object specified by ConditionTarget
+ CONDITION_REACTION_TO = 34, // ConditionTarget rankMask 0 true if object's reaction matches rankMask object specified by ConditionTarget
+ CONDITION_DISTANCE_TO = 35, // ConditionTarget distance ComparisonType true if object and ConditionTarget are within distance given by parameters
+ CONDITION_ALIVE = 36, // 0 0 0 true if unit is alive
+ CONDITION_HP_VAL = 37, // hpVal ComparisonType 0 true if unit's hp matches given value
+ CONDITION_HP_PCT = 38, // hpPct ComparisonType 0 true if unit's hp matches given pct
+ CONDITION_MAX = 39 // MAX
};
enum ConditionSourceType
@@ -102,6 +100,26 @@ enum ConditionSourceType
CONDITION_SOURCE_TYPE_MAX = 23 //MAX
};
+enum ComparisionType
+{
+ COMP_TYPE_EQ = 0,
+ COMP_TYPE_HIGH,
+ COMP_TYPE_LOW,
+ COMP_TYPE_HIGH_EQ,
+ COMP_TYPE_LOW_EQ,
+ COMP_TYPE_MAX
+};
+
+enum RelationType
+{
+ RELATION_SELF = 0,
+ RELATION_IN_PARTY,
+ RELATION_IN_RAID_OR_PARTY,
+ RELATION_OWNED_BY,
+ RELATION_PASSENGER_OF,
+ RELATION_MAX
+};
+
enum
{
MAX_CONDITION_TARGETS = 3,
@@ -109,7 +127,7 @@ enum
struct ConditionSourceInfo
{
- WorldObject* mConditionTargets[MAX_CONDITION_TARGETS];
+ WorldObject* mConditionTargets[MAX_CONDITION_TARGETS]; // an array of targets available for conditions
Condition* mLastFailedCondition;
ConditionSourceInfo(WorldObject* target0, WorldObject* target1 = NULL, WorldObject* target2 = NULL)
{
@@ -156,6 +174,7 @@ struct Condition
bool Meets(ConditionSourceInfo& sourceInfo);
bool isLoaded() const { return mConditionType > CONDITION_NONE || mReferenceId; }
+ uint32 GetMaxAvailableConditionTargets();
};
typedef std::list<Condition*> ConditionList;
@@ -221,6 +240,26 @@ class ConditionMgr
SmartEventConditionContainer SmartEventConditionStore;
};
+template <class T> bool CompareValues(ComparisionType type, T val1, T val2)
+{
+ switch (type)
+ {
+ case COMP_TYPE_EQ:
+ return val1 == val2;
+ case COMP_TYPE_HIGH:
+ return val1 > val2;
+ case COMP_TYPE_LOW:
+ return val1 < val2;
+ case COMP_TYPE_HIGH_EQ:
+ return val1 >= val2;
+ case COMP_TYPE_LOW_EQ:
+ return val1 <= val2;
+ }
+ // incorrect parameter
+ ASSERT(false);
+ return false;
+}
+
#define sConditionMgr ACE_Singleton<ConditionMgr, ACE_Null_Mutex>::instance()
#endif
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 4cc298e4349..c14b7599d5f 100755
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -51,7 +51,7 @@ enum TypeMask
TYPEMASK_OBJECT = 0x0001,
TYPEMASK_ITEM = 0x0002,
TYPEMASK_CONTAINER = 0x0006, // TYPEMASK_ITEM | 0x0004
- TYPEMASK_UNIT = 0x0008, //creature or player
+ TYPEMASK_UNIT = 0x0008, // creature
TYPEMASK_PLAYER = 0x0010,
TYPEMASK_GAMEOBJECT = 0x0020,
TYPEMASK_DYNAMICOBJECT = 0x0040,