@@ -365,17 +365,17 @@ bool QuestManager::CanStartQuest(uint64_t entity_id, uint64_t quest_id) const {
365365 return true ;
366366}
367367
368- void QuestManager::StartQuest (uint64_t entity_id, uint64_t quest_id) {
368+ bool QuestManager::StartQuest (uint64_t entity_id, uint64_t quest_id) {
369369 if (!CanStartQuest (entity_id, quest_id)) {
370370 Logger::Warn (" QuestManager: Entity {} cannot start quest {}" , entity_id, quest_id);
371- return ;
371+ return false ;
372372 }
373373
374374 std::unique_lock<std::shared_mutex> lock (mutex_);
375375 auto & data = entity_quests_[entity_id];
376376 if (data.active_quests .size () >= MAX_ACTIVE_QUESTS) {
377377 Logger::Warn (" QuestManager: Entity {} has too many active quests" , entity_id);
378- return ;
378+ return false ;
379379 }
380380
381381 const auto & def = quest_definitions_[quest_id];
@@ -399,6 +399,7 @@ void QuestManager::StartQuest(uint64_t entity_id, uint64_t quest_id) {
399399 lock.unlock ();
400400 FireQuestEvent (" quest_started" , entity_id, quest_id);
401401 Logger::Debug (" QuestManager: Entity {} started quest {}" , entity_id, quest_id);
402+ return true ;
402403}
403404
404405bool QuestManager::AbandonQuest (uint64_t entity_id, uint64_t quest_id) {
@@ -655,17 +656,25 @@ void QuestManager::OnItemCollected(uint64_t entity_id, const std::string& item_i
655656}
656657
657658void QuestManager::OnNPCTalkedTo (uint64_t entity_id, uint64_t npc_id) {
659+ auto to_uint64 = [](const std::string& s) -> uint64_t {
660+ try { return std::stoull (s); } catch (...) { return 0 ; }
661+ };
662+
658663 std::vector<std::pair<uint64_t , std::string>> updates;
659664 {
660665 std::shared_lock<std::shared_mutex> lock (mutex_);
661666 auto entity_it = entity_quests_.find (entity_id);
662667 if (entity_it == entity_quests_.end ()) return ;
668+
663669 for (const auto & [qid, progress] : entity_it->second .active_quests ) {
664670 if (progress.state != QuestState::IN_PROGRESS) continue ;
665671 const auto & def = quest_definitions_.at (qid);
666672 for (const auto & obj : def.objectives ) {
667- if (obj.type == ObjectiveType::TALK_TO_NPC && obj.target == npc_id) {
668- updates.emplace_back (qid, obj.id );
673+ if (obj.type == ObjectiveType::TALK_TO_NPC) {
674+ // Convert the objective's target (string) to uint64_t and compare
675+ if (to_uint64 (obj.target ) == npc_id) {
676+ updates.emplace_back (qid, obj.id );
677+ }
669678 }
670679 }
671680 }
@@ -674,14 +683,16 @@ void QuestManager::OnNPCTalkedTo(uint64_t entity_id, uint64_t npc_id) {
674683 UpdateObjective (entity_id, qid, obj_id, 1 );
675684 }
676685
677- // Also handle quest discovery from NPC
686+ // Quest discovery from NPC
678687 std::vector<uint64_t > possible_quests;
679688 {
680689 std::shared_lock<std::shared_mutex> lock (mutex_);
681690 for (const auto & [qid, def] : quest_definitions_) {
682- if (def.giver_npc_id == npc_id && def.is_discoverable &&
683- !HasQuest (entity_id, qid) && CanStartQuest (entity_id, qid)) {
684- possible_quests.push_back (qid);
691+ if (def.is_discoverable && !HasQuest (entity_id, qid) && CanStartQuest (entity_id, qid)) {
692+ // Convert giver_npc_id (string) to uint64_t and compare
693+ if (to_uint64 (def.giver_npc_id ) == npc_id) {
694+ possible_quests.push_back (qid);
695+ }
685696 }
686697 }
687698 }
@@ -1034,25 +1045,34 @@ uint64_t QuestManager::GetTrackedQuest(uint64_t entity_id) const {
10341045// =============== NPC Interaction ===============
10351046
10361047std::vector<uint64_t > QuestManager::GetQuestsFromNPC (uint64_t entity_id, uint64_t npc_id) const {
1048+ auto to_uint64 = [](const std::string& s) -> uint64_t {
1049+ try { return std::stoull (s); } catch (...) { return 0 ; }
1050+ };
1051+
10371052 std::vector<uint64_t > result;
10381053 std::shared_lock<std::shared_mutex> lock (mutex_);
10391054 for (const auto & [qid, def] : quest_definitions_) {
1040- if (def.giver_npc_id == npc_id && !HasQuest (entity_id, qid) && CanStartQuest (entity_id, qid)) {
1055+ if (to_uint64 ( def.giver_npc_id ) == npc_id && !HasQuest (entity_id, qid) && CanStartQuest (entity_id, qid)) {
10411056 result.push_back (qid);
10421057 }
10431058 }
10441059 return result;
10451060}
10461061
10471062std::vector<uint64_t > QuestManager::GetQuestsToTurnIn (uint64_t entity_id, uint64_t npc_id) const {
1063+ auto to_uint64 = [](const std::string& s) -> uint64_t {
1064+ try { return std::stoull (s); } catch (...) { return 0 ; }
1065+ };
1066+
10481067 std::vector<uint64_t > result;
10491068 std::shared_lock<std::shared_mutex> lock (mutex_);
10501069 auto it = entity_quests_.find (entity_id);
10511070 if (it == entity_quests_.end ()) return result;
1071+
10521072 for (const auto & [qid, progress] : it->second .active_quests ) {
10531073 if (progress.state == QuestState::COMPLETED) {
10541074 auto def_it = quest_definitions_.find (qid);
1055- if (def_it != quest_definitions_.end () && def_it->second .turn_in_npc_id == npc_id) {
1075+ if (def_it != quest_definitions_.end () && to_uint64 ( def_it->second .turn_in_npc_id ) == npc_id) {
10561076 result.push_back (qid);
10571077 }
10581078 }
0 commit comments