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())
596 IsActivateToQuest
= true;
597 updateMask
->SetBit(GAMEOBJECT_DYNAMIC
);
600 else if (isType(TYPEMASK_UNIT
))
602 if( ((Unit
*)this)->HasAuraState(AURA_STATE_CONFLAGRATE
))
604 IsPerCasterAuraState
= true;
605 updateMask
->SetBit(UNIT_FIELD_AURASTATE
);
609 else // case UPDATETYPE_VALUES
611 if (isType(TYPEMASK_GAMEOBJECT
) && !((GameObject
*)this)->IsTransport())
613 if ( ((GameObject
*)this)->ActivateToQuest(target
) || target
->isGameMaster())
615 IsActivateToQuest
= true;
617 updateMask
->SetBit(GAMEOBJECT_DYNAMIC
);
618 updateMask
->SetBit(GAMEOBJECT_BYTES_1
);
620 else if (isType(TYPEMASK_UNIT
))
622 if( ((Unit
*)this)->HasAuraState(AURA_STATE_CONFLAGRATE
))
624 IsPerCasterAuraState
= true;
625 updateMask
->SetBit(UNIT_FIELD_AURASTATE
);
630 WPAssert(updateMask
&& updateMask
->GetCount() == m_valuesCount
);
632 *data
<< (uint8
)updateMask
->GetBlockCount();
633 data
->append( updateMask
->GetMask(), updateMask
->GetLength() );
635 // 2 specialized loops for speed optimization in non-unit case
636 if(isType(TYPEMASK_UNIT
)) // unit (creature/player) case
638 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
640 if( updateMask
->GetBit( index
) )
642 if( index
== UNIT_NPC_FLAGS
)
644 // remove custom flag before sending
645 uint32 appendValue
= m_uint32Values
[ index
] & ~UNIT_NPC_FLAG_GUARD
;
647 if (GetTypeId() == TYPEID_UNIT
&& !target
->canSeeSpellClickOn((Creature
*)this))
648 appendValue
&= ~UNIT_NPC_FLAG_SPELLCLICK
;
650 *data
<< uint32(appendValue
);
652 else if (index
== UNIT_FIELD_AURASTATE
)
654 if(IsPerCasterAuraState
)
656 // IsPerCasterAuraState set if related pet caster aura state set already
657 if (((Unit
*)this)->HasAuraStateForCaster(AURA_STATE_CONFLAGRATE
,target
->GetGUID()))
658 *data
<< m_uint32Values
[ index
];
660 *data
<< (m_uint32Values
[ index
] & ~(1 << (AURA_STATE_CONFLAGRATE
-1)));
663 *data
<< m_uint32Values
[ index
];
665 // FIXME: Some values at server stored in float format but must be sent to client in uint32 format
666 else if(index
>= UNIT_FIELD_BASEATTACKTIME
&& index
<= UNIT_FIELD_RANGEDATTACKTIME
)
668 // convert from float to uint32 and send
669 *data
<< uint32(m_floatValues
[ index
] < 0 ? 0 : m_floatValues
[ index
]);
671 // there are some float values which may be negative or can't get negative due to other checks
672 else if ((index
>= UNIT_FIELD_NEGSTAT0
&& index
<= UNIT_FIELD_NEGSTAT4
) ||
673 (index
>= UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
&& index
<= (UNIT_FIELD_RESISTANCEBUFFMODSPOSITIVE
+ 6)) ||
674 (index
>= UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
&& index
<= (UNIT_FIELD_RESISTANCEBUFFMODSNEGATIVE
+ 6)) ||
675 (index
>= UNIT_FIELD_POSSTAT0
&& index
<= UNIT_FIELD_POSSTAT4
))
677 *data
<< uint32(m_floatValues
[ index
]);
679 // Gamemasters should be always able to select units - remove not selectable flag
680 else if(index
== UNIT_FIELD_FLAGS
&& target
->isGameMaster())
682 *data
<< (m_uint32Values
[ index
] & ~UNIT_FLAG_NOT_SELECTABLE
);
684 // hide lootable animation for unallowed players
685 else if(index
== UNIT_DYNAMIC_FLAGS
&& GetTypeId() == TYPEID_UNIT
)
687 if(!target
->isAllowedToLoot((Creature
*)this))
688 *data
<< (m_uint32Values
[ index
] & ~UNIT_DYNFLAG_LOOTABLE
);
690 *data
<< (m_uint32Values
[ index
] & ~UNIT_DYNFLAG_OTHER_TAGGER
);
694 // send in current format (float as float, uint32 as uint32)
695 *data
<< m_uint32Values
[ index
];
700 else if(isType(TYPEMASK_GAMEOBJECT
)) // gameobject case
702 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
704 if( updateMask
->GetBit( index
) )
706 // send in current format (float as float, uint32 as uint32)
707 if ( index
== GAMEOBJECT_DYNAMIC
)
709 if(IsActivateToQuest
)
711 switch(((GameObject
*)this)->GetGoType())
713 case GAMEOBJECT_TYPE_CHEST
:
714 *data
<< uint32(9); // enable quest object. Represent 9, but 1 for client before 2.3.0
716 case GAMEOBJECT_TYPE_GOOBER
:
720 *data
<< uint32(0); // unknown, not happen.
725 *data
<< uint32(0); // disable quest object
728 *data
<< m_uint32Values
[ index
]; // other cases
732 else // other objects case (no special index checks)
734 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
736 if( updateMask
->GetBit( index
) )
738 // send in current format (float as float, uint32 as uint32)
739 *data
<< m_uint32Values
[ index
];
745 void Object::ClearUpdateMask(bool remove
)
747 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
749 if(m_uint32Values_mirror
[index
]!= m_uint32Values
[index
])
750 m_uint32Values_mirror
[index
] = m_uint32Values
[index
];
755 ObjectAccessor::Instance().RemoveUpdateObject(this);
756 m_objectUpdated
= false;
760 // Send current value fields changes to all viewers
761 void Object::SendUpdateObjectToAllExcept(Player
* exceptPlayer
)
763 // changes will be send in create packet
771 ObjectAccessor::UpdateObject(this,exceptPlayer
);
774 bool Object::LoadValues(const char* data
)
776 if(!m_uint32Values
) _InitValues();
778 Tokens tokens
= StrSplit(data
, " ");
780 if(tokens
.size() != m_valuesCount
)
783 Tokens::iterator iter
;
785 for (iter
= tokens
.begin(), index
= 0; index
< m_valuesCount
; ++iter
, ++index
)
787 m_uint32Values
[index
] = atol((*iter
).c_str());
793 void Object::_SetUpdateBits(UpdateMask
*updateMask
, Player
* /*target*/) const
795 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
797 if(m_uint32Values_mirror
[index
]!= m_uint32Values
[index
])
798 updateMask
->SetBit(index
);
802 void Object::_SetCreateBits(UpdateMask
*updateMask
, Player
* /*target*/) const
804 for( uint16 index
= 0; index
< m_valuesCount
; ++index
)
806 if(GetUInt32Value(index
) != 0)
807 updateMask
->SetBit(index
);
811 void Object::SetInt32Value( uint16 index
, int32 value
)
813 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
815 if(m_int32Values
[ index
] != value
)
817 m_int32Values
[ index
] = value
;
823 ObjectAccessor::Instance().AddUpdateObject(this);
824 m_objectUpdated
= true;
830 void Object::SetUInt32Value( uint16 index
, uint32 value
)
832 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
834 if(m_uint32Values
[ index
] != value
)
836 m_uint32Values
[ index
] = value
;
842 ObjectAccessor::Instance().AddUpdateObject(this);
843 m_objectUpdated
= true;
849 void Object::SetUInt64Value( uint16 index
, const uint64
&value
)
851 ASSERT( index
+ 1 < m_valuesCount
|| PrintIndexError( index
, true ) );
852 if(*((uint64
*)&(m_uint32Values
[ index
])) != value
)
854 m_uint32Values
[ index
] = *((uint32
*)&value
);
855 m_uint32Values
[ index
+ 1 ] = *(((uint32
*)&value
) + 1);
861 ObjectAccessor::Instance().AddUpdateObject(this);
862 m_objectUpdated
= true;
868 void Object::SetFloatValue( uint16 index
, float value
)
870 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
872 if(m_floatValues
[ index
] != value
)
874 m_floatValues
[ index
] = value
;
880 ObjectAccessor::Instance().AddUpdateObject(this);
881 m_objectUpdated
= true;
887 void Object::SetByteValue( uint16 index
, uint8 offset
, uint8 value
)
889 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
893 sLog
.outError("Object::SetByteValue: wrong offset %u", offset
);
897 if(uint8(m_uint32Values
[ index
] >> (offset
* 8)) != value
)
899 m_uint32Values
[ index
] &= ~uint32(uint32(0xFF) << (offset
* 8));
900 m_uint32Values
[ index
] |= uint32(uint32(value
) << (offset
* 8));
906 ObjectAccessor::Instance().AddUpdateObject(this);
907 m_objectUpdated
= true;
913 void Object::SetUInt16Value( uint16 index
, uint8 offset
, uint16 value
)
915 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
919 sLog
.outError("Object::SetUInt16Value: wrong offset %u", offset
);
923 if(uint16(m_uint32Values
[ index
] >> (offset
* 16)) != value
)
925 m_uint32Values
[ index
] &= ~uint32(uint32(0xFFFF) << (offset
* 16));
926 m_uint32Values
[ index
] |= uint32(uint32(value
) << (offset
* 16));
932 ObjectAccessor::Instance().AddUpdateObject(this);
933 m_objectUpdated
= true;
939 void Object::SetStatFloatValue( uint16 index
, float value
)
944 SetFloatValue(index
, value
);
947 void Object::SetStatInt32Value( uint16 index
, int32 value
)
952 SetUInt32Value(index
, uint32(value
));
955 void Object::ApplyModUInt32Value(uint16 index
, int32 val
, bool apply
)
957 int32 cur
= GetUInt32Value(index
);
958 cur
+= (apply
? val
: -val
);
961 SetUInt32Value(index
, cur
);
964 void Object::ApplyModInt32Value(uint16 index
, int32 val
, bool apply
)
966 int32 cur
= GetInt32Value(index
);
967 cur
+= (apply
? val
: -val
);
968 SetInt32Value(index
, cur
);
971 void Object::ApplyModSignedFloatValue(uint16 index
, float val
, bool apply
)
973 float cur
= GetFloatValue(index
);
974 cur
+= (apply
? val
: -val
);
975 SetFloatValue(index
, cur
);
978 void Object::ApplyModPositiveFloatValue(uint16 index
, float val
, bool apply
)
980 float cur
= GetFloatValue(index
);
981 cur
+= (apply
? val
: -val
);
984 SetFloatValue(index
, cur
);
987 void Object::SetFlag( uint16 index
, uint32 newFlag
)
989 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
990 uint32 oldval
= m_uint32Values
[ index
];
991 uint32 newval
= oldval
| newFlag
;
995 m_uint32Values
[ index
] = newval
;
1001 ObjectAccessor::Instance().AddUpdateObject(this);
1002 m_objectUpdated
= true;
1008 void Object::RemoveFlag( uint16 index
, uint32 oldFlag
)
1010 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
1011 uint32 oldval
= m_uint32Values
[ index
];
1012 uint32 newval
= oldval
& ~oldFlag
;
1014 if(oldval
!= newval
)
1016 m_uint32Values
[ index
] = newval
;
1020 if(!m_objectUpdated
)
1022 ObjectAccessor::Instance().AddUpdateObject(this);
1023 m_objectUpdated
= true;
1029 void Object::SetByteFlag( uint16 index
, uint8 offset
, uint8 newFlag
)
1031 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
1035 sLog
.outError("Object::SetByteFlag: wrong offset %u", offset
);
1039 if(!(uint8(m_uint32Values
[ index
] >> (offset
* 8)) & newFlag
))
1041 m_uint32Values
[ index
] |= uint32(uint32(newFlag
) << (offset
* 8));
1045 if(!m_objectUpdated
)
1047 ObjectAccessor::Instance().AddUpdateObject(this);
1048 m_objectUpdated
= true;
1054 void Object::RemoveByteFlag( uint16 index
, uint8 offset
, uint8 oldFlag
)
1056 ASSERT( index
< m_valuesCount
|| PrintIndexError( index
, true ) );
1060 sLog
.outError("Object::RemoveByteFlag: wrong offset %u", offset
);
1064 if(uint8(m_uint32Values
[ index
] >> (offset
* 8)) & oldFlag
)
1066 m_uint32Values
[ index
] &= ~uint32(uint32(oldFlag
) << (offset
* 8));
1070 if(!m_objectUpdated
)
1072 ObjectAccessor::Instance().AddUpdateObject(this);
1073 m_objectUpdated
= true;
1079 bool Object::PrintIndexError(uint32 index
, bool set
) const
1081 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
);
1083 // assert must fail after function call
1087 WorldObject::WorldObject()
1088 : m_mapId(0), m_InstanceId(0), m_phaseMask(PHASEMASK_NORMAL
),
1089 m_positionX(0.0f
), m_positionY(0.0f
), m_positionZ(0.0f
), m_orientation(0.0f
), m_currMap(NULL
)
1093 void WorldObject::CleanupsBeforeDelete()
1097 void WorldObject::_Create( uint32 guidlow
, HighGuid guidhigh
, uint32 phaseMask
)
1099 Object::_Create(guidlow
, 0, guidhigh
);
1100 m_phaseMask
= phaseMask
;
1103 uint32
WorldObject::GetZoneId() const
1105 return GetBaseMap()->GetZoneId(m_positionX
, m_positionY
, m_positionZ
);
1108 uint32
WorldObject::GetAreaId() const
1110 return GetBaseMap()->GetAreaId(m_positionX
, m_positionY
, m_positionZ
);
1113 void WorldObject::GetZoneAndAreaId(uint32
& zoneid
, uint32
& areaid
) const
1115 GetBaseMap()->GetZoneAndAreaId(zoneid
, areaid
, m_positionX
, m_positionY
, m_positionZ
);
1118 InstanceData
* WorldObject::GetInstanceData()
1120 Map
*map
= GetMap();
1121 return map
->IsDungeon() ? ((InstanceMap
*)map
)->GetInstanceData() : NULL
;
1125 float WorldObject::GetDistance(const WorldObject
* obj
) const
1127 float dx
= GetPositionX() - obj
->GetPositionX();
1128 float dy
= GetPositionY() - obj
->GetPositionY();
1129 float dz
= GetPositionZ() - obj
->GetPositionZ();
1130 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1131 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - sizefactor
;
1132 return ( dist
> 0 ? dist
: 0);
1135 float WorldObject::GetDistance2d(float x
, float y
) const
1137 float dx
= GetPositionX() - x
;
1138 float dy
= GetPositionY() - y
;
1139 float sizefactor
= GetObjectSize();
1140 float dist
= sqrt((dx
*dx
) + (dy
*dy
)) - sizefactor
;
1141 return ( dist
> 0 ? dist
: 0);
1144 float WorldObject::GetDistance(float x
, float y
, float z
) const
1146 float dx
= GetPositionX() - x
;
1147 float dy
= GetPositionY() - y
;
1148 float dz
= GetPositionZ() - z
;
1149 float sizefactor
= GetObjectSize();
1150 float dist
= sqrt((dx
*dx
) + (dy
*dy
) + (dz
*dz
)) - sizefactor
;
1151 return ( dist
> 0 ? dist
: 0);
1154 float WorldObject::GetDistance2d(const WorldObject
* obj
) const
1156 float dx
= GetPositionX() - obj
->GetPositionX();
1157 float dy
= GetPositionY() - obj
->GetPositionY();
1158 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1159 float dist
= sqrt((dx
*dx
) + (dy
*dy
)) - sizefactor
;
1160 return ( dist
> 0 ? dist
: 0);
1163 float WorldObject::GetDistanceZ(const WorldObject
* obj
) const
1165 float dz
= fabs(GetPositionZ() - obj
->GetPositionZ());
1166 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1167 float dist
= dz
- sizefactor
;
1168 return ( dist
> 0 ? dist
: 0);
1171 bool WorldObject::IsWithinDist3d(float x
, float y
, float z
, float dist2compare
) const
1173 float dx
= GetPositionX() - x
;
1174 float dy
= GetPositionY() - y
;
1175 float dz
= GetPositionZ() - z
;
1176 float distsq
= dx
*dx
+ dy
*dy
+ dz
*dz
;
1178 float sizefactor
= GetObjectSize();
1179 float maxdist
= dist2compare
+ sizefactor
;
1181 return distsq
< maxdist
* maxdist
;
1184 bool WorldObject::IsWithinDist2d(float x
, float y
, float dist2compare
) const
1186 float dx
= GetPositionX() - x
;
1187 float dy
= GetPositionY() - y
;
1188 float distsq
= dx
*dx
+ dy
*dy
;
1190 float sizefactor
= GetObjectSize();
1191 float maxdist
= dist2compare
+ sizefactor
;
1193 return distsq
< maxdist
* maxdist
;
1196 bool WorldObject::_IsWithinDist(WorldObject
const* obj
, float dist2compare
, bool is3D
) const
1198 float dx
= GetPositionX() - obj
->GetPositionX();
1199 float dy
= GetPositionY() - obj
->GetPositionY();
1200 float distsq
= dx
*dx
+ dy
*dy
;
1203 float dz
= GetPositionZ() - obj
->GetPositionZ();
1206 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1207 float maxdist
= dist2compare
+ sizefactor
;
1209 return distsq
< maxdist
* maxdist
;
1212 bool WorldObject::IsWithinLOSInMap(const WorldObject
* obj
) const
1214 if (!IsInMap(obj
)) return false;
1216 obj
->GetPosition(ox
,oy
,oz
);
1217 return(IsWithinLOS(ox
, oy
, oz
));
1220 bool WorldObject::IsWithinLOS(float ox
, float oy
, float oz
) const
1224 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
1225 return vMapManager
->isInLineOfSight(GetMapId(), x
, y
, z
+2.0f
, ox
, oy
, oz
+2.0f
);
1228 bool WorldObject::GetDistanceOrder(WorldObject
const* obj1
, WorldObject
const* obj2
, bool is3D
/* = true */) const
1230 float dx1
= GetPositionX() - obj1
->GetPositionX();
1231 float dy1
= GetPositionY() - obj1
->GetPositionY();
1232 float distsq1
= dx1
*dx1
+ dy1
*dy1
;
1235 float dz1
= GetPositionZ() - obj1
->GetPositionZ();
1239 float dx2
= GetPositionX() - obj2
->GetPositionX();
1240 float dy2
= GetPositionY() - obj2
->GetPositionY();
1241 float distsq2
= dx2
*dx2
+ dy2
*dy2
;
1244 float dz2
= GetPositionZ() - obj2
->GetPositionZ();
1248 return distsq1
< distsq2
;
1251 bool WorldObject::IsInRange(WorldObject
const* obj
, float minRange
, float maxRange
, bool is3D
/* = true */) const
1253 float dx
= GetPositionX() - obj
->GetPositionX();
1254 float dy
= GetPositionY() - obj
->GetPositionY();
1255 float distsq
= dx
*dx
+ dy
*dy
;
1258 float dz
= GetPositionZ() - obj
->GetPositionZ();
1262 float sizefactor
= GetObjectSize() + obj
->GetObjectSize();
1264 // check only for real range
1267 float mindist
= minRange
+ sizefactor
;
1268 if(distsq
< mindist
* mindist
)
1272 float maxdist
= maxRange
+ sizefactor
;
1273 return distsq
< maxdist
* maxdist
;
1276 bool WorldObject::IsInRange2d(float x
, float y
, float minRange
, float maxRange
) const
1278 float dx
= GetPositionX() - x
;
1279 float dy
= GetPositionY() - y
;
1280 float distsq
= dx
*dx
+ dy
*dy
;
1282 float sizefactor
= GetObjectSize();
1284 // check only for real range
1287 float mindist
= minRange
+ sizefactor
;
1288 if(distsq
< mindist
* mindist
)
1292 float maxdist
= maxRange
+ sizefactor
;
1293 return distsq
< maxdist
* maxdist
;
1296 bool WorldObject::IsInRange3d(float x
, float y
, float z
, float minRange
, float maxRange
) const
1298 float dx
= GetPositionX() - x
;
1299 float dy
= GetPositionY() - y
;
1300 float dz
= GetPositionZ() - z
;
1301 float distsq
= dx
*dx
+ dy
*dy
+ dz
*dz
;
1303 float sizefactor
= GetObjectSize();
1305 // check only for real range
1308 float mindist
= minRange
+ sizefactor
;
1309 if(distsq
< mindist
* mindist
)
1313 float maxdist
= maxRange
+ sizefactor
;
1314 return distsq
< maxdist
* maxdist
;
1317 float WorldObject::GetAngle(const WorldObject
* obj
) const
1320 return GetAngle( obj
->GetPositionX(), obj
->GetPositionY() );
1323 // Return angle in range 0..2*pi
1324 float WorldObject::GetAngle( const float x
, const float y
) const
1326 float dx
= x
- GetPositionX();
1327 float dy
= y
- GetPositionY();
1329 float ang
= atan2(dy
, dx
);
1330 ang
= (ang
>= 0) ? ang
: 2 * M_PI
+ ang
;
1334 bool WorldObject::HasInArc(const float arcangle
, const WorldObject
* obj
) const
1336 // always have self in arc
1340 float arc
= arcangle
;
1342 // move arc to range 0.. 2*pi
1343 while( arc
>= 2.0f
* M_PI
)
1348 float angle
= GetAngle( obj
);
1349 angle
-= m_orientation
;
1351 // move angle to range -pi ... +pi
1352 while( angle
> M_PI
)
1353 angle
-= 2.0f
* M_PI
;
1354 while(angle
< -M_PI
)
1355 angle
+= 2.0f
* M_PI
;
1357 float lborder
= -1 * (arc
/2.0f
); // in range -pi..0
1358 float rborder
= (arc
/2.0f
); // in range 0..pi
1359 return (( angle
>= lborder
) && ( angle
<= rborder
));
1362 bool WorldObject::isInFrontInMap(WorldObject
const* target
, float distance
, float arc
) const
1364 return IsWithinDistInMap(target
, distance
) && HasInArc( arc
, target
);
1367 bool WorldObject::isInBackInMap(WorldObject
const* target
, float distance
, float arc
) const
1369 return IsWithinDistInMap(target
, distance
) && !HasInArc( 2 * M_PI
- arc
, target
);
1372 void WorldObject::GetRandomPoint( float x
, float y
, float z
, float distance
, float &rand_x
, float &rand_y
, float &rand_z
) const
1382 // angle to face `obj` to `this`
1383 float angle
= rand_norm()*2*M_PI
;
1384 float new_dist
= rand_norm()*distance
;
1386 rand_x
= x
+ new_dist
* cos(angle
);
1387 rand_y
= y
+ new_dist
* sin(angle
);
1390 MaNGOS::NormalizeMapCoord(rand_x
);
1391 MaNGOS::NormalizeMapCoord(rand_y
);
1392 UpdateGroundPositionZ(rand_x
,rand_y
,rand_z
); // update to LOS height if available
1395 void WorldObject::UpdateGroundPositionZ(float x
, float y
, float &z
) const
1397 float new_z
= GetBaseMap()->GetHeight(x
,y
,z
,true);
1398 if(new_z
> INVALID_HEIGHT
)
1399 z
= new_z
+ 0.05f
; // just to be sure that we are not a few pixel under the surface
1402 bool WorldObject::IsPositionValid() const
1404 return MaNGOS::IsValidMapCoord(m_positionX
,m_positionY
,m_positionZ
,m_orientation
);
1407 void WorldObject::MonsterSay(const char* text
, uint32 language
, uint64 TargetGuid
)
1409 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1410 BuildMonsterChat(&data
,CHAT_MSG_MONSTER_SAY
,text
,language
,GetName(),TargetGuid
);
1411 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_SAY
),true);
1414 void WorldObject::MonsterYell(const char* text
, uint32 language
, uint64 TargetGuid
)
1416 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1417 BuildMonsterChat(&data
,CHAT_MSG_MONSTER_YELL
,text
,language
,GetName(),TargetGuid
);
1418 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_YELL
),true);
1421 void WorldObject::MonsterTextEmote(const char* text
, uint64 TargetGuid
, bool IsBossEmote
)
1423 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1424 BuildMonsterChat(&data
,IsBossEmote
? CHAT_MSG_RAID_BOSS_EMOTE
: CHAT_MSG_MONSTER_EMOTE
,text
,LANG_UNIVERSAL
,GetName(),TargetGuid
);
1425 SendMessageToSetInRange(&data
,sWorld
.getConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE
),true);
1428 void WorldObject::MonsterWhisper(const char* text
, uint64 receiver
, bool IsBossWhisper
)
1430 Player
*player
= objmgr
.GetPlayer(receiver
);
1431 if(!player
|| !player
->GetSession())
1434 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1435 BuildMonsterChat(&data
,IsBossWhisper
? CHAT_MSG_RAID_BOSS_WHISPER
: CHAT_MSG_MONSTER_WHISPER
,text
,LANG_UNIVERSAL
,GetName(),receiver
);
1437 player
->GetSession()->SendPacket(&data
);
1442 class MonsterChatBuilder
1445 MonsterChatBuilder(WorldObject
const& obj
, ChatMsg msgtype
, int32 textId
, uint32 language
, uint64 targetGUID
)
1446 : i_object(obj
), i_msgtype(msgtype
), i_textId(textId
), i_language(language
), i_targetGUID(targetGUID
) {}
1447 void operator()(WorldPacket
& data
, int32 loc_idx
)
1449 char const* text
= objmgr
.GetMangosString(i_textId
,loc_idx
);
1451 // TODO: i_object.GetName() also must be localized?
1452 i_object
.BuildMonsterChat(&data
,i_msgtype
,text
,i_language
,i_object
.GetNameForLocaleIdx(loc_idx
),i_targetGUID
);
1456 WorldObject
const& i_object
;
1460 uint64 i_targetGUID
;
1462 } // namespace MaNGOS
1464 void WorldObject::MonsterSay(int32 textId
, uint32 language
, uint64 TargetGuid
)
1466 CellPair p
= MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY());
1469 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1472 MaNGOS::MonsterChatBuilder
say_build(*this, CHAT_MSG_MONSTER_SAY
, textId
,language
,TargetGuid
);
1473 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1474 MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> > say_worker(this,sWorld
.getConfig(CONFIG_LISTEN_RANGE_SAY
),say_do
);
1475 TypeContainerVisitor
<MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> >, WorldTypeMapContainer
> message(say_worker
);
1476 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1477 cell_lock
->Visit(cell_lock
, message
, *GetMap());
1480 void WorldObject::MonsterYell(int32 textId
, uint32 language
, uint64 TargetGuid
)
1482 CellPair p
= MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY());
1485 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1488 MaNGOS::MonsterChatBuilder
say_build(*this, CHAT_MSG_MONSTER_YELL
, textId
,language
,TargetGuid
);
1489 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1490 MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> > say_worker(this,sWorld
.getConfig(CONFIG_LISTEN_RANGE_YELL
),say_do
);
1491 TypeContainerVisitor
<MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> >, WorldTypeMapContainer
> message(say_worker
);
1492 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1493 cell_lock
->Visit(cell_lock
, message
, *GetMap());
1496 void WorldObject::MonsterYellToZone(int32 textId
, uint32 language
, uint64 TargetGuid
)
1498 MaNGOS::MonsterChatBuilder
say_build(*this, CHAT_MSG_MONSTER_YELL
, textId
,language
,TargetGuid
);
1499 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1501 uint32 zoneid
= GetZoneId();
1503 Map::PlayerList
const& pList
= GetMap()->GetPlayers();
1504 for(Map::PlayerList::const_iterator itr
= pList
.begin(); itr
!= pList
.end(); ++itr
)
1505 if(itr
->getSource()->GetZoneId()==zoneid
)
1506 say_do(itr
->getSource());
1509 void WorldObject::MonsterTextEmote(int32 textId
, uint64 TargetGuid
, bool IsBossEmote
)
1511 CellPair p
= MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY());
1514 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1517 MaNGOS::MonsterChatBuilder
say_build(*this, IsBossEmote
? CHAT_MSG_RAID_BOSS_EMOTE
: CHAT_MSG_MONSTER_EMOTE
, textId
,LANG_UNIVERSAL
,TargetGuid
);
1518 MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> say_do(say_build
);
1519 MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> > say_worker(this,sWorld
.getConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE
),say_do
);
1520 TypeContainerVisitor
<MaNGOS::PlayerDistWorker
<MaNGOS::LocalizedPacketDo
<MaNGOS::MonsterChatBuilder
> >, WorldTypeMapContainer
> message(say_worker
);
1521 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1522 cell_lock
->Visit(cell_lock
, message
, *GetMap());
1525 void WorldObject::MonsterWhisper(int32 textId
, uint64 receiver
, bool IsBossWhisper
)
1527 Player
*player
= objmgr
.GetPlayer(receiver
);
1528 if(!player
|| !player
->GetSession())
1531 uint32 loc_idx
= player
->GetSession()->GetSessionDbLocaleIndex();
1532 char const* text
= objmgr
.GetMangosString(textId
,loc_idx
);
1534 WorldPacket
data(SMSG_MESSAGECHAT
, 200);
1535 BuildMonsterChat(&data
,IsBossWhisper
? CHAT_MSG_RAID_BOSS_WHISPER
: CHAT_MSG_MONSTER_WHISPER
,text
,LANG_UNIVERSAL
,GetNameForLocaleIdx(loc_idx
),receiver
);
1537 player
->GetSession()->SendPacket(&data
);
1540 void WorldObject::BuildMonsterChat(WorldPacket
*data
, uint8 msgtype
, char const* text
, uint32 language
, char const* name
, uint64 targetGuid
) const
1542 *data
<< (uint8
)msgtype
;
1543 *data
<< (uint32
)language
;
1544 *data
<< (uint64
)GetGUID();
1545 *data
<< (uint32
)0; // 2.1.0
1546 *data
<< (uint32
)(strlen(name
)+1);
1548 *data
<< (uint64
)targetGuid
; // Unit Target
1549 if( targetGuid
&& !IS_PLAYER_GUID(targetGuid
) )
1551 *data
<< (uint32
)1; // target name length
1552 *data
<< (uint8
)0; // target name
1554 *data
<< (uint32
)(strlen(text
)+1);
1556 *data
<< (uint8
)0; // ChatTag
1559 void WorldObject::SendMessageToSet(WorldPacket
*data
, bool /*bToSelf*/)
1561 //if object is in world, map for it already created!
1562 Map
* _map
= IsInWorld() ? GetMap() : MapManager::Instance().FindMap(GetMapId(), GetInstanceId());
1564 _map
->MessageBroadcast(this, data
);
1567 void WorldObject::SendMessageToSetInRange(WorldPacket
*data
, float dist
, 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
->MessageDistBroadcast(this, data
, dist
);
1575 void WorldObject::SendObjectDeSpawnAnim(uint64 guid
)
1577 WorldPacket
data(SMSG_GAMEOBJECT_DESPAWN_ANIM
, 8);
1578 data
<< uint64(guid
);
1579 SendMessageToSet(&data
, true);
1582 void WorldObject::SetMap(Map
* map
)
1586 //lets save current map's Id/instanceId
1587 m_mapId
= map
->GetId();
1588 m_InstanceId
= map
->GetInstanceId();
1591 Map
const* WorldObject::GetBaseMap() const
1594 return m_currMap
->GetParent();
1597 void WorldObject::AddObjectToRemoveList()
1599 GetMap()->AddObjectToRemoveList(this);
1602 Creature
* WorldObject::SummonCreature(uint32 id
, float x
, float y
, float z
, float ang
,TempSummonType spwtype
,uint32 despwtime
)
1604 TemporarySummon
* pCreature
= new TemporarySummon(GetGUID());
1607 if (GetTypeId()==TYPEID_PLAYER
)
1608 team
= ((Player
*)this)->GetTeam();
1610 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), GetMap(), GetPhaseMask(), id
, team
))
1616 if (x
== 0.0f
&& y
== 0.0f
&& z
== 0.0f
)
1617 GetClosePoint(x
, y
, z
, pCreature
->GetObjectSize());
1619 pCreature
->Relocate(x
, y
, z
, ang
);
1621 if(!pCreature
->IsPositionValid())
1623 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());
1628 pCreature
->Summon(spwtype
, despwtime
);
1630 if(GetTypeId()==TYPEID_UNIT
&& ((Creature
*)this)->AI())
1631 ((Creature
*)this)->AI()->JustSummoned(pCreature
);
1633 // return the creature therewith the summoner has access to it
1642 NearUsedPosDo(WorldObject
const& obj
, WorldObject
const* searcher
, float angle
, ObjectPosSelector
& selector
)
1643 : i_object(obj
), i_searcher(searcher
), i_angle(angle
), i_selector(selector
) {}
1645 void operator()(Corpse
*) const {}
1646 void operator()(DynamicObject
*) const {}
1648 void operator()(Creature
* c
) const
1650 // skip self or target
1651 if(c
==i_searcher
|| c
==&i_object
)
1656 if( !c
->isAlive() || c
->hasUnitState(UNIT_STAT_ROOT
| UNIT_STAT_STUNNED
| UNIT_STAT_DISTRACTED
) ||
1657 !c
->GetMotionMaster()->GetDestination(x
,y
,z
) )
1659 x
= c
->GetPositionX();
1660 y
= c
->GetPositionY();
1667 void operator()(T
* u
) const
1669 // skip self or target
1670 if(u
==i_searcher
|| u
==&i_object
)
1675 x
= u
->GetPositionX();
1676 y
= u
->GetPositionY();
1681 // we must add used pos that can fill places around center
1682 void add(WorldObject
* u
, float x
, float y
) const
1684 // u is too nearest/far away to i_object
1685 if(!i_object
.IsInRange2d(x
,y
,i_selector
.m_dist
- i_selector
.m_size
,i_selector
.m_dist
+ i_selector
.m_size
))
1688 float angle
= i_object
.GetAngle(u
)-i_angle
;
1690 // move angle to range -pi ... +pi
1691 while( angle
> M_PI
)
1692 angle
-= 2.0f
* M_PI
;
1693 while(angle
< -M_PI
)
1694 angle
+= 2.0f
* M_PI
;
1696 // dist include size of u
1697 float dist2d
= i_object
.GetDistance2d(x
,y
);
1698 i_selector
.AddUsedPos(u
->GetObjectSize(),angle
,dist2d
+ i_object
.GetObjectSize());
1701 WorldObject
const& i_object
;
1702 WorldObject
const* i_searcher
;
1704 ObjectPosSelector
& i_selector
;
1706 } // namespace MaNGOS
1708 //===================================================================================================
1710 void WorldObject::GetNearPoint2D(float &x
, float &y
, float distance2d
, float absAngle
) const
1712 x
= GetPositionX() + (GetObjectSize() + distance2d
) * cos(absAngle
);
1713 y
= GetPositionY() + (GetObjectSize() + distance2d
) * sin(absAngle
);
1715 MaNGOS::NormalizeMapCoord(x
);
1716 MaNGOS::NormalizeMapCoord(y
);
1719 void WorldObject::GetNearPoint(WorldObject
const* searcher
, float &x
, float &y
, float &z
, float searcher_size
, float distance2d
, float absAngle
) const
1721 GetNearPoint2D(x
,y
,distance2d
+searcher_size
,absAngle
);
1724 // if detection disabled, return first point
1725 if(!sWorld
.getConfig(CONFIG_DETECT_POS_COLLISION
))
1727 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1731 // or remember first point
1734 bool first_los_conflict
= false; // first point LOS problems
1736 // prepare selector for work
1737 ObjectPosSelector
selector(GetPositionX(),GetPositionY(),GetObjectSize(),distance2d
+searcher_size
);
1739 // adding used positions around object
1741 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
1743 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1746 MaNGOS::NearUsedPosDo
u_do(*this,searcher
,absAngle
,selector
);
1747 MaNGOS::WorldObjectWorker
<MaNGOS::NearUsedPosDo
> worker(this,u_do
);
1749 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::NearUsedPosDo
>, GridTypeMapContainer
> grid_obj_worker(worker
);
1750 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::NearUsedPosDo
>, WorldTypeMapContainer
> world_obj_worker(worker
);
1752 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1753 cell_lock
->Visit(cell_lock
, grid_obj_worker
, *GetMap());
1754 cell_lock
->Visit(cell_lock
, world_obj_worker
, *GetMap());
1757 // maybe can just place in primary position
1758 if( selector
.CheckOriginal() )
1760 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1762 if(IsWithinLOS(x
,y
,z
))
1765 first_los_conflict
= true; // first point have LOS problems
1768 float angle
; // candidate of angle for free pos
1770 // special case when one from list empty and then empty side preferred
1771 if(selector
.FirstAngle(angle
))
1773 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1775 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1777 if(IsWithinLOS(x
,y
,z
))
1781 // set first used pos in lists
1782 selector
.InitializeAngle();
1784 // select in positions after current nodes (selection one by one)
1785 while(selector
.NextAngle(angle
)) // angle for free pos
1787 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1789 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1791 if(IsWithinLOS(x
,y
,z
))
1795 // BAD NEWS: not free pos (or used or have LOS problems)
1796 // Attempt find _used_ pos without LOS problem
1798 if(!first_los_conflict
)
1803 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1807 // special case when one from list empty and then empty side preferred
1808 if( selector
.IsNonBalanced() )
1810 if(!selector
.FirstAngle(angle
)) // _used_ pos
1812 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1814 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1816 if(IsWithinLOS(x
,y
,z
))
1821 // set first used pos in lists
1822 selector
.InitializeAngle();
1824 // select in positions after current nodes (selection one by one)
1825 while(selector
.NextUsedAngle(angle
)) // angle for used pos but maybe without LOS problem
1827 GetNearPoint2D(x
,y
,distance2d
,absAngle
+angle
);
1829 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1831 if(IsWithinLOS(x
,y
,z
))
1835 // BAD BAD NEWS: all found pos (free and used) have LOS problem :(
1839 UpdateGroundPositionZ(x
,y
,z
); // update to LOS height if available
1842 void WorldObject::SetPhaseMask(uint32 newPhaseMask
, bool update
)
1844 m_phaseMask
= newPhaseMask
;
1846 if(update
&& IsInWorld())
1847 ObjectAccessor::UpdateObjectVisibility(this);
1850 void WorldObject::PlayDistanceSound( uint32 sound_id
, Player
* target
/*= NULL*/ )
1852 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1853 data
<< uint32(sound_id
);
1854 data
<< uint64(GetGUID());
1856 target
->SendDirectMessage( &data
);
1858 SendMessageToSet( &data
, true );
1861 void WorldObject::PlayDirectSound( uint32 sound_id
, Player
* target
/*= NULL*/ )
1863 WorldPacket
data(SMSG_PLAY_SOUND
, 4);
1864 data
<< uint32(sound_id
);
1866 target
->SendDirectMessage( &data
);
1868 SendMessageToSet( &data
, true );