mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-13 10:10:03 +00:00
Replace group filter operator with function
This commit is contained in:
parent
2a622f901c
commit
6d760f5bce
@ -77,7 +77,7 @@ static void requestGroup(CNSocket* sock, CNPacketData* data) {
|
||||
return;
|
||||
|
||||
// fail if the group is full or the other player is already in a group
|
||||
if ((plr->group != nullptr && (*plr->group)[EntityKind::PLAYER].size() >= 4) || otherPlr->group != nullptr) {
|
||||
if ((plr->group != nullptr && plr->group->filter(EntityKind::PLAYER).size() >= 4) || otherPlr->group != nullptr) {
|
||||
INITSTRUCT(sP_FE2CL_PC_GROUP_INVITE_FAIL, resp);
|
||||
sock->sendPacket((void*)&resp, P_FE2CL_PC_GROUP_INVITE_FAIL, sizeof(sP_FE2CL_PC_GROUP_INVITE_FAIL));
|
||||
return;
|
||||
@ -120,7 +120,7 @@ static void joinGroup(CNSocket* sock, CNPacketData* data) {
|
||||
if (otherPlr == nullptr)
|
||||
return;
|
||||
|
||||
int size = otherPlr->group == nullptr ? 1 : (*otherPlr->group)[EntityKind::PLAYER].size();
|
||||
int size = otherPlr->group == nullptr ? 1 : otherPlr->group->filter(EntityKind::PLAYER).size();
|
||||
|
||||
// fail if the group is full or the other player is already in a group
|
||||
if (plr->group != nullptr || size + 1 > 4) {
|
||||
@ -140,7 +140,7 @@ static void joinGroup(CNSocket* sock, CNPacketData* data) {
|
||||
addToGroup(PlayerManager::getSockFromID(recv->iID_From), otherPlr->group);
|
||||
}
|
||||
addToGroup(sock, otherPlr->group);
|
||||
auto players = (*otherPlr->group)[EntityKind::PLAYER];
|
||||
auto players = otherPlr->group->filter(EntityKind::PLAYER);
|
||||
|
||||
size_t resplen = sizeof(sP_FE2CL_PC_GROUP_JOIN) + players.size() * sizeof(sPCGroupMemberInfo);
|
||||
uint8_t respbuf[CN_PACKET_BUFFER_SIZE];
|
||||
@ -196,7 +196,7 @@ static void leaveGroup(CNSocket* sock, CNPacketData* data) {
|
||||
}
|
||||
|
||||
void Groups::sendToGroup(Group* group, void* buf, uint32_t type, size_t size) {
|
||||
auto players = (*group)[EntityKind::PLAYER];
|
||||
auto players = group->filter(EntityKind::PLAYER);
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
CNSocket* sock = players[i].sock;
|
||||
sock->sendPacket(buf, type, size);
|
||||
@ -205,7 +205,7 @@ void Groups::sendToGroup(Group* group, void* buf, uint32_t type, size_t size) {
|
||||
|
||||
void Groups::groupTickInfo(Player* plr) {
|
||||
|
||||
auto players = (*plr->group)[EntityKind::PLAYER];
|
||||
auto players = plr->group->filter(EntityKind::PLAYER);
|
||||
|
||||
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_MEMBER_INFO), players.size(), sizeof(sPCGroupMemberInfo))) {
|
||||
std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_JOIN packet size\n";
|
||||
@ -280,7 +280,7 @@ void Groups::groupKick(Player* plr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto players = (*group)[EntityKind::PLAYER];
|
||||
auto players = group->filter(EntityKind::PLAYER);
|
||||
|
||||
if (!validOutVarPacket(sizeof(sP_FE2CL_PC_GROUP_LEAVE), players.size() - 1, sizeof(sPCGroupMemberInfo))) {
|
||||
std::cout << "[WARN] bad sP_FE2CL_PC_GROUP_LEAVE packet size\n";
|
||||
@ -307,7 +307,7 @@ void Groups::groupKick(Player* plr) {
|
||||
|
||||
removeFromGroup(sock, group);
|
||||
|
||||
players = (*group)[EntityKind::PLAYER];
|
||||
players = group->filter(EntityKind::PLAYER);
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
CNSocket* sockTo = players[i].sock;
|
||||
Player* varPlr = PlayerManager::getPlayer(sock);
|
||||
|
@ -14,7 +14,7 @@ struct Group {
|
||||
std::vector<EntityRef> members;
|
||||
int32_t conditionBitFlag;
|
||||
|
||||
auto operator[](EntityKind kind) {
|
||||
std::vector<EntityRef> filter(EntityKind kind) {
|
||||
std::vector<EntityRef> filtered;
|
||||
std::copy_if(members.begin(), members.end(), std::back_inserter(filtered), [kind](EntityRef e) {
|
||||
return e.kind == kind;
|
||||
|
@ -851,7 +851,7 @@ void MobAI::onDeath(CombatNPC* npc, EntityRef src) {
|
||||
Missions::mobKilled(src.sock, self->type, qitemRolls);
|
||||
}
|
||||
else {
|
||||
auto players = (*plr->group)[EntityKind::PLAYER];
|
||||
auto players = plr->group->filter(EntityKind::PLAYER);
|
||||
for (EntityRef pRef : players) playerRefs.push_back(PlayerManager::getPlayer(pRef.sock));
|
||||
Combat::genQItemRolls(playerRefs, qitemRolls);
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
|
@ -183,7 +183,7 @@ static void handleWarp(CNSocket* sock, int32_t warpId) {
|
||||
uint64_t instanceID = Warps[warpId].instanceID;
|
||||
|
||||
Player* leader = plr;
|
||||
if (plr->group != nullptr) leader = PlayerManager::getPlayer((*plr->group)[EntityKind::PLAYER][0].sock);
|
||||
if (plr->group != nullptr) leader = PlayerManager::getPlayer(plr->group->filter(EntityKind::PLAYER)[0].sock);
|
||||
|
||||
// if warp requires you to be on a mission, it's gotta be a unique instance
|
||||
if (Warps[warpId].limitTaskID != 0 || instanceID == 14) { // 14 is a special case for the Time Lab
|
||||
@ -200,7 +200,7 @@ static void handleWarp(CNSocket* sock, int32_t warpId) {
|
||||
if (plr->group == nullptr)
|
||||
PlayerManager::sendPlayerTo(sock, Warps[warpId].x, Warps[warpId].y, Warps[warpId].z, instanceID);
|
||||
else {
|
||||
auto players = (*plr->group)[EntityKind::PLAYER];
|
||||
auto players = plr->group->filter(EntityKind::PLAYER);
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
CNSocket* sockTo = players[i].sock;
|
||||
Player* otherPlr = PlayerManager::getPlayer(sockTo);
|
||||
|
Loading…
Reference in New Issue
Block a user