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");