Skip to content

Commit

Permalink
Core/GameObjects: Chests will now remain locked for players who left …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
Shauren committed Mar 12, 2012
1 parent a48216e commit 671fd41
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/server/game/Entities/GameObject/GameObject.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions src/server/game/Entities/GameObject/GameObject.h
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/server/game/Entities/Object/Object.cpp
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 671fd41

Please sign in to comment.