Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentic Handling of Mission-Related Barker Messages #266

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions src/NPCManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,49 @@ void NPCManager::sendToViewable(Entity *npc, void *buf, uint32_t type, size_t si
static void npcBarkHandler(CNSocket* sock, CNPacketData* data) {
sP_CL2FE_REQ_BARKER* req = (sP_CL2FE_REQ_BARKER*)data->buf;

// get bark IDs from task data
TaskData* td = Missions::Tasks[req->iMissionTaskID];
std::vector<int> 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]);
int taskID = req->iMissionTaskID;
// ignore req->iNPC_ID as it is often fixated on a single npc in the region

if (Missions::Tasks.find(taskID) == Missions::Tasks.end()) {
yungcomputerchair marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "mission task not found: " << taskID << std::endl;
return;
}

if (barks.empty())
return; // no barks
TaskData* td = Missions::Tasks[taskID];
auto& barks = td->task["m_iHBarkerTextID"];

Player* plr = PlayerManager::getPlayer(sock);
std::vector<std::pair<int32_t, int32_t>> npcLines;

for (Chunk* chunk : plr->viewableChunks) {
for (auto ent = chunk->entities.begin(); ent != chunk->entities.end(); ent++) {
if (ent->kind != EntityKind::SIMPLE_NPC)
continue;

BaseNPC* npc = (BaseNPC*)ent->getEntity();
if (npc->type < 0 || npc->type >= NPCData.size())
yungcomputerchair marked this conversation as resolved.
Show resolved Hide resolved
continue; // npc unknown ?!

int barkType = NPCData[npc->type]["m_iBarkerType"];
if (barkType < 1 || barkType > 4)
continue; // no barks

int barkID = barks[barkType - 1];
if (barkID == 0)
continue; // no barks

npcLines.push_back(std::make_pair(npc->id, barkID));
}
}

if (npcLines.size() == 0)
return; // totally no barks

auto& [npcID, missionStringID] = npcLines[Rand::rand(npcLines.size())];

INITSTRUCT(sP_FE2CL_REP_BARKER, resp);
resp.iNPC_ID = req->iNPC_ID;
resp.iMissionStringID = barks[Rand::rand(barks.size())];
resp.iNPC_ID = npcID;
resp.iMissionStringID = missionStringID;
sock->sendPacket(resp, P_FE2CL_REP_BARKER);
}

Expand Down
Loading