[refactor] Replace a few uses of magic numbers with enums

This commit is contained in:
dongresource 2021-10-20 00:40:40 +02:00 committed by gsemaj
parent 71a7d3d164
commit 18ed96493f
6 changed files with 61 additions and 38 deletions

View File

@ -247,17 +247,17 @@ static void teleportPlayer(CNSocket *sock, CNPacketData *data) {
uint64_t instance = plr->instanceID; uint64_t instance = plr->instanceID;
const int unstickRange = 400; const int unstickRange = 400;
switch (req->eTeleportType) { switch ((eCN_GM_TeleportType)req->eTeleportType) {
case eCN_GM_TeleportMapType__MyLocation: case eCN_GM_TeleportType::MyLocation:
PlayerManager::sendPlayerTo(targetSock, plr->x, plr->y, plr->z, instance); PlayerManager::sendPlayerTo(targetSock, plr->x, plr->y, plr->z, instance);
break; break;
case eCN_GM_TeleportMapType__MapXYZ: case eCN_GM_TeleportType::MapXYZ:
instance = req->iToMap; instance = req->iToMap;
// fallthrough // fallthrough
case eCN_GM_TeleportMapType__XYZ: case eCN_GM_TeleportType::XYZ:
PlayerManager::sendPlayerTo(targetSock, req->iToX, req->iToY, req->iToZ, instance); PlayerManager::sendPlayerTo(targetSock, req->iToX, req->iToY, req->iToZ, instance);
break; break;
case eCN_GM_TeleportMapType__SomeoneLocation: case eCN_GM_TeleportType::SomeoneLocation:
// player to teleport to // player to teleport to
goalSock = PlayerManager::getSockFromAny(req->eGoalPCSearchBy, req->iGoalPC_ID, req->iGoalPC_UID, goalSock = PlayerManager::getSockFromAny(req->eGoalPCSearchBy, req->iGoalPC_ID, req->iGoalPC_UID,
AUTOU16TOU8(req->szGoalPC_FirstName), AUTOU16TOU8(req->szGoalPC_LastName)); AUTOU16TOU8(req->szGoalPC_FirstName), AUTOU16TOU8(req->szGoalPC_LastName));
@ -269,7 +269,7 @@ static void teleportPlayer(CNSocket *sock, CNPacketData *data) {
PlayerManager::sendPlayerTo(targetSock, goalPlr->x, goalPlr->y, goalPlr->z, goalPlr->instanceID); PlayerManager::sendPlayerTo(targetSock, goalPlr->x, goalPlr->y, goalPlr->z, goalPlr->instanceID);
break; break;
case eCN_GM_TeleportMapType__Unstick: case eCN_GM_TeleportType::Unstick:
targetPlr = PlayerManager::getPlayer(targetSock); targetPlr = PlayerManager::getPlayer(targetSock);
PlayerManager::sendPlayerTo(targetSock, targetPlr->x - unstickRange/2 + Rand::rand(unstickRange), PlayerManager::sendPlayerTo(targetSock, targetPlr->x - unstickRange/2 + Rand::rand(unstickRange),

View File

@ -367,7 +367,7 @@ static void taskStart(CNSocket* sock, CNPacketData* data) {
sock->sendPacket((void*)&response, P_FE2CL_REP_PC_TASK_START_SUCC, sizeof(sP_FE2CL_REP_PC_TASK_START_SUCC)); sock->sendPacket((void*)&response, P_FE2CL_REP_PC_TASK_START_SUCC, sizeof(sP_FE2CL_REP_PC_TASK_START_SUCC));
// if escort task, assign matching paths to all nearby NPCs // if escort task, assign matching paths to all nearby NPCs
if (task["m_iHTaskType"] == 6) { if (task["m_iHTaskType"] == (int)eTaskTypeProperty::EscortDefence) {
for (ChunkPos& chunkPos : Chunking::getChunksInMap(plr->instanceID)) { // check all NPCs in the instance for (ChunkPos& chunkPos : Chunking::getChunksInMap(plr->instanceID)) { // check all NPCs in the instance
Chunk* chunk = Chunking::chunks[chunkPos]; Chunk* chunk = Chunking::chunks[chunkPos];
for (EntityRef ref : chunk->entities) { for (EntityRef ref : chunk->entities) {
@ -399,7 +399,7 @@ static void taskEnd(CNSocket* sock, CNPacketData* data) {
* once we comb over mission logic more throughly * once we comb over mission logic more throughly
*/ */
bool mobsAreKilled = false; bool mobsAreKilled = false;
if (task->task["m_iHTaskType"] == 5) { if (task->task["m_iHTaskType"] == (int)eTaskTypeProperty::Defeat) {
mobsAreKilled = true; mobsAreKilled = true;
for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) { for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) {
if (plr->tasks[i] == missionData->iTaskNum) { if (plr->tasks[i] == missionData->iTaskNum) {

View File

@ -234,14 +234,14 @@ static void dealCorruption(Mob *mob, std::vector<int> targetData, int skillID, i
int style2 = Nanos::nanoStyle(plr->activeNano); int style2 = Nanos::nanoStyle(plr->activeNano);
if (style2 == -1) { // no nano if (style2 == -1) { // no nano
respdata[i].iHitFlag = 8; respdata[i].iHitFlag = HF_BIT_STYLE_TIE;
respdata[i].iDamage = Abilities::SkillTable[skillID].powerIntensity[0] * PC_MAXHEALTH((int)mob->data["m_iNpcLevel"]) / 1500; respdata[i].iDamage = Abilities::SkillTable[skillID].powerIntensity[0] * PC_MAXHEALTH((int)mob->data["m_iNpcLevel"]) / 1500;
} else if (style == style2) { } else if (style == style2) {
respdata[i].iHitFlag = 8; // tie respdata[i].iHitFlag = HF_BIT_STYLE_TIE;
respdata[i].iDamage = 0; respdata[i].iDamage = 0;
respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina; respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina;
} else if (style - style2 == 1 || style2 - style == 2) { } else if (style - style2 == 1 || style2 - style == 2) {
respdata[i].iHitFlag = 4; // win respdata[i].iHitFlag = HF_BIT_STYLE_WIN;
respdata[i].iDamage = 0; respdata[i].iDamage = 0;
respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina += 45; respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina += 45;
if (plr->Nanos[plr->activeNano].iStamina > 150) if (plr->Nanos[plr->activeNano].iStamina > 150)
@ -252,7 +252,7 @@ static void dealCorruption(Mob *mob, std::vector<int> targetData, int skillID, i
if (pwr.skillType == EST_DAMAGE) if (pwr.skillType == EST_DAMAGE)
pwr.handle(sock, targetData2, plr->activeNano, skillID, 0, 200); pwr.handle(sock, targetData2, plr->activeNano, skillID, 0, 200);
} else { } else {
respdata[i].iHitFlag = 16; // lose respdata[i].iHitFlag = HF_BIT_STYLE_LOSE;
respdata[i].iDamage = Abilities::SkillTable[skillID].powerIntensity[0] * PC_MAXHEALTH((int)mob->data["m_iNpcLevel"]) / 1500; respdata[i].iDamage = Abilities::SkillTable[skillID].powerIntensity[0] * PC_MAXHEALTH((int)mob->data["m_iNpcLevel"]) / 1500;
respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina -= 90; respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina -= 90;
if (plr->Nanos[plr->activeNano].iStamina < 0) { if (plr->Nanos[plr->activeNano].iStamina < 0) {

View File

@ -407,21 +407,22 @@ static void revivePlayer(CNSocket* sock, CNPacketData* data) {
int activeSlot = -1; int activeSlot = -1;
bool move = false; bool move = false;
if (reviveData->iRegenType == 3 && plr->iConditionBitFlag & CSB_BIT_PHOENIX) { switch ((ePCRegenType)reviveData->iRegenType) {
// nano revive case ePCRegenType::HereByPhoenix: // nano revive
if (!(plr->iConditionBitFlag & CSB_BIT_PHOENIX))
return; // sanity check
plr->Nanos[plr->activeNano].iStamina = 0; plr->Nanos[plr->activeNano].iStamina = 0;
plr->HP = PC_MAXHEALTH(plr->level) / 2;
Abilities::applyBuff(sock, plr->Nanos[plr->activeNano].iSkillID, 2, 1, 0); Abilities::applyBuff(sock, plr->Nanos[plr->activeNano].iSkillID, 2, 1, 0);
} else if (reviveData->iRegenType == 4) { // fallthrough
// revived by group member's nano case ePCRegenType::HereByPhoenixGroup: // revived by group member's nano
plr->HP = PC_MAXHEALTH(plr->level) / 2; plr->HP = PC_MAXHEALTH(plr->level) / 2;
} else if (reviveData->iRegenType == 5) { break;
// warp away default: // plain respawn
move = true;
} else {
// plain respawn
move = true;
plr->HP = PC_MAXHEALTH(plr->level) / 2; plr->HP = PC_MAXHEALTH(plr->level) / 2;
// fallthrough
case ePCRegenType::Unstick: // warp away
move = true;
break;
} }
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
@ -668,16 +669,16 @@ CNSocket *PlayerManager::getSockFromName(std::string firstname, std::string last
} }
CNSocket *PlayerManager::getSockFromAny(int by, int id, int uid, std::string firstname, std::string lastname) { CNSocket *PlayerManager::getSockFromAny(int by, int id, int uid, std::string firstname, std::string lastname) {
switch (by) { switch ((eCN_GM_TargetSearchBy)by) {
case eCN_GM_TargetSearchBy__PC_ID: case eCN_GM_TargetSearchBy::PC_ID:
assert(id != 0); assert(id != 0);
return getSockFromID(id); return getSockFromID(id);
case eCN_GM_TargetSearchBy__PC_UID: // account id; not player id case eCN_GM_TargetSearchBy::PC_UID: // account id; not player id
assert(uid != 0); assert(uid != 0);
for (auto& pair : players) for (auto& pair : players)
if (pair.second->accountId == uid) if (pair.second->accountId == uid)
return pair.first; return pair.first;
case eCN_GM_TargetSearchBy__PC_Name: case eCN_GM_TargetSearchBy::PC_Name:
assert(firstname != "" && lastname != ""); // XXX: remove this if we start messing around with edited names? assert(firstname != "" && lastname != ""); // XXX: remove this if we start messing around with edited names?
return getSockFromName(firstname, lastname); return getSockFromName(firstname, lastname);
} }

View File

@ -10,18 +10,40 @@ const float CN_EP_RANK_4 = 0.3f;
const float CN_EP_RANK_5 = 0.29f; const float CN_EP_RANK_5 = 0.29f;
// methods of finding players for GM commands // methods of finding players for GM commands
enum eCN_GM_TargetSearchBy { enum class eCN_GM_TargetSearchBy {
eCN_GM_TargetSearchBy__PC_ID, // player id PC_ID, // player id
eCN_GM_TargetSearchBy__PC_Name, // firstname, lastname PC_Name, // firstname, lastname
eCN_GM_TargetSearchBy__PC_UID // account id PC_UID // account id
}; };
enum eCN_GM_TeleportType { enum class eCN_GM_TeleportType {
eCN_GM_TeleportMapType__XYZ, XYZ,
eCN_GM_TeleportMapType__MapXYZ, MapXYZ,
eCN_GM_TeleportMapType__MyLocation, MyLocation,
eCN_GM_TeleportMapType__SomeoneLocation, SomeoneLocation,
eCN_GM_TeleportMapType__Unstick Unstick
};
enum class eTaskTypeProperty {
None = -1,
Talk = 1,
GotoLocation = 2,
UseItems = 3,
Delivery = 4,
Defeat = 5,
EscortDefence = 6,
Max = 7
};
enum class ePCRegenType {
None,
Xcom,
Here,
HereByPhoenix,
HereByPhoenixGroup,
Unstick,
HereByPhoenixItem,
End
}; };
// nano powers // nano powers