2010-10-07 15:35:36 +02:00
/*
2019-01-01 10:13:49 +01:00
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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/>.
2008-10-11 14:16:25 -05:00
*/
2009-10-17 15:51:44 -07:00
2013-03-20 14:18:26 +01:00
#include "Creature.h"
2012-11-20 12:30:30 +01:00
#include "BattlegroundMgr.h"
#include "CellImpl.h"
2017-06-04 01:00:45 +02:00
#include "CombatPackets.h"
2008-10-11 14:16:25 -05:00
#include "Common.h"
#include "CreatureAI.h"
#include "CreatureAISelector.h"
2012-11-20 12:30:30 +01:00
#include "CreatureGroups.h"
#include "DatabaseEnv.h"
2010-06-08 15:50:23 -06:00
#include "Formulas.h"
2012-11-20 12:30:30 +01:00
#include "GameEventMgr.h"
#include "GossipDef.h"
2010-06-08 15:50:23 -06:00
#include "GridNotifiersImpl.h"
2010-11-29 07:50:31 +01:00
#include "Group.h"
2012-11-20 12:30:30 +01:00
#include "GroupMgr.h"
#include "InstanceScript.h"
#include "Log.h"
#include "LootMgr.h"
2017-06-04 01:00:45 +02:00
#include "MiscPackets.h"
#include "MotionMaster.h"
#include "ObjectAccessor.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"
#include "PoolMgr.h"
#include "QuestDef.h"
2017-06-04 01:00:45 +02:00
#include "ScriptedGossip.h"
2012-11-20 12:30:30 +01:00
#include "SpellAuraEffects.h"
#include "SpellMgr.h"
#include "TemporarySummon.h"
2017-06-04 01:00:45 +02:00
#include "Transport.h"
2012-11-20 12:30:30 +01:00
#include "Util.h"
#include "Vehicle.h"
#include "World.h"
#include "WorldPacket.h"
2017-06-04 01:00:45 +02:00
#include <G3D/g3dmath.h>
2010-06-25 00:18:01 +02:00
2017-06-04 01:00:45 +02:00
bool VendorItem :: IsGoldRequired ( ItemTemplate const * pProto ) const
{
return pProto -> GetFlags2 () & ITEM_FLAG2_DONT_IGNORE_BUY_PRICE || ! ExtendedCost ;
}
2012-08-14 18:11:06 +01:00
bool VendorItemData :: RemoveItem ( uint32 item_id , uint8 type )
2008-10-11 14:16:25 -05:00
{
2017-06-04 01:00:45 +02:00
auto newEnd = std :: remove_if ( m_items . begin (), m_items . end (), [ = ]( VendorItem const & vendorItem )
2008-10-11 14:16:25 -05:00
{
2017-06-04 01:00:45 +02:00
return vendorItem . item == item_id && vendorItem . Type == type ;
});
bool found = newEnd != m_items . end ();
m_items . erase ( newEnd , m_items . end ());
2010-04-30 22:35:37 +02:00
return found ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2012-08-14 18:11:06 +01:00
VendorItem const * VendorItemData :: FindItemCostPair ( uint32 item_id , uint32 extendedCost , uint8 type ) const
2008-10-11 14:16:25 -05:00
{
2017-06-04 01:00:45 +02:00
for ( VendorItem const & vendorItem : m_items )
if ( vendorItem . item == item_id && vendorItem . ExtendedCost == extendedCost && vendorItem . Type == type )
return & vendorItem ;
2016-04-02 02:50:44 +02:00
return nullptr ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
CreatureModel const CreatureModel :: DefaultInvisibleModel ( 11686 , 1.0f , 1.0f );
CreatureModel const CreatureModel :: DefaultVisibleModel ( 17519 , 1.0f , 1.0f );
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
CreatureModel const * CreatureTemplate :: GetModelByIdx ( uint32 idx ) const
2008-10-27 11:48:45 -05:00
{
2018-11-07 20:23:30 +01:00
return idx < Models . size () ? & Models [ idx ] : nullptr ;
2008-10-27 11:48:45 -05:00
}
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
CreatureModel const * CreatureTemplate :: GetRandomValidModel () const
2015-12-05 18:47:35 +01:00
{
2018-11-07 20:23:30 +01:00
if ( ! Models . size ())
return nullptr ;
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
// If only one element, ignore the Probability (even if 0)
if ( Models . size () == 1 )
return & Models [ 0 ];
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
auto selectedItr = Trinity :: Containers :: SelectRandomWeightedContainerElement ( Models , []( CreatureModel const & model )
{
return model . Probability ;
});
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
return & ( * selectedItr );
}
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
CreatureModel const * CreatureTemplate :: GetFirstValidModel () const
{
for ( CreatureModel const & model : Models )
if ( model . CreatureDisplayID )
return & model ;
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
return nullptr ;
2015-12-05 18:47:35 +01:00
}
2018-11-07 20:23:30 +01:00
CreatureModel const * CreatureTemplate :: GetModelWithDisplayId ( uint32 displayId ) const
2015-12-05 18:47:35 +01:00
{
2018-11-07 20:23:30 +01:00
for ( CreatureModel const & model : Models )
if ( displayId == model . CreatureDisplayID )
return & model ;
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
return nullptr ;
}
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
CreatureModel const * CreatureTemplate :: GetFirstInvisibleModel () const
{
for ( CreatureModel const & model : Models )
if ( CreatureModelInfo const * modelInfo = sObjectMgr -> GetCreatureModelInfo ( model . CreatureDisplayID ))
if ( modelInfo && modelInfo -> is_trigger )
return & model ;
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
return & CreatureModel :: DefaultInvisibleModel ;
}
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
CreatureModel const * CreatureTemplate :: GetFirstVisibleModel () const
{
for ( CreatureModel const & model : Models )
if ( CreatureModelInfo const * modelInfo = sObjectMgr -> GetCreatureModelInfo ( model . CreatureDisplayID ))
if ( modelInfo && ! modelInfo -> is_trigger )
return & model ;
2015-12-05 18:47:35 +01:00
2018-11-07 20:23:30 +01:00
return & CreatureModel :: DefaultVisibleModel ;
2015-12-05 18:47:35 +01:00
}
2008-11-25 16:36:50 -06:00
bool AssistDelayEvent :: Execute ( uint64 /*e_time*/ , uint32 /*p_time*/ )
{
2014-05-20 21:21:33 +02:00
if ( Unit * victim = ObjectAccessor :: GetUnit ( m_owner , m_victim ))
2008-11-25 16:36:50 -06:00
{
while ( ! m_assistants . empty ())
{
2014-05-20 21:21:33 +02:00
Creature * assistant = ObjectAccessor :: GetCreature ( m_owner , * m_assistants . begin ());
2008-11-25 16:36:50 -06:00
m_assistants . pop_front ();
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
if ( assistant && assistant -> CanAssistTo ( & m_owner , victim ))
{
2008-12-01 12:59:39 -06:00
assistant -> SetNoCallAssistance ( true );
2008-11-25 16:36:50 -06:00
assistant -> CombatStart ( victim );
2010-04-07 19:14:10 +02:00
if ( assistant -> IsAIEnabled )
2008-11-25 16:36:50 -06:00
assistant -> AI () -> AttackStart ( victim );
}
}
}
return true ;
}
2009-10-17 15:51:44 -07:00
2010-03-03 02:48:31 +02:00
CreatureBaseStats const * CreatureBaseStats :: GetBaseStats ( uint8 level , uint8 unitClass )
2010-01-10 22:02:03 +01:00
{
2010-12-22 21:25:23 +01:00
return sObjectMgr -> GetCreatureBaseStats ( level , unitClass );
2010-01-10 22:02:03 +01:00
}
2010-01-16 19:51:59 +03:00
bool ForcedDespawnDelayEvent :: Execute ( uint64 /*e_time*/ , uint32 /*p_time*/ )
{
2016-08-25 23:04:21 +02:00
m_owner . DespawnOrUnsummon ( 0 , m_respawnTimer ); // since we are here, we are not TempSummon as object type cannot change during runtime
2010-01-16 19:51:59 +03:00
return true ;
}
2013-10-16 18:37:29 +02:00
Creature :: Creature ( bool isWorldObject ) : Unit ( isWorldObject ), MapObject (),
2014-10-22 00:35:00 +02:00
m_groupLootTimer ( 0 ), m_PlayerDamageReq ( 0 ),
_pickpocketLootRestore ( 0 ), m_corpseRemoveTime ( 0 ), m_respawnTime ( 0 ),
2016-01-13 15:33:17 +01:00
m_respawnDelay ( 300 ), m_corpseDelay ( 60 ), m_respawnradius ( 0.0f ), m_boundaryCheckTime ( 2500 ), m_combatPulseTime ( 0 ), m_combatPulseDelay ( 0 ), m_reactState ( REACT_AGGRESSIVE ),
2015-02-25 00:13:14 +01:00
m_defaultMovementType ( IDLE_MOTION_TYPE ), m_spawnId ( UI64LIT ( 0 )), m_equipmentId ( 0 ), m_originalEquipmentId ( 0 ), m_AlreadyCallAssistance ( false ),
2016-03-24 16:12:53 +01:00
m_AlreadySearchedAssistance ( false ), m_regenHealth ( true ), m_cannotReachTarget ( false ), m_cannotReachTimer ( 0 ), m_AI_locked ( false ), m_meleeDamageSchoolMask ( SPELL_SCHOOL_MASK_NORMAL ),
2017-02-05 15:39:22 +01:00
m_originalEntry ( 0 ), m_homePosition (), m_transportHomePosition (), m_creatureInfo ( nullptr ), m_creatureData ( nullptr ), m_waypointID ( 0 ), m_path_id ( 0 ), m_formation ( nullptr ), m_focusSpell ( nullptr ), m_focusDelay ( 0 ), m_shouldReacquireTarget ( false ), m_suppressedOrientation ( 0.0f ),
_lastDamagedTime ( 0 )
2008-10-11 14:16:25 -05:00
{
2010-01-10 01:23:15 +01:00
m_regenTimer = CREATURE_REGEN_INTERVAL ;
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
for ( uint8 i = 0 ; i < MAX_CREATURE_SPELLS ; ++ i )
2008-10-11 14:16:25 -05:00
m_spells [ i ] = 0 ;
2009-10-17 15:51:44 -07:00
2009-04-10 18:11:09 +02:00
DisableReputationGain = false ;
2009-10-17 15:51:44 -07:00
2010-12-23 23:25:44 +01:00
m_SightDistance = sWorld -> getFloatConfig ( CONFIG_SIGHT_MONSTER );
2009-08-23 16:27:00 -05:00
m_CombatDistance = 0 ; //MELEE_RANGE;
2009-10-28 16:31:19 -07:00
ResetLootMode (); // restore default loot mode
2016-04-02 02:50:44 +02:00
m_TriggerJustRespawned = false ;
2011-12-20 17:05:08 -05:00
m_isTempWorldObject = false ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
Creature ::~ Creature ()
{
2010-06-21 23:20:58 +02:00
delete i_AI ;
2016-04-02 02:50:44 +02:00
i_AI = nullptr ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
//if (m_uint32Values)
2013-11-08 10:50:51 +01:00
// TC_LOG_ERROR("entities.unit", "Deconstruct Creature Entry = %u", GetEntry());
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: AddToWorld ()
{
///- Register the creature for guid lookup
2010-04-07 19:14:10 +02:00
if ( ! IsInWorld ())
2009-03-23 20:13:37 -06:00
{
2014-01-04 18:22:06 +01:00
if ( GetZoneScript ())
GetZoneScript () -> OnCreatureCreate ( this );
2015-02-25 00:13:14 +01:00
GetMap () -> GetObjectsStore (). Insert < Creature > ( GetGUID (), this );
if ( m_spawnId )
GetMap () -> GetCreatureBySpawnIdStore (). insert ( std :: make_pair ( m_spawnId , this ));
2009-03-23 20:13:37 -06:00
Unit :: AddToWorld ();
2009-09-19 12:13:08 -07:00
SearchFormation ();
2009-04-06 20:33:52 -05:00
AIM_Initialize ();
2010-04-07 19:14:10 +02:00
if ( IsVehicle ())
2009-08-28 11:26:20 -05:00
GetVehicleKit () -> Install ();
2009-03-23 20:13:37 -06:00
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: RemoveFromWorld ()
{
2010-04-07 19:14:10 +02:00
if ( IsInWorld ())
2009-03-23 20:13:37 -06:00
{
2014-01-04 18:22:06 +01:00
if ( GetZoneScript ())
GetZoneScript () -> OnCreatureRemove ( this );
2015-02-25 00:13:14 +01:00
2010-04-07 19:14:10 +02:00
if ( m_formation )
2012-05-30 08:01:02 +02:00
sFormationMgr -> RemoveCreatureFromGroup ( m_formation , this );
2015-02-25 00:13:14 +01:00
2009-03-23 20:13:37 -06:00
Unit :: RemoveFromWorld ();
2015-02-25 00:13:14 +01:00
if ( m_spawnId )
Trinity :: Containers :: MultimapErasePair ( GetMap () -> GetCreatureBySpawnIdStore (), m_spawnId , this );
GetMap () -> GetObjectsStore (). Remove < Creature > ( GetGUID ());
2009-03-23 20:13:37 -06:00
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2009-08-14 22:26:07 -05:00
void Creature :: DisappearAndDie ()
{
2017-02-05 15:39:22 +01:00
ForcedDespawn ( 0 );
2009-08-14 22:26:07 -05:00
}
2009-10-17 15:51:44 -07:00
2009-09-19 12:13:08 -07:00
void Creature :: SearchFormation ()
2008-12-15 00:07:21 +02:00
{
2013-06-11 19:54:27 -02:30
if ( IsSummon ())
2009-04-04 15:04:24 -06:00
return ;
2009-10-17 15:51:44 -07:00
2015-02-25 00:13:14 +01:00
ObjectGuid :: LowType lowguid = GetSpawnId ();
2010-04-07 19:14:10 +02:00
if ( ! lowguid )
2009-04-06 13:27:42 -05:00
return ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
CreatureGroupInfoType :: iterator frmdata = sFormationMgr -> CreatureGroupMap . find ( lowguid );
if ( frmdata != sFormationMgr -> CreatureGroupMap . end ())
sFormationMgr -> AddCreatureToGroup ( frmdata -> second -> leaderGUID , this );
2008-12-15 00:07:21 +02:00
}
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
void Creature :: RemoveCorpse ( bool setSpawnTime , bool destroyForNearbyPlayers )
2008-10-11 14:16:25 -05:00
{
2011-06-27 20:22:53 +02:00
if ( getDeathState () != CORPSE )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-09-15 06:22:54 +02:00
m_corpseRemoveTime = time ( NULL );
2008-10-11 14:16:25 -05:00
setDeathState ( DEAD );
2011-07-12 00:19:50 +02:00
RemoveAllAuras ();
2017-01-28 05:00:28 +01:00
DestroyForNearbyPlayers (); // old UpdateObjectVisibility()
2008-10-11 14:16:25 -05:00
loot . clear ();
2009-10-09 20:48:55 -07:00
uint32 respawnDelay = m_respawnDelay ;
2009-12-06 16:41:05 +01:00
if ( IsAIEnabled )
2009-10-09 20:48:55 -07:00
AI () -> CorpseRemoved ( respawnDelay );
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
if ( destroyForNearbyPlayers )
DestroyForNearbyPlayers ();
2010-09-15 06:22:54 +02:00
// Should get removed later, just keep "compatibility" with scripts
2011-06-12 02:30:32 +02:00
if ( setSpawnTime )
2017-02-05 15:02:08 +01:00
m_respawnTime = std :: max < time_t > ( time ( NULL ) + respawnDelay , m_respawnTime );
2009-10-17 15:51:44 -07:00
2017-01-30 10:57:24 +01:00
// if corpse was removed during falling, the falling will continue and override relocation to respawn position
if ( IsFalling ())
StopMoving ();
2011-04-29 20:47:02 +02:00
float x , y , z , o ;
2011-10-18 10:53:34 -04:00
GetRespawnPosition ( x , y , z , & o );
2017-02-05 15:39:22 +01:00
// We were spawned on transport, calculate real position
if ( IsSpawnedOnTransport ())
{
Position & pos = m_movementInfo . transport . pos ;
pos . m_positionX = x ;
pos . m_positionY = y ;
pos . m_positionZ = z ;
pos . SetOrientation ( o );
if ( TransportBase * transport = GetDirectTransport ())
transport -> CalculatePassengerPosition ( x , y , z , & o );
}
2011-04-29 20:47:02 +02:00
SetHomePosition ( x , y , z , o );
GetMap () -> CreatureRelocation ( this , x , y , z , o );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
/**
* change the entry of creature until respawn
*/
2014-04-28 20:05:36 +02:00
bool Creature :: InitEntry ( uint32 entry , CreatureData const * data /*= nullptr*/ )
2008-10-11 14:16:25 -05:00
{
2013-03-20 14:18:26 +01:00
CreatureTemplate const * normalInfo = sObjectMgr -> GetCreatureTemplate ( entry );
2010-04-07 19:14:10 +02:00
if ( ! normalInfo )
2008-10-11 14:16:25 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Creature::InitEntry creature entry %u does not exist." , entry );
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2009-12-17 11:06:50 +01:00
// get difficulty 1 mode entry
2015-01-10 01:35:47 +01:00
CreatureTemplate const * cinfo = nullptr ;
2018-09-15 17:55:26 +02:00
DifficultyEntry const * difficultyEntry = sDifficultyStore . LookupEntry ( GetMap () -> GetDifficultyID ());
2015-01-10 01:35:47 +01:00
while ( ! cinfo && difficultyEntry )
2008-10-11 14:16:25 -05:00
{
2015-01-10 01:35:47 +01:00
int32 idx = CreatureTemplate :: DifficultyIDToDifficultyEntryIndex ( difficultyEntry -> ID );
if ( idx == - 1 )
break ;
2011-02-04 15:45:59 +01:00
2015-01-10 01:35:47 +01:00
if ( normalInfo -> DifficultyEntry [ idx ])
{
cinfo = sObjectMgr -> GetCreatureTemplate ( normalInfo -> DifficultyEntry [ idx ]);
break ;
2008-10-11 14:16:25 -05:00
}
2011-02-04 15:45:59 +01:00
2015-01-10 01:35:47 +01:00
if ( ! difficultyEntry -> FallbackDifficultyID )
break ;
difficultyEntry = sDifficultyStore . LookupEntry ( difficultyEntry -> FallbackDifficultyID );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2015-01-10 01:35:47 +01:00
if ( ! cinfo )
cinfo = normalInfo ;
2013-02-13 20:24:23 +01:00
// Initialize loot duplicate count depending on raid difficulty
2013-02-14 11:41:20 +01:00
if ( GetMap () -> Is25ManRaid ())
2013-02-13 20:24:23 +01:00
loot . maxDuplicates = 3 ;
2013-03-20 14:18:26 +01:00
SetEntry ( entry ); // normal entry always
2008-10-11 14:16:25 -05:00
m_creatureInfo = cinfo ; // map mode related always
2009-10-17 15:51:44 -07:00
2009-05-29 21:24:23 -05:00
// equal to player Race field, but creature does not have race
2019-06-03 20:40:34 +02:00
SetRace ( 0 );
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
// known valid are: CLASS_WARRIOR, CLASS_PALADIN, CLASS_ROGUE, CLASS_MAGE
2019-06-03 20:40:34 +02:00
SetClass ( uint8 ( cinfo -> unit_class ));
2009-10-17 15:51:44 -07:00
2008-10-27 11:48:45 -05:00
// Cancel load if no model defined
2018-11-07 20:23:30 +01:00
if ( ! ( cinfo -> GetFirstValidModel ()))
2008-10-11 14:16:25 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "sql.sql" , "Creature (Entry: %u) has no model defined in table `creature_template`, can't load. " , entry );
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
CreatureModel model = * ObjectMgr :: ChooseDisplayId ( cinfo , data );
CreatureModelInfo const * minfo = sObjectMgr -> GetCreatureModelRandomGender ( & model , cinfo );
2009-06-15 18:02:12 -05:00
if ( ! minfo ) // Cancel load if no model defined
2008-10-11 14:16:25 -05:00
{
2018-11-07 20:23:30 +01:00
TC_LOG_ERROR ( "sql.sql" , "Creature (Entry: %u) has invalid model %u defined in table `creature_template`, can't load." , entry , model . CreatureDisplayID );
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
SetDisplayId ( model . CreatureDisplayID , model . DisplayScale );
SetNativeDisplayId ( model . CreatureDisplayID , model . DisplayScale );
2019-06-03 20:40:34 +02:00
SetGender ( minfo -> gender );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// Load creature equipment
2016-05-29 18:51:58 +01:00
if ( ! data || data -> equipmentId == 0 )
LoadEquipment (); // use default equipment (if available)
else if ( data && data -> equipmentId != 0 ) // override, 0 means no equipment
2013-02-20 01:17:00 +00:00
{
m_originalEquipmentId = data -> equipmentId ;
2008-10-11 14:16:25 -05:00
LoadEquipment ( data -> equipmentId );
2013-02-20 01:17:00 +00:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
SetName ( normalInfo -> Name ); // at normal entry always
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
SetModCastingSpeed ( 1.0f );
SetModSpellHaste ( 1.0f );
SetModHaste ( 1.0f );
SetModRangedHaste ( 1.0f );
SetModHasteRegen ( 1.0f );
SetModTimeRate ( 1.0f );
2009-10-17 15:51:44 -07:00
2016-04-16 01:36:32 +02:00
SetSpeedRate ( MOVE_WALK , cinfo -> speed_walk );
SetSpeedRate ( MOVE_RUN , cinfo -> speed_run );
SetSpeedRate ( MOVE_SWIM , 1.0f ); // using 1.0 rate
SetSpeedRate ( MOVE_FLIGHT , 1.0f ); // using 1.0 rate
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
// Will set UNIT_FIELD_BOUNDINGRADIUS, UNIT_FIELD_COMBATREACH and UNIT_FIELD_DISPLAYSCALE
2012-05-30 08:01:02 +02:00
SetObjectScale ( cinfo -> scale );
2019-06-03 20:40:34 +02:00
SetHoverHeight ( cinfo -> HoverHeight );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// checked at loading
m_defaultMovementType = MovementGeneratorType ( cinfo -> MovementType );
2010-04-07 23:25:02 +02:00
if ( ! m_respawnradius && m_defaultMovementType == RANDOM_MOTION_TYPE )
2008-10-11 14:16:25 -05:00
m_defaultMovementType = IDLE_MOTION_TYPE ;
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
for ( uint8 i = 0 ; i < MAX_CREATURE_SPELLS ; ++ i )
2012-05-30 08:01:02 +02:00
m_spells [ i ] = GetCreatureTemplate () -> spells [ i ];
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2016-08-23 23:46:24 +02:00
bool Creature :: UpdateEntry ( uint32 entry , CreatureData const * data /*= nullptr*/ , bool updateLevel /* = true */ )
2008-10-11 14:16:25 -05:00
{
2014-04-28 20:05:36 +02:00
if ( ! InitEntry ( entry , data ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
CreatureTemplate const * cInfo = GetCreatureTemplate ();
2010-01-10 22:02:03 +01:00
m_regenHealth = cInfo -> RegenHealth ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
// creatures always have melee weapon ready if any unless specified otherwise
if ( ! GetCreatureAddon ())
SetSheath ( SHEATH_STATE_MELEE );
2009-10-17 15:51:44 -07:00
2014-04-28 20:05:36 +02:00
setFaction ( cInfo -> faction );
2009-10-17 15:51:44 -07:00
2017-05-21 14:15:04 +02:00
uint64 npcFlags ;
uint32 unitFlags , unitFlags2 , unitFlags3 , dynamicFlags ;
ObjectMgr :: ChooseCreatureFlags ( cInfo , npcFlags , unitFlags , unitFlags2 , unitFlags3 , dynamicFlags , data );
2010-10-09 17:52:00 +02:00
2010-04-07 19:14:10 +02:00
if ( cInfo -> flags_extra & CREATURE_FLAG_EXTRA_WORLDEVENT )
2019-06-03 20:40:34 +02:00
npcFlags |= sGameEventMgr -> GetNPCFlag ( this );
SetNpcFlags ( NPCFlags ( npcFlags & 0xFFFFFFFF ));
SetNpcFlags2 ( NPCFlags2 ( npcFlags >> 32 ));
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
// if unit is in combat, keep this flag
unitFlags &= ~ UNIT_FLAG_IN_COMBAT ;
if ( IsInCombat ())
unitFlags |= UNIT_FLAG_IN_COMBAT ;
2019-06-03 20:40:34 +02:00
SetUnitFlags ( UnitFlags ( unitFlags ));
SetUnitFlags2 ( UnitFlags2 ( unitFlags2 ));
SetUnitFlags3 ( UnitFlags3 ( unitFlags3 ));
2010-10-09 17:52:00 +02:00
2019-06-03 20:40:34 +02:00
SetDynamicFlags ( dynamicFlags );
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: StateAnimID ), sAnimationDataStore . GetNumRows ());
2018-10-04 18:50:21 +02:00
2016-11-25 17:58:48 +01:00
SetBaseAttackTime ( BASE_ATTACK , cInfo -> BaseAttackTime );
SetBaseAttackTime ( OFF_ATTACK , cInfo -> BaseAttackTime );
SetBaseAttackTime ( RANGED_ATTACK , cInfo -> RangeAttackTime );
2014-01-04 18:22:06 +01:00
2016-08-23 23:46:24 +02:00
if ( updateLevel )
SelectLevel ();
2017-07-29 21:40:28 +02:00
else
UpdateLevelDependantStats (); // We still re-initialize level dependant stats on entry update
2016-09-24 03:50:20 +02:00
2010-01-10 22:02:03 +01:00
SetMeleeDamageSchool ( SpellSchools ( cInfo -> dmgschool ));
2011-04-28 22:57:08 +02:00
SetModifierValue ( UNIT_MOD_RESISTANCE_HOLY , BASE_VALUE , float ( cInfo -> resistance [ SPELL_SCHOOL_HOLY ]));
SetModifierValue ( UNIT_MOD_RESISTANCE_FIRE , BASE_VALUE , float ( cInfo -> resistance [ SPELL_SCHOOL_FIRE ]));
SetModifierValue ( UNIT_MOD_RESISTANCE_NATURE , BASE_VALUE , float ( cInfo -> resistance [ SPELL_SCHOOL_NATURE ]));
SetModifierValue ( UNIT_MOD_RESISTANCE_FROST , BASE_VALUE , float ( cInfo -> resistance [ SPELL_SCHOOL_FROST ]));
SetModifierValue ( UNIT_MOD_RESISTANCE_SHADOW , BASE_VALUE , float ( cInfo -> resistance [ SPELL_SCHOOL_SHADOW ]));
SetModifierValue ( UNIT_MOD_RESISTANCE_ARCANE , BASE_VALUE , float ( cInfo -> resistance [ SPELL_SCHOOL_ARCANE ]));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
SetCanModifyStats ( true );
UpdateAllStats ();
2009-10-17 15:51:44 -07:00
2009-12-19 19:10:14 +01:00
// checked and error show at loading templates
2014-04-27 18:13:55 -04:00
if ( FactionTemplateEntry const * factionTemplate = sFactionTemplateStore . LookupEntry ( cInfo -> faction ))
2008-10-11 14:16:25 -05:00
{
2014-11-08 19:26:20 +02:00
if ( factionTemplate -> Flags & FACTION_TEMPLATE_FLAG_PVP )
2009-12-19 19:10:14 +01:00
SetPvP ( true );
else
SetPvP ( false );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2012-12-05 23:34:50 +02:00
// updates spell bars for vehicles and set player's faction - should be called here, to overwrite faction that is set from the new template
if ( IsVehicle ())
2012-12-17 05:39:04 +01:00
{
2012-12-05 23:34:50 +02:00
if ( Player * owner = Creature :: GetCharmerOrOwnerPlayerOrPlayerItself ()) // this check comes in case we don't have a player
2012-12-17 05:39:04 +01:00
{
2012-12-05 23:34:50 +02:00
setFaction ( owner -> getFaction ()); // vehicles should have same as owner faction
2012-12-17 05:39:04 +01:00
owner -> VehicleSpellInitialize ();
2012-12-05 23:34:50 +02:00
}
}
2010-04-21 13:55:43 +02:00
// trigger creature is always not selectable and can not be attacked
2013-06-11 19:54:27 -02:30
if ( IsTrigger ())
2019-06-03 20:40:34 +02:00
AddUnitFlag ( UNIT_FLAG_NOT_SELECTABLE );
2009-10-17 15:51:44 -07:00
2010-06-27 03:47:18 +02:00
InitializeReactState ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( cInfo -> flags_extra & CREATURE_FLAG_EXTRA_NO_TAUNT )
2009-01-27 15:23:26 -06:00
{
ApplySpellImmune ( 0 , IMMUNITY_STATE , SPELL_AURA_MOD_TAUNT , true );
2011-04-29 20:47:02 +02:00
ApplySpellImmune ( 0 , IMMUNITY_EFFECT , SPELL_EFFECT_ATTACK_ME , true );
2009-01-27 15:23:26 -06:00
}
2009-10-17 15:51:44 -07:00
2016-07-15 16:48:04 +02:00
if ( cInfo -> InhabitType & INHABIT_ROOT )
SetControlled ( true , UNIT_STATE_ROOT );
2013-06-07 16:05:39 +02:00
UpdateMovementFlags ();
2015-11-22 18:30:42 +01:00
LoadCreaturesAddon ();
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: Update ( uint32 diff )
{
2016-04-02 02:50:44 +02:00
if ( IsAIEnabled && m_TriggerJustRespawned )
2010-11-03 18:33:47 +01:00
{
2016-04-02 02:50:44 +02:00
m_TriggerJustRespawned = false ;
2010-11-03 18:33:47 +01:00
AI () -> JustRespawned ();
2011-04-22 21:59:37 +02:00
if ( m_vehicleKit )
m_vehicleKit -> Reset ();
2010-11-03 18:33:47 +01:00
}
2013-06-07 16:05:39 +02:00
UpdateMovementFlags ();
2012-12-29 04:01:46 +01:00
2011-09-29 12:43:05 +02:00
switch ( m_deathState )
2008-10-11 14:16:25 -05:00
{
2012-05-30 08:01:02 +02:00
case JUST_RESPAWNED :
// Must not be called, see Creature::setDeathState JUST_RESPAWNED -> ALIVE promoting.
2014-10-22 17:33:55 +02:00
TC_LOG_ERROR ( "entities.unit" , "Creature (%s) in wrong state: JUST_RESPAWNED (4)" , GetGUID (). ToString (). c_str ());
2008-10-11 14:16:25 -05:00
break ;
case JUST_DIED :
2011-07-29 14:18:28 +02:00
// Must not be called, see Creature::setDeathState JUST_DIED -> CORPSE promoting.
2014-10-22 17:33:55 +02:00
TC_LOG_ERROR ( "entities.unit" , "Creature (%s) in wrong state: JUST_DEAD (1)" , GetGUID (). ToString (). c_str ());
2008-10-11 14:16:25 -05:00
break ;
case DEAD :
{
2010-12-24 16:18:23 +01:00
time_t now = time ( NULL );
if ( m_respawnTime <= now )
2008-10-11 14:16:25 -05:00
{
2016-09-09 16:21:27 +02:00
// First check if there are any scripts that object to us respawning
if ( ! sScriptMgr -> CanSpawn ( GetSpawnId (), GetEntry (), GetCreatureTemplate (), GetCreatureData (), GetMap ()))
break ; // Will be rechecked on next Update call
2010-12-24 16:18:23 +01:00
2015-02-25 00:13:14 +01:00
ObjectGuid dbtableHighGuid = ObjectGuid :: Create < HighGuid :: Creature > ( GetMapId (), GetEntry (), m_spawnId );
2012-06-07 23:20:57 +02:00
time_t linkedRespawntime = GetMap () -> GetLinkedRespawnTime ( dbtableHighGuid );
2010-12-24 18:55:50 +01:00
if ( ! linkedRespawntime ) // Can respawn
2009-04-14 14:33:48 +02:00
Respawn ();
2010-12-24 16:18:23 +01:00
else // the master is dead
2008-10-11 14:16:25 -05:00
{
2014-09-14 16:14:12 +02:00
ObjectGuid targetGuid = sObjectMgr -> GetLinkedRespawnGuid ( dbtableHighGuid );
2011-05-16 15:36:02 +02:00
if ( targetGuid == dbtableHighGuid ) // if linking self, never respawn (check delayed to next day)
2010-12-24 18:55:50 +01:00
SetRespawnTime ( DAY );
2009-04-14 14:33:48 +02:00
else
2014-09-14 16:14:12 +02:00
m_respawnTime = ( now > linkedRespawntime ? now : linkedRespawntime ) + urand ( 5 , MINUTE ); // else copy time from master and add a little
2010-12-24 18:55:50 +01:00
SaveRespawnTime (); // also save to DB immediately
2008-10-11 14:16:25 -05:00
}
}
break ;
}
case CORPSE :
{
2012-01-14 15:34:41 +01:00
Unit :: Update ( diff );
2011-07-12 00:19:50 +02:00
// deathstate changed on spells update, prevent problems
if ( m_deathState != CORPSE )
break ;
2014-10-22 00:35:00 +02:00
if ( m_groupLootTimer && ! lootingGroupLowGUID . IsEmpty ())
2010-03-11 22:55:02 +01:00
{
if ( m_groupLootTimer <= diff )
{
2014-10-22 00:35:00 +02:00
if ( Group * group = sGroupMgr -> GetGroupByGUID ( lootingGroupLowGUID ))
2017-02-04 22:37:16 +01:00
group -> EndRoll ( & loot , GetMap ());
2014-10-22 00:35:00 +02:00
2010-03-11 22:55:02 +01:00
m_groupLootTimer = 0 ;
2014-10-22 00:35:00 +02:00
lootingGroupLowGUID . Clear ();
2010-03-11 22:55:02 +01:00
}
2014-10-22 00:35:00 +02:00
else
m_groupLootTimer -= diff ;
2010-03-11 22:55:02 +01:00
}
2010-09-15 06:22:54 +02:00
else if ( m_corpseRemoveTime <= time ( NULL ))
2008-10-11 14:16:25 -05:00
{
2010-09-15 06:22:54 +02:00
RemoveCorpse ( false );
2019-06-03 20:40:34 +02:00
TC_LOG_DEBUG ( "entities.unit" , "Removing corpse... %u " , GetEntry ());
2008-10-11 14:16:25 -05:00
}
break ;
}
case ALIVE :
{
2010-04-07 22:59:46 +02:00
Unit :: Update ( diff );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// creature can be dead after Unit::Update call
// CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly)
2013-06-11 19:54:27 -02:30
if ( ! IsAlive ())
2008-10-11 14:16:25 -05:00
break ;
2009-10-17 15:51:44 -07:00
2016-08-21 11:07:38 +02:00
if ( m_shouldReacquireTarget && ! IsFocusing ( nullptr , true ))
{
SetTarget ( m_suppressedTarget );
if ( ! m_suppressedTarget . IsEmpty ())
{
if ( WorldObject const * objTarget = ObjectAccessor :: GetWorldObject ( * this , m_suppressedTarget ))
SetFacingToObject ( objTarget );
}
else
SetFacingTo ( m_suppressedOrientation );
m_shouldReacquireTarget = false ;
}
2013-08-20 00:43:03 +02:00
// if creature is charmed, switch to charmed AI (and back)
2010-04-07 19:14:10 +02:00
if ( NeedChangeAI )
2009-03-13 17:48:57 -06:00
{
UpdateCharmAI ();
NeedChangeAI = false ;
IsAIEnabled = true ;
2014-10-21 19:23:32 +02:00
if ( ! IsInEvadeMode () && ! LastCharmerGUID . IsEmpty ())
2013-08-20 00:43:03 +02:00
if ( Unit * charmer = ObjectAccessor :: GetUnit ( * this , LastCharmerGUID ))
2016-03-01 20:12:46 +01:00
if ( CanStartAttack ( charmer , true ))
i_AI -> AttackStart ( charmer );
2013-08-20 00:43:03 +02:00
2014-09-14 16:14:12 +02:00
LastCharmerGUID . Clear ();
2009-03-13 17:48:57 -06:00
}
2009-10-17 15:51:44 -07:00
2016-01-13 15:33:17 +01:00
// periodic check to see if the creature has passed an evade boundary
if ( IsAIEnabled && ! IsInEvadeMode () && IsInCombat ())
{
if ( diff >= m_boundaryCheckTime )
{
AI () -> CheckInRoom ();
m_boundaryCheckTime = 2500 ;
} else
m_boundaryCheckTime -= diff ;
}
2015-09-13 22:02:38 +02:00
// if periodic combat pulse is enabled and we are both in combat and in a dungeon, do this now
if ( m_combatPulseDelay > 0 && IsInCombat () && GetMap () -> IsDungeon ())
{
if ( diff > m_combatPulseTime )
m_combatPulseTime = 0 ;
else
m_combatPulseTime -= diff ;
if ( m_combatPulseTime == 0 )
{
2015-09-25 15:14:53 +02:00
Map :: PlayerList const & players = GetMap () -> GetPlayers ();
if ( ! players . isEmpty ())
for ( Map :: PlayerList :: const_iterator it = players . begin (); it != players . end (); ++ it )
{
if ( Player * player = it -> GetSource ())
{
if ( player -> IsGameMaster ())
continue ;
if ( player -> IsAlive () && this -> IsHostileTo ( player ))
{
if ( CanHaveThreatList ())
AddThreat ( player , 0.0f );
this -> SetInCombatWith ( player );
player -> SetInCombatWith ( this );
}
}
}
2015-09-13 22:02:38 +02:00
m_combatPulseTime = m_combatPulseDelay * IN_MILLISECONDS ;
}
}
2010-04-07 19:14:10 +02:00
if ( ! IsInEvadeMode () && IsAIEnabled )
2008-10-11 14:16:25 -05:00
{
// do not allow the AI to be changed during update
m_AI_locked = true ;
2015-09-13 22:02:38 +02:00
2008-11-20 16:16:57 -06:00
i_AI -> UpdateAI ( diff );
2008-10-11 14:16:25 -05:00
m_AI_locked = false ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// creature can be dead after UpdateAI call
// CORPSE/DEAD state will processed at next tick (in other case death timer will be updated unexpectedly)
2013-06-11 19:54:27 -02:30
if ( ! IsAlive ())
2008-10-11 14:16:25 -05:00
break ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( m_regenTimer > 0 )
2009-10-10 16:26:00 -07:00
{
2010-04-07 19:14:10 +02:00
if ( diff >= m_regenTimer )
2009-10-10 16:26:00 -07:00
m_regenTimer = 0 ;
else
m_regenTimer -= diff ;
}
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
if ( m_regenTimer == 0 )
{
bool bInCombat = IsInCombat () && ( ! GetVictim () || // if IsInCombat() is true and this has no victim
! EnsureVictim () -> GetCharmerOrOwnerPlayerOrPlayerItself () || // or the victim/owner/charmer is not a player
! EnsureVictim () -> GetCharmerOrOwnerPlayerOrPlayerItself () -> IsGameMaster ()); // or the victim/owner/charmer is not a GameMaster
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
if ( ! IsInEvadeMode () && ( ! bInCombat || IsPolymorphed () || CanNotReachTarget ())) // regenerate health if not in combat or if polymorphed
RegenerateHealth ();
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
if ( GetPowerType () == POWER_ENERGY )
Regenerate ( POWER_ENERGY );
else
Regenerate ( POWER_MANA );
2016-03-24 16:12:53 +01:00
m_regenTimer = CREATURE_REGEN_INTERVAL ;
2009-08-23 22:36:51 -05:00
}
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
if ( CanNotReachTarget () && ! IsInEvadeMode () && ! GetMap () -> IsRaid ())
{
m_cannotReachTimer += diff ;
if ( m_cannotReachTimer >= CREATURE_NOPATH_EVADE_TIME )
if ( IsAIEnabled )
AI () -> EnterEvadeMode ( CreatureAI :: EVADE_REASON_NO_PATH );
2009-10-17 16:20:24 -07:00
}
2008-10-11 14:16:25 -05:00
break ;
}
default :
break ;
}
2010-08-06 19:23:43 +02:00
2010-12-22 21:25:23 +01:00
sScriptMgr -> OnCreatureUpdate ( this , diff );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
void Creature :: Regenerate ( Powers power )
2008-10-11 14:16:25 -05:00
{
2017-02-05 15:39:22 +01:00
uint32 curValue = GetPower ( power );
uint32 maxValue = GetMaxPower ( power );
if ( ! HasUnitFlag2 ( UNIT_FLAG2_REGENERATE_POWER ))
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( curValue >= maxValue )
return ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
float addvalue = 0.0f ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
switch ( power )
2008-10-11 14:16:25 -05:00
{
2017-02-05 15:39:22 +01:00
case POWER_FOCUS :
{
// For hunter pets.
addvalue = 24 * sWorld -> getRate ( RATE_POWER_FOCUS );
break ;
}
case POWER_ENERGY :
{
// For deathknight's ghoul.
addvalue = 20 ;
break ;
}
case POWER_MANA :
{
// Combat and any controlled creature
if ( IsInCombat () || GetCharmerOrOwnerGUID (). IsEmpty ())
{
float ManaIncreaseRate = sWorld -> getRate ( RATE_POWER_MANA );
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
addvalue = uint32 (( 27.0f / 5.0f + 17.0f ) * ManaIncreaseRate );
}
else
addvalue = maxValue / 3 ;
break ;
}
default :
return ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-01-10 01:23:15 +01:00
// Apply modifiers (if any).
2017-02-05 15:39:22 +01:00
addvalue *= GetTotalAuraMultiplierByMiscValue ( SPELL_AURA_MOD_POWER_REGEN_PERCENT , power );
2010-01-10 01:23:15 +01:00
2017-02-05 15:39:22 +01:00
addvalue += GetTotalAuraModifierByMiscValue ( SPELL_AURA_MOD_POWER_REGEN , power ) * ( IsHunterPet () ? PET_FOCUS_REGEN_INTERVAL : CREATURE_REGEN_INTERVAL ) / ( 5 * IN_MILLISECONDS );
2010-01-10 01:23:15 +01:00
2017-02-05 15:39:22 +01:00
ModifyPower ( power , int32 ( addvalue ));
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: RegenerateHealth ()
{
if ( ! isRegeneratingHealth ())
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 curValue = GetHealth ();
uint32 maxValue = GetMaxHealth ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( curValue >= maxValue )
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 addvalue = 0 ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
// Not only pet, but any controlled creature (and not polymorphed)
if ( ! GetCharmerOrOwnerGUID (). IsEmpty () && ! IsPolymorphed ())
2008-10-11 14:16:25 -05:00
{
2010-12-23 23:25:44 +01:00
float HealthIncreaseRate = sWorld -> getRate ( RATE_HEALTH );
2009-10-17 15:51:44 -07:00
2016-04-26 18:56:35 +02:00
addvalue = 0.015f * (( float ) GetMaxHealth ()) * HealthIncreaseRate ;
2008-10-11 14:16:25 -05:00
}
else
addvalue = maxValue / 3 ;
2009-10-17 15:51:44 -07:00
2010-01-10 01:23:15 +01:00
// Apply modifiers (if any).
2016-12-13 02:06:07 -03:00
addvalue *= GetTotalAuraMultiplier ( SPELL_AURA_MOD_HEALTH_REGEN_PERCENT );
2010-01-10 01:23:15 +01:00
2010-07-12 00:30:17 +02:00
addvalue += GetTotalAuraModifier ( SPELL_AURA_MOD_REGEN ) * CREATURE_REGEN_INTERVAL / ( 5 * IN_MILLISECONDS );
2010-01-10 01:23:15 +01:00
2008-10-11 14:16:25 -05:00
ModifyHealth ( addvalue );
}
2009-10-17 15:51:44 -07:00
2009-05-21 10:48:00 -05:00
void Creature :: DoFleeToGetAssistance ()
{
2013-06-11 19:54:27 -02:30
if ( ! GetVictim ())
2009-05-21 10:48:00 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( HasAuraType ( SPELL_AURA_PREVENTS_FLEEING ))
2009-05-21 10:48:00 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-12-23 23:25:44 +01:00
float radius = sWorld -> getFloatConfig ( CONFIG_CREATURE_FAMILY_FLEE_ASSISTANCE_RADIUS );
2009-05-21 10:48:00 -05:00
if ( radius > 0 )
{
2016-04-02 02:50:44 +02:00
Creature * creature = nullptr ;
2013-06-11 19:54:27 -02:30
Trinity :: NearestAssistCreatureInCreatureRangeCheck u_check ( this , GetVictim (), radius );
2011-10-07 11:08:09 -05:00
Trinity :: CreatureLastSearcher < Trinity :: NearestAssistCreatureInCreatureRangeCheck > searcher ( this , creature , u_check );
2017-05-13 19:37:33 +02:00
Cell :: VisitGridObjects ( this , searcher , radius );
2009-10-17 15:51:44 -07:00
2009-05-21 10:48:00 -05:00
SetNoSearchAssistance ( true );
2016-04-16 01:36:32 +02:00
UpdateSpeed ( MOVE_RUN );
2010-01-16 19:35:30 +03:00
2011-10-07 11:08:09 -05:00
if ( ! creature )
2014-04-19 21:48:22 +02:00
//SetFeared(true, EnsureVictim()->GetGUID(), 0, sWorld->getIntConfig(CONFIG_CREATURE_FAMILY_FLEE_DELAY));
2013-03-08 21:41:30 +01:00
/// @todo use 31365
2012-02-03 19:12:41 +02:00
SetControlled ( true , UNIT_STATE_FLEEING );
2009-05-21 10:48:00 -05:00
else
2011-10-07 11:08:09 -05:00
GetMotionMaster () -> MoveSeekAssistance ( creature -> GetPositionX (), creature -> GetPositionY (), creature -> GetPositionZ ());
2009-05-21 10:48:00 -05:00
}
}
2009-10-17 15:51:44 -07:00
2016-03-11 17:09:26 +01:00
bool Creature :: AIM_Destroy ()
{
if ( m_AI_locked )
{
TC_LOG_DEBUG ( "scripts" , "AIM_Destroy: failed to destroy, locked." );
return false ;
}
ASSERT ( ! i_disabledAI ,
"The disabled AI wasn't cleared!" );
delete i_AI ;
i_AI = nullptr ;
IsAIEnabled = false ;
return true ;
}
2018-02-05 20:52:19 +01:00
bool Creature :: AIM_Create ( CreatureAI * ai /*= nullptr*/ )
2008-10-11 14:16:25 -05:00
{
// make sure nothing can change the AI during AI update
2010-04-07 19:14:10 +02:00
if ( m_AI_locked )
2008-10-11 14:16:25 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "scripts" , "AIM_Initialize: failed to init, locked." );
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2016-03-11 17:09:26 +01:00
AIM_Destroy ();
2009-10-17 15:51:44 -07:00
2009-04-06 20:33:52 -05:00
Motion_Initialize ();
2009-10-17 16:20:24 -07:00
2009-04-06 20:33:52 -05:00
i_AI = ai ? ai : FactorySelector :: selectAI ( this );
2018-02-05 21:08:09 +01:00
return true ;
2018-02-05 20:52:19 +01:00
}
2016-03-11 17:09:26 +01:00
2018-02-05 20:52:19 +01:00
void Creature :: AI_InitializeAndEnable ()
{
2009-04-06 20:33:52 -05:00
IsAIEnabled = true ;
2009-04-13 17:53:09 -05:00
i_AI -> InitializeAI ();
2011-04-22 21:59:37 +02:00
// Initialize vehicle
if ( GetVehicleKit ())
GetVehicleKit () -> Reset ();
2018-02-05 20:52:19 +01:00
}
bool Creature :: AIM_Initialize ( CreatureAI * ai )
{
if ( ! AIM_Create ( ai ))
return false ;
AI_InitializeAndEnable ();
2009-04-06 20:33:52 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2009-04-06 20:33:52 -05:00
void Creature :: Motion_Initialize ()
{
2010-04-07 19:14:10 +02:00
if ( ! m_formation )
2013-12-12 09:50:52 +01:00
GetMotionMaster () -> Initialize ();
2010-04-07 19:14:10 +02:00
else if ( m_formation -> getLeader () == this )
2009-10-17 16:20:24 -07:00
{
2009-04-07 10:51:45 +02:00
m_formation -> FormationReset ( false );
2013-12-12 09:50:52 +01:00
GetMotionMaster () -> Initialize ();
2009-04-07 10:51:45 +02:00
}
2010-04-07 19:14:10 +02:00
else if ( m_formation -> isFormed ())
2013-12-12 09:50:52 +01:00
GetMotionMaster () -> MoveIdle (); //wait the order of leader
2009-04-06 20:33:52 -05:00
else
2013-12-12 09:50:52 +01:00
GetMotionMaster () -> Initialize ();
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2018-01-10 22:01:40 +01:00
bool Creature :: Create ( ObjectGuid :: LowType guidlow , Map * map , uint32 entry , float x , float y , float z , float ang , CreatureData const * data /*= nullptr*/ , uint32 vehId /*= 0*/ )
2008-10-11 14:16:25 -05:00
{
2009-08-01 00:20:32 +02:00
ASSERT ( map );
SetMap ( map );
2014-06-02 17:43:59 -05:00
2018-01-28 11:37:20 +01:00
if ( data )
{
PhasingHandler :: InitDbPhaseShift ( GetPhaseShift (), data -> phaseUseFlags , data -> phaseId , data -> phaseGroup );
PhasingHandler :: InitDbVisibleMapId ( GetPhaseShift (), data -> terrainSwapMap );
}
2009-10-17 15:51:44 -07:00
2014-04-28 20:05:36 +02:00
CreatureTemplate const * cinfo = sObjectMgr -> GetCreatureTemplate ( entry );
2010-11-16 14:00:47 +01:00
if ( ! cinfo )
{
2014-10-27 21:56:12 +00:00
TC_LOG_ERROR ( "sql.sql" , "Creature::Create(): creature template (guidlow: " UI64FMTD ", entry: %u) does not exist." , guidlow , entry );
2010-11-16 14:00:47 +01:00
return false ;
}
2012-05-30 08:01:02 +02:00
//! Relocate before CreateFromProto, to initialize coords and allow
//! returning correct zone id for selecting OutdoorPvP/Battlefield script
2009-05-30 22:15:05 -05:00
Relocate ( x , y , z , ang );
2009-10-17 15:51:44 -07:00
2016-06-21 22:19:31 +02:00
// Check if the position is valid before calling CreateFromProto(), otherwise we might add Auras to Creatures at
// invalid position, triggering a crash about Auras not removed in the destructor
2010-04-07 19:14:10 +02:00
if ( ! IsPositionValid ())
2009-05-30 22:15:05 -05:00
{
2014-10-27 21:56:12 +00:00
TC_LOG_ERROR ( "entities.unit" , "Creature::Create(): given coordinates for creature (guidlow " UI64FMTD ", entry %d) are not valid (X: %f, Y: %f, Z: %f, O: %f)" , guidlow , entry , x , y , z , ang );
2009-05-30 22:15:05 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
// Allow players to see those units while dead, do it here (mayby altered by addon auras)
if ( cinfo -> type_flags & CREATURE_TYPE_FLAG_GHOST_VISIBLE )
m_serverSideVisibility . SetValue ( SERVERSIDE_VISIBILITY_GHOST , GHOST_VISIBILITY_ALIVE | GHOST_VISIBILITY_GHOST );
2016-06-21 22:19:31 +02:00
if ( ! CreateFromProto ( guidlow , entry , data , vehId ))
return false ;
2018-11-07 20:23:30 +01:00
cinfo = GetCreatureTemplate (); // might be different than initially requested
2017-02-05 15:02:08 +01:00
if ( cinfo -> flags_extra & CREATURE_FLAG_EXTRA_DUNGEON_BOSS && map -> IsDungeon ())
m_respawnDelay = 0 ; // special value, prevents respawn for dungeon bosses unless overridden
2018-11-07 20:23:30 +01:00
switch ( cinfo -> rank )
2008-10-11 14:16:25 -05:00
{
2011-02-18 19:48:47 +01:00
case CREATURE_ELITE_RARE :
m_corpseDelay = sWorld -> getIntConfig ( CONFIG_CORPSE_DECAY_RARE );
break ;
case CREATURE_ELITE_ELITE :
m_corpseDelay = sWorld -> getIntConfig ( CONFIG_CORPSE_DECAY_ELITE );
break ;
case CREATURE_ELITE_RAREELITE :
m_corpseDelay = sWorld -> getIntConfig ( CONFIG_CORPSE_DECAY_RAREELITE );
break ;
case CREATURE_ELITE_WORLDBOSS :
m_corpseDelay = sWorld -> getIntConfig ( CONFIG_CORPSE_DECAY_WORLDBOSS );
break ;
default :
m_corpseDelay = sWorld -> getIntConfig ( CONFIG_CORPSE_DECAY_NORMAL );
break ;
}
2009-10-17 15:51:44 -07:00
2011-02-18 19:48:47 +01:00
LoadCreaturesAddon ();
2012-05-30 08:01:02 +02:00
//! Need to be called after LoadCreaturesAddon - MOVEMENTFLAG_HOVER is set there
if ( HasUnitMovementFlag ( MOVEMENTFLAG_HOVER ))
{
2019-06-03 20:40:34 +02:00
z += m_unitData -> HoverHeight ;
2012-05-30 08:01:02 +02:00
//! Relocate again with updated Z coord
Relocate ( x , y , z , ang );
}
2018-11-07 20:23:30 +01:00
CreatureModel display ( GetNativeDisplayId (), GetNativeDisplayScale (), 1.0f );
CreatureModelInfo const * minfo = sObjectMgr -> GetCreatureModelRandomGender ( & display , cinfo );
2013-06-11 19:54:27 -02:30
if ( minfo && ! IsTotem ()) // Cancel load if no model defined or if totem
2011-02-18 19:48:47 +01:00
{
2018-11-07 20:23:30 +01:00
SetDisplayId ( display . CreatureDisplayID , display . DisplayScale );
SetNativeDisplayId ( display . CreatureDisplayID , display . DisplayScale );
2019-06-03 20:40:34 +02:00
SetGender ( minfo -> gender );
2011-02-18 19:48:47 +01:00
}
2010-02-28 20:30:20 +01:00
2017-03-18 11:31:31 +01:00
LastUsedScriptID = GetScriptId ();
2011-02-18 19:48:47 +01:00
2013-03-08 21:41:30 +01:00
/// @todo Replace with spell, handle from DB
2013-06-11 19:54:27 -02:30
if ( IsSpiritHealer () || IsSpiritGuide ())
2010-11-13 17:18:09 +01:00
{
m_serverSideVisibility . SetValue ( SERVERSIDE_VISIBILITY_GHOST , GHOST_VISIBILITY_GHOST );
m_serverSideVisibilityDetect . SetValue ( SERVERSIDE_VISIBILITY_GHOST , GHOST_VISIBILITY_GHOST );
}
2018-11-07 20:23:30 +01:00
if ( cinfo -> flags_extra & CREATURE_FLAG_EXTRA_IGNORE_PATHFINDING )
2014-07-11 03:08:20 +02:00
AddUnitState ( UNIT_STATE_IGNORE_PATHFINDING );
2018-11-07 20:23:30 +01:00
if ( cinfo -> flags_extra & CREATURE_FLAG_EXTRA_IMMUNITY_KNOCKBACK )
2016-02-04 15:46:23 +01:00
{
ApplySpellImmune ( 0 , IMMUNITY_EFFECT , SPELL_EFFECT_KNOCK_BACK , true );
ApplySpellImmune ( 0 , IMMUNITY_EFFECT , SPELL_EFFECT_KNOCK_BACK_DEST , true );
}
2011-02-18 19:48:47 +01:00
return true ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2018-01-27 21:47:37 +01:00
Creature * Creature :: CreateCreature ( uint32 entry , Map * map , Position const & pos , uint32 vehId /*= 0*/ )
{
CreatureTemplate const * cInfo = sObjectMgr -> GetCreatureTemplate ( entry );
if ( ! cInfo )
return nullptr ;
ObjectGuid :: LowType lowGuid ;
if ( vehId || cInfo -> VehicleId )
lowGuid = map -> GenerateLowGuid < HighGuid :: Vehicle > ();
else
lowGuid = map -> GenerateLowGuid < HighGuid :: Creature > ();
Creature * creature = new Creature ();
if ( ! creature -> Create ( lowGuid , map , entry , pos . GetPositionX (), pos . GetPositionY (), pos . GetPositionZ (), pos . GetOrientation (), nullptr , vehId ))
{
delete creature ;
return nullptr ;
}
return creature ;
}
Creature * Creature :: CreateCreatureFromDB ( ObjectGuid :: LowType spawnId , Map * map , bool addToMap /*= true*/ , bool allowDuplicate /*= false*/ )
{
Creature * creature = new Creature ();
if ( ! creature -> LoadCreatureFromDB ( spawnId , map , addToMap , allowDuplicate ))
{
delete creature ;
return nullptr ;
}
return creature ;
}
2013-03-04 12:41:17 +01:00
void Creature :: InitializeReactState ()
{
2014-08-14 16:09:14 +02:00
if ( IsTotem () || IsTrigger () || IsCritter () || IsSpiritService ())
2013-03-04 12:41:17 +01:00
SetReactState ( REACT_PASSIVE );
2014-04-28 20:05:36 +02:00
/*
else if (IsCivilian())
SetReactState(REACT_DEFENSIVE);
*/
2013-03-04 12:41:17 +01:00
else
SetReactState ( REACT_AGGRESSIVE );
}
2011-10-07 11:08:09 -05:00
bool Creature :: isCanInteractWithBattleMaster ( Player * player , bool msg ) const
2008-10-11 14:16:25 -05:00
{
2013-06-11 19:54:27 -02:30
if ( ! IsBattleMaster ())
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
BattlegroundTypeId bgTypeId = sBattlegroundMgr -> GetBattleMasterBG ( GetEntry ());
2010-04-07 19:14:10 +02:00
if ( ! msg )
2011-10-07 11:08:09 -05:00
return player -> GetBGAccessByLevel ( bgTypeId );
2009-10-17 15:51:44 -07:00
2011-10-07 11:08:09 -05:00
if ( ! player -> GetBGAccessByLevel ( bgTypeId ))
2008-10-11 14:16:25 -05:00
{
2016-08-31 00:59:04 +02:00
ClearGossipMenuFor ( player );
2011-09-29 12:43:05 +02:00
switch ( bgTypeId )
2008-10-11 14:16:25 -05:00
{
2016-08-31 00:59:04 +02:00
case BATTLEGROUND_AV : SendGossipMenuFor ( player , 7616 , this ); break ;
case BATTLEGROUND_WS : SendGossipMenuFor ( player , 7599 , this ); break ;
case BATTLEGROUND_AB : SendGossipMenuFor ( player , 7642 , this ); break ;
2008-10-11 14:16:25 -05:00
case BATTLEGROUND_EY :
case BATTLEGROUND_NA :
case BATTLEGROUND_BE :
case BATTLEGROUND_AA :
2008-12-24 09:58:26 -06:00
case BATTLEGROUND_RL :
case BATTLEGROUND_SA :
case BATTLEGROUND_DS :
2016-08-31 00:59:04 +02:00
case BATTLEGROUND_RV : SendGossipMenuFor ( player , 10024 , this ); break ;
2008-12-24 09:58:26 -06:00
default : break ;
2008-10-11 14:16:25 -05:00
}
return false ;
}
return true ;
}
2009-10-17 15:51:44 -07:00
2017-07-26 00:53:25 +02:00
bool Creature :: CanResetTalents ( Player * player ) const
2008-10-11 14:16:25 -05:00
{
2017-07-24 23:24:32 +02:00
return player -> getLevel () >= 15
2012-05-30 08:01:02 +02:00
&& player -> getClass () == GetCreatureTemplate () -> trainer_class ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
Player * Creature :: GetLootRecipient () const
2008-10-11 14:16:25 -05:00
{
2010-09-15 13:44:40 +02:00
if ( ! m_lootRecipient )
2016-04-02 02:50:44 +02:00
return nullptr ;
2014-10-22 00:35:00 +02:00
2014-10-16 22:47:02 +02:00
return ObjectAccessor :: FindConnectedPlayer ( m_lootRecipient );
2010-09-15 13:44:40 +02:00
}
2011-09-15 14:08:17 +02:00
Group * Creature :: GetLootRecipientGroup () const
2010-09-15 13:44:40 +02:00
{
2014-10-22 00:35:00 +02:00
if ( m_lootRecipientGroup . IsEmpty ())
2016-04-02 02:50:44 +02:00
return nullptr ;
2014-10-22 00:35:00 +02:00
2011-05-05 10:23:00 +02:00
return sGroupMgr -> GetGroupByGUID ( m_lootRecipientGroup );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
void Creature :: SetLootRecipient ( Unit * unit )
2008-10-11 14:16:25 -05:00
{
// set the player whose group should receive the right
// to loot the creature after it dies
2016-04-02 02:50:44 +02:00
// should be set to nullptr after the loot disappears
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( ! unit )
{
2014-09-14 16:14:12 +02:00
m_lootRecipient . Clear ();
2014-10-22 00:35:00 +02:00
m_lootRecipientGroup . Clear ();
2019-06-03 20:40:34 +02:00
RemoveDynamicFlag ( UNIT_DYNFLAG_LOOTABLE | UNIT_DYNFLAG_TAPPED );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2010-09-13 22:49:20 +02:00
if ( unit -> GetTypeId () != TYPEID_PLAYER && ! unit -> IsVehicle ())
return ;
2008-10-11 14:16:25 -05:00
Player * player = unit -> GetCharmerOrOwnerPlayerOrPlayerItself ();
2010-04-07 19:14:10 +02:00
if ( ! player ) // normal creature, no player involved
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
m_lootRecipient = player -> GetGUID ();
2011-06-12 01:47:45 +02:00
if ( Group * group = player -> GetGroup ())
2014-10-22 00:35:00 +02:00
m_lootRecipientGroup = group -> GetGUID ();
2010-09-15 13:44:40 +02:00
2019-06-03 20:40:34 +02:00
AddDynamicFlag ( UNIT_DYNFLAG_TAPPED );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-03-14 00:22:53 +01:00
// return true if this creature is tapped by the player or by a member of his group.
2011-08-19 14:53:40 +02:00
bool Creature :: isTappedBy ( Player const * player ) const
2010-03-14 00:22:53 +01:00
{
if ( player -> GetGUID () == m_lootRecipient )
return true ;
2011-08-19 14:53:40 +02:00
Group const * playerGroup = player -> GetGroup ();
2010-09-15 13:44:40 +02:00
if ( ! playerGroup || playerGroup != GetLootRecipientGroup ()) // if we dont have a group we arent the recipient
return false ; // if creature doesnt have group bound it means it was solo killed by someone else
2010-03-14 00:22:53 +01:00
return true ;
}
2008-10-11 14:16:25 -05:00
void Creature :: SaveToDB ()
{
// this should only be used when the creature has already been loaded
2008-11-14 16:28:45 -06:00
// preferably after adding to map, because mapid may not be valid otherwise
2015-02-25 00:13:14 +01:00
CreatureData const * data = sObjectMgr -> GetCreatureData ( m_spawnId );
2010-04-07 19:14:10 +02:00
if ( ! data )
2008-10-11 14:16:25 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "entities.unit" , "Creature::SaveToDB failed, cannot get creature data!" );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2016-05-30 23:49:35 +02:00
uint32 mapId = GetTransport () ? GetTransport () -> GetGOInfo () -> moTransport . SpawnMap : GetMapId ();
2018-09-15 17:55:26 +02:00
SaveToDB ( mapId , data -> spawnDifficulties );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2018-09-15 17:55:26 +02:00
void Creature :: SaveToDB ( uint32 mapid , std :: vector < Difficulty > const & spawnDifficulties )
2008-10-11 14:16:25 -05:00
{
// update in loaded data
2015-02-25 00:13:14 +01:00
if ( ! m_spawnId )
m_spawnId = sObjectMgr -> GenerateCreatureSpawnId ();
2014-10-22 17:33:55 +02:00
2015-02-25 00:13:14 +01:00
CreatureData & data = sObjectMgr -> NewOrExistCreatureData ( m_spawnId );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 displayId = GetNativeDisplayId ();
2019-06-03 20:40:34 +02:00
uint64 npcflag = ( uint64 ( m_unitData -> NpcFlags [ 1 ]) << 32 ) | m_unitData -> NpcFlags [ 0 ];
uint32 unitFlags = m_unitData -> Flags ;
uint32 unitFlags2 = m_unitData -> Flags2 ;
uint32 unitFlags3 = m_unitData -> Flags3 ;
uint32 dynamicflags = m_objectData -> DynamicFlags ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// check if it's a custom model and if not, use 0 for displayId
2012-05-30 08:01:02 +02:00
CreatureTemplate const * cinfo = GetCreatureTemplate ();
2009-06-15 18:02:12 -05:00
if ( cinfo )
2008-10-11 14:16:25 -05:00
{
2018-11-07 20:23:30 +01:00
for ( CreatureModel model : cinfo -> Models )
if ( displayId && displayId == model . CreatureDisplayID )
displayId = 0 ;
2010-10-09 17:52:00 +02:00
if ( npcflag == cinfo -> npcflag )
npcflag = 0 ;
2017-05-21 14:15:04 +02:00
if ( unitFlags == cinfo -> unit_flags )
unitFlags = 0 ;
if ( unitFlags2 == cinfo -> unit_flags2 )
unitFlags2 = 0 ;
if ( unitFlags3 == cinfo -> unit_flags3 )
unitFlags3 = 0 ;
2010-10-09 17:52:00 +02:00
if ( dynamicflags == cinfo -> dynamicflags )
dynamicflags = 0 ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2011-07-29 14:18:28 +02:00
// data->guid = guid must not be updated at save
2008-10-11 14:16:25 -05:00
data . id = GetEntry ();
data . mapid = mapid ;
data . displayid = displayId ;
2013-02-18 12:24:18 +00:00
data . equipmentId = GetCurrentEquipmentId ();
2013-10-16 18:37:29 +02:00
if ( ! GetTransport ())
{
data . posX = GetPositionX ();
data . posY = GetPositionY ();
data . posZ = GetPositionZMinusOffset ();
data . orientation = GetOrientation ();
}
else
{
data . posX = GetTransOffsetX ();
data . posY = GetTransOffsetY ();
data . posZ = GetTransOffsetZ ();
data . orientation = GetTransOffsetO ();
}
2008-10-11 14:16:25 -05:00
data . spawntimesecs = m_respawnDelay ;
// prevent add data integrity problems
2012-05-30 08:01:02 +02:00
data . spawndist = GetDefaultMovementType () == IDLE_MOTION_TYPE ? 0.0f : m_respawnradius ;
2008-10-11 14:16:25 -05:00
data . currentwaypoint = 0 ;
data . curhealth = GetHealth ();
data . curmana = GetPower ( POWER_MANA );
// prevent add data integrity problems
2010-04-07 23:25:02 +02:00
data . movementType = ! m_respawnradius && GetDefaultMovementType () == RANDOM_MOTION_TYPE
2008-10-11 14:16:25 -05:00
? IDLE_MOTION_TYPE : GetDefaultMovementType ();
2018-09-15 17:55:26 +02:00
data . spawnDifficulties = spawnDifficulties ;
2010-10-09 17:52:00 +02:00
data . npcflag = npcflag ;
2017-05-21 14:15:04 +02:00
data . unit_flags = unitFlags ;
data . unit_flags2 = unitFlags2 ;
data . unit_flags3 = unitFlags3 ;
2010-10-09 17:52:00 +02:00
data . dynamicflags = dynamicflags ;
2015-04-06 00:40:56 +02:00
2018-01-10 22:01:40 +01:00
data . phaseId = GetDBPhase () > 0 ? GetDBPhase () : data . phaseId ;
data . phaseGroup = GetDBPhase () < 0 ? - GetDBPhase () : data . phaseGroup ;
2009-10-17 15:51:44 -07:00
2011-07-29 14:18:28 +02:00
// update in DB
2010-08-21 03:19:25 +02:00
SQLTransaction trans = WorldDatabase . BeginTransaction ();
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_CREATURE );
2015-02-25 00:13:14 +01:00
stmt -> setUInt64 ( 0 , m_spawnId );
2012-05-30 08:01:02 +02:00
trans -> Append ( stmt );
uint8 index = 0 ;
stmt = WorldDatabase . GetPreparedStatement ( WORLD_INS_CREATURE );
2015-02-25 00:13:14 +01:00
stmt -> setUInt64 ( index ++ , m_spawnId );
2012-05-30 08:01:02 +02:00
stmt -> setUInt32 ( index ++ , GetEntry ());
stmt -> setUInt16 ( index ++ , uint16 ( mapid ));
2018-09-15 17:55:26 +02:00
stmt -> setString ( index ++ , StringJoin ( data . spawnDifficulties , "," ));
2018-01-06 19:56:11 +01:00
stmt -> setUInt32 ( index ++ , data . phaseId );
2015-03-16 07:28:49 +01:00
stmt -> setUInt32 ( index ++ , data . phaseGroup );
2012-05-30 08:01:02 +02:00
stmt -> setUInt32 ( index ++ , displayId );
2015-01-24 19:49:05 +01:00
stmt -> setUInt8 ( index ++ , GetCurrentEquipmentId ());
2012-05-30 08:01:02 +02:00
stmt -> setFloat ( index ++ , GetPositionX ());
stmt -> setFloat ( index ++ , GetPositionY ());
stmt -> setFloat ( index ++ , GetPositionZ ());
stmt -> setFloat ( index ++ , GetOrientation ());
stmt -> setUInt32 ( index ++ , m_respawnDelay );
stmt -> setFloat ( index ++ , m_respawnradius );
stmt -> setUInt32 ( index ++ , 0 );
stmt -> setUInt32 ( index ++ , GetHealth ());
stmt -> setUInt32 ( index ++ , GetPower ( POWER_MANA ));
stmt -> setUInt8 ( index ++ , uint8 ( GetDefaultMovementType ()));
2015-05-04 12:39:36 +02:00
stmt -> setUInt64 ( index ++ , npcflag );
2017-05-21 14:15:04 +02:00
stmt -> setUInt32 ( index ++ , unitFlags );
stmt -> setUInt32 ( index ++ , unitFlags2 );
stmt -> setUInt32 ( index ++ , unitFlags3 );
2012-05-30 08:01:02 +02:00
stmt -> setUInt32 ( index ++ , dynamicflags );
trans -> Append ( stmt );
2009-10-17 15:51:44 -07:00
2010-08-21 03:19:25 +02:00
WorldDatabase . CommitTransaction ( trans );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2014-01-06 20:30:11 +01:00
void Creature :: SelectLevel ()
2008-10-11 14:16:25 -05:00
{
2014-01-06 20:30:11 +01:00
CreatureTemplate const * cInfo = GetCreatureTemplate ();
2018-04-12 21:57:49 +02:00
// level
uint8 minlevel = std :: min ( cInfo -> maxlevel , cInfo -> minlevel );
uint8 maxlevel = std :: max ( cInfo -> maxlevel , cInfo -> minlevel );
uint8 level = minlevel == maxlevel ? minlevel : urand ( minlevel , maxlevel );
SetLevel ( level );
if ( HasScalableLevels ())
2017-07-29 21:40:28 +02:00
{
2019-06-03 20:40:34 +02:00
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: ScalingLevelMin ), cInfo -> levelScaling -> MinLevel );
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: ScalingLevelMax ), cInfo -> levelScaling -> MaxLevel );
2018-04-12 21:57:49 +02:00
int8 mindelta = std :: min ( cInfo -> levelScaling -> DeltaLevelMax , cInfo -> levelScaling -> DeltaLevelMin );
int8 maxdelta = std :: max ( cInfo -> levelScaling -> DeltaLevelMax , cInfo -> levelScaling -> DeltaLevelMin );
int8 delta = mindelta == maxdelta ? mindelta : irand ( mindelta , maxdelta );
2019-06-03 20:40:34 +02:00
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: ScalingLevelDelta ), delta );
2017-07-29 21:40:28 +02:00
}
UpdateLevelDependantStats ();
2016-09-24 03:50:20 +02:00
}
2009-10-17 15:51:44 -07:00
2016-09-24 03:50:20 +02:00
void Creature :: UpdateLevelDependantStats ()
{
CreatureTemplate const * cInfo = GetCreatureTemplate ();
uint32 rank = IsPet () ? 0 : cInfo -> rank ;
CreatureBaseStats const * stats = sObjectMgr -> GetCreatureBaseStats ( getLevel (), cInfo -> unit_class );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// health
float healthmod = _GetHealthMod ( rank );
2009-10-17 15:51:44 -07:00
2014-01-06 20:30:11 +01:00
uint32 basehp = stats -> GenerateHealth ( cInfo );
2009-12-20 20:23:18 -07:00
uint32 health = uint32 ( basehp * healthmod );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
SetCreateHealth ( health );
SetMaxHealth ( health );
SetHealth ( health );
2009-06-11 17:54:59 +02:00
ResetPlayerDamageReq ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// mana
2014-01-06 20:30:11 +01:00
uint32 mana = stats -> GenerateMana ( cInfo );
2008-10-11 14:16:25 -05:00
SetCreateMana ( mana );
2009-10-17 15:51:44 -07:00
2012-07-24 15:28:41 +02:00
switch ( getClass ())
{
2018-03-04 12:48:22 +01:00
case CLASS_PALADIN :
case CLASS_MAGE :
SetMaxPower ( POWER_MANA , mana );
SetFullPower ( POWER_MANA );
2012-07-24 15:28:41 +02:00
break ;
2018-03-04 12:48:22 +01:00
default : // We don't set max power here, 0 makes power bar hidden
2012-07-24 15:28:41 +02:00
break ;
}
2009-10-17 15:51:44 -07:00
2010-08-22 12:39:39 -07:00
SetModifierValue ( UNIT_MOD_HEALTH , BASE_VALUE , ( float ) health );
2008-10-11 14:16:25 -05:00
2014-01-04 18:22:06 +01:00
// damage
2014-01-06 20:30:11 +01:00
float basedamage = stats -> GenerateBaseDamage ( cInfo );
2009-10-17 15:51:44 -07:00
2014-01-04 18:22:06 +01:00
float weaponBaseMinDamage = basedamage ;
2014-08-21 16:56:11 +02:00
float weaponBaseMaxDamage = basedamage * 1.5f ;
2009-10-17 15:51:44 -07:00
2014-01-04 18:22:06 +01:00
SetBaseWeaponDamage ( BASE_ATTACK , MINDAMAGE , weaponBaseMinDamage );
SetBaseWeaponDamage ( BASE_ATTACK , MAXDAMAGE , weaponBaseMaxDamage );
2009-10-17 15:51:44 -07:00
2014-01-04 18:22:06 +01:00
SetBaseWeaponDamage ( OFF_ATTACK , MINDAMAGE , weaponBaseMinDamage );
SetBaseWeaponDamage ( OFF_ATTACK , MAXDAMAGE , weaponBaseMaxDamage );
2009-10-17 15:51:44 -07:00
2014-01-04 18:22:06 +01:00
SetBaseWeaponDamage ( RANGED_ATTACK , MINDAMAGE , weaponBaseMinDamage );
SetBaseWeaponDamage ( RANGED_ATTACK , MAXDAMAGE , weaponBaseMaxDamage );
2009-10-17 15:51:44 -07:00
2014-01-04 18:22:06 +01:00
SetModifierValue ( UNIT_MOD_ATTACK_POWER , BASE_VALUE , stats -> AttackPower );
SetModifierValue ( UNIT_MOD_ATTACK_POWER_RANGED , BASE_VALUE , stats -> RangedAttackPower );
2016-09-24 03:50:20 +02:00
float armor = ( float ) stats -> GenerateArmor ( cInfo ); /// @todo Why is this treated as uint32 when it's a float?
SetModifierValue ( UNIT_MOD_ARMOR , BASE_VALUE , armor );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
float Creature :: _GetHealthMod ( int32 Rank )
{
switch ( Rank ) // define rates for each elite rank
{
case CREATURE_ELITE_NORMAL :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_NORMAL_HP );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_ELITE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_ELITE_HP );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_RAREELITE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_RAREELITE_HP );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_WORLDBOSS :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_WORLDBOSS_HP );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_RARE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_RARE_HP );
2008-10-11 14:16:25 -05:00
default :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_ELITE_HP );
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2017-06-07 17:23:50 +02:00
void Creature :: LowerPlayerDamageReq ( uint64 unDamage )
2013-03-04 12:41:17 +01:00
{
if ( m_PlayerDamageReq )
m_PlayerDamageReq > unDamage ? m_PlayerDamageReq -= unDamage : m_PlayerDamageReq = 0 ;
}
2008-10-11 14:16:25 -05:00
float Creature :: _GetDamageMod ( int32 Rank )
{
switch ( Rank ) // define rates for each elite rank
{
case CREATURE_ELITE_NORMAL :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_NORMAL_DAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_ELITE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_ELITE_DAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_RAREELITE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_RAREELITE_DAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_WORLDBOSS :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_WORLDBOSS_DAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_RARE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_RARE_DAMAGE );
2008-10-11 14:16:25 -05:00
default :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_ELITE_DAMAGE );
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2013-03-20 14:18:26 +01:00
float Creature :: GetSpellDamageMod ( int32 Rank ) const
2008-10-11 14:16:25 -05:00
{
switch ( Rank ) // define rates for each elite rank
{
case CREATURE_ELITE_NORMAL :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_NORMAL_SPELLDAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_ELITE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_ELITE_SPELLDAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_RAREELITE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_RAREELITE_SPELLDAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_WORLDBOSS :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_WORLDBOSS_SPELLDAMAGE );
2008-10-11 14:16:25 -05:00
case CREATURE_ELITE_RARE :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_RARE_SPELLDAMAGE );
2008-10-11 14:16:25 -05:00
default :
2010-12-23 23:25:44 +01:00
return sWorld -> getRate ( RATE_CREATURE_ELITE_ELITE_SPELLDAMAGE );
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2014-10-26 02:57:28 +02:00
bool Creature :: CreateFromProto ( ObjectGuid :: LowType guidlow , uint32 entry , CreatureData const * data /*= nullptr*/ , uint32 vehId /*= 0*/ )
2008-10-11 14:16:25 -05:00
{
2009-05-30 22:15:05 -05:00
SetZoneScript ();
2014-01-04 18:22:06 +01:00
if ( GetZoneScript () && data )
2009-05-30 22:15:05 -05:00
{
2014-04-28 20:05:36 +02:00
entry = GetZoneScript () -> GetCreatureEntry ( guidlow , data );
if ( ! entry )
2009-05-30 22:15:05 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2014-04-28 20:05:36 +02:00
CreatureTemplate const * cinfo = sObjectMgr -> GetCreatureTemplate ( entry );
2010-04-07 19:14:10 +02:00
if ( ! cinfo )
2008-10-11 14:16:25 -05:00
{
2014-10-27 21:56:12 +00:00
TC_LOG_ERROR ( "sql.sql" , "Creature::CreateFromProto(): creature template (guidlow: " UI64FMTD ", entry: %u) does not exist." , guidlow , entry );
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2014-04-28 20:05:36 +02:00
SetOriginalEntry ( entry );
2009-10-17 15:51:44 -07:00
2014-10-29 21:13:21 +01:00
if ( vehId || cinfo -> VehicleId )
Object :: _Create ( ObjectGuid :: Create < HighGuid :: Vehicle > ( GetMapId (), entry , guidlow ));
else
Object :: _Create ( ObjectGuid :: Create < HighGuid :: Creature > ( GetMapId (), entry , guidlow ));
2009-10-17 15:51:44 -07:00
2014-04-28 20:05:36 +02:00
if ( ! UpdateEntry ( entry , data ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2014-06-15 17:49:17 +02:00
if ( ! vehId )
{
if ( GetCreatureTemplate () -> VehicleId )
{
vehId = GetCreatureTemplate () -> VehicleId ;
entry = GetCreatureTemplate () -> Entry ;
}
else
vehId = cinfo -> VehicleId ;
}
2013-03-13 11:34:58 +01:00
if ( vehId )
2015-04-06 00:40:56 +02:00
CreateVehicleKit ( vehId , entry , true );
2013-02-18 00:39:58 +01:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2016-02-03 12:34:38 +00:00
bool Creature :: LoadCreatureFromDB ( ObjectGuid :: LowType spawnId , Map * map , bool addToMap , bool allowDuplicate )
2008-10-11 14:16:25 -05:00
{
2016-02-03 12:34:38 +00:00
if ( ! allowDuplicate )
{
// If an alive instance of this spawnId is already found, skip creation
// If only dead instance(s) exist, despawn them and spawn a new (maybe also dead) version
const auto creatureBounds = map -> GetCreatureBySpawnIdStore (). equal_range ( spawnId );
std :: vector < Creature *> despawnList ;
if ( creatureBounds . first != creatureBounds . second )
{
for ( auto itr = creatureBounds . first ; itr != creatureBounds . second ; ++ itr )
{
if ( itr -> second -> IsAlive ())
{
2016-04-02 19:22:30 +02:00
TC_LOG_DEBUG ( "maps" , "Would have spawned " UI64FMTD " but %s already exists" , spawnId , creatureBounds . first -> second -> GetGUID (). ToString (). c_str ());
2016-02-03 12:34:38 +00:00
return false ;
}
else
{
despawnList . push_back ( itr -> second );
2016-04-02 19:22:30 +02:00
TC_LOG_DEBUG ( "maps" , "Despawned dead instance of spawn " UI64FMTD " (%s)" , spawnId , itr -> second -> GetGUID (). ToString (). c_str ());
2016-02-03 12:34:38 +00:00
}
}
for ( Creature * despawnCreature : despawnList )
{
despawnCreature -> AddObjectToRemoveList ();
}
}
}
2015-02-25 00:13:14 +01:00
CreatureData const * data = sObjectMgr -> GetCreatureData ( spawnId );
2010-04-07 19:14:10 +02:00
if ( ! data )
2008-10-11 14:16:25 -05:00
{
2015-02-25 00:13:14 +01:00
TC_LOG_ERROR ( "sql.sql" , "Creature (GUID: " UI64FMTD ") not found in table `creature`, can't load. " , spawnId );
2008-10-11 14:16:25 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2015-02-25 00:13:14 +01:00
m_spawnId = spawnId ;
2016-08-08 11:22:11 +02:00
m_creatureData = data ;
2017-02-05 15:02:08 +01:00
m_respawnradius = data -> spawndist ;
m_respawnDelay = data -> spawntimesecs ;
2018-01-27 21:47:37 +01:00
if ( ! Create ( map -> GenerateLowGuid < HighGuid :: Creature > (), map , data -> id , data -> posX , data -> posY , data -> posZ , data -> orientation , data , 0 ))
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2009-02-09 08:16:34 -05:00
//We should set first home position, because then AI calls home movement
2011-04-29 20:47:02 +02:00
SetHomePosition ( data -> posX , data -> posY , data -> posZ , data -> orientation );
2009-10-17 15:51:44 -07:00
2011-06-27 20:22:53 +02:00
m_deathState = ALIVE ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:02:08 +01:00
m_respawnTime = GetMap () -> GetCreatureRespawnTime ( m_spawnId );
2016-09-09 16:21:27 +02:00
// Is the creature script objecting to us spawning? If yes, delay by one second (then re-check in ::Update)
if ( ! m_respawnTime && ! sScriptMgr -> CanSpawn ( spawnId , GetEntry (), GetCreatureTemplate (), GetCreatureData (), map ))
m_respawnTime = time ( NULL ) + 1 ;
2010-04-07 19:14:10 +02:00
if ( m_respawnTime ) // respawn on Update
2008-12-08 16:34:03 -06:00
{
2008-10-11 14:16:25 -05:00
m_deathState = DEAD ;
2012-05-30 08:01:02 +02:00
if ( CanFly ())
2008-12-08 16:34:03 -06:00
{
2018-01-28 11:37:20 +01:00
float tz = map -> GetHeight ( GetPhaseShift (), data -> posX , data -> posY , data -> posZ , true , MAX_FALL_DISTANCE );
2016-03-15 22:02:14 +01:00
if ( data -> posZ - tz > 0.1f && Trinity :: IsValidMapCoord ( tz ))
2011-04-29 20:47:02 +02:00
Relocate ( data -> posX , data -> posY , tz );
2008-12-08 16:34:03 -06:00
}
}
2009-10-17 15:51:44 -07:00
2016-08-08 11:22:11 +02:00
SetSpawnHealth ();
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// checked at creature_template loading
m_defaultMovementType = MovementGeneratorType ( data -> movementType );
2009-10-17 15:51:44 -07:00
2015-02-25 00:13:14 +01:00
loot . SetGUID ( ObjectGuid :: Create < HighGuid :: LootObject > ( data -> mapid , data -> id , GetMap () -> GenerateLowGuid < HighGuid :: LootObject > ()));
2014-12-30 02:23:37 +02:00
2011-11-28 14:05:25 -05:00
if ( addToMap && ! GetMap () -> AddToMap ( this ))
return false ;
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2014-01-04 18:22:06 +01:00
void Creature :: SetCanDualWield ( bool value )
{
Unit :: SetCanDualWield ( value );
UpdateDamagePhysical ( OFF_ATTACK );
}
2013-02-18 12:24:18 +00:00
void Creature :: LoadEquipment ( int8 id , bool force /*= true*/ )
2008-10-11 14:16:25 -05:00
{
2013-02-18 12:24:18 +00:00
if ( id == 0 )
2008-10-11 14:16:25 -05:00
{
if ( force )
{
2013-02-18 12:24:18 +00:00
for ( uint8 i = 0 ; i < MAX_EQUIPMENT_ITEMS ; ++ i )
2015-07-01 02:22:03 +02:00
SetVirtualItem ( i , 0 );
2008-10-11 14:16:25 -05:00
m_equipmentId = 0 ;
}
2016-01-30 11:40:24 +02:00
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2013-02-18 12:24:18 +00:00
EquipmentInfo const * einfo = sObjectMgr -> GetEquipmentInfo ( GetEntry (), id );
2008-10-11 14:16:25 -05:00
if ( ! einfo )
return ;
2009-10-17 15:51:44 -07:00
2013-02-18 12:24:18 +00:00
m_equipmentId = id ;
2015-07-01 02:22:03 +02:00
for ( uint8 i = 0 ; i < MAX_EQUIPMENT_ITEMS ; ++ i )
2017-02-19 10:58:08 +01:00
SetVirtualItem ( i , einfo -> Items [ i ]. ItemId , einfo -> Items [ i ]. AppearanceModId , einfo -> Items [ i ]. ItemVisual );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2016-08-08 11:22:11 +02:00
void Creature :: SetSpawnHealth ()
{
2016-10-11 01:43:14 -03:00
if ( ! m_creatureData )
return ;
2016-08-08 11:22:11 +02:00
uint32 curhealth ;
if ( ! m_regenHealth )
{
2016-10-11 01:43:14 -03:00
curhealth = m_creatureData -> curhealth ;
if ( curhealth )
2016-08-08 11:22:11 +02:00
{
2016-10-11 01:43:14 -03:00
curhealth = uint32 ( curhealth * _GetHealthMod ( GetCreatureTemplate () -> rank ));
if ( curhealth < 1 )
curhealth = 1 ;
2016-08-08 11:22:11 +02:00
}
2016-10-11 01:43:14 -03:00
SetPower ( POWER_MANA , m_creatureData -> curmana );
2016-08-08 11:22:11 +02:00
}
else
{
curhealth = GetMaxHealth ();
2018-01-03 16:39:00 +01:00
SetFullPower ( POWER_MANA );
2016-08-08 11:22:11 +02:00
}
SetHealth (( m_deathState == ALIVE || m_deathState == JUST_RESPAWNED ) ? curhealth : 0 );
}
2008-10-11 14:16:25 -05:00
bool Creature :: hasQuest ( uint32 quest_id ) const
{
2010-12-22 21:25:23 +01:00
QuestRelationBounds qr = sObjectMgr -> GetCreatureQuestRelationBounds ( GetEntry ());
2010-09-13 13:18:27 +02:00
for ( QuestRelations :: const_iterator itr = qr . first ; itr != qr . second ; ++ itr )
2008-10-11 14:16:25 -05:00
{
2010-04-07 23:25:02 +02:00
if ( itr -> second == quest_id )
2008-10-11 14:16:25 -05:00
return true ;
}
return false ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool Creature :: hasInvolvedQuest ( uint32 quest_id ) const
{
2010-12-22 21:25:23 +01:00
QuestRelationBounds qir = sObjectMgr -> GetCreatureQuestInvolvedRelationBounds ( GetEntry ());
2010-09-13 13:18:27 +02:00
for ( QuestRelations :: const_iterator itr = qir . first ; itr != qir . second ; ++ itr )
2008-10-11 14:16:25 -05:00
{
2010-04-07 23:25:02 +02:00
if ( itr -> second == quest_id )
2008-10-11 14:16:25 -05:00
return true ;
}
return false ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: DeleteFromDB ()
{
2015-02-25 00:13:14 +01:00
if ( ! m_spawnId )
2008-10-11 14:16:25 -05:00
{
2014-10-22 17:33:55 +02:00
TC_LOG_ERROR ( "entities.unit" , "Trying to delete not saved %s!" , GetGUID (). ToString (). c_str ());
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2015-02-25 00:13:14 +01:00
GetMap () -> RemoveCreatureRespawnTime ( m_spawnId );
sObjectMgr -> DeleteCreatureData ( m_spawnId );
2009-10-17 15:51:44 -07:00
2010-08-21 03:19:25 +02:00
SQLTransaction trans = WorldDatabase . BeginTransaction ();
2012-05-30 08:01:02 +02:00
PreparedStatement * stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_CREATURE );
2015-02-25 00:13:14 +01:00
stmt -> setUInt64 ( 0 , m_spawnId );
2012-05-30 08:01:02 +02:00
trans -> Append ( stmt );
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_CREATURE_ADDON );
2015-02-25 00:13:14 +01:00
stmt -> setUInt64 ( 0 , m_spawnId );
2012-05-30 08:01:02 +02:00
trans -> Append ( stmt );
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_GAME_EVENT_CREATURE );
2015-02-25 00:13:14 +01:00
stmt -> setUInt64 ( 0 , m_spawnId );
2012-05-30 08:01:02 +02:00
trans -> Append ( stmt );
stmt = WorldDatabase . GetPreparedStatement ( WORLD_DEL_GAME_EVENT_MODEL_EQUIP );
2015-02-25 00:13:14 +01:00
stmt -> setUInt64 ( 0 , m_spawnId );
2012-05-30 08:01:02 +02:00
trans -> Append ( stmt );
2010-08-21 03:19:25 +02:00
WorldDatabase . CommitTransaction ( trans );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2011-10-13 13:26:27 -04:00
bool Creature :: IsInvisibleDueToDespawn () const
2008-11-06 10:27:58 -06:00
{
2011-10-13 13:26:27 -04:00
if ( Unit :: IsInvisibleDueToDespawn ())
return true ;
2009-10-17 15:51:44 -07:00
2013-12-11 09:38:24 +07:00
if ( IsAlive () || isDying () || m_corpseRemoveTime > time ( NULL ))
2011-10-13 13:26:27 -04:00
return false ;
2009-10-17 15:51:44 -07:00
2011-10-13 13:26:27 -04:00
return true ;
2008-11-06 10:27:58 -06:00
}
2009-10-17 15:51:44 -07:00
2011-10-13 17:01:55 -04:00
bool Creature :: CanAlwaysSee ( WorldObject const * obj ) const
2011-02-10 22:36:35 -03:00
{
if ( IsAIEnabled && AI () -> CanSeeAlways ( obj ))
return true ;
return false ;
}
2013-06-11 21:25:12 -02:30
bool Creature :: CanStartAttack ( Unit const * who , bool force ) const
2008-11-21 10:07:11 -06:00
{
2013-06-11 19:54:27 -02:30
if ( IsCivilian ())
2009-06-15 12:02:55 -05:00
return false ;
2009-10-17 16:20:24 -07:00
2015-06-26 16:52:40 +02:00
// This set of checks is should be done only for creatures
2019-06-03 20:40:34 +02:00
if (( HasUnitFlag ( UNIT_FLAG_IMMUNE_TO_NPC ) && who -> GetTypeId () != TYPEID_PLAYER ) // flag is valid only for non player characters
|| ( HasUnitFlag ( UNIT_FLAG_IMMUNE_TO_PC ) && who -> GetTypeId () == TYPEID_PLAYER ) // immune to PC and target is a player, return false
|| ( who -> GetOwner () && who -> GetOwner () -> GetTypeId () == TYPEID_PLAYER && HasUnitFlag ( UNIT_FLAG_IMMUNE_TO_PC ))) // player pets are immune to pc as well
2015-06-26 16:52:40 +02:00
return false ;
2015-07-05 04:03:36 +02:00
2011-10-01 16:57:10 +01:00
// Do not attack non-combat pets
if ( who -> GetTypeId () == TYPEID_UNIT && who -> GetCreatureType () == CREATURE_TYPE_NON_COMBAT_PET )
return false ;
2011-03-06 12:22:04 +01:00
2012-05-30 08:01:02 +02:00
if ( ! CanFly () && ( GetDistanceZ ( who ) > CREATURE_Z_ATTACK_RANGE + m_CombatDistance ))
2009-06-15 12:02:55 -05:00
//|| who->IsControlledByPlayer() && who->IsFlying()))
// we cannot check flying for other creatures, too much map/vmap calculation
2013-03-08 21:41:30 +01:00
/// @todo should switch to range attack
2008-11-21 10:07:11 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! force )
2009-08-27 13:54:57 -05:00
{
2010-04-07 19:14:10 +02:00
if ( ! _IsTargetAcceptable ( who ))
2009-09-29 01:16:08 -07:00
return false ;
2009-10-17 15:51:44 -07:00
2013-06-11 19:54:27 -02:30
if ( who -> IsInCombat () && IsWithinDist ( who , ATTACK_DISTANCE ))
2011-06-12 01:47:45 +02:00
if ( Unit * victim = who -> getAttackerForHelper ())
2010-12-23 23:25:44 +01:00
if ( IsWithinDistInMap ( victim , sWorld -> getFloatConfig ( CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS )))
2009-08-27 13:54:57 -05:00
force = true ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! force && ( IsNeutralToAll () || ! IsWithinDistInMap ( who , GetAttackDistance ( who ) + m_CombatDistance )))
2009-08-27 13:54:57 -05:00
return false ;
}
2009-10-17 15:51:44 -07:00
2013-06-11 21:25:12 -02:30
if ( ! CanCreatureAttack ( who , force ))
2008-11-21 10:07:11 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2015-01-26 19:15:06 +00:00
// No aggro from gray creatures
2017-07-29 21:40:28 +02:00
if ( CheckNoGrayAggroConfig ( who -> GetLevelForTarget ( this ), GetLevelForTarget ( who )))
2015-01-26 19:15:06 +00:00
return false ;
2008-11-21 10:07:11 -06:00
return IsWithinLOSInMap ( who );
}
2009-10-17 15:51:44 -07:00
2015-01-26 19:15:06 +00:00
bool Creature :: CheckNoGrayAggroConfig ( uint32 playerLevel , uint32 creatureLevel ) const
{
if ( Trinity :: XP :: GetColorCode ( playerLevel , creatureLevel ) != XP_GRAY )
return false ;
uint32 notAbove = sWorld -> getIntConfig ( CONFIG_NO_GRAY_AGGRO_ABOVE );
uint32 notBelow = sWorld -> getIntConfig ( CONFIG_NO_GRAY_AGGRO_BELOW );
if ( notAbove == 0 && notBelow == 0 )
return false ;
if ( playerLevel <= notBelow || ( playerLevel >= notAbove && notAbove > 0 ))
return true ;
return false ;
}
2011-11-07 11:18:00 -06:00
float Creature :: GetAttackDistance ( Unit const * player ) const
2008-10-11 14:16:25 -05:00
{
2017-11-15 21:56:15 +01:00
// WoW Wiki: the minimum radius seems to be 5 yards, while the maximum range is 45 yards
float maxRadius = ( 45.0f * sWorld -> getRate ( RATE_CREATURE_AGGRO ));
float minRadius = ( 5.0f * sWorld -> getRate ( RATE_CREATURE_AGGRO ));
2010-12-23 23:25:44 +01:00
float aggroRate = sWorld -> getRate ( RATE_CREATURE_AGGRO );
2017-11-15 21:56:15 +01:00
uint8 expansionMaxLevel = uint8 ( GetMaxLevelForExpansion ( GetCreatureTemplate () -> RequiredExpansion ));
2017-11-19 16:30:54 +01:00
uint32 playerLevel = player -> GetLevelForTarget ( this );
uint32 creatureLevel = GetLevelForTarget ( player );
2009-10-17 15:51:44 -07:00
2017-11-15 21:56:15 +01:00
if ( aggroRate == 0.0f )
2017-11-19 16:30:54 +01:00
return 0.0f ;
2009-10-17 15:51:44 -07:00
2017-11-15 21:56:15 +01:00
// The aggro radius for creatures with equal level as the player is 20 yards.
// The combatreach should not get taken into account for the distance so we drop it from the range (see Supremus as expample)
2017-11-19 16:30:54 +01:00
float baseAggroDistance = 20.0f - GetCombatReach ();
float aggroRadius = baseAggroDistance ;
2009-10-17 15:51:44 -07:00
2017-11-15 21:56:15 +01:00
// detect range auras
2017-11-19 16:30:54 +01:00
if (( creatureLevel + 5 ) <= sWorld -> getIntConfig ( CONFIG_MAX_PLAYER_LEVEL ))
2008-10-11 14:16:25 -05:00
{
2017-11-15 21:56:15 +01:00
aggroRadius += GetTotalAuraModifier ( SPELL_AURA_MOD_DETECT_RANGE );
2009-10-17 15:51:44 -07:00
2017-11-19 16:30:54 +01:00
aggroRadius += player -> GetTotalAuraModifier ( SPELL_AURA_MOD_DETECTED_RANGE );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2017-11-15 21:56:15 +01:00
// The aggro range of creatures with higher levels than the total player level for the expansion should get the maxlevel treatment
// This makes sure that creatures such as bosses wont have a bigger aggro range than the rest of the npc's
2017-11-19 16:30:54 +01:00
// The following code is used for blizzlike behavior such as skipable bosses (e.g. Commander Springvale at level 85)
if ( creatureLevel > expansionMaxLevel )
aggroRadius += float ( expansionMaxLevel ) - float ( playerLevel );
// + - 1 yard for each level difference between player and creature
else
aggroRadius += float ( creatureLevel ) - float ( playerLevel );
2017-11-15 21:56:15 +01:00
// Make sure that we wont go over the total range limits
if ( aggroRadius > maxRadius )
aggroRadius = maxRadius ;
else if ( aggroRadius < minRadius )
aggroRadius = minRadius ;
2009-10-17 15:51:44 -07:00
2017-11-15 21:56:15 +01:00
return ( aggroRadius * aggroRate );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: setDeathState ( DeathState s )
{
2011-06-27 20:22:53 +02:00
Unit :: setDeathState ( s );
if ( s == JUST_DIED )
2008-10-11 14:16:25 -05:00
{
2010-09-15 06:22:54 +02:00
m_corpseRemoveTime = time ( NULL ) + m_corpseDelay ;
2017-02-05 15:02:08 +01:00
if ( IsDungeonBoss () && ! m_respawnDelay )
m_respawnTime = std :: numeric_limits < time_t >:: max (); // never respawn in this instance
else
m_respawnTime = time ( NULL ) + m_respawnDelay + m_corpseDelay ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// always save boss respawn time at death to prevent crash cheating
2010-12-23 23:25:44 +01:00
if ( sWorld -> getBoolConfig ( CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY ) || isWorldBoss ())
2008-10-11 14:16:25 -05:00
SaveRespawnTime ();
2009-10-17 15:51:44 -07:00
2016-04-02 02:50:44 +02:00
ReleaseFocus ( nullptr , false ); // remove spellcast focus
2016-10-16 12:35:32 +02:00
DoNotReacquireTarget (); // cancel delayed re-target
2016-01-13 18:38:54 +01:00
SetTarget ( ObjectGuid :: Empty ); // drop target - dead mobs shouldn't ever target things
2019-06-03 20:40:34 +02:00
SetNpcFlags ( UNIT_NPC_FLAG_NONE );
SetNpcFlags2 ( UNIT_NPC_FLAG_2_NONE );
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
SetMountDisplayId ( 0 ); // if creature is mounted on a virtual mount, remove it at death
2015-04-19 14:56:12 +02:00
2009-06-03 19:29:55 -05:00
setActive ( false );
2009-10-17 15:51:44 -07:00
2010-01-16 19:35:30 +03:00
if ( HasSearchedAssistance ())
{
SetNoSearchAssistance ( false );
2016-04-16 01:36:32 +02:00
UpdateSpeed ( MOVE_RUN );
2010-01-16 19:35:30 +03:00
}
2009-10-17 16:20:24 -07:00
2009-04-07 10:51:45 +02:00
//Dismiss group if is leader
2010-04-07 19:14:10 +02:00
if ( m_formation && m_formation -> getLeader () == this )
2009-04-07 10:51:45 +02:00
m_formation -> FormationReset ( true );
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if (( CanFly () || IsFlying ()))
2013-12-12 09:50:52 +01:00
GetMotionMaster () -> MoveFall ();
2009-10-17 15:51:44 -07:00
2009-08-26 19:28:21 -05:00
Unit :: setDeathState ( CORPSE );
2009-04-07 10:51:45 +02:00
}
2012-05-30 08:01:02 +02:00
else if ( s == JUST_RESPAWNED )
2008-10-11 14:16:25 -05:00
{
2016-08-08 11:22:11 +02:00
if ( IsPet ())
SetFullHealth ();
else
SetSpawnHealth ();
2016-04-02 02:50:44 +02:00
SetLootRecipient ( nullptr );
2009-06-11 17:54:59 +02:00
ResetPlayerDamageReq ();
2012-12-27 19:31:22 +01:00
2016-11-03 13:55:30 +01:00
SetCannotReachTarget ( false );
2013-06-07 16:05:39 +02:00
UpdateMovementFlags ();
2012-12-27 19:31:22 +01:00
2013-12-31 14:12:02 +01:00
ClearUnitState ( uint32 ( UNIT_STATE_ALL_STATE & ~ UNIT_STATE_IGNORE_PATHFINDING ));
2016-01-24 01:11:19 +00:00
if ( ! IsPet ())
{
CreatureData const * creatureData = GetCreatureData ();
2017-05-21 14:15:04 +02:00
CreatureTemplate const * cInfo = GetCreatureTemplate ();
uint64 npcFlags ;
uint32 unitFlags , unitFlags2 , unitFlags3 , dynamicFlags ;
ObjectMgr :: ChooseCreatureFlags ( cInfo , npcFlags , unitFlags , unitFlags2 , unitFlags3 , dynamicFlags , creatureData );
2016-01-24 01:11:19 +00:00
2017-05-21 14:15:04 +02:00
if ( cInfo -> flags_extra & CREATURE_FLAG_EXTRA_WORLDEVENT )
2019-06-03 20:40:34 +02:00
npcFlags |= sGameEventMgr -> GetNPCFlag ( this );
SetNpcFlags ( NPCFlags ( npcFlags & 0xFFFFFFFF ));
SetNpcFlags2 ( NPCFlags2 ( npcFlags >> 32 ));
2016-01-24 01:11:19 +00:00
2019-06-03 20:40:34 +02:00
SetUnitFlags ( UnitFlags ( unitFlags ));
SetUnitFlags2 ( UnitFlags2 ( unitFlags2 ));
SetUnitFlags3 ( UnitFlags3 ( unitFlags3 ));
SetDynamicFlags ( dynamicFlags );
2016-01-24 01:11:19 +00:00
2019-06-03 20:40:34 +02:00
RemoveUnitFlag ( UNIT_FLAG_IN_COMBAT );
2016-01-24 01:11:19 +00:00
2017-05-21 14:15:04 +02:00
SetMeleeDamageSchool ( SpellSchools ( cInfo -> dmgschool ));
2016-01-24 01:11:19 +00:00
}
2009-04-06 20:33:52 -05:00
Motion_Initialize ();
2009-08-25 00:56:23 -05:00
Unit :: setDeathState ( ALIVE );
2015-11-10 19:58:13 +01:00
LoadCreaturesAddon ();
2009-04-07 10:51:45 +02:00
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2009-06-17 01:01:39 -05:00
void Creature :: Respawn ( bool force )
2008-10-11 14:16:25 -05:00
{
2009-06-17 01:01:39 -05:00
DestroyForNearbyPlayers ();
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( force )
2009-06-17 01:01:39 -05:00
{
2013-06-11 19:54:27 -02:30
if ( IsAlive ())
2009-06-17 01:01:39 -05:00
setDeathState ( JUST_DIED );
2010-04-07 19:14:10 +02:00
else if ( getDeathState () != CORPSE )
2009-06-17 01:01:39 -05:00
setDeathState ( CORPSE );
}
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
RemoveCorpse ( false , false );
2009-10-17 15:51:44 -07:00
2010-04-07 23:25:02 +02:00
if ( getDeathState () == DEAD )
2008-10-11 14:16:25 -05:00
{
2015-02-25 00:13:14 +01:00
if ( m_spawnId )
GetMap () -> RemoveCreatureRespawnTime ( m_spawnId );
2009-10-17 15:51:44 -07:00
2014-09-16 20:47:08 +02:00
TC_LOG_DEBUG ( "entities.unit" , "Respawning creature %s (%s)" ,
GetName (). c_str (), GetGUID (). ToString (). c_str ());
2009-04-14 14:33:48 +02:00
m_respawnTime = 0 ;
2014-07-31 21:41:41 +02:00
ResetPickPocketRefillTimer ();
2014-06-26 22:01:55 +02:00
loot . clear ();
2010-04-07 19:14:10 +02:00
if ( m_originalEntry != GetEntry ())
2009-04-14 14:33:48 +02:00
UpdateEntry ( m_originalEntry );
2017-07-29 21:40:28 +02:00
else
SelectLevel ();
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
setDeathState ( JUST_RESPAWNED );
2009-10-17 15:51:44 -07:00
2018-11-07 20:23:30 +01:00
CreatureModel display ( GetNativeDisplayId (), GetNativeDisplayScale (), 1.0f );
CreatureModelInfo const * minfo = sObjectMgr -> GetCreatureModelRandomGender ( & display , GetCreatureTemplate ());
2009-09-27 15:14:25 -07:00
if ( minfo ) // Cancel load if no model defined
{
2018-11-07 20:23:30 +01:00
SetDisplayId ( display . CreatureDisplayID , display . DisplayScale );
SetNativeDisplayId ( display . CreatureDisplayID , display . DisplayScale );
2019-06-03 20:40:34 +02:00
SetGender ( minfo -> gender );
2009-09-27 15:14:25 -07:00
}
2009-10-17 15:51:44 -07:00
2010-09-15 06:23:25 +02:00
GetMotionMaster () -> InitDefault ();
2016-10-15 13:19:03 +02:00
//Re-initialize reactstate that could be altered by movementgenerators
InitializeReactState ();
2010-09-15 06:23:25 +02:00
2009-04-14 14:33:48 +02:00
//Call AI respawn virtual function
2009-12-06 16:41:05 +01:00
if ( IsAIEnabled )
2013-12-15 21:14:47 +01:00
{
//reset the AI to be sure no dirty or uninitialized values will be used till next tick
AI () -> Reset ();
2016-04-02 02:50:44 +02:00
m_TriggerJustRespawned = true ; //delay event to next tick so all creatures are created on the map before processing
2013-12-15 21:14:47 +01:00
}
2009-10-17 15:51:44 -07:00
2015-02-25 00:13:14 +01:00
uint32 poolid = GetSpawnId () ? sPoolMgr -> IsPartOfAPool < Creature > ( GetSpawnId ()) : 0 ;
2009-04-15 17:06:38 -05:00
if ( poolid )
2015-02-25 00:13:14 +01:00
sPoolMgr -> UpdatePool < Creature > ( poolid , GetSpawnId ());
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-02-27 15:25:14 +02:00
UpdateObjectVisibility ();
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2016-08-25 23:04:21 +02:00
void Creature :: ForcedDespawn ( uint32 timeMSToDespawn , Seconds const & forceRespawnTimer )
2009-06-18 17:05:01 -05:00
{
2010-01-16 19:51:59 +03:00
if ( timeMSToDespawn )
{
2016-08-25 23:04:21 +02:00
ForcedDespawnDelayEvent * pEvent = new ForcedDespawnDelayEvent ( * this , forceRespawnTimer );
2010-01-16 19:51:59 +03:00
m_Events . AddEvent ( pEvent , m_Events . CalculateTime ( timeMSToDespawn ));
return ;
}
2017-02-05 15:39:22 +01:00
// do it before killing creature
DestroyForNearbyPlayers ();
if ( IsAlive ())
setDeathState ( JUST_DIED );
bool overrideRespawnTime = true ;
2017-04-24 09:19:58 -02:30
if ( forceRespawnTimer > Seconds :: zero ())
2016-08-25 23:04:21 +02:00
{
2017-02-05 15:39:22 +01:00
SetRespawnTime ( forceRespawnTimer . count ());
overrideRespawnTime = false ;
2016-08-25 23:04:21 +02:00
}
2010-01-16 19:51:59 +03:00
2017-02-05 15:39:22 +01:00
// Skip corpse decay time
RemoveCorpse ( overrideRespawnTime , false );
2009-06-18 17:05:01 -05:00
}
2009-10-17 15:51:44 -07:00
2016-08-25 23:04:21 +02:00
void Creature :: DespawnOrUnsummon ( uint32 msTimeToDespawn /*= 0*/ , Seconds const & forceRespawnTimer /*= 0*/ )
2011-01-02 21:33:37 +01:00
{
if ( TempSummon * summon = this -> ToTempSummon ())
2011-03-07 21:25:34 +01:00
summon -> UnSummon ( msTimeToDespawn );
2011-01-02 21:33:37 +01:00
else
2016-08-25 23:04:21 +02:00
ForcedDespawn ( msTimeToDespawn , forceRespawnTimer );
2011-01-02 21:33:37 +01:00
}
2017-02-04 23:50:32 +01:00
bool Creature :: HasMechanicTemplateImmunity ( uint32 mask ) const
{
return ! GetOwnerGUID (). IsPlayer () && ( GetCreatureTemplate () -> MechanicImmuneMask & mask );
}
2016-12-11 15:01:13 -03:00
bool Creature :: IsImmunedToSpell ( SpellInfo const * spellInfo , Unit * caster ) const
2008-10-11 14:16:25 -05:00
{
if ( ! spellInfo )
return false ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
// Creature is immune to main mechanic of the spell
2017-02-04 23:50:32 +01:00
if ( spellInfo -> Mechanic > MECHANIC_NONE && HasMechanicTemplateImmunity ( 1 << ( spellInfo -> Mechanic - 1 )))
2011-12-14 16:13:10 +01:00
return true ;
2012-05-30 08:01:02 +02:00
// This check must be done instead of 'if (GetCreatureTemplate()->MechanicImmuneMask & (1 << (spellInfo->Mechanic - 1)))' for not break
// the check of mechanic immunity on DB (tested) because GetCreatureTemplate()->MechanicImmuneMask and m_spellImmune[IMMUNITY_MECHANIC] don't have same data.
2011-12-14 16:13:10 +01:00
bool immunedToAllEffects = true ;
2015-01-10 01:35:47 +01:00
for ( SpellEffectInfo const * effect : spellInfo -> GetEffectsForDifficulty ( GetMap () -> GetDifficultyID ()))
2012-06-17 02:21:40 +02:00
{
2014-11-24 18:57:49 +01:00
if ( ! effect || ! effect -> IsEffect ())
2012-06-17 23:17:59 +02:00
continue ;
2017-02-04 23:50:32 +01:00
2016-12-11 15:01:13 -03:00
if ( ! IsImmunedToSpellEffect ( spellInfo , effect -> EffectIndex , caster ))
2011-12-14 16:13:10 +01:00
{
immunedToAllEffects = false ;
break ;
}
2012-06-17 02:21:40 +02:00
}
2017-02-04 23:50:32 +01:00
2011-12-14 16:13:10 +01:00
if ( immunedToAllEffects )
2008-10-11 14:16:25 -05:00
return true ;
2009-10-17 15:51:44 -07:00
2016-12-11 15:01:13 -03:00
return Unit :: IsImmunedToSpell ( spellInfo , caster );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2016-12-11 15:01:13 -03:00
bool Creature :: IsImmunedToSpellEffect ( SpellInfo const * spellInfo , uint32 index , Unit * caster ) const
2008-10-11 14:16:25 -05:00
{
2017-05-15 22:55:16 +02:00
SpellEffectInfo const * effect = spellInfo -> GetEffect ( GetMap () -> GetDifficultyID (), index );
2014-11-24 18:57:49 +01:00
if ( ! effect )
return true ;
2017-02-04 23:50:32 +01:00
if ( effect -> Mechanic > MECHANIC_NONE && HasMechanicTemplateImmunity ( 1 << ( effect -> Mechanic - 1 )))
2008-10-11 14:16:25 -05:00
return true ;
2009-10-17 15:51:44 -07:00
2014-11-24 18:57:49 +01:00
if ( GetCreatureTemplate () -> type == CREATURE_TYPE_MECHANICAL && effect -> Effect == SPELL_EFFECT_HEAL )
2010-07-28 01:26:18 +02:00
return true ;
2016-12-11 15:01:13 -03:00
return Unit :: IsImmunedToSpellEffect ( spellInfo , index , caster );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2013-03-04 12:41:17 +01:00
bool Creature :: isElite () const
{
2013-06-11 18:39:51 -02:30
if ( IsPet ())
2013-03-04 12:41:17 +01:00
return false ;
uint32 rank = GetCreatureTemplate () -> rank ;
return rank != CREATURE_ELITE_NORMAL && rank != CREATURE_ELITE_RARE ;
}
bool Creature :: isWorldBoss () const
{
2013-06-11 18:39:51 -02:30
if ( IsPet ())
2013-03-04 12:41:17 +01:00
return false ;
2016-05-26 12:56:50 +04:00
return ( GetCreatureTemplate () -> type_flags & CREATURE_TYPE_FLAG_BOSS_MOB ) != 0 ;
2013-03-04 12:41:17 +01:00
}
2012-05-30 08:01:02 +02:00
SpellInfo const * Creature :: reachWithSpellAttack ( Unit * victim )
2008-10-11 14:16:25 -05:00
{
2012-05-30 08:01:02 +02:00
if ( ! victim )
2016-04-02 02:50:44 +02:00
return nullptr ;
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
for ( uint32 i = 0 ; i < MAX_CREATURE_SPELLS ; ++ i )
2008-10-11 14:16:25 -05:00
{
2010-04-07 19:14:10 +02:00
if ( ! m_spells [ i ])
2008-10-11 14:16:25 -05:00
continue ;
2011-09-15 14:08:17 +02:00
SpellInfo const * spellInfo = sSpellMgr -> GetSpellInfo ( m_spells [ i ]);
2010-04-07 19:14:10 +02:00
if ( ! spellInfo )
2008-10-11 14:16:25 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "entities.unit" , "WORLD: unknown spell id %i" , m_spells [ i ]);
2008-10-11 14:16:25 -05:00
continue ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool bcontinue = true ;
2015-01-10 01:35:47 +01:00
for ( SpellEffectInfo const * effect : spellInfo -> GetEffectsForDifficulty ( GetMap () -> GetDifficultyID ()))
2008-10-11 14:16:25 -05:00
{
2014-11-24 18:57:49 +01:00
if ( effect && (( effect -> Effect == SPELL_EFFECT_SCHOOL_DAMAGE ) ||
( effect -> Effect == SPELL_EFFECT_INSTAKILL ) ||
( effect -> Effect == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE ) ||
( effect -> Effect == SPELL_EFFECT_HEALTH_LEECH )
))
2008-10-11 14:16:25 -05:00
{
bcontinue = false ;
break ;
}
}
2012-03-17 20:13:37 +08:00
if ( bcontinue )
continue ;
2009-10-17 15:51:44 -07:00
2017-05-21 23:18:43 +02:00
std :: vector < SpellPowerCost > costs = spellInfo -> CalcPowerCost ( this , SpellSchoolMask ( spellInfo -> SchoolMask ));
auto m = std :: find_if ( costs . begin (), costs . end (), []( SpellPowerCost const & cost ) { return cost . Power == POWER_MANA ; });
2015-03-08 13:31:57 +01:00
if ( m != costs . end ())
2015-03-22 13:47:55 +01:00
if ( m -> Amount > GetPower ( POWER_MANA ))
2015-03-08 13:31:57 +01:00
continue ;
2011-07-26 23:09:28 +02:00
float range = spellInfo -> GetMaxRange ( false );
float minrange = spellInfo -> GetMinRange ( false );
2012-05-30 08:01:02 +02:00
float dist = GetDistance ( victim );
2010-04-07 22:59:46 +02:00
if ( dist > range || dist < minrange )
2008-10-11 14:16:25 -05:00
continue ;
2019-06-03 20:40:34 +02:00
if ( spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_SILENCE && HasUnitFlag ( UNIT_FLAG_SILENCED ))
2009-01-07 11:56:57 -06:00
continue ;
2019-06-03 20:40:34 +02:00
if ( spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_PACIFY && HasUnitFlag ( UNIT_FLAG_PACIFIED ))
2008-10-11 14:16:25 -05:00
continue ;
return spellInfo ;
}
2016-04-02 02:50:44 +02:00
return nullptr ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
SpellInfo const * Creature :: reachWithSpellCure ( Unit * victim )
2008-10-11 14:16:25 -05:00
{
2012-05-30 08:01:02 +02:00
if ( ! victim )
2016-04-02 02:50:44 +02:00
return nullptr ;
2009-10-17 15:51:44 -07:00
2016-03-24 16:12:53 +01:00
for ( uint32 i = 0 ; i < MAX_CREATURE_SPELLS ; ++ i )
2008-10-11 14:16:25 -05:00
{
2010-04-07 19:14:10 +02:00
if ( ! m_spells [ i ])
2008-10-11 14:16:25 -05:00
continue ;
2011-09-15 14:08:17 +02:00
SpellInfo const * spellInfo = sSpellMgr -> GetSpellInfo ( m_spells [ i ]);
2010-04-07 19:14:10 +02:00
if ( ! spellInfo )
2008-10-11 14:16:25 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "entities.unit" , "WORLD: unknown spell id %i" , m_spells [ i ]);
2008-10-11 14:16:25 -05:00
continue ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool bcontinue = true ;
2015-01-10 01:35:47 +01:00
for ( SpellEffectInfo const * effect : spellInfo -> GetEffectsForDifficulty ( GetMap () -> GetDifficultyID ()))
2008-10-11 14:16:25 -05:00
{
2014-11-24 18:57:49 +01:00
if ( effect && ( effect -> Effect == SPELL_EFFECT_HEAL ))
2008-10-11 14:16:25 -05:00
{
bcontinue = false ;
break ;
}
}
2012-05-30 08:01:02 +02:00
if ( bcontinue )
continue ;
2009-10-17 15:51:44 -07:00
2017-05-21 23:18:43 +02:00
std :: vector < SpellPowerCost > costs = spellInfo -> CalcPowerCost ( this , SpellSchoolMask ( spellInfo -> SchoolMask ));
auto m = std :: find_if ( costs . begin (), costs . end (), []( SpellPowerCost const & cost ) { return cost . Power == POWER_MANA ; });
2015-03-08 13:31:57 +01:00
if ( m != costs . end ())
2015-03-22 13:47:55 +01:00
if ( m -> Amount > GetPower ( POWER_MANA ))
2015-03-08 13:31:57 +01:00
continue ;
2011-07-26 23:09:28 +02:00
float range = spellInfo -> GetMaxRange ( true );
float minrange = spellInfo -> GetMinRange ( true );
2012-05-30 08:01:02 +02:00
float dist = GetDistance ( victim );
//if (!isInFront(victim, range) && spellInfo->AttributesEx)
2008-10-11 14:16:25 -05:00
// continue;
2010-04-07 22:59:46 +02:00
if ( dist > range || dist < minrange )
2008-10-11 14:16:25 -05:00
continue ;
2019-06-03 20:40:34 +02:00
if ( spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_SILENCE && HasUnitFlag ( UNIT_FLAG_SILENCED ))
2009-01-07 11:56:57 -06:00
continue ;
2019-06-03 20:40:34 +02:00
if ( spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_PACIFY && HasUnitFlag ( UNIT_FLAG_PACIFIED ))
2008-10-11 14:16:25 -05:00
continue ;
return spellInfo ;
}
2016-04-02 02:50:44 +02:00
return nullptr ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-25 12:59:27 +02:00
// select nearest hostile unit within the given distance (regardless of threat list).
2013-09-30 10:11:02 +02:00
Unit * Creature :: SelectNearestTarget ( float dist , bool playerOnly /* = false */ ) const
2008-11-20 20:28:17 -06:00
{
2017-05-13 19:37:33 +02:00
if ( dist == 0.0f )
dist = MAX_VISIBILITY_DISTANCE ;
2009-10-17 15:51:44 -07:00
2016-04-02 02:50:44 +02:00
Unit * target = nullptr ;
2017-05-13 19:37:33 +02:00
Trinity :: NearestHostileUnitCheck u_check ( this , dist , playerOnly );
Trinity :: UnitLastSearcher < Trinity :: NearestHostileUnitCheck > searcher ( this , target , u_check );
Cell :: VisitAllObjects ( this , searcher , dist );
2010-04-25 12:59:27 +02:00
return target ;
}
// select nearest hostile unit within the given attack distance (i.e. distance is ignored if > than ATTACK_DISTANCE), regardless of threat list.
Unit * Creature :: SelectNearestTargetInAttackDistance ( float dist ) const
{
2011-06-12 17:13:28 +02:00
if ( dist > MAX_VISIBILITY_DISTANCE )
{
2014-10-22 17:33:55 +02:00
TC_LOG_ERROR ( "entities.unit" , "Creature (%s) SelectNearestTargetInAttackDistance called with dist > MAX_VISIBILITY_DISTANCE. Distance set to ATTACK_DISTANCE." , GetGUID (). ToString (). c_str ());
2011-06-12 17:13:28 +02:00
dist = ATTACK_DISTANCE ;
}
2010-04-25 12:59:27 +02:00
2017-05-13 19:37:33 +02:00
Unit * target = nullptr ;
Trinity :: NearestHostileUnitInAttackDistanceCheck u_check ( this , dist );
Trinity :: UnitLastSearcher < Trinity :: NearestHostileUnitInAttackDistanceCheck > searcher ( this , target , u_check );
Cell :: VisitAllObjects ( this , searcher , std :: max ( dist , ATTACK_DISTANCE ));
2008-11-21 10:07:11 -06:00
return target ;
2008-11-20 20:28:17 -06:00
}
2009-10-17 15:51:44 -07:00
2011-07-11 16:17:21 +02:00
Player * Creature :: SelectNearestPlayer ( float distance ) const
{
2016-04-02 02:50:44 +02:00
Player * target = nullptr ;
2011-07-11 16:17:21 +02:00
Trinity :: NearestPlayerInObjectRangeCheck checker ( this , distance );
Trinity :: PlayerLastSearcher < Trinity :: NearestPlayerInObjectRangeCheck > searcher ( this , target , checker );
2017-05-13 19:37:33 +02:00
Cell :: VisitAllObjects ( this , searcher , distance );
2011-07-11 16:17:21 +02:00
return target ;
}
2009-12-19 17:43:47 +01:00
void Creature :: SendAIReaction ( AiReaction reactionType )
{
2014-11-19 00:30:31 +02:00
WorldPackets :: Combat :: AIReaction packet ;
2009-12-19 17:43:47 +01:00
2014-11-19 00:30:31 +02:00
packet . UnitGUID = GetGUID ();
packet . Reaction = reactionType ;
2009-12-19 17:43:47 +01:00
2014-11-19 21:09:30 +01:00
SendMessageToSet ( packet . Write (), true );
2009-12-19 17:43:47 +01:00
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "network" , "WORLD: Sent SMSG_AI_REACTION, type %u." , reactionType );
2009-12-19 17:43:47 +01:00
}
2009-05-21 10:48:00 -05:00
void Creature :: CallAssistance ()
2008-10-11 14:16:25 -05:00
{
2013-06-11 19:54:27 -02:30
if ( ! m_AlreadyCallAssistance && GetVictim () && ! IsPet () && ! IsCharmed ())
2008-10-11 14:16:25 -05:00
{
2008-11-25 16:36:50 -06:00
SetNoCallAssistance ( true );
2009-10-17 15:51:44 -07:00
2010-12-23 23:25:44 +01:00
float radius = sWorld -> getFloatConfig ( CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS );
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( radius > 0 )
2008-10-11 14:16:25 -05:00
{
std :: list < Creature *> assistList ;
2017-05-13 19:37:33 +02:00
Trinity :: AnyAssistCreatureInRangeCheck u_check ( this , GetVictim (), radius );
Trinity :: CreatureListSearcher < Trinity :: AnyAssistCreatureInRangeCheck > searcher ( this , assistList , u_check );
Cell :: VisitGridObjects ( this , searcher , radius );
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
if ( ! assistList . empty ())
2008-10-11 14:16:25 -05:00
{
2014-04-19 21:48:22 +02:00
AssistDelayEvent * e = new AssistDelayEvent ( EnsureVictim () -> GetGUID (), * this );
2008-11-25 16:36:50 -06:00
while ( ! assistList . empty ())
{
// Pushing guids because in delay can happen some creature gets despawned => invalid pointer
e -> AddAssistant (( * assistList . begin ()) -> GetGUID ());
assistList . pop_front ();
}
2010-12-23 23:25:44 +01:00
m_Events . AddEvent ( e , m_Events . CalculateTime ( sWorld -> getIntConfig ( CONFIG_CREATURE_FAMILY_ASSISTANCE_DELAY )));
2008-10-11 14:16:25 -05:00
}
}
}
}
2009-10-17 15:51:44 -07:00
2011-10-19 17:40:44 +01:00
void Creature :: CallForHelp ( float radius )
2009-06-04 16:10:26 -05:00
{
2013-06-11 19:54:27 -02:30
if ( radius <= 0.0f || ! GetVictim () || IsPet () || IsCharmed ())
2009-06-04 16:10:26 -05:00
return ;
2009-10-17 15:51:44 -07:00
2013-06-11 19:54:27 -02:30
Trinity :: CallOfHelpCreatureInRangeDo u_do ( this , GetVictim (), radius );
2009-12-20 15:20:04 +01:00
Trinity :: CreatureWorker < Trinity :: CallOfHelpCreatureInRangeDo > worker ( this , u_do );
2017-05-13 19:37:33 +02:00
Cell :: VisitGridObjects ( this , worker , radius );
2009-06-04 16:10:26 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-21 10:15:09 -05:00
bool Creature :: CanAssistTo ( const Unit * u , const Unit * enemy , bool checkfaction /*= true*/ ) const
2008-11-25 16:36:50 -06:00
{
2014-10-13 22:37:44 +02:00
if ( IsInEvadeMode ())
return false ;
2008-12-07 09:21:12 -06:00
// is it true?
2010-04-07 19:14:10 +02:00
if ( ! HasReactState ( REACT_AGGRESSIVE ))
2008-11-25 16:36:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
// we don't need help from zombies :)
2013-06-11 19:54:27 -02:30
if ( ! IsAlive ())
2008-11-25 16:36:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
// we cannot assist in evade mode
if ( IsInEvadeMode ())
return false ;
// or if enemy is in evade mode
if ( enemy -> GetTypeId () == TYPEID_UNIT && enemy -> ToCreature () -> IsInEvadeMode ())
return false ;
2009-07-24 09:15:52 +08:00
// we don't need help from non-combatant ;)
2013-06-11 19:54:27 -02:30
if ( IsCivilian ())
2009-07-24 09:15:52 +08:00
return false ;
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
if ( HasUnitFlag ( UnitFlags ( UNIT_FLAG_NON_ATTACKABLE | UNIT_FLAG_NOT_SELECTABLE | UNIT_FLAG_IMMUNE_TO_NPC )))
2011-03-06 12:22:04 +01:00
return false ;
2008-11-25 16:36:50 -06:00
// skip fighting creature
2013-06-11 19:54:27 -02:30
if ( IsInCombat ())
2008-11-25 16:36:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
// only free creature
2014-10-21 20:27:00 +02:00
if ( ! GetCharmerOrOwnerGUID (). IsEmpty ())
2008-11-25 16:36:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2009-05-21 10:15:09 -05:00
// only from same creature faction
if ( checkfaction )
{
if ( getFaction () != u -> getFaction ())
return false ;
}
else
{
if ( ! IsFriendlyTo ( u ))
return false ;
}
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
// skip non hostile to caster enemy creatures
2009-05-21 10:15:09 -05:00
if ( ! IsHostileTo ( enemy ))
2008-11-25 16:36:50 -06:00
return false ;
2009-10-17 15:51:44 -07:00
2008-11-25 16:36:50 -06:00
return true ;
}
2009-10-17 15:51:44 -07:00
2009-09-29 15:13:46 -07:00
// use this function to avoid having hostile creatures attack
// friendlies and other mobs they shouldn't attack
2011-06-12 01:47:45 +02:00
bool Creature :: _IsTargetAcceptable ( const Unit * target ) const
2009-09-29 15:13:46 -07:00
{
2010-07-30 20:04:28 +02:00
ASSERT ( target );
2009-10-22 02:19:30 -07:00
2009-10-23 23:26:04 -07:00
// if the target cannot be attacked, the target is not acceptable
2009-10-24 14:53:03 -07:00
if ( IsFriendlyTo ( target )
2011-08-19 14:53:40 +02:00
|| ! target -> isTargetableForAttack ( false )
2009-10-24 14:53:03 -07:00
|| ( m_vehicle && ( IsOnVehicle ( target ) || m_vehicle -> GetBase () -> IsOnVehicle ( target ))))
2009-10-23 20:01:15 -07:00
return false ;
2009-10-17 15:51:44 -07:00
2012-02-03 19:12:41 +02:00
if ( target -> HasUnitState ( UNIT_STATE_DIED ))
2011-02-10 22:36:35 -03:00
{
// guards can detect fake death
2019-06-03 20:40:34 +02:00
if ( IsGuard () && target -> HasUnitFlag2 ( UNIT_FLAG2_FEIGN_DEATH ))
2011-02-10 22:36:35 -03:00
return true ;
else
return false ;
}
2011-09-15 14:08:17 +02:00
const Unit * myVictim = getAttackerForHelper ();
2011-06-12 01:47:45 +02:00
const Unit * targetVictim = target -> getAttackerForHelper ();
2009-10-23 23:29:45 -07:00
2009-10-23 23:26:04 -07:00
// if I'm already fighting target, or I'm hostile towards the target, the target is acceptable
if ( myVictim == target || targetVictim == this || IsHostileTo ( target ))
return true ;
2009-10-17 15:51:44 -07:00
2009-10-10 16:26:00 -07:00
// if the target's victim is friendly, and the target is neutral, the target is acceptable
2009-10-24 14:53:03 -07:00
if ( targetVictim && IsFriendlyTo ( targetVictim ))
2009-10-10 16:26:00 -07:00
return true ;
2009-10-17 15:51:44 -07:00
2009-10-10 16:26:00 -07:00
// if the target's victim is not friendly, or the target is friendly, the target is not acceptable
return false ;
2009-09-29 15:13:46 -07:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: SaveRespawnTime ()
{
2015-02-25 00:13:14 +01:00
if ( IsSummon () || ! m_spawnId || ( m_creatureData && ! m_creatureData -> dbData ))
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2015-02-25 00:13:14 +01:00
GetMap () -> SaveCreatureRespawnTime ( m_spawnId , m_respawnTime );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
// this should not be called by petAI or
2013-06-11 21:25:12 -02:30
bool Creature :: CanCreatureAttack ( Unit const * victim , bool /*force*/ ) const
2008-10-11 14:16:25 -05:00
{
2012-05-30 08:01:02 +02:00
if ( ! victim -> IsInMap ( this ))
2009-08-15 14:30:14 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if ( ! IsValidAttackTarget ( victim ))
2009-08-15 14:30:14 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if ( ! victim -> isInAccessiblePlaceFor ( this ))
2009-08-15 14:30:14 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
if ( IsAIEnabled && ! AI () -> CanAIAttack ( victim ))
2009-08-26 16:54:59 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
// we cannot attack in evade mode
if ( IsInEvadeMode ())
return false ;
// or if enemy is in evade mode
if ( victim -> GetTypeId () == TYPEID_UNIT && victim -> ToCreature () -> IsInEvadeMode ())
return false ;
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
if ( ! GetCharmerOrOwnerGUID (). IsPlayer ())
{
if ( GetMap () -> IsDungeon ())
return true ;
// don't check distance to home position if recently damaged, this should include taunt auras
if ( ! isWorldBoss () && ( GetLastDamagedTime () > sWorld -> GetGameTime () || HasAuraType ( SPELL_AURA_MOD_TAUNT )))
2016-02-09 22:53:38 +01:00
return true ;
2017-02-05 15:39:22 +01:00
}
2016-02-09 22:53:38 +01:00
2017-02-05 15:39:22 +01:00
// Map visibility range, but no more than 2*cell size
float dist = std :: min < float > ( GetMap () -> GetVisibilityRange (), SIZE_OF_GRID_CELL * 2 );
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
if ( Unit * unit = GetCharmerOrOwner ())
2012-05-30 08:01:02 +02:00
return victim -> IsWithinDist ( unit , dist );
2009-08-15 14:30:14 -05:00
else
2017-02-05 15:39:22 +01:00
{
// include sizes for huge npcs
dist += GetObjectSize () + victim -> GetObjectSize ();
// to prevent creatures in air ignore attacks because distance is already too high...
if ( GetCreatureTemplate () -> InhabitType & INHABIT_AIR )
return victim -> IsInDist2d ( & m_homePosition , dist );
else
return victim -> IsInDist ( & m_homePosition , dist );
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2011-04-28 22:46:40 +02:00
CreatureAddon const * Creature :: GetCreatureAddon () const
2008-10-11 14:16:25 -05:00
{
2015-02-25 00:13:14 +01:00
if ( m_spawnId )
2008-10-11 14:16:25 -05:00
{
2015-02-25 00:13:14 +01:00
if ( CreatureAddon const * addon = sObjectMgr -> GetCreatureAddon ( m_spawnId ))
2008-10-11 14:16:25 -05:00
return addon ;
}
2009-10-17 15:51:44 -07:00
2009-12-17 11:06:50 +01:00
// dependent from difficulty mode entry
2012-05-30 08:01:02 +02:00
return sObjectMgr -> GetCreatureTemplateAddon ( GetCreatureTemplate () -> Entry );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//creature_addon table
2015-11-10 19:58:13 +01:00
bool Creature :: LoadCreaturesAddon ()
2008-10-11 14:16:25 -05:00
{
2011-09-15 14:08:17 +02:00
CreatureAddon const * cainfo = GetCreatureAddon ();
2010-04-07 19:14:10 +02:00
if ( ! cainfo )
2008-10-11 14:16:25 -05:00
return false ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( cainfo -> mount != 0 )
Mount ( cainfo -> mount );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( cainfo -> bytes1 != 0 )
2009-05-31 15:58:58 -05:00
{
// 0 StandState
// 1 FreeTalentPoints Pet only, so always 0 for default creature
// 2 StandFlags
// 3 StandMiscFlags
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
SetStandState ( UnitStandStateType ( cainfo -> bytes1 & 0xFF ));
SetVisFlags ( UnitVisFlags (( cainfo -> bytes1 >> 16 ) & 0xFF ));
SetAnimTier ( UnitBytes1_Flags (( cainfo -> bytes1 >> 24 ) & 0xFF ), false );
2012-05-30 08:01:02 +02:00
//! Suspected correlation between UNIT_FIELD_BYTES_1, offset 3, value 0x2:
2013-02-22 01:21:49 +01:00
//! If no inhabittype_fly (if no MovementFlag_DisableGravity or MovementFlag_CanFly flag found in sniffs)
//! Check using InhabitType as movement flags are assigned dynamically
//! basing on whether the creature is in air or not
2012-05-30 08:01:02 +02:00
//! Set MovementFlag_Hover. Otherwise do nothing.
2019-06-03 20:40:34 +02:00
if ( m_unitData -> AnimTier & UNIT_BYTE1_FLAG_HOVER && ! ( GetCreatureTemplate () -> InhabitType & INHABIT_AIR ))
2012-05-30 08:01:02 +02:00
AddUnitMovementFlag ( MOVEMENTFLAG_HOVER );
2009-05-31 15:58:58 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( cainfo -> bytes2 != 0 )
2009-05-31 15:58:58 -05:00
{
// 0 SheathState
2016-12-13 20:58:22 +01:00
// 1 PvpFlags
// 2 PetFlags Pet only, so always 0 for default creature
2009-05-31 15:58:58 -05:00
// 3 ShapeshiftForm Must be determined/set by shapeshift spell/aura
2009-10-17 15:51:44 -07:00
2019-06-03 20:40:34 +02:00
SetSheath ( SheathState ( cainfo -> bytes2 & 0xFF ));
SetPvpFlags ( UNIT_BYTE2_FLAG_NONE );
SetPetFlags ( UNIT_PET_FLAG_NONE );
SetShapeshiftForm ( FORM_NONE );
2009-05-31 15:58:58 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
if ( cainfo -> emote != 0 )
2019-06-03 20:40:34 +02:00
SetEmoteState ( Emote ( cainfo -> emote ));
2009-10-17 15:51:44 -07:00
2016-08-20 19:23:07 -02:30
SetAIAnimKitId ( cainfo -> aiAnimKit );
SetMovementAnimKitId ( cainfo -> movementAnimKit );
SetMeleeAnimKitId ( cainfo -> meleeAnimKit );
2019-01-16 20:48:01 +01:00
// Check if visibility distance different
if ( cainfo -> visibilityDistanceType != VisibilityDistanceType :: Normal )
SetVisibilityDistanceOverride ( cainfo -> visibilityDistanceType );
2009-09-19 12:13:08 -07:00
//Load Path
if ( cainfo -> path_id != 0 )
m_path_id = cainfo -> path_id ;
2009-10-17 15:51:44 -07:00
2011-04-28 22:46:40 +02:00
if ( ! cainfo -> auras . empty ())
2008-10-11 14:16:25 -05:00
{
2011-04-28 22:46:40 +02:00
for ( std :: vector < uint32 >:: const_iterator itr = cainfo -> auras . begin (); itr != cainfo -> auras . end (); ++ itr )
2008-10-11 14:16:25 -05:00
{
2011-09-15 14:08:17 +02:00
SpellInfo const * AdditionalSpellInfo = sSpellMgr -> GetSpellInfo ( * itr );
2008-10-11 14:16:25 -05:00
if ( ! AdditionalSpellInfo )
{
2014-10-22 17:33:55 +02:00
TC_LOG_ERROR ( "sql.sql" , "Creature (%s) has wrong spell %u defined in `auras` field." , GetGUID (). ToString (). c_str (), * itr );
2008-10-11 14:16:25 -05:00
continue ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// skip already applied aura
2011-04-28 22:46:40 +02:00
if ( HasAura ( * itr ))
2008-10-11 14:16:25 -05:00
continue ;
2009-10-17 15:51:44 -07:00
2011-04-28 22:46:40 +02:00
AddAura ( * itr , this );
2014-10-22 17:33:55 +02:00
TC_LOG_DEBUG ( "entities.unit" , "Spell: %u added to creature (%s)" , * itr , GetGUID (). ToString (). c_str ());
2008-10-11 14:16:25 -05:00
}
}
2012-05-30 08:01:02 +02:00
2008-10-11 14:16:25 -05:00
return true ;
}
2009-10-17 15:51:44 -07:00
2008-11-14 16:28:45 -06:00
/// Send a message to LocalDefense channel for players opposition team in the zone
2008-10-11 14:16:25 -05:00
void Creature :: SendZoneUnderAttackMessage ( Player * attacker )
{
uint32 enemy_team = attacker -> GetTeam ();
2015-04-04 19:52:53 +02:00
WorldPackets :: Misc :: ZoneUnderAttack packet ;
2015-04-04 18:03:56 +02:00
packet . AreaID = GetAreaId ();
2016-04-02 02:50:44 +02:00
sWorld -> SendGlobalMessage ( packet . Write (), nullptr , ( enemy_team == ALLIANCE ? HORDE : ALLIANCE ));
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2009-06-27 15:37:33 -05:00
void Creature :: SetInCombatWithZone ()
{
if ( ! CanHaveThreatList ())
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "entities.unit" , "Creature entry %u call SetInCombatWithZone but creature cannot have threat list." , GetEntry ());
2009-06-27 15:37:33 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
Map * map = GetMap ();
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
if ( ! map -> IsDungeon ())
2009-06-27 15:37:33 -05:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "entities.unit" , "Creature entry %u call SetInCombatWithZone for map (id: %u) that isn't an instance." , GetEntry (), map -> GetId ());
2009-06-27 15:37:33 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2011-10-07 19:45:43 -05:00
Map :: PlayerList const & PlList = map -> GetPlayers ();
2009-10-17 15:51:44 -07:00
2009-06-27 15:37:33 -05:00
if ( PlList . isEmpty ())
return ;
2009-10-17 15:51:44 -07:00
2009-10-17 16:20:24 -07:00
for ( Map :: PlayerList :: const_iterator i = PlList . begin (); i != PlList . end (); ++ i )
2009-06-27 15:37:33 -05:00
{
2013-06-11 21:25:12 -02:30
if ( Player * player = i -> GetSource ())
2009-06-27 15:37:33 -05:00
{
2013-06-11 21:25:12 -02:30
if ( player -> IsGameMaster ())
2009-06-27 15:37:33 -05:00
continue ;
2009-10-17 15:51:44 -07:00
2013-06-11 19:54:27 -02:30
if ( player -> IsAlive ())
2009-06-27 15:37:33 -05:00
{
2011-10-07 11:08:09 -05:00
this -> SetInCombatWith ( player );
player -> SetInCombatWith ( this );
AddThreat ( player , 0.0f );
2009-06-27 15:37:33 -05:00
}
}
}
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
bool Creature :: HasSpell ( uint32 spellID ) const
{
2018-03-19 17:51:27 +01:00
for ( uint8 i = 0 ; i < MAX_CREATURE_SPELLS ; ++ i )
2010-04-07 19:14:10 +02:00
if ( spellID == m_spells [ i ])
2018-03-19 17:51:27 +01:00
return true ;
return false ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
time_t Creature :: GetRespawnTimeEx () const
{
2009-12-24 10:20:15 +01:00
time_t now = time ( NULL );
2010-09-15 06:22:54 +02:00
if ( m_respawnTime > now )
2008-10-11 14:16:25 -05:00
return m_respawnTime ;
else
return now ;
}
2009-10-17 15:51:44 -07:00
2011-10-18 10:53:34 -04:00
void Creature :: GetRespawnPosition ( float & x , float & y , float & z , float * ori , float * dist ) const
2008-10-11 14:16:25 -05:00
{
2017-02-05 15:39:22 +01:00
// for npcs on transport, this will return transport offset
2015-02-25 00:13:14 +01:00
if ( m_spawnId )
2008-10-11 14:16:25 -05:00
{
2015-02-25 00:13:14 +01:00
if ( CreatureData const * data = sObjectMgr -> GetCreatureData ( GetSpawnId ()))
2008-10-11 14:16:25 -05:00
{
x = data -> posX ;
y = data -> posY ;
z = data -> posZ ;
2010-04-07 19:14:10 +02:00
if ( ori )
2008-10-11 14:16:25 -05:00
* ori = data -> orientation ;
2010-04-07 19:14:10 +02:00
if ( dist )
2008-10-11 14:16:25 -05:00
* dist = data -> spawndist ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return ;
}
}
2009-10-17 15:51:44 -07:00
2017-02-05 15:39:22 +01:00
// changed this from current position to home position, fixes world summons with infinite duration (wg npcs for example)
Position homePos = GetHomePosition ();
x = homePos . GetPositionX ();
y = homePos . GetPositionY ();
z = homePos . GetPositionZ ();
2010-04-07 19:14:10 +02:00
if ( ori )
2017-02-05 15:39:22 +01:00
* ori = homePos . GetOrientation ();
2010-04-07 19:14:10 +02:00
if ( dist )
2008-10-11 14:16:25 -05:00
* dist = 0 ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
void Creature :: AllLootRemovedFromCorpse ()
{
2014-06-26 22:01:55 +02:00
if ( loot . loot_type != LOOT_SKINNING && ! IsPet () && GetCreatureTemplate () -> SkinLootId && hasLootRecipient ())
if ( LootTemplates_Skinning . HaveLootFor ( GetCreatureTemplate () -> SkinLootId ))
2019-06-03 20:40:34 +02:00
AddUnitFlag ( UNIT_FLAG_SKINNABLE );
2009-10-17 15:51:44 -07:00
2014-06-26 22:01:55 +02:00
time_t now = time ( NULL );
2014-07-12 17:27:26 +02:00
// Do not reset corpse remove time if corpse is already removed
2014-06-26 22:01:55 +02:00
if ( m_corpseRemoveTime <= now )
return ;
2009-10-17 15:51:44 -07:00
2014-06-26 22:01:55 +02:00
float decayRate = sWorld -> getRate ( RATE_CORPSE_DECAY_LOOTED );
2014-06-24 15:21:34 -05:00
2014-06-26 22:01:55 +02:00
// corpse skinnable, but without skinning flag, and then skinned, corpse will despawn next update
if ( loot . loot_type == LOOT_SKINNING )
2014-07-12 17:27:26 +02:00
m_corpseRemoveTime = now ;
2014-06-26 22:01:55 +02:00
else
2014-08-19 00:00:54 +02:00
m_corpseRemoveTime = now + uint32 ( m_corpseDelay * decayRate );
2014-06-26 22:01:55 +02:00
2017-02-05 15:02:08 +01:00
m_respawnTime = std :: max < time_t > ( m_corpseRemoveTime + m_respawnDelay , m_respawnTime );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2017-07-29 21:40:28 +02:00
bool Creature :: HasScalableLevels () const
2008-10-11 14:16:25 -05:00
{
2017-07-29 21:40:28 +02:00
CreatureTemplate const * cinfo = GetCreatureTemplate ();
return cinfo -> levelScaling . is_initialized ();
}
uint64 Creature :: GetMaxHealthByLevel ( uint8 level ) const
{
CreatureTemplate const * cInfo = GetCreatureTemplate ();
CreatureBaseStats const * stats = sObjectMgr -> GetCreatureBaseStats ( level , cInfo -> unit_class );
return stats -> GenerateHealth ( cInfo );
}
float Creature :: GetHealthMultiplierForTarget ( WorldObject const * target ) const
{
if ( ! HasScalableLevels ())
return 1.0f ;
uint8 levelForTarget = GetLevelForTarget ( target );
if ( getLevel () < levelForTarget )
return 1.0f ;
return double ( GetMaxHealthByLevel ( levelForTarget )) / double ( GetCreateHealth ());
}
float Creature :: GetBaseDamageForLevel ( uint8 level ) const
{
CreatureTemplate const * cInfo = GetCreatureTemplate ();
CreatureBaseStats const * stats = sObjectMgr -> GetCreatureBaseStats ( level , cInfo -> unit_class );
return stats -> GenerateBaseDamage ( cInfo );
}
float Creature :: GetDamageMultiplierForTarget ( WorldObject const * target ) const
{
if ( ! HasScalableLevels ())
return 1.0f ;
uint8 levelForTarget = GetLevelForTarget ( target );
return GetBaseDamageForLevel ( levelForTarget ) / GetBaseDamageForLevel ( getLevel ());
}
float Creature :: GetBaseArmorForLevel ( uint8 level ) const
{
CreatureTemplate const * cInfo = GetCreatureTemplate ();
CreatureBaseStats const * stats = sObjectMgr -> GetCreatureBaseStats ( level , cInfo -> unit_class );
return stats -> GenerateArmor ( cInfo );
}
float Creature :: GetArmorMultiplierForTarget ( WorldObject const * target ) const
{
if ( ! HasScalableLevels ())
return 1.0f ;
uint8 levelForTarget = GetLevelForTarget ( target );
return GetBaseArmorForLevel ( levelForTarget ) / GetBaseArmorForLevel ( getLevel ());
}
uint8 Creature :: GetLevelForTarget ( WorldObject const * target ) const
{
if ( Unit const * unitTarget = target -> ToUnit ())
{
if ( isWorldBoss ())
{
uint8 level = unitTarget -> getLevel () + sWorld -> getIntConfig ( CONFIG_WORLD_BOSS_LEVEL_DIFF );
return RoundToInterval < uint8 > ( level , 1u , 255u );
}
// If this creature should scale level, adapt level depending of target level
// between UNIT_FIELD_SCALING_LEVEL_MIN and UNIT_FIELD_SCALING_LEVEL_MAX
if ( HasScalableLevels ())
{
2019-06-03 20:40:34 +02:00
uint8 targetLevelWithDelta = unitTarget -> getLevel () + m_unitData -> ScalingLevelDelta ;
2017-07-29 21:40:28 +02:00
if ( target -> IsPlayer ())
2019-06-03 20:40:34 +02:00
targetLevelWithDelta += target -> ToPlayer () -> m_activePlayerData -> ScalingPlayerLevelDelta ;
2017-07-29 21:40:28 +02:00
2019-06-03 20:40:34 +02:00
return RoundToInterval < uint8 > ( targetLevelWithDelta , m_unitData -> ScalingLevelMin , m_unitData -> ScalingLevelMax );
2017-07-29 21:40:28 +02:00
}
}
2009-10-17 15:51:44 -07:00
2017-07-29 21:40:28 +02:00
return Unit :: GetLevelForTarget ( target );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2009-04-14 18:31:31 -05:00
std :: string Creature :: GetAIName () const
{
2011-04-28 22:57:08 +02:00
return sObjectMgr -> GetCreatureTemplate ( GetEntry ()) -> AIName ;
2009-04-14 18:31:31 -05:00
}
2009-10-17 15:51:44 -07:00
2009-04-14 18:31:31 -05:00
std :: string Creature :: GetScriptName () const
2008-10-11 14:16:25 -05:00
{
2010-12-22 21:25:23 +01:00
return sObjectMgr -> GetScriptName ( GetScriptId ());
2008-11-20 16:16:57 -06:00
}
2009-10-17 15:51:44 -07:00
2009-04-14 18:31:31 -05:00
uint32 Creature :: GetScriptId () const
2008-11-20 16:16:57 -06:00
{
2017-03-18 11:31:31 +01:00
if ( CreatureData const * creatureData = GetCreatureData ())
return creatureData -> ScriptId ;
2011-04-28 22:57:08 +02:00
return sObjectMgr -> GetCreatureTemplate ( GetEntry ()) -> ScriptID ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
VendorItemData const * Creature :: GetVendorItems () const
{
2010-12-22 21:25:23 +01:00
return sObjectMgr -> GetNpcVendorItemList ( GetEntry ());
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 Creature :: GetVendorItemCurrentCount ( VendorItem const * vItem )
{
2010-04-07 19:14:10 +02:00
if ( ! vItem -> maxcount )
2008-10-11 14:16:25 -05:00
return vItem -> maxcount ;
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
VendorItemCounts :: iterator itr = m_vendorItemCounts . begin ();
for (; itr != m_vendorItemCounts . end (); ++ itr )
2010-04-07 23:25:02 +02:00
if ( itr -> itemId == vItem -> item )
2009-12-24 10:20:15 +01:00
break ;
2010-04-07 19:14:10 +02:00
if ( itr == m_vendorItemCounts . end ())
2008-10-11 14:16:25 -05:00
return vItem -> maxcount ;
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
VendorItemCount * vCount = &* itr ;
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
time_t ptime = time ( NULL );
2009-10-17 15:51:44 -07:00
2010-08-23 15:11:06 +02:00
if ( time_t ( vCount -> lastIncrementTime + vItem -> incrtime ) <= ptime )
2013-05-30 13:14:06 +02:00
if ( ItemTemplate const * pProto = sObjectMgr -> GetItemTemplate ( vItem -> item ))
2008-10-11 14:16:25 -05:00
{
2013-05-30 13:14:06 +02:00
uint32 diff = uint32 (( ptime - vCount -> lastIncrementTime ) / vItem -> incrtime );
2014-12-21 13:35:43 +01:00
if (( vCount -> count + diff * pProto -> GetBuyCount ()) >= vItem -> maxcount )
2013-05-30 13:14:06 +02:00
{
m_vendorItemCounts . erase ( itr );
return vItem -> maxcount ;
}
2009-10-17 15:51:44 -07:00
2014-12-21 13:35:43 +01:00
vCount -> count += diff * pProto -> GetBuyCount ();
2013-05-30 13:14:06 +02:00
vCount -> lastIncrementTime = ptime ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
return vCount -> count ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 Creature :: UpdateVendorItemCurrentCount ( VendorItem const * vItem , uint32 used_count )
{
2010-04-07 19:14:10 +02:00
if ( ! vItem -> maxcount )
2008-10-11 14:16:25 -05:00
return 0 ;
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
VendorItemCounts :: iterator itr = m_vendorItemCounts . begin ();
for (; itr != m_vendorItemCounts . end (); ++ itr )
2010-04-07 23:25:02 +02:00
if ( itr -> itemId == vItem -> item )
2009-12-24 10:20:15 +01:00
break ;
2010-04-07 19:14:10 +02:00
if ( itr == m_vendorItemCounts . end ())
2008-10-11 14:16:25 -05:00
{
2010-08-23 15:11:06 +02:00
uint32 new_count = vItem -> maxcount > used_count ? vItem -> maxcount - used_count : 0 ;
2011-04-29 20:47:02 +02:00
m_vendorItemCounts . push_back ( VendorItemCount ( vItem -> item , new_count ));
2008-10-11 14:16:25 -05:00
return new_count ;
}
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
VendorItemCount * vCount = &* itr ;
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
time_t ptime = time ( NULL );
2009-10-17 15:51:44 -07:00
2010-08-30 15:25:15 +02:00
if ( time_t ( vCount -> lastIncrementTime + vItem -> incrtime ) <= ptime )
2013-05-30 13:14:06 +02:00
if ( ItemTemplate const * pProto = sObjectMgr -> GetItemTemplate ( vItem -> item ))
{
uint32 diff = uint32 (( ptime - vCount -> lastIncrementTime ) / vItem -> incrtime );
2014-12-21 13:35:43 +01:00
if (( vCount -> count + diff * pProto -> GetBuyCount ()) < vItem -> maxcount )
vCount -> count += diff * pProto -> GetBuyCount ();
2013-05-30 13:14:06 +02:00
else
vCount -> count = vItem -> maxcount ;
}
2009-10-17 15:51:44 -07:00
2009-12-24 10:20:15 +01:00
vCount -> count = vCount -> count > used_count ? vCount -> count - used_count : 0 ;
2008-10-11 14:16:25 -05:00
vCount -> lastIncrementTime = ptime ;
return vCount -> count ;
}
2009-10-17 15:51:44 -07:00
2008-11-14 17:03:03 -06:00
// overwrite WorldObject function for proper name localization
2012-10-24 13:29:34 +02:00
std :: string const & Creature :: GetNameForLocaleIdx ( LocaleConstant loc_idx ) const
2008-11-14 17:03:03 -06:00
{
2010-09-17 07:04:29 +02:00
if ( loc_idx != DEFAULT_LOCALE )
2008-11-14 17:03:03 -06:00
{
2010-08-23 15:11:06 +02:00
uint8 uloc_idx = uint8 ( loc_idx );
2011-09-15 14:08:17 +02:00
CreatureLocale const * cl = sObjectMgr -> GetCreatureLocale ( GetEntry ());
2008-11-14 17:03:03 -06:00
if ( cl )
{
2010-08-23 15:11:06 +02:00
if ( cl -> Name . size () > uloc_idx && ! cl -> Name [ uloc_idx ]. empty ())
2012-10-24 13:29:34 +02:00
return cl -> Name [ uloc_idx ];
2008-11-14 17:03:03 -06:00
}
}
2009-10-17 15:51:44 -07:00
2008-11-14 17:03:03 -06:00
return GetName ();
}
2009-10-17 15:51:44 -07:00
2013-03-04 12:41:17 +01:00
uint32 Creature :: GetPetAutoSpellOnPos ( uint8 pos ) const
{
if ( pos >= MAX_SPELL_CHARM || m_charmInfo -> GetCharmSpell ( pos ) -> GetType () != ACT_ENABLED )
return 0 ;
else
return m_charmInfo -> GetCharmSpell ( pos ) -> GetAction ();
}
2016-11-28 01:22:46 +01:00
float Creature :: GetPetChaseDistance () const
{
float range = MELEE_RANGE ;
for ( uint8 i = 0 ; i < GetPetAutoSpellSize (); ++ i )
{
uint32 spellID = GetPetAutoSpellOnPos ( i );
if ( ! spellID )
continue ;
if ( SpellInfo const * spellInfo = sSpellMgr -> GetSpellInfo ( spellID ))
{
if ( spellInfo -> GetRecoveryTime () == 0 && // No cooldown
spellInfo -> RangeEntry -> ID != 1 /*Self*/ && spellInfo -> RangeEntry -> ID != 2 /*Combat Range*/ &&
spellInfo -> GetMinRange () > range )
range = spellInfo -> GetMinRange ();
}
}
return range ;
}
2011-10-10 17:08:01 -04:00
void Creature :: SetPosition ( float x , float y , float z , float o )
{
// prevent crash when a bad coord is sent by the client
if ( ! Trinity :: IsValidMapCoord ( x , y , z , o ))
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "entities.unit" , "Creature::SetPosition(%f, %f, %f) .. bad coordinates!" , x , y , z );
2011-10-10 17:08:01 -04:00
return ;
}
2014-01-04 18:22:06 +01:00
GetMap () -> CreatureRelocation ( this , x , y , z , o );
2011-10-10 17:08:01 -04:00
if ( IsVehicle ())
2012-09-10 15:44:12 +02:00
GetVehicleKit () -> RelocatePassengers ();
2010-10-24 02:55:50 +02:00
}
2011-02-09 16:28:56 +01:00
bool Creature :: IsDungeonBoss () const
{
2011-09-15 14:08:17 +02:00
CreatureTemplate const * cinfo = sObjectMgr -> GetCreatureTemplate ( GetEntry ());
2011-02-09 16:28:56 +01:00
return cinfo && ( cinfo -> flags_extra & CREATURE_FLAG_EXTRA_DUNGEON_BOSS );
}
2012-01-14 15:34:41 +01:00
2012-12-06 09:58:32 -05:00
float Creature :: GetAggroRange ( Unit const * target ) const
{
// Determines the aggro range for creatures (usually pets), used mainly for aggressive pet target selection.
// Based on data from wowwiki due to lack of 3.3.5a data
2013-06-11 18:39:51 -02:30
if ( target && this -> IsPet ())
2012-12-06 09:58:32 -05:00
{
uint32 targetLevel = 0 ;
2012-12-14 01:23:53 +00:00
2012-12-06 09:58:32 -05:00
if ( target -> GetTypeId () == TYPEID_PLAYER )
2017-07-29 21:40:28 +02:00
targetLevel = target -> GetLevelForTarget ( this );
2012-12-06 09:58:32 -05:00
else if ( target -> GetTypeId () == TYPEID_UNIT )
2017-07-29 21:40:28 +02:00
targetLevel = target -> ToCreature () -> GetLevelForTarget ( this );
2012-12-06 09:58:32 -05:00
2017-07-29 21:40:28 +02:00
uint32 myLevel = GetLevelForTarget ( target );
2012-12-06 09:58:32 -05:00
int32 levelDiff = int32 ( targetLevel ) - int32 ( myLevel );
2012-12-14 01:23:53 +00:00
2012-12-06 09:58:32 -05:00
// The maximum Aggro Radius is capped at 45 yards (25 level difference)
if ( levelDiff < - 25 )
levelDiff = - 25 ;
// The base aggro radius for mob of same level
float aggroRadius = 20 ;
// Aggro Radius varies with level difference at a rate of roughly 1 yard/level
aggroRadius -= ( float ) levelDiff ;
// detect range auras
aggroRadius += GetTotalAuraModifier ( SPELL_AURA_MOD_DETECT_RANGE );
// detected range auras
aggroRadius += target -> GetTotalAuraModifier ( SPELL_AURA_MOD_DETECTED_RANGE );
// Just in case, we don't want pets running all over the map
if ( aggroRadius > MAX_AGGRO_RADIUS )
aggroRadius = MAX_AGGRO_RADIUS ;
// Minimum Aggro Radius for a mob seems to be combat range (5 yards)
// hunter pets seem to ignore minimum aggro radius so we'll default it a little higher
if ( aggroRadius < 10 )
aggroRadius = 10 ;
return ( aggroRadius );
}
// Default
return 0.0f ;
}
Unit * Creature :: SelectNearestHostileUnitInAggroRange ( bool useLOS ) const
{
// Selects nearest hostile target within creature's aggro range. Used primarily by
// pets set to aggressive. Will not return neutral or friendly targets.
Unit * target = NULL ;
2017-05-13 19:37:33 +02:00
Trinity :: NearestHostileUnitInAggroRangeCheck u_check ( this , useLOS );
Trinity :: UnitSearcher < Trinity :: NearestHostileUnitInAggroRangeCheck > searcher ( this , target , u_check );
2012-12-06 09:58:32 -05:00
2017-05-13 19:37:33 +02:00
Cell :: VisitGridObjects ( this , searcher , MAX_AGGRO_RADIUS );
2012-12-06 09:58:32 -05:00
return target ;
}
2013-06-07 16:05:39 +02:00
void Creature :: UpdateMovementFlags ()
{
2013-06-22 13:42:13 +02:00
// Do not update movement flags if creature is controlled by a player (charm/vehicle)
2016-08-20 12:43:04 +02:00
if ( m_playerMovingMe )
2013-06-22 13:42:13 +02:00
return ;
2017-01-27 20:47:54 -02:00
// Creatures with CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE should control MovementFlags in your own scripts
if ( GetCreatureTemplate () -> flags_extra & CREATURE_FLAG_EXTRA_NO_MOVE_FLAGS_UPDATE )
return ;
2013-06-07 16:05:39 +02:00
// Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc)
2018-01-28 11:37:20 +01:00
float ground = GetMap () -> GetHeight ( GetPhaseShift (), GetPositionX (), GetPositionY (), GetPositionZMinusOffset ());
2013-06-07 16:05:39 +02:00
2013-06-22 13:42:13 +02:00
bool isInAir = ( G3D :: fuzzyGt ( GetPositionZMinusOffset (), ground + 0.05f ) || G3D :: fuzzyLt ( GetPositionZMinusOffset (), ground - 0.05f )); // Can be underground too, prevent the falling
2013-06-07 16:05:39 +02:00
2013-06-22 13:42:13 +02:00
if ( GetCreatureTemplate () -> InhabitType & INHABIT_AIR && isInAir && ! IsFalling ())
2013-06-07 16:05:39 +02:00
{
if ( GetCreatureTemplate () -> InhabitType & INHABIT_GROUND )
SetCanFly ( true );
else
SetDisableGravity ( true );
}
else
{
SetCanFly ( false );
SetDisableGravity ( false );
}
2013-06-22 13:42:13 +02:00
if ( ! isInAir )
2013-08-10 13:44:08 +02:00
SetFall ( false );
2013-06-22 13:42:13 +02:00
2013-06-18 16:47:12 +02:00
SetSwim ( GetCreatureTemplate () -> InhabitType & INHABIT_WATER && IsInWater ());
2013-06-07 16:05:39 +02:00
}
2013-06-11 17:28:16 +02:00
void Creature :: SetObjectScale ( float scale )
{
Unit :: SetObjectScale ( scale );
if ( CreatureModelInfo const * minfo = sObjectMgr -> GetCreatureModelInfo ( GetDisplayId ()))
{
2019-06-03 20:40:34 +02:00
SetBoundingRadius (( IsPet () ? 1.0f : minfo -> bounding_radius ) * scale );
SetCombatReach (( IsPet () ? DEFAULT_COMBAT_REACH : minfo -> combat_reach ) * scale );
2013-06-11 17:28:16 +02:00
}
}
2018-11-07 20:23:30 +01:00
void Creature :: SetDisplayId ( uint32 modelId , float displayScale /*= 1.f*/ )
2013-06-11 17:28:16 +02:00
{
2018-11-07 20:23:30 +01:00
Unit :: SetDisplayId ( modelId , displayScale );
2013-06-11 17:28:16 +02:00
if ( CreatureModelInfo const * minfo = sObjectMgr -> GetCreatureModelInfo ( modelId ))
{
2019-06-03 20:40:34 +02:00
SetBoundingRadius (( IsPet () ? 1.0f : minfo -> bounding_radius ) * GetObjectScale ());
SetCombatReach (( IsPet () ? DEFAULT_COMBAT_REACH : minfo -> combat_reach ) * GetObjectScale ());
2013-06-11 17:28:16 +02:00
}
}
2013-10-03 17:07:25 +02:00
2018-11-07 20:23:30 +01:00
void Creature :: SetDisplayFromModel ( uint32 modelIdx )
{
if ( CreatureModel const * model = GetCreatureTemplate () -> GetModelByIdx ( modelIdx ))
SetDisplayId ( model -> CreatureDisplayID , model -> DisplayScale );
}
2014-11-23 04:25:47 +01:00
void Creature :: SetTarget ( ObjectGuid const & guid )
2013-10-03 17:07:25 +02:00
{
2016-08-21 11:07:38 +02:00
if ( IsFocusing ( nullptr , true ))
m_suppressedTarget = guid ;
else
2019-06-03 20:40:34 +02:00
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: Target ), guid );
2013-10-03 17:07:25 +02:00
}
2016-08-21 11:07:38 +02:00
void Creature :: FocusTarget ( Spell const * focusSpell , WorldObject const * target )
2013-10-03 17:07:25 +02:00
{
// already focused
2016-04-02 02:50:44 +02:00
if ( m_focusSpell )
2016-08-21 11:07:38 +02:00
return ;
2017-01-22 02:24:48 -03:00
SpellInfo const * spellInfo = focusSpell -> GetSpellInfo ();
2016-08-21 11:07:38 +02:00
// don't use spell focus for vehicle spells
2017-01-22 02:24:48 -03:00
if ( spellInfo -> HasAura ( DIFFICULTY_NONE , SPELL_AURA_CONTROL_VEHICLE ))
2016-08-21 11:07:38 +02:00
return ;
2016-01-13 18:38:54 +01:00
if (( ! target || target == this ) && ! focusSpell -> GetCastTime ()) // instant cast, untargeted (or self-targeted) spell doesn't need any facing updates
2016-08-21 11:07:38 +02:00
return ;
2013-10-03 17:07:25 +02:00
2016-08-21 11:07:38 +02:00
// store pre-cast values for target and orientation (used to later restore)
if ( ! IsFocusing ( nullptr , true ))
{ // only overwrite these fields if we aren't transitioning from one spell focus to another
2019-06-03 20:40:34 +02:00
m_suppressedTarget = GetTarget ();
2016-08-21 11:07:38 +02:00
m_suppressedOrientation = GetOrientation ();
}
2013-10-03 17:07:25 +02:00
2016-08-21 11:07:38 +02:00
m_focusSpell = focusSpell ;
2016-01-13 18:38:54 +01:00
// set target, then force send update packet to players if it changed to provide appropriate facing
ObjectGuid newTarget = target ? target -> GetGUID () : ObjectGuid :: Empty ;
2019-06-03 20:40:34 +02:00
if ( GetTarget () != newTarget )
2016-01-13 18:38:54 +01:00
{
2019-06-03 20:40:34 +02:00
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: Target ), newTarget );
2016-01-24 01:11:19 +00:00
2016-01-13 18:38:54 +01:00
if ( // here we determine if the (relatively expensive) forced update is worth it, or whether we can afford to wait until the scheduled update tick
( // only require instant update for spells that actually have a visual
2017-01-22 02:24:48 -03:00
spellInfo -> GetSpellVisual ()
2016-01-24 01:11:19 +00:00
) && (
2016-01-13 18:38:54 +01:00
! focusSpell -> GetCastTime () || // if the spell is instant cast
2017-01-22 02:24:48 -03:00
spellInfo -> HasAttribute ( SPELL_ATTR5_DONT_TURN_DURING_CAST ) // client gets confused if we attempt to turn at the regularly scheduled update packet
2016-01-13 18:38:54 +01:00
)
)
{
2017-01-22 02:24:48 -03:00
std :: vector < Player *> playersNearby ;
2016-03-22 23:23:03 +00:00
GetPlayerListInGrid ( playersNearby , GetVisibilityRange ());
for ( Player * player : playersNearby )
{
// only update players that are known to the client (have already been created)
if ( player -> HaveAtClient ( this ))
SendUpdateToPlayer ( player );
}
2016-01-13 18:38:54 +01:00
}
}
2017-01-22 02:24:48 -03:00
bool const canTurnDuringCast = ! spellInfo -> HasAttribute ( SPELL_ATTR5_DONT_TURN_DURING_CAST );
2016-01-13 18:38:54 +01:00
// Face the target - we need to do this before the unit state is modified for no-turn spells
if ( target )
2016-09-20 20:19:15 +02:00
SetFacingToObject ( target );
2016-01-13 18:38:54 +01:00
else if ( ! canTurnDuringCast )
2016-03-16 21:38:01 +01:00
if ( Unit * victim = GetVictim ())
2016-09-20 20:19:15 +02:00
SetFacingToObject ( victim ); // ensure orientation is correct at beginning of cast
2016-01-13 18:38:54 +01:00
if ( ! canTurnDuringCast )
AddUnitState ( UNIT_STATE_CANNOT_TURN );
}
bool Creature :: IsFocusing ( Spell const * focusSpell , bool withDelay )
{
if ( ! IsAlive ()) // dead creatures cannot focus
{
ReleaseFocus ( nullptr , false );
return false ;
}
2016-04-02 02:50:44 +02:00
if ( focusSpell && ( focusSpell != m_focusSpell ))
2016-01-13 18:38:54 +01:00
return false ;
2016-04-02 02:50:44 +02:00
if ( ! m_focusSpell )
2016-01-13 18:38:54 +01:00
{
2016-04-02 02:50:44 +02:00
if ( ! withDelay || ! m_focusDelay )
2016-01-13 18:38:54 +01:00
return false ;
2016-04-02 02:50:44 +02:00
if ( GetMSTimeDiffToNow ( m_focusDelay ) > 1000 ) // @todo figure out if we can get rid of this magic number somehow
2016-01-13 18:38:54 +01:00
{
2016-04-02 02:50:44 +02:00
m_focusDelay = 0 ; // save checks in the future
2016-01-13 18:38:54 +01:00
return false ;
}
}
return true ;
2013-10-03 17:07:25 +02:00
}
2016-01-13 18:38:54 +01:00
void Creature :: ReleaseFocus ( Spell const * focusSpell , bool withDelay )
2013-10-03 17:07:25 +02:00
{
2016-04-02 02:50:44 +02:00
if ( ! m_focusSpell )
2016-01-13 18:38:54 +01:00
return ;
2013-10-03 17:07:25 +02:00
// focused to something else
2016-04-02 02:50:44 +02:00
if ( focusSpell && focusSpell != m_focusSpell )
2013-10-03 17:07:25 +02:00
return ;
2016-04-02 02:50:44 +02:00
if ( IsPet ()) // player pets do not use delay system
2016-08-21 11:07:38 +02:00
{
2019-06-03 20:40:34 +02:00
SetUpdateFieldValue ( m_values . ModifyValue ( & Unit :: m_unitData ). ModifyValue ( & UF :: UnitData :: Target ), m_suppressedTarget );
2016-08-21 11:07:38 +02:00
if ( ! m_suppressedTarget . IsEmpty ())
{
if ( WorldObject const * objTarget = ObjectAccessor :: GetWorldObject ( * this , m_suppressedTarget ))
2016-09-20 20:19:15 +02:00
SetFacingToObject ( objTarget );
2016-08-21 11:07:38 +02:00
}
else
SetFacingTo ( m_suppressedOrientation );
}
2016-03-23 16:22:05 +01:00
else
2016-08-21 11:07:38 +02:00
// tell the creature that it should reacquire its actual target after the delay expires (this is handled in ::Update)
2016-04-02 02:50:44 +02:00
// player pets don't need to do this, as they automatically reacquire their target on focus release
MustReacquireTarget ();
2016-01-13 18:38:54 +01:00
2016-04-02 02:50:44 +02:00
if ( m_focusSpell -> GetSpellInfo () -> HasAttribute ( SPELL_ATTR5_DONT_TURN_DURING_CAST ))
2016-01-13 18:38:54 +01:00
ClearUnitState ( UNIT_STATE_CANNOT_TURN );
2013-10-03 17:07:25 +02:00
2016-04-02 02:50:44 +02:00
m_focusSpell = nullptr ;
m_focusDelay = ( ! IsPet () && withDelay ) ? getMSTime () : 0 ; // don't allow re-target right away to prevent visual bugs
2013-10-03 17:07:25 +02:00
}
2014-06-24 22:13:59 -05:00
void Creature :: StartPickPocketRefillTimer ()
{
_pickpocketLootRestore = time ( NULL ) + sWorld -> getIntConfig ( CONFIG_CREATURE_PICKPOCKET_REFILL );
}
2015-06-13 12:27:19 +02:00
void Creature :: SetTextRepeatId ( uint8 textGroup , uint8 id )
{
CreatureTextRepeatIds & repeats = m_textRepeat [ textGroup ];
if ( std :: find ( repeats . begin (), repeats . end (), id ) == repeats . end ())
repeats . push_back ( id );
else
2015-07-03 02:23:58 +01:00
TC_LOG_ERROR ( "sql.sql" , "CreatureTextMgr: TextGroup %u for Creature (%s) % s , id % u already added ", uint32(textGroup), GetName().c_str(), GetGUID().ToString().c_str(), uint32(id)) ;
2015-06-13 12:27:19 +02:00
}
CreatureTextRepeatIds Creature :: GetTextRepeatGroup ( uint8 textGroup )
{
CreatureTextRepeatIds ids ;
CreatureTextRepeatGroup :: const_iterator groupItr = m_textRepeat . find ( textGroup );
if ( groupItr != m_textRepeat . end ())
ids = groupItr -> second ;
return ids ;
}
void Creature :: ClearTextRepeatGroup ( uint8 textGroup )
{
CreatureTextRepeatGroup :: iterator groupItr = m_textRepeat . find ( textGroup );
if ( groupItr != m_textRepeat . end ())
groupItr -> second . clear ();
}
2017-05-05 14:44:47 +02:00
bool Creature :: CanGiveExperience () const
{
return ! IsCritter ()
&& ! IsPet ()
&& ! IsTotem ()
&& ! ( GetCreatureTemplate () -> flags_extra & CREATURE_FLAG_EXTRA_NO_XP_AT_KILL );
}