diff --git a/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp b/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp index 04c5b96458..9f9f204492 100644 --- a/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp +++ b/src/modules/PlayerbotV2/Api/PlayerbotAPI.cpp @@ -7418,8 +7418,39 @@ Result API::use_game_object(ObjectGuid go_guid) // ---- Quest --------------------------------------------------------------- +QuestRefusal API::why_cant_take_quest(uint32 quest_id) const +{ + if (!p_) return QuestRefusal::Other; + Quest const* q = sObjectMgr->GetQuestTemplate(quest_id); + if (!q) return QuestRefusal::Other; + // CanTakeQuest's own gates, in its order, each asked without a message to the bot's client. + if (DisableMgr::IsDisabledFor(DISABLE_TYPE_QUEST, quest_id, p_)) return QuestRefusal::Disabled; + if (!p_->SatisfyQuestStatus(q, false)) + return p_->GetQuestStatus(quest_id) == QUEST_STATUS_REWARDED ? QuestRefusal::Done : QuestRefusal::OnIt; + if (!p_->SatisfyQuestExclusiveGroup(q, false)) return QuestRefusal::OtherChoice; + if (!p_->SatisfyQuestClass(q, false)) return QuestRefusal::Class; + if (!p_->SatisfyQuestRace(q, false)) return QuestRefusal::Race; + if (!p_->SatisfyQuestMinLevel(q, false)) return QuestRefusal::LowLevel; + if (!p_->SatisfyQuestMaxLevel(q, false)) return QuestRefusal::HighLevel; + if (!p_->SatisfyQuestSkill(q, false)) return QuestRefusal::Skill; + if (!p_->SatisfyQuestReputation(q, false)) return QuestRefusal::Reputation; + if (!p_->SatisfyQuestDependentQuests(q, false)) return QuestRefusal::Prerequisite; + if (!p_->SatisfyQuestTimed(q, false)) return QuestRefusal::Timed; + if (!p_->SatisfyQuestDay(q, false) || !p_->SatisfyQuestWeek(q, false) || + !p_->SatisfyQuestMonth(q, false) || !p_->SatisfyQuestSeasonal(q, false)) + return QuestRefusal::NotAgainYet; + if (!p_->SatisfyQuestConditions(q, false)) return QuestRefusal::Conditions; + if (!p_->SatisfyQuestExpansion(q, false)) return QuestRefusal::Expansion; + if (!p_->CanTakeQuest(q, false)) return QuestRefusal::Other; // a gate added to CanTakeQuest later + if (!p_->SatisfyQuestLog(false)) return QuestRefusal::LogFull; + if (!p_->CanAddQuest(q, false)) return QuestRefusal::BagsFull; + return QuestRefusal::None; +} + Result API::accept_quest(ObjectGuid quest_giver, uint32 quest_id) { + last_quest_refusal_ = QuestRefusal::None; + last_quest_refusal_quest_ = quest_id; if (!p_) return Result::Other; Quest const* quest = sObjectMgr->GetQuestTemplate(quest_id); if (!quest) @@ -7427,11 +7458,13 @@ Result API::accept_quest(ObjectGuid quest_giver, uint32 quest_id) TC_LOG_INFO("playerbot.v2", "[accept_quest] {} reject quest={} reason=template_missing", "?", quest_id); + last_quest_refusal_ = QuestRefusal::Other; return Result::NotKnown; } - auto log_reject = [&](char const* why) + auto log_reject = [&](char const* why, QuestRefusal refusal) { + last_quest_refusal_ = refusal; TC_LOG_INFO("playerbot.v2", "[accept_quest] {} reject quest={} lvl={} reason={}", p_->GetName(), quest_id, uint32(p_->GetLevel()), why); @@ -7447,10 +7480,10 @@ Result API::accept_quest(ObjectGuid quest_giver, uint32 quest_id) object = ObjectAccessor::GetObjectByTypeMask(*p_, quest_giver, TYPEMASK_UNIT | TYPEMASK_GAMEOBJECT | TYPEMASK_ITEM); } - if (!object) { log_reject("giver_not_found"); return Result::InvalidTarget; } - if (quest_giver.IsPlayer()) { log_reject("player_giver_unsupp"); return Result::Other; } - if (!object->hasQuest(quest_id)) { log_reject("giver_lost_relation"); return Result::InvalidTarget; } - if (!p_->CanInteractWithQuestGiver(object)) { log_reject("out_of_range"); return Result::OutOfRange; } + if (!object) { log_reject("giver_not_found", QuestRefusal::NoGiver); return Result::InvalidTarget; } + if (quest_giver.IsPlayer()) { log_reject("player_giver_unsupp", QuestRefusal::Other); return Result::Other; } + if (!object->hasQuest(quest_id)) { log_reject("giver_lost_relation", QuestRefusal::NoGiver); return Result::InvalidTarget; } + if (!p_->CanInteractWithQuestGiver(object)) { log_reject("out_of_range", QuestRefusal::OutOfRange); return Result::OutOfRange; } // Junk-quest accept-gate (R2, defense-in-depth). A quest with ZERO // objectives AND no creature/GO turn-in NPC is structurally unfinishable // and unturnable — accepting it parks the bot forever (current_quest_id=0 @@ -7463,11 +7496,11 @@ Result API::accept_quest(ObjectGuid quest_giver, uint32 quest_id) auto ce = sObjectMgr->GetCreatureQuestInvolvedRelationReverseBounds(quest_id); auto ge = sObjectMgr->GetGOQuestInvolvedRelationReverseBounds(quest_id); if (ce.begin() == ce.end() && ge.begin() == ge.end()) - { log_reject("no_ender_or_objectives"); return Result::Locked; } + { log_reject("no_ender_or_objectives", QuestRefusal::Unfinishable); return Result::Locked; } } - if (!p_->CanTakeQuest(quest, true)) { log_reject("cant_take_quest"); return Result::Locked; } - if (!p_->SatisfyQuestLog(false)) { log_reject("quest_log_full"); return Result::InventoryFull; } - if (!p_->CanAddQuest(quest, true)) { log_reject("src_item_no_bag_space"); return Result::InventoryFull; } + if (!p_->CanTakeQuest(quest, true)) { log_reject("cant_take_quest", why_cant_take_quest(quest_id)); return Result::Locked; } + if (!p_->SatisfyQuestLog(false)) { log_reject("quest_log_full", QuestRefusal::LogFull); return Result::InventoryFull; } + if (!p_->CanAddQuest(quest, true)) { log_reject("src_item_no_bag_space", QuestRefusal::BagsFull); return Result::InventoryFull; } p_->AddQuestAndCheckCompletion(quest, object); p_->PlayerTalkClass->SendCloseGossip(); @@ -8043,15 +8076,20 @@ Result API::equip_item(uint8 from_bag, uint8 from_slot, uint8 to_slot) Result API::accept_shared_quest() { + last_quest_refusal_ = QuestRefusal::None; + last_quest_refusal_quest_ = 0; if (!p_) return Result::Other; const ObjectGuid sender_guid = p_->GetPlayerSharingQuest(); const uint32 quest_id = p_->GetSharedQuestID(); - if (sender_guid.IsEmpty() || quest_id == 0) return Result::Locked; + // The share ran out (or was answered already) between the order and this tick. + if (sender_guid.IsEmpty() || quest_id == 0) { last_quest_refusal_ = QuestRefusal::NoGiver; return Result::Locked; } + last_quest_refusal_quest_ = quest_id; Quest const* quest = sObjectMgr->GetQuestTemplate(quest_id); - if (!quest) { p_->ClearQuestSharingInfo(); return Result::NotKnown; } + if (!quest) { p_->ClearQuestSharingInfo(); last_quest_refusal_ = QuestRefusal::Other; return Result::NotKnown; } Player* sender = ObjectAccessor::FindConnectedPlayer(sender_guid); if (!p_->CanTakeQuest(quest, false) || !p_->CanAddQuest(quest, false)) { + last_quest_refusal_ = why_cant_take_quest(quest_id); TC_LOG_INFO("playerbot.v2", "[quest_share] {} cannot take shared quest {} from {} (CanTake={} CanAdd={})", p_->GetName(), quest_id, sender ? sender->GetName() : std::string("?"), p_->CanTakeQuest(quest, false), p_->CanAddQuest(quest, false)); diff --git a/src/modules/PlayerbotV2/Api/PlayerbotAPI.h b/src/modules/PlayerbotV2/Api/PlayerbotAPI.h index f82b27d7aa..36a58847bc 100644 --- a/src/modules/PlayerbotV2/Api/PlayerbotAPI.h +++ b/src/modules/PlayerbotV2/Api/PlayerbotAPI.h @@ -11,6 +11,7 @@ #include "Define.h" #include "ObjectGuid.h" +#include "Bot/Quest/QuestRefusal.h" #include #include #include @@ -169,6 +170,13 @@ public: // rejoin rule waits for a slot instead of walking a full instance's entrance. uint32 last_instance_full_map() const { return last_instance_full_map_; } void clear_instance_full_map() { last_instance_full_map_ = 0; } + // Why the last accept_quest / accept_shared_quest was refused (None after an accept that went through), and the quest it was + // for, so the executor can tell the player who ordered it (Bot/Quest/QuestRefusal.h). + QuestRefusal last_quest_refusal() const { return last_quest_refusal_; } + uint32 last_quest_refusal_quest() const { return last_quest_refusal_quest_; } + // The first of the server's own accept gates `quest_id` fails for this bot right now (CanTakeQuest, then the quest log and + // the bag room CanAddQuest checks), None when it could take it. No message reaches the bot's client. World thread. + QuestRefusal why_cant_take_quest(uint32 quest_id) const; static char const* CastFailName(uint32 code); // Why a mount spell would draw nothing on the client, nullptr when its model resolves: the display the aura picks (Mount @@ -1167,6 +1175,8 @@ private: Player* p_; uint32 last_cast_fail_ = 0; // see last_cast_fail() uint32 last_instance_full_map_ = 0; // see last_instance_full_map() + QuestRefusal last_quest_refusal_ = QuestRefusal::None; // see last_quest_refusal() + uint32 last_quest_refusal_quest_ = 0; }; } // namespace Playerbot diff --git a/src/modules/PlayerbotV2/Bot/BotBridge.cpp b/src/modules/PlayerbotV2/Bot/BotBridge.cpp index e5fa2307f3..1e56ce7488 100644 --- a/src/modules/PlayerbotV2/Bot/BotBridge.cpp +++ b/src/modules/PlayerbotV2/Bot/BotBridge.cpp @@ -10,7 +10,10 @@ #include "BotSnapshot.h" #include "ChannelTalk.h" #include "ClassicUpkeep.h" +#include "Quest/CompanionQuest.h" #include "Quest/QuestOrders.h" +#include "Quest/QuestRefusal.h" +#include "../Api/PlayerbotAPI.h" #include "../Api/BotTradeShop.h" #include "../Diagnostics/ScenarioHuman.h" #include "../Fleet/BotGuildCharter.h" @@ -1364,7 +1367,12 @@ std::string RunAction(ConfigReader::BridgeConfig const& cfg, Player* bot, Player for (auto const& off : snap->quest_discovery.quest_offers) offered = offered || off.quest_id == a.quest; if (!offered) + { + QuestRefusal const why = API(bot).why_cant_take_quest(a.quest); + if (why != QuestRefusal::None && why != QuestRefusal::Other) + return QuestRefusalLine(why, CompanionQuest::QuestLabel(a.quest)); return "nobody close offers me that quest"; + } detail = JoinLines(QuestOrders::AcceptAll(speaker, bot, std::to_string(a.quest))); return {}; } diff --git a/src/modules/PlayerbotV2/Bot/BotIntent.h b/src/modules/PlayerbotV2/Bot/BotIntent.h index c3f79888e9..285bac0548 100644 --- a/src/modules/PlayerbotV2/Bot/BotIntent.h +++ b/src/modules/PlayerbotV2/Bot/BotIntent.h @@ -144,7 +144,9 @@ struct RepairAllIntent { ObjectGuid npc; bool from_guild_bank; }; struct VendorBuyByCategoryIntent { ObjectGuid npc; uint8 item_class, item_subclass; uint8 total_count; }; // ---- Quest ---- -struct QuestAcceptIntent { ObjectGuid npc; uint32 quest_id; }; +// tell: the player who ordered the accept; when the server refuses it, the bot whispers them why (Bot/Quest/QuestRefusal.h). +// Empty for the bot's own questing, which retries quietly. +struct QuestAcceptIntent { ObjectGuid npc; uint32 quest_id; ObjectGuid tell; }; // `reward_choice` selects from the quest's choice-item list (0 = first). // Pass 0xFF to let PlayerbotAPI auto-pick (ScoreQuestReward weighs equippable // upgrades > vendor value). Quests with only fixed rewards ignore the field. @@ -154,8 +156,8 @@ struct QuestAbandonIntent { uint32 quest_id; }; // Accept a quest just shared by a group member. The receiver-side popup is // driven by `Player::SetQuestSharingInfo`; the API uses GetSharedQuestID for // the actual accept. No fields needed on the intent — the bot side already -// knows what's pending via the snapshot. -struct QuestSharedAcceptIntent {}; +// knows what's pending via the snapshot. `tell` as in QuestAcceptIntent. +struct QuestSharedAcceptIntent { ObjectGuid tell; }; // Run JunkQuestResolver on the bot: force-complete auto-granted feature quests // (55660 "Time Trials" etc. — abandon doesn't stick, they re-push at login) and // resolve profession-spec choice quests. No fields — the resolver processes the diff --git a/src/modules/PlayerbotV2/Bot/BotIntentEmitter.h b/src/modules/PlayerbotV2/Bot/BotIntentEmitter.h index fe1e15a1ac..51ab26b55b 100644 --- a/src/modules/PlayerbotV2/Bot/BotIntentEmitter.h +++ b/src/modules/PlayerbotV2/Bot/BotIntentEmitter.h @@ -323,12 +323,12 @@ public: { return emit(VehicleSpellIntent{spell_id, target}); } bool cast_vehicle_at(uint32 spell_id, float x, float y, float z) { return emit(VehicleGroundSpellIntent{spell_id, x, y, z}); } - bool accept_quest(ObjectGuid giver, uint32 quest_id) - { return emit(QuestAcceptIntent{giver, quest_id}); } + bool accept_quest(ObjectGuid giver, uint32 quest_id, ObjectGuid tell = ObjectGuid::Empty) + { return emit(QuestAcceptIntent{giver, quest_id, tell}); } bool complete_quest(ObjectGuid giver, uint32 quest_id, uint8 reward_choice = 0, bool copy_leader = false) { return emit(QuestCompleteIntent{giver, quest_id, reward_choice, copy_leader}); } bool abandon_quest(uint32 quest_id) { return emit(QuestAbandonIntent{quest_id}); } - bool accept_shared_quest() { return emit(QuestSharedAcceptIntent{}); } + bool accept_shared_quest(ObjectGuid tell = ObjectGuid::Empty) { return emit(QuestSharedAcceptIntent{tell}); } bool resolve_junk_quests() { return emit(ResolveJunkQuestsIntent{}); } // Mail. Mailbox guid is a GameObject (mailbox) or Creature (mailbox NPC); diff --git a/src/modules/PlayerbotV2/Bot/BotIntentExecutor.cpp b/src/modules/PlayerbotV2/Bot/BotIntentExecutor.cpp index e112d1312c..8bbfeff2b3 100644 --- a/src/modules/PlayerbotV2/Bot/BotIntentExecutor.cpp +++ b/src/modules/PlayerbotV2/Bot/BotIntentExecutor.cpp @@ -39,6 +39,8 @@ #include "GameTime.h" #include "Log.h" #include "Bot/DrainOrder.h" +#include "Bot/Quest/CompanionQuest.h" +#include "Bot/Quest/QuestRefusal.h" #include "Bot/ReactionTiming.h" #include "Combat/Apl/ApInterrupt.h" #include @@ -98,6 +100,27 @@ Result SayInZoneChannel(Player* bot, uint8 channel_id, std::string const& text) return Result::Ok; } +// A quest accept a player ordered (QuestAcceptIntent / QuestSharedAcceptIntent with `tell`) and the server refused: the bot +// whispers that player the gate that failed, in their language, instead of going quiet. The bot's own questing has no `tell`. +static void TellQuestRefusal(API& api, IntentBody const& body) +{ + ObjectGuid tell; + if (auto const* a = std::get_if(&body)) + tell = a->tell; + else if (auto const* s = std::get_if(&body)) + tell = s->tell; + if (tell.IsEmpty() || api.last_quest_refusal() == QuestRefusal::None) + return; + Player* const who = ObjectAccessor::FindConnectedPlayer(tell); + if (!who) + return; + uint32 const quest = api.last_quest_refusal_quest(); + if (quest == 0) // a share that ran out before this tick: there is no quest id left to name + api.whisper(who->GetName(), "The quest share ran out before I could take it."); + else + api.whisper(who->GetName(), QuestRefusalLine(api.last_quest_refusal(), CompanionQuest::QuestLabel(quest))); +} + // [bot_cc_onset]: the tick a bot goes from free to feared / confused / stunned, name the aura, its caster and how far the // caster is. Deadmines Sneed's Shredder Terrify hit the priest standing at 1.4 y and the warrior at 2.5-5 y; the log had no // onset line, so the radius of the effect was unknown. Edge-triggered per bot, no polling cost beyond a bit test. @@ -784,6 +807,8 @@ size_t V2::Module::DrainIntents() if (r == Result::ServerRefused && api.last_instance_full_map() != 0 && entry.ai) entry.ai->note_instance_full(api.last_instance_full_map(), GameTime::GetGameTimeMS()); api.clear_instance_full_map(); + if (r != Result::Ok) + TellQuestRefusal(api, intent.body); Services::Perf().record_intent_executed(); Services::Perf().record_intent_result(static_cast(r)); if (r != Result::Ok) diff --git a/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.cpp b/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.cpp index 1bea8e80ea..e329fcefa5 100644 --- a/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.cpp +++ b/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.cpp @@ -2,6 +2,8 @@ #include "Bot/Quest/QuestOrders.h" #include "Bot/Quest/CompanionQuest.h" +#include "Bot/Quest/QuestRefusal.h" +#include "Api/PlayerbotAPI.h" #include "Bot/BotSnapshot.h" #include "Bot/BotIntentEmitter.h" #include "Bot/BotRegistry.h" @@ -193,7 +195,7 @@ std::vector List(Player* /*sender*/, Player* bot, std::string_view return out; } -std::vector AcceptAll(Player* /*sender*/, Player* bot, std::string_view arg) +std::vector AcceptAll(Player* sender, Player* bot, std::string_view arg) { std::vector out; auto snap = SnapOf(bot); @@ -209,7 +211,7 @@ std::vector AcceptAll(Player* /*sender*/, Player* bot, std::string_ // A quest the group just shared with me. if (snap->social_events.shared_quest_id != 0) { - emit.accept_shared_quest(); + emit.accept_shared_quest(sender ? sender->GetGUID() : ObjectGuid::Empty); LogOrder(bot, "accept shared", snap->social_events.shared_quest_id); out.push_back(fmt::format("Taking the shared quest: {}", CompanionQuest::QuestLabel(snap->social_events.shared_quest_id))); ++taken; @@ -224,7 +226,7 @@ std::vector AcceptAll(Player* /*sender*/, Player* bot, std::string_ if (taken >= kMaxAcceptPerOrder) break; if (want && off.quest_id != want) continue; if (!needle.empty() && Lower(CompanionQuest::QuestLabel(off.quest_id)).find(needle) == std::string::npos) continue; - emit.accept_quest(off.giver, off.quest_id); + emit.accept_quest(off.giver, off.quest_id, sender ? sender->GetGUID() : ObjectGuid::Empty); LogOrder(bot, "accept", off.quest_id); out.push_back(fmt::format("Accepting: {}", CompanionQuest::QuestLabel(off.quest_id))); ++taken; @@ -238,7 +240,15 @@ std::vector AcceptAll(Player* /*sender*/, Player* bot, std::string_ out.push_back("Nothing on offer right here; I'll pick up what the quest givers near us have for the next 45 seconds."); } else if (taken == 0) - out.push_back("That quest isn't on offer from anyone next to me."); + { + // A quest named by id or link that the offers left out: the offers only hold what the bot can take, so say which gate + // keeps it out (level, class, done, log full ...) before saying nobody here has it. + QuestRefusal const why = want ? API(bot).why_cant_take_quest(want) : QuestRefusal::None; + if (why != QuestRefusal::None && why != QuestRefusal::Other) + out.push_back(QuestRefusalLine(why, CompanionQuest::QuestLabel(want))); + else + out.push_back("That quest isn't on offer from anyone next to me."); + } return out; } diff --git a/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.h b/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.h index 993fe14fca..39c0a1dce6 100644 --- a/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.h +++ b/src/modules/PlayerbotV2/Bot/Quest/QuestOrders.h @@ -2,8 +2,10 @@ // // Every function runs on the WORLD thread (the whisper / party-chat hook, where BotCommandParser::Dispatch // runs): it reads the bot's latest published snapshot and static data (ObjectMgr) and QUEUES intents on the -// bot's own intent queue; it never touches the bot's Player. The sender's Player is only read (quest status, -// CanTakeQuest) to filter what is worth sharing. It returns the reply lines for the owner; the caller whispers +// bot's own intent queue; it never changes the bot's Player (it reads it only through API::why_cant_take_quest, to say +// why a named quest is not on offer). The sender's Player is only read (quest status, CanTakeQuest) to filter what is +// worth sharing. An accept it queues carries the sender, so a refusal on the world thread is whispered back with its +// reason (Bot/Quest/QuestRefusal.h). It returns the reply lines for the owner; the caller whispers // them (WhisperIntent{sender->GetName(), line} through Push, or Chat). Nothing is whispered here. // // `arg` is the text after the verb, trimmed: a quest id, a quest link ("|Hquest:123:45|h[Title]|h|r"), a title diff --git a/src/modules/PlayerbotV2/Bot/Quest/QuestRefusal.h b/src/modules/PlayerbotV2/Bot/Quest/QuestRefusal.h new file mode 100644 index 0000000000..5ebf7dcc49 --- /dev/null +++ b/src/modules/PlayerbotV2/Bot/Quest/QuestRefusal.h @@ -0,0 +1,88 @@ +// QuestRefusal - why a bot could not take a quest, said to the player who asked for it (pure: no game objects, unit tested). +// +// The server's accept path (API::accept_quest / accept_shared_quest, Api/PlayerbotAPI.cpp) runs the same gates as a player's +// accept and records the first one that failed. When the owner ordered the accept ("accept", the AI bots bridge, a shared +// quest), the bot then says which gate it was instead of going quiet. The lines are English templates with `{}` for the quest; +// Util/BotLocaleRu.cpp has every one of them, so a Russian client reads them in Russian. + +#pragma once + +#include +#include +#include + +namespace Playerbot { + +enum class QuestRefusal : uint8_t +{ + None = 0, // nothing refused (or nothing recorded) + Other, // the quest is unknown, or a giver the bot cannot take quests from + Disabled, // turned off on this server (disables table) + OnIt, // already in the quest log + Done, // already handed in and not repeatable + OtherChoice, // one quest of its exclusive group is already taken or done + Class, + Race, + LowLevel, + HighLevel, + Skill, + Reputation, + Prerequisite, // the quest before it (or a breadcrumb's follow-up) is not done + Timed, // another timed quest is running + NotAgainYet, // a daily / weekly / monthly / seasonal quest already done this time + Conditions, // the conditions table says no (a phase, an aura, a world state) + Expansion, + LogFull, + BagsFull, // the item the quest hands out has no room + NoGiver, // the giver or the sharer is gone, or the share ran out + OutOfRange, + Unfinishable, // no objectives and nobody to hand it in to +}; + +// The template for `why` ("I can't take {}: ..."), or an empty view for None. +inline std::string_view QuestRefusalTemplate(QuestRefusal why) +{ + switch (why) + { + case QuestRefusal::None: return {}; + case QuestRefusal::Other: return "I can't take {}."; + case QuestRefusal::Disabled: return "I can't take {}: it is turned off on this server."; + case QuestRefusal::OnIt: return "I already have {}."; + case QuestRefusal::Done: return "I already did {}."; + case QuestRefusal::OtherChoice: return "I can't take {}: I already took another quest that rules it out."; + case QuestRefusal::Class: return "I can't take {}: it is not for my class."; + case QuestRefusal::Race: return "I can't take {}: it is not for my race."; + case QuestRefusal::LowLevel: return "I can't take {}: my level is too low."; + case QuestRefusal::HighLevel: return "I can't take {}: my level is too high."; + case QuestRefusal::Skill: return "I can't take {}: I don't have the skill for it."; + case QuestRefusal::Reputation: return "I can't take {}: my reputation isn't right for it."; + case QuestRefusal::Prerequisite: return "I can't take {}: I haven't done the quest that comes before it."; + case QuestRefusal::Timed: return "I can't take {}: I'm already on a timed quest."; + case QuestRefusal::NotAgainYet: return "I can't take {} again yet."; + case QuestRefusal::Conditions: return "I can't take {} yet: something else has to happen first."; + case QuestRefusal::Expansion: return "I can't take {}: it is from a later expansion."; + case QuestRefusal::LogFull: return "I can't take {}: my quest log is full."; + case QuestRefusal::BagsFull: return "I can't take {}: no room in my bags for its item."; + case QuestRefusal::NoGiver: return "I can't take {}: whoever offered it is gone."; + case QuestRefusal::OutOfRange: return "I can't take {}: I'm too far from the quest giver."; + case QuestRefusal::Unfinishable: return "I won't take {}: it can't be finished."; + } + return {}; +} + +// The line for `why` with the quest's name in it, or an empty string for None. +inline std::string QuestRefusalLine(QuestRefusal why, std::string_view quest) +{ + std::string_view const t = QuestRefusalTemplate(why); + size_t const at = t.find("{}"); + if (t.empty() || at == std::string_view::npos) + return std::string(t); + std::string out; + out.reserve(t.size() + quest.size()); + out.append(t.substr(0, at)); + out.append(quest.empty() ? std::string_view("that quest") : quest); + out.append(t.substr(at + 2)); + return out; +} + +} // namespace Playerbot diff --git a/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp b/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp index 2f765634d2..bd2c3b6845 100644 --- a/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp +++ b/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp @@ -386,6 +386,31 @@ std::vector const& RussianEntries() { "Nothing on offer right here; I'll pick up what the quest givers near us have for the next 45 seconds.", "Здесь заданий нет; следующие 45 секунд беру то, что дадут ближайшие NPC с заданиями." }, { "That quest isn't on offer from anyone next to me.", "Это задание никто рядом со мной не дает." }, + // why an accept was refused (Bot/Quest/QuestRefusal.h) + { "I can't take {}.", "Я не могу взять задание {}." }, + { "I can't take {}: it is turned off on this server.", "Я не могу взять задание {}: на этом сервере оно отключено." }, + { "I already have {}.", "Задание {} у меня уже есть." }, + { "I already did {}.", "Задание {} у меня уже сдано." }, + { "I can't take {}: I already took another quest that rules it out.", + "Я не могу взять задание {}: у меня уже было другое задание, которое его исключает." }, + { "I can't take {}: it is not for my class.", "Я не могу взять задание {}: оно не для моего класса." }, + { "I can't take {}: it is not for my race.", "Я не могу взять задание {}: оно не для моей расы." }, + { "I can't take {}: my level is too low.", "Я не могу взять задание {}: у меня слишком низкий уровень." }, + { "I can't take {}: my level is too high.", "Я не могу взять задание {}: у меня слишком высокий уровень." }, + { "I can't take {}: I don't have the skill for it.", "Я не могу взять задание {}: у меня нет нужного навыка." }, + { "I can't take {}: my reputation isn't right for it.", "Я не могу взять задание {}: не та репутация." }, + { "I can't take {}: I haven't done the quest that comes before it.", + "Я не могу взять задание {}: сначала нужно выполнить задание перед ним." }, + { "I can't take {}: I'm already on a timed quest.", "Я не могу взять задание {}: у меня уже есть задание на время." }, + { "I can't take {} again yet.", "Задание {} пока нельзя взять снова." }, + { "I can't take {} yet: something else has to happen first.", "Задание {} пока нельзя взять: сначала должно случиться другое." }, + { "I can't take {}: it is from a later expansion.", "Я не могу взять задание {}: оно из более позднего дополнения." }, + { "I can't take {}: my quest log is full.", "Я не могу взять задание {}: мой журнал заданий полон." }, + { "I can't take {}: no room in my bags for its item.", "Я не могу взять задание {}: в сумках нет места для его предмета." }, + { "I can't take {}: whoever offered it is gone.", "Я не могу взять задание {}: того, кто его дал, уже нет рядом." }, + { "I can't take {}: I'm too far from the quest giver.", "Я не могу взять задание {}: я слишком далеко от того, кто его дает." }, + { "I won't take {}: it can't be finished.", "Я не возьму задание {}: его нельзя выполнить." }, + { "The quest share ran out before I could take it.", "Время на общее задание вышло, взять его уже нельзя." }, { "I can't drop quests right now.", "Сейчас я не могу отменять задания." }, { "Drop which quest? Give its name, link or id, or \"all\".", "Какое задание отменить? Назовите его, дайте ссылку или номер, или \"all\"." }, { "I have no quest matching \"{}\".", "У меня нет задания \"{}\"." }, diff --git a/tests/game/ClassicBotLocale.cpp b/tests/game/ClassicBotLocale.cpp index cadc5660b2..b77e3cb4c0 100644 --- a/tests/game/ClassicBotLocale.cpp +++ b/tests/game/ClassicBotLocale.cpp @@ -21,6 +21,7 @@ #include "../../src/modules/PlayerbotV2/Util/BotLocaleText.h" #include "../../src/modules/PlayerbotV2/Bot/Raid/RaidBanter.h" +#include "../../src/modules/PlayerbotV2/Bot/Quest/QuestRefusal.h" #include #include #include @@ -231,6 +232,28 @@ TEST_CASE("BotLocale: boss tactics answers", "[BotLocale]") CHECK(Translate(Lang::Ru, "Bosses here: Lucifron, Magmadar.") == "Боссы здесь: Lucifron, Magmadar."); } +TEST_CASE("BotLocale: why a quest accept was refused", "[BotLocale]") +{ + using Playerbot::QuestRefusal; + using Playerbot::QuestRefusalLine; + CHECK(QuestRefusalLine(QuestRefusal::None, "Wolves") == ""); + CHECK(QuestRefusalLine(QuestRefusal::LowLevel, "Wolves Across the Border") == "I can't take Wolves Across the Border: my level is too low."); + CHECK(QuestRefusalLine(QuestRefusal::Done, "") == "I already did that quest."); + CHECK(Translate(Lang::Ru, QuestRefusalLine(QuestRefusal::LogFull, "Wolves")) == "Я не могу взять задание Wolves: мой журнал заданий полон."); + CHECK(Translate(Lang::Ru, QuestRefusalLine(QuestRefusal::NotAgainYet, "Wolves")) == "Задание Wolves пока нельзя взять снова."); + + // Every reason has a line with the quest in it, and every line has its Russian form. + Catalog const& ru = Russian(); + for (uint8_t r = uint8_t(QuestRefusal::Other); r <= uint8_t(QuestRefusal::Unfinishable); ++r) + { + std::string const s = QuestRefusalLine(QuestRefusal(r), "Wolves"); + INFO(s); + CHECK(s.find("Wolves") != std::string::npos); + CHECK(ru.Knows(s)); + } + CHECK(ru.Knows("The quest share ran out before I could take it.")); +} + TEST_CASE("BotLocale: unknown lines come back in English", "[BotLocale]") { CHECK(Translate(Lang::Ru, "Perf: ticks=5 emit=3") == "Perf: ticks=5 emit=3");