Tracking of player character ids for loot in encounters

Fixes #92 Who could loot was tracked by entity ids.  For players, this meant if you camped and came back you couldn't loot.  Now there is a secondary list for players only that uses character ids.
This commit is contained in:
Image 2020-04-23 00:04:16 -04:00
parent c14c35c612
commit 22dc084991
2 changed files with 26 additions and 0 deletions

View file

@ -398,13 +398,21 @@ void Brain::AddToEncounter(Entity* entity) {
deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(group_id);
for (itr = members->begin(); itr != members->end(); itr++) {
if ((*itr)->client)
{
m_encounter.push_back((*itr)->client->GetPlayer()->GetID());
m_encounter_playerlist.insert(make_pair((*itr)->client->GetPlayer()->GetCharacterID(), (*itr)->client->GetPlayer()->GetID()));
}
}
world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
}
else {
m_encounter.push_back(entity->GetID());
if (entity->IsPlayer())
{
Player* plyr = (Player*)entity;
m_encounter_playerlist.insert(make_pair(plyr->GetCharacterID(), entity->GetID()));
}
}
MEncounter.releasewritelock(__FUNCTION__, __LINE__);
}
@ -415,6 +423,21 @@ bool Brain::CheckLootAllowed(Entity* entity) {
// Check the encounter list to see if the given entity is in it, if so return true.
MEncounter.readlock(__FUNCTION__, __LINE__);
if (entity->IsPlayer())
{
Player* plyr = (Player*)entity;
map<int32, int32>::iterator itr = m_encounter_playerlist.find(plyr->GetCharacterID());
if (itr != m_encounter_playerlist.end())
{
MEncounter.releasereadlock(__FUNCTION__, __LINE__);
return true;
}
MEncounter.releasereadlock(__FUNCTION__, __LINE__);
return false;
}
for (itr = m_encounter.begin(); itr != m_encounter.end(); itr++) {
if ((*itr) == entity->GetID()) {
// found the entity in the encounter list, set return value to true and break the loop
@ -456,6 +479,7 @@ vector<int32>* Brain::GetEncounter() {
void Brain::ClearEncounter() {
MEncounter.writelock(__FUNCTION__, __LINE__);
m_encounter.clear();
m_encounter_playerlist.clear();
m_playerInEncounter = false;
MEncounter.releasewritelock(__FUNCTION__, __LINE__);
}

View file

@ -140,6 +140,8 @@ private:
int16 m_tick;
// m_encounter = list of players (entities) that will get a reward (xp/loot) for killing this npc
vector<int32> m_encounter;
map<int32, int32> m_encounter_playerlist;
// MEncounter = mutex to lock and unlock the encounter list
Mutex MEncounter;
//m_playerInEncounter = true if a player is added to the encounter