2 * Copyright (C) 2005-2010 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
21 #include "GameObject.h"
22 #include "ObjectMgr.h"
23 #include "PoolManager.h"
26 #include "UpdateMask.h"
28 #include "WorldPacket.h"
30 #include "Database/DatabaseEnv.h"
32 #include "GridNotifiers.h"
33 #include "GridNotifiersImpl.h"
35 #include "InstanceData.h"
36 #include "BattleGround.h"
37 #include "BattleGroundAV.h"
39 #include "ScriptCalls.h"
41 GameObject::GameObject() : WorldObject()
43 m_objectType
|= TYPEMASK_GAMEOBJECT
;
44 m_objectTypeId
= TYPEID_GAMEOBJECT
;
46 m_updateFlag
= (UPDATEFLAG_HIGHGUID
| UPDATEFLAG_HAS_POSITION
| UPDATEFLAG_POSITION
| UPDATEFLAG_ROTATION
);
48 m_valuesCount
= GAMEOBJECT_END
;
50 m_respawnDelayTime
= 25;
51 m_lootState
= GO_NOT_READY
;
52 m_spawnedByDefault
= true;
62 GameObject::~GameObject()
66 void GameObject::AddToWorld()
68 ///- Register the gameobject for guid lookup
70 GetMap()->GetObjectsStore().insert
<GameObject
>(GetGUID(), (GameObject
*)this);
75 void GameObject::RemoveFromWorld()
77 ///- Remove the gameobject from the accessor
80 // Remove GO from owner
81 if(uint64 owner_guid
= GetOwnerGUID())
83 if (Unit
* owner
= ObjectAccessor::GetUnit(*this,owner_guid
))
84 owner
->RemoveGameObject(this,false);
87 const char * ownerType
= "creature";
88 if(IS_PLAYER_GUID(owner_guid
))
90 else if(IS_PET_GUID(owner_guid
))
93 sLog
.outError("Delete GameObject (GUID: %u Entry: %u SpellId %u LinkedGO %u) that lost references to owner (GUID %u Type '%s') GO list. Crash possible later.",
94 GetGUIDLow(), GetGOInfo()->id
, m_spellId
, GetGOInfo()->GetLinkedGameObjectEntry(), GUID_LOPART(owner_guid
), ownerType
);
98 GetMap()->GetObjectsStore().erase
<GameObject
>(GetGUID(), (GameObject
*)NULL
);
101 Object::RemoveFromWorld();
104 bool GameObject::Create(uint32 guidlow
, uint32 name_id
, Map
*map
, uint32 phaseMask
, float x
, float y
, float z
, float ang
, float rotation0
, float rotation1
, float rotation2
, float rotation3
, uint32 animprogress
, GOState go_state
)
109 SetPhaseMask(phaseMask
,false);
111 if(!IsPositionValid())
113 sLog
.outError("Gameobject (GUID: %u Entry: %u ) not created. Suggested coordinates isn't valid (X: %f Y: %f)",guidlow
,name_id
,x
,y
);
117 GameObjectInfo
const* goinfo
= ObjectMgr::GetGameObjectInfo(name_id
);
120 sLog
.outErrorDb("Gameobject (GUID: %u Entry: %u) not created: it have not exist entry in `gameobject_template`. Map: %u (X: %f Y: %f Z: %f) ang: %f rotation0: %f rotation1: %f rotation2: %f rotation3: %f",guidlow
, name_id
, map
->GetId(), x
, y
, z
, ang
, rotation0
, rotation1
, rotation2
, rotation3
);
124 Object::_Create(guidlow
, goinfo
->id
, HIGHGUID_GAMEOBJECT
);
128 if (goinfo
->type
>= MAX_GAMEOBJECT_TYPE
)
130 sLog
.outErrorDb("Gameobject (GUID: %u Entry: %u) not created: it have not exist GO type '%u' in `gameobject_template`. It's will crash client if created.",guidlow
,name_id
,goinfo
->type
);
134 SetFloatValue(GAMEOBJECT_PARENTROTATION
+0, rotation0
);
135 SetFloatValue(GAMEOBJECT_PARENTROTATION
+1, rotation1
);
137 UpdateRotationFields(rotation2
,rotation3
); // GAMEOBJECT_FACING, GAMEOBJECT_ROTATION, GAMEOBJECT_PARENTROTATION+2/3
139 SetFloatValue(OBJECT_FIELD_SCALE_X
, goinfo
->size
);
141 SetUInt32Value(GAMEOBJECT_FACTION
, goinfo
->faction
);
142 SetUInt32Value(GAMEOBJECT_FLAGS
, goinfo
->flags
);
144 SetEntry(goinfo
->id
);
146 SetUInt32Value(GAMEOBJECT_DISPLAYID
, goinfo
->displayId
);
148 // GAMEOBJECT_BYTES_1, index at 0, 1, 2 and 3
149 SetGoState(go_state
);
150 SetGoType(GameobjectTypes(goinfo
->type
));
151 SetGoArtKit(0); // unknown what this is
152 SetGoAnimProgress(animprogress
);
154 //Notify the map's instance data.
155 //Only works if you create the object in it, not if it is moves to that map.
156 //Normally non-players do not teleport to other maps.
157 if(map
->IsDungeon() && ((InstanceMap
*)map
)->GetInstanceData())
159 ((InstanceMap
*)map
)->GetInstanceData()->OnObjectCreate(this);
165 void GameObject::Update(uint32
/*p_time*/)
167 if (IS_MO_TRANSPORT(GetGUID()))
169 //((Transport*)this)->Update(p_time);
179 case GAMEOBJECT_TYPE_TRAP
:
181 // Arming Time for GAMEOBJECT_TYPE_TRAP (6)
182 Unit
* owner
= GetOwner();
183 if (owner
&& ((Player
*)owner
)->isInCombat())
184 m_cooldownTime
= time(NULL
) + GetGOInfo()->trap
.startDelay
;
185 m_lootState
= GO_READY
;
188 case GAMEOBJECT_TYPE_FISHINGNODE
:
190 // fishing code (bobber ready)
191 if( time(NULL
) > m_respawnTime
- FISHING_BOBBER_READY_TIME
)
193 // splash bobber (bobber ready now)
194 Unit
* caster
= GetOwner();
195 if(caster
&& caster
->GetTypeId()==TYPEID_PLAYER
)
197 SetGoState(GO_STATE_ACTIVE
);
198 SetUInt32Value(GAMEOBJECT_FLAGS
, GO_FLAG_NODESPAWN
);
202 BuildValuesUpdateBlockForPlayer(&udata
,((Player
*)caster
));
203 udata
.BuildPacket(&packet
);
204 ((Player
*)caster
)->GetSession()->SendPacket(&packet
);
206 SendGameObjectCustomAnim(GetGUID());
209 m_lootState
= GO_READY
; // can be successfully open with some chance
214 m_lootState
= GO_READY
; // for other GOis same switched without delay to GO_READY
217 // NO BREAK for switch (m_lootState)
221 if (m_respawnTime
> 0) // timer on
223 if (m_respawnTime
<= time(NULL
)) // timer expired
226 m_SkillupList
.clear();
231 case GAMEOBJECT_TYPE_FISHINGNODE
: // can't fish now
233 Unit
* caster
= GetOwner();
234 if(caster
&& caster
->GetTypeId()==TYPEID_PLAYER
)
236 caster
->FinishSpell(CURRENT_CHANNELED_SPELL
);
238 WorldPacket
data(SMSG_FISH_NOT_HOOKED
,0);
239 ((Player
*)caster
)->GetSession()->SendPacket(&data
);
242 m_lootState
= GO_JUST_DEACTIVATED
;
245 case GAMEOBJECT_TYPE_DOOR
:
246 case GAMEOBJECT_TYPE_BUTTON
:
247 //we need to open doors if they are closed (add there another condition if this code breaks some usage, but it need to be here for battlegrounds)
248 if (GetGoState() != GO_STATE_READY
)
250 //flags in AB are type_button and we need to add them here so no break!
252 if (!m_spawnedByDefault
) // despawn timer
254 // can be despawned or destroyed
255 SetLootState(GO_JUST_DEACTIVATED
);
267 // traps can have time and can not have
268 GameObjectInfo
const* goInfo
= GetGOInfo();
269 if(goInfo
->type
== GAMEOBJECT_TYPE_TRAP
)
271 if(m_cooldownTime
>= time(NULL
))
275 Unit
* owner
= GetOwner();
276 Unit
* ok
= NULL
; // pointer to appropriate target if found any
278 bool IsBattleGroundTrap
= false;
279 //FIXME: this is activation radius (in different casting radius that must be selected from spell data)
280 //TODO: move activated state code (cast itself) to GO_ACTIVATED, in this place only check activating and set state
281 float radius
= float(goInfo
->trap
.radius
);
284 if(goInfo
->trap
.cooldown
!= 3) // cast in other case (at some triggering/linked go/etc explicit call)
288 if(m_respawnTime
> 0)
291 // battlegrounds gameobjects has data2 == 0 && data5 == 3
292 radius
= float(goInfo
->trap
.cooldown
);
293 IsBattleGroundTrap
= true;
297 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
299 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
301 // Note: this hack with search required until GO casting not implemented
302 // search unfriendly creature
303 if(owner
&& goInfo
->trap
.charges
> 0) // hunter trap
305 MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
u_check(this, owner
, radius
);
306 MaNGOS::UnitSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
> checker(this,ok
, u_check
);
308 TypeContainerVisitor
<MaNGOS::UnitSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_object_checker(checker
);
309 cell
.Visit(p
, grid_object_checker
, *GetMap(), *this, radius
);
311 // or unfriendly player/pet
314 TypeContainerVisitor
<MaNGOS::UnitSearcher
<MaNGOS::AnyUnfriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_object_checker(checker
);
315 cell
.Visit(p
, world_object_checker
, *GetMap(), *this, radius
);
318 else // environmental trap
320 // environmental damage spells already have around enemies targeting but this not help in case not existed GO casting support
322 // affect only players
324 MaNGOS::AnyPlayerInObjectRangeCheck
p_check(this, radius
);
325 MaNGOS::PlayerSearcher
<MaNGOS::AnyPlayerInObjectRangeCheck
> checker(this,p_ok
, p_check
);
327 TypeContainerVisitor
<MaNGOS::PlayerSearcher
<MaNGOS::AnyPlayerInObjectRangeCheck
>, WorldTypeMapContainer
> world_object_checker(checker
);
328 cell
.Visit(p
, world_object_checker
, *GetMap(), *this, radius
);
334 Unit
*caster
= owner
? owner
: ok
;
336 caster
->CastSpell(ok
, goInfo
->trap
.spellId
, true, NULL
, NULL
, GetGUID());
337 // use template cooldown if provided
338 m_cooldownTime
= time(NULL
) + (goInfo
->trap
.cooldown
? goInfo
->trap
.cooldown
: uint32(4));
341 if(goInfo
->trap
.charges
> 0)
344 if(IsBattleGroundTrap
&& ok
->GetTypeId() == TYPEID_PLAYER
)
346 //BattleGround gameobjects case
347 if(((Player
*)ok
)->InBattleGround())
348 if(BattleGround
*bg
= ((Player
*)ok
)->GetBattleGround())
349 bg
->HandleTriggerBuff(GetGUID());
354 if(uint32 max_charges
= goInfo
->GetCharges())
356 if (m_usetimes
>= max_charges
)
359 SetLootState(GO_JUST_DEACTIVATED
); // can be despawned or destroyed
370 case GAMEOBJECT_TYPE_DOOR
:
371 case GAMEOBJECT_TYPE_BUTTON
:
372 if (GetGOInfo()->GetAutoCloseTime() && (m_cooldownTime
< time(NULL
)))
375 case GAMEOBJECT_TYPE_GOOBER
:
376 if (m_cooldownTime
< time(NULL
))
378 RemoveFlag(GAMEOBJECT_FLAGS
, GO_FLAG_IN_USE
);
380 SetLootState(GO_JUST_DEACTIVATED
);
389 case GO_JUST_DEACTIVATED
:
391 //if Gameobject should cast spell, then this, but some GOs (type = 10) should be destroyed
392 if (GetGoType() == GAMEOBJECT_TYPE_GOOBER
)
394 uint32 spellId
= GetGOInfo()->goober
.spellId
;
398 std::set
<uint32
>::const_iterator it
= m_unique_users
.begin();
399 std::set
<uint32
>::const_iterator end
= m_unique_users
.end();
400 for (; it
!= end
; it
++)
402 if (Unit
* owner
= Unit::GetUnit(*this, uint64(*it
)))
403 owner
->CastSpell(owner
, spellId
, false, NULL
, NULL
, GetGUID());
406 m_unique_users
.clear();
410 SetGoState(GO_STATE_READY
);
412 //any return here in case battleground traps
417 if(Unit
* owner
= GetOwner())
418 owner
->RemoveGameObject(this, false);
425 //burning flags in some battlegrounds, if you find better condition, just add it
426 if (GetGOInfo()->IsDespawnAtAction() || GetGoAnimProgress() > 0)
428 SendObjectDeSpawnAnim(GetGUID());
430 SetUInt32Value(GAMEOBJECT_FLAGS
, GetGOInfo()->flags
);
434 SetLootState(GO_READY
);
436 if(!m_respawnDelayTime
)
439 if(!m_spawnedByDefault
)
445 // since pool system can fail to roll unspawned object, this one can remain spawned, so must set respawn nevertheless
446 m_respawnTime
= time(NULL
) + m_respawnDelayTime
;
448 // if option not set then object will be saved at grid unload
449 if(sWorld
.getConfig(CONFIG_BOOL_SAVE_RESPAWN_TIME_IMMEDIATLY
))
452 // if part of pool, let pool system schedule new spawn instead of just scheduling respawn
453 if(uint16 poolid
= GetDBTableGUIDLow() ? sPoolMgr
.IsPartOfAPool
<GameObject
>(GetDBTableGUIDLow()) : 0)
454 sPoolMgr
.UpdatePool
<GameObject
>(poolid
, GetDBTableGUIDLow());
456 // can be not in world at pool despawn
458 UpdateObjectVisibility();
465 void GameObject::Refresh()
467 // not refresh despawned not casted GO (despawned casted GO destroyed in all cases anyway)
468 if(m_respawnTime
> 0 && m_spawnedByDefault
)
475 void GameObject::AddUniqueUse(Player
* player
)
478 m_unique_users
.insert(player
->GetGUIDLow());
481 void GameObject::Delete()
483 SendObjectDeSpawnAnim(GetGUID());
485 SetGoState(GO_STATE_READY
);
486 SetUInt32Value(GAMEOBJECT_FLAGS
, GetGOInfo()->flags
);
488 uint16 poolid
= GetDBTableGUIDLow() ? sPoolMgr
.IsPartOfAPool
<GameObject
>(GetDBTableGUIDLow()) : 0;
490 sPoolMgr
.UpdatePool
<GameObject
>(poolid
, GetDBTableGUIDLow());
492 AddObjectToRemoveList();
495 void GameObject::getFishLoot(Loot
*fishloot
, Player
* loot_owner
)
499 uint32 zone
, subzone
;
500 GetZoneAndAreaId(zone
,subzone
);
502 // if subzone loot exist use it
503 if (!fishloot
->FillLoot(subzone
, LootTemplates_Fishing
, loot_owner
, true, true))
504 // else use zone loot (must exist in like case)
505 fishloot
->FillLoot(zone
, LootTemplates_Fishing
, loot_owner
,true);
508 void GameObject::SaveToDB()
510 // this should only be used when the gameobject has already been loaded
511 // preferably after adding to map, because mapid may not be valid otherwise
512 GameObjectData
const *data
= sObjectMgr
.GetGOData(m_DBTableGuid
);
515 sLog
.outError("GameObject::SaveToDB failed, cannot get gameobject data!");
519 SaveToDB(GetMapId(), data
->spawnMask
, data
->phaseMask
);
522 void GameObject::SaveToDB(uint32 mapid
, uint8 spawnMask
, uint32 phaseMask
)
524 const GameObjectInfo
*goI
= GetGOInfo();
530 m_DBTableGuid
= GetGUIDLow();
531 // update in loaded data (changing data only in this place)
532 GameObjectData
& data
= sObjectMgr
.NewGOData(m_DBTableGuid
);
534 // data->guid = guid don't must be update at save
535 data
.id
= GetEntry();
537 data
.phaseMask
= phaseMask
;
538 data
.posX
= GetPositionX();
539 data
.posY
= GetPositionY();
540 data
.posZ
= GetPositionZ();
541 data
.orientation
= GetOrientation();
542 data
.rotation0
= GetFloatValue(GAMEOBJECT_PARENTROTATION
+0);
543 data
.rotation1
= GetFloatValue(GAMEOBJECT_PARENTROTATION
+1);
544 data
.rotation2
= GetFloatValue(GAMEOBJECT_PARENTROTATION
+2);
545 data
.rotation3
= GetFloatValue(GAMEOBJECT_PARENTROTATION
+3);
546 data
.spawntimesecs
= m_spawnedByDefault
? (int32
)m_respawnDelayTime
: -(int32
)m_respawnDelayTime
;
547 data
.animprogress
= GetGoAnimProgress();
548 data
.go_state
= GetGoState();
549 data
.spawnMask
= spawnMask
;
552 std::ostringstream ss
;
553 ss
<< "INSERT INTO gameobject VALUES ( "
554 << m_DBTableGuid
<< ", "
555 << GetEntry() << ", "
557 << uint32(spawnMask
) << "," // cast to prevent save as symbol
558 << uint16(GetPhaseMask()) << "," // prevent out of range error
559 << GetPositionX() << ", "
560 << GetPositionY() << ", "
561 << GetPositionZ() << ", "
562 << GetOrientation() << ", "
563 << GetFloatValue(GAMEOBJECT_PARENTROTATION
) << ", "
564 << GetFloatValue(GAMEOBJECT_PARENTROTATION
+1) << ", "
565 << GetFloatValue(GAMEOBJECT_PARENTROTATION
+2) << ", "
566 << GetFloatValue(GAMEOBJECT_PARENTROTATION
+3) << ", "
567 << m_respawnDelayTime
<< ", "
568 << uint32(GetGoAnimProgress()) << ", "
569 << uint32(GetGoState()) << ")";
571 WorldDatabase
.BeginTransaction();
572 WorldDatabase
.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid
);
573 WorldDatabase
.PExecuteLog("%s", ss
.str().c_str());
574 WorldDatabase
.CommitTransaction();
577 bool GameObject::LoadFromDB(uint32 guid
, Map
*map
)
579 GameObjectData
const* data
= sObjectMgr
.GetGOData(guid
);
583 sLog
.outErrorDb("Gameobject (GUID: %u) not found in table `gameobject`, can't load. ",guid
);
587 uint32 entry
= data
->id
;
588 //uint32 map_id = data->mapid; // already used before call
589 uint32 phaseMask
= data
->phaseMask
;
590 float x
= data
->posX
;
591 float y
= data
->posY
;
592 float z
= data
->posZ
;
593 float ang
= data
->orientation
;
595 float rotation0
= data
->rotation0
;
596 float rotation1
= data
->rotation1
;
597 float rotation2
= data
->rotation2
;
598 float rotation3
= data
->rotation3
;
600 uint32 animprogress
= data
->animprogress
;
601 GOState go_state
= data
->go_state
;
603 m_DBTableGuid
= guid
;
604 if (map
->GetInstanceId() != 0) guid
= sObjectMgr
.GenerateLowGuid(HIGHGUID_GAMEOBJECT
);
606 if (!Create(guid
,entry
, map
, phaseMask
, x
, y
, z
, ang
, rotation0
, rotation1
, rotation2
, rotation3
, animprogress
, go_state
) )
609 if (!GetGOInfo()->GetDespawnPossibility() && !GetGOInfo()->IsDespawnAtAction() && data
->spawntimesecs
>= 0)
611 SetFlag(GAMEOBJECT_FLAGS
, GO_FLAG_NODESPAWN
);
612 m_spawnedByDefault
= true;
613 m_respawnDelayTime
= 0;
618 if(data
->spawntimesecs
>= 0)
620 m_spawnedByDefault
= true;
621 m_respawnDelayTime
= data
->spawntimesecs
;
622 m_respawnTime
= sObjectMgr
.GetGORespawnTime(m_DBTableGuid
, map
->GetInstanceId());
625 if(m_respawnTime
&& m_respawnTime
<= time(NULL
))
628 sObjectMgr
.SaveGORespawnTime(m_DBTableGuid
,GetInstanceId(),0);
633 m_spawnedByDefault
= false;
634 m_respawnDelayTime
= -data
->spawntimesecs
;
642 void GameObject::DeleteFromDB()
644 sObjectMgr
.SaveGORespawnTime(m_DBTableGuid
,GetInstanceId(),0);
645 sObjectMgr
.DeleteGOData(m_DBTableGuid
);
646 WorldDatabase
.PExecuteLog("DELETE FROM gameobject WHERE guid = '%u'", m_DBTableGuid
);
647 WorldDatabase
.PExecuteLog("DELETE FROM game_event_gameobject WHERE guid = '%u'", m_DBTableGuid
);
648 WorldDatabase
.PExecuteLog("DELETE FROM gameobject_battleground WHERE guid = '%u'", m_DBTableGuid
);
651 GameObjectInfo
const *GameObject::GetGOInfo() const
656 /*********************************************************/
657 /*** QUEST SYSTEM ***/
658 /*********************************************************/
659 bool GameObject::hasQuest(uint32 quest_id
) const
661 QuestRelations
const& qr
= sObjectMgr
.mGOQuestRelations
;
662 for(QuestRelations::const_iterator itr
= qr
.lower_bound(GetEntry()); itr
!= qr
.upper_bound(GetEntry()); ++itr
)
664 if(itr
->second
==quest_id
)
670 bool GameObject::hasInvolvedQuest(uint32 quest_id
) const
672 QuestRelations
const& qr
= sObjectMgr
.mGOQuestInvolvedRelations
;
673 for(QuestRelations::const_iterator itr
= qr
.lower_bound(GetEntry()); itr
!= qr
.upper_bound(GetEntry()); ++itr
)
675 if(itr
->second
==quest_id
)
681 bool GameObject::IsTransport() const
683 // If something is marked as a transport, don't transmit an out of range packet for it.
684 GameObjectInfo
const * gInfo
= GetGOInfo();
685 if(!gInfo
) return false;
686 return gInfo
->type
== GAMEOBJECT_TYPE_TRANSPORT
|| gInfo
->type
== GAMEOBJECT_TYPE_MO_TRANSPORT
;
689 Unit
* GameObject::GetOwner() const
691 return ObjectAccessor::GetUnit(*this, GetOwnerGUID());
694 void GameObject::SaveRespawnTime()
696 if(m_respawnTime
> time(NULL
) && m_spawnedByDefault
)
697 sObjectMgr
.SaveGORespawnTime(m_DBTableGuid
,GetInstanceId(),m_respawnTime
);
700 bool GameObject::isVisibleForInState(Player
const* u
, WorldObject
const* viewPoint
, bool inVisibleList
) const
703 if(!IsInWorld() || !u
->IsInWorld())
706 // invisible at client always
707 if(!GetGOInfo()->displayId
)
710 // Transport always visible at this step implementation
711 if(IsTransport() && IsInMap(u
))
714 // quick check visibility false cases for non-GM-mode
715 if(!u
->isGameMaster())
717 // despawned and then not visible for non-GM in GM-mode
721 // special invisibility cases
722 /* TODO: implement trap stealth, take look at spell 2836
723 if(GetGOInfo()->type == GAMEOBJECT_TYPE_TRAP && GetGOInfo()->trap.stealthed && u->IsHostileTo(GetOwner()))
731 return IsWithinDistInMap(viewPoint
,World::GetMaxVisibleDistanceForObject() +
732 (inVisibleList
? World::GetVisibleObjectGreyDistance() : 0.0f
), false);
735 void GameObject::Respawn()
737 if(m_spawnedByDefault
&& m_respawnTime
> 0)
739 m_respawnTime
= time(NULL
);
740 sObjectMgr
.SaveGORespawnTime(m_DBTableGuid
,GetInstanceId(),0);
744 bool GameObject::ActivateToQuest( Player
*pTarget
)const
746 if(!sObjectMgr
.IsGameObjectForQuests(GetEntry()))
751 // scan GO chest with loot including quest items
752 case GAMEOBJECT_TYPE_CHEST
:
754 if(LootTemplates_Gameobject
.HaveQuestLootForPlayer(GetGOInfo()->GetLootId(), pTarget
))
756 //look for battlegroundAV for some objects which are only activated after mine gots captured by own team
757 if (GetEntry() == BG_AV_OBJECTID_MINE_N
|| GetEntry() == BG_AV_OBJECTID_MINE_S
)
758 if (BattleGround
*bg
= pTarget
->GetBattleGround())
759 if (bg
->GetTypeID() == BATTLEGROUND_AV
&& !(((BattleGroundAV
*)bg
)->PlayerCanDoMineQuest(GetEntry(),pTarget
->GetTeam())))
765 case GAMEOBJECT_TYPE_GOOBER
:
767 if(pTarget
->GetQuestStatus(GetGOInfo()->goober
.questId
) == QUEST_STATUS_INCOMPLETE
)
778 void GameObject::SummonLinkedTrapIfAny()
780 uint32 linkedEntry
= GetGOInfo()->GetLinkedGameObjectEntry();
784 GameObject
* linkedGO
= new GameObject
;
785 if (!linkedGO
->Create(sObjectMgr
.GenerateLowGuid(HIGHGUID_GAMEOBJECT
), linkedEntry
, GetMap(),
786 GetPhaseMask(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(), 0.0f
, 0.0f
, 0.0f
, 0.0f
, 100, GO_STATE_READY
))
793 linkedGO
->SetRespawnTime(GetRespawnDelay());
794 linkedGO
->SetSpellId(GetSpellId());
798 linkedGO
->SetOwnerGUID(GetOwnerGUID());
799 linkedGO
->SetUInt32Value(GAMEOBJECT_LEVEL
, GetUInt32Value(GAMEOBJECT_LEVEL
));
802 GetMap()->Add(linkedGO
);
805 void GameObject::TriggeringLinkedGameObject( uint32 trapEntry
, Unit
* target
)
807 GameObjectInfo
const* trapInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(trapEntry
);
808 if(!trapInfo
|| trapInfo
->type
!=GAMEOBJECT_TYPE_TRAP
)
811 SpellEntry
const* trapSpell
= sSpellStore
.LookupEntry(trapInfo
->trap
.spellId
);
812 if(!trapSpell
) // checked at load already
815 float range
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(trapSpell
->rangeIndex
));
817 // search nearest linked GO
818 GameObject
* trapGO
= NULL
;
820 // using original GO distance
821 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(), GetPositionY()));
823 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
825 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*target
,trapEntry
,range
);
826 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(this, trapGO
,go_check
);
828 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
829 cell
.Visit(p
, object_checker
, *GetMap(), *target
, range
);
833 // FIXME: when GO casting will be implemented trap must cast spell to target
835 target
->CastSpell(target
, trapSpell
, true, NULL
, NULL
, GetGUID());
838 GameObject
* GameObject::LookupFishingHoleAround(float range
)
840 GameObject
* ok
= NULL
;
842 CellPair
p(MaNGOS::ComputeCellPair(GetPositionX(),GetPositionY()));
844 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
845 MaNGOS::NearestGameObjectFishingHole
u_check(*this, range
);
846 MaNGOS::GameObjectSearcher
<MaNGOS::NearestGameObjectFishingHole
> checker(this, ok
, u_check
);
848 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::NearestGameObjectFishingHole
>, GridTypeMapContainer
> grid_object_checker(checker
);
849 cell
.Visit(p
, grid_object_checker
, *GetMap(), *this, range
);
854 void GameObject::ResetDoorOrButton()
856 if (m_lootState
== GO_READY
|| m_lootState
== GO_JUST_DEACTIVATED
)
859 SwitchDoorOrButton(false);
860 SetLootState(GO_JUST_DEACTIVATED
);
864 void GameObject::UseDoorOrButton(uint32 time_to_restore
, bool alternative
/* = false */)
866 if(m_lootState
!= GO_READY
)
870 time_to_restore
= GetGOInfo()->GetAutoCloseTime();
872 SwitchDoorOrButton(true,alternative
);
873 SetLootState(GO_ACTIVATED
);
875 m_cooldownTime
= time(NULL
) + time_to_restore
;
878 void GameObject::SwitchDoorOrButton(bool activate
, bool alternative
/* = false */)
881 SetFlag(GAMEOBJECT_FLAGS
, GO_FLAG_IN_USE
);
883 RemoveFlag(GAMEOBJECT_FLAGS
, GO_FLAG_IN_USE
);
885 if(GetGoState() == GO_STATE_READY
) //if closed -> open
886 SetGoState(alternative
? GO_STATE_ACTIVE_ALTERNATIVE
: GO_STATE_ACTIVE
);
887 else //if open -> close
888 SetGoState(GO_STATE_READY
);
891 void GameObject::Use(Unit
* user
)
893 // by default spell caster is user
894 Unit
* spellCaster
= user
;
896 bool triggered
= false;
898 if (user
->GetTypeId() == TYPEID_PLAYER
&& Script
->GOHello((Player
*)user
, this))
903 case GAMEOBJECT_TYPE_DOOR
: //0
905 //doors never really despawn, only reset to default state/flags
909 GetMap()->ScriptsStart(sGameObjectScripts
, GetDBTableGUIDLow(), spellCaster
, this);
912 case GAMEOBJECT_TYPE_BUTTON
: //1
914 //buttons never really despawn, only reset to default state/flags
918 GetMap()->ScriptsStart(sGameObjectScripts
, GetDBTableGUIDLow(), spellCaster
, this);
920 // triggering linked GO
921 if (uint32 trapEntry
= GetGOInfo()->button
.linkedTrapId
)
922 TriggeringLinkedGameObject(trapEntry
, user
);
926 case GAMEOBJECT_TYPE_QUESTGIVER
: //2
928 if (user
->GetTypeId() != TYPEID_PLAYER
)
931 Player
* player
= (Player
*)user
;
933 player
->PrepareGossipMenu(this, GetGOInfo()->questgiver
.gossipID
);
934 player
->SendPreparedGossip(this);
937 case GAMEOBJECT_TYPE_CHEST
:
939 if (user
->GetTypeId() != TYPEID_PLAYER
)
942 // TODO: possible must be moved to loot release (in different from linked triggering)
943 if (GetGOInfo()->chest
.eventId
)
945 sLog
.outDebug("Chest ScriptStart id %u for GO %u", GetGOInfo()->chest
.eventId
, GetDBTableGUIDLow());
946 GetMap()->ScriptsStart(sEventScripts
, GetGOInfo()->chest
.eventId
, user
, this);
949 // triggering linked GO
950 if (uint32 trapEntry
= GetGOInfo()->chest
.linkedTrapId
)
951 TriggeringLinkedGameObject(trapEntry
, user
);
955 case GAMEOBJECT_TYPE_CHAIR
: //7 Sitting: Wooden bench, chairs
957 GameObjectInfo
const* info
= GetGOInfo();
961 if (user
->GetTypeId() != TYPEID_PLAYER
)
964 Player
* player
= (Player
*)user
;
966 // a chair may have n slots. we have to calculate their positions and teleport the player to the nearest one
968 // check if the db is sane
969 if (info
->chair
.slots
> 0)
971 float lowestDist
= DEFAULT_VISIBILITY_DISTANCE
;
973 float x_lowest
= GetPositionX();
974 float y_lowest
= GetPositionY();
976 // the object orientation + 1/2 pi
977 // every slot will be on that straight line
978 float orthogonalOrientation
= GetOrientation()+M_PI_F
*0.5f
;
980 for(uint32 i
=0; i
<info
->chair
.slots
; ++i
)
982 // the distance between this slot and the center of the go - imagine a 1D space
983 float relativeDistance
= (info
->size
*i
)-(info
->size
*(info
->chair
.slots
-1)/2.0f
);
985 float x_i
= GetPositionX() + relativeDistance
* cos(orthogonalOrientation
);
986 float y_i
= GetPositionY() + relativeDistance
* sin(orthogonalOrientation
);
988 // calculate the distance between the player and this slot
989 float thisDistance
= player
->GetDistance2d(x_i
, y_i
);
991 /* debug code. It will spawn a npc on each slot to visualize them.
992 Creature* helper = player->SummonCreature(14496, x_i, y_i, GetPositionZ(), GetOrientation(), TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 10000);
993 std::ostringstream output;
994 output << i << ": thisDist: " << thisDistance;
995 helper->MonsterSay(output.str().c_str(), LANG_UNIVERSAL, 0);
998 if (thisDistance
<= lowestDist
)
1000 lowestDist
= thisDistance
;
1005 player
->TeleportTo(GetMapId(), x_lowest
, y_lowest
, GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT
| TELE_TO_NOT_LEAVE_COMBAT
| TELE_TO_NOT_UNSUMMON_PET
);
1009 // fallback, will always work
1010 player
->TeleportTo(GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT
| TELE_TO_NOT_LEAVE_COMBAT
| TELE_TO_NOT_UNSUMMON_PET
);
1012 player
->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR
+info
->chair
.height
);
1015 case GAMEOBJECT_TYPE_SPELL_FOCUS
:
1017 // triggering linked GO
1018 if (uint32 trapEntry
= GetGOInfo()->spellFocus
.linkedTrapId
)
1019 TriggeringLinkedGameObject(trapEntry
, user
);
1021 // some may be activated in addition? Conditions for this? (ex: entry 181616)
1024 case GAMEOBJECT_TYPE_GOOBER
: //10
1026 GameObjectInfo
const* info
= GetGOInfo();
1028 if(user
->GetTypeId()==TYPEID_PLAYER
)
1030 Player
* player
= (Player
*)user
;
1032 if (info
->goober
.pageId
) // show page...
1034 WorldPacket
data(SMSG_GAMEOBJECT_PAGETEXT
, 8);
1036 player
->GetSession()->SendPacket(&data
);
1038 else if (info
->goober
.gossipID
) // ...or gossip, if page does not exist
1040 player
->PrepareGossipMenu(this, info
->goober
.gossipID
);
1041 player
->SendPreparedGossip(this);
1044 if (info
->goober
.eventId
)
1046 sLog
.outDebug("Goober ScriptStart id %u for GO entry %u (GUID %u).", info
->goober
.eventId
, GetEntry(), GetDBTableGUIDLow());
1047 GetMap()->ScriptsStart(sEventScripts
, info
->goober
.eventId
, player
, this);
1050 // possible quest objective for active quests
1051 if (info
->goober
.questId
&& sObjectMgr
.GetQuestTemplate(info
->goober
.questId
))
1053 //Quest require to be active for GO using
1054 if (player
->GetQuestStatus(info
->goober
.questId
) != QUEST_STATUS_INCOMPLETE
)
1058 player
->CastedCreatureOrGO(info
->id
, GetGUID(), 0);
1061 if (uint32 trapEntry
= info
->goober
.linkedTrapId
)
1062 TriggeringLinkedGameObject(trapEntry
, user
);
1064 SetFlag(GAMEOBJECT_FLAGS
, GO_FLAG_IN_USE
);
1065 SetLootState(GO_ACTIVATED
);
1067 uint32 time_to_restore
= info
->GetAutoCloseTime();
1069 // this appear to be ok, however others exist in addition to this that should have custom (ex: 190510, 188692, 187389)
1070 if (time_to_restore
&& info
->goober
.customAnim
)
1071 SendGameObjectCustomAnim(GetGUID());
1073 SetGoState(GO_STATE_ACTIVE
);
1075 m_cooldownTime
= time(NULL
) + time_to_restore
;
1077 // cast this spell later if provided
1078 spellId
= info
->goober
.spellId
;
1080 // database may contain a dummy spell, so it need replacement by actually existing
1083 case 34448: spellId
= 26566; break;
1084 case 34452: spellId
= 26572; break;
1085 case 37639: spellId
= 36326; break;
1086 case 45367: spellId
= 45371; break;
1087 case 45370: spellId
= 45368; break;
1092 case GAMEOBJECT_TYPE_CAMERA
: //13
1094 GameObjectInfo
const* info
= GetGOInfo();
1098 if (user
->GetTypeId() != TYPEID_PLAYER
)
1101 Player
* player
= (Player
*)user
;
1103 if (info
->camera
.cinematicId
)
1104 player
->SendCinematicStart(info
->camera
.cinematicId
);
1106 if (info
->camera
.eventID
)
1107 GetMap()->ScriptsStart(sEventScripts
, info
->camera
.eventID
, player
, this);
1111 case GAMEOBJECT_TYPE_FISHINGNODE
: //17 fishing bobber
1113 if (user
->GetTypeId() != TYPEID_PLAYER
)
1116 Player
* player
= (Player
*)user
;
1118 if (player
->GetGUID() != GetOwnerGUID())
1121 switch(getLootState())
1123 case GO_READY
: // ready for loot
1125 // 1) skill must be >= base_zone_skill
1126 // 2) if skill == base_zone_skill => 5% chance
1127 // 3) chance is linear dependence from (base_zone_skill-skill)
1129 uint32 zone
, subzone
;
1130 GetZoneAndAreaId(zone
,subzone
);
1132 int32 zone_skill
= sObjectMgr
.GetFishingBaseSkillLevel(subzone
);
1134 zone_skill
= sObjectMgr
.GetFishingBaseSkillLevel(zone
);
1136 //provide error, no fishable zone or area should be 0
1138 sLog
.outErrorDb("Fishable areaId %u are not properly defined in `skill_fishing_base_level`.",subzone
);
1140 int32 skill
= player
->GetSkillValue(SKILL_FISHING
);
1141 int32 chance
= skill
- zone_skill
+ 5;
1142 int32 roll
= irand(1,100);
1144 DEBUG_LOG("Fishing check (skill: %i zone min skill: %i chance %i roll: %i",skill
,zone_skill
,chance
,roll
);
1146 if (skill
>= zone_skill
&& chance
>= roll
)
1148 // prevent removing GO at spell cancel
1149 player
->RemoveGameObject(this,false);
1150 SetOwnerGUID(player
->GetGUID());
1153 player
->UpdateFishingSkill();
1155 //TODO: find reasonable value for fishing hole search
1156 GameObject
* ok
= LookupFishingHoleAround(20.0f
+ CONTACT_DISTANCE
);
1159 player
->SendLoot(ok
->GetGUID(),LOOT_FISHINGHOLE
);
1160 player
->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT
, ok
->GetGOInfo()->id
);
1161 SetLootState(GO_JUST_DEACTIVATED
);
1164 player
->SendLoot(GetGUID(),LOOT_FISHING
);
1168 // fish escaped, can be deleted now
1169 SetLootState(GO_JUST_DEACTIVATED
);
1171 WorldPacket
data(SMSG_FISH_ESCAPED
, 0);
1172 player
->GetSession()->SendPacket(&data
);
1176 case GO_JUST_DEACTIVATED
: // nothing to do, will be deleted at next update
1180 SetLootState(GO_JUST_DEACTIVATED
);
1182 WorldPacket
data(SMSG_FISH_NOT_HOOKED
, 0);
1183 player
->GetSession()->SendPacket(&data
);
1188 player
->FinishSpell(CURRENT_CHANNELED_SPELL
);
1191 case GAMEOBJECT_TYPE_SUMMONING_RITUAL
: //18
1193 if (user
->GetTypeId() != TYPEID_PLAYER
)
1196 Player
* player
= (Player
*)user
;
1198 Unit
* caster
= GetOwner();
1200 GameObjectInfo
const* info
= GetGOInfo();
1202 if (!caster
|| caster
->GetTypeId()!=TYPEID_PLAYER
)
1205 // accept only use by player from same group for caster except caster itself
1206 if (((Player
*)caster
) == player
|| !((Player
*)caster
)->IsInSameRaidWith(player
))
1209 AddUniqueUse(player
);
1211 // full amount unique participants including original summoner
1212 if (GetUniqueUseCount() < info
->summoningRitual
.reqParticipants
)
1215 // in case summoning ritual caster is GO creator
1216 spellCaster
= caster
;
1218 if (!caster
->GetCurrentSpell(CURRENT_CHANNELED_SPELL
))
1221 spellId
= info
->summoningRitual
.spellId
;
1222 if (spellId
== 62330) // GO store not existed spell, replace by expected
1224 // spell have reagent and mana cost but it not expected use its
1225 // it triggered spell in fact casted at currently channeled GO
1231 player
->FinishSpell(CURRENT_CHANNELED_SPELL
);
1233 // can be deleted now
1234 SetLootState(GO_JUST_DEACTIVATED
);
1236 // go to end function to spell casting
1239 case GAMEOBJECT_TYPE_SPELLCASTER
: //22
1241 SetUInt32Value(GAMEOBJECT_FLAGS
,2);
1243 GameObjectInfo
const* info
= GetGOInfo();
1247 if (info
->spellcaster
.partyOnly
)
1249 Unit
* caster
= GetOwner();
1250 if (!caster
|| caster
->GetTypeId() != TYPEID_PLAYER
)
1253 if (user
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)user
)->IsInSameRaidWith((Player
*)caster
))
1257 spellId
= info
->spellcaster
.spellId
;
1262 case GAMEOBJECT_TYPE_MEETINGSTONE
: //23
1264 GameObjectInfo
const* info
= GetGOInfo();
1266 if (user
->GetTypeId() != TYPEID_PLAYER
)
1269 Player
* player
= (Player
*)user
;
1271 Player
* targetPlayer
= ObjectAccessor::FindPlayer(player
->GetSelection());
1273 // accept only use by player from same group for caster except caster itself
1274 if (!targetPlayer
|| targetPlayer
== player
|| !targetPlayer
->IsInSameGroupWith(player
))
1277 //required lvl checks!
1278 uint8 level
= player
->getLevel();
1279 if (level
< info
->meetingstone
.minLevel
|| level
> info
->meetingstone
.maxLevel
)
1282 level
= targetPlayer
->getLevel();
1283 if (level
< info
->meetingstone
.minLevel
|| level
> info
->meetingstone
.maxLevel
)
1286 if (info
->id
== 194097)
1287 spellId
= 61994; // Ritual of Summoning
1289 spellId
= 59782; // Summoning Stone Effect
1293 case GAMEOBJECT_TYPE_FLAGSTAND
: // 24
1295 if (user
->GetTypeId() != TYPEID_PLAYER
)
1298 Player
* player
= (Player
*)user
;
1300 if (player
->CanUseBattleGroundObject())
1302 // in battleground check
1303 BattleGround
*bg
= player
->GetBattleGround();
1313 bg
->EventPlayerClickedOnFlag(player
, this);
1314 return; //we don;t need to delete flag ... it is despawned!
1318 case GAMEOBJECT_TYPE_FLAGDROP
: // 26
1320 if (user
->GetTypeId() != TYPEID_PLAYER
)
1323 Player
* player
= (Player
*)user
;
1325 if (player
->CanUseBattleGroundObject())
1327 // in battleground check
1328 BattleGround
*bg
= player
->GetBattleGround();
1333 // 179785 - Silverwing Flag
1334 // 179786 - Warsong Flag
1336 // 184142 - Netherstorm Flag
1337 GameObjectInfo
const* info
= GetGOInfo();
1342 case 179785: // Silverwing Flag
1343 // check if it's correct bg
1344 if(bg
->GetTypeID() == BATTLEGROUND_WS
)
1345 bg
->EventPlayerClickedOnFlag(player
, this);
1347 case 179786: // Warsong Flag
1348 if(bg
->GetTypeID() == BATTLEGROUND_WS
)
1349 bg
->EventPlayerClickedOnFlag(player
, this);
1351 case 184142: // Netherstorm Flag
1352 if(bg
->GetTypeID() == BATTLEGROUND_EY
)
1353 bg
->EventPlayerClickedOnFlag(player
, this);
1357 //this cause to call return, all flags must be deleted here!!
1363 case GAMEOBJECT_TYPE_BARBER_CHAIR
: //32
1365 GameObjectInfo
const* info
= GetGOInfo();
1369 if (user
->GetTypeId() != TYPEID_PLAYER
)
1372 Player
* player
= (Player
*)user
;
1374 // fallback, will always work
1375 player
->TeleportTo(GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT
| TELE_TO_NOT_LEAVE_COMBAT
| TELE_TO_NOT_UNSUMMON_PET
);
1377 WorldPacket
data(SMSG_ENABLE_BARBER_SHOP
, 0);
1378 player
->GetSession()->SendPacket(&data
);
1380 player
->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR
+info
->barberChair
.chairheight
);
1384 sLog
.outError("GameObject::Use unhandled GameObject type %u (entry %u).", GetGoType(), GetEntry());
1391 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellId
);
1394 sLog
.outError("WORLD: unknown spell id %u at use action for gameobject (Entry: %u GoType: %u )", spellId
,GetEntry(),GetGoType());
1398 Spell
*spell
= new Spell(spellCaster
, spellInfo
, triggered
,GetGUID());
1400 // spell target is user of GO
1401 SpellCastTargets targets
;
1402 targets
.setUnitTarget( user
);
1404 spell
->prepare(&targets
);
1407 // overwrite WorldObject function for proper name localization
1408 const char* GameObject::GetNameForLocaleIdx(int32 loc_idx
) const
1412 GameObjectLocale
const *cl
= sObjectMgr
.GetGameObjectLocale(GetEntry());
1415 if (cl
->Name
.size() > (size_t)loc_idx
&& !cl
->Name
[loc_idx
].empty())
1416 return cl
->Name
[loc_idx
].c_str();
1423 void GameObject::UpdateRotationFields(float rotation2
/*=0.0f*/, float rotation3
/*=0.0f*/)
1425 static double const atan_pow
= atan(pow(2.0f
, -20.0f
));
1427 double f_rot1
= sin(GetOrientation() / 2.0f
);
1428 double f_rot2
= cos(GetOrientation() / 2.0f
);
1430 int64 i_rot1
= int64(f_rot1
/ atan_pow
*(f_rot2
>= 0 ? 1.0f
: -1.0f
));
1431 int64 rotation
= (i_rot1
<< 43 >> 43) & 0x00000000001FFFFF;
1433 //float f_rot2 = sin(0.0f / 2.0f);
1434 //int64 i_rot2 = f_rot2 / atan(pow(2.0f, -20.0f));
1435 //rotation |= (((i_rot2 << 22) >> 32) >> 11) & 0x000003FFFFE00000;
1437 //float f_rot3 = sin(0.0f / 2.0f);
1438 //int64 i_rot3 = f_rot3 / atan(pow(2.0f, -21.0f));
1439 //rotation |= (i_rot3 >> 42) & 0x7FFFFC0000000000;
1441 m_rotation
= rotation
;
1443 if(rotation2
==0.0f
&& rotation3
==0.0f
)
1445 rotation2
= (float)f_rot1
;
1446 rotation3
= (float)f_rot2
;
1449 SetFloatValue(GAMEOBJECT_PARENTROTATION
+2, rotation2
);
1450 SetFloatValue(GAMEOBJECT_PARENTROTATION
+3, rotation3
);
1453 bool GameObject::IsHostileTo(Unit
const* unit
) const
1455 // always non-hostile to GM in GM mode
1456 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
1459 // test owner instead if have
1460 if (Unit
const* owner
= GetOwner())
1461 return owner
->IsHostileTo(unit
);
1463 if (Unit
const* targetOwner
= unit
->GetCharmerOrOwner())
1464 return IsHostileTo(targetOwner
);
1466 // for not set faction case (wild object) use hostile case
1467 if(!GetGOInfo()->faction
)
1470 // faction base cases
1471 FactionTemplateEntry
const*tester_faction
= sFactionTemplateStore
.LookupEntry(GetGOInfo()->faction
);
1472 FactionTemplateEntry
const*target_faction
= unit
->getFactionTemplateEntry();
1473 if(!tester_faction
|| !target_faction
)
1476 // GvP forced reaction and reputation case
1477 if(unit
->GetTypeId()==TYPEID_PLAYER
)
1480 if(tester_faction
->faction
)
1482 if(ReputationRank
const* force
= ((Player
*)unit
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
1483 return *force
<= REP_HOSTILE
;
1485 // apply reputation state
1486 FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
);
1487 if(raw_tester_faction
&& raw_tester_faction
->reputationListID
>=0 )
1488 return ((Player
const*)unit
)->GetReputationMgr().GetRank(raw_tester_faction
) <= REP_HOSTILE
;
1492 // common faction based case (GvC,GvP)
1493 return tester_faction
->IsHostileTo(*target_faction
);
1496 bool GameObject::IsFriendlyTo(Unit
const* unit
) const
1498 // always friendly to GM in GM mode
1499 if(unit
->GetTypeId()==TYPEID_PLAYER
&& ((Player
const*)unit
)->isGameMaster())
1502 // test owner instead if have
1503 if (Unit
const* owner
= GetOwner())
1504 return owner
->IsFriendlyTo(unit
);
1506 if (Unit
const* targetOwner
= unit
->GetCharmerOrOwner())
1507 return IsFriendlyTo(targetOwner
);
1509 // for not set faction case (wild object) use hostile case
1510 if(!GetGOInfo()->faction
)
1513 // faction base cases
1514 FactionTemplateEntry
const*tester_faction
= sFactionTemplateStore
.LookupEntry(GetGOInfo()->faction
);
1515 FactionTemplateEntry
const*target_faction
= unit
->getFactionTemplateEntry();
1516 if(!tester_faction
|| !target_faction
)
1519 // GvP forced reaction and reputation case
1520 if(unit
->GetTypeId()==TYPEID_PLAYER
)
1523 if(tester_faction
->faction
)
1525 if(ReputationRank
const* force
=((Player
*)unit
)->GetReputationMgr().GetForcedRankIfAny(tester_faction
))
1526 return *force
>= REP_FRIENDLY
;
1528 // apply reputation state
1529 if(FactionEntry
const* raw_tester_faction
= sFactionStore
.LookupEntry(tester_faction
->faction
))
1530 if(raw_tester_faction
->reputationListID
>=0 )
1531 return ((Player
const*)unit
)->GetReputationMgr().GetRank(raw_tester_faction
) >= REP_FRIENDLY
;
1535 // common faction based case (GvC,GvP)
1536 return tester_faction
->IsFriendlyTo(*target_faction
);