2010-10-07 15:35:36 +02:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2010-10-07 15:35:36 +02:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2010-06-04 23:24:48 +02:00
*/
2012-11-20 12:30:30 +01:00
#include "ConditionMgr.h"
2012-11-20 16:01:31 +01:00
#include "AchievementMgr.h"
2017-05-21 23:18:43 +02:00
#include "Containers.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
2017-06-04 01:00:45 +02:00
#include "DB2Stores.h"
2010-06-04 23:24:48 +02:00
#include "GameEventMgr.h"
2017-05-20 00:09:37 +02:00
#include "GameObject.h"
2018-10-23 16:20:45 +02:00
#include "GameTime.h"
2016-01-03 00:40:18 +01:00
#include "Group.h"
2010-08-08 22:54:58 +06:00
#include "InstanceScript.h"
2017-06-04 01:00:45 +02:00
#include "Item.h"
2021-03-30 02:27:50 +03:00
#include "LanguageMgr.h"
2019-11-14 00:38:43 +01:00
#include "LFGMgr.h"
2017-05-18 23:52:58 +02:00
#include "Log.h"
#include "LootMgr.h"
2017-06-04 01:00:45 +02:00
#include "Map.h"
2012-11-20 12:30:30 +01:00
#include "ObjectMgr.h"
2018-01-28 11:37:20 +01:00
#include "PhasingHandler.h"
2012-11-20 12:30:30 +01:00
#include "Player.h"
2016-08-06 20:20:07 +02:00
#include "Pet.h"
2020-03-30 19:06:11 +02:00
#include "RaceMask.h"
2018-10-23 16:20:45 +02:00
#include "Realm.h"
2012-11-20 12:30:30 +01:00
#include "ReputationMgr.h"
#include "ScriptMgr.h"
#include "SpellAuras.h"
#include "SpellMgr.h"
2017-05-21 23:18:43 +02:00
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2018-10-23 16:20:45 +02:00
#include <random>
2020-09-04 13:38:24 +02:00
#include <sstream>
2010-06-04 23:24:48 +02:00
2015-10-25 12:22:53 +01:00
char const * const ConditionMgr :: StaticSourceTypeData [ CONDITION_SOURCE_TYPE_MAX ] =
2014-11-20 13:55:26 +01:00
{
"None" ,
"Creature Loot" ,
"Disenchant Loot" ,
"Fishing Loot" ,
"GameObject Loot" ,
"Item Loot" ,
"Mail Loot" ,
"Milling Loot" ,
"Pickpocketing Loot" ,
"Prospecting Loot" ,
"Reference Loot" ,
"Skinning Loot" ,
"Spell Loot" ,
"Spell Impl. Target" ,
"Gossip Menu" ,
"Gossip Menu Option" ,
"Creature Vehicle" ,
"Spell Expl. Target" ,
"Spell Click Event" ,
2017-11-05 12:33:07 +01:00
"Quest Available" ,
"Unused" ,
2014-11-20 13:55:26 +01:00
"Vehicle Spell" ,
"SmartScript" ,
"Npc Vendor" ,
"Spell Proc" ,
2015-03-30 16:08:48 +02:00
"Terrain Swap" ,
"Phase"
2014-11-20 13:55:26 +01:00
};
ConditionMgr :: ConditionTypeInfo const ConditionMgr :: StaticConditionTypeData [ CONDITION_MAX ] =
{
{ "None" , false , false , false },
{ "Aura" , true , true , true },
{ "Item Stored" , true , true , true },
{ "Item Equipped" , true , false , false },
{ "Zone" , true , false , false },
{ "Reputation" , true , true , false },
{ "Team" , true , false , false },
{ "Skill" , true , true , false },
{ "Quest Rewarded" , true , false , false },
{ "Quest Taken" , true , false , false },
{ "Drunken" , true , false , false },
{ "WorldState" , true , true , false },
{ "Active Event" , true , false , false },
{ "Instance Info" , true , true , true },
{ "Quest None" , true , false , false },
{ "Class" , true , false , false },
{ "Race" , true , false , false },
{ "Achievement" , true , false , false },
{ "Title" , true , false , false },
{ "SpawnMask" , true , false , false },
{ "Gender" , true , false , false },
{ "Unit State" , true , false , false },
{ "Map" , true , false , false },
{ "Area" , true , false , false },
{ "CreatureType" , true , false , false },
{ "Spell Known" , true , false , false },
{ "Phase" , true , false , false },
{ "Level" , true , true , false },
{ "Quest Completed" , true , false , false },
2015-12-03 21:37:33 +01:00
{ "Near Creature" , true , true , true },
2014-11-20 13:55:26 +01:00
{ "Near GameObject" , true , true , false },
{ "Object Entry or Guid" , true , true , true },
{ "Object TypeMask" , true , false , false },
{ "Relation" , true , true , false },
{ "Reaction" , true , true , false },
{ "Distance" , true , true , true },
{ "Alive" , false , false , false },
{ "Health Value" , true , true , false },
2015-03-30 16:08:48 +02:00
{ "Health Pct" , true , true , false },
{ "Realm Achievement" , true , false , false },
2015-04-18 17:11:03 +02:00
{ "In Water" , false , false , false },
2016-02-25 19:00:20 +01:00
{ "Terrain Swap" , true , false , false },
2016-07-16 21:10:54 +02:00
{ "Sit/stand state" , true , true , false },
2016-08-06 17:08:52 +02:00
{ "Daily Quest Completed" , true , false , false },
2016-08-06 20:20:07 +02:00
{ "Charmed" , false , false , false },
2016-08-20 14:36:26 +02:00
{ "Pet type" , true , false , false },
2016-09-09 17:14:34 +02:00
{ "On Taxi" , false , false , false },
2017-03-20 08:54:29 +01:00
{ "Quest state mask" , true , true , false },
2018-09-15 17:55:26 +02:00
{ "Objective Complete" , true , false , false },
2019-07-21 17:12:34 +02:00
{ "Map Difficulty" , true , false , false },
{ nullptr , false , false , false },
{ "Object Entry or Guid" , true , true , true },
{ "Object TypeMask" , true , false , false },
2014-11-20 13:55:26 +01:00
};
2012-02-10 14:18:59 +01:00
// Checks if object meets the condition
2012-08-14 01:57:42 +02:00
// Can have CONDITION_SOURCE_TYPE_NONE && !mReferenceId if called from a special event (ie: SmartAI)
2015-10-25 12:22:53 +01:00
bool Condition :: Meets ( ConditionSourceInfo & sourceInfo ) const
2010-06-10 20:52:15 +02:00
{
2012-02-14 12:46:26 -05:00
ASSERT ( ConditionTarget < MAX_CONDITION_TARGETS );
WorldObject * object = sourceInfo . mConditionTargets [ ConditionTarget ];
2012-02-10 14:18:59 +01:00
// object not present, return false
if ( ! object )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_DEBUG ( "condition" , "Condition object not found for %s" , ToString (). c_str ());
2012-02-10 14:18:59 +01:00
return false ;
2010-06-04 23:24:48 +02:00
}
bool condMeets = false ;
2012-02-14 12:46:26 -05:00
switch ( ConditionType )
2010-06-04 23:24:48 +02:00
{
case CONDITION_NONE :
condMeets = true ; // empty condition, always met
break ;
case CONDITION_AURA :
2012-02-10 14:18:59 +01:00
{
if ( Unit * unit = object -> ToUnit ())
2012-02-16 13:16:43 +01:00
condMeets = unit -> HasAuraEffect ( ConditionValue1 , ConditionValue2 );
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_ITEM :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-02-10 16:47:22 +01:00
{
// don't allow 0 items (it's checked during table load)
2012-02-14 12:46:26 -05:00
ASSERT ( ConditionValue2 );
bool checkBank = ConditionValue3 ? true : false ;
condMeets = player -> HasItemCount ( ConditionValue1 , ConditionValue2 , checkBank );
2012-02-10 16:47:22 +01:00
}
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_ITEM_EQUIPPED :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-02-14 12:46:26 -05:00
condMeets = player -> HasItemOrGemWithIdEquipped ( ConditionValue1 , 1 );
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_ZONEID :
2012-02-14 12:46:26 -05:00
condMeets = object -> GetZoneId () == ConditionValue1 ;
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_REPUTATION_RANK :
{
2012-02-10 14:18:59 +01:00
if ( Player * player = object -> ToPlayer ())
{
2012-02-14 12:46:26 -05:00
if ( FactionEntry const * faction = sFactionStore . LookupEntry ( ConditionValue1 ))
2014-07-17 15:42:57 +02:00
condMeets = ( ConditionValue2 & ( 1 << player -> GetReputationMgr (). GetRank ( faction ))) != 0 ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
break ;
}
case CONDITION_ACHIEVEMENT :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-09-18 14:29:53 +02:00
condMeets = player -> HasAchieved ( ConditionValue1 );
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_TEAM :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-02-14 12:46:26 -05:00
condMeets = player -> GetTeam () == ConditionValue1 ;
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_CLASS :
2012-02-10 14:18:59 +01:00
{
2012-02-21 20:03:27 +01:00
if ( Unit * unit = object -> ToUnit ())
2014-07-17 15:42:57 +02:00
condMeets = ( unit -> getClassMask () & ConditionValue1 ) != 0 ;
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_RACE :
2012-02-10 14:18:59 +01:00
{
2012-02-21 20:03:27 +01:00
if ( Unit * unit = object -> ToUnit ())
2020-03-30 19:06:11 +02:00
condMeets = Trinity :: RaceMask < uint32 > { ConditionValue1 }. HasRace ( unit -> getRace ());
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2012-11-26 14:34:23 -05:00
case CONDITION_GENDER :
{
if ( Player * player = object -> ToPlayer ())
condMeets = player -> getGender () == ConditionValue1 ;
break ;
}
2010-06-04 23:24:48 +02:00
case CONDITION_SKILL :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-02-14 12:46:26 -05:00
condMeets = player -> HasSkill ( ConditionValue1 ) && player -> GetBaseSkillValue ( ConditionValue1 ) >= ConditionValue2 ;
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_QUESTREWARDED :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-02-29 13:55:57 +01:00
condMeets = player -> GetQuestRewardStatus ( ConditionValue1 );
2010-06-04 23:24:48 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_QUESTTAKEN :
{
2012-02-10 14:18:59 +01:00
if ( Player * player = object -> ToPlayer ())
{
2012-02-14 12:46:26 -05:00
QuestStatus status = player -> GetQuestStatus ( ConditionValue1 );
2012-02-29 13:55:57 +01:00
condMeets = ( status == QUEST_STATUS_INCOMPLETE );
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
break ;
}
2010-10-24 21:44:58 +02:00
case CONDITION_QUEST_COMPLETE :
{
2012-02-10 14:18:59 +01:00
if ( Player * player = object -> ToPlayer ())
{
2012-02-14 12:46:26 -05:00
QuestStatus status = player -> GetQuestStatus ( ConditionValue1 );
2012-02-29 13:55:57 +01:00
condMeets = ( status == QUEST_STATUS_COMPLETE && ! player -> GetQuestRewardStatus ( ConditionValue1 ));
2012-02-10 14:18:59 +01:00
}
2010-10-24 21:44:58 +02:00
break ;
}
2010-06-04 23:24:48 +02:00
case CONDITION_QUEST_NONE :
{
2012-02-10 14:18:59 +01:00
if ( Player * player = object -> ToPlayer ())
{
2012-02-14 12:46:26 -05:00
QuestStatus status = player -> GetQuestStatus ( ConditionValue1 );
2012-02-29 13:55:57 +01:00
condMeets = ( status == QUEST_STATUS_NONE );
2012-02-10 14:18:59 +01:00
}
2010-06-04 23:24:48 +02:00
break ;
}
case CONDITION_ACTIVE_EVENT :
2012-02-14 12:46:26 -05:00
condMeets = sGameEventMgr -> IsActiveEvent ( ConditionValue1 );
2010-06-04 23:24:48 +02:00
break ;
2012-12-30 16:03:25 -05:00
case CONDITION_INSTANCE_INFO :
2010-06-04 23:24:48 +02:00
{
2012-02-10 14:18:59 +01:00
Map * map = object -> GetMap ();
2015-10-04 14:53:05 +02:00
if ( map -> IsDungeon ())
2012-12-30 16:03:25 -05:00
{
if ( InstanceScript const * instance = (( InstanceMap * ) map ) -> GetInstanceScript ())
{
switch ( ConditionValue3 )
{
case INSTANCE_INFO_DATA :
condMeets = instance -> GetData ( ConditionValue1 ) == ConditionValue2 ;
break ;
2014-10-23 17:01:26 +02:00
//case INSTANCE_INFO_GUID_DATA:
// condMeets = instance->GetGuidData(ConditionValue1) == ObjectGuid(uint64(ConditionValue2));
// break;
2012-12-30 16:03:25 -05:00
case INSTANCE_INFO_BOSS_STATE :
2012-12-31 20:43:14 +01:00
condMeets = instance -> GetBossState ( ConditionValue1 ) == EncounterState ( ConditionValue2 );
2012-12-30 16:03:25 -05:00
break ;
2014-09-14 23:23:23 +02:00
case INSTANCE_INFO_DATA64 :
condMeets = instance -> GetData64 ( ConditionValue1 ) == ConditionValue2 ;
break ;
2012-12-30 16:03:25 -05:00
}
}
}
2010-06-04 23:24:48 +02:00
break ;
}
case CONDITION_MAPID :
2012-02-14 12:46:26 -05:00
condMeets = object -> GetMapId () == ConditionValue1 ;
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_AREAID :
2012-02-14 12:46:26 -05:00
condMeets = object -> GetAreaId () == ConditionValue1 ;
2010-06-04 23:24:48 +02:00
break ;
2010-09-10 20:49:29 +02:00
case CONDITION_SPELL :
2012-02-10 14:18:59 +01:00
{
if ( Player * player = object -> ToPlayer ())
2012-02-14 12:46:26 -05:00
condMeets = player -> HasSpell ( ConditionValue1 );
2010-09-10 20:49:29 +02:00
break ;
2012-02-10 14:18:59 +01:00
}
2010-10-05 17:54:27 +02:00
case CONDITION_LEVEL :
2011-08-04 14:27:10 +02:00
{
2012-02-10 14:18:59 +01:00
if ( Unit * unit = object -> ToUnit ())
2012-02-14 12:46:26 -05:00
condMeets = CompareValues ( static_cast < ComparisionType > ( ConditionValue2 ), static_cast < uint32 > ( unit -> getLevel ()), ConditionValue1 );
2011-08-04 14:27:10 +02:00
break ;
}
2010-10-11 23:35:55 +02:00
case CONDITION_DRUNKENSTATE :
2011-08-04 14:27:10 +02:00
{
2012-02-10 14:18:59 +01:00
if ( Player * player = object -> ToPlayer ())
2012-02-14 12:46:26 -05:00
condMeets = ( uint32 ) Player :: GetDrunkenstateByValue ( player -> GetDrunkValue ()) >= ConditionValue1 ;
2011-08-04 14:27:10 +02:00
break ;
}
2010-10-31 22:10:31 +01:00
case CONDITION_NEAR_CREATURE :
2011-08-04 14:27:10 +02:00
{
2017-05-21 23:18:43 +02:00
condMeets = object -> FindNearestCreature ( ConditionValue1 , ( float ) ConditionValue2 , bool ( ! ConditionValue3 )) != nullptr ;
2011-08-04 14:27:10 +02:00
break ;
}
2010-10-31 22:10:31 +01:00
case CONDITION_NEAR_GAMEOBJECT :
2011-08-04 14:27:10 +02:00
{
2017-05-21 23:18:43 +02:00
condMeets = object -> FindNearestGameObject ( ConditionValue1 , ( float ) ConditionValue2 ) != nullptr ;
2011-08-04 14:27:10 +02:00
break ;
}
2014-08-24 00:10:09 +02:00
case CONDITION_OBJECT_ENTRY_GUID :
2012-02-11 15:16:18 +01:00
{
2012-05-20 17:58:35 +01:00
if ( uint32 ( object -> GetTypeId ()) == ConditionValue1 )
2014-08-24 00:10:09 +02:00
{
condMeets = ! ConditionValue2 || ( object -> GetEntry () == ConditionValue2 );
if ( ConditionValue3 )
{
switch ( object -> GetTypeId ())
{
case TYPEID_UNIT :
2015-02-25 00:13:14 +01:00
condMeets &= object -> ToCreature () -> GetSpawnId () == ConditionValue3 ;
2014-08-24 00:10:09 +02:00
break ;
case TYPEID_GAMEOBJECT :
2015-02-25 00:13:14 +01:00
condMeets &= object -> ToGameObject () -> GetSpawnId () == ConditionValue3 ;
2014-08-24 00:10:09 +02:00
break ;
2014-08-24 02:22:14 +02:00
default :
break ;
2014-08-24 00:10:09 +02:00
}
}
}
2012-02-11 15:16:18 +01:00
break ;
}
case CONDITION_TYPE_MASK :
{
2012-02-14 12:46:26 -05:00
condMeets = object -> isType ( ConditionValue1 );
2012-02-11 15:16:18 +01:00
break ;
}
case CONDITION_RELATION_TO :
{
2012-02-14 12:46:26 -05:00
if ( WorldObject * toObject = sourceInfo . mConditionTargets [ ConditionValue1 ])
2012-02-11 15:16:18 +01:00
{
Unit * toUnit = toObject -> ToUnit ();
Unit * unit = object -> ToUnit ();
if ( toUnit && unit )
{
2015-11-14 00:56:44 +01:00
switch ( static_cast < RelationType > ( ConditionValue2 ))
2012-02-11 15:16:18 +01:00
{
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 ;
2012-09-21 00:07:56 +03:00
case RELATION_CREATED_BY :
condMeets = unit -> GetCreatorGUID () == toUnit -> GetGUID ();
break ;
2015-11-14 01:23:28 +01:00
default :
break ;
2012-02-11 15:16:18 +01:00
}
}
}
break ;
}
case CONDITION_REACTION_TO :
{
2012-02-14 12:46:26 -05:00
if ( WorldObject * toObject = sourceInfo . mConditionTargets [ ConditionValue1 ])
2012-02-11 15:16:18 +01:00
{
Unit * toUnit = toObject -> ToUnit ();
Unit * unit = object -> ToUnit ();
if ( toUnit && unit )
2014-07-17 15:42:57 +02:00
condMeets = (( 1 << unit -> GetReactionTo ( toUnit )) & ConditionValue2 ) != 0 ;
2012-02-11 15:16:18 +01:00
}
break ;
}
case CONDITION_DISTANCE_TO :
{
2012-02-14 12:46:26 -05:00
if ( WorldObject * toObject = sourceInfo . mConditionTargets [ ConditionValue1 ])
condMeets = CompareValues ( static_cast < ComparisionType > ( ConditionValue3 ), object -> GetDistance ( toObject ), static_cast < float > ( ConditionValue2 ));
2012-02-11 15:16:18 +01:00
break ;
}
case CONDITION_ALIVE :
{
if ( Unit * unit = object -> ToUnit ())
2013-06-11 19:54:27 -02:30
condMeets = unit -> IsAlive ();
2012-02-11 15:16:18 +01:00
break ;
}
case CONDITION_HP_VAL :
{
if ( Unit * unit = object -> ToUnit ())
2016-06-03 09:27:27 +02:00
condMeets = CompareValues ( static_cast < ComparisionType > ( ConditionValue2 ), unit -> GetHealth (), static_cast < uint64 > ( ConditionValue1 ));
2012-02-11 15:16:18 +01:00
break ;
}
case CONDITION_HP_PCT :
{
if ( Unit * unit = object -> ToUnit ())
2012-02-14 12:46:26 -05:00
condMeets = CompareValues ( static_cast < ComparisionType > ( ConditionValue2 ), unit -> GetHealthPct (), static_cast < float > ( ConditionValue1 ));
2012-02-11 15:16:18 +01:00
break ;
}
2012-02-11 19:46:41 +00:00
case CONDITION_WORLD_STATE :
{
2012-02-14 12:46:26 -05:00
condMeets = ConditionValue2 == sWorld -> getWorldState ( ConditionValue1 );
2012-02-11 19:46:41 +00:00
break ;
}
2014-06-07 19:42:08 -05:00
case CONDITION_PHASEID :
2012-02-11 19:46:41 +00:00
{
2018-01-28 11:37:20 +01:00
condMeets = object -> GetPhaseShift (). HasPhase ( ConditionValue1 );
2012-02-11 19:46:41 +00:00
break ;
2012-04-08 12:56:18 +01:00
}
case CONDITION_TITLE :
{
if ( Player * player = object -> ToPlayer ())
condMeets = player -> HasTitle ( ConditionValue1 );
break ;
2012-02-11 19:46:41 +00:00
}
2013-01-11 23:34:08 +01:00
case CONDITION_UNIT_STATE :
{
if ( Unit * unit = object -> ToUnit ())
condMeets = unit -> HasUnitState ( ConditionValue1 );
break ;
}
2013-05-25 07:51:23 +01:00
case CONDITION_CREATURE_TYPE :
{
if ( Creature * creature = object -> ToCreature ())
condMeets = creature -> GetCreatureTemplate () -> type == ConditionValue1 ;
break ;
}
2015-03-17 12:42:35 +00:00
case CONDITION_REALM_ACHIEVEMENT :
{
2016-05-07 01:16:29 +02:00
AchievementEntry const * achievement = sAchievementStore . LookupEntry ( ConditionValue1 );
if ( achievement && sAchievementMgr -> IsRealmCompleted ( achievement ))
2015-03-17 12:42:35 +00:00
condMeets = true ;
break ;
}
2015-04-18 17:11:03 +02:00
case CONDITION_IN_WATER :
{
if ( Unit * unit = object -> ToUnit ())
condMeets = unit -> IsInWater ();
break ;
}
2015-03-16 07:28:49 +01:00
case CONDITION_TERRAIN_SWAP :
{
2018-01-28 11:37:20 +01:00
condMeets = object -> GetPhaseShift (). HasVisibleMapId ( ConditionValue1 );
2015-03-16 07:28:49 +01:00
break ;
}
2016-02-25 19:00:20 +01:00
case CONDITION_STAND_STATE :
{
if ( Unit * unit = object -> ToUnit ())
{
if ( ConditionValue1 == 0 )
2016-06-08 13:05:23 +02:00
condMeets = ( unit -> GetStandState () == UnitStandStateType ( ConditionValue2 ));
2016-02-25 19:00:20 +01:00
else if ( ConditionValue2 == 0 )
condMeets = unit -> IsStandState ();
else if ( ConditionValue2 == 1 )
condMeets = unit -> IsSitState ();
}
break ;
}
2016-07-16 21:10:54 +02:00
case CONDITION_DAILY_QUEST_DONE :
{
if ( Player * player = object -> ToPlayer ())
condMeets = player -> IsDailyQuestDone ( ConditionValue1 );
break ;
}
2016-08-06 17:08:52 +02:00
case CONDITION_CHARMED :
{
if ( Unit * unit = object -> ToUnit ())
condMeets = unit -> IsCharmed ();
break ;
}
2016-08-06 20:20:07 +02:00
case CONDITION_PET_TYPE :
{
if ( Player * player = object -> ToPlayer ())
if ( Pet * pet = player -> GetPet ())
condMeets = ((( 1 << pet -> getPetType ()) & ConditionValue1 ) != 0 );
break ;
}
2016-08-20 14:36:26 +02:00
case CONDITION_TAXI :
{
if ( Player * player = object -> ToPlayer ())
condMeets = player -> IsInFlight ();
break ;
}
2016-09-09 17:14:34 +02:00
case CONDITION_QUESTSTATE :
{
if ( Player * player = object -> ToPlayer ())
{
if (
(( ConditionValue2 & ( 1 << QUEST_STATUS_NONE )) && ( player -> GetQuestStatus ( ConditionValue1 ) == QUEST_STATUS_NONE )) ||
(( ConditionValue2 & ( 1 << QUEST_STATUS_COMPLETE )) && ( player -> GetQuestStatus ( ConditionValue1 ) == QUEST_STATUS_COMPLETE )) ||
(( ConditionValue2 & ( 1 << QUEST_STATUS_INCOMPLETE )) && ( player -> GetQuestStatus ( ConditionValue1 ) == QUEST_STATUS_INCOMPLETE )) ||
(( ConditionValue2 & ( 1 << QUEST_STATUS_FAILED )) && ( player -> GetQuestStatus ( ConditionValue1 ) == QUEST_STATUS_FAILED )) ||
(( ConditionValue2 & ( 1 << QUEST_STATUS_REWARDED )) && player -> GetQuestRewardStatus ( ConditionValue1 ))
)
condMeets = true ;
}
break ;
}
2017-03-20 08:54:29 +01:00
case CONDITION_QUEST_OBJECTIVE_COMPLETE :
{
if ( Player * player = object -> ToPlayer ())
{
QuestObjective const * obj = sObjectMgr -> GetQuestObjective ( ConditionValue1 );
if ( ! obj )
break ;
2017-04-06 23:39:34 +02:00
2021-05-09 20:21:32 +02:00
Quest const * quest = sObjectMgr -> GetQuestTemplate ( obj -> QuestID );
if ( ! quest )
break ;
uint16 slot = player -> FindQuestSlot ( obj -> QuestID );
if ( slot >= MAX_QUEST_LOG_SIZE )
break ;
condMeets = ( ! player -> GetQuestRewardStatus ( obj -> QuestID ) && player -> IsQuestObjectiveComplete ( slot , quest , * obj ));
2017-03-20 08:54:29 +01:00
}
break ;
}
2018-09-15 17:55:26 +02:00
case CONDITION_DIFFICULTY_ID :
{
condMeets = object -> GetMap () -> GetDifficultyID () == ConditionValue1 ;
break ;
}
2010-06-04 23:24:48 +02:00
default :
condMeets = false ;
break ;
}
2012-02-14 12:46:26 -05:00
if ( NegativeCondition )
2012-02-10 12:44:07 +01:00
condMeets = ! condMeets ;
2012-02-10 23:40:38 +01:00
if ( ! condMeets )
sourceInfo . mLastFailedCondition = this ;
2010-06-04 23:24:48 +02:00
2012-02-10 23:40:38 +01:00
bool script = sScriptMgr -> OnConditionCheck ( this , sourceInfo ); // Returns true by default.
2012-02-10 15:43:19 +01:00
return condMeets && script ;
2010-06-04 23:24:48 +02:00
}
2015-10-25 12:22:53 +01:00
uint32 Condition :: GetSearcherTypeMaskForCondition () const
2012-02-21 20:03:27 +01:00
{
// build mask of types for which condition can return true
// this is used for speeding up gridsearches
if ( NegativeCondition )
return ( GRID_MAP_TYPE_MASK_ALL );
uint32 mask = 0 ;
switch ( ConditionType )
{
case CONDITION_NONE :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_AURA :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_ITEM :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_ITEM_EQUIPPED :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_ZONEID :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_REPUTATION_RANK :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_ACHIEVEMENT :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_TEAM :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_CLASS :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_RACE :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_SKILL :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_QUESTREWARDED :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_QUESTTAKEN :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_QUEST_COMPLETE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_QUEST_NONE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_ACTIVE_EVENT :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2012-12-30 16:03:25 -05:00
case CONDITION_INSTANCE_INFO :
2012-02-21 20:03:27 +01:00
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_MAPID :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_AREAID :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_SPELL :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_LEVEL :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_DRUNKENSTATE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_NEAR_CREATURE :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_NEAR_GAMEOBJECT :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2014-08-24 00:10:09 +02:00
case CONDITION_OBJECT_ENTRY_GUID :
2012-02-21 20:03:27 +01:00
switch ( ConditionValue1 )
{
case TYPEID_UNIT :
mask |= GRID_MAP_TYPE_MASK_CREATURE ;
break ;
case TYPEID_PLAYER :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case TYPEID_GAMEOBJECT :
mask |= GRID_MAP_TYPE_MASK_GAMEOBJECT ;
break ;
case TYPEID_CORPSE :
mask |= GRID_MAP_TYPE_MASK_CORPSE ;
break ;
2013-05-26 04:56:43 +03:00
case TYPEID_AREATRIGGER :
mask |= GRID_MAP_TYPE_MASK_AREATRIGGER ;
break ;
2012-02-21 20:03:27 +01:00
default :
break ;
}
2013-02-20 20:41:48 +01:00
break ;
2012-02-21 20:03:27 +01:00
case CONDITION_TYPE_MASK :
if ( ConditionValue1 & TYPEMASK_UNIT )
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
if ( ConditionValue1 & TYPEMASK_PLAYER )
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
if ( ConditionValue1 & TYPEMASK_GAMEOBJECT )
mask |= GRID_MAP_TYPE_MASK_GAMEOBJECT ;
if ( ConditionValue1 & TYPEMASK_CORPSE )
mask |= GRID_MAP_TYPE_MASK_CORPSE ;
2013-05-26 04:56:43 +03:00
if ( ConditionValue1 & TYPEMASK_AREATRIGGER )
mask |= GRID_MAP_TYPE_MASK_AREATRIGGER ;
2012-02-21 20:03:27 +01:00
break ;
case CONDITION_RELATION_TO :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_REACTION_TO :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_DISTANCE_TO :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
case CONDITION_ALIVE :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_HP_VAL :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_HP_PCT :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
case CONDITION_WORLD_STATE :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2014-06-07 19:42:08 -05:00
case CONDITION_PHASEID :
2012-02-21 20:03:27 +01:00
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2012-04-07 23:15:16 +01:00
case CONDITION_TITLE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2012-11-26 14:34:23 -05:00
case CONDITION_GENDER :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
2012-11-26 23:50:14 +02:00
break ;
2013-01-11 23:34:08 +01:00
case CONDITION_UNIT_STATE :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2013-05-25 08:57:49 +01:00
case CONDITION_CREATURE_TYPE :
mask |= GRID_MAP_TYPE_MASK_CREATURE ;
break ;
2015-03-17 12:42:35 +00:00
case CONDITION_REALM_ACHIEVEMENT :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2015-04-18 17:11:03 +02:00
case CONDITION_IN_WATER :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2015-03-16 07:28:49 +01:00
case CONDITION_TERRAIN_SWAP :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2016-02-25 19:00:20 +01:00
case CONDITION_STAND_STATE :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2016-07-16 21:10:54 +02:00
case CONDITION_DAILY_QUEST_DONE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2016-08-06 17:08:52 +02:00
case CONDITION_CHARMED :
mask |= GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2016-08-06 20:20:07 +02:00
case CONDITION_PET_TYPE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2016-08-20 14:36:26 +02:00
case CONDITION_TAXI :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2016-09-09 17:14:34 +02:00
case CONDITION_QUESTSTATE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2017-03-20 08:54:29 +01:00
case CONDITION_QUEST_OBJECTIVE_COMPLETE :
mask |= GRID_MAP_TYPE_MASK_PLAYER ;
break ;
2018-09-15 17:55:26 +02:00
case CONDITION_DIFFICULTY_ID :
mask |= GRID_MAP_TYPE_MASK_ALL ;
break ;
2012-02-21 20:03:27 +01:00
default :
ASSERT ( false && "Condition::GetSearcherTypeMaskForCondition - missing condition handling!" );
break ;
}
return mask ;
}
2015-10-25 12:22:53 +01:00
uint32 Condition :: GetMaxAvailableConditionTargets () const
2012-02-11 15:16:18 +01:00
{
// returns number of targets which are available for given source type
2012-06-30 16:07:09 +02:00
switch ( SourceType )
2012-02-11 15:16:18 +01:00
{
case CONDITION_SOURCE_TYPE_SPELL :
2012-02-21 20:03:27 +01:00
case CONDITION_SOURCE_TYPE_SPELL_IMPLICIT_TARGET :
2012-02-15 22:12:15 +01:00
case CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE :
case CONDITION_SOURCE_TYPE_VEHICLE_SPELL :
2012-02-20 23:21:12 +01:00
case CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT :
2012-02-15 22:12:15 +01:00
case CONDITION_SOURCE_TYPE_GOSSIP_MENU :
case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION :
2012-02-18 16:52:08 +01:00
case CONDITION_SOURCE_TYPE_SMART_EVENT :
2012-12-01 01:49:44 +01:00
case CONDITION_SOURCE_TYPE_NPC_VENDOR :
2012-12-22 01:37:54 +01:00
case CONDITION_SOURCE_TYPE_SPELL_PROC :
2012-02-18 16:52:08 +01:00
return 2 ;
2012-02-11 15:16:18 +01:00
default :
return 1 ;
}
}
2014-11-20 13:55:26 +01:00
std :: string Condition :: ToString ( bool ext /*= false*/ ) const
{
std :: ostringstream ss ;
ss << "[Condition " ;
ss << "SourceType: " << SourceType ;
if ( SourceType < CONDITION_SOURCE_TYPE_MAX )
ss << " (" << ConditionMgr :: StaticSourceTypeData [ SourceType ] << ")" ;
else
ss << " (Unknown)" ;
if ( ConditionMgr :: CanHaveSourceGroupSet ( SourceType ))
ss << ", SourceGroup: " << SourceGroup ;
ss << ", SourceEntry: " << SourceEntry ;
if ( ConditionMgr :: CanHaveSourceIdSet ( SourceType ))
ss << ", SourceId: " << SourceId ;
if ( ext )
{
ss << ", ConditionType: " << ConditionType ;
if ( ConditionType < CONDITION_MAX )
ss << " (" << ConditionMgr :: StaticConditionTypeData [ ConditionType ]. Name << ")" ;
else
ss << " (Unknown)" ;
}
ss << "]" ;
return ss . str ();
}
2013-10-28 14:36:07 -04:00
ConditionMgr :: ConditionMgr () { }
2010-06-04 23:24:48 +02:00
ConditionMgr ::~ ConditionMgr ()
{
2010-06-11 01:25:10 +02:00
Clean ();
2010-06-04 23:24:48 +02:00
}
2015-10-25 13:20:28 +01:00
uint32 ConditionMgr :: GetSearcherTypeMaskForConditionList ( ConditionContainer const & conditions ) const
2012-02-21 20:03:27 +01:00
{
if ( conditions . empty ())
return GRID_MAP_TYPE_MASK_ALL ;
// groupId, typeMask
2015-10-25 13:20:28 +01:00
std :: map < uint32 , uint32 > elseGroupSearcherTypeMasks ;
2015-10-25 10:59:58 +01:00
for ( ConditionContainer :: const_iterator i = conditions . begin (); i != conditions . end (); ++ i )
2012-02-21 20:03:27 +01:00
{
// no point of having not loaded conditions in list
ASSERT (( * i ) -> isLoaded () && "ConditionMgr::GetSearcherTypeMaskForConditionList - not yet loaded condition found in list" );
2015-10-25 13:20:28 +01:00
std :: map < uint32 , uint32 >:: const_iterator itr = elseGroupSearcherTypeMasks . find (( * i ) -> ElseGroup );
2012-02-21 20:03:27 +01:00
// group not filled yet, fill with widest mask possible
2015-10-25 13:20:28 +01:00
if ( itr == elseGroupSearcherTypeMasks . end ())
elseGroupSearcherTypeMasks [( * i ) -> ElseGroup ] = GRID_MAP_TYPE_MASK_ALL ;
2012-02-21 20:03:27 +01:00
// no point of checking anymore, empty mask
2015-10-25 13:20:28 +01:00
else if ( ! itr -> second )
2012-02-21 20:03:27 +01:00
continue ;
if (( * i ) -> ReferenceId ) // handle reference
{
ConditionReferenceContainer :: const_iterator ref = ConditionReferenceStore . find (( * i ) -> ReferenceId );
ASSERT ( ref != ConditionReferenceStore . end () && "ConditionMgr::GetSearcherTypeMaskForConditionList - incorrect reference" );
2015-10-25 13:20:28 +01:00
elseGroupSearcherTypeMasks [( * i ) -> ElseGroup ] &= GetSearcherTypeMaskForConditionList (( * ref ). second );
2012-02-21 20:03:27 +01:00
}
else // handle normal condition
{
// object will match conditions in one ElseGroupStore only when it matches all of them
// so, let's find a smallest possible mask which satisfies all conditions
2015-10-25 13:20:28 +01:00
elseGroupSearcherTypeMasks [( * i ) -> ElseGroup ] &= ( * i ) -> GetSearcherTypeMaskForCondition ();
2012-02-21 20:03:27 +01:00
}
}
// object will match condition when one of the checks in ElseGroupStore is matching
// so, let's include all possible masks
uint32 mask = 0 ;
2015-10-25 13:20:28 +01:00
for ( std :: map < uint32 , uint32 >:: const_iterator i = elseGroupSearcherTypeMasks . begin (); i != elseGroupSearcherTypeMasks . end (); ++ i )
2012-02-21 20:03:27 +01:00
mask |= i -> second ;
return mask ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: IsObjectMeetToConditionList ( ConditionSourceInfo & sourceInfo , ConditionContainer const & conditions ) const
2010-06-04 23:24:48 +02:00
{
2012-02-21 20:03:27 +01:00
// groupId, groupCheckPassed
2015-10-25 13:20:28 +01:00
std :: map < uint32 , bool > elseGroupStore ;
for ( Condition const * condition : conditions )
2010-06-04 23:24:48 +02:00
{
2015-10-25 13:20:28 +01:00
TC_LOG_DEBUG ( "condition" , "ConditionMgr::IsPlayerMeetToConditionList %s val1: %u" , condition -> ToString (). c_str (), condition -> ConditionValue1 );
if ( condition -> isLoaded ())
2010-06-04 23:24:48 +02:00
{
2012-03-01 14:30:19 +01:00
//! Find ElseGroup in ElseGroupStore
2015-10-25 13:20:28 +01:00
std :: map < uint32 , bool >:: const_iterator itr = elseGroupStore . find ( condition -> ElseGroup );
2012-03-01 14:30:19 +01:00
//! If not found, add an entry in the store and set to true (placeholder)
2015-10-25 13:20:28 +01:00
if ( itr == elseGroupStore . end ())
elseGroupStore [ condition -> ElseGroup ] = true ;
2016-05-25 23:41:40 +02:00
else if ( ! ( * itr ). second ) //! If another condition in this group was unmatched before this, don't bother checking (the group is false anyway)
2010-06-04 23:24:48 +02:00
continue ;
2015-10-25 13:20:28 +01:00
if ( condition -> ReferenceId ) //handle reference
2010-06-04 23:24:48 +02:00
{
2015-10-25 13:20:28 +01:00
ConditionReferenceContainer :: const_iterator ref = ConditionReferenceStore . find ( condition -> ReferenceId );
2012-01-29 13:49:19 -05:00
if ( ref != ConditionReferenceStore . end ())
2010-06-04 23:24:48 +02:00
{
2015-10-25 13:20:28 +01:00
if ( ! IsObjectMeetToConditionList ( sourceInfo , ref -> second ))
elseGroupStore [ condition -> ElseGroup ] = false ;
2010-08-06 19:23:43 +02:00
}
else
{
2014-11-20 13:55:26 +01:00
TC_LOG_DEBUG ( "condition" , "ConditionMgr::IsPlayerMeetToConditionList %s Reference template -%u not found" ,
2015-10-25 13:20:28 +01:00
condition -> ToString (). c_str (), condition -> ReferenceId ); // checked at loading, should never happen
2010-06-04 23:24:48 +02:00
}
2010-06-11 01:25:10 +02:00
2010-08-06 19:23:43 +02:00
}
else //handle normal condition
2010-06-04 23:24:48 +02:00
{
2015-10-25 13:20:28 +01:00
if ( ! condition -> Meets ( sourceInfo ))
elseGroupStore [ condition -> ElseGroup ] = false ;
2010-06-10 20:52:15 +02:00
}
2010-06-04 23:24:48 +02:00
}
}
2015-10-25 13:20:28 +01:00
for ( std :: map < uint32 , bool >:: const_iterator i = elseGroupStore . begin (); i != elseGroupStore . end (); ++ i )
2010-06-04 23:24:48 +02:00
if ( i -> second )
return true ;
2010-08-06 19:23:43 +02:00
2010-06-04 23:24:48 +02:00
return false ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: IsObjectMeetToConditions ( WorldObject * object , ConditionContainer const & conditions ) const
2012-02-10 23:40:38 +01:00
{
2012-02-11 00:15:05 +01:00
ConditionSourceInfo srcInfo = ConditionSourceInfo ( object );
return IsObjectMeetToConditions ( srcInfo , conditions );
2012-02-10 23:40:38 +01:00
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: IsObjectMeetToConditions ( WorldObject * object1 , WorldObject * object2 , ConditionContainer const & conditions ) const
2012-02-15 22:12:15 +01:00
{
ConditionSourceInfo srcInfo = ConditionSourceInfo ( object1 , object2 );
return IsObjectMeetToConditions ( srcInfo , conditions );
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: IsObjectMeetToConditions ( ConditionSourceInfo & sourceInfo , ConditionContainer const & conditions ) const
2010-06-04 23:24:48 +02:00
{
if ( conditions . empty ())
return true ;
2010-08-06 19:23:43 +02:00
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "condition" , "ConditionMgr::IsObjectMeetToConditions" );
2012-02-10 23:40:38 +01:00
return IsObjectMeetToConditionList ( sourceInfo , conditions );
2010-06-04 23:24:48 +02:00
}
2014-11-20 13:55:26 +01:00
bool ConditionMgr :: CanHaveSourceGroupSet ( ConditionSourceType sourceType )
2012-02-21 20:03:27 +01:00
{
return ( sourceType == CONDITION_SOURCE_TYPE_CREATURE_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_DISENCHANT_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_FISHING_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_GAMEOBJECT_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_ITEM_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_MAIL_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_MILLING_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_PICKPOCKETING_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_PROSPECTING_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_REFERENCE_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_SKINNING_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_SPELL_LOOT_TEMPLATE ||
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU ||
sourceType == CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION ||
sourceType == CONDITION_SOURCE_TYPE_VEHICLE_SPELL ||
sourceType == CONDITION_SOURCE_TYPE_SPELL_IMPLICIT_TARGET ||
2012-02-21 20:17:32 +01:00
sourceType == CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT ||
2012-09-26 17:46:00 +02:00
sourceType == CONDITION_SOURCE_TYPE_SMART_EVENT ||
2015-10-25 00:22:21 +02:00
sourceType == CONDITION_SOURCE_TYPE_NPC_VENDOR ||
sourceType == CONDITION_SOURCE_TYPE_PHASE );
2012-02-21 20:03:27 +01:00
}
2014-11-20 13:55:26 +01:00
bool ConditionMgr :: CanHaveSourceIdSet ( ConditionSourceType sourceType )
2012-02-21 20:03:27 +01:00
{
return ( sourceType == CONDITION_SOURCE_TYPE_SMART_EVENT );
}
2015-10-25 13:20:28 +01:00
bool ConditionMgr :: IsObjectMeetingNotGroupedConditions ( ConditionSourceType sourceType , uint32 entry , ConditionSourceInfo & sourceInfo ) const
2010-06-04 23:24:48 +02:00
{
2012-01-29 13:49:19 -05:00
if ( sourceType > CONDITION_SOURCE_TYPE_NONE && sourceType < CONDITION_SOURCE_TYPE_MAX )
2010-06-04 23:24:48 +02:00
{
2015-10-25 13:35:45 +01:00
ConditionsByEntryMap :: const_iterator i = ConditionStore [ sourceType ]. find ( entry );
if ( i != ConditionStore [ sourceType ]. end ())
2010-06-11 01:25:10 +02:00
{
2015-10-25 13:35:45 +01:00
TC_LOG_DEBUG ( "condition" , "GetConditionsForNotGroupedEntry: found conditions for type %u and entry %u" , uint32 ( sourceType ), entry );
return IsObjectMeetToConditions ( sourceInfo , i -> second );
2010-06-04 23:24:48 +02:00
}
}
2015-10-25 13:20:28 +01:00
return true ;
}
bool ConditionMgr :: IsObjectMeetingNotGroupedConditions ( ConditionSourceType sourceType , uint32 entry , WorldObject * target0 , WorldObject * target1 /*= nullptr*/ , WorldObject * target2 /*= nullptr*/ ) const
{
ConditionSourceInfo conditionSource ( target0 , target1 , target2 );
return IsObjectMeetingNotGroupedConditions ( sourceType , entry , conditionSource );
}
bool ConditionMgr :: HasConditionsForNotGroupedEntry ( ConditionSourceType sourceType , uint32 entry ) const
{
if ( sourceType > CONDITION_SOURCE_TYPE_NONE && sourceType < CONDITION_SOURCE_TYPE_MAX )
2015-10-25 13:35:45 +01:00
if ( ConditionStore [ sourceType ]. find ( entry ) != ConditionStore [ sourceType ]. end ())
return true ;
2015-10-25 13:20:28 +01:00
return false ;
2010-06-04 23:24:48 +02:00
}
2015-10-25 13:20:28 +01:00
bool ConditionMgr :: IsObjectMeetingSpellClickConditions ( uint32 creatureId , uint32 spellId , WorldObject * clicker , WorldObject * target ) const
2012-02-20 23:21:12 +01:00
{
2015-10-25 10:59:58 +01:00
ConditionEntriesByCreatureIdMap :: const_iterator itr = SpellClickEventConditionStore . find ( creatureId );
2012-02-20 23:21:12 +01:00
if ( itr != SpellClickEventConditionStore . end ())
{
2015-10-25 13:20:28 +01:00
ConditionsByEntryMap :: const_iterator i = itr -> second . find ( spellId );
if ( i != itr -> second . end ())
2012-02-20 23:21:12 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_DEBUG ( "condition" , "GetConditionsForSpellClickEvent: found conditions for SpellClickEvent entry %u spell %u" , creatureId , spellId );
2015-10-25 13:20:28 +01:00
ConditionSourceInfo sourceInfo ( clicker , target );
return IsObjectMeetToConditions ( sourceInfo , i -> second );
2012-02-20 23:21:12 +01:00
}
}
2015-10-25 13:20:28 +01:00
return true ;
2012-02-20 23:21:12 +01:00
}
2015-10-25 13:20:28 +01:00
ConditionContainer const * ConditionMgr :: GetConditionsForSpellClickEvent ( uint32 creatureId , uint32 spellId ) const
{
ConditionEntriesByCreatureIdMap :: const_iterator itr = SpellClickEventConditionStore . find ( creatureId );
if ( itr != SpellClickEventConditionStore . end ())
{
ConditionsByEntryMap :: const_iterator i = itr -> second . find ( spellId );
if ( i != itr -> second . end ())
{
TC_LOG_DEBUG ( "condition" , "GetConditionsForSpellClickEvent: found conditions for SpellClickEvent entry %u spell %u" , creatureId , spellId );
return & i -> second ;
}
}
return nullptr ;
}
bool ConditionMgr :: IsObjectMeetingVehicleSpellConditions ( uint32 creatureId , uint32 spellId , Player * player , Unit * vehicle ) const
2010-10-22 22:45:11 +02:00
{
2015-10-25 10:59:58 +01:00
ConditionEntriesByCreatureIdMap :: const_iterator itr = VehicleSpellConditionStore . find ( creatureId );
2012-01-29 13:49:19 -05:00
if ( itr != VehicleSpellConditionStore . end ())
2010-10-22 22:45:11 +02:00
{
2015-10-25 13:20:28 +01:00
ConditionsByEntryMap :: const_iterator i = itr -> second . find ( spellId );
if ( i != itr -> second . end ())
2010-10-22 22:45:11 +02:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "condition" , "GetConditionsForVehicleSpell: found conditions for Vehicle entry %u spell %u" , creatureId , spellId );
2015-10-25 13:20:28 +01:00
ConditionSourceInfo sourceInfo ( player , vehicle );
return IsObjectMeetToConditions ( sourceInfo , i -> second );
2010-10-22 22:45:11 +02:00
}
}
2015-10-25 13:20:28 +01:00
return true ;
2010-10-22 22:45:11 +02:00
}
2015-10-25 13:20:28 +01:00
bool ConditionMgr :: IsObjectMeetingSmartEventConditions ( int64 entryOrGuid , uint32 eventId , uint32 sourceType , Unit * unit , WorldObject * baseObject ) const
2012-01-29 13:49:19 -05:00
{
2012-01-31 09:50:02 -05:00
SmartEventConditionContainer :: const_iterator itr = SmartEventConditionStore . find ( std :: make_pair ( entryOrGuid , sourceType ));
2012-01-29 13:49:19 -05:00
if ( itr != SmartEventConditionStore . end ())
{
2015-10-25 13:20:28 +01:00
ConditionsByEntryMap :: const_iterator i = itr -> second . find ( eventId + 1 );
if ( i != itr -> second . end ())
2012-01-29 13:49:19 -05:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_DEBUG ( "condition" , "GetConditionsForSmartEvent: found conditions for Smart Event entry or guid " SI64FMTD " eventId %u" , entryOrGuid , eventId );
2015-10-25 13:20:28 +01:00
ConditionSourceInfo sourceInfo ( unit , baseObject );
return IsObjectMeetToConditions ( sourceInfo , i -> second );
2012-01-29 13:49:19 -05:00
}
}
2015-10-25 13:20:28 +01:00
return true ;
2012-01-29 13:49:19 -05:00
}
2015-10-25 13:20:28 +01:00
bool ConditionMgr :: IsObjectMeetingVendorItemConditions ( uint32 creatureId , uint32 itemId , Player * player , Creature * vendor ) const
2012-12-01 01:49:44 +01:00
{
2015-10-25 10:59:58 +01:00
ConditionEntriesByCreatureIdMap :: const_iterator itr = NpcVendorConditionContainerStore . find ( creatureId );
2012-12-01 01:49:44 +01:00
if ( itr != NpcVendorConditionContainerStore . end ())
{
2015-10-25 10:59:58 +01:00
ConditionsByEntryMap :: const_iterator i = ( * itr ). second . find ( itemId );
2012-12-01 01:49:44 +01:00
if ( i != ( * itr ). second . end ())
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "condition" , "GetConditionsForNpcVendorEvent: found conditions for creature entry %u item %u" , creatureId , itemId );
2015-10-25 13:20:28 +01:00
ConditionSourceInfo sourceInfo ( player , vendor );
return IsObjectMeetToConditions ( sourceInfo , i -> second );
2012-12-01 01:49:44 +01:00
}
}
2015-10-25 13:20:28 +01:00
return true ;
2012-09-26 17:46:00 +02:00
}
2016-03-11 17:11:05 +01:00
ConditionMgr * ConditionMgr :: instance ()
{
static ConditionMgr instance ;
return & instance ;
}
2010-06-04 23:24:48 +02:00
void ConditionMgr :: LoadConditions ( bool isReload )
{
2010-12-19 17:06:33 +01:00
uint32 oldMSTime = getMSTime ();
2010-06-11 01:25:10 +02:00
Clean ();
2010-06-04 23:24:48 +02:00
//must clear all custom handled cases (groupped types) before reload
if ( isReload )
{
2013-11-08 10:50:51 +01:00
TC_LOG_INFO ( "misc" , "Reseting Loot Conditions..." );
2010-06-04 23:24:48 +02:00
LootTemplates_Creature . ResetConditions ();
LootTemplates_Fishing . ResetConditions ();
LootTemplates_Gameobject . ResetConditions ();
LootTemplates_Item . ResetConditions ();
LootTemplates_Mail . ResetConditions ();
LootTemplates_Milling . ResetConditions ();
LootTemplates_Pickpocketing . ResetConditions ();
LootTemplates_Reference . ResetConditions ();
LootTemplates_Skinning . ResetConditions ();
LootTemplates_Disenchant . ResetConditions ();
LootTemplates_Prospecting . ResetConditions ();
LootTemplates_Spell . ResetConditions ();
2013-11-08 10:50:51 +01:00
TC_LOG_INFO ( "misc" , "Re-Loading `gossip_menu` Table for Conditions!" );
2010-12-22 21:25:23 +01:00
sObjectMgr -> LoadGossipMenu ();
2010-06-04 23:24:48 +02:00
2013-11-08 10:50:51 +01:00
TC_LOG_INFO ( "misc" , "Re-Loading `gossip_menu_option` Table for Conditions!" );
2010-12-22 21:25:23 +01:00
sObjectMgr -> LoadGossipMenuItems ();
2016-03-02 22:02:45 -03:00
2012-02-21 20:03:27 +01:00
sSpellMgr -> UnloadSpellInfoImplicitTargetConditionLists ();
2015-10-25 00:22:21 +02:00
2018-01-28 11:37:20 +01:00
sObjectMgr -> UnloadPhaseConditions ();
2010-06-04 23:24:48 +02:00
}
2012-02-10 23:40:38 +01:00
QueryResult result = WorldDatabase . Query ( "SELECT SourceTypeOrReferenceId, SourceGroup, SourceEntry, SourceId, ElseGroup, ConditionTypeOrReference, ConditionTarget, "
2012-11-24 02:45:48 +01:00
" ConditionValue1, ConditionValue2, ConditionValue3, NegativeCondition, ErrorType, ErrorTextId, ScriptName FROM conditions" );
2010-06-04 23:24:48 +02:00
if ( ! result )
{
2017-10-29 13:12:38 +01:00
TC_LOG_INFO ( "server.loading" , ">> Loaded 0 conditions. DB table `conditions` is empty!" );
2010-06-04 23:24:48 +02:00
return ;
}
2010-12-19 17:06:33 +01:00
uint32 count = 0 ;
2010-06-04 23:24:48 +02:00
do
{
2011-09-15 14:08:17 +02:00
Field * fields = result -> Fetch ();
2010-06-04 23:24:48 +02:00
Condition * cond = new Condition ();
2012-11-24 02:45:48 +01:00
int32 iSourceTypeOrReferenceId = fields [ 0 ]. GetInt32 ();
2012-02-14 12:46:26 -05:00
cond -> SourceGroup = fields [ 1 ]. GetUInt32 ();
2012-10-21 15:33:31 -05:00
cond -> SourceEntry = fields [ 2 ]. GetInt32 ();
2012-03-27 00:43:56 +01:00
cond -> SourceId = fields [ 3 ]. GetInt32 ();
2012-02-14 12:46:26 -05:00
cond -> ElseGroup = fields [ 4 ]. GetUInt32 ();
2012-11-24 02:45:48 +01:00
int32 iConditionTypeOrReference = fields [ 5 ]. GetInt32 ();
2012-02-14 12:46:26 -05:00
cond -> ConditionTarget = fields [ 6 ]. GetUInt8 ();
cond -> ConditionValue1 = fields [ 7 ]. GetUInt32 ();
cond -> ConditionValue2 = fields [ 8 ]. GetUInt32 ();
cond -> ConditionValue3 = fields [ 9 ]. GetUInt32 ();
2014-07-17 15:42:57 +02:00
cond -> NegativeCondition = fields [ 10 ]. GetBool ();
2012-11-24 02:45:48 +01:00
cond -> ErrorType = fields [ 11 ]. GetUInt32 ();
cond -> ErrorTextId = fields [ 12 ]. GetUInt32 ();
2015-11-04 20:06:20 +01:00
cond -> ScriptId = sObjectMgr -> GetScriptId ( fields [ 13 ]. GetString ());
2010-06-04 23:24:48 +02:00
if ( iConditionTypeOrReference >= 0 )
2012-02-14 12:46:26 -05:00
cond -> ConditionType = ConditionTypes ( iConditionTypeOrReference );
2010-06-04 23:24:48 +02:00
2012-02-16 12:06:14 +01:00
if ( iSourceTypeOrReferenceId >= 0 )
cond -> SourceType = ConditionSourceType ( iSourceTypeOrReferenceId );
2010-06-04 23:24:48 +02:00
if ( iConditionTypeOrReference < 0 ) //it has a reference
{
2010-06-10 20:52:15 +02:00
if ( iConditionTypeOrReference == iSourceTypeOrReferenceId ) //self referencing, skip
2010-06-04 23:24:48 +02:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition reference %i is referencing self, skipped" , iSourceTypeOrReferenceId );
2010-06-11 01:25:10 +02:00
delete cond ;
2010-06-04 23:24:48 +02:00
continue ;
}
2012-02-14 12:46:26 -05:00
cond -> ReferenceId = uint32 ( abs ( iConditionTypeOrReference ));
2010-06-04 23:24:48 +02:00
2020-09-04 13:38:24 +02:00
char const * rowType = "reference template" ;
2010-06-04 23:24:48 +02:00
if ( iSourceTypeOrReferenceId >= 0 )
rowType = "reference" ;
//check for useless data
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionTarget )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in ConditionTarget (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> ConditionTarget );
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in value1 (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> ConditionValue1 );
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in value2 (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> ConditionValue2 );
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue3 )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in value3 (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> ConditionValue3 );
2012-02-14 12:46:26 -05:00
if ( cond -> NegativeCondition )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in NegativeCondition (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> NegativeCondition );
2012-02-14 12:46:26 -05:00
if ( cond -> SourceGroup && iSourceTypeOrReferenceId < 0 )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in SourceGroup (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> SourceGroup );
2012-02-14 12:46:26 -05:00
if ( cond -> SourceEntry && iSourceTypeOrReferenceId < 0 )
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Condition %s %i has useless data in SourceEntry (%u)!" , rowType , iSourceTypeOrReferenceId , cond -> SourceEntry );
2010-08-06 19:23:43 +02:00
}
else if ( ! isConditionTypeValid ( cond )) //doesn't have reference, validate ConditionType
2010-06-11 01:25:10 +02:00
{
delete cond ;
continue ;
}
2010-06-04 23:24:48 +02:00
if ( iSourceTypeOrReferenceId < 0 ) //it is a reference template
{
2015-10-25 12:22:04 +01:00
ConditionReferenceStore [ std :: abs ( iSourceTypeOrReferenceId )]. push_back ( cond ); //add to reference storage
++ count ;
2010-06-04 23:24:48 +02:00
continue ;
} //end of reference templates
//if not a reference and SourceType is invalid, skip
if ( iConditionTypeOrReference >= 0 && ! isSourceTypeValid ( cond ))
2010-06-11 01:25:10 +02:00
{
delete cond ;
2010-06-04 23:24:48 +02:00
continue ;
2010-06-11 01:25:10 +02:00
}
2010-06-04 23:24:48 +02:00
//Grouping is only allowed for some types (loot templates, gossip menus, gossip items)
2012-02-21 20:03:27 +01:00
if ( cond -> SourceGroup && ! CanHaveSourceGroupSet ( cond -> SourceType ))
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has not allowed value of SourceGroup = %u!" , cond -> ToString (). c_str (), cond -> SourceGroup );
2012-02-21 20:03:27 +01:00
delete cond ;
continue ;
}
if ( cond -> SourceId && ! CanHaveSourceIdSet ( cond -> SourceType ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has not allowed value of SourceId = %u!" , cond -> ToString (). c_str (), cond -> SourceId );
2010-06-11 01:25:10 +02:00
delete cond ;
2010-06-04 23:24:48 +02:00
continue ;
2010-08-06 19:23:43 +02:00
}
2012-02-21 20:03:27 +01:00
2012-11-24 02:45:48 +01:00
if ( cond -> ErrorType && cond -> SourceType != CONDITION_SOURCE_TYPE_SPELL )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s can't have ErrorType (%u), set to 0!" , cond -> ToString (). c_str (), cond -> ErrorType );
2012-11-24 02:45:48 +01:00
cond -> ErrorType = 0 ;
}
if ( cond -> ErrorTextId && ! cond -> ErrorType )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has any ErrorType, ErrorTextId (%u) is set, set to 0!" , cond -> ToString (). c_str (), cond -> ErrorTextId );
2012-11-24 02:45:48 +01:00
cond -> ErrorTextId = 0 ;
}
2012-02-21 20:03:27 +01:00
if ( cond -> SourceGroup )
2010-06-04 23:24:48 +02:00
{
2012-01-29 13:49:19 -05:00
bool valid = false ;
2012-02-21 20:03:27 +01:00
// handle grouped conditions
2012-02-14 12:46:26 -05:00
switch ( cond -> SourceType )
2010-06-04 23:24:48 +02:00
{
case CONDITION_SOURCE_TYPE_CREATURE_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Creature . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_DISENCHANT_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Disenchant . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_FISHING_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Fishing . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_GAMEOBJECT_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Gameobject . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_ITEM_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Item . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_MAIL_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Mail . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_MILLING_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Milling . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_PICKPOCKETING_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Pickpocketing . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_PROSPECTING_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Prospecting . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_REFERENCE_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Reference . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_SKINNING_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Skinning . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_SPELL_LOOT_TEMPLATE :
2012-02-14 12:46:26 -05:00
valid = addToLootTemplate ( cond , LootTemplates_Spell . GetLootForConditionFill ( cond -> SourceGroup ));
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_GOSSIP_MENU :
2012-01-29 13:49:19 -05:00
valid = addToGossipMenus ( cond );
2010-06-04 23:24:48 +02:00
break ;
case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION :
2012-01-29 13:49:19 -05:00
valid = addToGossipMenuItems ( cond );
2010-06-04 23:24:48 +02:00
break ;
2012-02-22 11:43:38 +01:00
case CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT :
{
SpellClickEventConditionStore [ cond -> SourceGroup ][ cond -> SourceEntry ]. push_back ( cond );
valid = true ;
++ count ;
continue ; // do not add to m_AllocatedMemory to avoid double deleting
}
2012-02-21 20:03:27 +01:00
case CONDITION_SOURCE_TYPE_SPELL_IMPLICIT_TARGET :
valid = addToSpellImplicitTargetConditions ( cond );
break ;
2010-10-22 22:45:11 +02:00
case CONDITION_SOURCE_TYPE_VEHICLE_SPELL :
2010-11-13 20:48:20 +01:00
{
2012-02-14 12:46:26 -05:00
VehicleSpellConditionStore [ cond -> SourceGroup ][ cond -> SourceEntry ]. push_back ( cond );
2012-01-29 13:49:19 -05:00
valid = true ;
2010-11-13 20:48:20 +01:00
++ count ;
continue ; // do not add to m_AllocatedMemory to avoid double deleting
}
2012-01-29 13:49:19 -05:00
case CONDITION_SOURCE_TYPE_SMART_EVENT :
{
2012-03-01 14:30:19 +01:00
//! TODO: PAIR_32 ?
2012-02-14 12:46:26 -05:00
std :: pair < int32 , uint32 > key = std :: make_pair ( cond -> SourceEntry , cond -> SourceId );
SmartEventConditionStore [ key ][ cond -> SourceGroup ]. push_back ( cond );
2012-01-29 13:49:19 -05:00
valid = true ;
++ count ;
continue ;
}
2012-12-01 01:49:44 +01:00
case CONDITION_SOURCE_TYPE_NPC_VENDOR :
{
NpcVendorConditionContainerStore [ cond -> SourceGroup ][ cond -> SourceEntry ]. push_back ( cond );
2012-12-01 13:51:02 +01:00
valid = true ;
2012-12-01 01:49:44 +01:00
++ count ;
continue ;
}
2015-10-25 00:22:21 +02:00
case CONDITION_SOURCE_TYPE_PHASE :
valid = addToPhases ( cond );
break ;
2010-08-21 20:55:31 +02:00
default :
break ;
2010-06-04 23:24:48 +02:00
}
2010-08-06 19:23:43 +02:00
2012-01-29 13:49:19 -05:00
if ( ! valid )
2010-06-11 01:25:10 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s Not handled grouped condition." , cond -> ToString (). c_str ());
2010-06-11 01:25:10 +02:00
delete cond ;
}
2010-06-04 23:24:48 +02:00
else
2010-06-11 01:25:10 +02:00
{
2012-01-29 13:49:19 -05:00
AllocatedMemoryStore . push_back ( cond );
2010-06-04 23:24:48 +02:00
++ count ;
2010-06-11 01:25:10 +02:00
}
2010-06-04 23:24:48 +02:00
continue ;
}
//handle not grouped conditions
//add new Condition to storage based on Type/Entry
2012-02-14 12:46:26 -05:00
ConditionStore [ cond -> SourceType ][ cond -> SourceEntry ]. push_back ( cond );
2010-06-04 23:24:48 +02:00
++ count ;
}
while ( result -> NextRow ());
2013-11-08 10:50:51 +01:00
TC_LOG_INFO ( "server.loading" , ">> Loaded %u conditions in %u ms" , count , GetMSTimeDiffToNow ( oldMSTime ));
2010-06-04 23:24:48 +02:00
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: addToLootTemplate ( Condition * cond , LootTemplate * loot ) const
2010-06-04 23:24:48 +02:00
{
if ( ! loot )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s LootTemplate %u not found." , cond -> ToString (). c_str (), cond -> SourceGroup );
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2010-06-04 23:24:48 +02:00
if ( loot -> addConditionItem ( cond ))
return true ;
2010-08-06 19:23:43 +02:00
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s Item %u not found in LootTemplate %u." , cond -> ToString (). c_str (), cond -> SourceEntry , cond -> SourceGroup );
2010-06-04 23:24:48 +02:00
return false ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: addToGossipMenus ( Condition * cond ) const
2010-06-04 23:24:48 +02:00
{
2012-02-14 12:46:26 -05:00
GossipMenusMapBoundsNonConst pMenuBounds = sObjectMgr -> GetGossipMenusMapBoundsNonConst ( cond -> SourceGroup );
2010-06-04 23:24:48 +02:00
if ( pMenuBounds . first != pMenuBounds . second )
{
2012-02-12 20:10:09 -05:00
for ( GossipMenusContainer :: iterator itr = pMenuBounds . first ; itr != pMenuBounds . second ; ++ itr )
2010-06-04 23:24:48 +02:00
{
2018-02-01 12:09:58 +01:00
if (( * itr ). second . MenuId == cond -> SourceGroup && ( * itr ). second . TextId == uint32 ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2017-11-10 00:41:32 +01:00
( * itr ). second . Conditions . push_back ( cond );
2010-06-04 23:24:48 +02:00
return true ;
}
}
2010-06-11 01:25:10 +02:00
}
2010-08-06 19:23:43 +02:00
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s GossipMenu %u not found." , cond -> ToString (). c_str (), cond -> SourceGroup );
2010-06-04 23:24:48 +02:00
return false ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: addToGossipMenuItems ( Condition * cond ) const
2010-06-04 23:24:48 +02:00
{
2012-02-14 12:46:26 -05:00
GossipMenuItemsMapBoundsNonConst pMenuItemBounds = sObjectMgr -> GetGossipMenuItemsMapBoundsNonConst ( cond -> SourceGroup );
2010-06-04 23:24:48 +02:00
if ( pMenuItemBounds . first != pMenuItemBounds . second )
{
2012-02-12 20:10:09 -05:00
for ( GossipMenuItemsContainer :: iterator itr = pMenuItemBounds . first ; itr != pMenuItemBounds . second ; ++ itr )
2010-06-04 23:24:48 +02:00
{
2018-02-01 12:09:58 +01:00
if (( * itr ). second . MenuId == cond -> SourceGroup && ( * itr ). second . OptionIndex == uint32 ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2011-05-26 23:57:17 +02:00
( * itr ). second . Conditions . push_back ( cond );
2010-06-04 23:24:48 +02:00
return true ;
}
}
}
2010-08-06 19:23:43 +02:00
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s GossipMenuId %u Item %u not found." , cond -> ToString (). c_str (), cond -> SourceGroup , cond -> SourceEntry );
2010-06-04 23:24:48 +02:00
return false ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: addToSpellImplicitTargetConditions ( Condition * cond ) const
2012-02-21 20:03:27 +01:00
{
2020-06-12 01:29:18 +02:00
bool valid = false ;
sSpellMgr -> ForEachSpellInfoDifficulty ( cond -> SourceEntry , [ & ]( SpellInfo const * spellInfo )
2012-02-21 20:03:27 +01:00
{
2020-06-12 01:29:18 +02:00
uint32 conditionEffMask = cond -> SourceGroup ;
std :: list < uint32 > sharedMasks ;
for ( uint8 i = 0 ; i < MAX_SPELL_EFFECTS ; ++ i )
2012-02-21 20:03:27 +01:00
{
2020-06-12 01:29:18 +02:00
SpellEffectInfo const * effect = spellInfo -> GetEffect ( i );
if ( ! effect )
continue ;
// check if effect is already a part of some shared mask
bool found = false ;
for ( std :: list < uint32 >:: iterator itr = sharedMasks . begin (); itr != sharedMasks . end (); ++ itr )
2012-02-21 20:03:27 +01:00
{
2020-06-12 01:29:18 +02:00
if (( 1 << i ) & * itr )
{
found = true ;
break ;
}
2012-02-21 20:03:27 +01:00
}
2020-06-12 01:29:18 +02:00
if ( found )
2014-11-22 17:18:16 +01:00
continue ;
2015-01-10 01:35:47 +01:00
2020-06-12 01:29:18 +02:00
// build new shared mask with found effect
uint32 sharedMask = 1 << i ;
ConditionContainer * cmp = effect -> ImplicitTargetConditions ;
for ( uint8 effIndex = i + 1 ; effIndex < MAX_SPELL_EFFECTS ; ++ effIndex )
{
SpellEffectInfo const * inner = spellInfo -> GetEffect ( effIndex );
if ( ! inner )
continue ;
2015-01-10 01:35:47 +01:00
2020-06-12 01:29:18 +02:00
if ( inner -> ImplicitTargetConditions == cmp )
sharedMask |= 1 << effIndex ;
}
2012-02-21 20:03:27 +01:00
2020-06-12 01:29:18 +02:00
sharedMasks . push_back ( sharedMask );
}
for ( std :: list < uint32 >:: iterator itr = sharedMasks . begin (); itr != sharedMasks . end (); ++ itr )
2012-02-21 20:03:27 +01:00
{
2020-06-12 01:29:18 +02:00
// some effect indexes should have same data
if ( uint32 commonMask = * itr & conditionEffMask )
{
uint8 firstEffIndex = 0 ;
for (; firstEffIndex < MAX_SPELL_EFFECTS ; ++ firstEffIndex )
if (( 1 << firstEffIndex ) & * itr )
break ;
2012-02-21 20:03:27 +01:00
2020-06-12 01:29:18 +02:00
if ( firstEffIndex >= MAX_SPELL_EFFECTS )
return ;
2013-05-17 21:30:02 +02:00
2020-06-12 01:29:18 +02:00
SpellEffectInfo const * effect = spellInfo -> GetEffect ( firstEffIndex );
if ( ! effect )
continue ;
2014-11-22 17:18:16 +01:00
2020-06-12 01:29:18 +02:00
// get shared data
ConditionContainer * sharedList = effect -> ImplicitTargetConditions ;
2012-02-21 20:03:27 +01:00
2020-06-12 01:29:18 +02:00
// there's already data entry for that sharedMask
if ( sharedList )
2012-02-21 20:03:27 +01:00
{
2020-06-12 01:29:18 +02:00
// we have overlapping masks in db
if ( conditionEffMask != * itr )
{
TC_LOG_ERROR ( "sql.sql" , "%s in `condition` table, has incorrect SourceGroup %u (spell effectMask) set - "
"effect masks are overlapping (all SourceGroup values having given bit set must be equal) - ignoring (Difficulty %u)." ,
cond -> ToString (). c_str (), cond -> SourceGroup , uint32 ( spellInfo -> Difficulty ));
return ;
}
2012-02-21 20:03:27 +01:00
}
2020-06-12 01:29:18 +02:00
// no data for shared mask, we can create new submask
else
2013-05-17 21:30:02 +02:00
{
2020-06-12 01:29:18 +02:00
// add new list, create new shared mask
sharedList = new ConditionContainer ();
bool assigned = false ;
for ( uint8 i = firstEffIndex ; i < MAX_SPELL_EFFECTS ; ++ i )
2013-05-17 21:30:02 +02:00
{
2020-06-12 01:29:18 +02:00
SpellEffectInfo const * eff = spellInfo -> GetEffect ( i );
if ( ! eff )
continue ;
if (( 1 << i ) & commonMask )
{
const_cast < SpellEffectInfo *> ( eff ) -> ImplicitTargetConditions = sharedList ;
assigned = true ;
}
2013-05-17 21:30:02 +02:00
}
2020-06-12 01:29:18 +02:00
if ( ! assigned )
{
delete sharedList ;
break ;
}
2015-01-18 18:30:34 +01:00
}
2020-06-12 01:29:18 +02:00
sharedList -> push_back ( cond );
break ;
2012-02-21 20:03:27 +01:00
}
}
2020-06-12 01:29:18 +02:00
valid = true ;
});
2012-02-21 20:03:27 +01:00
return true ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: addToPhases ( Condition * cond ) const
2015-10-25 00:22:21 +02:00
{
if ( ! cond -> SourceEntry )
{
2018-01-28 11:37:20 +01:00
if ( PhaseInfoStruct const * phaseInfo = sObjectMgr -> GetPhaseInfo ( cond -> SourceGroup ))
2015-10-25 00:22:21 +02:00
{
2018-01-28 11:37:20 +01:00
bool found = false ;
for ( uint32 areaId : phaseInfo -> Areas )
2015-10-25 00:22:21 +02:00
{
2018-01-28 11:37:20 +01:00
if ( std :: vector < PhaseAreaInfo >* phases = const_cast < std :: vector < PhaseAreaInfo >*> ( sObjectMgr -> GetPhasesForArea ( areaId )))
2015-10-25 00:22:21 +02:00
{
2018-01-28 11:37:20 +01:00
for ( PhaseAreaInfo & phase : * phases )
{
if ( phase . PhaseInfo -> Id == cond -> SourceGroup )
{
phase . Conditions . push_back ( cond );
found = true ;
}
}
2015-10-25 00:22:21 +02:00
}
}
2016-05-17 21:35:54 +02:00
2018-01-28 11:37:20 +01:00
if ( found )
return true ;
}
2015-10-25 00:22:21 +02:00
}
2018-01-28 11:37:20 +01:00
else if ( std :: vector < PhaseAreaInfo >* phases = const_cast < std :: vector < PhaseAreaInfo >*> ( sObjectMgr -> GetPhasesForArea ( cond -> SourceEntry )))
2015-10-25 00:22:21 +02:00
{
2018-01-28 11:37:20 +01:00
for ( PhaseAreaInfo & phase : * phases )
2015-10-25 00:22:21 +02:00
{
2018-01-28 11:37:20 +01:00
if ( phase . PhaseInfo -> Id == cond -> SourceGroup )
2015-10-25 00:22:21 +02:00
{
phase . Conditions . push_back ( cond );
return true ;
}
}
}
TC_LOG_ERROR ( "sql.sql" , "%s Area %u does not have phase %u." , cond -> ToString (). c_str (), cond -> SourceGroup , cond -> SourceEntry );
return false ;
}
2015-10-25 12:22:53 +01:00
bool ConditionMgr :: isSourceTypeValid ( Condition * cond ) const
2010-06-04 23:24:48 +02:00
{
2012-02-14 12:46:26 -05:00
switch ( cond -> SourceType )
2010-06-04 23:24:48 +02:00
{
case CONDITION_SOURCE_TYPE_CREATURE_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Creature . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `creature_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Creature . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_DISENCHANT_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Disenchant . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `disenchant_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Disenchant . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_FISHING_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Fishing . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `fishing_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Fishing . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_GAMEOBJECT_LOOT_TEMPLATE :
2010-06-11 01:25:10 +02:00
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Gameobject . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `gameobject_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Gameobject . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_ITEM_LOOT_TEMPLATE :
2010-06-11 01:25:10 +02:00
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Item . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `item_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Item . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_MAIL_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Mail . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `mail_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Mail . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_MILLING_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Milling . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `milling_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Milling . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_PICKPOCKETING_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Pickpocketing . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `pickpocketing_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Pickpocketing . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_PROSPECTING_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Prospecting . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `prospecting_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Prospecting . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_REFERENCE_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Reference . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `reference_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Reference . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_SKINNING_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Skinning . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `skinning_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Skinning . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_SPELL_LOOT_TEMPLATE :
{
2012-02-14 12:46:26 -05:00
if ( ! LootTemplates_Spell . HaveLootFor ( cond -> SourceGroup ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceGroup in `condition` table, does not exist in `spell_loot_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
LootTemplate * loot = LootTemplates_Spell . GetLootForConditionFill ( cond -> SourceGroup );
ItemTemplate const * pItemProto = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! pItemProto && ! loot -> isReference ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceType, SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
2012-02-21 20:03:27 +01:00
case CONDITION_SOURCE_TYPE_SPELL_IMPLICIT_TARGET :
2010-06-04 23:24:48 +02:00
{
2020-06-12 01:29:18 +02:00
SpellInfo const * spellInfo = sSpellMgr -> GetSpellInfo ( cond -> SourceEntry , DIFFICULTY_NONE );
2012-02-21 20:03:27 +01:00
if ( ! spellInfo )
2010-06-04 23:24:48 +02:00
{
2017-05-12 10:42:50 +02:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table does not exist in `spell.dbc`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2012-02-21 20:03:27 +01:00
if (( cond -> SourceGroup > MAX_EFFECT_MASK ) || ! cond -> SourceGroup )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s in `condition` table, has incorrect SourceGroup (spell effectMask) set, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
2012-02-21 20:03:27 +01:00
uint32 origGroup = cond -> SourceGroup ;
2010-09-28 08:21:51 +03:00
for ( uint8 i = 0 ; i < MAX_SPELL_EFFECTS ; ++ i )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
if ( ! (( 1 << i ) & cond -> SourceGroup ))
2012-02-21 20:03:27 +01:00
continue ;
2020-06-12 01:29:18 +02:00
SpellEffectInfo const * effect = spellInfo -> GetEffect ( i );
2014-11-22 17:18:16 +01:00
if ( ! effect )
continue ;
2015-06-26 03:57:57 +01:00
if ( effect -> ChainTargets > 0 )
2015-04-27 01:47:03 -03:00
continue ;
2014-11-22 17:18:16 +01:00
switch ( effect -> TargetA . GetSelectionCategory ())
2010-06-04 23:24:48 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_SELECT_CATEGORY_NEARBY :
case TARGET_SELECT_CATEGORY_CONE :
case TARGET_SELECT_CATEGORY_AREA :
2017-02-06 01:10:15 +01:00
case TARGET_SELECT_CATEGORY_TRAJ :
2012-02-21 20:03:27 +01:00
continue ;
2012-02-22 09:15:57 +01:00
default :
break ;
2010-10-16 16:34:21 +02:00
}
2012-03-07 00:05:34 +01:00
2014-11-22 17:18:16 +01:00
switch ( effect -> TargetB . GetSelectionCategory ())
2010-10-16 16:34:21 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_SELECT_CATEGORY_NEARBY :
case TARGET_SELECT_CATEGORY_CONE :
case TARGET_SELECT_CATEGORY_AREA :
2017-02-06 01:10:15 +01:00
case TARGET_SELECT_CATEGORY_TRAJ :
2012-02-21 20:03:27 +01:00
continue ;
2012-02-22 09:15:57 +01:00
default :
break ;
2010-06-04 23:24:48 +02:00
}
2012-02-22 09:15:57 +01:00
2015-04-27 01:47:03 -03:00
TC_LOG_ERROR ( "sql.sql" , "SourceEntry %u SourceGroup %u in `condition` table - spell %u does not have implicit targets of types: _AREA_, _CONE_, _NEARBY_, __CHAIN__ for effect %u, SourceGroup needs correction, ignoring." , cond -> SourceEntry , origGroup , cond -> SourceEntry , uint32 ( i ));
2014-11-20 13:55:26 +01:00
cond -> SourceGroup &= ~ ( 1 << i );
2010-06-04 23:24:48 +02:00
}
2012-02-21 20:03:27 +01:00
// all effects were removed, no need to add the condition at all
if ( ! cond -> SourceGroup )
2010-08-30 17:32:51 +02:00
return false ;
2010-06-04 23:24:48 +02:00
break ;
2010-06-10 20:52:15 +02:00
}
2010-06-04 23:24:48 +02:00
case CONDITION_SOURCE_TYPE_CREATURE_TEMPLATE_VEHICLE :
{
2012-02-14 12:46:26 -05:00
if ( ! sObjectMgr -> GetCreatureTemplate ( cond -> SourceEntry ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in `creature_template`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_SPELL :
2012-12-22 01:37:54 +01:00
case CONDITION_SOURCE_TYPE_SPELL_PROC :
2010-06-04 23:24:48 +02:00
{
2020-06-12 01:29:18 +02:00
SpellInfo const * spellProto = sSpellMgr -> GetSpellInfo ( cond -> SourceEntry , DIFFICULTY_NONE );
2010-06-04 23:24:48 +02:00
if ( ! spellProto )
{
2017-05-12 10:42:50 +02:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table does not exist in `spell.dbc`, ignoring." , cond -> ToString (). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
2017-08-20 12:59:29 +02:00
case CONDITION_SOURCE_TYPE_QUEST_AVAILABLE :
2012-02-14 12:46:26 -05:00
if ( ! sObjectMgr -> GetQuestTemplate ( cond -> SourceEntry ))
2010-09-20 10:19:20 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry specifies non-existing quest, skipped." , cond -> ToString (). c_str ());
2011-08-04 14:27:10 +02:00
return false ;
2010-09-19 19:49:23 +02:00
}
break ;
2010-10-22 22:45:11 +02:00
case CONDITION_SOURCE_TYPE_VEHICLE_SPELL :
2012-02-14 12:46:26 -05:00
if ( ! sObjectMgr -> GetCreatureTemplate ( cond -> SourceGroup ))
2010-10-22 22:45:11 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in `creature_template`, ignoring." , cond -> ToString (). c_str ());
2011-08-04 14:27:10 +02:00
return false ;
}
2020-06-12 01:29:18 +02:00
if ( ! sSpellMgr -> GetSpellInfo ( cond -> SourceEntry , DIFFICULTY_NONE ))
2011-08-04 14:27:10 +02:00
{
2017-05-12 10:42:50 +02:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table does not exist in `spell.dbc`, ignoring." , cond -> ToString (). c_str ());
2011-08-04 14:27:10 +02:00
return false ;
2010-10-22 22:45:11 +02:00
}
2011-08-04 14:27:10 +02:00
break ;
2012-02-20 23:21:12 +01:00
case CONDITION_SOURCE_TYPE_SPELL_CLICK_EVENT :
if ( ! sObjectMgr -> GetCreatureTemplate ( cond -> SourceGroup ))
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in `creature_template`, ignoring." , cond -> ToString (). c_str ());
2012-02-20 23:21:12 +01:00
return false ;
}
2020-06-12 01:29:18 +02:00
if ( ! sSpellMgr -> GetSpellInfo ( cond -> SourceEntry , DIFFICULTY_NONE ))
2012-02-20 23:21:12 +01:00
{
2017-05-12 10:42:50 +02:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table does not exist in `spell.dbc`, ignoring." , cond -> ToString (). c_str ());
2012-02-20 23:21:12 +01:00
return false ;
}
break ;
2012-12-01 01:49:44 +01:00
case CONDITION_SOURCE_TYPE_NPC_VENDOR :
{
if ( ! sObjectMgr -> GetCreatureTemplate ( cond -> SourceGroup ))
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in `creature_template`, ignoring." , cond -> ToString (). c_str ());
2012-12-01 01:49:44 +01:00
return false ;
}
ItemTemplate const * itemTemplate = sObjectMgr -> GetItemTemplate ( cond -> SourceEntry );
if ( ! itemTemplate )
{
2020-01-25 14:15:20 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, item does not exist, ignoring." , cond -> ToString (). c_str ());
2012-12-01 01:49:44 +01:00
return false ;
}
break ;
}
2015-10-25 00:22:21 +02:00
case CONDITION_SOURCE_TYPE_TERRAIN_SWAP :
{
if ( ! sMapStore . LookupEntry ( cond -> SourceEntry ))
{
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in Map.dbc, ignoring." , cond -> ToString (). c_str ());
return false ;
}
break ;
}
case CONDITION_SOURCE_TYPE_PHASE :
{
2016-02-02 19:13:04 +01:00
if ( cond -> SourceEntry && ! sAreaTableStore . LookupEntry ( cond -> SourceEntry ))
2015-10-25 00:22:21 +02:00
{
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in AreaTable.dbc, ignoring." , cond -> ToString (). c_str ());
return false ;
}
break ;
}
2010-06-04 23:24:48 +02:00
case CONDITION_SOURCE_TYPE_GOSSIP_MENU :
case CONDITION_SOURCE_TYPE_GOSSIP_MENU_OPTION :
2012-01-29 13:49:19 -05:00
case CONDITION_SOURCE_TYPE_SMART_EVENT :
2010-06-04 23:24:48 +02:00
break ;
2018-03-14 23:31:49 +01:00
case CONDITION_SOURCE_TYPE_GRAVEYARD :
2019-10-26 23:58:29 +02:00
if ( ! sObjectMgr -> GetWorldSafeLoc ( cond -> SourceEntry ))
2018-03-14 23:31:49 +01:00
{
TC_LOG_ERROR ( "sql.sql" , "%s SourceEntry in `condition` table, does not exist in WorldSafeLocs.db2, ignoring." , cond -> ToString (). c_str ());
return false ;
}
break ;
2017-11-05 12:33:07 +01:00
default :
TC_LOG_ERROR ( "sql.sql" , "%s Invalid ConditionSourceType in `condition` table, ignoring." , cond -> ToString (). c_str ());
return false ;
2010-06-04 23:24:48 +02:00
}
2010-08-06 19:23:43 +02:00
2010-06-04 23:24:48 +02:00
return true ;
}
2012-09-26 17:46:00 +02:00
2015-10-25 13:20:28 +01:00
bool ConditionMgr :: isConditionTypeValid ( Condition * cond ) const
2010-06-04 23:24:48 +02:00
{
2012-02-14 12:46:26 -05:00
switch ( cond -> ConditionType )
2010-06-04 23:24:48 +02:00
{
case CONDITION_AURA :
{
2020-06-12 01:29:18 +02:00
if ( ! sSpellMgr -> GetSpellInfo ( cond -> ConditionValue1 , DIFFICULTY_NONE ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing spell (Id: %d), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-20 23:21:12 +01:00
if ( cond -> ConditionValue2 > EFFECT_2 )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing effect index (%u) (must be 0..2), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_ITEM :
{
2012-02-14 12:46:26 -05:00
ItemTemplate const * proto = sObjectMgr -> GetItemTemplate ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! proto )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s Item (%u) does not exist, skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
if ( ! cond -> ConditionValue2 )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s Zero item count in ConditionValue2, skipped." , cond -> ToString ( true ). c_str ());
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_ITEM_EQUIPPED :
{
2012-02-14 12:46:26 -05:00
ItemTemplate const * proto = sObjectMgr -> GetItemTemplate ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! proto )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s Item (%u) does not exist, skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_ZONEID :
{
2016-02-02 19:13:04 +01:00
AreaTableEntry const * areaEntry = sAreaTableStore . LookupEntry ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! areaEntry )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s Area (%u) does not exist, skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2014-11-13 02:30:19 +02:00
if ( areaEntry -> ParentAreaID != 0 )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s requires to be in area (%u) which is a subzone but zone expected, skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_REPUTATION_RANK :
{
2012-02-14 12:46:26 -05:00
FactionEntry const * factionEntry = sFactionStore . LookupEntry ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! factionEntry )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing faction (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_TEAM :
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 != ALLIANCE && cond -> ConditionValue1 != HORDE )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s specifies unknown team (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_SKILL :
{
2012-02-14 12:46:26 -05:00
SkillLineEntry const * pSkill = sSkillLineStore . LookupEntry ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! pSkill )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s specifies non-existing skill (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
2010-08-06 19:23:43 +02:00
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 < 1 || cond -> ConditionValue2 > sWorld -> GetConfigMaxSkillValue ())
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s specifies skill (%u) with invalid value (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 , cond -> ConditionValue2 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
2016-09-09 17:14:34 +02:00
case CONDITION_QUESTSTATE :
if ( cond -> ConditionValue2 >= ( 1 << MAX_QUEST_STATUS ))
{
TC_LOG_ERROR ( "sql.sql" , "%s has invalid state mask (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
return false ;
}
2020-05-21 22:15:58 +02:00
/* fallthrough */
2010-06-04 23:24:48 +02:00
case CONDITION_QUESTREWARDED :
case CONDITION_QUESTTAKEN :
case CONDITION_QUEST_NONE :
2010-10-24 21:44:58 +02:00
case CONDITION_QUEST_COMPLETE :
2016-07-16 21:10:54 +02:00
case CONDITION_DAILY_QUEST_DONE :
2010-06-04 23:24:48 +02:00
{
2012-02-14 12:46:26 -05:00
if ( ! sObjectMgr -> GetQuestTemplate ( cond -> ConditionValue1 ))
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s points to non-existing quest (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_ACTIVE_EVENT :
{
2010-12-22 21:25:23 +01:00
GameEventMgr :: GameEventDataMap const & events = sGameEventMgr -> GetEventMap ();
2014-11-20 13:55:26 +01:00
if ( cond -> ConditionValue1 >= events . size () || ! events [ cond -> ConditionValue1 ]. isValid ())
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing event id (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_ACHIEVEMENT :
{
2016-05-07 01:16:29 +02:00
AchievementEntry const * achievement = sAchievementStore . LookupEntry ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! achievement )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing achivement id (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_CLASS :
{
2018-09-26 21:34:56 +02:00
if ( cond -> ConditionValue1 & ~ CLASSMASK_ALL_PLAYABLE )
2010-06-04 23:24:48 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing classmask (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 & ~ CLASSMASK_ALL_PLAYABLE );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
case CONDITION_RACE :
{
2020-03-30 19:06:11 +02:00
if ( uint32 ( cond -> ConditionValue1 & ~ RACEMASK_ALL_PLAYABLE )) // uint32 works thanks to weird index remapping in racemask
2010-06-04 23:24:48 +02:00
{
2018-09-26 21:34:56 +02:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing racemask (" UI64FMTD "), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 & ~ RACEMASK_ALL_PLAYABLE );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
2012-11-26 14:34:23 -05:00
case CONDITION_GENDER :
{
if ( ! Player :: IsValidGender ( uint8 ( cond -> ConditionValue1 )))
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid gender (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-11-26 14:34:23 -05:00
return false ;
}
break ;
}
2010-06-04 23:24:48 +02:00
case CONDITION_MAPID :
{
2012-02-14 12:46:26 -05:00
MapEntry const * me = sMapStore . LookupEntry ( cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
if ( ! me )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing map (%u), skipped" , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-06-04 23:24:48 +02:00
return false ;
}
break ;
}
2010-09-10 20:49:29 +02:00
case CONDITION_SPELL :
{
2020-06-12 01:29:18 +02:00
if ( ! sSpellMgr -> GetSpellInfo ( cond -> ConditionValue1 , DIFFICULTY_NONE ))
2010-09-10 20:49:29 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing spell (Id: %d), skipped" , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-09-10 20:49:29 +02:00
return false ;
}
break ;
}
2010-10-05 17:54:27 +02:00
case CONDITION_LEVEL :
2011-08-04 14:27:10 +02:00
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 >= COMP_TYPE_MAX )
2010-10-05 17:54:27 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ComparisionType (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2011-08-04 14:27:10 +02:00
return false ;
2010-10-05 17:54:27 +02:00
}
2011-08-04 14:27:10 +02:00
break ;
}
2010-10-11 23:35:55 +02:00
case CONDITION_DRUNKENSTATE :
2011-08-04 14:27:10 +02:00
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 > DRUNKEN_SMASHED )
2010-10-11 23:35:55 +02:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid state (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2011-08-04 14:27:10 +02:00
return false ;
2010-10-11 23:35:55 +02:00
}
2011-08-04 14:27:10 +02:00
break ;
}
2010-10-31 22:10:31 +01:00
case CONDITION_NEAR_CREATURE :
{
2012-02-14 12:46:26 -05:00
if ( ! sObjectMgr -> GetCreatureTemplate ( cond -> ConditionValue1 ))
2010-10-31 22:10:31 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing creature template entry (%u), skipped" , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2010-10-31 22:10:31 +01:00
return false ;
}
break ;
}
case CONDITION_NEAR_GAMEOBJECT :
{
2012-02-14 12:46:26 -05:00
if ( ! sObjectMgr -> GetGameObjectTemplate ( cond -> ConditionValue1 ))
2010-10-31 22:10:31 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing gameobject template entry (%u), skipped." , cond -> ToString (). c_str (), cond -> ConditionValue1 );
2010-10-31 22:10:31 +01:00
return false ;
}
break ;
}
2019-07-21 17:12:34 +02:00
case CONDITION_OBJECT_ENTRY_GUID_LEGACY :
cond -> ConditionType = CONDITION_OBJECT_ENTRY_GUID ;
cond -> ConditionValue1 = Trinity :: Legacy :: ConvertLegacyTypeID ( Trinity :: Legacy :: TypeID ( cond -> ConditionValue1 ));
/* fallthrough */
2014-08-24 00:10:09 +02:00
case CONDITION_OBJECT_ENTRY_GUID :
2012-02-11 15:16:18 +01:00
{
2012-02-14 12:46:26 -05:00
switch ( cond -> ConditionValue1 )
2012-02-11 15:16:18 +01:00
{
case TYPEID_UNIT :
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 && ! sObjectMgr -> GetCreatureTemplate ( cond -> ConditionValue2 ))
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing creature template entry (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
2014-08-24 00:10:09 +02:00
if ( cond -> ConditionValue3 )
{
if ( CreatureData const * creatureData = sObjectMgr -> GetCreatureData ( cond -> ConditionValue3 ))
{
if ( cond -> ConditionValue2 && creatureData -> id != cond -> ConditionValue2 )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has guid %u set but does not match creature entry (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue3 , cond -> ConditionValue2 );
2014-08-24 00:10:09 +02:00
return false ;
}
}
else
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing creature guid (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue3 );
2014-08-24 00:10:09 +02:00
return false ;
}
}
2012-02-11 15:16:18 +01:00
break ;
case TYPEID_GAMEOBJECT :
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 && ! sObjectMgr -> GetGameObjectTemplate ( cond -> ConditionValue2 ))
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing gameobject template entry (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
2014-08-24 00:10:09 +02:00
if ( cond -> ConditionValue3 )
{
2017-05-07 21:48:41 +01:00
if ( GameObjectData const * goData = sObjectMgr -> GetGameObjectData ( cond -> ConditionValue3 ))
2014-08-24 00:10:09 +02:00
{
if ( cond -> ConditionValue2 && goData -> id != cond -> ConditionValue2 )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has guid %u set but does not match gameobject entry (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue3 , cond -> ConditionValue2 );
2014-08-24 00:10:09 +02:00
return false ;
}
}
else
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing gameobject guid (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue3 );
2014-08-24 00:10:09 +02:00
return false ;
}
}
2012-02-11 15:16:18 +01:00
break ;
case TYPEID_PLAYER :
case TYPEID_CORPSE :
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 )
2014-11-20 13:55:26 +01:00
LogUselessConditionValue ( cond , 2 , cond -> ConditionValue2 );
2014-08-24 00:10:09 +02:00
if ( cond -> ConditionValue3 )
2014-11-20 13:55:26 +01:00
LogUselessConditionValue ( cond , 3 , cond -> ConditionValue3 );
2012-02-11 15:16:18 +01:00
break ;
default :
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has wrong typeid set (%u), skipped" , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
2019-07-21 17:12:34 +02:00
case CONDITION_TYPE_MASK_LEGACY :
cond -> ConditionType = CONDITION_TYPE_MASK ;
cond -> ConditionValue1 = Trinity :: Legacy :: ConvertLegacyTypeMask ( cond -> ConditionValue1 );
/* fallthrough */
2012-02-11 15:16:18 +01:00
case CONDITION_TYPE_MASK :
{
2012-02-14 12:46:26 -05:00
if ( ! cond -> ConditionValue1 || ( cond -> ConditionValue1 & ~ ( TYPEMASK_UNIT | TYPEMASK_PLAYER | TYPEMASK_GAMEOBJECT | TYPEMASK_CORPSE )))
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid typemask set (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
case CONDITION_RELATION_TO :
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 >= cond -> GetMaxAvailableConditionTargets ())
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ConditionValue1(ConditionTarget selection) (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 == cond -> ConditionTarget )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has ConditionValue1(ConditionTarget selection) set to self (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 >= RELATION_MAX )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ConditionValue2(RelationType) (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
case CONDITION_REACTION_TO :
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 >= cond -> GetMaxAvailableConditionTargets ())
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ConditionValue1(ConditionTarget selection) (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 == cond -> ConditionTarget )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has ConditionValue1(ConditionTarget selection) set to self (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( ! cond -> ConditionValue2 )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ConditionValue2(rankMask) (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
case CONDITION_DISTANCE_TO :
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 >= cond -> GetMaxAvailableConditionTargets ())
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ConditionValue1(ConditionTarget selection) (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 == cond -> ConditionTarget )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has ConditionValue1(ConditionTarget selection) set to self (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue3 >= COMP_TYPE_MAX )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ComparisionType (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue3 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
case CONDITION_HP_VAL :
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 >= COMP_TYPE_MAX )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ComparisionType (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
case CONDITION_HP_PCT :
{
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue1 > 100 )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has too big percent value (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 15:16:18 +01:00
return false ;
}
2012-02-14 12:46:26 -05:00
if ( cond -> ConditionValue2 >= COMP_TYPE_MAX )
2012-02-11 15:16:18 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has invalid ComparisionType (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue2 );
2012-02-11 15:16:18 +01:00
return false ;
}
break ;
}
2012-02-11 19:46:41 +00:00
case CONDITION_WORLD_STATE :
{
2012-02-14 12:46:26 -05:00
if ( ! sWorld -> getWorldState ( cond -> ConditionValue1 ))
2012-02-11 19:46:41 +00:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing world state in value1 (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-02-11 19:46:41 +00:00
return false ;
}
break ;
}
2014-06-07 19:42:08 -05:00
case CONDITION_PHASEID :
2012-02-11 19:46:41 +00:00
{
2014-06-07 19:42:08 -05:00
if ( ! sPhaseStore . LookupEntry ( cond -> ConditionValue1 ))
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has nonexistent phaseid in value1 (%u), skipped" , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2014-06-07 19:42:08 -05:00
return false ;
}
2012-02-11 19:46:41 +00:00
break ;
}
2012-04-07 23:15:16 +01:00
case CONDITION_TITLE :
{
CharTitlesEntry const * titleEntry = sCharTitlesStore . LookupEntry ( cond -> ConditionValue1 );
if ( ! titleEntry )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing title in value1 (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2012-04-07 23:15:16 +01:00
return false ;
}
break ;
}
2018-09-15 17:55:26 +02:00
case CONDITION_SPAWNMASK_DEPRECATED :
2012-09-15 20:27:01 +02:00
{
2018-09-15 17:55:26 +02:00
TC_LOG_ERROR ( "sql.sql" , "%s using deprecated condition type CONDITION_SPAWNMASK." , cond -> ToString ( true ). c_str ());
return false ;
2012-09-15 20:27:01 +02:00
}
2013-01-11 23:34:08 +01:00
case CONDITION_UNIT_STATE :
{
2014-03-20 21:34:05 +01:00
if ( ! ( cond -> ConditionValue1 & UNIT_STATE_ALL_STATE_SUPPORTED ))
2013-01-11 23:34:08 +01:00
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing UnitState in value1 (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2013-01-11 23:34:08 +01:00
return false ;
}
break ;
}
2013-05-25 07:51:23 +01:00
case CONDITION_CREATURE_TYPE :
{
if ( ! cond -> ConditionValue1 || cond -> ConditionValue1 > CREATURE_TYPE_GAS_CLOUD )
{
2014-11-20 13:55:26 +01:00
TC_LOG_ERROR ( "sql.sql" , "%s has non existing CreatureType in value1 (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
2013-05-25 07:51:23 +01:00
return false ;
}
break ;
}
2015-03-17 12:42:35 +00:00
case CONDITION_REALM_ACHIEVEMENT :
{
2016-05-07 01:16:29 +02:00
AchievementEntry const * achievement = sAchievementStore . LookupEntry ( cond -> ConditionValue1 );
2015-03-17 12:42:35 +00:00
if ( ! achievement )
{
TC_LOG_ERROR ( "sql.sql" , "%s has non existing realm first achivement id (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
return false ;
}
break ;
}
2016-02-25 19:00:20 +01:00
case CONDITION_STAND_STATE :
{
bool valid = false ;
switch ( cond -> ConditionValue1 )
{
case 0 :
valid = cond -> ConditionValue2 <= UNIT_STAND_STATE_SUBMERGED ;
break ;
case 1 :
valid = cond -> ConditionValue2 <= 1 ;
break ;
default :
valid = false ;
break ;
}
if ( ! valid )
{
TC_LOG_ERROR ( "sql.sql" , "%s has non-existing stand state (%u,%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 , cond -> ConditionValue2 );
return false ;
}
break ;
}
2017-03-20 08:54:29 +01:00
case CONDITION_QUEST_OBJECTIVE_COMPLETE :
{
QuestObjective const * obj = sObjectMgr -> GetQuestObjective ( cond -> ConditionValue1 );
if ( ! obj )
{
TC_LOG_ERROR ( "sql.sql" , "%s points to non-existing quest objective (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
return false ;
}
break ;
}
2016-08-06 20:20:07 +02:00
case CONDITION_PET_TYPE :
if ( cond -> ConditionValue1 >= ( 1 << MAX_PET_TYPE ))
{
TC_LOG_ERROR ( "sql.sql" , "%s has non-existing pet type %u, skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
return false ;
}
break ;
2017-11-05 12:33:07 +01:00
case CONDITION_INSTANCE_INFO :
case CONDITION_AREAID :
case CONDITION_ALIVE :
2016-08-06 17:08:52 +02:00
case CONDITION_IN_WATER :
2017-11-05 12:33:07 +01:00
case CONDITION_TERRAIN_SWAP :
2016-08-06 17:08:52 +02:00
case CONDITION_CHARMED :
2016-08-20 14:36:26 +02:00
case CONDITION_TAXI :
2010-08-21 20:55:31 +02:00
break ;
2018-09-15 17:55:26 +02:00
case CONDITION_DIFFICULTY_ID :
if ( ! sDifficultyStore . LookupEntry ( cond -> ConditionValue1 ))
{
TC_LOG_ERROR ( "sql.sql" , "%s has non existing difficulty in value1 (%u), skipped." , cond -> ToString ( true ). c_str (), cond -> ConditionValue1 );
return false ;
}
break ;
2017-11-05 12:33:07 +01:00
default :
TC_LOG_ERROR ( "sql.sql" , "%s Invalid ConditionType in `condition` table, ignoring." , cond -> ToString (). c_str ());
return false ;
}
if ( cond -> ConditionTarget >= cond -> GetMaxAvailableConditionTargets ())
{
TC_LOG_ERROR ( "sql.sql" , "%s in `condition` table, has incorrect ConditionTarget set, ignoring." , cond -> ToString ( true ). c_str ());
return false ;
2010-06-04 23:24:48 +02:00
}
2014-11-20 13:55:26 +01:00
if ( cond -> ConditionValue1 && ! StaticConditionTypeData [ cond -> ConditionType ]. HasConditionValue1 )
LogUselessConditionValue ( cond , 1 , cond -> ConditionValue1 );
if ( cond -> ConditionValue2 && ! StaticConditionTypeData [ cond -> ConditionType ]. HasConditionValue2 )
LogUselessConditionValue ( cond , 2 , cond -> ConditionValue2 );
if ( cond -> ConditionValue3 && ! StaticConditionTypeData [ cond -> ConditionType ]. HasConditionValue3 )
LogUselessConditionValue ( cond , 3 , cond -> ConditionValue3 );
2010-06-04 23:24:48 +02:00
return true ;
}
2010-06-11 01:25:10 +02:00
2014-11-20 13:55:26 +01:00
void ConditionMgr :: LogUselessConditionValue ( Condition * cond , uint8 index , uint32 value )
{
TC_LOG_ERROR ( "sql.sql" , "%s has useless data in ConditionValue%u (%u)!" , cond -> ToString ( true ). c_str (), index , value );
}
2010-06-11 01:25:10 +02:00
void ConditionMgr :: Clean ()
{
2012-01-29 13:49:19 -05:00
for ( ConditionReferenceContainer :: iterator itr = ConditionReferenceStore . begin (); itr != ConditionReferenceStore . end (); ++ itr )
2015-10-25 10:59:58 +01:00
for ( ConditionContainer :: const_iterator it = itr -> second . begin (); it != itr -> second . end (); ++ it )
2010-06-11 01:25:10 +02:00
delete * it ;
2010-08-06 19:23:43 +02:00
2012-01-29 13:49:19 -05:00
ConditionReferenceStore . clear ();
2015-10-25 13:35:45 +01:00
for ( uint32 i = 0 ; i < CONDITION_SOURCE_TYPE_MAX ; ++ i )
{
for ( ConditionsByEntryMap :: iterator it = ConditionStore [ i ]. begin (); it != ConditionStore [ i ]. end (); ++ it )
2015-10-31 00:05:09 +01:00
for ( ConditionContainer :: const_iterator itr = it -> second . begin (); itr != it -> second . end (); ++ itr )
delete * itr ;
2012-01-29 13:49:19 -05:00
2015-10-25 13:35:45 +01:00
ConditionStore [ i ]. clear ();
}
2010-06-11 01:25:10 +02:00
2015-10-25 10:59:58 +01:00
for ( ConditionEntriesByCreatureIdMap :: iterator itr = VehicleSpellConditionStore . begin (); itr != VehicleSpellConditionStore . end (); ++ itr )
for ( ConditionsByEntryMap :: iterator it = itr -> second . begin (); it != itr -> second . end (); ++ it )
for ( ConditionContainer :: const_iterator i = it -> second . begin (); i != it -> second . end (); ++ i )
2010-06-11 01:25:10 +02:00
delete * i ;
2010-08-06 19:23:43 +02:00
2012-01-29 13:49:19 -05:00
VehicleSpellConditionStore . clear ();
2010-06-11 01:25:10 +02:00
2012-01-29 13:49:19 -05:00
for ( SmartEventConditionContainer :: iterator itr = SmartEventConditionStore . begin (); itr != SmartEventConditionStore . end (); ++ itr )
2015-10-25 10:59:58 +01:00
for ( ConditionsByEntryMap :: iterator it = itr -> second . begin (); it != itr -> second . end (); ++ it )
for ( ConditionContainer :: const_iterator i = it -> second . begin (); i != it -> second . end (); ++ i )
2010-10-22 22:45:11 +02:00
delete * i ;
2012-01-29 13:49:19 -05:00
SmartEventConditionStore . clear ();
2010-10-22 22:45:11 +02:00
2015-10-25 10:59:58 +01:00
for ( ConditionEntriesByCreatureIdMap :: iterator itr = SpellClickEventConditionStore . begin (); itr != SpellClickEventConditionStore . end (); ++ itr )
for ( ConditionsByEntryMap :: iterator it = itr -> second . begin (); it != itr -> second . end (); ++ it )
for ( ConditionContainer :: const_iterator i = it -> second . begin (); i != it -> second . end (); ++ i )
2012-03-01 14:30:19 +01:00
delete * i ;
SpellClickEventConditionStore . clear ();
2015-10-25 10:59:58 +01:00
for ( ConditionEntriesByCreatureIdMap :: iterator itr = NpcVendorConditionContainerStore . begin (); itr != NpcVendorConditionContainerStore . end (); ++ itr )
for ( ConditionsByEntryMap :: iterator it = itr -> second . begin (); it != itr -> second . end (); ++ it )
for ( ConditionContainer :: const_iterator i = it -> second . begin (); i != it -> second . end (); ++ i )
2012-12-01 01:49:44 +01:00
delete * i ;
NpcVendorConditionContainerStore . clear ();
2010-06-11 01:25:10 +02:00
// this is a BIG hack, feel free to fix it if you can figure out the ConditionMgr ;)
2015-10-25 11:38:38 +01:00
for ( std :: vector < Condition *>:: const_iterator itr = AllocatedMemoryStore . begin (); itr != AllocatedMemoryStore . end (); ++ itr )
2010-06-11 01:25:10 +02:00
delete * itr ;
2010-08-06 19:23:43 +02:00
2012-01-29 13:49:19 -05:00
AllocatedMemoryStore . clear ();
2010-06-11 01:25:10 +02:00
}
2016-01-03 00:40:18 +01:00
inline bool PlayerConditionCompare ( int32 comparisonType , int32 value1 , int32 value2 )
{
switch ( comparisonType )
{
case 1 :
return value1 == value2 ;
case 2 :
return value1 != value2 ;
case 3 :
return value1 > value2 ;
case 4 :
return value1 >= value2 ;
case 5 :
return value1 < value2 ;
case 6 :
return value1 <= value2 ;
default :
break ;
}
return false ;
}
template < std :: size_t N >
inline bool PlayerConditionLogic ( uint32 logic , std :: array < bool , N >& results )
{
static_assert ( N < 16 , "Logic array size must be equal to or less than 16" );
for ( std :: size_t i = 0 ; i < results . size (); ++ i )
if (( logic >> ( 16 + i )) & 1 )
results [ i ] ^= true ;
bool result = results [ 0 ];
for ( std :: size_t i = 1 ; i < results . size (); ++ i )
{
switch (( logic >> ( 2 * ( i - 1 ))) & 3 )
{
case 1 :
result = result && results [ i ];
break ;
case 2 :
result = result || results [ i ];
break ;
default :
break ;
}
}
return result ;
}
2019-11-14 00:38:43 +01:00
uint32 ConditionMgr :: GetPlayerConditionLfgValue ( Player const * player , PlayerConditionLfgStatus status )
{
Group const * group = player -> GetGroup ();
if ( ! group )
return 0 ;
switch ( status )
{
case PlayerConditionLfgStatus :: InLFGDungeon :
return sLFGMgr -> inLfgDungeonMap ( player -> GetGUID (), player -> GetMapId (), player -> GetMap () -> GetDifficultyID ()) ? 1 : 0 ;
case PlayerConditionLfgStatus :: InLFGRandomDungeon :
return sLFGMgr -> inLfgDungeonMap ( player -> GetGUID (), player -> GetMapId (), player -> GetMap () -> GetDifficultyID ()) &&
sLFGMgr -> selectedRandomLfgDungeon ( player -> GetGUID ()) ? 1 : 0 ;
case PlayerConditionLfgStatus :: InLFGFirstRandomDungeon :
{
if ( ! sLFGMgr -> inLfgDungeonMap ( player -> GetGUID (), player -> GetMapId (), player -> GetMap () -> GetDifficultyID ()))
return 0 ;
uint32 selectedRandomDungeon = sLFGMgr -> GetSelectedRandomDungeon ( player -> GetGUID ());
if ( ! selectedRandomDungeon )
return 0 ;
if ( lfg :: LfgReward const * reward = sLFGMgr -> GetRandomDungeonReward ( selectedRandomDungeon , player -> getLevel ()))
if ( Quest const * quest = sObjectMgr -> GetQuestTemplate ( reward -> firstQuest ))
if ( player -> CanRewardQuest ( quest , false ))
return 1 ;
return 0 ;
}
case PlayerConditionLfgStatus :: PartialClear :
break ;
case PlayerConditionLfgStatus :: StrangerCount :
break ;
case PlayerConditionLfgStatus :: VoteKickCount :
break ;
case PlayerConditionLfgStatus :: BootCount :
break ;
case PlayerConditionLfgStatus :: GearDiff :
break ;
default :
break ;
}
return 0 ;
}
2016-06-08 21:46:08 +02:00
bool ConditionMgr :: IsPlayerMeetingCondition ( Player const * player , PlayerConditionEntry const * condition )
2016-01-03 00:40:18 +01:00
{
2020-12-01 21:08:06 +01:00
if ( Optional < ContentTuningLevels > levels = sDB2Manager . GetContentTuningData ( condition -> ContentTuningID , player -> m_playerData -> CtrOptions -> ContentTuningConditionMask ))
{
uint8 minLevel = condition -> Flags & 0x800 ? levels -> MinLevelWithDelta : levels -> MinLevel ;
uint8 maxLevel = 0 ;
if ( ! ( condition -> Flags & 0x20 ))
maxLevel = condition -> Flags & 0x800 ? levels -> MaxLevelWithDelta : levels -> MaxLevel ;
2016-01-03 00:40:18 +01:00
2020-12-01 21:08:06 +01:00
if ( condition -> Flags & 0x80 )
{
if ( minLevel && player -> getLevel () >= minLevel && ( ! maxLevel || player -> getLevel () <= maxLevel ))
return false ;
if ( maxLevel && player -> getLevel () <= maxLevel && ( ! minLevel || player -> getLevel () >= minLevel ))
return false ;
}
else
{
if ( minLevel && player -> getLevel () < minLevel )
return false ;
if ( maxLevel && player -> getLevel () > maxLevel )
return false ;
}
}
2016-01-03 00:40:18 +01:00
2020-03-30 19:06:11 +02:00
if ( condition -> RaceMask && ! condition -> RaceMask . HasRace ( player -> getRace ()))
2016-01-03 00:40:18 +01:00
return false ;
if ( condition -> ClassMask && ! ( player -> getClassMask () & condition -> ClassMask ))
return false ;
if ( condition -> Gender >= 0 && player -> getGender () != condition -> Gender )
return false ;
2020-12-01 21:08:06 +01:00
if ( condition -> NativeGender >= 0 && player -> GetNativeSex () != condition -> NativeGender )
2016-01-03 00:40:18 +01:00
return false ;
if ( condition -> PowerType != - 1 && condition -> PowerTypeComp )
{
int32 requiredPowerValue = condition -> Flags & 4 ? player -> GetMaxPower ( Powers ( condition -> PowerType )) : condition -> PowerTypeValue ;
if ( ! PlayerConditionCompare ( condition -> PowerTypeComp , player -> GetPower ( Powers ( condition -> PowerType )), requiredPowerValue ))
return false ;
}
if ( condition -> ChrSpecializationIndex >= 0 || condition -> ChrSpecializationRole >= 0 )
{
2019-06-03 20:40:34 +02:00
if ( ChrSpecializationEntry const * spec = sChrSpecializationStore . LookupEntry ( player -> GetPrimarySpecialization ()))
2016-01-03 00:40:18 +01:00
{
2018-03-12 18:20:26 +01:00
if ( condition -> ChrSpecializationIndex >= 0 && spec -> OrderIndex != condition -> ChrSpecializationIndex )
2016-01-03 00:40:18 +01:00
return false ;
2018-03-12 18:20:26 +01:00
if ( condition -> ChrSpecializationRole >= 0 && spec -> Role != condition -> ChrSpecializationRole )
2016-01-03 00:40:18 +01:00
return false ;
}
}
if ( condition -> SkillID [ 0 ] || condition -> SkillID [ 1 ] || condition -> SkillID [ 2 ] || condition -> SkillID [ 3 ])
{
using SkillCount = std :: extent < decltype ( condition -> SkillID ) > ;
std :: array < bool , SkillCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < SkillCount :: value ; ++ i )
{
if ( condition -> SkillID [ i ])
{
uint16 skillValue = player -> GetSkillValue ( condition -> SkillID [ i ]);
results [ i ] = skillValue != 0 && skillValue > condition -> MinSkill [ i ] && skillValue < condition -> MaxSkill [ i ];
}
}
if ( ! PlayerConditionLogic ( condition -> SkillLogic , results ))
return false ;
}
if ( condition -> LanguageID )
{
2021-05-02 00:44:31 +02:00
int32 languageSkill = 0 ;
if ( player -> HasAuraTypeWithMiscvalue ( SPELL_AURA_COMPREHEND_LANGUAGE , condition -> LanguageID ))
languageSkill = 300 ;
else
2016-01-03 00:40:18 +01:00
{
2021-05-02 00:44:31 +02:00
for ( std :: pair < uint32 const , LanguageDesc > const & languageDesc : sLanguageMgr -> GetLanguageDescById ( Language ( condition -> LanguageID )))
languageSkill = std :: max < int32 > ( languageSkill , player -> GetSkillValue ( languageDesc . second . SkillId ));
}
2016-01-03 00:40:18 +01:00
2021-05-02 00:44:31 +02:00
if ( condition -> MinLanguage && languageSkill < condition -> MinLanguage )
return false ;
2016-01-03 00:40:18 +01:00
2021-05-02 00:44:31 +02:00
if ( condition -> MaxLanguage && languageSkill > condition -> MaxLanguage )
return false ;
2016-01-03 00:40:18 +01:00
}
if ( condition -> MinFactionID [ 0 ] && condition -> MinFactionID [ 1 ] && condition -> MinFactionID [ 2 ] && condition -> MaxFactionID )
{
if ( ! condition -> MinFactionID [ 0 ] && ! condition -> MinFactionID [ 1 ] && ! condition -> MinFactionID [ 2 ])
{
if ( ReputationRank const * forcedRank = player -> GetReputationMgr (). GetForcedRankIfAny ( condition -> MaxFactionID ))
{
2016-01-04 00:24:33 +01:00
if ( * forcedRank > ReputationRank ( condition -> MaxReputation ))
2016-01-03 00:40:18 +01:00
return false ;
}
2016-01-04 00:24:33 +01:00
else if ( player -> GetReputationRank ( condition -> MaxFactionID ) > ReputationRank ( condition -> MaxReputation ))
2016-01-03 00:40:18 +01:00
return false ;
}
else
{
using FactionCount = std :: extent < decltype ( condition -> MinFactionID ) > ;
std :: array < bool , FactionCount :: value + 1 > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < FactionCount :: value ; ++ i )
{
if ( condition -> MinFactionID [ i ])
{
if ( ReputationRank const * forcedRank = player -> GetReputationMgr (). GetForcedRankIfAny ( condition -> MinFactionID [ i ]))
2016-01-04 00:24:33 +01:00
results [ i ] = * forcedRank >= ReputationRank ( condition -> MinReputation [ i ]);
2016-01-03 00:40:18 +01:00
else
2016-01-04 00:24:33 +01:00
results [ i ] = player -> GetReputationRank ( condition -> MinFactionID [ i ]) >= ReputationRank ( condition -> MinReputation [ i ]);
2016-01-03 00:40:18 +01:00
}
}
if ( ReputationRank const * forcedRank = player -> GetReputationMgr (). GetForcedRankIfAny ( condition -> MaxFactionID ))
2016-01-04 00:24:33 +01:00
results [ 3 ] = * forcedRank <= ReputationRank ( condition -> MaxReputation );
2016-01-03 00:40:18 +01:00
else
2016-01-04 00:24:33 +01:00
results [ 3 ] = player -> GetReputationRank ( condition -> MaxFactionID ) <= ReputationRank ( condition -> MaxReputation );
2016-01-03 00:40:18 +01:00
if ( ! PlayerConditionLogic ( condition -> ReputationLogic , results ))
return false ;
}
}
2019-06-03 20:40:34 +02:00
if ( condition -> PvpMedal && ! (( 1 << ( condition -> PvpMedal - 1 )) & * player -> m_activePlayerData -> PvpMedals ))
2016-01-03 00:40:18 +01:00
return false ;
2019-06-03 20:40:34 +02:00
if ( condition -> LifetimeMaxPVPRank && player -> m_activePlayerData -> LifetimeMaxRank != condition -> LifetimeMaxPVPRank )
2016-01-03 00:40:18 +01:00
return false ;
2017-04-06 23:39:34 +02:00
if ( condition -> MovementFlags [ 0 ] && ! ( player -> GetUnitMovementFlags () & condition -> MovementFlags [ 0 ]))
return false ;
if ( condition -> MovementFlags [ 1 ] && ! ( player -> GetExtraUnitMovementFlags () & condition -> MovementFlags [ 1 ]))
return false ;
2018-03-12 18:20:26 +01:00
if ( condition -> WeaponSubclassMask )
2017-04-06 23:39:34 +02:00
{
Item * mainHand = player -> GetItemByPos ( INVENTORY_SLOT_BAG_0 , EQUIPMENT_SLOT_MAINHAND );
2018-03-12 18:20:26 +01:00
if ( ! mainHand || ! (( 1 << mainHand -> GetTemplate () -> GetSubClass ()) & condition -> WeaponSubclassMask ))
2017-04-06 23:39:34 +02:00
return false ;
}
2016-01-03 00:40:18 +01:00
if ( condition -> PartyStatus )
{
2016-06-08 21:46:08 +02:00
Group const * group = player -> GetGroup ();
2016-01-03 00:40:18 +01:00
switch ( condition -> PartyStatus )
{
case 1 :
if ( group )
return false ;
break ;
case 2 :
if ( ! group )
return false ;
break ;
case 3 :
if ( ! group || group -> isRaidGroup ())
return false ;
break ;
case 4 :
if ( ! group || ! group -> isRaidGroup ())
return false ;
break ;
case 5 :
if ( group && group -> isRaidGroup ())
return false ;
break ;
default :
break ;
}
}
if ( condition -> PrevQuestID [ 0 ])
{
using PrevQuestCount = std :: extent < decltype ( condition -> PrevQuestID ) > ;
std :: array < bool , PrevQuestCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < PrevQuestCount :: value ; ++ i )
if ( uint32 questBit = sDB2Manager . GetQuestUniqueBitFlag ( condition -> PrevQuestID [ i ]))
2019-06-03 20:40:34 +02:00
results [ i ] = ( player -> m_activePlayerData -> QuestCompleted [(( questBit - 1 ) >> 6 )] & ( UI64LIT ( 1 ) << (( questBit - 1 ) & 63 ))) != 0 ;
2016-01-03 00:40:18 +01:00
if ( ! PlayerConditionLogic ( condition -> PrevQuestLogic , results ))
return false ;
}
if ( condition -> CurrQuestID [ 0 ])
{
using CurrQuestCount = std :: extent < decltype ( condition -> CurrQuestID ) > ;
std :: array < bool , CurrQuestCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < CurrQuestCount :: value ; ++ i )
if ( condition -> CurrQuestID [ i ])
results [ i ] = player -> FindQuestSlot ( condition -> CurrQuestID [ i ]) != MAX_QUEST_LOG_SIZE ;
if ( ! PlayerConditionLogic ( condition -> CurrQuestLogic , results ))
return false ;
}
if ( condition -> CurrentCompletedQuestID [ 0 ])
{
using CurrentCompletedQuestCount = std :: extent < decltype ( condition -> CurrentCompletedQuestID ) > ;
std :: array < bool , CurrentCompletedQuestCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < CurrentCompletedQuestCount :: value ; ++ i )
if ( condition -> CurrentCompletedQuestID [ i ])
results [ i ] = player -> GetQuestStatus ( condition -> CurrentCompletedQuestID [ i ]) == QUEST_STATUS_COMPLETE ;
if ( ! PlayerConditionLogic ( condition -> CurrentCompletedQuestLogic , results ))
return false ;
}
if ( condition -> SpellID [ 0 ])
{
using SpellCount = std :: extent < decltype ( condition -> SpellID ) > ;
std :: array < bool , SpellCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < SpellCount :: value ; ++ i )
if ( condition -> SpellID [ i ])
results [ i ] = player -> HasSpell ( condition -> SpellID [ i ]);
if ( ! PlayerConditionLogic ( condition -> SpellLogic , results ))
return false ;
}
if ( condition -> ItemID [ 0 ])
{
using ItemCount = std :: extent < decltype ( condition -> ItemID ) > ;
std :: array < bool , ItemCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < ItemCount :: value ; ++ i )
if ( condition -> ItemID [ i ])
results [ i ] = player -> GetItemCount ( condition -> ItemID [ i ], condition -> ItemFlags != 0 ) >= condition -> ItemCount [ i ];
if ( ! PlayerConditionLogic ( condition -> ItemLogic , results ))
return false ;
}
if ( condition -> CurrencyID [ 0 ])
{
using CurrencyCount = std :: extent < decltype ( condition -> CurrencyID ) > ;
std :: array < bool , CurrencyCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < CurrencyCount :: value ; ++ i )
if ( condition -> CurrencyID [ i ])
results [ i ] = player -> GetCurrency ( condition -> CurrencyID [ i ]) >= condition -> CurrencyCount [ i ];
if ( ! PlayerConditionLogic ( condition -> CurrencyLogic , results ))
return false ;
}
if ( condition -> Explored [ 0 ] || condition -> Explored [ 1 ])
{
using ExploredCount = std :: extent < decltype ( condition -> Explored ) > ;
for ( std :: size_t i = 0 ; i < ExploredCount :: value ; ++ i )
{
2016-02-02 19:13:04 +01:00
if ( AreaTableEntry const * area = sAreaTableStore . LookupEntry ( condition -> Explored [ i ]))
2019-06-03 20:40:34 +02:00
if ( area -> AreaBit != - 1 && ! ( player -> m_activePlayerData -> ExploredZones [ area -> AreaBit / 64 ] & ( UI64LIT ( 1 ) << ( uint32 ( area -> AreaBit ) % 64 ))))
2016-01-03 00:40:18 +01:00
return false ;
}
}
if ( condition -> AuraSpellID [ 0 ])
{
using AuraCount = std :: extent < decltype ( condition -> AuraSpellID ) > ;
std :: array < bool , AuraCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < AuraCount :: value ; ++ i )
2016-01-24 15:56:10 +01:00
{
2016-01-03 00:40:18 +01:00
if ( condition -> AuraSpellID [ i ])
2016-01-24 15:56:10 +01:00
{
2018-03-12 18:20:26 +01:00
if ( condition -> AuraStacks [ i ])
results [ i ] = player -> GetAuraCount ( condition -> AuraSpellID [ i ]) >= condition -> AuraStacks [ i ];
2016-01-24 15:56:10 +01:00
else
results [ i ] = player -> HasAura ( condition -> AuraSpellID [ i ]);
}
}
2016-01-03 00:40:18 +01:00
if ( ! PlayerConditionLogic ( condition -> AuraSpellLogic , results ))
return false ;
}
2021-06-04 21:47:43 +02:00
if ( condition -> Time [ 0 ])
{
ByteBuffer unpacker ;
unpacker << condition -> Time [ 0 ];
time_t from = unpacker . ReadPackedTime ();
unpacker . rpos ( 0 );
unpacker . wpos ( 0 );
unpacker << condition -> Time [ 1 ];
time_t to = unpacker . ReadPackedTime ();
if ( GameTime :: GetGameTime () < from || GameTime :: GetGameTime () > to )
return false ;
}
2018-10-23 16:20:45 +02:00
if ( condition -> WorldStateExpressionID )
{
WorldStateExpressionEntry const * worldStateExpression = sWorldStateExpressionStore . LookupEntry ( condition -> WorldStateExpressionID );
if ( ! worldStateExpression )
return false ;
if ( ! IsPlayerMeetingExpression ( player , worldStateExpression ))
return false ;
}
2021-06-04 21:47:43 +02:00
if ( condition -> WeatherID )
if ( player -> GetMap () -> GetZoneWeather ( player -> GetZoneId ()) != WeatherState ( condition -> WeatherID ))
return false ;
2016-01-03 00:40:18 +01:00
if ( condition -> Achievement [ 0 ])
{
using AchievementCount = std :: extent < decltype ( condition -> Achievement ) > ;
std :: array < bool , AchievementCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < AchievementCount :: value ; ++ i )
{
if ( condition -> Achievement [ i ])
{
// if (condition->Flags & 2) { any character on account completed it } else { current character only }
// TODO: part of accountwide achievements
results [ i ] = player -> HasAchieved ( condition -> Achievement [ i ]);
}
}
if ( ! PlayerConditionLogic ( condition -> AchievementLogic , results ))
return false ;
}
2019-11-14 00:38:43 +01:00
if ( condition -> LfgStatus [ 0 ])
{
using LfgCount = std :: extent < decltype ( condition -> LfgStatus ) > ;
std :: array < bool , LfgCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < LfgCount :: value ; ++ i )
if ( condition -> LfgStatus [ i ])
results [ i ] = PlayerConditionCompare ( condition -> LfgCompare [ i ],
GetPlayerConditionLfgValue ( player , PlayerConditionLfgStatus ( condition -> LfgStatus [ i ])),
condition -> LfgValue [ i ]);
if ( ! PlayerConditionLogic ( condition -> LfgLogic , results ))
return false ;
}
2016-01-03 00:40:18 +01:00
if ( condition -> AreaID [ 0 ])
{
using AreaCount = std :: extent < decltype ( condition -> AreaID ) > ;
std :: array < bool , AreaCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < AreaCount :: value ; ++ i )
if ( condition -> AreaID [ i ])
results [ i ] = player -> GetAreaId () == condition -> AreaID [ i ] || player -> GetZoneId () == condition -> AreaID [ i ];
if ( ! PlayerConditionLogic ( condition -> AreaLogic , results ))
return false ;
}
if ( condition -> MinExpansionLevel != - 1 && player -> GetSession () -> GetExpansion () < condition -> MinExpansionLevel )
return false ;
if ( condition -> MaxExpansionLevel != - 1 && player -> GetSession () -> GetExpansion () > condition -> MaxExpansionLevel )
return false ;
if ( condition -> MinExpansionLevel != - 1 && condition -> MinExpansionTier != - 1 && ! player -> IsGameMaster ()
2016-01-04 00:24:33 +01:00
&& (( condition -> MinExpansionLevel == int32 ( sWorld -> getIntConfig ( CONFIG_EXPANSION )) && condition -> MinExpansionTier > 0 ) /*TODO: implement tier*/
|| condition -> MinExpansionLevel > int32 ( sWorld -> getIntConfig ( CONFIG_EXPANSION ))))
2016-01-03 00:40:18 +01:00
return false ;
2018-01-28 11:37:20 +01:00
if ( condition -> PhaseID || condition -> PhaseGroupID || condition -> PhaseUseFlags )
if ( ! PhasingHandler :: InDbPhaseShift ( player , condition -> PhaseUseFlags , condition -> PhaseID , condition -> PhaseGroupID ))
2016-01-03 00:40:18 +01:00
return false ;
if ( condition -> QuestKillID )
{
Quest const * quest = sObjectMgr -> GetQuestTemplate ( condition -> QuestKillID );
2021-05-09 20:21:32 +02:00
uint16 questSlot = player -> FindQuestSlot ( condition -> QuestKillID );
if ( quest && player -> GetQuestStatus ( condition -> QuestKillID ) != QUEST_STATUS_COMPLETE && questSlot < MAX_QUEST_LOG_SIZE )
2016-01-03 00:40:18 +01:00
{
using QuestKillCount = std :: extent < decltype ( condition -> QuestKillMonster ) > ;
std :: array < bool , QuestKillCount :: value > results ;
results . fill ( true );
for ( std :: size_t i = 0 ; i < QuestKillCount :: value ; ++ i )
{
if ( condition -> QuestKillMonster [ i ])
{
auto objectiveItr = std :: find_if ( quest -> GetObjectives (). begin (), quest -> GetObjectives (). end (), [ condition , i ]( QuestObjective const & objective ) -> bool
{
return objective . Type == QUEST_OBJECTIVE_MONSTER && uint32 ( objective . ObjectID ) == condition -> QuestKillMonster [ i ];
});
if ( objectiveItr != quest -> GetObjectives (). end ())
2021-05-09 20:21:32 +02:00
results [ i ] = player -> GetQuestSlotObjectiveData ( questSlot , * objectiveItr ) >= objectiveItr -> Amount ;
2016-01-03 00:40:18 +01:00
}
}
if ( ! PlayerConditionLogic ( condition -> QuestKillLogic , results ))
return false ;
}
}
2019-06-03 20:40:34 +02:00
if ( condition -> MinAvgItemLevel && int32 ( std :: floor ( player -> m_playerData -> AvgItemLevel [ 0 ])) < condition -> MinAvgItemLevel )
2016-01-03 00:40:18 +01:00
return false ;
2019-06-03 20:40:34 +02:00
if ( condition -> MaxAvgItemLevel && int32 ( std :: floor ( player -> m_playerData -> AvgItemLevel [ 0 ])) > condition -> MaxAvgItemLevel )
2016-01-03 00:40:18 +01:00
return false ;
2019-06-03 20:40:34 +02:00
if ( condition -> MinAvgEquippedItemLevel && uint32 ( std :: floor ( player -> m_playerData -> AvgItemLevel [ 1 ])) < condition -> MinAvgEquippedItemLevel )
2016-01-03 00:40:18 +01:00
return false ;
2019-06-03 20:40:34 +02:00
if ( condition -> MaxAvgEquippedItemLevel && uint32 ( std :: floor ( player -> m_playerData -> AvgItemLevel [ 1 ])) > condition -> MaxAvgEquippedItemLevel )
2016-01-03 00:40:18 +01:00
return false ;
2016-01-24 15:56:10 +01:00
if ( condition -> ModifierTreeID && ! player -> ModifierTreeSatisfied ( condition -> ModifierTreeID ))
return false ;
2020-12-01 21:08:06 +01:00
if ( condition -> CovenantID && player -> m_playerData -> CovenantID != condition -> CovenantID )
return false ;
2016-01-03 00:40:18 +01:00
return true ;
}
2018-10-23 16:20:45 +02:00
ByteBuffer HexToBytes ( const std :: string & hex )
{
2020-05-20 17:28:38 +02:00
ByteBuffer buffer ( hex . length () / 2 , ByteBuffer :: Resize {});
2018-10-23 16:20:45 +02:00
HexStrToByteArray ( hex , buffer . contents ());
return buffer ;
}
static int32 ( * const WorldStateExpressionFunctions [ WSE_FUNCTION_MAX ])( Player const * , uint32 , uint32 ) =
{
// WSE_FUNCTION_NONE
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_RANDOM
[]( Player const * /*player*/ , uint32 arg1 , uint32 arg2 ) -> int32
{
return irand ( std :: min ( arg1 , arg2 ), std :: max ( arg1 , arg2 ));
},
// WSE_FUNCTION_MONTH
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return GameTime :: GetDateAndTime () -> tm_mon + 1 ;
},
// WSE_FUNCTION_DAY
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return GameTime :: GetDateAndTime () -> tm_mday + 1 ;
},
// WSE_FUNCTION_TIME_OF_DAY
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
tm const * localTime = GameTime :: GetDateAndTime ();
return localTime -> tm_hour * MINUTE + localTime -> tm_min ;
},
// WSE_FUNCTION_REGION
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return realm . Id . Region ;
},
// WSE_FUNCTION_CLOCK_HOUR
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
uint32 currentHour = GameTime :: GetDateAndTime () -> tm_hour + 1 ;
return currentHour <= 12 ? ( currentHour ? currentHour : 12 ) : currentHour - 12 ;
},
// WSE_FUNCTION_OLD_DIFFICULTY_ID
[]( Player const * player , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
if ( DifficultyEntry const * difficulty = sDifficultyStore . LookupEntry ( player -> GetMap () -> GetDifficultyID ()))
return difficulty -> OldEnumValue ;
return - 1 ;
},
// WSE_FUNCTION_HOLIDAY_START
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_HOLIDAY_LEFT
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_HOLIDAY_ACTIVE
[]( Player const * /*player*/ , uint32 arg1 , uint32 /*arg2*/ ) -> int32
{
return int32 ( IsHolidayActive ( HolidayIds ( arg1 )));
},
// WSE_FUNCTION_TIMER_CURRENT_TIME
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return GameTime :: GetGameTime ();
},
// WSE_FUNCTION_WEEK_NUMBER
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
time_t now = GameTime :: GetGameTime ();
uint32 raidOrigin = 1135695600 ;
if ( Cfg_RegionsEntry const * region = sCfgRegionsStore . LookupEntry ( realm . Id . Region ))
raidOrigin = region -> Raidorigin ;
return ( now - raidOrigin ) / WEEK ;
},
// WSE_FUNCTION_UNK13
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK14
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_DIFFICULTY_ID
[]( Player const * player , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return player -> GetMap () -> GetDifficultyID ();
},
// WSE_FUNCTION_WAR_MODE_ACTIVE
[]( Player const * player , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return player -> HasPlayerFlag ( PLAYER_FLAGS_WAR_MODE_ACTIVE );
},
// WSE_FUNCTION_UNK17
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK18
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK19
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK20
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK21
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_WORLD_STATE_EXPRESSION
[]( Player const * player , uint32 arg1 , uint32 /*arg2*/ ) -> int32
{
if ( WorldStateExpressionEntry const * worldStateExpression = sWorldStateExpressionStore . LookupEntry ( arg1 ))
return ConditionMgr :: IsPlayerMeetingExpression ( player , worldStateExpression );
return 0 ;
},
// WSE_FUNCTION_KEYSTONE_AFFIX
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK24
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK25
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK26
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK27
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_KEYSTONE_LEVEL
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK29
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK30
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK31
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK32
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_MERSENNE_RANDOM
[]( Player const * /*player*/ , uint32 arg1 , uint32 arg2 ) -> int32
{
if ( arg1 == 1 )
return 1 ;
// init with predetermined seed
std :: mt19937 mt ( arg2 ? arg2 : 1 );
return mt () % arg1 + 1 ;
},
// WSE_FUNCTION_UNK34
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK35
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UNK36
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
// WSE_FUNCTION_UI_WIDGET_DATA
[]( Player const * /*player*/ , uint32 /*arg1*/ , uint32 /*arg2*/ ) -> int32
{
return 0 ;
},
};
int32 EvalSingleValue ( ByteBuffer & buffer , Player const * player )
{
WorldStateExpressionValueType valueType = buffer . read < WorldStateExpressionValueType > ();
int32 value = 0 ;
switch ( valueType )
{
case WorldStateExpressionValueType :: Constant :
{
value = buffer . read < int32 > ();
break ;
}
case WorldStateExpressionValueType :: WorldState :
{
uint32 worldStateId = buffer . read < uint32 > ();
value = sWorld -> getWorldState ( worldStateId );
break ;
}
case WorldStateExpressionValueType :: Function :
{
uint32 functionType = buffer . read < uint32 > ();
int32 arg1 = EvalSingleValue ( buffer , player );
int32 arg2 = EvalSingleValue ( buffer , player );
if ( functionType >= WSE_FUNCTION_MAX )
return 0 ;
value = WorldStateExpressionFunctions [ functionType ]( player , arg1 , arg2 );
}
default :
break ;
}
return value ;
}
int32 EvalValue ( ByteBuffer & buffer , Player const * player )
{
int32 leftValue = EvalSingleValue ( buffer , player );
WorldStateExpressionOperatorType operatorType = buffer . read < WorldStateExpressionOperatorType > ();
if ( operatorType == WorldStateExpressionOperatorType :: None )
return leftValue ;
int32 rightValue = EvalSingleValue ( buffer , player );
switch ( operatorType )
{
case WorldStateExpressionOperatorType :: Sum : return leftValue + rightValue ;
case WorldStateExpressionOperatorType :: Substraction : return leftValue - rightValue ;
case WorldStateExpressionOperatorType :: Multiplication : return leftValue * rightValue ;
case WorldStateExpressionOperatorType :: Division : return ! rightValue ? 0 : leftValue / rightValue ;
case WorldStateExpressionOperatorType :: Remainder : return ! rightValue ? 0 : leftValue % rightValue ;
default :
break ;
}
return leftValue ;
}
bool EvalRelOp ( ByteBuffer & buffer , Player const * player )
{
int32 leftValue = EvalValue ( buffer , player );
WorldStateExpressionComparisonType compareLogic = buffer . read < WorldStateExpressionComparisonType > ();
if ( compareLogic == WorldStateExpressionComparisonType :: None )
return leftValue != 0 ;
int32 rightValue = EvalValue ( buffer , player );
switch ( compareLogic )
{
case WorldStateExpressionComparisonType :: Equal : return leftValue == rightValue ;
case WorldStateExpressionComparisonType :: NotEqual : return leftValue != rightValue ;
case WorldStateExpressionComparisonType :: Less : return leftValue < rightValue ;
case WorldStateExpressionComparisonType :: LessOrEqual : return leftValue <= rightValue ;
case WorldStateExpressionComparisonType :: Greater : return leftValue > rightValue ;
case WorldStateExpressionComparisonType :: GreaterOrEqual : return leftValue >= rightValue ;
default :
break ;
}
return false ;
}
bool ConditionMgr :: IsPlayerMeetingExpression ( Player const * player , WorldStateExpressionEntry const * expression )
{
ByteBuffer buffer = HexToBytes ( expression -> Expression );
if ( buffer . empty ())
return false ;
bool enabled = buffer . read < bool > ();
if ( ! enabled )
return false ;
bool finalResult = EvalRelOp ( buffer , player );
WorldStateExpressionLogic resultLogic = buffer . read < WorldStateExpressionLogic > ();
while ( resultLogic != WorldStateExpressionLogic :: None )
{
bool secondResult = EvalRelOp ( buffer , player );
switch ( resultLogic )
{
case WorldStateExpressionLogic :: And : finalResult = finalResult && secondResult ; break ;
case WorldStateExpressionLogic :: Or : finalResult = finalResult || secondResult ; break ;
case WorldStateExpressionLogic :: Xor : finalResult = finalResult != secondResult ; break ;
default :
break ;
}
if ( buffer . rpos () < buffer . size ())
break ;
resultLogic = buffer . read < WorldStateExpressionLogic > ();
}
return finalResult ;
}