*add new fuction StartAutoRotate(direction, fullturntime) to creatures, it will rotate any creature 360degrees, turning shouldn't be stopped by taunt and other effects.

useful for some boss scripts

--HG--
branch : trunk
This commit is contained in:
Rat
2009-08-24 00:14:32 +02:00
parent 73c66a028c
commit 6ce460e04d
2 changed files with 67 additions and 3 deletions
+44 -2
View File
@@ -171,6 +171,8 @@ Unit::Unit()
// remove aurastates allowing special moves
for(uint8 i=0; i < MAX_REACTIVE; ++i)
m_reactiveTimer[i] = 0;
IsRotating = 0;
}
Unit::~Unit()
@@ -253,7 +255,10 @@ void Unit::Update( uint32 p_time )
ModifyAuraState(AURA_STATE_HEALTHLESS_35_PERCENT, GetHealth() < GetMaxHealth()*0.35f);
ModifyAuraState(AURA_STATE_HEALTH_ABOVE_75_PERCENT, GetHealth() > GetMaxHealth()*0.75f);
i_motionMaster.UpdateMotion(p_time);
if(!IsUnitRotating())
i_motionMaster.UpdateMotion(p_time);
else
AutoRotate(p_time);
}
bool Unit::haveOffhandWeapon() const
@@ -497,6 +502,42 @@ void Unit::GetRandomContactPoint( const Unit* obj, float &x, float &y, float &z,
, GetAngle(obj) + (attacker_number ? (M_PI/2 - M_PI * rand_norm()) * (float)attacker_number / combat_reach * 0.3 : 0));
}
void Unit::StartAutoRotate(uint8 type, uint32 fulltime)
{
if(getVictim())
RotateAngle = GetAngle(getVictim());
else
RotateAngle = GetOrientation();
RotateTimer = fulltime;
RotateTimerFull = fulltime;
IsRotating = type;
LastTargetGUID = GetUInt64Value(UNIT_FIELD_TARGET);
SetUInt64Value(UNIT_FIELD_TARGET, 0);
}
void Unit::AutoRotate(uint32 time)
{
if(!IsRotating)return;
if(IsRotating == CREATURE_ROTATE_LEFT)
{
RotateAngle += (double)time/RotateTimerFull*(double)M_PI*2;
if (RotateAngle >= M_PI*2)RotateAngle = 0;
}
else
{
RotateAngle -= (double)time/RotateTimerFull*(double)M_PI*2;
if (RotateAngle < 0)RotateAngle = M_PI*2;
}
SetOrientation(RotateAngle);
StopMoving();
if(RotateTimer <= time)
{
IsRotating = CREATURE_ROTATE_NONE;
RotateAngle = 0;
RotateTimer = RotateTimerFull;
SetUInt64Value(UNIT_FIELD_TARGET, LastTargetGUID);
}else RotateTimer -= time;
}
void Unit::RemoveMovementImpairingAuras()
{
for(AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();)
@@ -3422,7 +3463,8 @@ bool Unit::isInFrontInMap(Unit const* target, float distance, float arc) const
void Unit::SetInFront(Unit const* target)
{
SetOrientation(GetAngle(target));
if(!IsUnitRotating())
SetOrientation(GetAngle(target));
}
bool Unit::isInBackInMap(Unit const* target, float distance, float arc) const
+23 -1
View File
@@ -943,6 +943,13 @@ enum ActionBarIndex
ACTION_BAR_INDEX_END = 10,
};
enum Rotation
{
CREATURE_ROTATE_NONE = 0,
CREATURE_ROTATE_LEFT = 1,
CREATURE_ROTATE_RIGHT = 2
};
#define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
struct CharmInfo
@@ -1067,6 +1074,9 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
void GetRandomContactPoint( const Unit* target, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const;
uint32 m_extraAttacks;
bool m_canDualWield;
void StartAutoRotate(uint8 type, uint32 fulltime);
void AutoRotate(uint32 time);
bool IsUnitRotating() {return IsRotating;}
void _addAttacker(Unit *pAttacker) // must be called only from Unit::Attack(Unit*)
{
@@ -1092,7 +1102,13 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
void RemoveAllAttackers();
AttackerSet const& getAttackers() const { return m_attackers; }
bool isAttackingPlayer() const;
Unit* getVictim() const { return m_attacking; }
Unit* getVictim() const
{
if(IsRotating)return NULL;
return m_attacking;
}
void CombatStop(bool includingCast = false);
void CombatStopWithPets(bool includingCast = false);
Unit* SelectNearbyTarget(float dist = NOMINAL_MELEE_RANGE) const;
@@ -1928,6 +1944,12 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
uint32 m_reducedThreatPercent;
uint64 m_misdirectionTargetGUID;
uint8 IsRotating;//0none 1left 2right
uint32 RotateTimer;
uint32 RotateTimerFull;
double RotateAngle;
uint64 LastTargetGUID;
};
namespace Trinity