diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index 86f2f76..578d164 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -1,3 +1,4 @@ +#define M_PI 3.14159265358979323846 #include "CNShardServer.hpp" #include "CNStructs.hpp" #include "ChatManager.hpp" @@ -463,6 +464,44 @@ void buffCommand(std::string full, std::vector& args, CNSocket* soc } +void eggCommand(std::string full, std::vector& args, CNSocket* sock) { + if (args.size() < 2) { + ChatManager::sendServerMessage(sock, "/egg: no egg type specified"); + return; + } + + char* tmp; + int eggType = std::strtol(args[1].c_str(), &tmp, 10); + if (*tmp) + return; + + if (NPCManager::EggTypes.find(eggType) == NPCManager::EggTypes.end()) { + ChatManager::sendServerMessage(sock, "/egg: Unknown egg type"); + return; + } + + assert(NPCManager::nextId < INT32_MAX); + int id = NPCManager::nextId++; + + Player* plr = PlayerManager::getPlayer(sock); + + if (plr == nullptr) + return; + + // some math to place egg nicely in front of the player + // temporarly disabled for sake of gruntwork + int addX = 0; //-500.0f * sin(plr->angle / 180.0f * M_PI); + int addY = 0; //-500.0f * cos(plr->angle / 180.0f * M_PI); + + Egg* egg = new Egg(plr->x + addX, plr->y + addY, plr->z, plr->instanceID, eggType, id, false); // change last arg to true after gruntwork + NPCManager::NPCs[id] = egg; + NPCManager::Eggs[id] = egg; + NPCManager::updateNPCPosition(id, plr->x + addX, plr->y + addY, plr->z, plr->instanceID); + + // add to template + TableData::RunningEggs[id] = egg; +} + void notifyCommand(std::string full, std::vector& args, CNSocket* sock) { Player *plr = PlayerManager::getPlayer(sock); @@ -506,6 +545,7 @@ void ChatManager::init() { registerCommand("refresh", 100, refreshCommand, "teleport yourself to your current location"); registerCommand("minfo", 30, minfoCommand, "show details of the current mission and task."); registerCommand("buff", 50, buffCommand, "give yourself a buff effect"); + registerCommand("egg", 30, eggCommand, "summon a coco egg"); 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("players", 30, playersCommand, "print all players on the server"); diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index 2d5b8c4..c24fcdd 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -9,7 +9,6 @@ #include "ChatManager.hpp" #include -#define M_PI 3.14159265358979323846 #include #include #include @@ -50,7 +49,6 @@ void NPCManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY, npcVendorBuyback); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_VENDOR_BATTERY_BUY, npcVendorBuyBattery); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ITEM_COMBINATION, npcCombineItems); - REGISTER_SHARD_PACKET(P_CL2FE_REQ_SHINY_SUMMON, eggSummon); REGISTER_SHARD_PACKET(P_CL2FE_REQ_SHINY_PICKUP, eggPickup); REGISTER_SHARD_TIMER(eggStep, 1000); @@ -863,38 +861,6 @@ void NPCManager::npcDataToEggData(sNPCAppearanceData* npc, sShinyAppearanceData* egg->iShiny_ID = npc->iNPC_ID; } -void NPCManager::eggSummon(CNSocket* sock, CNPacketData* data) { - if (data->size != sizeof(sP_CL2FE_REQ_SHINY_SUMMON)) - return; // malformed packet - - sP_CL2FE_REQ_SHINY_SUMMON* summon = (sP_CL2FE_REQ_SHINY_SUMMON*)data->buf; - - assert(NPCManager::nextId < INT32_MAX); - int id = NPCManager::nextId++; - - Player* plr = PlayerManager::getPlayer(sock); - - if (plr == nullptr) - return; - - /* - * the packet sends us player position with a random offset, - * instead we're using some math to place the egg right in front of the player - */ - - // temporarly disabled for sake of gruntwork - int addX = 0; //-500.0f * sin(plr->angle / 180.0f * M_PI); - int addY = 0; //-500.0f * cos(plr->angle / 180.0f * M_PI); - - Egg* egg = new Egg (plr->x + addX, plr->y + addY, plr->z, plr->instanceID, summon->iShinyType, id, false); // change last arg to true after gruntwork - NPCManager::NPCs[id] = egg; - NPCManager::Eggs[id] = egg; - NPCManager::updateNPCPosition(id, plr->x + addX, plr->y + addY, plr->z, plr->instanceID); - - // add to template - TableData::RunningEggs[id] = egg; -} - void NPCManager::eggPickup(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_SHINY_PICKUP)) return; // malformed packet diff --git a/src/NPCManager.hpp b/src/NPCManager.hpp index fa19eb3..ebe738e 100644 --- a/src/NPCManager.hpp +++ b/src/NPCManager.hpp @@ -78,6 +78,5 @@ namespace NPCManager { int eggBuffPlayer(CNSocket* sock, int skillId, int duration); void eggStep(CNServer* serv, time_t currTime); void npcDataToEggData(sNPCAppearanceData* npc, sShinyAppearanceData* egg); - void eggSummon(CNSocket* sock, CNPacketData* data); void eggPickup(CNSocket* sock, CNPacketData* data); }