2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "SharedDefines.h"
21 #include "WorldPacket.h"
29 #include "ObjectMgr.h"
30 #include "UpdateData.h"
31 #include "UpdateMask.h"
33 #include "MapManager.h"
34 #include "ObjectAccessor.h"
36 #include "Transports.h"
37 #include "TargetedMovementGenerator.h"
38 #include "WaypointMovementGenerator.h"
39 #include "VMapFactory.h"
41 #include "GridNotifiers.h"
42 #include "GridNotifiersImpl.h"
44 #include "ObjectPosSelector.h"
46 #include "TemporarySummon.h"
48 uint32
GuidHigh2TypeId(uint32 guid_hi
)
52 case HIGHGUID_ITEM
: return TYPEID_ITEM
;
53 //case HIGHGUID_CONTAINER: return TYPEID_CONTAINER; HIGHGUID_CONTAINER==HIGHGUID_ITEM currently
54 case HIGHGUID_UNIT
: return TYPEID_UNIT
;
55 case HIGHGUID_PET
: return TYPEID_UNIT
;
56 case HIGHGUID_PLAYER
: return TYPEID_PLAYER
;
57 case HIGHGUID_GAMEOBJECT
: return TYPEID_GAMEOBJECT
;
58 case HIGHGUID_DYNAMICOBJECT
:return TYPEID_DYNAMICOBJECT
;
59 case HIGHGUID_CORPSE
: return TYPEID_CORPSE
;
60 case HIGHGUID_MO_TRANSPORT
: return TYPEID_GAMEOBJECT
;
61 case HIGHGUID_VEHICLE
: return TYPEID_UNIT
;
63 return NUM_CLIENT_OBJECT_TYPES
; // unknown
66 Object::Object( ) : m_PackGUID(sizeof(uint64
)+1)
68 m_objectTypeId
= TYPEID_OBJECT
;
69 m_objectType
= TYPEMASK_OBJECT
;
72 m_uint32Values_mirror
= 0;
76 m_objectUpdated
= false;
78 m_PackGUID
.appendPackGUID(0);
84 ObjectAccessor::Instance().RemoveUpdateObject(this);
90 ///- Do NOT call RemoveFromWorld here, if the object is a player it will crash
91 sLog
.outError("Object::~Object (GUID: %u TypeId: %u) deleted but still in world!!", GetGUIDLow(), GetTypeId());
95 //DEBUG_LOG("Object desctr 1 check (%p)",(void*)this);
96 delete [] m_uint32Values
;
97 delete [] m_uint32Values_mirror
;
98 //DEBUG_LOG("Object desctr 2 check (%p)",(void*)this);
102 void Object::_InitValues()
104 m_uint32Values
= new uint32
[ m_valuesCount
];
105 memset(m_uint32Values
, 0, m_valuesCount
*sizeof(uint32
));
107 m_uint32Values_mirror
= new uint32
[ m_valuesCount
];
108 memset(m_uint32Values_mirror
, 0, m_valuesCount
*sizeof(uint32
));
110 m_objectUpdated
= false;
113 void Object::_Create( uint32 guidlow
, uint32 entry
, HighGuid guidhigh
)
115 if(!m_uint32Values
) _InitValues();
117 uint64 guid
= MAKE_NEW_GUID(guidlow
, entry
, guidhigh
);
118 SetUInt64Value( OBJECT_FIELD_GUID
, guid
);
119 SetUInt32Value( OBJECT_FIELD_TYPE
, m_objectType
);
121 m_PackGUID
.appendPackGUID(GetGUID());
124 void Object::BuildMovementUpdateBlock(UpdateData
* data
, uint32 flags
) const
128 buf
<< uint8( UPDATETYPE_MOVEMENT
);
129 buf
.append(GetPackGUID());
131 _BuildMovementUpdate(&buf
, flags
, 0x00000000);
133 data
->AddUpdateBlock(buf
);
136 void Object::BuildCreateUpdateBlockForPlayer(UpdateData
*data
, Player
*target
) const
141 uint8 updatetype
= UPDATETYPE_CREATE_OBJECT
;
142 uint16 flags
= m_updateFlag
;
146 if(target
== this) // building packet for yourself
147 flags
|= UPDATEFLAG_SELF
;
149 if(flags
& UPDATEFLAG_HAS_POSITION
)
151 // UPDATETYPE_CREATE_OBJECT2 dynamic objects, corpses...
152 if(isType(TYPEMASK_DYNAMICOBJECT
) || isType(TYPEMASK_CORPSE
) || isType(TYPEMASK_PLAYER
))
153 updatetype
= UPDATETYPE_CREATE_OBJECT2
;
155 // UPDATETYPE_CREATE_OBJECT2 for pets...
156 if(target
->GetPetGUID() == GetGUID())
157 updatetype
= UPDATETYPE_CREATE_OBJECT2
;
159 // UPDATETYPE_CREATE_OBJECT2 for some gameobject types...
160 if(isType(TYPEMASK_GAMEOBJECT
))
162 switch(((GameObject
*)this)->GetGoType())
164 case GAMEOBJECT_TYPE_TRAP
:
165 case GAMEOBJECT_TYPE_DUEL_ARBITER
:
166 case GAMEOBJECT_TYPE_FLAGSTAND
:
167 case GAMEOBJECT_TYPE_FLAGDROP
:
168 updatetype
= UPDATETYPE_CREATE_OBJECT2
;
170 case GAMEOBJECT_TYPE_TRANSPORT
:
171 flags
|= UPDATEFLAG_TRANSPORT
;
178 if(isType(TYPEMASK_UNIT
))
180 if(((Unit
*)this)->getVictim())
181 flags
|= UPDATEFLAG_HAS_TARGET
;
185 //sLog.outDebug("BuildCreateUpdate: update-type: %u, object-type: %u got flags: %X, flags2: %X", updatetype, m_objectTypeId, flags, flags2);
188 buf
<< (uint8
)updatetype
;
189 buf
.append(GetPackGUID());
190 buf
<< (uint8
)m_objectTypeId
;
192 _BuildMovementUpdate(&buf
, flags
, flags2
);
194 UpdateMask updateMask
;
195 updateMask
.SetCount( m_valuesCount
);
196 _SetCreateBits( &updateMask
, target
);
197 _BuildValuesUpdate(updatetype
, &buf
, &updateMask
, target
);
198 data
->AddUpdateBlock(buf
);
201 void Object::BuildUpdate(UpdateDataMapType
&update_players
)
203 ObjectAccessor::_buildUpdateObject(this,update_players
);
204 ClearUpdateMask(true);
207 void Object::SendUpdateToPlayer(Player
* player
)
209 // send update to another players
210 SendUpdateObjectToAllExcept(player
);
212 // send create update to player
217 BuildCreateUpdateBlockForPlayer(&upd
, player
);
218 upd
.BuildPacket(&packet
);
219 player
->GetSession()->SendPacket(&packet
);
222 void Object::BuildValuesUpdateBlockForPlayer(UpdateData
*data
, Player
*target
) const
226 buf
<< (uint8
) UPDATETYPE_VALUES
;
227 buf
.append(GetPackGUID());
229 UpdateMask updateMask
;
230 updateMask
.SetCount( m_valuesCount
);
232 _SetUpdateBits( &updateMask
, target
);
233 _BuildValuesUpdate(UPDATETYPE_VALUES
, &buf
, &updateMask
, target
);
235 data
->AddUpdateBlock(buf
);
238 void Object::BuildOutOfRangeUpdateBlock(UpdateData
* data
) const
240 data
->AddOutOfRangeGUID(GetGUID());
243 void Object::DestroyForPlayer( Player
*target
, bool anim
) const
247 WorldPacket
data(SMSG_DESTROY_OBJECT
, 8);
248 data
<< uint64(GetGUID());
249 data
<< uint8(anim
? 1 : 0); // WotLK (bool), may be despawn animation
250 target
->GetSession()->SendPacket( &data
);
253 void Object::_BuildMovementUpdate(ByteBuffer
* data
, uint16 flags
, uint32 flags2
) const
255 uint16 unk_flags
= ((GetTypeId() == TYPEID_PLAYER
) ? ((Player
*)this)->m_movementInfo
.unk1
: 0);
257 if(GetTypeId() == TYPEID_UNIT
)
258 if(((Creature
*)this)->isVehicle())
259 unk_flags
|= 0x20; // always allow pitch
261 *data
<< (uint16
)flags
; // update flags
264 if (flags
& UPDATEFLAG_LIVING
)
270 flags2
= ((Unit
*)this)->isInFlight() ? (MOVEMENTFLAG_FORWARD
| MOVEMENTFLAG_LEVITATING
) : MOVEMENTFLAG_NONE
;
275 flags2
= ((Player
*)this)->m_movementInfo
.GetMovementFlags();
277 if(((Player
*)this)->GetTransport())
278 flags2
|= MOVEMENTFLAG_ONTRANSPORT
;
280 flags2
&= ~MOVEMENTFLAG_ONTRANSPORT
;
282 // remove unknown, unused etc flags for now
283 flags2
&= ~MOVEMENTFLAG_SPLINE2
; // will be set manually
285 if(((Player
*)this)->isInFlight())
287 WPAssert(((Player
*)this)->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE
);
288 flags2
= (MOVEMENTFLAG_FORWARD
| MOVEMENTFLAG_SPLINE2
);
294 *data
<< uint32(flags2
); // movement flags
295 *data
<< uint16(unk_flags
); // unknown 2.3.0
296 *data
<< uint32(getMSTime()); // time (in milliseconds)
299 *data
<< ((WorldObject
*)this)->GetPositionX();
300 *data
<< ((WorldObject
*)this)->GetPositionY();
301 *data
<< ((WorldObject
*)this)->GetPositionZ();
302 *data
<< ((WorldObject
*)this)->GetOrientation();
305 if(flags2
& MOVEMENTFLAG_ONTRANSPORT
)
307 if(GetTypeId() == TYPEID_PLAYER
)
309 data
->append(((Player
*)this)->GetTransport()->GetPackGUID());
310 *data
<< (float)((Player
*)this)->GetTransOffsetX();
311 *data
<< (float)((Player
*)this)->GetTransOffsetY();
312 *data
<< (float)((Player
*)this)->GetTransOffsetZ();
313 *data
<< (float)((Player
*)this)->GetTransOffsetO();
314 *data
<< (uint32
)((Player
*)this)->GetTransTime();
315 *data
<< (int8
)((Player
*)this)->GetTransSeat();
319 //MaNGOS currently not have support for other than player on transport
321 *data
<< float(0) << float(0) << float(0) << float(0);
328 if((flags2
& (MOVEMENTFLAG_SWIMMING
| MOVEMENTFLAG_FLYING2
)) || (unk_flags
& 0x20))
330 if(GetTypeId() == TYPEID_PLAYER
)
331 *data
<< (float)((Player
*)this)->m_movementInfo
.s_pitch
;
333 *data
<< (float)0; // is't part of movement packet, we must store and send it...
336 if(GetTypeId() == TYPEID_PLAYER
)
337 *data
<< (uint32
)((Player
*)this)->m_movementInfo
.fallTime
;
339 *data
<< (uint32
)0; // last fall time
342 if(flags2
& MOVEMENTFLAG_JUMPING
)
344 if(GetTypeId() == TYPEID_PLAYER
)
346 *data
<< (float)((Player
*)this)->m_movementInfo
.j_unk
;
347 *data
<< (float)((Player
*)this)->m_movementInfo
.j_sinAngle
;
348 *data
<< (float)((Player
*)this)->m_movementInfo
.j_cosAngle
;
349 *data
<< (float)((Player
*)this)->m_movementInfo
.j_xyspeed
;
361 if(flags2
& MOVEMENTFLAG_SPLINE
)
363 if(GetTypeId() == TYPEID_PLAYER
)
364 *data
<< (float)((Player
*)this)->m_movementInfo
.u_unk1
;
369 *data
<< ((Unit
*)this)->GetSpeed( MOVE_WALK
);
370 *data
<< ((Unit
*)this)->GetSpeed( MOVE_RUN
);
371 *data
<< ((Unit
*)this)->GetSpeed( MOVE_SWIM_BACK
);
372 *data
<< ((Unit
*)this)->GetSpeed( MOVE_SWIM
);
373 *data
<< ((Unit
*)this)->GetSpeed( MOVE_RUN_BACK
);
374 *data
<< ((Unit
*)this)->GetSpeed( MOVE_FLIGHT
);
375 *data
<< ((Unit
*)this)->GetSpeed( MOVE_FLIGHT_BACK
);
376 *data
<< ((Unit
*)this)->GetSpeed( MOVE_TURN_RATE
);
377 *data
<< ((Unit
*)this)->GetSpeed( MOVE_PITCH_RATE
);
380 if(flags2
& MOVEMENTFLAG_SPLINE2
)
382 if(GetTypeId() != TYPEID_PLAYER
)
384 sLog
.outDebug("_BuildMovementUpdate: MOVEMENTFLAG_SPLINE2 for non-player");
388 if(!((Player
*)this)->isInFlight())
390 sLog
.outDebug("_BuildMovementUpdate: MOVEMENTFLAG_SPLINE2 but not in flight");
394 WPAssert(((Player
*)this)->GetMotionMaster()->GetCurrentMovementGeneratorType() == FLIGHT_MOTION_TYPE
);
396 FlightPathMovementGenerator
*fmg
= (FlightPathMovementGenerator
*)(((Player
*)this)->GetMotionMaster()->top());
398 uint32 flags3
= MONSTER_MOVE_SPLINE_FLY
;
400 *data
<< uint32(flags3
); // splines flag?
402 if(flags3
& 0x20000) // may be orientation
408 if(flags3
& 0x8000) // probably x,y,z coords there
415 if(flags3
& 0x10000) // probably guid there
421 Path
&path
= fmg
->GetPath();
424 ((Player
*)this)->GetPosition(x
, y
, z
);
426 uint32 inflighttime
= uint32(path
.GetPassedLength(fmg
->GetCurrentNode(), x
, y
, z
) * 32);
427 uint32 traveltime
= uint32(path
.GetTotalLength() * 32);
429 *data
<< uint32(inflighttime
); // passed move time?
430 *data
<< uint32(traveltime
); // full move time?
431 *data
<< uint32(0); // ticks count?
433 *data
<< float(0); // added in 3.1
434 *data
<< float(0); // added in 3.1
435 *data
<< float(0); // added in 3.1
437 *data
<< uint32(0); // added in 3.1
439 uint32 poscount
= uint32(path
.Size());
440 *data
<< uint32(poscount
); // points count
442 for(uint32 i
= 0; i
< poscount
; ++i
)
444 *data
<< path
.GetNodes()[i
].x
;
445 *data
<< path
.GetNodes()[i
].y
;
446 *data
<< path
.GetNodes()[i
].z
;
449 *data
<< uint8(0); // added in 3.0.8
451 *data
<< path
.GetNodes()[poscount
-1].x
;
452 *data
<< path
.GetNodes()[poscount
-1].y
;
453 *data
<< path
.GetNodes()[poscount
-1].z
;
458 if(flags
& UPDATEFLAG_POSITION
)
460 *data
<< uint8(0); // unk PGUID!
461 *data
<< ((WorldObject
*)this)->GetPositionX();
462 *data
<< ((WorldObject
*)this)->GetPositionY();
463 *data
<< ((WorldObject
*)this)->GetPositionZ();
464 *data
<< ((WorldObject
*)this)->GetPositionX();
465 *data
<< ((WorldObject
*)this)->GetPositionY();
466 *data
<< ((WorldObject
*)this)->GetPositionZ();
467 *data
<< ((WorldObject
*)this)->GetOrientation();
469 if(GetTypeId() == TYPEID_CORPSE
)
470 *data
<< float(((WorldObject
*)this)->GetOrientation());
477 if (flags
& UPDATEFLAG_HAS_POSITION
)
480 if(flags
& UPDATEFLAG_TRANSPORT
&& ((GameObject
*)this)->GetGoType() == GAMEOBJECT_TYPE_MO_TRANSPORT
)
485 *data
<< ((WorldObject
*)this)->GetOrientation();
489 *data
<< ((WorldObject
*)this)->GetPositionX();
490 *data
<< ((WorldObject
*)this)->GetPositionY();
491 *data
<< ((WorldObject
*)this)->GetPositionZ();
492 *data
<< ((WorldObject
*)this)->GetOrientation();
499 if(flags
& UPDATEFLAG_LOWGUID
)
505 case TYPEID_CONTAINER
:
506 case TYPEID_GAMEOBJECT
:
507 case TYPEID_DYNAMICOBJECT
:
509 *data
<< uint32(GetGUIDLow()); // GetGUIDLow()
512 *data
<< uint32(0x0000000B); // unk, can be 0xB or 0xC
515 if(flags
& UPDATEFLAG_SELF
)
516 *data
<< uint32(0x0000002F); // unk, can be 0x15 or 0x22
518 *data
<< uint32(0x00000008); // unk, can be 0x7 or 0x8
521 *data
<< uint32(0x00000000); // unk
527 if(flags
& UPDATEFLAG_HIGHGUID
)
533 case TYPEID_CONTAINER
:
534 case TYPEID_GAMEOBJECT
:
535 case TYPEID_DYNAMICOBJECT
:
537 *data
<< uint32(GetGUIDHigh()); // GetGUIDHigh()
540 *data
<< uint32(0x0000000B); // unk, can be 0xB or 0xC
543 if(flags
& UPDATEFLAG_SELF
)
544 *data
<< uint32(0x0000002F); // unk, can be 0x15 or 0x22
546 *data
<< uint32(0x00000008); // unk, can be 0x7 or 0x8
549 *data
<< uint32(0x00000000); // unk
555 if(flags
& UPDATEFLAG_HAS_TARGET
) // packed guid (current target guid)
557 if(Unit
*victim
= ((Unit
*)this)->getVictim())
558 data
->append(victim
->GetPackGUID());
564 if(flags
& UPDATEFLAG_TRANSPORT
)
566 *data
<< uint32(getMSTime()); // ms time
570 if(flags
& UPDATEFLAG_VEHICLE
) // unused for now
572 *data
<< uint32(((Vehicle
*)this)->GetVehicleId()); // vehicle id
573 *data
<< float(0); // facing adjustment
577 if(flags
& UPDATEFLAG_ROTATION
)
579 *data
<< uint64(((GameObject
*)this)->GetRotation());
583 void Object::_BuildValuesUpdate(uint8 updatetype
, ByteBuffer
* data
, UpdateMask
*updateMask
, Player
*target
) const
588 bool IsActivateToQuest
= false;
589 bool IsPerCasterAuraState
= false;
590 if (updatetype
== UPDATETYPE_CREATE_OBJECT
|| updatetype
== UPDATETYPE_CREATE_OBJECT2
)
592 if (isType(TYPEMASK_GAMEOBJECT
) && !((GameObject
*)this)->IsTransport())
594 if ( ((GameObject
*)this)->ActivateToQuest(target
) || target
->isGameMaster())
595 IsActivateToQuest
= true;
597 updateMask
->SetBit(GAMEOBJECT_DYNAMIC
);
599 else if (isType(TYPEMASK_UNIT
))
601 if( ((Unit
*)this)->HasAuraState(AURA_STATE_CONFLAGRATE
))
603 IsPerCasterAuraState
= true;
604 updateMask
->SetBit(UNIT_FIELD_AURASTATE
);
608 else // case UPDATETYPE_VALUES
610 if (isType(TYPEMASK_GAMEOBJECT
) && !((GameObject
*)this)->IsTransport())
612 if ( ((GameObject
*)this)->ActivateToQuest(target
) || target
->isGameMaster())
614 IsActivateToQuest
= true;
616 updateMask
->SetBit(GAMEOBJECT_DYNAMIC
);
617 updateMask
->SetBit(GAMEOBJECT_BYTES_1
);
619 else if (isType(TYPEMASK_UNIT
))
621 if( ((Unit
*)this)->HasAuraState(AURA_STATE_CONFLAGRATE
))
623 IsPerCasterAuraState
= true;
624 updateMask
->SetBit(UNIT_FIELD_AURASTATE
);
629 WPAssert(updateMask
&& updateMask
->GetCount() == m_valuesCount
);
631 *data
<< (uint8
)updateMask
->GetBlockCount();
632 data
->append( updateMask
->GetMask(), updateMask
->GetLength() );
634 // 2 specialized loops for speed optimization in non-unit case
635 if(isType(TYPEMASK_UNIT
)) // unit (creature/player) case
637 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
639 if( updateMask
->GetBit( index
) )
641 if( index
== UNIT_NPC_FLAGS
)
643 // remove custom flag before sending
644 uint32 appendValue
= m_uint32Values
[ index
] & ~UNIT_NPC_FLAG_GUARD
;
646 if (GetTypeId() == TYPEID_UNIT
&& !target
->canSeeSpellClickOn((Creature
*)this))
647 appendValue
&= ~UNIT_NPC_FLAG_SPELLCLICK
;
649 *data
<< uint32(appendValue
);
651 else if (index
== UNIT_FIELD_AURASTATE
)
653 if(IsPerCasterAuraState
)
655 // IsPerCasterAuraState set if related pet caster aura state set already
656 if (((Unit
*)this)->HasAuraStateForCaster(AURA_STATE_CONFLAGRATE
,target
->GetGUID()))
657 *data
<< m_uint32Values
[ index
];
659 *data
<< (m_uint32Values
[ index
] & ~(1 << (AURA_STATE_CONFLAGRATE
-1)));
662 *data
<< m_uint32Values
[ index
];
664 // FIXME: Some values at server stored in float format but must be sent to client in uint32 format
665 else if(index
>= UNIT_FIELD_BASEATTACKTIME
&& index
<= UNIT_FIELD_RANGEDATTACKTIME
)
667 // convert from float to uint32 and send
668 *data
<< uint32(m_floatValues
[ index
] < 0 ? 0 : m_floatValues
[ index
]);
670 // there are some float values which may be negative or can't get negative due to other checks
671 else if ((index
>= UNIT_FIELD_NEGSTAT0
&& index
<= UNIT_FIELD_NEGSTAT4
) ||
672 (index
>= UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
&& index
<= (UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+ 6)) ||
673 (index
>= UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
&& index
<= (UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+ 6)) ||
674 (index
>= UNIT_FIELD_POSSTAT0
&& index
<= UNIT_FIELD_POSSTAT4
))
676 *data
<< uint32(m_floatValues
[ index
]);
678 // Gamemasters should be always able to select units - remove not selectable flag
679 else if(index
== UNIT_FIELD_FLAGS
&& target
->isGameMaster())
681 *data
<< (m_uint32Values
[ index
] & ~UNIT_FLAG_NOT_SELECTABLE
);
683 // hide lootable animation for unallowed players
684 else if(index
== UNIT_DYNAMIC_FLAGS
&& GetTypeId() == TYPEID_UNIT
)
686 if(!target
->isAllowedToLoot((Creature
*)this))
687 *data
<< (m_uint32Values
[ index
] & ~UNIT_DYNFLAG_LOOTABLE
);
689 *data
<< (m_uint32Values
[ index
] & ~UNIT_DYNFLAG_OTHER_TAGGER
);
693 // send in current format (float as float, uint32 as uint32)
694 *data
<< m_uint32Values
[ index
];
699 else if(isType(TYPEMASK_GAMEOBJECT
)) // gameobject case
701 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
703 if( updateMask
->GetBit( index
) )
705 // send in current format (float as float, uint32 as uint32)
706 if ( index
== GAMEOBJECT_DYNAMIC
)
708 if(IsActivateToQuest
)
710 switch(((GameObject
*)this)->GetGoType())
712 case GAMEOBJECT_TYPE_CHEST
:
713 // enable quest object. Represent 9, but 1 for client before 2.3.0
717 case GAMEOBJECT_TYPE_GOOBER
:
722 // unknown, not happen.
730 // disable quest object
736 *data
<< m_uint32Values
[ index
]; // other cases
740 else // other objects case (no special index checks)
742 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
744 if( updateMask
->GetBit( index
) )
746 // send in current format (float as float, uint32 as uint32)
747 *data
<< m_uint32Values
[ index
];
753 void Object::ClearUpdateMask(bool remove
)
755 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
757 if(m_uint32Values_mirror
[index
]!= m_uint32Values
[index
])
758 m_uint32Values_mirror
[index
] = m_uint32Values
[index
];
763 ObjectAccessor::Instance().RemoveUpdateObject(this);
764 m_objectUpdated
= false;
768 // Send current value fields changes to all viewers
769 void Object::SendUpdateObjectToAllExcept(Player
* exceptPlayer
)
771 // changes will be send in create packet
779 ObjectAccessor::UpdateObject(this,exceptPlayer
);
782 bool Object::LoadValues(const char* data
)
784 if(!m_uint32Values
) _InitValues();
786 Tokens tokens
= StrSplit(data
, " ");
788 if(tokens
.size() != m_valuesCount
)
791 Tokens::iterator iter
;
793 for (iter
= tokens
.begin(), index
= 0; index
< m_valuesCount
; ++iter
, ++index
)
795 m_uint32Values
[index
] = atol((*iter
).c_str());
801 void Object::_SetUpdateBits(UpdateMask
*updateMask
, Player
* /*target*/) const
803 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
805 if(m_uint32Values_mirror
[index
]!= m_uint32Values
[index
])
806 updateMask
->SetBit(index
);
810 void Object::_SetCreateBits(UpdateMask
*updateMask
, Player
* /*target*/) const
812 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
814 if(GetUInt32Value(index
) != 0)
815 updateMask
->SetBit(index
);
819 void Object::SetInt32Value( uint16 index
, int32 value
)
821 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
823 if(m_int32Values
[ index
] != value
)
825 m_int32Values
[ index
] = value
;
831 ObjectAccessor::Instance().AddUpdateObject(this);
832 m_objectUpdated
= true;
838 void Object::SetUInt32Value( uint16 index
, uint32 value
)
840 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
842 if(m_uint32Values
[ index
] != value
)
844 m_uint32Values
[ index
] = value
;
850 ObjectAccessor::Instance().AddUpdateObject(this);
851 m_objectUpdated
= true;
857 void Object::SetUInt64Value( uint16 index
, const uint64
&value
)
859 ASSERT( index
+ 1 < m_valuesCount
|| PrintIndexError( index
, true ) );
860 if(*((uint64
*)&(m_uint32Values
[ index
])) != value
)
862 m_uint32Values
[ index
] = *((uint32
*)&value
);
863 m_uint32Values
[ index
+ 1 ] = *(((uint32
*)&value
) + 1);
869 ObjectAccessor::Instance().AddUpdateObject(this);
870 m_objectUpdated
= true;
876 void Object::SetFloatValue( uint16 index
, float value
)
878 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
880 if(m_floatValues
[ index
] != value
)
882 m_floatValues
[ index
] = value
;
888 ObjectAccessor::Instance().AddUpdateObject(this);
889 m_objectUpdated
= true;
895 void Object::SetByteValue( uint16 index
, uint8 offset
, uint8 value
)
897 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
901 sLog
.outError("Object::SetByteValue: wrong offset %u", offset
);
905 if(uint8(m_uint32Values
[ index
] >> (offset
* 8)) != value
)
907 m_uint32Values
[ index
] &= ~uint32(uint32(0xFF) << (offset
* 8));
908 m_uint32Values
[ index
] |= uint32(uint32(value
) << (offset
* 8));
914 ObjectAccessor::Instance().AddUpdateObject(this);
915 m_objectUpdated
= true;
921 void Object::SetUInt16Value( uint16 index
, uint8 offset
, uint16 value
)
923 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
927 sLog
.outError("Object::SetUInt16Value: wrong offset %u", offset
);
931 if(uint16(m_uint32Values
[ index
] >> (offset
* 16)) != value
)
933 m_uint32Values
[ index
] &= ~uint32(uint32(0xFFFF) << (offset
* 16));
934 m_uint32Values
[ index
] |= uint32(uint32(value
) << (offset
* 16));
940 ObjectAccessor::Instance().AddUpdateObject(this);
941 m_objectUpdated
= true;
947 void Object::SetStatFloatValue( uint16 index
, float value
)
952 SetFloatValue(index
, value
);
955 void Object::SetStatInt32Value( uint16 index
, int32 value
)
960 SetUInt32Value(index
, uint32(value
));
963 void Object::ApplyModUInt32Value(uint16 index
, int32 val
, bool apply
)
965 int32 cur
= GetUInt32Value(index
);
966 cur
+= (apply
? val
: -val
);
969 SetUInt32Value(index
, cur
);
972 void Object::ApplyModInt32Value(uint16 index
, int32 val
, bool apply
)
974 int32 cur
= GetInt32Value(index
);
975 cur
+= (apply
? val
: -val
);
976 SetInt32Value(index
, cur
);
979 void Object::ApplyModSignedFloatValue(uint16 index
, float val
, bool apply
)
981 float cur
= GetFloatValue(index
);
982 cur
+= (apply
? val
: -val
);
983 SetFloatValue(index
, cur
);
986 void Object::ApplyModPositiveFloatValue(uint16 index
, float val
, bool apply
)
988 float cur
= GetFloatValue(index
);
989 cur
+= (apply
? val
: -val
);
992 SetFloatValue(index
, cur
);
995 void Object::SetFlag( uint16 index
, uint32 newFlag
)
997 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
998 uint32 oldval
= m_uint32Values
[ index
];
999 uint32 newval
= oldval
| newFlag
;
1001 if(oldval
!= newval
)
1003 m_uint32Values
[ index
] = newval
;
1007 if(!m_objectUpdated
)
1009 ObjectAccessor::Instance().AddUpdateObject(this);
1010 m_objectUpdated
= true;
1016 void Object::RemoveFlag( uint16 index
, uint32 oldFlag
)
1018 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
1019 uint32 oldval
= m_uint32Values
[ index
];
1020 uint32 newval
= oldval
& ~oldFlag
;
1022 if(oldval
!= newval
)
1024 m_uint32Values
[ index
] = newval
;
1028 if(!m_objectUpdated
)
1030 ObjectAccessor::Instance().AddUpdateObject(this);
1031 m_objectUpdated
= true;
1037 void Object::SetByteFlag( uint16 index
, uint8 offset
, uint8 newFlag
)
1039 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
1043 sLog
.outError("Object::SetByteFlag: wrong offset %u", offset
);
1047 if(!(uint8(m_uint32Values
[ index
] >> (offset
* 8)) & newFlag
))
1049 m_uint32Values
[ index
] |= uint32(uint32(newFlag
) << (offset
* 8));
1053 if(!m_objectUpdated
)
1055 ObjectAccessor::Instance().AddUpdateObject(this);
1056 m_objectUpdated
= true;
1062 void Object::RemoveByteFlag( uint16 index
, uint8 offset
, uint8 oldFlag
)
1064 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
1068 sLog
.outError("Object::RemoveByteFlag: wrong offset %u", offset
);
1072 if(uint8(m_uint32Values
[ index
] >> (offset
* 8)) & oldFlag
)
1074 m_uint32Values
[ index
] &= ~uint32(uint32(oldFlag
) << (offset
* 8));
1078 if(!m_objectUpdated
)
1080 ObjectAccessor::Instance().AddUpdateObject(this);
1081 m_objectUpdated
= true;
1087 bool Object::PrintIndexError(uint32 index
, bool set
) const
1089 sLog
.outError("Attempt %s non-existed value field: %u (count: %u) for object typeid: %u type mask: %u",(set
? "set value to" : "get value from"),index
,m_valuesCount
,GetTypeId(),m_objectType
);
1091 // assert must fail after function call
1095 WorldObject::WorldObject()
1096 : m_mapId(0), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL
),
1097 m_positionX(0.0f
), m_positionY(0.0f
), m_positionZ(0.0f
), m_orientation(0.0f
), m_currMap(NULL
)
1101 void WorldObject::CleanupsBeforeDelete()
1105 void WorldObject::_Create( uint32 guidlow
, HighGuid guidhigh
, uint32 phaseMask
)
1107 Object::_Create(guidlow
, 0, guidhigh
);
1108 m_phaseMask
= phaseMask
;
1111 uint32
WorldObject::GetZoneId() const
1113 return GetBaseMap()->GetZoneId(m_positionX
, m_positionY
, m_positionZ
);
1116 uint32
WorldObject::GetAreaId() const
1118 return GetBaseMap()->GetAreaId(m_positionX
, m_positionY
, m_positionZ
);
1121 void WorldObject::GetZoneAndAreaId(uint32
& zoneid
, uint32
& areaid
) const
1123 GetBaseMap()->GetZoneAndAreaId(zoneid
, areaid
, m_positionX
, m_positionY
, m_positionZ
);
1126 InstanceData
* WorldObject::GetInstanceData()
1128 Map
*map
= GetMap();
1129 return map
->IsDungeon() ? ((InstanceMap
*)map
)->GetInstanceData() : NULL
;
1133 float WorldObject::GetDistance(const WorldObject
* obj
) const
1135 float dx
= GetPositionX() - obj
->GetPositionX();
1136 float dy
= GetPositionY() - obj
->GetPositionY();
1137 float dz
= GetPositionZ() - obj
->GetPositionZ();
1138 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1139 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - sizefactor
;
1140 return ( dist
> 0 ? dist
: 0);
1143 float WorldObject::GetDistance2d(float x
, float y
) const
1145 float dx
= GetPositionX() - x
;
1146 float dy
= GetPositionY() - y
;
1147 float sizefactor
= GetObjectSize();
1148 float dist
= sqrt((dx
*dx
) + (dy
*dy
)) - sizefactor
;
1149 return ( dist
> 0 ? dist
: 0);
1152 float WorldObject::GetDistance(float x
, float y
, float z
) const
1154 float dx
= GetPositionX() - x
;
1155 float dy
= GetPositionY() - y
;
1156 float dz
= GetPositionZ() - z
;
1157 float sizefactor
= GetObjectSize();
1158 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - sizefactor
;
1159 return ( dist
> 0 ? dist
: 0);
1162 float WorldObject::GetDistance2d(const WorldObject
* obj
) const
1164 float dx
= GetPositionX() - obj
->GetPositionX();
1165 float dy
= GetPositionY() - obj
->GetPositionY();
1166 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1167 float dist
= sqrt((dx
*dx
) + (dy
*dy
)) - sizefactor
;
1168 return ( dist
> 0 ? dist
: 0);
1171 float WorldObject::GetDistanceZ(const WorldObject
* obj
) const
1173 float dz
= fabs(GetPositionZ() - obj
->GetPositionZ());
1174 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1175 float dist
= dz
- sizefactor
;
1176 return ( dist
> 0 ? dist
: 0);
1179 bool WorldObject::IsWithinDist3d(float x
, float y
, float z
, float dist2compare
) const
1181 float dx
= GetPositionX() - x
;
1182 float dy
= GetPositionY() - y
;
1183 float dz
= GetPositionZ() - z
;
1184 float distsq
= dx
*dx
+ dy
*dy
+ dz
*dz
;
1186 float sizefactor
= GetObjectSize();
1187 float maxdist
= dist2compare
+ sizefactor
;
1189 return distsq
< maxdist
* maxdist
;
1192 bool WorldObject::IsWithinDist2d(float x
, float y
, float dist2compare
) const
1194 float dx
= GetPositionX() - x
;
1195 float dy
= GetPositionY() - y
;
1196 float distsq
= dx
*dx
+ dy
*dy
;
1198 float sizefactor
= GetObjectSize();
1199 float maxdist
= dist2compare
+ sizefactor
;
1201 return distsq
< maxdist
* maxdist
;
1204 bool WorldObject::_IsWithinDist(WorldObject
const* obj
, float dist2compare
, bool is3D
) const
1206 float dx
= GetPositionX() - obj
->GetPositionX();
1207 float dy
= GetPositionY() - obj
->GetPositionY();
1208 float distsq
= dx
*dx
+ dy
*dy
;
1211 float dz
= GetPositionZ() - obj
->GetPositionZ();
1214 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1215 float maxdist
= dist2compare
+ sizefactor
;
1217 return distsq
< maxdist
* maxdist
;
1220 bool WorldObject::IsWithinLOSInMap(const WorldObject
* obj
) const
1222 if (!IsInMap(obj
)) return false;
1224 obj
->GetPosition(ox
,oy
,oz
);
1225 return(IsWithinLOS(ox
, oy
, oz
));
1228 bool WorldObject::IsWithinLOS(float ox
, float oy
, float oz
) const
1232 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
1233 return vMapManager
->isInLineOfSight(GetMapId(), x
, y
, z
+2.0f
, ox
, oy
, oz
+2.0f
);
1236 bool WorldObject::GetDistanceOrder(WorldObject
const* obj1
, WorldObject
const* obj2
, bool is3D
/* = true */) const
1238 float dx1
= GetPositionX() - obj1
->GetPositionX();
1239 float dy1
= GetPositionY() - obj1
->GetPositionY();
1240 float distsq1
= dx1
*dx1
+ dy1
*dy1
;
1243 float dz1
= GetPositionZ() - obj1
->GetPositionZ();
1247 float dx2
= GetPositionX() - obj2
->GetPositionX();
1248 float dy2
= GetPositionY() - obj2
->GetPositionY();
1249 float distsq2
= dx2
*dx2
+ dy2
*dy2
;
1252 float dz2
= GetPositionZ() - obj2
->GetPositionZ();
1256 return distsq1
< distsq2
;
1259 bool WorldObject::IsInRange(WorldObject
const* obj
, float minRange
, float maxRange
, bool is3D
/* = true */) const
1261 float dx
= GetPositionX() - obj
->GetPositionX();
1262 float dy
= GetPositionY() - obj
->GetPositionY();
1263 float distsq
= dx
*dx
+ dy
*dy
;
1266 float dz
= GetPositionZ() - obj
->GetPositionZ();
1270 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1272 // check only for real range
1275 float mindist
= minRange
+ sizefactor
;
1276 if(distsq
< mindist
* mindist
)
1280 float maxdist
= maxRange
+ sizefactor
;
1281 return distsq
< maxdist
* maxdist
;
1284 bool WorldObject::IsInRange2d(float x
, float y
, float minRange
, float maxRange
) const
1286 float dx
= GetPositionX() - x
;
1287 float dy
= GetPositionY() - y
;
1288 float distsq
= dx
*dx
+ dy
*dy
;
1290 float sizefactor
= GetObjectSize();
1292 // check only for real range
1295 float mindist
= minRange
+ sizefactor
;
1296 if(distsq
< mindist
* mindist
)
1300 float maxdist
= maxRange
+ sizefactor
;
1301 return distsq
< maxdist
* maxdist
;
1304 bool WorldObject::IsInRange3d(float x
, float y
, float z
, float minRange
, float maxRange
) const
1306 float dx
= GetPositionX() - x
;
1307 float dy
= GetPositionY() - y
;
1308 float dz
= GetPositionZ() - z
;
1309 float distsq
= dx
*dx
+ dy
*dy
+ dz
*dz
;
1311 float sizefactor
= GetObjectSize();
1313 // check only for real range
1316 float mindist
= minRange
+ sizefactor
;
1317 if(distsq
< mindist
* mindist
)
1321 float maxdist
= maxRange
+ sizefactor
;
1322 return distsq
< maxdist
* maxdist
;
1325 float WorldObject::GetAngle(const WorldObject
* obj
) const
1328 return GetAngle( obj
->GetPositionX(), obj
->GetPositionY() );
1331 // Return angle in range 0..2*pi
1332 float WorldObject::GetAngle( const float x
, const float y
) const
1334 float dx
= x
- GetPositionX();
1335 float dy
= y
- GetPositionY();
1337 float ang
= atan2(dy
, dx
);
1338 ang
= (ang
>= 0) ? ang
: 2 * M_PI
+ ang
;
1342 bool WorldObject::HasInArc(const float arcangle
, const WorldObject
* obj
) const
1344 // always have self in arc
1348 float arc
= arcangle
;
1350 // move arc to range 0.. 2*pi
1351 while( arc
>= 2.0f
* M_PI
)
1356 float angle
= GetAngle( obj
);
1357 angle
-= m_orientation
;
1359 // move angle to range -pi ... +pi
1360 while( angle
> M_PI
)
1361 angle
-= 2.0f
* M_PI
;
1362 while(angle
< -M_PI
)
1363 angle
+= 2.0f
* M_PI
;
1365 float lborder
= -1 * (arc
/2.0f
); // in range -pi..0
1366 float rborder
= (arc
/2.0f
); // in range 0..pi
1367 return (( angle
>= lborder
) && ( angle
<= rborder
));
1370 bool WorldObject::isInFrontInMap(WorldObject
const* target
, float distance
, float arc
) const
1372 return IsWithinDistInMap(target
, distance
) && HasInArc( arc
, target
);
1375 bool WorldObject::isInBackInMap(WorldObject
const* target
, float distance
, float arc
) const
1377 return IsWithinDistInMap(target
, distance
) && !HasInArc( 2 * M_PI
- arc
, target
);
1380 void WorldObject::GetRandomPoint( float x
, float y
, float z
, float distance
, float &rand_x
, float &rand_y
, float &rand_z
) const
1390 // angle to face `obj` to `this`
1391 float angle
= rand_norm()*2*M_PI
;
1392 float new_dist
= rand_norm()*distance
;
1394 rand_x
= x
+ new_dist
* cos(angle
);
1395 rand_y
= y
+ new_dist
* sin(angle
);
1398 MaNGOS::NormalizeMapCoord(rand_x
);
1399 MaNGOS::NormalizeMapCoord(rand_y
);
1400 UpdateGroundPositionZ(rand_x
,rand_y
,rand_z
); // update to LOS height if available
1403 void WorldObject::UpdateGroundPositionZ(float x
, float y
, float &z
) const
1405 float new_z
= GetBaseMap()->GetHeight(x
,y
,z
,true);
1406 if(new_z
> INVALID_HEIGHT
)
1407 z
= new_z
+ 0.05f
; // just to be sure that we are not a few pixel under the surface
1410 bool WorldObject::IsPositionValid() const
1412 return MaNGOS::IsValidMapCoord(m_positionX
,m_positionY
,m_positionZ
,m_orientation
);
1415 void WorldObject::MonsterSay(const char* text
, uint32 language
, uint64 TargetGuid
)
1417 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1418 BuildMonsterChat(&data
,CHAT_MSG_MONSTER_SAY
,text
,language
,GetName(),TargetGuid
);
1419 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_SAY
),true);
1422 void WorldObject::MonsterYell(const char* text
, uint32 language
, uint64 TargetGuid
)
1424 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1425 BuildMonsterChat(&data
,CHAT_MSG_MONSTER_YELL
,text
,language
,GetName(),TargetGuid
);
1426 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_YELL
),true);
1429 void WorldObject::MonsterTextEmote(const char* text
, uint64 TargetGuid
, bool IsBossEmote
)
1431 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1432 BuildMonsterChat(&data
,IsBossEmote
? CHAT_MSG_RAID_BOSS_EMOTE
: CHAT_MSG_MONSTER_EMOTE
,text
,LANG_UNIVERSAL
,GetName(),TargetGuid
);
1433 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE
),true);
1436 void WorldObject::MonsterWhisper(const char* text
, uint64 receiver
, bool IsBossWhisper
)
1438 Player
*player
= objmgr
.GetPlayer(receiver
);
1439 if(!player
|| !player
->GetSession())
1442 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1443 BuildMonsterChat(&data
,IsBossWhisper
? CHAT_MSG_RAID_BOSS_WHISPER
: CHAT_MSG_MONSTER_WHISPER
,text
,LANG_UNIVERSAL
,GetName(),receiver
);
1445 player
->GetSession()->SendPacket(&data
);
1450 class MonsterChatBuilder
1453 MonsterChatBuilder(WorldObject
const& obj
, ChatMsg msgtype
, int32 textId
, uint32 language
, uint64 targetGUID
)
1454 : i_object(obj
), i_msgtype(msgtype
), i_textId(textId
), i_language(language
), i_targetGUID(targetGUID
) {}
1455 void operator()(WorldPacket
& data
, int32 loc_idx
)
1457 char const* text
= objmgr
.GetMangosString(i_textId
,loc_idx
);
1459 // TODO: i_object.GetName() also must be localized?
1460 i_object
.BuildMonsterChat(&data
,i_msgtype
,text
,i_language
,i_object
.GetNameForLocaleIdx(loc_idx
),i_targetGUID
);
1464 WorldObject
const& i_object
;
1468 uint64 i_targetGUID
;
1470 } // namespace MaNGOS
1472 void WorldObject::MonsterSay(int32 textId
, uint32 language
, uint64 TargetGuid
)
1474 CellPair p
= MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY());
1477 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1480 MaNGOS::MonsterChatBuilder
say_build(*this, CHAT_MSG_MONSTER_SAY
, textId
,language
,TargetGuid
);
1481 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1482 MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> > say_worker(this,sWorld
.getConfig(CONFIG_LISTEN_RANGE_SAY
),say_do
);
1483 TypeContainerVisitor
<MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> >, WorldTypeMapContainer
> message(say_worker
);
1484 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1485 cell_lock
->Visit(cell_lock
, message
, *GetMap());
1488 void WorldObject::MonsterYell(int32 textId
, uint32 language
, uint64 TargetGuid
)
1490 CellPair p
= MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY());
1493 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1496 MaNGOS::MonsterChatBuilder
say_build(*this, CHAT_MSG_MONSTER_YELL
, textId
,language
,TargetGuid
);
1497 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1498 MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> > say_worker(this,sWorld
.getConfig(CONFIG_LISTEN_RANGE_YELL
),say_do
);
1499 TypeContainerVisitor
<MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> >, WorldTypeMapContainer
> message(say_worker
);
1500 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1501 cell_lock
->Visit(cell_lock
, message
, *GetMap());
1504 void WorldObject::MonsterYellToZone(int32 textId
, uint32 language
, uint64 TargetGuid
)
1506 MaNGOS::MonsterChatBuilder
say_build(*this, CHAT_MSG_MONSTER_YELL
, textId
,language
,TargetGuid
);
1507 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1509 uint32 zoneid
= GetZoneId();
1511 Map::PlayerList
const& pList
= GetMap()->GetPlayers();
1512 for(Map::PlayerList::const_iterator itr
= pList
.begin(); itr
!= pList
.end(); ++itr
)
1513 if(itr
->getSource()->GetZoneId()==zoneid
)
1514 say_do(itr
->getSource());
1517 void WorldObject::MonsterTextEmote(int32 textId
, uint64 TargetGuid
, bool IsBossEmote
)
1519 CellPair p
= MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY());
1522 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1525 MaNGOS::MonsterChatBuilder
say_build(*this, IsBossEmote
? CHAT_MSG_RAID_BOSS_EMOTE
: CHAT_MSG_MONSTER_EMOTE
, textId
,LANG_UNIVERSAL
,TargetGuid
);
1526 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1527 MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> > say_worker(this,sWorld
.getConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE
),say_do
);
1528 TypeContainerVisitor
<MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> >, WorldTypeMapContainer
> message(say_worker
);
1529 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1530 cell_lock
->Visit(cell_lock
, message
, *GetMap());
1533 void WorldObject::MonsterWhisper(int32 textId
, uint64 receiver
, bool IsBossWhisper
)
1535 Player
*player
= objmgr
.GetPlayer(receiver
);
1536 if(!player
|| !player
->GetSession())
1539 uint32 loc_idx
= player
->GetSession()->GetSessionDbLocaleIndex();
1540 char const* text
= objmgr
.GetMangosString(textId
,loc_idx
);
1542 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1543 BuildMonsterChat(&data
,IsBossWhisper
? CHAT_MSG_RAID_BOSS_WHISPER
: CHAT_MSG_MONSTER_WHISPER
,text
,LANG_UNIVERSAL
,GetNameForLocaleIdx(loc_idx
),receiver
);
1545 player
->GetSession()->SendPacket(&data
);
1548 void WorldObject::BuildMonsterChat(WorldPacket
*data
, uint8 msgtype
, char const* text
, uint32 language
, char const* name
, uint64 targetGuid
) const
1550 *data
<< (uint8
)msgtype
;
1551 *data
<< (uint32
)language
;
1552 *data
<< (uint64
)GetGUID();
1553 *data
<< (uint32
)0; // 2.1.0
1554 *data
<< (uint32
)(strlen(name
)+1);
1556 *data
<< (uint64
)targetGuid
; // Unit Target
1557 if( targetGuid
&& !IS_PLAYER_GUID(targetGuid
) )
1559 *data
<< (uint32
)1; // target name length
1560 *data
<< (uint8
)0; // target name
1562 *data
<< (uint32
)(strlen(text
)+1);
1564 *data
<< (uint8
)0; // ChatTag
1567 void WorldObject::SendMessageToSet(WorldPacket
*data
, bool /*bToSelf*/)
1569 //if object is in world, map for it already created!
1570 Map
* _map
= IsInWorld() ? GetMap() : MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
1572 _map
->MessageBroadcast(this, data
);
1575 void WorldObject::SendMessageToSetInRange(WorldPacket
*data
, float dist
, bool /*bToSelf*/)
1577 //if object is in world, map for it already created!
1578 Map
* _map
= IsInWorld() ? GetMap() : MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
1580 _map
->MessageDistBroadcast(this, data
, dist
);
1583 void WorldObject::SendObjectDeSpawnAnim(uint64 guid
)
1585 WorldPacket
data(SMSG_GAMEOBJECT_DESPAWN_ANIM
, 8);
1586 data
<< uint64(guid
);
1587 SendMessageToSet(&data
, true);
1590 void WorldObject::SetMap(Map
* map
)
1594 //lets save current map's Id/instanceId
1595 m_mapId
= map
->GetId();
1596 m_InstanceId
= map
->GetInstanceId();
1599 Map
const* WorldObject::GetBaseMap() const
1602 return m_currMap
->GetParent();
1605 void WorldObject::AddObjectToRemoveList()
1607 GetMap()->AddObjectToRemoveList(this);
1610 Creature
* WorldObject::SummonCreature(uint32 id
, float x
, float y
, float z
, float ang
,TempSummonType spwtype
,uint32 despwtime
)
1612 TemporarySummon
* pCreature
= new TemporarySummon(GetGUID());
1615 if (GetTypeId()==TYPEID_PLAYER
)
1616 team
= ((Player
*)this)->GetTeam();
1618 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), GetMap(), GetPhaseMask(), id
, team
))
1624 if (x
== 0.0f
&& y
== 0.0f
&& z
== 0.0f
)
1625 GetClosePoint(x
, y
, z
, pCreature
->GetObjectSize());
1627 pCreature
->Relocate(x
, y
, z
, ang
);
1629 if(!pCreature
->IsPositionValid())
1631 sLog
.outError("Creature (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature
->GetGUIDLow(),pCreature
->GetEntry(),pCreature
->GetPositionX(),pCreature
->GetPositionY());
1636 pCreature
->Summon(spwtype
, despwtime
);
1638 if(GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->AI())
1639 ((Creature
*)this)->AI()->JustSummoned(pCreature
);
1641 // return the creature therewith the summoner has access to it
1650 NearUsedPosDo(WorldObject
const& obj
, WorldObject
const* searcher
, float angle
, ObjectPosSelector
& selector
)
1651 : i_object(obj
), i_searcher(searcher
), i_angle(angle
), i_selector(selector
) {}
1653 void operator()(Corpse
*) const {}
1654 void operator()(DynamicObject
*) const {}
1656 void operator()(Creature
* c
) const
1658 // skip self or target
1659 if(c
==i_searcher
|| c
==&i_object
)
1664 if( !c
->isAlive() || c
->hasUnitState(UNIT_STAT_ROOT
| UNIT_STAT_STUNNED
| UNIT_STAT_DISTRACTED
) ||
1665 !c
->GetMotionMaster()->GetDestination(x
,y
,z
) )
1667 x
= c
->GetPositionX();
1668 y
= c
->GetPositionY();
1675 void operator()(T
* u
) const
1677 // skip self or target
1678 if(u
==i_searcher
|| u
==&i_object
)
1683 x
= u
->GetPositionX();
1684 y
= u
->GetPositionY();
1689 // we must add used pos that can fill places around center
1690 void add(WorldObject
* u
, float x
, float y
) const
1692 // u is too nearest/far away to i_object
1693 if(!i_object
.IsInRange2d(x
,y
,i_selector
.m_dist
- i_selector
.m_size
,i_selector
.m_dist
+ i_selector
.m_size
))
1696 float angle
= i_object
.GetAngle(u
)-i_angle
;
1698 // move angle to range -pi ... +pi
1699 while( angle
> M_PI
)
1700 angle
-= 2.0f
* M_PI
;
1701 while(angle
< -M_PI
)
1702 angle
+= 2.0f
* M_PI
;
1704 // dist include size of u
1705 float dist2d
= i_object
.GetDistance2d(x
,y
);
1706 i_selector
.AddUsedPos(u
->GetObjectSize(),angle
,dist2d
+ i_object
.GetObjectSize());
1709 WorldObject
const& i_object
;
1710 WorldObject
const* i_searcher
;
1712 ObjectPosSelector
& i_selector
;
1714 } // namespace MaNGOS
1716 //===================================================================================================
1718 void WorldObject::GetNearPoint2D(float &x
, float &y
, float distance2d
, float absAngle
) const
1720 x
= GetPositionX() + (GetObjectSize() + distance2d
) * cos(absAngle
);
1721 y
= GetPositionY() + (GetObjectSize() + distance2d
) * sin(absAngle
);
1723 MaNGOS::NormalizeMapCoord(x
);
1724 MaNGOS::NormalizeMapCoord(y
);
1727 void WorldObject::GetNearPoint(WorldObject
const* searcher
, float &x
, float &y
, float &z
, float searcher_size
, float distance2d
, float absAngle
) const
1729 GetNearPoint2D(x
,y
,distance2d
+searcher_size
,absAngle
);
1732 // if detection disabled, return first point
1733 if(!sWorld
.getConfig(CONFIG_DETECT_POS_COLLISION
))
1735 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1739 // or remember first point
1742 bool first_los_conflict
= false; // first point LOS problems
1744 // prepare selector for work
1745 ObjectPosSelector
selector(GetPositionX(),GetPositionY(),GetObjectSize(),distance2d
+searcher_size
);
1747 // adding used positions around object
1749 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
1751 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1754 MaNGOS::NearUsedPosDo
u_do(*this,searcher
,absAngle
,selector
);
1755 MaNGOS::WorldObjectWorker
<MaNGOS::NearUsedPosDo
> worker(this,u_do
);
1757 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::NearUsedPosDo
>, GridTypeMapContainer
> grid_obj_worker(worker
);
1758 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::NearUsedPosDo
>, WorldTypeMapContainer
> world_obj_worker(worker
);
1760 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1761 cell_lock
->Visit(cell_lock
, grid_obj_worker
, *GetMap());
1762 cell_lock
->Visit(cell_lock
, world_obj_worker
, *GetMap());
1765 // maybe can just place in primary position
1766 if( selector
.CheckOriginal() )
1768 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1770 if(IsWithinLOS(x
,y
,z
))
1773 first_los_conflict
= true; // first point have LOS problems
1776 float angle
; // candidate of angle for free pos
1778 // special case when one from list empty and then empty side preferred
1779 if(selector
.FirstAngle(angle
))
1781 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1783 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1785 if(IsWithinLOS(x
,y
,z
))
1789 // set first used pos in lists
1790 selector
.InitializeAngle();
1792 // select in positions after current nodes (selection one by one)
1793 while(selector
.NextAngle(angle
)) // angle for free pos
1795 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1797 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1799 if(IsWithinLOS(x
,y
,z
))
1803 // BAD NEWS: not free pos (or used or have LOS problems)
1804 // Attempt find _used_ pos without LOS problem
1806 if(!first_los_conflict
)
1811 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1815 // special case when one from list empty and then empty side preferred
1816 if( selector
.IsNonBalanced() )
1818 if(!selector
.FirstAngle(angle
)) // _used_ pos
1820 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1822 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1824 if(IsWithinLOS(x
,y
,z
))
1829 // set first used pos in lists
1830 selector
.InitializeAngle();
1832 // select in positions after current nodes (selection one by one)
1833 while(selector
.NextUsedAngle(angle
)) // angle for used pos but maybe without LOS problem
1835 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1837 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1839 if(IsWithinLOS(x
,y
,z
))
1843 // BAD BAD NEWS: all found pos (free and used) have LOS problem :(
1847 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1850 void WorldObject::SetPhaseMask(uint32 newPhaseMask
, bool update
)
1852 m_phaseMask
= newPhaseMask
;
1854 if(update
&& IsInWorld())
1855 ObjectAccessor::UpdateObjectVisibility(this);
1858 void WorldObject::PlayDistanceSound( uint32 sound_id
, Player
* target
/*= NULL*/ )
1860 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1861 data
<< uint32(sound_id
);
1862 data
<< uint64(GetGUID());
1864 target
->SendDirectMessage( &data
);
1866 SendMessageToSet( &data
, true );
1869 void WorldObject::PlayDirectSound( uint32 sound_id
, Player
* target
/*= NULL*/ )
1871 WorldPacket
data(SMSG_PLAY_SOUND
, 4);
1872 data
<< uint32(sound_id
);
1874 target
->SendDirectMessage( &data
);
1876 SendMessageToSet( &data
, true );