From 6129c0b4e28aaa0fef2ddaf77157c082a6729768 Mon Sep 17 00:00:00 2001 From: dongresource <69976329+dongresource@users.noreply.github.com> Date: Sun, 23 Aug 2020 02:52:54 +0200 Subject: [PATCH] Players can now see eachother's nanos. (#28) --- src/NanoManager.cpp | 35 +++++++++++++++++++++++++++++++---- src/Player.hpp | 6 ++++-- src/PlayerManager.cpp | 4 +++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/NanoManager.cpp b/src/NanoManager.cpp index 0b7ef25..a918c45 100644 --- a/src/NanoManager.cpp +++ b/src/NanoManager.cpp @@ -18,10 +18,15 @@ void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_NANO_EQUIP* nano = (sP_CL2FE_REQ_NANO_EQUIP*)data->buf; INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp); + Player plr = PlayerManager::getPlayer(sock); resp.iNanoID = nano->iNanoID; resp.iNanoSlotNum = nano->iNanoSlotNum; + // Update player + plr.equippedNanos[nano->iNanoSlotNum] = nano->iNanoID; + PlayerManager::updatePlayer(sock, plr); + sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC)); } @@ -31,9 +36,14 @@ void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) { sP_CL2FE_REQ_NANO_UNEQUIP* nano = (sP_CL2FE_REQ_NANO_UNEQUIP*)data->buf; INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp); + Player plr = PlayerManager::getPlayer(sock); resp.iNanoSlotNum = nano->iNanoSlotNum; + // update player + plr.equippedNanos[nano->iNanoSlotNum] = 0; + PlayerManager::updatePlayer(sock, plr); + sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_UNEQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC)); } @@ -57,16 +67,33 @@ void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_NANO_ACTIVE)) return; // malformed packet - sP_CL2FE_REQ_NANO_ACTIVE* nano = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf; + sP_CL2FE_REQ_NANO_ACTIVE* pkt = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf; PlayerView plr = PlayerManager::players[sock]; // Send to client INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp); - resp.iActiveNanoSlotNum = nano->iNanoSlotNum; + resp.iActiveNanoSlotNum = pkt->iNanoSlotNum; sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC)); + int nanoId = plr.plr.equippedNanos[pkt->iNanoSlotNum]; + sNano nano = plr.plr.Nanos[nanoId]; + + // Send to other players + for (CNSocket *s : PlayerManager::players[sock].viewable) { + INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt); + + pkt.iPC_ID = plr.plr.iID; + pkt.Nano = nano; + + s->sendPacket((void*)&pkt, P_FE2CL_NANO_ACTIVE, sizeof(sP_FE2CL_NANO_ACTIVE)); + } + + // update player + plr.plr.nano = nanoId; + PlayerManager::updatePlayer(sock, plr.plr); + DEBUGLOG( - std::cout << U16toU8(plr.plr.PCStyle.szFirstName) << U16toU8(plr.plr.PCStyle.szLastName) << " requested to summon nano slot: " << nano->iNanoSlotNum << std::endl; + std::cout << U16toU8(plr.plr.PCStyle.szFirstName) << U16toU8(plr.plr.PCStyle.szLastName) << " requested to summon nano slot: " << pkt->iNanoSlotNum << std::endl; ) } @@ -151,4 +178,4 @@ void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoId) { // Update the player PlayerManager::updatePlayer(sock, plr); } -#pragma endregion \ No newline at end of file +#pragma endregion diff --git a/src/Player.hpp b/src/Player.hpp index 9c3c001..c80af83 100644 --- a/src/Player.hpp +++ b/src/Player.hpp @@ -14,10 +14,12 @@ struct Player { int level; int HP; - int slot; + int slot; // player slot, not nano slot sPCStyle PCStyle; sPCStyle2 PCStyle2; sNano Nanos[37]; + int equippedNanos[3]; + int nano; // active nano (index into Nanos) int x, y, z, angle; sItemBase Equip[AEQUIP_COUNT]; @@ -25,4 +27,4 @@ struct Player { bool IsGM; }; -#endif \ No newline at end of file +#endif diff --git a/src/PlayerManager.cpp b/src/PlayerManager.cpp index b8f8b80..d3835b6 100644 --- a/src/PlayerManager.cpp +++ b/src/PlayerManager.cpp @@ -125,6 +125,7 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { newPlayer.PCAppearanceData.iZ = plr.z; newPlayer.PCAppearanceData.iAngle = plr.angle; newPlayer.PCAppearanceData.PCStyle = plr.PCStyle; + newPlayer.PCAppearanceData.Nano = plr.Nanos[plr.nano]; memcpy(newPlayer.PCAppearanceData.ItemEquip, plr.Equip, sizeof(sItemBase) * AEQUIP_COUNT); otherSock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW)); @@ -137,6 +138,7 @@ void PlayerManager::updatePlayerPosition(CNSocket* sock, int X, int Y, int Z) { newPlayer.PCAppearanceData.iZ = otherPlr.z; newPlayer.PCAppearanceData.iAngle = otherPlr.angle; newPlayer.PCAppearanceData.PCStyle = otherPlr.PCStyle; + newPlayer.PCAppearanceData.Nano = otherPlr.Nanos[otherPlr.nano]; memcpy(newPlayer.PCAppearanceData.ItemEquip, otherPlr.Equip, sizeof(sItemBase) * AEQUIP_COUNT); sock->sendPacket((void*)&newPlayer, P_FE2CL_PC_NEW, sizeof(sP_FE2CL_PC_NEW)); @@ -552,4 +554,4 @@ void PlayerManager::updatePlayer(CNSocket* key, Player plr) { plrv.plr = plr; players[key] = plrv; -} \ No newline at end of file +}