diff --git a/src/Combat.cpp b/src/Combat.cpp index 952c122..31fe980 100644 --- a/src/Combat.cpp +++ b/src/Combat.cpp @@ -259,16 +259,10 @@ void Combat::npcAttackPc(Mob *mob, time_t currTime) { * single RNG roll per mission task, and every group member shares that same * set of rolls. */ -void Combat::genQItemRolls(Player *leader, std::map& rolls) { - auto players = (*leader->group)[EntityKind::PLAYER]; +void Combat::genQItemRolls(std::vector players, std::map& rolls) { for (int i = 0; i < players.size(); i++) { - CNSocket *otherSock = players[i].sock; - if (otherSock == nullptr) - continue; - - Player *member = PlayerManager::getPlayer(otherSock); - + Player* member = players[i]; for (int j = 0; j < ACTIVE_MISSION_COUNT; j++) if (member->tasks[j] != 0) rolls[member->tasks[j]] = Rand::rand(); diff --git a/src/Combat.hpp b/src/Combat.hpp index 14d0076..5b53c86 100644 --- a/src/Combat.hpp +++ b/src/Combat.hpp @@ -25,5 +25,5 @@ namespace Combat { void init(); void npcAttackPc(Mob *mob, time_t currTime); - void genQItemRolls(Player* leader, std::map& rolls); + void genQItemRolls(std::vector players, std::map& rolls); } diff --git a/src/Groups.cpp b/src/Groups.cpp index 605beef..ba85d4c 100644 --- a/src/Groups.cpp +++ b/src/Groups.cpp @@ -120,14 +120,16 @@ static void joinGroup(CNSocket* sock, CNPacketData* data) { if (otherPlr == nullptr) return; + int size = otherPlr->group == nullptr ? 1 : (*otherPlr->group)[EntityKind::PLAYER].size(); + // fail if the group is full or the other player is already in a group - if (plr->group != nullptr || (otherPlr->group != nullptr && (*otherPlr->group)[EntityKind::PLAYER].size() >= 4)) { + if (plr->group != nullptr || size + 1 > 4) { INITSTRUCT(sP_FE2CL_PC_GROUP_JOIN_FAIL, resp); sock->sendPacket((void*)&resp, P_FE2CL_PC_GROUP_JOIN_FAIL, sizeof(sP_FE2CL_PC_GROUP_JOIN_FAIL)); return; } - if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_JOIN), (*otherPlr->group)[EntityKind::PLAYER].size() + 1, sizeof(sPCGroupMemberInfo))) { + if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_JOIN), size + 1, sizeof(sPCGroupMemberInfo))) { std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_JOIN packet size\n"; return; } diff --git a/src/MobAI.cpp b/src/MobAI.cpp index 6d71e81..1c9b860 100644 --- a/src/MobAI.cpp +++ b/src/MobAI.cpp @@ -842,16 +842,18 @@ void MobAI::onDeath(CombatNPC* npc, EntityRef src) { Items::DropRoll rolled; Items::DropRoll eventRolled; std::map qitemRolls; + std::vector playerRefs; if (plr->group == nullptr) { - Combat::genQItemRolls(plr, qitemRolls); + playerRefs.push_back(plr); + Combat::genQItemRolls(playerRefs, qitemRolls); Items::giveMobDrop(src.sock, self, rolled, eventRolled); Missions::mobKilled(src.sock, self->type, qitemRolls); } else { auto players = (*plr->group)[EntityKind::PLAYER]; - Player* leader = PlayerManager::getPlayer(players[0].sock); - Combat::genQItemRolls(leader, qitemRolls); + for (EntityRef pRef : players) playerRefs.push_back(PlayerManager::getPlayer(pRef.sock)); + Combat::genQItemRolls(playerRefs, qitemRolls); for (int i = 0; i < players.size(); i++) { CNSocket* sockTo = players[i].sock; Player* otherPlr = PlayerManager::getPlayer(sockTo); diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index 83939d8..61e11cc 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -46,7 +46,8 @@ void PlayerManager::removePlayer(CNSocket* key) { Player* plr = getPlayer(key); uint64_t fromInstance = plr->instanceID; - Groups::groupKick(plr); + if(plr->group != nullptr) + Groups::groupKick(plr); // remove player's bullets Combat::Bullets.erase(plr->iID);