17 std::string TrimCommandText(std::string text)
19 std::string::size_type first = text.find_first_not_of(
" \t\r\n");
20 if (first == std::string::npos)
23 std::string::size_type last = text.find_last_not_of(
" \t\r\n");
24 text = text.substr(first, last - first + 1);
26 if (text.size() >= 2 && text[0] ==
'"' && text[text.size() - 1] ==
'"')
27 text = text.substr(1, text.size() - 2);
29 first = text.find_first_not_of(
" \t\r\n");
30 if (first == std::string::npos)
33 last = text.find_last_not_of(
" \t\r\n");
34 return text.substr(first, last - first + 1);
37 std::string GetBattlePetCommandName(
char const* args)
39 return TrimCommandText(args ? args :
"");
42 bool IsAllArgument(std::string
const& text)
44 return !text.empty() && !stricmp(text.c_str(),
"all");
72 if (!nickname.empty())
76 return speciesName.empty() ? std::string(
"<unknown>") : speciesName;
81 std::string displayName = GetBattlePetDisplayName(battlePetMgr, battlePet);
87 speciesName.empty() ?
"unknown" : speciesName.c_str());
92 handler->
PSendSysMessage(
" Power: %u Speed: %u Quality: %u Breed: %u Flags: %u",
102 handler->
PSendSysMessage(
"Usage: .battlepet levelup \"name\" or .battlepet heal \"name\"");
110 handler->
PSendSysMessage(
"No battle pet named '%s' was found.", name.c_str());
115 if (matches.size() > 1)
117 handler->
PSendSysMessage(
"Multiple battle pets named '%s' were found. Rename one or use a unique species name.", name.c_str());
118 for (std::vector<BattlePet*>::const_iterator itr = matches.begin(); itr != matches.end(); ++itr)
120 uint64((*itr)->GetId()), GetBattlePetDisplayName(battlePetMgr, *itr).c_str(),
121 uint32((*itr)->GetLevel()));
127 return matches.front();
138 static std::vector<ChatCommand> battlePetCommandTable =
145 static std::vector<ChatCommand> commandTable =
154 Player* target = GetBattlePetCommandTarget(handler);
159 BattlePet* battlePet = GetUniqueBattlePetByName(handler, battlePetMgr, GetBattlePetCommandName(args));
165 handler->
PSendSysMessage(
"%s is already max level.", GetBattlePetDisplayName(battlePetMgr, battlePet).c_str());
177 GetBattlePetDisplayName(battlePetMgr, battlePet).c_str(),
uint32(oldLevel),
184 Player* target = GetBattlePetCommandTarget(handler);
189 std::string name = GetBattlePetCommandName(args);
190 if (IsAllArgument(name))
198 BattlePet* battlePet = GetUniqueBattlePetByName(handler, battlePetMgr, name);
207 GetBattlePetDisplayName(battlePetMgr, battlePet).c_str(), target->
GetName().c_str());
213 Player* target = GetBattlePetCommandTarget(handler);
220 handler->
PSendSysMessage(
" Loadout flags: %u Trap ability: %u Active battle: %s PvP queued: %s",
237 handler->
PSendSysMessage(
" Enemy species: %u quality: %u health: %u/%u payload: %u",
265 uint32(slot + 1), GetBattlePetDisplayName(battlePetMgr, battlePet).c_str(),
270 std::string name = GetBattlePetCommandName(args);
273 BattlePet* battlePet = GetUniqueBattlePetByName(handler, battlePetMgr, name);
277 SendBattlePetDetails(handler, battlePetMgr, battlePet);
uint16 BattlePetExperienceReward(uint8 petLevel, uint8 enemyLevel, uint8 participatingPetCount)
uint16 BattlePetExperienceForNextLevel(uint8 level)
#define BATTLE_PET_MAX_LEVEL
char const * BattlePetAchievementSourceName(BattlePetAchievementSource source)
#define BATTLE_PET_MAX_LOADOUT_SLOTS
void SetLevel(uint8 level)
void SetCurrentHealth(uint16 health)
uint16 GetCurrentHealth() const
uint16 GetSpecies() const
uint16 GetMaxHealth() const
std::string GetNickname() const
uint8 GetLoadoutFlags() const
bool IsPetBattlePvpQueued() const
uint32 GetTrapAbility() const
uint32 GetBattlePetCount() const
ActivePetBattle const & GetActivePetBattle() const
std::string GetBattlePetSpeciesName(BattlePet const *battlePet) const
uint64 GetLoadoutSlot(uint8 slot) const
uint64 GetCurrentSummonId() const
BattlePetAchievementContext BuildActivePetBattleAchievementContext(uint16 speciesId, uint8 quality, bool won, bool captured) const
bool HasLoadoutSlot(uint8 slot) const
BattlePet * GetBattlePet(uint64 id) const
void UpdateBattlePetLevelAchievement(BattlePet const &battlePet, uint8 initialLevel, uint8 finalLevel)
void SendBattlePetUpdate(BattlePet *battlePet, bool notification)
std::vector< BattlePet * > FindBattlePetNameMatches(std::string const &name) const
bool HasActivePetBattle() const
void HealBattlePets(uint8 percent)
bool HasLowerSecurity(Player *target, uint64 guid, bool strong=false)
Player * getSelectedPlayer()
WorldSession * GetSession()
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
void SetSentErrorMessage(bool val)
CommandScript(const char *name)
BattlePetMgr * GetBattlePetMgr()
std::string const & GetName() const
Player * GetPlayer() const
battlepet_commandscript()
std::vector< ChatCommand > GetCommands() const OVERRIDE
static bool HandleBattlePetDebugCommand(ChatHandler *handler, char const *args)
static bool HandleBattlePetLevelupCommand(ChatHandler *handler, char const *args)
static bool HandleBattlePetHealCommand(ChatHandler *handler, char const *args)
void AddSC_battlepet_commandscript()
@ RBAC_PERM_COMMAND_BATTLEPET
@ RBAC_PERM_COMMAND_BATTLEPET_LEVELUP
@ RBAC_PERM_COMMAND_BATTLEPET_HEAL
@ RBAC_PERM_COMMAND_BATTLEPET_DEBUG
BattlePetAchievementSource GetAchievementSource() const