added basic player buffs implementation

This commit is contained in:
kamilprzyb 2020-10-22 10:23:12 +02:00 committed by Gent
parent 2744ed64e3
commit f2ff4c7f4d
5 changed files with 79 additions and 3 deletions

View File

@ -436,6 +436,25 @@ void tasksCommand(std::string full, std::vector<std::string>& args, CNSocket* so
} }
} }
void buffCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
if (args.size() < 3) {
ChatManager::sendServerMessage(sock, "/buff: no skill Id and duration time specified");
return;
}
char* tmp;
int skillId = std::strtol(args[1].c_str(), &tmp, 10);
if (*tmp)
return;
int duration = std::strtol(args[2].c_str(), &tmp, 10);
if (*tmp)
return;
if (NPCManager::eggBuffPlayer(sock, skillId, duration)<0)
ChatManager::sendServerMessage(sock, "/buff: unknown skill Id");
}
void notifyCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) { void notifyCommand(std::string full, std::vector<std::string>& args, CNSocket* sock) {
Player *plr = PlayerManager::getPlayer(sock); Player *plr = PlayerManager::getPlayer(sock);
@ -478,6 +497,7 @@ void ChatManager::init() {
registerCommand("population", 100, populationCommand, "check how many players are online"); registerCommand("population", 100, populationCommand, "check how many players are online");
registerCommand("refresh", 100, refreshCommand, "teleport yourself to your current location"); registerCommand("refresh", 100, refreshCommand, "teleport yourself to your current location");
registerCommand("minfo", 30, minfoCommand, "show details of the current mission and task."); registerCommand("minfo", 30, minfoCommand, "show details of the current mission and task.");
registerCommand("buff", 50, buffCommand, "give yourself a buff effect");
registerCommand("tasks", 30, tasksCommand, "list all active missions and their respective task ids."); registerCommand("tasks", 30, tasksCommand, "list all active missions and their respective task ids.");
registerCommand("notify", 30, notifyCommand, "receive a message whenever a player joins the server"); registerCommand("notify", 30, notifyCommand, "receive a message whenever a player joins the server");
registerCommand("players", 30, playersCommand, "print all players on the server"); registerCommand("players", 30, playersCommand, "print all players on the server");

View File

@ -4,6 +4,7 @@
#include "MobManager.hpp" #include "MobManager.hpp"
#include "MissionManager.hpp" #include "MissionManager.hpp"
#include "ChunkManager.hpp" #include "ChunkManager.hpp"
#include "NanoManager.hpp"
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>
@ -18,6 +19,8 @@
std::map<int32_t, BaseNPC*> NPCManager::NPCs; std::map<int32_t, BaseNPC*> NPCManager::NPCs;
std::map<int32_t, WarpLocation> NPCManager::Warps; std::map<int32_t, WarpLocation> NPCManager::Warps;
std::vector<WarpLocation> NPCManager::RespawnPoints; std::vector<WarpLocation> NPCManager::RespawnPoints;
/// Player Id, CBFlag -> remaining time
std::map<std::pair<int32_t, int32_t>, time_t> NPCManager::EggBuffs;
nlohmann::json NPCManager::NPCData; nlohmann::json NPCManager::NPCData;
/* /*
@ -648,3 +651,49 @@ BaseNPC* NPCManager::getNearestNPC(std::vector<Chunk*> chunks, int X, int Y, int
} }
return npc; return npc;
} }
int NPCManager::eggBuffPlayer(CNSocket* sock, int skillId, int duration) {
Player* plr = PlayerManager::getPlayer(sock);
if (plr == nullptr)
return -1;
int32_t CBFlag = -1, iValue, CSTB;
// find the right passive power data
for (auto& pwr : NanoManager::PassivePowers)
if (pwr.powers.count(skillId)) {
CBFlag = pwr.iCBFlag;
CSTB = pwr.eCharStatusTimeBuffID;
iValue = pwr.iValue;
}
if (CBFlag < 0)
return -1;
std::pair<int32_t, int32_t> key = std::make_pair(plr->iID, CBFlag);
// if player doesn't have this buff yet
if (EggBuffs.find(key) == EggBuffs.end())
{
// save new cbflag serverside
plr->iEggConditionBitFlag |= CBFlag;
// send buff update package
INITSTRUCT(sP_FE2CL_PC_BUFF_UPDATE, updatePacket);
updatePacket.eCSTB = CSTB; // eCharStatusTimeBuffID
updatePacket.eTBU = 1; // eTimeBuffUpdate 1 means Add
updatePacket.eTBT = 3; // eTimeBuffType 3 means egg
updatePacket.TimeBuff.iValue = iValue;
int32_t updatedFlag = plr->iConditionBitFlag | plr->iGroupConditionBitFlag | plr->iEggConditionBitFlag;
updatePacket.iConditionBitFlag = updatedFlag;
sock->sendPacket((void*)&updatePacket, P_FE2CL_PC_BUFF_UPDATE, sizeof(sP_FE2CL_PC_BUFF_UPDATE));
}
// save the buff serverside;
EggBuffs[key] = duration;
return 0;
}

View File

@ -20,6 +20,7 @@ namespace NPCManager {
extern std::map<int32_t, BaseNPC*> NPCs; extern std::map<int32_t, BaseNPC*> NPCs;
extern std::map<int32_t, WarpLocation> Warps; extern std::map<int32_t, WarpLocation> Warps;
extern std::vector<WarpLocation> RespawnPoints; extern std::vector<WarpLocation> RespawnPoints;
extern std::map<std::pair<int32_t, int32_t>, time_t> EggBuffs;
extern nlohmann::json NPCData; extern nlohmann::json NPCData;
extern int32_t nextId; extern int32_t nextId;
void init(); void init();
@ -50,4 +51,7 @@ namespace NPCManager {
void handleWarp(CNSocket* sock, int32_t warpId); void handleWarp(CNSocket* sock, int32_t warpId);
BaseNPC* getNearestNPC(std::vector<Chunk*> chunks, int X, int Y, int Z); BaseNPC* getNearestNPC(std::vector<Chunk*> chunks, int X, int Y, int Z);
/// returns -1 on fail
int eggBuffPlayer(CNSocket* sock, int skillId, int duration);
} }

View File

@ -800,7 +800,7 @@ void NanoManager::nanoBuff(CNSocket* sock, int16_t nanoId, int skillId, int16_t
pkt1.eCSTB = eCharStatusTimeBuffID; // eCharStatusTimeBuffID pkt1.eCSTB = eCharStatusTimeBuffID; // eCharStatusTimeBuffID
pkt1.eTBU = 1; // eTimeBuffUpdate pkt1.eTBU = 1; // eTimeBuffUpdate
pkt1.eTBT = 1; // eTimeBuffType 1 means nano pkt1.eTBT = 1; // eTimeBuffType 1 means nano
pkt1.iConditionBitFlag = bitFlag | varPlr->iConditionBitFlag; pkt1.iConditionBitFlag = bitFlag | varPlr->iConditionBitFlag | varPlr->iEggConditionBitFlag;
if (iValue > 0) if (iValue > 0)
pkt1.TimeBuff.iValue = iValue; pkt1.TimeBuff.iValue = iValue;
@ -852,7 +852,7 @@ void NanoManager::nanoUnbuff(CNSocket* sock, int32_t iCBFlag, int16_t eCharStatu
resp1.eCSTB = eCharStatusTimeBuffID; // eCharStatusTimeBuffID resp1.eCSTB = eCharStatusTimeBuffID; // eCharStatusTimeBuffID
resp1.eTBU = 2; // eTimeBuffUpdate resp1.eTBU = 2; // eTimeBuffUpdate
resp1.eTBT = 1; // eTimeBuffType 1 means nano resp1.eTBT = 1; // eTimeBuffType 1 means nano
resp1.iConditionBitFlag = bitFlag | varPlr->iConditionBitFlag; resp1.iConditionBitFlag = bitFlag | varPlr->iConditionBitFlag | varPlr->iEggConditionBitFlag;
if (iValue > 0) if (iValue > 0)
resp1.TimeBuff.iValue = iValue; resp1.TimeBuff.iValue = iValue;

View File

@ -2,6 +2,7 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#include <unordered_map>
#include "CNProtocol.hpp" #include "CNProtocol.hpp"
#include "CNStructs.hpp" #include "CNStructs.hpp"
@ -69,6 +70,8 @@ struct Player {
int32_t groupIDs[4]; int32_t groupIDs[4];
int32_t iGroupConditionBitFlag; int32_t iGroupConditionBitFlag;
int32_t iEggConditionBitFlag;
bool notify; bool notify;
bool buddiesSynced; bool buddiesSynced;