Nano refactor cleanup

sanity checks and int[] -> vector<int>
This commit is contained in:
Gent S 2020-11-26 23:46:29 -05:00
parent 7851866d13
commit 36d6231da4
3 changed files with 15 additions and 14 deletions

View File

@ -954,7 +954,7 @@ void MobManager::playerTick(CNServer *serv, time_t currTime) {
// passive nano unbuffing // passive nano unbuffing
int skillID = plr->Nanos[plr->activeNano].iSkillID; int skillID = plr->Nanos[plr->activeNano].iSkillID;
if (NanoManager::SkillTable[skillID].drainType == 2) { if (NanoManager::SkillTable[skillID].drainType == 2) {
int* targetData = NanoManager::findTargets(plr, skillID); std::vector<int> targetData = NanoManager::findTargets(plr, skillID);
for (auto& pwr : NanoManager::NanoPowers) for (auto& pwr : NanoManager::NanoPowers)
if (pwr.skillType == NanoManager::SkillTable[skillID].skillType) if (pwr.skillType == NanoManager::SkillTable[skillID].skillType)

View File

@ -135,7 +135,7 @@ void NanoManager::nanoSkillUseHandler(CNSocket* sock, CNPacketData* data) {
std::cout << PlayerManager::getPlayerName(plr) << " requested to summon nano skill " << std::endl; std::cout << PlayerManager::getPlayerName(plr) << " requested to summon nano skill " << std::endl;
) )
int *targetData = findTargets(plr, skillID, data); std::vector<int> targetData = findTargets(plr, skillID, data);
int boost = 0; int boost = 0;
if (getNanoBoost(plr)) if (getNanoBoost(plr))
@ -304,7 +304,7 @@ void NanoManager::summonNano(CNSocket *sock, int slot) {
// passive nano unbuffing // passive nano unbuffing
if (SkillTable[skillID].drainType == 2) { if (SkillTable[skillID].drainType == 2) {
int *targetData = findTargets(plr, skillID); std::vector<int> targetData = findTargets(plr, skillID);
for (auto& pwr : NanoPowers) for (auto& pwr : NanoPowers)
if (pwr.skillType == SkillTable[skillID].skillType) if (pwr.skillType == SkillTable[skillID].skillType)
@ -322,7 +322,7 @@ void NanoManager::summonNano(CNSocket *sock, int slot) {
// passive nano buffing // passive nano buffing
if (SkillTable[skillID].drainType == 2) { if (SkillTable[skillID].drainType == 2) {
int *targetData = findTargets(plr, skillID); std::vector<int> targetData = findTargets(plr, skillID);
int boost = 0; int boost = 0;
if (getNanoBoost(plr)) if (getNanoBoost(plr))
@ -437,7 +437,7 @@ void NanoManager::resetNanoSkill(CNSocket* sock, int16_t nanoID) {
plr->Nanos[nanoID] = nano; plr->Nanos[nanoID] = nano;
} }
void NanoManager::nanoUnbuff(CNSocket* sock, int targetData[], int32_t bitFlag, int16_t timeBuffID, int16_t amount, bool groupPower) { void NanoManager::nanoUnbuff(CNSocket* sock, std::vector<int> targetData, int32_t bitFlag, int16_t timeBuffID, int16_t amount, bool groupPower) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
if (plr == nullptr) if (plr == nullptr)
@ -457,6 +457,8 @@ void NanoManager::nanoUnbuff(CNSocket* sock, int targetData[], int32_t bitFlag,
Player* varPlr = PlayerManager::getPlayerFromID(targetData[i+1]); Player* varPlr = PlayerManager::getPlayerFromID(targetData[i+1]);
if (!((groupFlags | varPlr->iSelfConditionBitFlag) & bitFlag)) { if (!((groupFlags | varPlr->iSelfConditionBitFlag) & bitFlag)) {
CNSocket* sockTo = PlayerManager::getSockFromID(targetData[i+1]); CNSocket* sockTo = PlayerManager::getSockFromID(targetData[i+1]);
if (sockTo == nullptr)
continue; // sanity check
INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, resp); INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, resp);
resp.eCSTB = timeBuffID; // eCharStatusTimeBuffID resp.eCSTB = timeBuffID; // eCharStatusTimeBuffID
@ -512,9 +514,8 @@ int NanoManager::nanoStyle(int nanoID) {
return NanoTable[nanoID].style; return NanoTable[nanoID].style;
} }
int* NanoManager::findTargets(Player* plr, int skillID, CNPacketData* data) { std::vector<int> NanoManager::findTargets(Player* plr, int skillID, CNPacketData* data) {
static int tD[5] = {0, 0, 0, 0, 0}; std::vector<int> tD(5);
tD[0] = 0;
if (SkillTable[skillID].targetType <= 2 && data != nullptr) { // client gives us the targets if (SkillTable[skillID].targetType <= 2 && data != nullptr) { // client gives us the targets
sP_CL2FE_REQ_NANO_SKILL_USE* pkt = (sP_CL2FE_REQ_NANO_SKILL_USE*)data->buf; sP_CL2FE_REQ_NANO_SKILL_USE* pkt = (sP_CL2FE_REQ_NANO_SKILL_USE*)data->buf;
@ -809,7 +810,7 @@ bool doMove(CNSocket *sock, sSkillResult_Move *respdata, int i, int32_t targetID
template<class sPAYLOAD, template<class sPAYLOAD,
bool (*work)(CNSocket*,sPAYLOAD*,int,int32_t,int32_t,int16_t,int16_t,int16_t)> bool (*work)(CNSocket*,sPAYLOAD*,int,int32_t,int32_t,int16_t,int16_t,int16_t)>
void nanoPower(CNSocket *sock, int targetData[], void nanoPower(CNSocket *sock, std::vector<int> targetData,
int16_t nanoID, int16_t skillID, int16_t duration, int16_t amount, int16_t nanoID, int16_t skillID, int16_t duration, int16_t amount,
int16_t skillType, int32_t bitFlag, int16_t timeBuffID) { int16_t skillType, int32_t bitFlag, int16_t timeBuffID) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
@ -856,7 +857,7 @@ void nanoPower(CNSocket *sock, int targetData[],
CNSocket *workSock = sock; CNSocket *workSock = sock;
for (int i = 0; i < targetData[0]; i++) { for (int i = 0; i < targetData[0]; i++) {
if (SkillTable[skillID].targetType == 3) if (SkillTable[skillID].targetType == 3 && PlayerManager::getSockFromID(targetData[i + 1]) != nullptr)
workSock = PlayerManager::getSockFromID(targetData[i+1]); workSock = PlayerManager::getSockFromID(targetData[i+1]);
if (skillType == EST_RECALL || skillType == EST_RECALL_GROUP) if (skillType == EST_RECALL || skillType == EST_RECALL_GROUP)
targetData[i+1] = plr->iID; targetData[i+1] = plr->iID;

View File

@ -5,7 +5,7 @@
#include "CNShardServer.hpp" #include "CNShardServer.hpp"
typedef void (*PowerHandler)(CNSocket*, int*, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t); typedef void (*PowerHandler)(CNSocket*, std::vector<int>, int16_t, int16_t, int16_t, int16_t, int16_t, int32_t, int16_t);
struct NanoPower { struct NanoPower {
int16_t skillType; int16_t skillType;
@ -15,7 +15,7 @@ struct NanoPower {
NanoPower(int16_t s, int32_t b, int16_t t, PowerHandler h) : skillType(s), bitFlag(b), timeBuffID(t), handler(h) {} NanoPower(int16_t s, int32_t b, int16_t t, PowerHandler h) : skillType(s), bitFlag(b), timeBuffID(t), handler(h) {}
void handle(CNSocket *sock, int* targetData, int16_t nanoID, int16_t skillID, int16_t duration, int16_t amount) { void handle(CNSocket *sock, std::vector<int> targetData, int16_t nanoID, int16_t skillID, int16_t duration, int16_t amount) {
if (handler == nullptr) if (handler == nullptr)
return; return;
@ -65,9 +65,9 @@ namespace NanoManager {
void summonNano(CNSocket* sock, int slot); void summonNano(CNSocket* sock, int slot);
void setNanoSkill(CNSocket* sock, sP_CL2FE_REQ_NANO_TUNE* skill); void setNanoSkill(CNSocket* sock, sP_CL2FE_REQ_NANO_TUNE* skill);
void resetNanoSkill(CNSocket* sock, int16_t nanoID); void resetNanoSkill(CNSocket* sock, int16_t nanoID);
void nanoUnbuff(CNSocket* sock, int* targetData, int32_t bitFlag, int16_t timeBuffID, int16_t amount, bool groupPower); void nanoUnbuff(CNSocket* sock, std::vector<int> targetData, int32_t bitFlag, int16_t timeBuffID, int16_t amount, bool groupPower);
int applyBuff(CNSocket* sock, int skillID, int eTBU, int eTBT, int32_t groupFlags); int applyBuff(CNSocket* sock, int skillID, int eTBU, int eTBT, int32_t groupFlags);
int nanoStyle(int nanoID); int nanoStyle(int nanoID);
int* findTargets(Player* plr, int skillID, CNPacketData* data = nullptr); std::vector<int> findTargets(Player* plr, int skillID, CNPacketData* data = nullptr);
bool getNanoBoost(Player* plr); bool getNanoBoost(Player* plr);
} }