aboutsummaryrefslogtreecommitdiff
path: root/src/game/Creature.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Creature.cpp')
-rw-r--r--src/game/Creature.cpp69
1 files changed, 58 insertions, 11 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp
index 646feb4951f..cb6a7640d16 100644
--- a/src/game/Creature.cpp
+++ b/src/game/Creature.cpp
@@ -122,7 +122,7 @@ Unit(), i_AI(NULL), i_AI_possessed(NULL),
lootForPickPocketed(false), lootForBody(false), m_groupLootTimer(0), lootingGroupLeaderGUID(0),
m_lootMoney(0), m_lootRecipient(0),
m_deathTimer(0), m_respawnTime(0), m_respawnDelay(25), m_corpseDelay(60), m_respawnradius(0.0f),
-m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false),
+m_gossipOptionLoaded(false), m_emoteState(0), m_isPet(false), m_isTotem(false), m_isAggressive(true),
m_regenTimer(2000), m_defaultMovementType(IDLE_MOTION_TYPE), m_equipmentId(0),
m_AlreadyCallAssistence(false), m_regenHealth(true), m_AI_locked(false), m_isDeadByDefault(false),
m_meleeDamageSchoolMask(SPELL_SCHOOL_MASK_NORMAL),m_creatureInfo(NULL), m_DBTableGuid(0)
@@ -181,7 +181,7 @@ void Creature::RemoveCorpse()
float x,y,z,o;
GetRespawnCoord(x, y, z, &o);
- MapManager::Instance().GetMap(GetMapId(), this)->CreatureRelocation(this,x,y,z,o);
+ GetMap()->CreatureRelocation(this,x,y,z,o);
}
/**
@@ -213,7 +213,7 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data )
}
}
- SetUInt32Value(OBJECT_FIELD_ENTRY, Entry); // normal entry always
+ SetEntry(Entry); // normal entry always
m_creatureInfo = cinfo; // map mode related always
// Cancel load if no model defined
@@ -297,6 +297,7 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data )
SetUInt32Value(UNIT_FIELD_FLAGS,GetCreatureInfo()->unit_flags);
SetUInt32Value(UNIT_DYNAMIC_FLAGS,GetCreatureInfo()->dynamicflags);
+ SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool));
SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetCreatureInfo()->armor));
SetModifierValue(UNIT_MOD_RESISTANCE_HOLY, BASE_VALUE, float(GetCreatureInfo()->resistance1));
SetModifierValue(UNIT_MOD_RESISTANCE_FIRE, BASE_VALUE, float(GetCreatureInfo()->resistance2));
@@ -327,6 +328,12 @@ bool Creature::UpdateEntry(uint32 Entry, uint32 team, const CreatureData *data )
if(GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER)
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
+ if(isTotem() || isCivilian() || GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER
+ || GetCreatureType() == CREATURE_TYPE_CRITTER)
+ m_isAggressive = false;
+ else
+ m_isAggressive = true;
+
return true;
}
@@ -356,7 +363,7 @@ void Creature::Update(uint32 diff)
lootForPickPocketed = false;
lootForBody = false;
- if(m_originalEntry != GetUInt32Value(OBJECT_FIELD_ENTRY))
+ if(m_originalEntry != GetEntry())
UpdateEntry(m_originalEntry);
CreatureInfo const *cinfo = GetCreatureInfo();
@@ -375,9 +382,9 @@ void Creature::Update(uint32 diff)
setDeathState( JUST_ALIVED );
//Call AI respawn virtual function
- AI()->JustRespawned();
+ i_AI->JustRespawned();
- MapManager::Instance().GetMap(GetMapId(), this)->Add(this);
+ GetMap()->Add(this);
}
break;
}
@@ -439,7 +446,7 @@ void Creature::Update(uint32 diff)
{
// do not allow the AI to be changed during update
m_AI_locked = true;
- AI()->UpdateAI(diff);
+ i_AI->UpdateAI(diff);
m_AI_locked = false;
}
@@ -1411,8 +1418,6 @@ bool Creature::LoadFromDB(uint32 guid, Map *map)
SetHealth(m_deathState == ALIVE ? curhealth : 0);
SetPower(POWER_MANA,data->curmana);
- SetMeleeDamageSchool(SpellSchools(GetCreatureInfo()->dmgschool));
-
// checked at creature_template loading
m_defaultMovementType = MovementGeneratorType(data->movementType);
@@ -1539,6 +1544,19 @@ bool Creature::IsWithinSightDist(Unit const* u) const
return IsWithinDistInMap(u, sWorld.getConfig(CONFIG_SIGHT_MONSTER));
}
+bool Creature::canStartAttack(Unit const* who) const
+{
+ if(!who->isInAccessiblePlaceFor(this)
+ || !canFly() && GetDistanceZ(who) > CREATURE_Z_ATTACK_RANGE
+ || !IsWithinDistInMap(who, GetAttackDistance(who)))
+ return false;
+
+ if(!canAttack(who))
+ return false;
+
+ return IsWithinLOSInMap(who);
+}
+
float Creature::GetAttackDistance(Unit const* pl) const
{
float aggroRate = sWorld.getRate(RATE_CREATURE_AGGRO);
@@ -1818,6 +1836,30 @@ void Creature::DoFleeToGetAssistance(float radius) // Optional parameter
}
}
+Unit* Creature::SelectNearestTarget(float dist) const
+{
+ CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY()));
+ Cell cell(p);
+ cell.data.Part.reserved = ALL_DISTRICT;
+ cell.SetNoCreate();
+
+ Unit *target = NULL;
+
+ {
+ Trinity::NearestHostileUnitInAttackDistanceCheck u_check(this, dist);
+ Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck> searcher(target, u_check);
+
+ TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
+ TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, GridTypeMapContainer > grid_unit_searcher(searcher);
+
+ CellLock<GridReadGuard> cell_lock(cell, p);
+ cell_lock->Visit(cell_lock, world_unit_searcher, *GetMap());
+ cell_lock->Visit(cell_lock, grid_unit_searcher, *GetMap());
+ }
+
+ return target;
+}
+
void Creature::CallAssistence()
{
if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed())
@@ -2097,9 +2139,14 @@ uint32 Creature::getLevelForTarget( Unit const* target ) const
return level;
}
-char const* Creature::GetScriptName() const
+std::string Creature::GetScriptName()
+{
+ return objmgr.GetScriptName(GetScriptId());
+}
+
+uint32 Creature::GetScriptId()
{
- return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptName;
+ return ObjectMgr::GetCreatureTemplate(GetEntry())->ScriptID;
}
VendorItemData const* Creature::GetVendorItems() const