[7333] Refactoring DestinationHolder/Traveler/Unit::SendMonsterMoveWithSpeed code. Author: VladimirMangos
* Move common code in appropriate functions.
* Correct select speed and 2D/3D distance for creature/player walk/fly
--HG--
branch : trunk
This commit is contained in:
@@ -174,8 +174,8 @@ struct TRINITY_DLL_DECL npc_highborne_lamenterAI : public ScriptedAI
|
||||
{
|
||||
if( EventMove_Timer < diff )
|
||||
{
|
||||
m_creature->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT | MOVEMENTFLAG_LEVITATING);
|
||||
m_creature->SendMonsterMoveWithSpeed(m_creature->GetPositionX(),m_creature->GetPositionY(),HIGHBORNE_LOC_Y_NEW,MOVEMENTFLAG_ONTRANSPORT,5000);
|
||||
m_creature->AddUnitMovementFlag(MOVEMENTFLAG_LEVITATING);
|
||||
m_creature->SendMonsterMoveWithSpeed(m_creature->GetPositionX(),m_creature->GetPositionY(),HIGHBORNE_LOC_Y_NEW,5000);
|
||||
m_creature->GetMap()->CreatureRelocation(m_creature,m_creature->GetPositionX(),m_creature->GetPositionY(),HIGHBORNE_LOC_Y_NEW,m_creature->GetOrientation());
|
||||
EventMove = false;
|
||||
}else EventMove_Timer -= diff;
|
||||
|
||||
@@ -85,24 +85,7 @@ DestinationHolder<TRAVELLER>::StartTravel(TRAVELLER &traveller, bool sendMove)
|
||||
i_fromY = traveller.GetPositionY();
|
||||
i_fromZ = traveller.GetPositionZ();
|
||||
|
||||
float dx = i_destX - i_fromX;
|
||||
float dy = i_destY - i_fromY;
|
||||
float dz = i_destZ - i_fromZ;
|
||||
|
||||
float dist;
|
||||
//Should be for Creature Flying and Swimming.
|
||||
if(traveller.GetTraveller().hasUnitState(UNIT_STAT_IN_FLIGHT))
|
||||
dist = sqrt((dx*dx) + (dy*dy) + (dz*dz));
|
||||
else //Walking on the ground
|
||||
dist = sqrt((dx*dx) + (dy*dy));
|
||||
|
||||
float speed;
|
||||
if(traveller.GetTraveller().hasUnitState(UNIT_STAT_CHARGING))
|
||||
speed = SPEED_CHARGE * 0.001f;
|
||||
else
|
||||
speed = traveller.Speed() * 0.001f; // speed is in seconds so convert from second to millisecond
|
||||
i_totalTravelTime = static_cast<uint32>(dist/speed);
|
||||
|
||||
i_totalTravelTime = traveller.GetTotalTrevelTimeTo(i_destX,i_destY,i_destZ);
|
||||
i_timeElapsed = 0;
|
||||
if(sendMove)
|
||||
traveller.MoveTo(i_destX, i_destY, i_destZ, i_totalTravelTime);
|
||||
|
||||
@@ -142,11 +142,17 @@ VisibleNotifier::Notify()
|
||||
|
||||
// Now do operations that required done at object visibility change to visible
|
||||
|
||||
// target aura duration for caster show only if target exist at caster client
|
||||
// send data at target visibility change (adding to client)
|
||||
for(std::set<WorldObject*>::const_iterator vItr = i_visibleNow.begin(); vItr != i_visibleNow.end(); ++vItr)
|
||||
{
|
||||
// target aura duration for caster show only if target exist at caster client
|
||||
if((*vItr)!=&i_player && (*vItr)->isType(TYPEMASK_UNIT))
|
||||
i_player.SendAurasForTarget((Unit*)(*vItr));
|
||||
|
||||
// non finished movements show to player
|
||||
if((*vItr)->GetTypeId()==TYPEID_UNIT && ((Creature*)(*vItr))->isAlive())
|
||||
((Creature*)(*vItr))->SendMonsterMoveWithSpeedToCurrentDestination(&i_player);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+3
-3
@@ -18495,7 +18495,7 @@ void Player::UpdateVisibilityOf(T* target, UpdateData& data, UpdateDataMapType&
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
/*template<>
|
||||
void Player::UpdateVisibilityOf<Creature>(Creature* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow)
|
||||
{
|
||||
if(HaveAtClient(target))
|
||||
@@ -18528,10 +18528,10 @@ void Player::UpdateVisibilityOf<Creature>(Creature* target, UpdateData& data, Up
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
template void Player::UpdateVisibilityOf(Player* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
|
||||
//template void Player::UpdateVisibilityOf(Creature* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
|
||||
template void Player::UpdateVisibilityOf(Creature* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
|
||||
template void Player::UpdateVisibilityOf(Corpse* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
|
||||
template void Player::UpdateVisibilityOf(GameObject* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
|
||||
template void Player::UpdateVisibilityOf(DynamicObject* target, UpdateData& data, UpdateDataMapType& data_updates, std::set<WorldObject*>& visibleNow);
|
||||
|
||||
@@ -53,11 +53,27 @@ struct TRINITY_DLL_DECL Traveller
|
||||
T& GetTraveller(void) { return i_traveller; }
|
||||
|
||||
float Speed(void) { assert(false); return 0.0f; }
|
||||
float GetMoveDestinationTo(float x, float y, float z);
|
||||
uint32 GetTotalTrevelTimeTo(float x, float y, float z);
|
||||
|
||||
void Relocation(float x, float y, float z, float orientation) {}
|
||||
void Relocation(float x, float y, float z) { Relocation(x, y, z, i_traveller.GetOrientation()); }
|
||||
void MoveTo(float x, float y, float z, uint32 t) {}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline uint32 Traveller<T>::GetTotalTrevelTimeTo(float x, float y, float z)
|
||||
{
|
||||
float dist = GetMoveDestinationTo(x,y,z);
|
||||
float speed = 0.001f;
|
||||
if(GetTraveller().hasUnitState(UNIT_STAT_CHARGING))
|
||||
speed *= SPEED_CHARGE;
|
||||
else
|
||||
speed *= Speed(); // speed is in seconds so convert from second to millisecond
|
||||
|
||||
return static_cast<uint32>(dist/speed);
|
||||
}
|
||||
|
||||
// specialization for creatures
|
||||
template<>
|
||||
inline float Traveller<Creature>::Speed()
|
||||
@@ -76,6 +92,20 @@ inline void Traveller<Creature>::Relocation(float x, float y, float z, float ori
|
||||
MapManager::Instance().GetMap(i_traveller.GetMapId(), &i_traveller)->CreatureRelocation(&i_traveller, x, y, z, orientation);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline float Traveller<Creature>::GetMoveDestinationTo(float x, float y, float z)
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
float dz = z - GetPositionZ();
|
||||
|
||||
if(i_traveller.hasUnitState(UNIT_STAT_IN_FLIGHT))
|
||||
return sqrt((dx*dx) + (dy*dy) + (dz*dz));
|
||||
else //Walking on the ground
|
||||
return sqrt((dx*dx) + (dy*dy));
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
inline void Traveller<Creature>::MoveTo(float x, float y, float z, uint32 t)
|
||||
{
|
||||
@@ -97,6 +127,19 @@ inline float Traveller<Player>::Speed()
|
||||
return i_traveller.GetSpeed(i_traveller.HasUnitMovementFlag(MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline float Traveller<Player>::GetMoveDestinationTo(float x, float y, float z)
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
float dz = z - GetPositionZ();
|
||||
|
||||
if (i_traveller.isInFlight())
|
||||
return sqrt((dx*dx) + (dy*dy) + (dz*dz));
|
||||
else //Walking on the ground
|
||||
return sqrt((dx*dx) + (dy*dy));
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void Traveller<Player>::Relocation(float x, float y, float z, float orientation)
|
||||
{
|
||||
|
||||
+12
-16
@@ -47,6 +47,7 @@
|
||||
#include "CellImpl.h"
|
||||
#include "Path.h"
|
||||
#include "CreatureGroups.h"
|
||||
#include "Traveller.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
@@ -276,28 +277,23 @@ void Unit::SendMonsterMoveWithSpeedToCurrentDestination(Player* player)
|
||||
{
|
||||
float x, y, z;
|
||||
if(GetMotionMaster()->GetDestination(x, y, z))
|
||||
SendMonsterMoveWithSpeed(x, y, z, GetUnitMovementFlags(), 0, player);
|
||||
SendMonsterMoveWithSpeed(x, y, z, 0, player);
|
||||
}
|
||||
|
||||
void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime, Player* player)
|
||||
void Unit::SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime, Player* player)
|
||||
{
|
||||
if (!transitTime)
|
||||
{
|
||||
float dx = x - GetPositionX();
|
||||
float dy = y - GetPositionY();
|
||||
float dz = z - GetPositionZ();
|
||||
|
||||
float dist = ((dx*dx) + (dy*dy) + (dz*dz));
|
||||
if(dist<0)
|
||||
dist = 0;
|
||||
if(GetTypeId()==TYPEID_PLAYER)
|
||||
{
|
||||
Traveller<Player> traveller(*(Player*)this);
|
||||
transitTime = traveller.GetTotalTrevelTimeTo(x,y,z);
|
||||
}
|
||||
else
|
||||
dist = sqrt(dist);
|
||||
|
||||
double speed = GetSpeed((MovementFlags & MOVEMENTFLAG_WALK_MODE) ? MOVE_WALK : MOVE_RUN);
|
||||
if(speed<=0)
|
||||
speed = 2.5f;
|
||||
speed *= 0.001f;
|
||||
transitTime = static_cast<uint32>(dist / speed + 0.5);
|
||||
{
|
||||
Traveller<Creature> traveller(*(Creature*)this);
|
||||
transitTime = traveller.GetTotalTrevelTimeTo(x,y,z);
|
||||
}
|
||||
}
|
||||
//float orientation = (float)atan2((double)dy, (double)dx);
|
||||
SendMonsterMove(x, y, z, transitTime, player);
|
||||
|
||||
+1
-1
@@ -1143,7 +1143,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
|
||||
void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint32 Time, Player* player = NULL);
|
||||
//void SendMonsterMove(float NewPosX, float NewPosY, float NewPosZ, uint8 type, uint32 MovementFlags, uint32 Time, Player* player = NULL);
|
||||
void SendMonsterMoveByPath(Path const& path, uint32 start, uint32 end);
|
||||
void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 MovementFlags, uint32 transitTime = 0, Player* player = NULL);
|
||||
void SendMonsterMoveWithSpeed(float x, float y, float z, uint32 transitTime = 0, Player* player = NULL);
|
||||
void SendMonsterMoveWithSpeedToCurrentDestination(Player* player = NULL);
|
||||
|
||||
virtual void MoveOutOfRange(Player &) { };
|
||||
|
||||
+1
-1
@@ -1959,7 +1959,7 @@ void World::ScriptsProcess()
|
||||
sLog.outError("SCRIPT_COMMAND_MOVE_TO call for non-creature (TypeId: %u), skipping.",source->GetTypeId());
|
||||
break;
|
||||
}
|
||||
((Unit *)source)->SendMonsterMoveWithSpeed(step.script->x, step.script->y, step.script->z, ((Unit *)source)->GetUnitMovementFlags(), step.script->datalong2 );
|
||||
((Unit *)source)->SendMonsterMoveWithSpeed(step.script->x, step.script->y, step.script->z, step.script->datalong2 );
|
||||
((Unit *)source)->GetMap()->CreatureRelocation(((Creature *)source), step.script->x, step.script->y, step.script->z, 0);
|
||||
break;
|
||||
case SCRIPT_COMMAND_FLAG_SET:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "7332"
|
||||
#define REVISION_NR "7334"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
||||
Reference in New Issue
Block a user