[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;
const int unstickRange = 400;
switch (req->eTeleportType) {
case eCN_GM_TeleportMapType__MyLocation:
switch ((eCN_GM_TeleportType)req->eTeleportType) {
case eCN_GM_TeleportType::MyLocation:
PlayerManager::sendPlayerTo(targetSock, plr->x, plr->y, plr->z, instance);
break;
case eCN_GM_TeleportMapType__MapXYZ:
case eCN_GM_TeleportType::MapXYZ:
instance = req->iToMap;
// fallthrough
case eCN_GM_TeleportMapType__XYZ:
case eCN_GM_TeleportType::XYZ:
PlayerManager::sendPlayerTo(targetSock, req->iToX, req->iToY, req->iToZ, instance);
break;
case eCN_GM_TeleportMapType__SomeoneLocation:
case eCN_GM_TeleportType::SomeoneLocation:
// player to teleport to
goalSock = PlayerManager::getSockFromAny(req->eGoalPCSearchBy, req->iGoalPC_ID, req->iGoalPC_UID,
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);
break;
case eCN_GM_TeleportMapType__Unstick:
case eCN_GM_TeleportType::Unstick:
targetPlr = PlayerManager::getPlayer(targetSock);
PlayerManager::sendPlayerTo(targetSock, targetPlr->x - unstickRange/2 + Rand::rand(unstickRange),

View File

@ -5,6 +5,6 @@
namespace Email {
extern std::vector<std::string> dump;
void init();
}

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));
// 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
Chunk* chunk = Chunking::chunks[chunkPos];
for (EntityRef ref : chunk->entities) {
@ -399,7 +399,7 @@ static void taskEnd(CNSocket* sock, CNPacketData* data) {
* once we comb over mission logic more throughly
*/
bool mobsAreKilled = false;
if (task->task["m_iHTaskType"] == 5) {
if (task->task["m_iHTaskType"] == (int)eTaskTypeProperty::Defeat) {
mobsAreKilled = true;
for (int i = 0; i < ACTIVE_MISSION_COUNT; i++) {
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);
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;
} else if (style == style2) {
respdata[i].iHitFlag = 8; // tie
respdata[i].iHitFlag = HF_BIT_STYLE_TIE;
respdata[i].iDamage = 0;
respdata[i].iNanoStamina = plr->Nanos[plr->activeNano].iStamina;
} 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].iNanoStamina = plr->Nanos[plr->activeNano].iStamina += 45;
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)
pwr.handle(sock, targetData2, plr->activeNano, skillID, 0, 200);
} 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].iNanoStamina = plr->Nanos[plr->activeNano].iStamina -= 90;
if (plr->Nanos[plr->activeNano].iStamina < 0) {

View File

@ -407,21 +407,22 @@ static void revivePlayer(CNSocket* sock, CNPacketData* data) {
int activeSlot = -1;
bool move = false;
if (reviveData->iRegenType == 3 && plr->iConditionBitFlag & CSB_BIT_PHOENIX) {
// nano revive
switch ((ePCRegenType)reviveData->iRegenType) {
case ePCRegenType::HereByPhoenix: // nano revive
if (!(plr->iConditionBitFlag & CSB_BIT_PHOENIX))
return; // sanity check
plr->Nanos[plr->activeNano].iStamina = 0;
plr->HP = PC_MAXHEALTH(plr->level) / 2;
Abilities::applyBuff(sock, plr->Nanos[plr->activeNano].iSkillID, 2, 1, 0);
} else if (reviveData->iRegenType == 4) {
// revived by group member's nano
// fallthrough
case ePCRegenType::HereByPhoenixGroup: // revived by group member's nano
plr->HP = PC_MAXHEALTH(plr->level) / 2;
} else if (reviveData->iRegenType == 5) {
// warp away
move = true;
} else {
// plain respawn
move = true;
break;
default: // plain respawn
plr->HP = PC_MAXHEALTH(plr->level) / 2;
// fallthrough
case ePCRegenType::Unstick: // warp away
move = true;
break;
}
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) {
switch (by) {
case eCN_GM_TargetSearchBy__PC_ID:
switch ((eCN_GM_TargetSearchBy)by) {
case eCN_GM_TargetSearchBy::PC_ID:
assert(id != 0);
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);
for (auto& pair : players)
if (pair.second->accountId == uid)
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?
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;
// methods of finding players for GM commands
enum eCN_GM_TargetSearchBy {
eCN_GM_TargetSearchBy__PC_ID, // player id
eCN_GM_TargetSearchBy__PC_Name, // firstname, lastname
eCN_GM_TargetSearchBy__PC_UID // account id
enum class eCN_GM_TargetSearchBy {
PC_ID, // player id
PC_Name, // firstname, lastname
PC_UID // account id
};
enum eCN_GM_TeleportType {
eCN_GM_TeleportMapType__XYZ,
eCN_GM_TeleportMapType__MapXYZ,
eCN_GM_TeleportMapType__MyLocation,
eCN_GM_TeleportMapType__SomeoneLocation,
eCN_GM_TeleportMapType__Unstick
enum class eCN_GM_TeleportType {
XYZ,
MapXYZ,
MyLocation,
SomeoneLocation,
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