From 618a8d0a9f617b1cd5e77f3d520079d82ec635ad Mon Sep 17 00:00:00 2001 From: Gent S Date: Tue, 15 Dec 2020 18:42:22 -0500 Subject: [PATCH] Reimplement NPC barking --- src/NPCManager.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index e3594c6..ba9b107 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -431,7 +431,28 @@ void NPCManager::npcCombineItems(CNSocket* sock, CNPacketData* data) { sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_COMBINATION_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_COMBINATION_SUCC)); } -void NPCManager::npcBarkHandler(CNSocket* sock, CNPacketData* data) {} // stubbed for now +void NPCManager::npcBarkHandler(CNSocket* sock, CNPacketData* data) { + if (data->size != sizeof(sP_CL2FE_REQ_BARKER)) + return; // malformed packet + + sP_CL2FE_REQ_BARKER* req = (sP_CL2FE_REQ_BARKER*)data->buf; + + // get bark IDs from task data + TaskData* td = MissionManager::Tasks[req->iMissionTaskID]; + std::vector barks; + for (int i = 0; i < 4; i++) { + if (td->task["m_iHBarkerTextID"][i] != 0) // non-zeroes only + barks.push_back(td->task["m_iHBarkerTextID"][i]); + } + + if (barks.empty()) + return; // no barks + + INITSTRUCT(sP_FE2CL_REP_BARKER, resp); + resp.iNPC_ID = req->iNPC_ID; + resp.iMissionStringID = barks[rand() % barks.size()]; + sock->sendPacket((void*)&resp, P_FE2CL_REP_BARKER, sizeof(sP_FE2CL_REP_BARKER)); +} void NPCManager::npcUnsummonHandler(CNSocket* sock, CNPacketData* data) { if (data->size != sizeof(sP_CL2FE_REQ_NPC_UNSUMMON))