-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skill action: New skill command which lists all current skills, a spe…
…cific skill based on namepart or link and allows unlearning of skills using skill unlearn link/namepart
- Loading branch information
1 parent
c6f2c42
commit 5706830
Showing
7 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
|
||
#include "playerbot/playerbot.h" | ||
#include "SkillAction.h" | ||
#include "Tools/Language.h" | ||
|
||
using namespace ai; | ||
|
||
bool SkillAction::Execute(Event& event) | ||
{ | ||
Player* requester = event.getOwner() ? event.getOwner() : GetMaster(); | ||
std::string cmd = event.getParam(); | ||
|
||
bool unlearn = (cmd.find("unlearn ") == 0); | ||
|
||
std::string skillName = cmd; | ||
|
||
if (unlearn) | ||
skillName = skillName.substr(8); | ||
|
||
std::wstring wnamepart; | ||
|
||
if (!Utf8toWStr(skillName, wnamepart)) | ||
return false; | ||
|
||
std::set<uint32> skillIds = ChatHelper::ExtractAllSkillIds(skillName); | ||
|
||
// converting string that we try to find to lower case | ||
wstrToLower(wnamepart); | ||
|
||
bool skillFound = false; | ||
std::map<std::string, std::string> args; | ||
|
||
for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); ++id) | ||
{ | ||
if (!bot->HasSkill(id)) | ||
continue; | ||
|
||
SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id); | ||
if (skillInfo) | ||
{ | ||
int loc = requester->GetSession()->GetSessionDbcLocale(); | ||
|
||
std::string name = skillInfo->name[loc]; | ||
|
||
if (!skillName.empty() && skillIds.empty()) | ||
{ | ||
if (name.empty()) | ||
continue; | ||
|
||
if (!Utf8FitTo(name, wnamepart)) | ||
{ | ||
loc = 0; | ||
for (; loc < MAX_LOCALE; ++loc) | ||
{ | ||
if (loc == requester->GetSession()->GetSessionDbcLocale()) | ||
continue; | ||
|
||
name = skillInfo->name[loc]; | ||
if (name.empty()) | ||
continue; | ||
|
||
if (Utf8FitTo(name, wnamepart)) | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (skillName.empty() || skillIds.find(id) != skillIds.end() || (loc < MAX_LOCALE && skillIds.empty())) | ||
{ | ||
if (unlearn) | ||
{ | ||
args["%skillname"] = name; | ||
|
||
if (!bot->GetSkillInfo(uint16(id), ([](SkillRaceClassInfoEntry const& entry) { return (entry.flags & SKILL_FLAG_CAN_UNLEARN); }))) | ||
{ | ||
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unable to unlearn %skillname", args)); | ||
return false; | ||
} | ||
|
||
bot->SetSkillStep(uint16(id), 0); | ||
|
||
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Unlearned %skillname", args)); | ||
|
||
return true; | ||
} | ||
|
||
char valStr[50] = ""; | ||
char const* knownStr = ""; | ||
knownStr = requester->GetSession()->GetMangosString(LANG_KNOWN); | ||
uint32 curValue = bot->GetSkillValuePure(id); | ||
uint32 maxValue = bot->GetSkillMaxPure(id); | ||
uint32 permValue = bot->GetSkillBonusPermanent(id); | ||
uint32 tempValue = bot->GetSkillBonusTemporary(id); | ||
|
||
char const* valFormat = requester->GetSession()->GetMangosString(LANG_SKILL_VALUES); | ||
snprintf(valStr, 50, valFormat, curValue, maxValue, permValue, tempValue); | ||
std::ostringstream out; | ||
out << "|cffffffff|Hskill:"; | ||
out << id; | ||
out << "|h["; | ||
out << name; | ||
out << "]|h|r ("; | ||
|
||
out << curValue << "/" << maxValue; | ||
|
||
if (permValue) | ||
out << " +perm " << permValue; | ||
|
||
if (tempValue) | ||
out << " +temp " << permValue; | ||
|
||
out << ")"; | ||
|
||
ai->TellPlayerNoFacing(requester, out); | ||
|
||
skillFound = true; | ||
} | ||
} | ||
} | ||
|
||
if (!skillFound) | ||
{ | ||
if (skillName.empty()) | ||
{ | ||
ai->TellPlayerNoFacing(requester, BOT_TEXT2("No skills found.", args)); | ||
} | ||
else | ||
{ | ||
args["%skillname"] = skillName; | ||
ai->TellPlayerNoFacing(requester, BOT_TEXT2("Skill %skillname not found.", args)); | ||
} | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "playerbot/LootObjectStack.h" | ||
#include "GenericActions.h" | ||
|
||
namespace ai | ||
{ | ||
class SkillAction : public ChatCommandAction | ||
{ | ||
public: | ||
SkillAction(PlayerbotAI* ai) : ChatCommandAction(ai, "skill") {} | ||
virtual bool Execute(Event& event) override; | ||
|
||
#ifdef GenerateBotHelp | ||
virtual std::string GetHelpName() { return "skill"; } //Must equal iternal name | ||
virtual std::string GetHelpDescription() | ||
{ | ||
return "This chat command gives information about a bot\'s skills.\n" | ||
"Examples:\n" | ||
"skill : List all skills and their current level.\n" | ||
"skill [name] : List the skill level of a current skill.\n" | ||
"ss unlearn [name] : Unlearns a primary profession.\n"; | ||
} | ||
virtual std::vector<std::string> GetUsedActions() { return {}; } | ||
virtual std::vector<std::string> GetUsedValues() { return {}; } | ||
#endif | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters