[9338] Simplify group loading code.

This commit is contained in:
VladimirMangos 2010-02-09 08:48:21 +03:00
parent 9c346fc0a9
commit b50c3a9355
4 changed files with 27 additions and 59 deletions

View file

@ -124,71 +124,40 @@ bool Group::Create(const uint64 &guid, const char * name)
return true; return true;
} }
bool Group::LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result, bool loadMembers) bool Group::LoadGroupFromDB(Field* fields)
{ {
if(isBGGroup()) // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
return false; // result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups");
bool external = true; m_leaderGuid = MAKE_NEW_GUID(fields[16].GetUInt32(),0,HIGHGUID_PLAYER);
if(!result)
{
external = false;
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
result = CharacterDatabase.PQuery("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty FROM groups WHERE leaderGuid ='%u'", GUID_LOPART(leaderGuid));
if(!result)
return false;
}
m_leaderGuid = leaderGuid;
// group leader not exist // group leader not exist
if(!sObjectMgr.GetPlayerNameByGUID(m_leaderGuid, m_leaderName)) if(!sObjectMgr.GetPlayerNameByGUID(m_leaderGuid, m_leaderName))
{
if(!external) delete result;
return false; return false;
}
m_groupType = (*result)[13].GetBool() ? GROUPTYPE_RAID : GROUPTYPE_NORMAL; m_groupType = fields[13].GetBool() ? GROUPTYPE_RAID : GROUPTYPE_NORMAL;
if (m_groupType == GROUPTYPE_RAID) if (m_groupType == GROUPTYPE_RAID)
_initRaidSubGroupsCounter(); _initRaidSubGroupsCounter();
uint32 diff = (*result)[14].GetUInt8(); uint32 diff = fields[14].GetUInt8();
if (diff >= MAX_DUNGEON_DIFFICULTY) if (diff >= MAX_DUNGEON_DIFFICULTY)
diff = DUNGEON_DIFFICULTY_NORMAL; diff = DUNGEON_DIFFICULTY_NORMAL;
m_dungeonDifficulty = Difficulty(diff); m_dungeonDifficulty = Difficulty(diff);
uint32 r_diff = (*result)[15].GetUInt8(); uint32 r_diff = fields[15].GetUInt8();
if (r_diff >= MAX_RAID_DIFFICULTY) if (r_diff >= MAX_RAID_DIFFICULTY)
r_diff = RAID_DIFFICULTY_10MAN_NORMAL; r_diff = RAID_DIFFICULTY_10MAN_NORMAL;
m_raidDifficulty = Difficulty(r_diff); m_raidDifficulty = Difficulty(r_diff);
m_mainTank = (*result)[0].GetUInt64(); m_mainTank = fields[0].GetUInt64();
m_mainAssistant = (*result)[1].GetUInt64(); m_mainAssistant = fields[1].GetUInt64();
m_lootMethod = (LootMethod)(*result)[2].GetUInt8(); m_lootMethod = (LootMethod)fields[2].GetUInt8();
m_looterGuid = MAKE_NEW_GUID((*result)[3].GetUInt32(), 0, HIGHGUID_PLAYER); m_looterGuid = MAKE_NEW_GUID(fields[3].GetUInt32(), 0, HIGHGUID_PLAYER);
m_lootThreshold = (ItemQualities)(*result)[4].GetUInt16(); m_lootThreshold = (ItemQualities)fields[4].GetUInt16();
for(int i = 0; i < TARGETICONCOUNT; ++i) for(int i = 0; i < TARGETICONCOUNT; ++i)
m_targetIcons[i] = (*result)[5+i].GetUInt64(); m_targetIcons[i] = fields[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());
} while( result->NextRow() );
delete result;
// group too small
if(GetMembersCount() < 2)
return false;
}
m_Id = sObjectMgr.GenerateGroupId(); m_Id = sObjectMgr.GenerateGroupId();
return true; return true;

View file

@ -163,7 +163,7 @@ class MANGOS_DLL_SPEC Group
// group manipulation methods // group manipulation methods
bool Create(const uint64 &guid, const char * name); bool Create(const uint64 &guid, const char * name);
bool LoadGroupFromDB(const uint64 &leaderGuid, QueryResult *result = NULL, bool loadMembers = true); bool LoadGroupFromDB(Field *fields);
bool LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant); bool LoadMemberFromDB(uint32 guidLow, uint8 subgroup, bool assistant);
bool AddInvite(Player *player); bool AddInvite(Player *player);
uint32 RemoveInvite(Player *player); uint32 RemoveInvite(Player *player);

View file

@ -3124,7 +3124,7 @@ void ObjectMgr::LoadGroups()
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
QueryResult *result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups"); QueryResult *result = CharacterDatabase.Query("SELECT mainTank, mainAssistant, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, isRaid, difficulty, raiddifficulty, leaderGuid FROM groups");
if( !result ) if (!result)
{ {
barGoLink bar( 1 ); barGoLink bar( 1 );
@ -3144,16 +3144,15 @@ void ObjectMgr::LoadGroups()
bar.step(); bar.step();
Field *fields = result->Fetch(); Field *fields = result->Fetch();
++count; ++count;
uint64 leaderGuid = MAKE_NEW_GUID(fields[16].GetUInt32(),0,HIGHGUID_PLAYER);
Group *group = new Group; Group *group = new Group;
if(!group->LoadGroupFromDB(leaderGuid, result, false)) if (!group->LoadGroupFromDB(fields))
{ {
group->Disband(); group->Disband();
delete group; delete group;
continue; continue;
} }
AddGroup(group); AddGroup(group);
leader2groupMap[GUID_LOPART(leaderGuid)] = group->GetId(); leader2groupMap[GUID_LOPART(group->GetLeaderGUID())] = group->GetId();
}while( result->NextRow() ); }while( result->NextRow() );
delete result; delete result;
@ -3165,7 +3164,7 @@ void ObjectMgr::LoadGroups()
count = 0; count = 0;
// 0 1 2 3 // 0 1 2 3
result = CharacterDatabase.Query("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid"); result = CharacterDatabase.Query("SELECT memberGuid, assistant, subgroup, leaderGuid FROM group_member ORDER BY leaderGuid");
if(!result) if (!result)
{ {
barGoLink bar2( 1 ); barGoLink bar2( 1 );
bar2.step(); bar2.step();
@ -3185,14 +3184,14 @@ void ObjectMgr::LoadGroups()
bool assistent = fields[1].GetBool(); bool assistent = fields[1].GetBool();
uint8 subgroup = fields[2].GetUInt8(); uint8 subgroup = fields[2].GetUInt8();
uint32 leaderGuidLow = fields[3].GetUInt32(); uint32 leaderGuidLow = fields[3].GetUInt32();
if(!group || GUID_LOPART(group->GetLeaderGUID()) != leaderGuidLow) if (!group || GUID_LOPART(group->GetLeaderGUID()) != leaderGuidLow)
{ {
// find group id in map by leader low guid // find group id in map by leader low guid
std::map<uint32,uint32>::const_iterator l2g_itr = leader2groupMap.find(leaderGuidLow); std::map<uint32,uint32>::const_iterator l2g_itr = leader2groupMap.find(leaderGuidLow);
if (l2g_itr != leader2groupMap.end()) if (l2g_itr != leader2groupMap.end())
group = GetGroupById(l2g_itr->second); group = GetGroupById(l2g_itr->second);
if(!group) if (!group)
{ {
sLog.outErrorDb("Incorrect entry in group_member table : no group with leader %d for member %d!", leaderGuidLow, memberGuidlow); sLog.outErrorDb("Incorrect entry in group_member table : no group with leader %d for member %d!", leaderGuidLow, memberGuidlow);
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", memberGuidlow); CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", memberGuidlow);
@ -3200,7 +3199,7 @@ void ObjectMgr::LoadGroups()
} }
} }
if(!group->LoadMemberFromDB(memberGuidlow, subgroup, assistent)) if (!group->LoadMemberFromDB(memberGuidlow, subgroup, assistent))
{ {
sLog.outErrorDb("Incorrect entry in group_member table : member %d cannot be added to player %d's group!", memberGuidlow, leaderGuidLow); sLog.outErrorDb("Incorrect entry in group_member table : member %d cannot be added to player %d's group!", memberGuidlow, leaderGuidLow);
CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", memberGuidlow); CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid = '%d'", memberGuidlow);
@ -3233,7 +3232,7 @@ void ObjectMgr::LoadGroups()
"FROM group_instance LEFT JOIN instance ON instance = id ORDER BY leaderGuid" "FROM group_instance LEFT JOIN instance ON instance = id ORDER BY leaderGuid"
); );
if(!result) if (!result)
{ {
barGoLink bar2( 1 ); barGoLink bar2( 1 );
bar2.step(); bar2.step();
@ -3253,14 +3252,14 @@ void ObjectMgr::LoadGroups()
uint32 mapId = fields[1].GetUInt32(); uint32 mapId = fields[1].GetUInt32();
Difficulty diff = (Difficulty)fields[4].GetUInt8(); Difficulty diff = (Difficulty)fields[4].GetUInt8();
if(!group || GUID_LOPART(group->GetLeaderGUID()) != leaderGuidLow) if (!group || GUID_LOPART(group->GetLeaderGUID()) != leaderGuidLow)
{ {
// find group id in map by leader low guid // find group id in map by leader low guid
std::map<uint32,uint32>::const_iterator l2g_itr = leader2groupMap.find(leaderGuidLow); std::map<uint32,uint32>::const_iterator l2g_itr = leader2groupMap.find(leaderGuidLow);
if (l2g_itr != leader2groupMap.end()) if (l2g_itr != leader2groupMap.end())
group = GetGroupById(l2g_itr->second); group = GetGroupById(l2g_itr->second);
if(!group) if (!group)
{ {
sLog.outErrorDb("Incorrect entry in group_instance table : no group with leader %d", leaderGuidLow); sLog.outErrorDb("Incorrect entry in group_instance table : no group with leader %d", leaderGuidLow);
continue; continue;
@ -3268,13 +3267,13 @@ void ObjectMgr::LoadGroups()
} }
MapEntry const* mapEntry = sMapStore.LookupEntry(mapId); MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
if(!mapEntry || !mapEntry->IsDungeon()) if (!mapEntry || !mapEntry->IsDungeon())
{ {
sLog.outErrorDb("Incorrect entry in group_instance table : no dungeon map %d", mapId); sLog.outErrorDb("Incorrect entry in group_instance table : no dungeon map %d", mapId);
continue; continue;
} }
if(diff >= (mapEntry->IsRaid() ? MAX_RAID_DIFFICULTY : MAX_DUNGEON_DIFFICULTY)) if (diff >= (mapEntry->IsRaid() ? MAX_RAID_DIFFICULTY : MAX_DUNGEON_DIFFICULTY))
{ {
sLog.outErrorDb("Wrong dungeon difficulty use in group_instance table: %d", diff + 1); sLog.outErrorDb("Wrong dungeon difficulty use in group_instance table: %d", diff + 1);
diff = REGULAR_DIFFICULTY; // default for both difficaly types diff = REGULAR_DIFFICULTY; // default for both difficaly types

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9337" #define REVISION_NR "9338"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__