moved egg summoning to a custom ChatManager command

This commit is contained in:
Kamil 2020-11-09 11:04:30 +01:00 committed by Gent
parent 9087baae3c
commit 0ecf76c5ec
3 changed files with 40 additions and 35 deletions

View File

@ -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<std::string>& args, CNSocket* soc
}
void eggCommand(std::string full, std::vector<std::string>& 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<std::string>& 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");

View File

@ -9,7 +9,6 @@
#include "ChatManager.hpp"
#include <cmath>
#define M_PI 3.14159265358979323846
#include <algorithm>
#include <list>
#include <fstream>
@ -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

View File

@ -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);
}