Compare commits

..

3 Commits

7 changed files with 34 additions and 30 deletions

View File

@ -101,6 +101,22 @@ std::string PlayerbotTextMgr::GetBotText(std::string name, std::map<std::string,
return botText;
}
std::string PlayerbotTextMgr::GetBotTextOrDefault(std::string name, std::string defaultText,
std::map<std::string, std::string> placeholders)
{
std::string botText = GetBotText(name, placeholders);
if (botText.empty())
{
for (std::map<std::string, std::string>::iterator i = placeholders.begin(); i != placeholders.end(); ++i)
{
replaceAll(defaultText, i->first, i->second);
}
return defaultText;
}
return botText;
}
// chat replies
std::string PlayerbotTextMgr::GetBotText(ChatReplyType replyType, std::map<std::string, std::string> placeholders)

View File

@ -83,6 +83,8 @@ public:
std::string GetBotText(ChatReplyType replyType, std::string name);
bool GetBotText(std::string name, std::string& text);
bool GetBotText(std::string name, std::string& text, std::map<std::string, std::string> placeholders);
std::string GetBotTextOrDefault(std::string name, std::string defaultText,
std::map<std::string, std::string> placeholders);
void LoadBotTexts();
void LoadBotTextChance();
static void replaceAll(std::string& str, const std::string& from, const std::string& to);

View File

@ -47,6 +47,8 @@ public:
std::unordered_map<std::string, ObjectCreator> creators;
public:
virtual ~NamedObjectFactory() = default;
virtual T* create(std::string name, PlayerbotAI* botAI)
{
size_t found = name.find("::");
@ -147,9 +149,7 @@ public:
{
contexts.push_back(context);
for (const auto& iter : context->creators)
{
creators[iter.first] = iter.second;
}
}
};
@ -208,6 +208,7 @@ public:
if (T* object = create(name, botAI))
return created[name] = object;
}
return created[name];
}
@ -236,7 +237,6 @@ public:
for (auto i = contexts.begin(); i != contexts.end(); i++)
{
std::set<std::string> supported = (*i)->supports();
for (std::set<std::string>::const_iterator j = supported.begin(); j != supported.end(); ++j)
result.insert(*j);
}
@ -248,9 +248,7 @@ public:
{
std::set<std::string> result;
for (typename std::unordered_map<std::string, T*>::const_iterator i = created.begin(); i != created.end(); i++)
{
result.insert(i->first);
}
return result;
}
@ -297,15 +295,14 @@ public:
{
factories.push_back(context);
for (const auto& iter : context->creators)
{
creators[iter.first] = iter.second;
}
}
T* GetContextObject(const std::string& name, PlayerbotAI* botAI)
{
if (T* object = create(name, botAI))
return object;
return nullptr;
}
};

View File

@ -184,8 +184,8 @@ private:
static Strategy* grind(PlayerbotAI* botAI) { return new GrindingStrategy(botAI); }
static Strategy* avoid_aoe(PlayerbotAI* botAI) { return new AvoidAoeStrategy(botAI); }
static Strategy* tank_face(PlayerbotAI* botAI) { return new TankFaceStrategy(botAI); }
static Strategy* move_random(PlayerbotAI* ai) { return new MoveRandomStrategy(ai); }
static Strategy* combat_formation(PlayerbotAI* ai) { return new CombatFormationStrategy(ai); }
static Strategy* move_random(PlayerbotAI* botAI) { return new MoveRandomStrategy(botAI); }
static Strategy* combat_formation(PlayerbotAI* botAI) { return new CombatFormationStrategy(botAI); }
static Strategy* move_from_group(PlayerbotAI* botAI) { return new MoveFromGroupStrategy(botAI); }
static Strategy* world_buff(PlayerbotAI* botAI) { return new WorldBuffStrategy(botAI); }
};

View File

@ -125,26 +125,15 @@ namespace ai::buff
key = "rp_missing_reagent_generic";
// Placeholders
std::map<std::string, std::string> ph;
ph["%group_spell"] = groupName;
ph["%base_spell"] = baseName;
std::map<std::string, std::string> placeholders;
placeholders["%group_spell"] = groupName;
placeholders["%base_spell"] = baseName;
// Respecte ai_playerbot_texts_chance if present
std::string rp;
bool got = sPlayerbotTextMgr->GetBotText(key, rp, ph);
if (got && !rp.empty())
{
announce(rp);
last = now;
}
else
{
// Minimal Fallback
std::ostringstream oss;
oss << "Out of components for " << groupName << ". Using " << baseName << "!";
announce(oss.str());
last = now;
}
std::string announceText = sPlayerbotTextMgr->GetBotTextOrDefault(key,
"Out of components for %group_spell. Using %base_spell!", placeholders);
announce(announceText);
last = now;
}
}
}

View File

@ -20,7 +20,7 @@ public:
class AutoShareQuestAction : public ShareQuestAction
{
public:
AutoShareQuestAction(PlayerbotAI* ai) : ShareQuestAction(botAI, "auto share quest") {}
AutoShareQuestAction(PlayerbotAI* botAI) : ShareQuestAction(botAI, "auto share quest") {}
bool Execute(Event event) override;
bool isUseful() override;

View File

@ -24,7 +24,7 @@ public:
class MoveRandomStrategy : public NonCombatStrategy
{
public:
MoveRandomStrategy(PlayerbotAI* ai) : NonCombatStrategy(botAI) {}
MoveRandomStrategy(PlayerbotAI* botAI) : NonCombatStrategy(botAI) {}
std::string const getName() override { return "move random"; }
void InitTriggers(std::vector<TriggerNode*>& triggers) override;
};