Skip to content

Commit

Permalink
Localize more bot texts
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed Sep 28, 2023
1 parent 739f864 commit 03f168f
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 71 deletions.
9 changes: 4 additions & 5 deletions playerbot/strategy/actions/AutoLearnSpellAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "AutoLearnSpellAction.h"
#include "ServerFacade.h"


using namespace ai;

bool AutoLearnSpellAction::Execute(Event& event)
Expand All @@ -18,20 +17,20 @@ bool AutoLearnSpellAction::Execute(Event& event)
{
const std::string& temp = out.str();
out.seekp(0);
out << "Learned spells: ";
out << temp;
out.seekp(-2, out.cur);
out << ".";
ai->TellPlayer(GetMaster(), out, PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, false);

map<string, string> args;
args["%spells"] = out.str();
ai->TellPlayer(GetMaster(), BOT_TEXT2("auto_learn_spell", args), PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, false);
}

return true;
}


void AutoLearnSpellAction::LearnSpells(ostringstream* out)
{

if (sPlayerbotAIConfig.guildFeedbackRate && frand(0, 100) <= sPlayerbotAIConfig.guildFeedbackRate && bot->GetGuildId() && sRandomPlayerbotMgr.IsFreeBot(bot))
{
Guild* guild = sGuildMgr.GetGuildById(bot->GetGuildId());
Expand Down
28 changes: 23 additions & 5 deletions playerbot/strategy/actions/EquipAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,37 @@ bool EquipAction::Execute(Event& event)
{
//Get items based on text.
list<Item*> found = ai->InventoryParseItems(text, IterateItemsMask::ITERATE_ITEMS_IN_BAGS);

//Sort items on itemLevel descending.
found.sort([](Item* i, Item* j) {return i->GetProto()->ItemLevel > j->GetProto()->ItemLevel; });

vector< uint16> dests;

for (auto& item : found)
{
uint32 itemId = item->GetProto()->ItemId;
if (std::find(ids.begin(), ids.end(), itemId) != ids.end())
{
continue;
}

uint16 dest;
InventoryResult msg = bot->CanEquipItem(NULL_SLOT, dest, item, true);

if (msg != EQUIP_ERR_OK)
{
continue;
}

if (std::find(dests.begin(), dests.end(), dest) != dests.end())
{
continue;
}

dests.push_back(dest);
ids.insert(itemId);
}
}

EquipItems(requester, ids);
return true;
}
Expand Down Expand Up @@ -83,7 +90,10 @@ void EquipAction::EquipItem(Player* requester, FindItemVisitor* visitor)
{
ai->InventoryIterateItems(visitor, IterateItemsMask::ITERATE_ITEMS_IN_BAGS);
list<Item*> items = visitor->GetResult();
if (!items.empty()) EquipItem(requester, *items.begin());
if (!items.empty())
{
EquipItem(requester, *items.begin());
}
}

//Return the bag slot with smallest bag
Expand All @@ -97,13 +107,17 @@ uint8 EquipAction::GetSmallestBagSlot()
if (pBag)
{
if (curBag > 0 && curSlots < pBag->GetBagSize())
{
continue;
}

curBag = bag;
curSlots = pBag->GetBagSize();
}
else
{
return bag;
}
}

return curBag;
Expand Down Expand Up @@ -153,9 +167,9 @@ void EquipAction::EquipItem(Player* requester, Item* item)

sPlayerbotAIConfig.logEvent(ai, "EquipAction", item->GetProto()->Name1, to_string(item->GetProto()->ItemId));

ostringstream out; out << "equipping " << chat->formatItem(item);

ai->TellPlayer(requester, out, PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, false);
map<string, string> args;
args["%item"] = chat->formatItem(item);
ai->TellPlayer(requester, BOT_TEXT2("equip_command", args), PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, false);
}

bool EquipUpgradesAction::Execute(Event& event)
Expand All @@ -171,7 +185,9 @@ bool EquipUpgradesAction::Execute(Event& event)
p >> status;

if (status != TRADE_STATUS_TRADE_ACCEPT)
{
return false;
}
}
else if (event.getSource() == "item push result")
{
Expand All @@ -184,7 +200,9 @@ bool EquipUpgradesAction::Execute(Event& event)
ObjectGuid guid;
data >> guid;
if (guid != bot->GetObjectGuid())
{
return false;
}

uint32 received, created, isShowChatMessage, slotId, itemId, suffixFactor, count;
uint32 itemRandomPropertyId;
Expand Down
23 changes: 14 additions & 9 deletions playerbot/strategy/actions/RewardAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,37 @@ bool RewardAction::Execute(Event& event)

ItemIds itemIds = chat->parseItems(link);
if (itemIds.empty())
{
return false;
}

uint32 itemId = *itemIds.begin();

list<ObjectGuid> npcs = AI_VALUE(list<ObjectGuid>, "nearest npcs");
for (list<ObjectGuid>::iterator i = npcs.begin(); i != npcs.end(); i++)
{
Unit* npc = ai->GetUnit(*i);
if (npc && Reward(requester, itemId, npc))
{
return true;
}
}

list<ObjectGuid> gos = AI_VALUE(list<ObjectGuid>, "nearest game objects");
for (list<ObjectGuid>::iterator i = gos.begin(); i != gos.end(); i++)
{
GameObject* go = ai->GetGameObject(*i);
if (go && Reward(requester, itemId, go))
{
return true;
}
}

if (requester && Reward(requester, itemId, requester))
return true;
{
return true;
}

ai->TellError("Cannot talk to quest giver");
ai->TellPlayer(requester, BOT_TEXT("quest_error_talk"), PlayerbotSecurityLevel::PLAYERBOT_SECURITY_ALLOW_ALL, false);
return false;
}

Expand All @@ -53,7 +60,7 @@ bool RewardAction::Reward(Player* requester, uint32 itemId, Object* questGiver)

// if quest is complete, turn it in
if (status == QUEST_STATUS_COMPLETE &&
! bot->GetQuestRewardStatus(questID) &&
!bot->GetQuestRewardStatus(questID) &&
pQuest->GetRewChoiceItemsCount() > 1 &&
bot->CanRewardQuest(pQuest, false))
{
Expand All @@ -64,11 +71,9 @@ bool RewardAction::Reward(Player* requester, uint32 itemId, Object* questGiver)
{
bot->RewardQuest(pQuest, rewardIdx, questGiver, false);

string questTitle = pQuest->GetTitle();
string itemName = pRewardItem->Name1;

ostringstream out; out << chat->formatItem(pRewardItem) << " rewarded";
ai->TellPlayer(requester, out);
map<string, string> args;
args["%item"] = chat->formatItem(pRewardItem);
ai->TellPlayer(requester, BOT_TEXT2("quest_choose_reward", args));

return true;
}
Expand Down
Loading

0 comments on commit 03f168f

Please sign in to comment.