void CreatureGroup::MemberAttackStart(Creature *member, Unit *target) { if (!member || !target) return; const CreatureGroupInfoType::iterator fInfo = CreatureGroupMap.find(member->GetDBTableGUIDLow()); if (fInfo == CreatureGroupMap.end() || !fInfo->second) return; uint8 groupAI = fInfo->second->groupAI; if (!groupAI) return; if (groupAI == 1 && member != m_leader) return; for (CreatureGroupMemberType::iterator itr = m_members.begin(); itr != m_members.end(); ++itr) { sLog.outDebug("GROUP ATTACK: group instance id %u calls member instid %u", m_leader ? m_leader->GetInstanceId() : 0, member->GetInstanceId()); //sLog.outDebug("AI:%u:Group member found: %u, attacked by %s.", groupAI, itr->second->GetGUIDLow(), member->getVictim()->GetName()); //Skip one check if (itr->first == member->GetGUID()) continue; if (Creature *mem = member->GetMap()->GetCreature(itr->first)) { if (!mem->isAlive()) continue; if (mem->getVictim()) continue; if (mem->canAttack(target)) mem->AI()->AttackStart(target); } } m_Respawned = false; m_Evaded = false; }
void CreatureGroupManager::LoadCreatureFormations() { uint32 oldMSTime = getMSTime(); for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr) // for reload case delete itr->second; CreatureGroupMap.clear(); //Get group data QueryResult result = WorldDatabase.Query("SELECT leaderGUID, memberGUID, dist, angle, groupAI FROM creature_formations ORDER BY leaderGUID"); if (!result) { sLog->outErrorDb(">> Loaded 0 creatures in formations. DB table `creature_formations` is empty!"); sLog->outString(); return; } std::set<uint32> guidSet; QueryResult guidResult = WorldDatabase.PQuery("SELECT guid FROM creature"); if (guidResult) { do { Field* fields = guidResult->Fetch(); uint32 guid = fields[0].GetUInt32(); guidSet.insert(guid); } while (guidResult->NextRow()); } uint32 count = 0; Field* fields; FormationInfo *group_member; do { fields = result->Fetch(); //Load group member data group_member = new FormationInfo; group_member->leaderGUID = fields[0].GetUInt32(); uint32 memberGUID = fields[1].GetUInt32(); group_member->groupAI = fields[4].GetUInt8(); //If creature is group leader we may skip loading of dist/angle if (group_member->leaderGUID != memberGUID) { group_member->follow_dist = fields[2].GetFloat(); group_member->follow_angle = fields[3].GetFloat() * M_PI / 180; } else { group_member->follow_dist = 0; group_member->follow_angle = 0; } // check data correctness { if (guidSet.find(group_member->leaderGUID) == guidSet.end()) { sLog->outErrorDb("creature_formations table leader guid %u incorrect (not exist)", group_member->leaderGUID); delete group_member; continue; } if (guidSet.find(memberGUID) == guidSet.end()) { sLog->outErrorDb("creature_formations table member guid %u incorrect (not exist)", memberGUID); delete group_member; continue; } } CreatureGroupMap[memberGUID] = group_member; ++count; } while (result->NextRow()) ; sLog->outString(">> Loaded %u creatures in formations in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); sLog->outString(); }
void CreatureGroupManager::LoadCreatureGroups() { uint32 oldMSTime = getMSTime(); for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr) // for reload case delete itr->second; CreatureGroupMap.clear(); CreatureGroupDataMap.clear(); //Check if groups without member exist PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_CREGROUPS_WITHOUT_DATA); PreparedQueryResult result = WorldDatabase.Query(stmt); if (result) sLog->outDetail(">> %u Groups without member found, groups skipped.",result->Fetch()->GetInt32()); //Check if member without group exist stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_CREGROUP_DATA_WITHOUT_GROUP); result = WorldDatabase.Query(stmt); if (result) sLog->outDetail(">> %u Member without group found, member skipped.",result->Fetch()->GetInt32()); //Get groups stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_CREGROUPS); PreparedQueryResult result_data = WorldDatabase.Query(stmt); if (!result_data) { sLog->outString(">> Loaded 0 creature groups. DB table `creature_groups` is empty."); sLog->outString(); return; } //Get member stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_CREGROUP_DATA); PreparedQueryResult result_member = WorldDatabase.Query(stmt); if (!result_member) { sLog->outString(">> Loaded 0 creature groups. DB table `creature_group_data` is empty."); sLog->outString(); return; } std::set<uint32> guidSet; stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_CREATURE_GUIDS); PreparedQueryResult guidResult = WorldDatabase.Query(stmt); if (guidResult) { do { Field* fields = guidResult->Fetch(); uint32 guid = fields[0].GetUInt32(); guidSet.insert(guid); } while (guidResult->NextRow()); } //Loading groups... uint32 group_count = 0; GroupInfo* group_member; do { Field* fields = result_data->Fetch(); //Load group member data uint32 groupId = fields[0].GetUInt32(); uint32 leaderGUID = fields[1].GetUInt32(); uint8 groupType = fields[2].GetUInt8(); group_member = new GroupInfo; group_member->leaderGUID = leaderGUID; group_member->groupType = groupType; // check data correctness if (guidSet.find(group_member->leaderGUID) == guidSet.end()) { sLog->outErrorDb("creature_groups table leader guid %u incorrect (not exist)", group_member->leaderGUID); delete group_member; return; } CreatureGroupMap[groupId] = group_member; sLog->outDebug(LOG_FILTER_UNITS, "CreatureGroup::LoadCreatureGroups: Load Group %u with Leader %u and groupType %u.", groupId, leaderGUID, groupType); ++group_count; } while (result_data->NextRow()) ; //Loading member... uint32 member_count = 0; do { Field* fields = result_member->Fetch(); //Load group member data uint32 groupId = fields[0].GetUInt32(); uint32 memberGUID = fields[1].GetUInt32(); // check data correctness if (guidSet.find(memberGUID) == guidSet.end()) { sLog->outErrorDb("creature_group_data table member guid %u incorrect (not exist)", memberGUID); continue; } CreatureGroupDataMap[memberGUID] = groupId; sLog->outDebug(LOG_FILTER_UNITS, "CreatureGroup::LoadCreatureGroups: Load Member %u for Group with groupId %u.", memberGUID, groupId); ++member_count; } while (result->NextRow()) ; sLog->outString(">> Loaded %u creatures in %u groups in %u ms", member_count, group_count, GetMSTimeDiffToNow(oldMSTime)); sLog->outString(); }
void CreatureGroupManager::LoadCreatureGroups() { //Clear existing map for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr) delete itr->second; CreatureGroupMap.clear(); CreatureGroupDataMap.clear(); //Check Integrity of the table QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(groupId) FROM creature_groups"); if (!result) { sLog.outErrorDb(" ...an error occured while loading the table creature_groups (maybe it doesn't exist ?)\n"); return; } //Get group data result = WorldDatabase.Query("SELECT MAX(groupId) FROM creature_group_data"); if (!result) { sLog.outErrorDb(" ...an error occured while loading the table creature_group_data (maybe it doesn't exist ?)\n"); return; } //Check if groups without member exist result = WorldDatabase.Query("SELECT COUNT(groupId) FROM creature_groups WHERE groupId NOT IN (SELECT groupId FROM creature_group_data)"); if (result) { sLog.outDetail(">> %u Groups without member found, groups skipped.",result->Fetch()->GetInt32()); } //Check if member without group exist result = WorldDatabase.Query("SELECT COUNT(groupId) FROM creature_group_data WHERE groupId NOT IN (SELECT groupId FROM creature_groups)"); if (result) { sLog.outDetail(">> %u Member without group found, member skipped.",result->Fetch()->GetInt32()); } //Get groups QueryResult_AutoPtr result_data = WorldDatabase.Query("SELECT groupId, leaderGUID, groupType FROM creature_groups WHERE groupId IN (SELECT groupId FROM creature_group_data) ORDER BY groupId"); if (!result_data) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded 0 creature groups. DB table `creature_groups` is empty."); return; } //Get member QueryResult_AutoPtr result_member = WorldDatabase.Query("SELECT groupId, memberGUID FROM creature_group_data WHERE groupId IN (SELECT groupId FROM creature_groups) ORDER BY groupId"); if (!result_member) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded 0 creature groups. DB table `creature_group_data` is empty."); return; } //Loading groups... uint64 total_groups = result_data->GetRowCount(); uint64 total_member = result_member->GetRowCount(); barGoLink bar(total_groups+total_member); Field *fields; std::set<uint32> guidSet; GroupInfo *group_member; do { fields = result_data->Fetch(); bar.step(); //Load group member data uint32 groupId = fields[0].GetUInt32(); uint32 leaderGUID = fields[1].GetUInt32(); uint8 groupType = fields[2].GetUInt8(); group_member = new GroupInfo; group_member->leaderGUID = leaderGUID; group_member->groupType = groupType; // check data correctness if (guidSet.find(group_member->leaderGUID) == guidSet.end()) { sLog.outErrorDb("creature_groups table leader guid %u incorrect (not exist)", group_member->leaderGUID); delete group_member; return; } CreatureGroupMap[groupId] = group_member; sLog.outDebug("CreatureGroup::LoadCreatureGroups: Load Group %u with Leader %u and groupType %u.", groupId, leaderGUID, groupType); } while (result_data->NextRow()) ; //Loading member... do { fields = result_member->Fetch(); bar.step(); //Load group member data uint32 groupId = fields[0].GetUInt32(); uint32 memberGUID = fields[1].GetUInt32(); // check data correctness if (guidSet.find(memberGUID) == guidSet.end()) { sLog.outErrorDb("creature_group_data table member guid %u incorrect (not exist)", memberGUID); continue; } CreatureGroupDataMap[memberGUID] = groupId; sLog.outDebug("CreatureGroup::LoadCreatureGroups: Load Member %u for Group with groupId %u.", memberGUID, groupId); } while (result_member->NextRow()) ; sLog.outString(); sLog.outString(">> Loaded " UI64FMTD " groups", total_groups); sLog.outString(">> Loaded " UI64FMTD " creatures in groups", total_member); sLog.outString(); }
void CreatureGroupManager::LoadCreatureFormations() { //Clear existing map for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr) delete itr->second; CreatureGroupMap.clear(); //Check Integrity of the table QueryResult result = WorldDatabase.Query("SELECT MAX(leaderGUID) FROM creature_formations"); if (!result) { sLog->outErrorDb(" ...an error occured while loading the table creature_formations (maybe it doesn't exist ?)\n"); return; } //Get group data result = WorldDatabase.Query("SELECT leaderGUID, memberGUID, dist, angle, groupAI FROM creature_formations ORDER BY leaderGUID"); if (!result) { sLog->outErrorDb("The table creature_formations is empty or corrupted"); return; } std::set<uint32> guidSet; QueryResult guidResult = WorldDatabase.PQuery("SELECT guid FROM creature"); if (guidResult) { do { Field *fields = guidResult->Fetch(); uint32 guid = fields[0].GetUInt32(); guidSet.insert(guid); } while (guidResult->NextRow()); } uint64 total_records = result->GetRowCount(); Field *fields; FormationInfo *group_member; //Loading data... do { fields = result->Fetch(); //Load group member data group_member = new FormationInfo; group_member->leaderGUID = fields[0].GetUInt32(); uint32 memberGUID = fields[1].GetUInt32(); group_member->groupAI = fields[4].GetUInt8(); //If creature is group leader we may skip loading of dist/angle if (group_member->leaderGUID != memberGUID) { group_member->follow_dist = fields[2].GetFloat(); group_member->follow_angle = fields[3].GetFloat() * M_PI / 180; } else { group_member->follow_dist = 0; group_member->follow_angle = 0; } // check data correctness { if (guidSet.find(group_member->leaderGUID) == guidSet.end()) { sLog->outErrorDb("creature_formations table leader guid %u incorrect (not exist)", group_member->leaderGUID); delete group_member; continue; } if (guidSet.find(memberGUID) == guidSet.end()) { sLog->outErrorDb("creature_formations table member guid %u incorrect (not exist)", memberGUID); delete group_member; continue; } } CreatureGroupMap[memberGUID] = group_member; } while (result->NextRow()) ; sLog->outString(); sLog->outString(">> Loaded " UI64FMTD " creatures in formations", total_records); sLog->outString(); }