diff options
author | Shauren <shauren.trinity@gmail.com> | 2012-03-12 18:07:34 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2012-03-12 18:07:34 +0100 |
commit | 671fd4176a2000b5dd8cdb5b009bc13046dc9bc1 (patch) | |
tree | 39b73166d049923f85000a54aced6fd3f4cd52f5 /src | |
parent | a48216e1226601817a76605b12ee7bafbaf66a78 (diff) |
Core/GameObjects: Chests will now remain locked for players who left the group if loot from that boss is stored in it (note: this is just an implementation of locking the chest, they still need to be linked to a boss - not yet implemented)
Diffstat (limited to 'src')
-rwxr-xr-x | src/server/game/Entities/GameObject/GameObject.cpp | 56 | ||||
-rwxr-xr-x | src/server/game/Entities/GameObject/GameObject.h | 7 | ||||
-rwxr-xr-x | src/server/game/Entities/Object/Object.cpp | 13 |
3 files changed, 76 insertions, 0 deletions
diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 0ba46609945..2e8e68cf8b2 100755 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -55,6 +55,8 @@ GameObject::GameObject() : WorldObject(false), m_model(NULL), m_goValue(new Game m_DBTableGuid = 0; m_rotation = 0; + m_lootRecipient = 0; + m_lootRecipientGroup = 0; m_groupLootTimer = 0; lootingGroupLowGUID = 0; @@ -1968,3 +1970,57 @@ void GameObject::UpdateModel() if (m_model) GetMap()->Insert(*m_model); } + +Player* GameObject::GetLootRecipient() const +{ + if (!m_lootRecipient) + return NULL; + return ObjectAccessor::FindPlayer(m_lootRecipient); +} + +Group* GameObject::GetLootRecipientGroup() const +{ + if (!m_lootRecipientGroup) + return NULL; + return sGroupMgr->GetGroupByGUID(m_lootRecipientGroup); +} + +void GameObject::SetLootRecipient(Unit* unit) +{ + // set the player whose group should receive the right + // to loot the creature after it dies + // should be set to NULL after the loot disappears + + if (!unit) + { + m_lootRecipient = 0; + m_lootRecipientGroup = 0; + return; + } + + if (unit->GetTypeId() != TYPEID_PLAYER && !unit->IsVehicle()) + return; + + Player* player = unit->GetCharmerOrOwnerPlayerOrPlayerItself(); + if (!player) // normal creature, no player involved + return; + + m_lootRecipient = player->GetGUID(); + if (Group* group = player->GetGroup()) + m_lootRecipientGroup = group->GetLowGUID(); +} + +bool GameObject::IsLootAllowedFor(Player const* player) const +{ + if (!m_lootRecipient && !m_lootRecipientGroup) + return true; + + if (player->GetGUID() == m_lootRecipient) + return true; + + Group const* playerGroup = player->GetGroup(); + if (!playerGroup || playerGroup != GetLootRecipientGroup()) // if we dont have a group we arent the recipient + return false; // if go doesnt have group bound it means it was solo killed by someone else + + return true; +} diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index ee643648a6a..bde8780e78f 100755 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -745,6 +745,11 @@ class GameObject : public WorldObject, public GridObject<GameObject> Loot loot; + Player* GetLootRecipient() const; + Group* GetLootRecipientGroup() const; + void SetLootRecipient(Unit* unit); + bool IsLootAllowedFor(Player const* player) const; + bool HasLootRecipient() const { return m_lootRecipient || m_lootRecipientGroup; } uint32 m_groupLootTimer; // (msecs)timer used for group loot uint32 lootingGroupLowGUID; // used to find group which is looting @@ -821,6 +826,8 @@ class GameObject : public WorldObject, public GridObject<GameObject> uint64 m_rotation; + uint64 m_lootRecipient; + uint32 m_lootRecipientGroup; uint16 m_LootMode; // bitmask, default LOOT_MODE_DEFAULT, determines what loot will be lootable private: void RemoveFromOwner(); diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 56ddd14dc3a..d8ee305230e 100755 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -486,6 +486,10 @@ void Object::_BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask* } updateMask->SetBit(GAMEOBJECT_DYNAMIC); updateMask->SetBit(GAMEOBJECT_BYTES_1); + + if (ToGameObject()->GetGoType() == GAMEOBJECT_TYPE_CHEST && ToGameObject()->GetGOInfo()->chest.groupLootRules && + ToGameObject()->HasLootRecipient()) + updateMask->SetBit(GAMEOBJECT_FLAGS); } else if (isType(TYPEMASK_UNIT)) { @@ -709,6 +713,15 @@ void Object::_BuildValuesUpdate(uint8 updatetype, ByteBuffer * data, UpdateMask* *data << uint16(-1); } } + else if (index == GAMEOBJECT_FLAGS) + { + uint32 flags = m_uint32Values[index]; + if (ToGameObject()->GetGoType() == GAMEOBJECT_TYPE_CHEST) + if (ToGameObject()->GetGOInfo()->chest.groupLootRules && !ToGameObject()->IsLootAllowedFor(target)) + flags |= GO_FLAG_LOCKED | GO_FLAG_NOT_SELECTABLE; + + *data << flags; + } else *data << m_uint32Values[index]; // other cases } |