*Add virtual bool IsEscorted() to escort_ai.h

*Some minor cleanup and optimization

--HG--
branch : trunk
This commit is contained in:
maximius
2009-10-30 18:54:38 -07:00
parent 98d53f6a9d
commit e6e621bfad
6 changed files with 45 additions and 48 deletions
+1
View File
@@ -71,6 +71,7 @@ struct TRINITY_DLL_DECL npc_escortAI : public ScriptedAI
void SetEscortPaused(bool uPaused); void SetEscortPaused(bool uPaused);
bool HasEscortState(uint32 uiEscortState) { return (m_uiEscortState & uiEscortState); } bool HasEscortState(uint32 uiEscortState) { return (m_uiEscortState & uiEscortState); }
virtual bool IsEscorted() { return true; }
void SetMaxPlayerDistance(float newMax) { MaxPlayerDistance = newMax; } void SetMaxPlayerDistance(float newMax) { MaxPlayerDistance = newMax; }
float GetMaxPlayerDistance() { return MaxPlayerDistance; } float GetMaxPlayerDistance() { return MaxPlayerDistance; }
+2 -2
View File
@@ -14944,9 +14944,9 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
{ {
sLog.outError("Player (guidlow %d) was in BG in database, but BG was not found, and entry point was invalid! Teleport to default race/class locations.",guid); sLog.outError("Player (guidlow %d) was in BG in database, but BG was not found, and entry point was invalid! Teleport to default race/class locations.",guid);
RelocateToHomebind(); RelocateToHomebind();
} else {
Relocate(&_loc);
} }
else
Relocate(&_loc);
// We are not in BG anymore // We are not in BG anymore
m_bgData.bgInstanceID = 0; m_bgData.bgInstanceID = 0;
+11 -14
View File
@@ -6005,7 +6005,7 @@ void Spell::DelayedChannel()
delaytime = delaytime * (100 - delayReduce) / 100; delaytime = delaytime * (100 - delayReduce) / 100;
if(int32(m_timer) < delaytime) if(int32(m_timer) <= delaytime)
{ {
delaytime = m_timer; delaytime = m_timer;
m_timer = 0; m_timer = 0;
@@ -6016,16 +6016,9 @@ void Spell::DelayedChannel()
sLog.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo->Id, delaytime, m_timer); sLog.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo->Id, delaytime, m_timer);
for (std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit) for (std::list<TargetInfo>::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
if ((*ihit).missCondition == SPELL_MISS_NONE) if ((*ihit).missCondition == SPELL_MISS_NONE)
{ if (Unit* unit = m_caster->GetGUID() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID))
Unit* unit = m_caster->GetGUID() == ihit->targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, ihit->targetGUID);
if (unit)
{
unit->DelayAura(m_spellInfo->Id, m_caster->GetGUID(), delaytime); unit->DelayAura(m_spellInfo->Id, m_caster->GetGUID(), delaytime);
}
}
}
// partially interrupt persistent area auras // partially interrupt persistent area auras
if(DynamicObject* dynObj = m_caster->GetDynObject(m_spellInfo->Id)) if(DynamicObject* dynObj = m_caster->GetDynObject(m_spellInfo->Id))
@@ -6041,7 +6034,8 @@ void Spell::UpdatePointers()
else else
{ {
m_originalCaster = ObjectAccessor::GetUnit(*m_caster,m_originalCasterGUID); m_originalCaster = ObjectAccessor::GetUnit(*m_caster,m_originalCasterGUID);
if(m_originalCaster && !m_originalCaster->IsInWorld()) m_originalCaster = NULL; if (m_originalCaster && !m_originalCaster->IsInWorld())
m_originalCaster = NULL;
} }
if (m_castItemGUID && m_caster->GetTypeId() == TYPEID_PLAYER) if (m_castItemGUID && m_caster->GetTypeId() == TYPEID_PLAYER)
@@ -6350,8 +6344,6 @@ bool SpellEvent::IsDeletable() const
bool Spell::IsValidSingleTargetEffect(Unit const* target, Targets type) const bool Spell::IsValidSingleTargetEffect(Unit const* target, Targets type) const
{ {
if (target->GetMapId() == MAPID_INVALID)
return false;
switch (type) switch (type)
{ {
case TARGET_UNIT_TARGET_ENEMY: case TARGET_UNIT_TARGET_ENEMY:
@@ -6369,7 +6361,12 @@ bool Spell::IsValidSingleTargetEffect(Unit const* target, Targets type) const
bool Spell::IsValidSingleTargetSpell(Unit const* target) const bool Spell::IsValidSingleTargetSpell(Unit const* target) const
{ {
for (int i = 0; i < 3; ++i) if (target->GetMapId() == MAPID_INVALID)
{
sLog.outDebug("Spell::IsValidSingleTargetSpell - a spell was cast on '%s' (GUIDLow: %u), but they have an invalid map id!", target->GetName(), target->GetGUIDLow());
return false;
}
for (uint8 i = 0; i < 3; ++i)
{ {
if(!IsValidSingleTargetEffect(target, Targets(m_spellInfo->EffectImplicitTargetA[i]))) if(!IsValidSingleTargetEffect(target, Targets(m_spellInfo->EffectImplicitTargetA[i])))
return false; return false;
@@ -6383,7 +6380,7 @@ bool Spell::IsValidSingleTargetSpell(Unit const* target) const
void Spell::CalculateDamageDoneForAllTargets() void Spell::CalculateDamageDoneForAllTargets()
{ {
float multiplier[3]; float multiplier[3];
for (int i = 0; i < 3; ++i) for (uint8 i = 0; i < 3; ++i)
{ {
if (m_applyMultiplierMask & (1 << i)) if (m_applyMultiplierMask & (1 << i))
{ {
+2 -1
View File
@@ -2366,7 +2366,8 @@ void Spell::EffectTeleportUnits(uint32 i)
// Init dest coordinates // Init dest coordinates
uint32 mapid = m_targets.m_dstPos.GetMapId(); uint32 mapid = m_targets.m_dstPos.GetMapId();
if(mapid == MAPID_INVALID) mapid = unitTarget->GetMapId(); if(mapid == MAPID_INVALID)
mapid = unitTarget->GetMapId();
float x, y, z; float x, y, z;
m_targets.m_dstPos.GetPosition(x, y, z); m_targets.m_dstPos.GetPosition(x, y, z);
float orientation = m_targets.getUnitTarget() ? m_targets.getUnitTarget()->GetOrientation() : unitTarget->GetOrientation(); float orientation = m_targets.getUnitTarget() ? m_targets.getUnitTarget()->GetOrientation() : unitTarget->GetOrientation();
+4 -6
View File
@@ -10615,19 +10615,19 @@ void Unit::SetInCombatState(bool PvP, Unit* enemy)
if (GetTypeId() != TYPEID_PLAYER) if (GetTypeId() != TYPEID_PLAYER)
{ {
// Set home position at place of engaging combat for escorted creatures // Set home position at place of engaging combat for escorted creatures
if(( ((Creature*)this)->IsAIEnabled && ((Creature*)this)->AI()->IsEscorted() ) || if(( IsAIEnabled && ((Creature*)this)->AI()->IsEscorted() ) ||
((Creature*)this)->GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE) GetMotionMaster()->GetCurrentMovementGeneratorType() == WAYPOINT_MOTION_TYPE)
((Creature*)this)->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation()); ((Creature*)this)->SetHomePosition(GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation());
if (enemy) if (enemy)
{ {
if(((Creature*)this)->IsAIEnabled) if (IsAIEnabled)
((Creature*)this)->AI()->EnterCombat(enemy); ((Creature*)this)->AI()->EnterCombat(enemy);
if (((Creature*)this)->GetFormation()) if (((Creature*)this)->GetFormation())
((Creature*)this)->GetFormation()->MemberAttackStart((Creature*)this, enemy); ((Creature*)this)->GetFormation()->MemberAttackStart((Creature*)this, enemy);
} }
if(((Creature*)this)->isPet()) if (isPet())
{ {
UpdateSpeed(MOVE_RUN, true); UpdateSpeed(MOVE_RUN, true);
UpdateSpeed(MOVE_SWIM, true); UpdateSpeed(MOVE_SWIM, true);
@@ -10660,12 +10660,10 @@ void Unit::ClearInCombat()
if (GetTypeId() != TYPEID_PLAYER && ((Creature*)this)->isPet()) if (GetTypeId() != TYPEID_PLAYER && ((Creature*)this)->isPet())
{ {
if (Unit *owner = GetOwner()) if (Unit *owner = GetOwner())
{
for (uint8 i = 0; i < MAX_MOVE_TYPE; ++i) for (uint8 i = 0; i < MAX_MOVE_TYPE; ++i)
if (owner->GetSpeedRate(UnitMoveType(i)) > GetSpeedRate(UnitMoveType(i))) if (owner->GetSpeedRate(UnitMoveType(i)) > GetSpeedRate(UnitMoveType(i)))
SetSpeed(UnitMoveType(i), owner->GetSpeedRate(UnitMoveType(i)), true); SetSpeed(UnitMoveType(i), owner->GetSpeedRate(UnitMoveType(i)), true);
} }
}
else if (!isCharmed()) else if (!isCharmed())
return; return;