aboutsummaryrefslogtreecommitdiff
path: root/src/game/Group.cpp
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:35:07 -0700
committermaximius <none@none>2009-10-17 15:35:07 -0700
commit26b5e033ffde3d161382fc9addbfa99738379641 (patch)
treea344f369ca32945f787a02dee35c3dbe342bed7e /src/game/Group.cpp
parentf21f47005dcb6b76e1abc9f35fbcd03eed191bff (diff)
*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
Diffstat (limited to 'src/game/Group.cpp')
-rw-r--r--src/game/Group.cpp238
1 files changed, 0 insertions, 238 deletions
diff --git a/src/game/Group.cpp b/src/game/Group.cpp
index 8a02afa25d2..16e91e564d2 100644
--- a/src/game/Group.cpp
+++ b/src/game/Group.cpp
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-
#include "Common.h"
#include "Opcodes.h"
#include "WorldPacket.h"
@@ -33,7 +32,6 @@
#include "InstanceSaveMgr.h"
#include "MapInstanced.h"
#include "Util.h"
-
Group::Group()
{
m_leaderGuid = 0;
@@ -45,11 +43,9 @@ Group::Group()
m_looterGuid = 0;
m_lootThreshold = ITEM_QUALITY_UNCOMMON;
m_subGroupsCounts = NULL;
-
for (int i=0; i<TARGETICONCOUNT; ++i)
m_targetIcons[i] = 0;
}
-
Group::~Group()
{
if(m_bgGroup)
@@ -67,41 +63,32 @@ Group::~Group()
RollId.erase(itr);
delete(r);
}
-
// it is undefined whether objectmgr (which stores the groups) or instancesavemgr
// will be unloaded first so we must be prepared for both cases
// this may unload some instance saves
for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
for(BoundInstancesMap::iterator itr2 = m_boundInstances[i].begin(); itr2 != m_boundInstances[i].end(); ++itr2)
itr2->second.save->RemoveGroup(this);
-
// Sub group counters clean up
if (m_subGroupsCounts)
delete[] m_subGroupsCounts;
}
-
bool Group::Create(const uint64 &guid, const char * name)
{
m_leaderGuid = guid;
m_leaderName = name;
-
m_groupType = isBGGroup() ? GROUPTYPE_RAID : GROUPTYPE_NORMAL;
-
if (m_groupType == GROUPTYPE_RAID)
_initRaidSubGroupsCounter();
-
m_lootMethod = GROUP_LOOT;
m_lootThreshold = ITEM_QUALITY_UNCOMMON;
m_looterGuid = guid;
-
m_difficulty = DIFFICULTY_NORMAL;
if(!isBGGroup())
{
Player *leader = objmgr.GetPlayer(guid);
if(leader) m_difficulty = leader->GetDifficulty();
-
Player::ConvertInstancesToGroup(leader, this, guid);
-
// store group in database
CharacterDatabase.BeginTransaction();
CharacterDatabase.PExecute("DELETE FROM groups WHERE leaderGuid ='%u'", GUID_LOPART(m_leaderGuid));
@@ -111,20 +98,15 @@ bool Group::Create(const uint64 &guid, const char * name)
GUID_LOPART(m_leaderGuid), GUID_LOPART(m_mainTank), GUID_LOPART(m_mainAssistant), uint32(m_lootMethod),
GUID_LOPART(m_looterGuid), uint32(m_lootThreshold), m_targetIcons[0], m_targetIcons[1], m_targetIcons[2], m_targetIcons[3], m_targetIcons[4], m_targetIcons[5], m_targetIcons[6], m_targetIcons[7], isRaidGroup(), m_difficulty);
}
-
if(!AddMember(guid, name))
return false;
-
if(!isBGGroup()) CharacterDatabase.CommitTransaction();
-
return true;
}
-
bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool loadMembers)
{
if(isBGGroup())
return false;
-
bool external = true;
if(!result)
{
@@ -134,38 +116,30 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool
if(!result)
return false;
}
-
m_leaderGuid = leaderGuid;
-
// group leader not exist
if(!objmgr.GetPlayerNameByGUID(m_leaderGuid, m_leaderName))
{
if(!external) delete result;
return false;
}
-
m_groupType = (*result)[13].GetBool() ? GROUPTYPE_RAID : GROUPTYPE_NORMAL;
-
if (m_groupType == GROUPTYPE_RAID)
_initRaidSubGroupsCounter();
-
m_difficulty = (*result)[14].GetUInt8();
m_mainTank = (*result)[0].GetUInt64();
m_mainAssistant = (*result)[1].GetUInt64();
m_lootMethod = (LootMethod)(*result)[2].GetUInt8();
m_looterGuid = MAKE_NEW_GUID((*result)[3].GetUInt32(), 0, HIGHGUID_PLAYER);
m_lootThreshold = (ItemQualities)(*result)[4].GetUInt16();
-
for(int i=0; i<TARGETICONCOUNT; ++i)
m_targetIcons[i] = (*result)[5+i].GetUInt64();
if(!external) delete result;
-
if(loadMembers)
{
result = CharacterDatabase.PQuery("SELECT memberGuid, assistant, subgroup FROM group_member WHERE leaderGuid ='%u'", GUID_LOPART(leaderGuid));
if(!result)
return false;
-
do
{
LoadMemberFromDB((*result)[0].GetUInt32(), (*result)[2].GetUInt8(), (*result)[1].GetBool());
@@ -175,44 +149,33 @@ bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool
if(GetMembersCount() < 2)
return false;
}
-
return true;
}
-
bool Group::LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant)
{
MemberSlot member;
member.guid = MAKE_NEW_GUID(guidLow, 0, HIGHGUID_PLAYER);
-
// skip non-existed member
if(!objmgr.GetPlayerNameByGUID(member.guid, member.name))
return false;
-
member.group = subgroup;
member.assistant = assistant;
m_memberSlots.push_back(member);
-
SubGroupCounterIncrease(subgroup);
-
return true;
}
-
void Group::ConvertToRaid()
{
m_groupType = GROUPTYPE_RAID;
-
_initRaidSubGroupsCounter();
-
if(!isBGGroup())
CharacterDatabase.PExecute("UPDATE groups SET isRaid = 1 WHERE leaderGuid='%u'", GUID_LOPART(m_leaderGuid));
SendUpdate();
-
// update quest related GO states (quest activity dependent from raid membership)
for(member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr)
if(Player* player = objmgr.GetPlayer(citr->guid))
player->UpdateForQuestWorldObjects();
}
-
bool Group::AddInvite(Player *player)
{
if( !player || player->GetGroupInvite() )
@@ -222,42 +185,31 @@ bool Group::AddInvite(Player *player)
group = player->GetOriginalGroup();
if( group )
return false;
-
RemoveInvite(player);
-
m_invitees.insert(player);
-
player->SetGroupInvite(this);
-
return true;
}
-
bool Group::AddLeaderInvite(Player *player)
{
if(!AddInvite(player))
return false;
-
m_leaderGuid = player->GetGUID();
m_leaderName = player->GetName();
return true;
}
-
uint32 Group::RemoveInvite(Player *player)
{
m_invitees.erase(player);
-
player->SetGroupInvite(NULL);
return GetMembersCount();
}
-
void Group::RemoveAllInvites()
{
for(InvitesList::iterator itr=m_invitees.begin(); itr!=m_invitees.end(); ++itr)
(*itr)->SetGroupInvite(NULL);
-
m_invitees.clear();
}
-
Player* Group::GetInvited(const uint64& guid) const
{
for(InvitesList::const_iterator itr = m_invitees.begin(); itr != m_invitees.end(); ++itr)
@@ -267,7 +219,6 @@ Player* Group::GetInvited(const uint64& guid) const
}
return NULL;
}
-
Player* Group::GetInvited(const std::string& name) const
{
for(InvitesList::const_iterator itr = m_invitees.begin(); itr != m_invitees.end(); ++itr)
@@ -277,13 +228,11 @@ Player* Group::GetInvited(const std::string& name) const
}
return NULL;
}
-
bool Group::AddMember(const uint64 &guid, const char* name)
{
if(!_addMember(guid, name))
return false;
SendUpdate();
-
Player *player = objmgr.GetPlayer(guid);
if(player)
{
@@ -292,7 +241,6 @@ bool Group::AddMember(const uint64 &guid, const char* name)
// reset the new member's instances, unless he is currently in one of them
// including raid/heroic instances that they are not permanently bound to!
player->ResetInstances(INSTANCE_RESET_GROUP_JOIN);
-
if(player->getLevel() >= LEVELREQUIREMENT_HEROIC && player->GetDifficulty() != GetDifficulty() )
{
player->SetDifficulty(m_difficulty);
@@ -301,38 +249,30 @@ bool Group::AddMember(const uint64 &guid, const char* name)
}
player->SetGroupUpdateFlag(GROUP_UPDATE_FULL);
UpdatePlayerOutOfRange(player);
-
// quest related GO state dependent from raid memebership
if(isRaidGroup())
player->UpdateForQuestWorldObjects();
}
-
return true;
}
-
uint32 Group::RemoveMember(const uint64 &guid, const uint8 &method)
{
BroadcastGroupUpdate();
-
// remove member and change leader (if need) only if strong more 2 members _before_ member remove
if(GetMembersCount() > (isBGGroup() ? 1 : 2)) // in BG group case allow 1 members group
{
bool leaderChanged = _removeMember(guid);
-
if(Player *player = objmgr.GetPlayer( guid ))
{
// quest related GO state dependent from raid membership
if(isRaidGroup())
player->UpdateForQuestWorldObjects();
-
WorldPacket data;
-
if(method == 1)
{
data.Initialize( SMSG_GROUP_UNINVITE, 0 );
player->GetSession()->SendPacket( &data );
}
-
//we already removed player from group and in player->GetGroup() is his original group!
if( Group* group = player->GetGroup() )
{
@@ -344,51 +284,40 @@ uint32 Group::RemoveMember(const uint64 &guid, const uint8 &method)
data << uint64(0) << uint64(0) << uint64(0);
player->GetSession()->SendPacket(&data);
}
-
_homebindIfInstance(player);
}
-
if(leaderChanged)
{
WorldPacket data(SMSG_GROUP_SET_LEADER, (m_memberSlots.front().name.size()+1));
data << m_memberSlots.front().name;
BroadcastPacket(&data, true);
}
-
SendUpdate();
}
// if group before remove <= 2 disband it
else
Disband(true);
-
return m_memberSlots.size();
}
-
void Group::ChangeLeader(const uint64 &guid)
{
member_citerator slot = _getMemberCSlot(guid);
-
if(slot==m_memberSlots.end())
return;
-
_setLeader(guid);
-
WorldPacket data(SMSG_GROUP_SET_LEADER, slot->name.size()+1);
data << slot->name;
BroadcastPacket(&data, true);
SendUpdate();
}
-
void Group::Disband(bool hideDestroy)
{
Player *player;
-
for(member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr)
{
player = objmgr.GetPlayer(citr->guid);
if(!player)
continue;
-
//we cannot call _removeMember because it would invalidate member iterator
//if we are removing player from battleground raid
if( isBGGroup() )
@@ -401,21 +330,17 @@ void Group::Disband(bool hideDestroy)
else
player->SetGroup(NULL);
}
-
// quest related GO state dependent from raid membership
if(isRaidGroup())
player->UpdateForQuestWorldObjects();
-
if(!player->GetSession())
continue;
-
WorldPacket data;
if(!hideDestroy)
{
data.Initialize(SMSG_GROUP_DESTROYED, 0);
player->GetSession()->SendPacket(&data);
}
-
//we already removed player from group and in player->GetGroup() is his original group, send update
if( Group* group = player->GetGroup() )
{
@@ -427,14 +352,11 @@ void Group::Disband(bool hideDestroy)
data << uint64(0) << uint64(0) << uint64(0);
player->GetSession()->SendPacket(&data);
}
-
_homebindIfInstance(player);
}
RollId.clear();
m_memberSlots.clear();
-
RemoveAllInvites();
-
if(!isBGGroup())
{
CharacterDatabase.BeginTransaction();
@@ -443,15 +365,12 @@ void Group::Disband(bool hideDestroy)
CharacterDatabase.CommitTransaction();
ResetInstances(INSTANCE_RESET_GROUP_DISBAND, NULL);
}
-
m_leaderGuid = 0;
m_leaderName = "";
}
-
/*********************************************************/
/*** LOOT SYSTEM ***/
/*********************************************************/
-
void Group::SendLootStartRoll(uint32 CountDown, const Roll &r)
{
WorldPacket data(SMSG_LOOT_START_ROLL, (8+4+4+4+4+4));
@@ -461,18 +380,15 @@ void Group::SendLootStartRoll(uint32 CountDown, const Roll &r)
data << uint32(r.itemRandomSuffix); // randomSuffix
data << uint32(r.itemRandomPropId); // item random property ID
data << uint32(CountDown); // the countdown time to choose "need" or "greed"
-
for (Roll::PlayerVote::const_iterator itr=r.playerVote.begin(); itr!=r.playerVote.end(); ++itr)
{
Player *p = objmgr.GetPlayer(itr->first);
if(!p || !p->GetSession())
continue;
-
if(itr->second != NOT_VALID)
p->GetSession()->SendPacket( &data );
}
}
-
void Group::SendLootRoll(const uint64& SourceGuid, const uint64& TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r)
{
WorldPacket data(SMSG_LOOT_ROLL, (8+4+8+4+4+4+1+1));
@@ -485,18 +401,15 @@ void Group::SendLootRoll(const uint64& SourceGuid, const uint64& TargetGuid, uin
data << uint8(RollNumber); // 0: "Need for: [item name]" > 127: "you passed on: [item name]" Roll number
data << uint8(RollType); // 0: "Need for: [item name]" 0: "You have selected need for [item name] 1: need roll 2: greed roll
data << uint8(0); // 2.4.0
-
for( Roll::PlayerVote::const_iterator itr=r.playerVote.begin(); itr!=r.playerVote.end(); ++itr)
{
Player *p = objmgr.GetPlayer(itr->first);
if(!p || !p->GetSession())
continue;
-
if(itr->second != NOT_VALID)
p->GetSession()->SendPacket( &data );
}
}
-
void Group::SendLootRollWon(const uint64& SourceGuid, const uint64& TargetGuid, uint8 RollNumber, uint8 RollType, const Roll &r)
{
WorldPacket data(SMSG_LOOT_ROLL_WON, (8+4+4+4+4+8+1+1));
@@ -508,18 +421,15 @@ void Group::SendLootRollWon(const uint64& SourceGuid, const uint64& TargetGuid,
data << uint64(TargetGuid); // guid of the player who won.
data << uint8(RollNumber); // rollnumber realted to SMSG_LOOT_ROLL
data << uint8(RollType); // Rolltype related to SMSG_LOOT_ROLL
-
for( Roll::PlayerVote::const_iterator itr=r.playerVote.begin(); itr!=r.playerVote.end(); ++itr)
{
Player *p = objmgr.GetPlayer(itr->first);
if(!p || !p->GetSession())
continue;
-
if(itr->second != NOT_VALID)
p->GetSession()->SendPacket( &data );
}
}
-
void Group::SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r)
{
WorldPacket data(SMSG_LOOT_ALL_PASSED, (8+4+4+4+4));
@@ -528,18 +438,15 @@ void Group::SendLootAllPassed(uint32 NumberOfPlayers, const Roll &r)
data << uint32(r.itemid); // The itemEntryId for the item that shall be rolled for
data << uint32(r.itemRandomPropId); // Item random property ID
data << uint32(r.itemRandomSuffix); // Item random suffix ID
-
for( Roll::PlayerVote::const_iterator itr=r.playerVote.begin(); itr!=r.playerVote.end(); ++itr)
{
Player *p = objmgr.GetPlayer(itr->first);
if(!p || !p->GetSession())
continue;
-
if(itr->second != NOT_VALID)
p->GetSession()->SendPacket( &data );
}
}
-
void Group::GroupLoot(const uint64& playerGUID, Loot *loot, Creature *creature)
{
std::vector<LootItem>::iterator i;
@@ -547,7 +454,6 @@ void Group::GroupLoot(const uint64& playerGUID, Loot *loot, Creature *creature)
uint8 itemSlot = 0;
Player *player = objmgr.GetPlayer(playerGUID);
Group *group = player->GetGroup();
-
for (i=loot->items.begin(); i != loot->items.end(); ++i, ++itemSlot)
{
item = objmgr.GetItemPrototype(i->itemid);
@@ -556,13 +462,11 @@ void Group::GroupLoot(const uint64& playerGUID, Loot *loot, Creature *creature)
//sLog.outDebug("Group::GroupLoot: missing item prototype for item with id: %d", i->itemid);
continue;
}
-
//roll for over-threshold item if it's one-player loot
if (item->Quality >= uint32(m_lootThreshold) && !i->freeforall)
{
uint64 newitemGUID = MAKE_NEW_GUID(objmgr.GenerateLowGuid(HIGHGUID_ITEM),0,HIGHGUID_ITEM);
Roll* r=new Roll(newitemGUID,*i);
-
//a vector is filled with only near party members
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
@@ -578,47 +482,37 @@ void Group::GroupLoot(const uint64& playerGUID, Loot *loot, Creature *creature)
}
}
}
-
r->setLoot(loot);
r->itemSlot = itemSlot;
-
group->SendLootStartRoll(60000, *r);
-
loot->items[itemSlot].is_blocked = true;
creature->m_groupLootTimer = 60000;
creature->lootingGroupLeaderGUID = GetLeaderGUID();
-
RollId.push_back(r);
}
else
i->is_underthreshold=1;
-
}
}
-
void Group::NeedBeforeGreed(const uint64& playerGUID, Loot *loot, Creature *creature)
{
ItemPrototype const *item;
Player *player = objmgr.GetPlayer(playerGUID);
Group *group = player->GetGroup();
-
uint8 itemSlot = 0;
for(std::vector<LootItem>::iterator i=loot->items.begin(); i != loot->items.end(); ++i, ++itemSlot)
{
item = objmgr.GetItemPrototype(i->itemid);
-
//only roll for one-player items, not for ones everyone can get
if (item->Quality >= uint32(m_lootThreshold) && !i->freeforall)
{
uint64 newitemGUID = MAKE_NEW_GUID(objmgr.GenerateLowGuid(HIGHGUID_ITEM),0,HIGHGUID_ITEM);
Roll* r=new Roll(newitemGUID,*i);
-
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *playerToRoll = itr->getSource();
if(!playerToRoll || !playerToRoll->GetSession())
continue;
-
if (playerToRoll->CanUseItem(item) && i->AllowedForPlayer(playerToRoll) )
{
if (playerToRoll->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false))
@@ -628,16 +522,12 @@ void Group::NeedBeforeGreed(const uint64& playerGUID, Loot *loot, Creature *crea
}
}
}
-
if (r->totalPlayersRolling > 0)
{
r->setLoot(loot);
r->itemSlot = itemSlot;
-
group->SendLootStartRoll(60000, *r);
-
loot->items[itemSlot].is_blocked = true;
-
RollId.push_back(r);
}
else
@@ -649,35 +539,27 @@ void Group::NeedBeforeGreed(const uint64& playerGUID, Loot *loot, Creature *crea
i->is_underthreshold=1;
}
}
-
void Group::MasterLoot(const uint64& playerGUID, Loot* /*loot*/, Creature *creature)
{
Player *player = objmgr.GetPlayer(playerGUID);
if(!player)
return;
-
sLog.outDebug("Group::MasterLoot (SMSG_LOOT_MASTER_LIST, 330) player = [%s].", player->GetName());
-
uint32 real_count = 0;
-
WorldPacket data(SMSG_LOOT_MASTER_LIST, 330);
data << (uint8)GetMembersCount();
-
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *looter = itr->getSource();
if (!looter->IsInWorld())
continue;
-
if (looter->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false))
{
data << looter->GetGUID();
++real_count;
}
}
-
data.put<uint8>(0,real_count);
-
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *looter = itr->getSource();
@@ -685,23 +567,19 @@ void Group::MasterLoot(const uint64& playerGUID, Loot* /*loot*/, Creature *creat
looter->GetSession()->SendPacket(&data);
}
}
-
void Group::CountRollVote(const uint64& playerGUID, const uint64& Guid, uint32 NumberOfPlayers, uint8 Choise)
{
Rolls::iterator rollI = GetRoll(Guid);
if (rollI == RollId.end())
return;
Roll* roll = *rollI;
-
Roll::PlayerVote::iterator itr = roll->playerVote.find(playerGUID);
// this condition means that player joins to the party after roll begins
if (itr == roll->playerVote.end())
return;
-
if (roll->getLoot())
if (roll->getLoot()->items.empty())
return;
-
switch (Choise)
{
case 0: //Player choose pass
@@ -731,7 +609,6 @@ void Group::CountRollVote(const uint64& playerGUID, const uint64& Guid, uint32 N
CountTheRoll(rollI, NumberOfPlayers);
}
}
-
//called when roll timer expires
void Group::EndRoll()
{
@@ -743,7 +620,6 @@ void Group::EndRoll()
CountTheRoll(itr, GetMembersCount()); //i don't have to edit player votes, who didn't vote ... he will pass
}
}
-
void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
{
Roll* roll = *rollI;
@@ -761,12 +637,10 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
uint8 maxresul = 0;
uint64 maxguid = (*roll->playerVote.begin()).first;
Player *player;
-
for( Roll::PlayerVote::const_iterator itr=roll->playerVote.begin(); itr!=roll->playerVote.end(); ++itr)
{
if (itr->second != NEED)
continue;
-
uint8 randomN = urand(1, 99);
SendLootRoll(0, itr->first, randomN, 1, *roll);
if (maxresul < randomN)
@@ -777,11 +651,9 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
}
SendLootRollWon(0, maxguid, maxresul, 1, *roll);
player = objmgr.GetPlayer(maxguid);
-
if(player && player->GetSession())
{
player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT, roll->itemid, maxresul);
-
ItemPosCountVec dest;
LootItem *item = &(roll->getLoot()->items[roll->itemSlot]);
uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, roll->itemid, item->count );
@@ -807,13 +679,11 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
uint8 maxresul = 0;
uint64 maxguid = (*roll->playerVote.begin()).first;
Player *player;
-
Roll::PlayerVote::iterator itr;
for (itr=roll->playerVote.begin(); itr!=roll->playerVote.end(); ++itr)
{
if (itr->second != GREED)
continue;
-
uint8 randomN = urand(1, 99);
SendLootRoll(0, itr->first, randomN, 2, *roll);
if (maxresul < randomN)
@@ -824,11 +694,9 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
}
SendLootRollWon(0, maxguid, maxresul, 2, *roll);
player = objmgr.GetPlayer(maxguid);
-
if(player && player->GetSession())
{
player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT, roll->itemid, maxresul);
-
ItemPosCountVec dest;
LootItem *item = &(roll->getLoot()->items[roll->itemSlot]);
uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, roll->itemid, item->count );
@@ -856,27 +724,22 @@ void Group::CountTheRoll(Rolls::iterator rollI, uint32 NumberOfPlayers)
RollId.erase(rollI);
delete roll;
}
-
void Group::SetTargetIcon(uint8 id, uint64 guid)
{
if(id >= TARGETICONCOUNT)
return;
-
// clean other icons
if( guid != 0 )
for(int i=0; i<TARGETICONCOUNT; ++i)
if( m_targetIcons[i] == guid )
SetTargetIcon(i, 0);
-
m_targetIcons[id] = guid;
-
WorldPacket data(MSG_RAID_TARGET_UPDATE, (2+8));
data << (uint8)0;
data << id;
data << guid;
BroadcastPacket(&data, true);
}
-
void Group::GetDataForXPAtKill(Unit const* victim, uint32& count,uint32& sum_level, Player* & member_with_max_level, Player* & not_gray_member_with_max_level)
{
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
@@ -884,46 +747,36 @@ void Group::GetDataForXPAtKill(Unit const* victim, uint32& count,uint32& sum_lev
Player* member = itr->getSource();
if(!member || !member->isAlive()) // only for alive
continue;
-
if(!member->IsAtGroupRewardDistance(victim)) // at req. distance
continue;
-
++count;
sum_level += member->getLevel();
if(!member_with_max_level || member_with_max_level->getLevel() < member->getLevel())
member_with_max_level = member;
-
uint32 gray_level = MaNGOS::XP::GetGrayLevel(member->getLevel());
if( victim->getLevel() > gray_level && (!not_gray_member_with_max_level
|| not_gray_member_with_max_level->getLevel() < member->getLevel()))
not_gray_member_with_max_level = member;
}
}
-
void Group::SendTargetIconList(WorldSession *session)
{
if(!session)
return;
-
WorldPacket data(MSG_RAID_TARGET_UPDATE, (1+TARGETICONCOUNT*9));
data << (uint8)1;
-
for(int i=0; i<TARGETICONCOUNT; ++i)
{
if(m_targetIcons[i] == 0)
continue;
-
data << (uint8)i;
data << m_targetIcons[i];
}
-
session->SendPacket(&data);
}
-
void Group::SendUpdate()
{
Player *player;
-
for(member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr)
{
player = objmgr.GetPlayer(citr->guid);
@@ -944,7 +797,6 @@ void Group::SendUpdate()
Player* member = objmgr.GetPlayer(citr2->guid);
uint8 onlineState = (member) ? MEMBER_STATUS_ONLINE : MEMBER_STATUS_OFFLINE;
onlineState = onlineState | ((isBGGroup()) ? MEMBER_STATUS_PVP : 0);
-
data << citr2->name;
data << (uint64)citr2->guid;
// online-state
@@ -952,7 +804,6 @@ void Group::SendUpdate()
data << (uint8)(citr2->group); // groupid
data << (uint8)(citr2->assistant?0x01:0); // 0x2 main assist, 0x4 main tank
}
-
data << uint64(m_leaderGuid); // leader guid
if(GetMembersCount()-1)
{
@@ -964,16 +815,13 @@ void Group::SendUpdate()
player->GetSession()->SendPacket( &data );
}
}
-
void Group::UpdatePlayerOutOfRange(Player* pPlayer)
{
if(!pPlayer || !pPlayer->IsInWorld())
return;
-
Player *player;
WorldPacket data;
pPlayer->GetSession()->BuildPartyMemberStatsChangedPacket(pPlayer, &data);
-
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
player = itr->getSource();
@@ -981,7 +829,6 @@ void Group::UpdatePlayerOutOfRange(Player* pPlayer)
player->GetSession()->SendPacket(&data);
}
}
-
void Group::BroadcastPacket(WorldPacket *packet, bool ignorePlayersInBGRaid, int group, uint64 ignore)
{
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
@@ -989,12 +836,10 @@ void Group::BroadcastPacket(WorldPacket *packet, bool ignorePlayersInBGRaid, int
Player *pl = itr->getSource();
if(!pl || (ignore != 0 && pl->GetGUID() == ignore) || (ignorePlayersInBGRaid && pl->GetGroup() != this) )
continue;
-
if (pl->GetSession() && (group==-1 || itr->getSubGroup()==group))
pl->GetSession()->SendPacket(packet);
}
}
-
void Group::BroadcastReadyCheck(WorldPacket *packet)
{
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
@@ -1005,7 +850,6 @@ void Group::BroadcastReadyCheck(WorldPacket *packet)
pl->GetSession()->SendPacket(packet);
}
}
-
void Group::OfflineReadyCheck()
{
for(member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr)
@@ -1020,7 +864,6 @@ void Group::OfflineReadyCheck()
}
}
}
-
bool Group::_addMember(const uint64 &guid, const char* name, bool isAssistant)
{
// get first not-full group
@@ -1040,29 +883,22 @@ bool Group::_addMember(const uint64 &guid, const char* name, bool isAssistant)
if (!groupFound)
return false;
}
-
return _addMember(guid, name, isAssistant, groupid);
}
-
bool Group::_addMember(const uint64 &guid, const char* name, bool isAssistant, uint8 group)
{
if(IsFull())
return false;
-
if(!guid)
return false;
-
Player *player = objmgr.GetPlayer(guid);
-
MemberSlot member;
member.guid = guid;
member.name = name;
member.group = group;
member.assistant = isAssistant;
m_memberSlots.push_back(member);
-
SubGroupCounterIncrease(group);
-
if(player)
{
player->SetGroupInvite(NULL);
@@ -1080,22 +916,18 @@ bool Group::_addMember(const uint64 &guid, const char* name, bool isAssistant, u
if(bind && bind->save->GetInstanceId() == player->GetInstanceId())
player->m_InstanceValid = true;
}
-
if(!isRaidGroup()) // reset targetIcons for non-raid-groups
{
for(int i=0; i<TARGETICONCOUNT; ++i)
m_targetIcons[i] = 0;
}
-
if(!isBGGroup())
{
// insert into group table
CharacterDatabase.PExecute("INSERT INTO group_member(leaderGuid,memberGuid,assistant,subgroup) VALUES('%u','%u','%u','%u')", GUID_LOPART(m_leaderGuid), GUID_LOPART(member.guid), ((member.assistant==1)?1:0), member.group);
}
-
return true;
}
-
bool Group::_removeMember(const uint64 &guid)
{
Player *player = objmgr.GetPlayer(guid);
@@ -1113,43 +945,33 @@ bool Group::_removeMember(const uint64 &guid)
player->SetGroup(NULL);
}
}
-
_removeRolls(guid);
-
member_witerator slot = _getMemberWSlot(guid);
if (slot != m_memberSlots.end())
{
SubGroupCounterDecrease(slot->group);
-
m_memberSlots.erase(slot);
}
-
if(!isBGGroup())
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid='%u'", GUID_LOPART(guid));
-
if(m_leaderGuid == guid) // leader was removed
{
if(GetMembersCount() > 0)
_setLeader(m_memberSlots.front().guid);
return true;
}
-
return false;
}
-
void Group::_setLeader(const uint64 &guid)
{
member_citerator slot = _getMemberCSlot(guid);
if(slot==m_memberSlots.end())
return;
-
if(!isBGGroup())
{
// TODO: set a time limit to have this function run rarely cause it can be slow
CharacterDatabase.BeginTransaction();
-
// update the group's bound instances when changing leaders
-
// remove all permanent binds from the group
// in the DB also remove solo binds that will be replaced with permbinds
// from the new leader
@@ -1158,7 +980,6 @@ void Group::_setLeader(const uint64 &guid)
"instance IN (SELECT instance FROM character_instance WHERE guid = '%u')"
")", GUID_LOPART(m_leaderGuid), GUID_LOPART(slot->guid)
);
-
Player *player = objmgr.GetPlayer(slot->guid);
if(player)
{
@@ -1176,25 +997,20 @@ void Group::_setLeader(const uint64 &guid)
}
}
}
-
// update the group's solo binds to the new leader
CharacterDatabase.PExecute("UPDATE group_instance SET leaderGuid='%u' WHERE leaderGuid = '%u'", GUID_LOPART(slot->guid), GUID_LOPART(m_leaderGuid));
-
// copy the permanent binds from the new leader to the group
// overwriting the solo binds with permanent ones if necessary
// in the DB those have been deleted already
Player::ConvertInstancesToGroup(player, this, slot->guid);
-
// update the group leader
CharacterDatabase.PExecute("UPDATE groups SET leaderGuid='%u' WHERE leaderGuid='%u'", GUID_LOPART(slot->guid), GUID_LOPART(m_leaderGuid));
CharacterDatabase.PExecute("UPDATE group_member SET leaderGuid='%u' WHERE leaderGuid='%u'", GUID_LOPART(slot->guid), GUID_LOPART(m_leaderGuid));
CharacterDatabase.CommitTransaction();
}
-
m_leaderGuid = slot->guid;
m_leaderName = slot->name;
}
-
void Group::_removeRolls(const uint64 &guid)
{
for (Rolls::iterator it = RollId.begin(); it != RollId.end(); ++it)
@@ -1203,91 +1019,72 @@ void Group::_removeRolls(const uint64 &guid)
Roll::PlayerVote::iterator itr2 = roll->playerVote.find(guid);
if(itr2 == roll->playerVote.end())
continue;
-
if (itr2->second == GREED) --roll->totalGreed;
if (itr2->second == NEED) --roll->totalNeed;
if (itr2->second == PASS) --roll->totalPass;
if (itr2->second != NOT_VALID) --roll->totalPlayersRolling;
-
roll->playerVote.erase(itr2);
-
CountRollVote(guid, roll->itemGUID, GetMembersCount()-1, 3);
}
}
-
bool Group::_setMembersGroup(const uint64 &guid, const uint8 &group)
{
member_witerator slot = _getMemberWSlot(guid);
if(slot==m_memberSlots.end())
return false;
-
slot->group = group;
-
SubGroupCounterIncrease(group);
-
if(!isBGGroup()) CharacterDatabase.PExecute("UPDATE group_member SET subgroup='%u' WHERE memberGuid='%u'", group, GUID_LOPART(guid));
-
return true;
}
-
bool Group::_setAssistantFlag(const uint64 &guid, const bool &state)
{
member_witerator slot = _getMemberWSlot(guid);
if(slot==m_memberSlots.end())
return false;
-
slot->assistant = state;
if(!isBGGroup()) CharacterDatabase.PExecute("UPDATE group_member SET assistant='%u' WHERE memberGuid='%u'", (state==true)?1:0, GUID_LOPART(guid));
return true;
}
-
bool Group::_setMainTank(const uint64 &guid)
{
member_citerator slot = _getMemberCSlot(guid);
if(slot==m_memberSlots.end())
return false;
-
if(m_mainAssistant == guid)
_setMainAssistant(0);
m_mainTank = guid;
if(!isBGGroup()) CharacterDatabase.PExecute("UPDATE groups SET mainTank='%u' WHERE leaderGuid='%u'", GUID_LOPART(m_mainTank), GUID_LOPART(m_leaderGuid));
return true;
}
-
bool Group::_setMainAssistant(const uint64 &guid)
{
member_witerator slot = _getMemberWSlot(guid);
if(slot==m_memberSlots.end())
return false;
-
if(m_mainTank == guid)
_setMainTank(0);
m_mainAssistant = guid;
if(!isBGGroup()) CharacterDatabase.PExecute("UPDATE groups SET mainAssistant='%u' WHERE leaderGuid='%u'", GUID_LOPART(m_mainAssistant), GUID_LOPART(m_leaderGuid));
return true;
}
-
bool Group::SameSubGroup(Player const* member1, Player const* member2) const
{
if(!member1 || !member2) return false;
if (member1->GetGroup() != this || member2->GetGroup() != this) return false;
else return member1->GetSubGroup() == member2->GetSubGroup();
}
-
// allows setting subgroup for offline members
void Group::ChangeMembersGroup(const uint64 &guid, const uint8 &group)
{
if(!isRaidGroup())
return;
Player *player = objmgr.GetPlayer(guid);
-
if (!player)
{
uint8 prevSubGroup;
prevSubGroup = GetMemberGroup(guid);
-
SubGroupCounterDecrease(prevSubGroup);
-
if(_setMembersGroup(guid, group))
SendUpdate();
}
@@ -1295,7 +1092,6 @@ void Group::ChangeMembersGroup(const uint64 &guid, const uint8 &group)
// This methods handles itself groupcounter decrease
ChangeMembersGroup(player, group);
}
-
// only for online members
void Group::ChangeMembersGroup(Player *player, const uint8 &group)
{
@@ -1313,11 +1109,9 @@ void Group::ChangeMembersGroup(Player *player, const uint8 &group)
player->GetOriginalGroupRef().setSubGroup(group);
}
SubGroupCounterDecrease(prevSubGroup);
-
SendUpdate();
}
}
-
void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
{
switch (GetLootMethod())
@@ -1330,7 +1124,6 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
// quality items in each loot method except free for all and master loot
break;
}
-
member_citerator guid_itr = _getMemberCSlot(GetLooterGuid());
if(guid_itr != m_memberSlots.end())
{
@@ -1343,7 +1136,6 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
}
++guid_itr;
}
-
// search next after current
if(guid_itr != m_memberSlots.end())
{
@@ -1354,7 +1146,6 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
if (pl->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false))
{
bool refresh = pl->GetLootGUID()==creature->GetGUID();
-
//if(refresh) // update loot for new looter
// pl->GetSession()->DoLootRelease(pl->GetLootGUID());
SetLooterGuid(pl->GetGUID());
@@ -1366,7 +1157,6 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
}
}
}
-
// search from start
for(member_citerator itr = m_memberSlots.begin(); itr != guid_itr; ++itr)
{
@@ -1375,7 +1165,6 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
if (pl->IsWithinDist(creature,sWorld.getConfig(CONFIG_GROUP_XP_DISTANCE),false))
{
bool refresh = pl->GetLootGUID()==creature->GetGUID();
-
//if(refresh) // update loot for new looter
// pl->GetSession()->DoLootRelease(pl->GetLootGUID());
SetLooterGuid(pl->GetGUID());
@@ -1386,11 +1175,9 @@ void Group::UpdateLooterGuid( Creature* creature, bool ifneed )
}
}
}
-
SetLooterGuid(0);
SendUpdate();
}
-
uint32 Group::CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId, BattleGroundQueueTypeId bgQueueTypeId, uint32 MinPlayerCount, uint32 MaxPlayerCount, bool isRated, uint32 arenaSlot)
{
// check for min / max count
@@ -1399,17 +1186,14 @@ uint32 Group::CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId, BattleGround
return BG_JOIN_ERR_GROUP_NOT_ENOUGH;
if(memberscount > MaxPlayerCount)
return BG_JOIN_ERR_GROUP_TOO_MANY;
-
// get a player as reference, to compare other players' stats to (arena team id, queue id based on level, etc.)
Player * reference = GetFirstMember()->getSource();
// no reference found, can't join this way
if(!reference)
return BG_JOIN_ERR_OFFLINE_MEMBER;
-
BGQueueIdBasedOnLevel queue_id = reference->GetBattleGroundQueueIdFromLevel(bgTypeId);
uint32 arenaTeamId = reference->GetArenaTeamId(arenaSlot);
uint32 team = reference->GetTeam();
-
// check every member of the group to be able to join
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
@@ -1438,22 +1222,18 @@ uint32 Group::CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId, BattleGround
}
return BG_JOIN_ERR_OK;
}
-
//===================================================
//============== Roll ===============================
//===================================================
-
void Roll::targetObjectBuildLink()
{
// called from link()
getTarget()->addLootValidatorRef(this);
}
-
void Group::SetDifficulty(uint8 difficulty)
{
m_difficulty = difficulty;
if(!isBGGroup()) CharacterDatabase.PExecute("UPDATE groups SET difficulty = %u WHERE leaderGuid ='%u'", m_difficulty, GUID_LOPART(m_leaderGuid));
-
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *player = itr->getSource();
@@ -1463,7 +1243,6 @@ void Group::SetDifficulty(uint8 difficulty)
player->SendDungeonDifficulty(true);
}
}
-
bool Group::InCombatToInstance(uint32 instanceId)
{
for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
@@ -1476,17 +1255,13 @@ bool Group::InCombatToInstance(uint32 instanceId)
}
return false;
}
-
void Group::ResetInstances(uint8 method, Player* SendMsgTo)
{
if(isBGGroup())
return;
-
// method can be INSTANCE_RESET_ALL, INSTANCE_RESET_CHANGE_DIFFICULTY, INSTANCE_RESET_GROUP_DISBAND
-
// we assume that when the difficulty changes, all instances that can be reset will be
uint8 dif = GetDifficulty();
-
for(BoundInstancesMap::iterator itr = m_boundInstances[dif].begin(); itr != m_boundInstances[dif].end();)
{
InstanceSave *p = itr->second.save;
@@ -1496,7 +1271,6 @@ void Group::ResetInstances(uint8 method, Player* SendMsgTo)
++itr;
continue;
}
-
if(method == INSTANCE_RESET_ALL)
{
// the "reset all instances" method can only reset normal maps
@@ -1506,7 +1280,6 @@ void Group::ResetInstances(uint8 method, Player* SendMsgTo)
continue;
}
}
-
bool isEmpty = true;
// if the map is loaded, reset it
Map *map = MapManager::Instance().FindMap(p->GetMapId(), p->GetInstanceId());
@@ -1517,13 +1290,11 @@ void Group::ResetInstances(uint8 method, Player* SendMsgTo)
else
isEmpty = !map->HavePlayers();
}
-
if(SendMsgTo)
{
if(isEmpty) SendMsgTo->SendResetInstanceSuccess(p->GetMapId());
else SendMsgTo->SendResetInstanceFailed(0, p->GetMapId());
}
-
if(isEmpty || method == INSTANCE_RESET_GROUP_DISBAND || method == INSTANCE_RESET_CHANGE_DIFFICULTY)
{
// do not reset the instance, just unbind if others are permanently bound to it
@@ -1540,20 +1311,17 @@ void Group::ResetInstances(uint8 method, Player* SendMsgTo)
++itr;
}
}
-
InstanceGroupBind* Group::GetBoundInstance(uint32 mapid, uint8 difficulty)
{
// some instances only have one difficulty
const MapEntry* entry = sMapStore.LookupEntry(mapid);
if(!entry || !entry->SupportsHeroicMode()) difficulty = DIFFICULTY_NORMAL;
-
BoundInstancesMap::iterator itr = m_boundInstances[difficulty].find(mapid);
if(itr != m_boundInstances[difficulty].end())
return &itr->second;
else
return NULL;
}
-
InstanceGroupBind* Group::BindToInstance(InstanceSave *save, bool permanent, bool load)
{
if(save && !isBGGroup())
@@ -1567,13 +1335,11 @@ InstanceGroupBind* Group::BindToInstance(InstanceSave *save, bool permanent, boo
}
else
if(!load) CharacterDatabase.PExecute("INSERT INTO group_instance (leaderGuid, instance, permanent) VALUES ('%u', '%u', '%u')", GUID_LOPART(GetLeaderGUID()), save->GetInstanceId(), permanent);
-
if(bind.save != save)
{
if(bind.save) bind.save->RemoveGroup(this);
save->AddGroup(this);
}
-
bind.save = save;
bind.perm = permanent;
if(!load) sLog.outDebug("Group::BindToInstance: %d is now bound to map %d, instance %d, difficulty %d", GUID_LOPART(GetLeaderGUID()), save->GetMapId(), save->GetInstanceId(), save->GetDifficulty());
@@ -1582,7 +1348,6 @@ InstanceGroupBind* Group::BindToInstance(InstanceSave *save, bool permanent, boo
else
return NULL;
}
-
void Group::UnbindInstance(uint32 mapid, uint8 difficulty, bool unload)
{
BoundInstancesMap::iterator itr = m_boundInstances[difficulty].find(mapid);
@@ -1593,7 +1358,6 @@ void Group::UnbindInstance(uint32 mapid, uint8 difficulty, bool unload)
m_boundInstances[difficulty].erase(itr);
}
}
-
void Group::_homebindIfInstance(Player *player)
{
if(player && !player->isGameMaster() && sMapStore.LookupEntry(player->GetMapId())->IsDungeon())
@@ -1606,14 +1370,12 @@ void Group::_homebindIfInstance(Player *player)
player->m_InstanceValid = false;
}
}
-
void Group::BroadcastGroupUpdate(void)
{
// FG: HACK: force flags update on group leave - for values update hack
// -- not very efficient but safe
for(member_citerator citr = m_memberSlots.begin(); citr != m_memberSlots.end(); ++citr)
{
-
Player *pp = objmgr.GetPlayer(citr->guid);
if(pp && pp->IsInWorld())
{