2020-08-20 15:43:37 +00:00
|
|
|
#include "CNShardServer.hpp"
|
|
|
|
#include "CNStructs.hpp"
|
|
|
|
#include "NanoManager.hpp"
|
|
|
|
#include "PlayerManager.hpp"
|
|
|
|
|
|
|
|
void NanoManager::init() {
|
2020-08-21 00:37:34 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_ACTIVE, nanoSummonHandler);
|
2020-08-22 18:02:08 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_EQUIP, nanoEquipHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_UNEQUIP, nanoUnEquipHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GIVE_NANO, nanoGMGiveHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_TUNE, nanoSkillSetHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_NANO_SKILL_USE, nanoSkillUseHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::nanoEquipHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NANO_EQUIP))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_NANO_EQUIP* nano = (sP_CL2FE_REQ_NANO_EQUIP*)data->buf;
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_NANO_EQUIP_SUCC, resp);
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-22 18:02:08 +00:00
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
// sanity check
|
|
|
|
if (nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0)
|
2020-08-23 03:15:27 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iNanoID = nano->iNanoID;
|
|
|
|
resp.iNanoSlotNum = nano->iNanoSlotNum;
|
|
|
|
|
2020-08-23 00:52:54 +00:00
|
|
|
// Update player
|
2020-08-24 22:02:07 +00:00
|
|
|
plr->equippedNanos[nano->iNanoSlotNum] = nano->iNanoID;
|
2020-08-23 00:52:54 +00:00
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
// unsummon nano if replaced
|
|
|
|
if (plr->activeNano == plr->equippedNanos[nano->iNanoSlotNum])
|
|
|
|
summonNano(sock, -1);
|
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_EQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_EQUIP_SUCC));
|
2020-08-22 18:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::nanoUnEquipHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NANO_UNEQUIP))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_NANO_UNEQUIP* nano = (sP_CL2FE_REQ_NANO_UNEQUIP*)data->buf;
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_NANO_UNEQUIP_SUCC, resp);
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-22 23:31:09 +00:00
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
// sanity check
|
|
|
|
if (nano->iNanoSlotNum > 2 || nano->iNanoSlotNum < 0)
|
2020-08-23 03:15:27 +00:00
|
|
|
return;
|
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iNanoSlotNum = nano->iNanoSlotNum;
|
2020-08-22 18:02:08 +00:00
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
// unsummon nano if removed
|
|
|
|
if (plr->equippedNanos[nano->iNanoSlotNum] == plr->activeNano)
|
|
|
|
summonNano(sock, -1);
|
|
|
|
|
2020-08-23 00:52:54 +00:00
|
|
|
// update player
|
2020-08-24 22:02:07 +00:00
|
|
|
plr->equippedNanos[nano->iNanoSlotNum] = 0;
|
2020-08-23 00:52:54 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_UNEQUIP_SUCC, sizeof(sP_FE2CL_REP_NANO_UNEQUIP_SUCC));
|
2020-08-22 18:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::nanoGMGiveHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_GIVE_NANO))
|
|
|
|
return; // ignore the malformed packet
|
|
|
|
|
|
|
|
// Cmd: /nano <nanoId>
|
|
|
|
sP_CL2FE_REQ_PC_GIVE_NANO* nano = (sP_CL2FE_REQ_PC_GIVE_NANO*)data->buf;
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
// Add nano to player
|
|
|
|
addNano(sock, nano->iNanoID, 0);
|
|
|
|
|
|
|
|
DEBUGLOG(
|
2020-08-24 22:02:07 +00:00
|
|
|
std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to add nano id: " << nano->iNanoID << std::endl;
|
2020-08-22 18:02:08 +00:00
|
|
|
)
|
2020-08-20 15:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::nanoSummonHandler(CNSocket* sock, CNPacketData* data) {
|
2020-08-21 00:37:34 +00:00
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NANO_ACTIVE))
|
2020-08-20 23:50:30 +00:00
|
|
|
return; // malformed packet
|
|
|
|
|
2020-08-23 00:52:54 +00:00
|
|
|
sP_CL2FE_REQ_NANO_ACTIVE* pkt = (sP_CL2FE_REQ_NANO_ACTIVE*)data->buf;
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-20 15:43:37 +00:00
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
summonNano(sock, pkt->iNanoSlotNum);
|
2020-08-23 00:52:54 +00:00
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
// Send to client
|
2020-08-22 18:02:08 +00:00
|
|
|
DEBUGLOG(
|
2020-08-24 22:02:07 +00:00
|
|
|
std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to summon nano slot: " << pkt->iNanoSlotNum << std::endl;
|
2020-08-22 18:02:08 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NANO_SKILL_USE))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_NANO_SKILL_USE* skill = (sP_CL2FE_REQ_NANO_SKILL_USE*)data->buf;
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
// Send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_NANO_SKILL_USE_SUCC, resp);
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iArg1 = skill->iArg1;
|
|
|
|
resp.iArg2 = skill->iArg2;
|
|
|
|
resp.iArg3 = skill->iArg3;
|
|
|
|
resp.iBulletID = skill->iBulletID;
|
|
|
|
resp.iTargetCnt = skill->iTargetCnt;
|
2020-08-24 22:02:07 +00:00
|
|
|
resp.iPC_ID = plr->iID;
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iNanoStamina = 150; // Hardcoded for now
|
2020-08-22 18:02:08 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_NANO_SKILL_USE_SUCC, sizeof(sP_FE2CL_NANO_SKILL_USE_SUCC));
|
2020-08-24 22:02:07 +00:00
|
|
|
|
|
|
|
DEBUGLOG(
|
|
|
|
std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " requested to summon nano skill " << std::endl;
|
|
|
|
)
|
2020-08-22 18:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::nanoSkillSetHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_NANO_TUNE))
|
|
|
|
return; // malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_NANO_TUNE* skill = (sP_CL2FE_REQ_NANO_TUNE*)data->buf;
|
|
|
|
setNanoSkill(sock, skill->iNanoID, skill->iTuneID);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma region Helper methods
|
|
|
|
void NanoManager::addNano(CNSocket* sock, int16_t nanoId, int16_t slot) {
|
2020-08-23 03:15:27 +00:00
|
|
|
if (nanoId > 36)
|
|
|
|
return;
|
|
|
|
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
// Send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_NANO_CREATE_SUCC, resp);
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.Nano.iID = nanoId;
|
|
|
|
resp.Nano.iStamina = 150;
|
|
|
|
resp.iQuestItemSlotNum = slot;
|
2020-08-22 18:02:08 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_NANO_CREATE_SUCC, sizeof(sP_FE2CL_REP_PC_NANO_CREATE_SUCC));
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
// Update player
|
2020-08-24 22:02:07 +00:00
|
|
|
plr->Nanos[nanoId] = resp.Nano;
|
2020-09-10 16:51:52 +00:00
|
|
|
|
|
|
|
// After a nano gets added, setting the level seems to be important so we are doing that
|
|
|
|
if (nanoId < plr->level)
|
|
|
|
nanoId = plr->level;
|
|
|
|
// Even if player level is unchanged, this packet still needs to be sent as using /nano always sets the player to 0
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_CHANGE_LEVEL, resp2);
|
|
|
|
|
|
|
|
resp2.iPC_ID = plr->iID;
|
|
|
|
resp2.iPC_Level = nanoId;
|
|
|
|
|
|
|
|
sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL));
|
|
|
|
for (CNSocket* s : PlayerManager::players[sock].viewable)
|
|
|
|
s->sendPacket((void*)&resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL));
|
|
|
|
|
|
|
|
plr->level = nanoId;
|
2020-08-22 18:02:08 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 18:30:20 +00:00
|
|
|
void NanoManager::summonNano(CNSocket *sock, int slot) {
|
|
|
|
INITSTRUCT(sP_FE2CL_REP_NANO_ACTIVE_SUCC, resp);
|
|
|
|
resp.iActiveNanoSlotNum = slot;
|
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_ACTIVE_SUCC, sizeof(sP_FE2CL_REP_NANO_ACTIVE_SUCC));
|
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
|
|
|
|
std::cout << "summon nano\n";
|
|
|
|
|
|
|
|
if (slot > 2 || slot < 0)
|
|
|
|
return; //sanity check
|
|
|
|
|
|
|
|
int nanoId = plr->equippedNanos[slot];
|
|
|
|
|
|
|
|
if (nanoId > 36 || nanoId < 0)
|
|
|
|
return; // sanity check
|
|
|
|
|
|
|
|
sNano nano = plr->Nanos[nanoId];
|
|
|
|
|
|
|
|
// Send to other players
|
|
|
|
INITSTRUCT(sP_FE2CL_NANO_ACTIVE, pkt1);
|
|
|
|
|
|
|
|
pkt1.iPC_ID = plr->iID;
|
|
|
|
pkt1.Nano = nano;
|
|
|
|
|
|
|
|
for (CNSocket* s : PlayerManager::players[sock].viewable)
|
|
|
|
s->sendPacket((void*)&pkt1, P_FE2CL_NANO_ACTIVE, sizeof(sP_FE2CL_NANO_ACTIVE));
|
|
|
|
|
|
|
|
// update player
|
|
|
|
plr->activeNano = nanoId;
|
|
|
|
}
|
|
|
|
|
2020-08-22 18:02:08 +00:00
|
|
|
void NanoManager::setNanoSkill(CNSocket* sock, int16_t nanoId, int16_t skillId) {
|
2020-08-23 03:15:27 +00:00
|
|
|
if (nanoId > 36)
|
|
|
|
return;
|
|
|
|
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
sNano nano = plr->Nanos[nanoId];
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
nano.iSkillID = skillId;
|
2020-08-24 22:02:07 +00:00
|
|
|
plr->Nanos[nanoId] = nano;
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
// Send to client
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_NANO_TUNE_SUCC, resp);
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.iNanoID = nanoId;
|
|
|
|
resp.iSkillID = skillId;
|
2020-08-22 18:02:08 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_NANO_TUNE_SUCC, sizeof(sP_FE2CL_REP_NANO_TUNE_SUCC));
|
2020-08-22 18:02:08 +00:00
|
|
|
|
|
|
|
DEBUGLOG(
|
2020-08-24 22:02:07 +00:00
|
|
|
std::cout << U16toU8(plr->PCStyle.szFirstName) << U16toU8(plr->PCStyle.szLastName) << " set skill id " << skillId << " for nano: " << nanoId << std::endl;
|
2020-08-22 18:02:08 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoId) {
|
2020-08-23 03:15:27 +00:00
|
|
|
if (nanoId > 36)
|
|
|
|
return;
|
2020-08-24 21:04:56 +00:00
|
|
|
|
2020-08-24 22:02:07 +00:00
|
|
|
Player *plr = PlayerManager::getPlayer(sock);
|
|
|
|
sNano nano = plr->Nanos[nanoId];
|
2020-08-22 18:02:08 +00:00
|
|
|
|
2020-08-24 21:04:56 +00:00
|
|
|
// 0 is reset
|
2020-08-22 18:02:08 +00:00
|
|
|
nano.iSkillID = 0;
|
2020-08-24 22:02:07 +00:00
|
|
|
plr->Nanos[nanoId] = nano;
|
2020-08-21 00:37:34 +00:00
|
|
|
}
|
2020-08-23 00:52:54 +00:00
|
|
|
#pragma endregion
|