diff --git a/src/ChatManager.cpp b/src/ChatManager.cpp index a278266..4ae3aab 100644 --- a/src/ChatManager.cpp +++ b/src/ChatManager.cpp @@ -704,6 +704,52 @@ void whoisCommand(std::string full, std::vector& args, CNSocket* so ChatManager::sendServerMessage(sock, "[WHOIS] Instance: " + std::to_string(PLAYERID(npc->instanceID))); } +void lairUnlock(std::string full, std::vector& args, CNSocket* sock) { + Player* plr = PlayerManager::getPlayer(sock); + if (!ChunkManager::chunkExists(plr->chunkPos)) + return; + + Chunk* chnk = ChunkManager::chunks[plr->chunkPos]; + int taskID = -1; + int missionID = -1; + int found = 0; + for (int32_t id : chnk->NPCs) { + if (NPCManager::NPCs.find(id) == NPCManager::NPCs.end()) + continue; + + BaseNPC* npc = NPCManager::NPCs[id]; + for (auto it = NPCManager::Warps.begin(); it != NPCManager::Warps.end(); it++) { + if ((*it).second.npcID == npc->appearanceData.iNPCType) { + taskID = (*it).second.limitTaskID; + missionID = MissionManager::Tasks[taskID]->task["m_iHMissionID"]; + found++; + break; + } + } + } + + if (missionID == -1 || taskID == -1) { + ChatManager::sendServerMessage(sock, "You are NOT standing near a lair portal; move around and try again!"); + return; + } + + if (found > 1) { + ChatManager::sendServerMessage(sock, "More than one lair found; decrease chunk size and try again!"); + return; + } + + INITSTRUCT(sP_FE2CL_REP_PC_TASK_START_SUCC, taskResp); + MissionManager::startTask(plr, taskID, false); + taskResp.iTaskNum = taskID; + taskResp.iRemainTime = 0; + sock->sendPacket((void*)&taskResp, P_FE2CL_REP_PC_TASK_START_SUCC, sizeof(sP_FE2CL_REP_PC_TASK_START_SUCC)); + + INITSTRUCT(sP_FE2CL_REP_PC_SET_CURRENT_MISSION_ID, missionResp); + missionResp.iCurrentMissionID = missionID; + plr->CurrentMissionID = missionID; + sock->sendPacket((void*)&missionResp, P_FE2CL_REP_PC_SET_CURRENT_MISSION_ID, sizeof(sP_FE2CL_REP_PC_SET_CURRENT_MISSION_ID)); +} + void ChatManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE, chatHandler); REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT, emoteHandler); @@ -732,6 +778,7 @@ void ChatManager::init() { registerCommand("summonGroup", 30, summonGroupCommand, "summon group NPCs"); registerCommand("summonGroupW", 30, summonGroupCommand, "permanently summon group NPCs"); registerCommand("whois", 50, whoisCommand, "describe nearest NPC"); + registerCommand("lair", 50, lairUnlock, "Allows entry to lair by granting you the required mission and task"); } void ChatManager::registerCommand(std::string cmd, int requiredLevel, CommandHandler handlr, std::string help) { diff --git a/src/MissionManager.cpp b/src/MissionManager.cpp index 5786381..a02ecd9 100644 --- a/src/MissionManager.cpp +++ b/src/MissionManager.cpp @@ -18,7 +18,7 @@ void MissionManager::init() { REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_TASK_STOP, quitMission); } -bool startTask(Player* plr, int TaskID, bool NanoMission) { +bool MissionManager::startTask(Player* plr, int TaskID, bool NanoMission) { if (MissionManager::Tasks.find(TaskID) == MissionManager::Tasks.end()) { std::cout << "[WARN] Player submitted unknown task!?" << std::endl; return false; diff --git a/src/MissionManager.hpp b/src/MissionManager.hpp index 819b3f8..8d6a52e 100644 --- a/src/MissionManager.hpp +++ b/src/MissionManager.hpp @@ -41,6 +41,7 @@ namespace MissionManager { extern nlohmann::json AvatarGrowth[37]; void init(); + bool startTask(Player* plr, int TaskID, bool NanoMission); void taskStart(CNSocket* sock, CNPacketData* data); void taskEnd(CNSocket* sock, CNPacketData* data); void setMission(CNSocket* sock, CNPacketData* data);