static bool HandleLearnCommand(ChatHandler* handler, const char* args) { Player* targetPlayer = handler->getSelectedPlayer(); if(!targetPlayer) { handler->SendSysMessage(LANG_PLAYER_NOT_FOUND); handler->SetSentErrorMessage(true); return false; } // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spell = handler->extractSpellIdFromLink((char*)args); if(!spell || !sSpellStore.LookupEntry(spell)) return false; char const* allStr = strtok(NULL, " "); bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false; SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell); if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer())) { handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell); handler->SetSentErrorMessage(true); return false; } if(!allRanks && targetPlayer->HasSpell(spell)) { if(targetPlayer == handler->GetSession()->GetPlayer()) handler->SendSysMessage(LANG_YOU_KNOWN_SPELL); else handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str()); handler->SetSentErrorMessage(true); return false; } if(allRanks) targetPlayer->learnSpellHighRank(spell); else targetPlayer->learnSpell(spell, false); uint32 first_spell = sSpellMgr->GetFirstSpellInChain(spell); if(GetTalentSpellCost(first_spell)) targetPlayer->SendTalentsInfoData(false); return true; }
static bool HandleListAurasCommand(ChatHandler* handler, char const* /*args*/) { Unit* unit = handler->getSelectedUnit(); if (!unit) { handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE); handler->SetSentErrorMessage(true); return false; } char const* talentStr = handler->GetTrinityString(LANG_TALENT); char const* passiveStr = handler->GetTrinityString(LANG_PASSIVE); Unit::AuraApplicationMap const& auras = unit->GetAppliedAuras(); handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, auras.size()); for (Unit::AuraApplicationMap::const_iterator itr = auras.begin(); itr != auras.end(); ++itr) { bool talent = GetTalentSpellCost(itr->second->GetBase()->GetId()) > 0; AuraApplication const* aurApp = itr->second; Aura const* aura = aurApp->GetBase(); char const* name = aura->GetSpellInfo()->SpellName[handler->GetSessionDbcLocale()]; std::ostringstream ss_name; ss_name << "|cffffffff|Hspell:" << aura->GetId() << "|h[" << name << "]|h|r"; handler->PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, aura->GetId(), (handler->GetSession() ? ss_name.str().c_str() : name), aurApp->GetEffectMask(), aura->GetCharges(), aura->GetStackAmount(), aurApp->GetSlot(), aura->GetDuration(), aura->GetMaxDuration(), (aura->IsPassive() ? passiveStr : ""), (talent ? talentStr : ""), aura->GetCasterGUID().IsPlayer() ? "player" : "creature", aura->GetCasterGUID().GetCounter()); } for (uint16 i = 0; i < TOTAL_AURAS; ++i) { Unit::AuraEffectList const& auraList = unit->GetAuraEffectsByType(AuraType(i)); if (auraList.empty()) continue; handler->PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, auraList.size(), i); for (Unit::AuraEffectList::const_iterator itr = auraList.begin(); itr != auraList.end(); ++itr) handler->PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(), (*itr)->GetAmount()); } return true; }
static bool HandleLearnAllMySpellsCommand(ChatHandler* handler, char const* /*args*/) { ChrClassesEntry const* classEntry = sChrClassesStore.LookupEntry(handler->GetSession()->GetPlayer()->getClass()); if (!classEntry) return true; uint32 family = classEntry->spellfamily; for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i) { SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(i); if (!entry) continue; SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(entry->spellId); if (!spellInfo) continue; // skip server-side/triggered spells if (spellInfo->SpellLevel == 0) continue; // skip wrong class/race skills if (!handler->GetSession()->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id)) continue; // skip other spell families if (spellInfo->SpellFamilyName != family) continue; // skip spells with first rank learned as talent (and all talents then also) uint32 firstRank = sSpellMgr->GetFirstSpellInChain(spellInfo->Id); if (GetTalentSpellCost(firstRank) > 0) continue; // skip broken spells if (!SpellMgr::IsSpellValid(spellInfo, handler->GetSession()->GetPlayer(), false)) continue; handler->GetSession()->GetPlayer()->learnSpell(spellInfo->Id, false); } handler->SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS); return true; }
static bool HandleUnLearnCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r uint32 spellId = handler->extractSpellIdFromLink((char*)args); if (!spellId) return false; char const* allStr = strtok(NULL, " "); bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false; Player* target = handler->getSelectedPlayer(); if (!target) { handler->SendSysMessage(LANG_NO_CHAR_SELECTED); handler->SetSentErrorMessage(true); return false; } if (!target->GetCommandStatus(TOGGLE_MODIFY) && !handler->GetSession()->GetPlayer()->IsAdmin() && handler->GetSession()->GetPlayer()->GetGUID() != target->GetGUID()) { handler->PSendSysMessage("%s has modify disabled. You can't use commands on them.", target->GetName().c_str()); return true; } if (allRanks) spellId = sSpellMgr->GetFirstSpellInChain(spellId); if (target->HasSpell(spellId)) target->RemoveSpell(spellId, false, !allRanks); else handler->SendSysMessage(LANG_FORGET_SPELL); if (GetTalentSpellCost(spellId)) target->SendTalentsInfoData(false); return true; }
static bool HandleUnLearnCommand(ChatHandler* handler, char const* args) { Player* target; uint64 targetGuid; std::string targetName; if (!handler->extractPlayerTarget((char*)args, &target, &targetGuid, &targetName)) return false; if (!target) { handler->SetSentErrorMessage(true); return false; } char const* spell = strtok(NULL, ""); if (!spell) return false; // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellId = handler->extractSpellIdFromLink((char*)spell); if (!spellId || !sSpellMgr->GetSpellInfo(spellId)) return false; char const* allStr = strtok(NULL, " "); bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false; if (allRanks) spellId = sSpellMgr->GetFirstSpellInChain (spellId); if (target->HasSpell(spellId)) target->removeSpell(spellId, false, !allRanks); else handler->SendSysMessage(LANG_FORGET_SPELL); if (GetTalentSpellCost(spellId)) target->SendTalentsInfoData(false); return true; }
uint32 GetTalentSpellCost(uint32 spellId) { return GetTalentSpellCost(GetTalentSpellPos(spellId)); }
static bool HandleLearnCommand(ChatHandler* handler, char const* args) { Player* targetPlayer = handler->getSelectedPlayer(); if (!targetPlayer) { handler->SendSysMessage(LANG_PLAYER_NOT_FOUND); handler->SetSentErrorMessage(true); return false; } // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spell = handler->extractSpellIdFromLink((char*)args); if (!spell) return false; SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spell); if (!spellInfo) { handler->PSendSysMessage(LANG_COMMAND_NOSPELLFOUND); handler->SetSentErrorMessage(true); return false; } if (!SpellMgr::IsSpellValid(spellInfo)) { handler->PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell); handler->SetSentErrorMessage(true); return false; } SpellScriptsBounds bounds = sObjectMgr->GetSpellScriptsBounds(spell); uint32 spellDifficultyId = sSpellMgr->GetSpellDifficultyId(spell); if (handler->GetSession()->GetSecurity() < SEC_CONSOLE && (bounds.first != bounds.second || spellDifficultyId)) { handler->PSendSysMessage("Spell %u cannot be learnt using a command!", spell); handler->SetSentErrorMessage(true); return false; } char const* all = strtok(NULL, " "); bool allRanks = all ? (strncmp(all, "all", strlen(all)) == 0) : false; if (!allRanks && targetPlayer->HasSpell(spell)) { if (targetPlayer == handler->GetSession()->GetPlayer()) handler->SendSysMessage(LANG_YOU_KNOWN_SPELL); else handler->PSendSysMessage(LANG_TARGET_KNOWN_SPELL, handler->GetNameLink(targetPlayer).c_str()); handler->SetSentErrorMessage(true); return false; } if (allRanks) targetPlayer->learnSpellHighRank(spell); else targetPlayer->learnSpell(spell); uint32 firstSpell = sSpellMgr->GetFirstSpellInChain(spell); if (GetTalentSpellCost(firstSpell)) targetPlayer->SendTalentsInfoData(false); return true; }
static bool HandleLookupSpellIdCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // can be NULL at console call Player* target = handler->getSelectedPlayer(); uint32 id = atoi((char*)args); if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id)) { int locale = handler->GetSessionDbcLocale(); std::string name = spellInfo->SpellName; if (name.empty()) { handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); return true; } bool known = target && target->HasSpell(id); bool learn = (spellInfo->Effects[0].Effect == SPELL_EFFECT_LEARN_SPELL); SpellInfo const* learnSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[0].TriggerSpell); uint32 talentCost = GetTalentSpellCost(id); bool talent = (talentCost > 0); bool passive = spellInfo->IsPassive(); bool active = target && target->HasAura(id); // unit32 used to prevent interpreting uint8 as char at output // find rank of learned spell for learning spell, or talent rank uint32 rank = talentCost ? talentCost : learn && learnSpellInfo ? learnSpellInfo->GetRank() : spellInfo->GetRank(); // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format std::ostringstream ss; if (handler->GetSession()) ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; else ss << id << " - " << name; // include rank in link name if (rank) ss << handler->GetTrinityString(LANG_SPELL_RANK) << rank; if (handler->GetSession()) ss << ' ' << localeNames[locale] << "]|h|r"; else ss << ' ' << localeNames[locale]; if (talent) ss << handler->GetTrinityString(LANG_TALENT); if (passive) ss << handler->GetTrinityString(LANG_PASSIVE); if (learn) ss << handler->GetTrinityString(LANG_LEARN); if (known) ss << handler->GetTrinityString(LANG_KNOWN); if (active) ss << handler->GetTrinityString(LANG_ACTIVE); handler->SendSysMessage(ss.str().c_str()); } else handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); return true; }
static bool HandleLookupSpellCommand(ChatHandler* handler, char const* args) { if (!*args) return false; // can be NULL at console call Player* target = handler->getSelectedPlayer(); std::string namePart = args; std::wstring wNamePart; if (!Utf8toWStr(namePart, wNamePart)) return false; // converting string that we try to find to lower case wstrToLower(wNamePart); bool found = false; uint32 count = 0; uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS); // Search in Spell.dbc for (uint32 id = 0; id < sSpellMgr->GetSpellInfoStoreSize(); id++) { SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id); if (spellInfo) { std::string name = spellInfo->SpellName; if (name.empty()) continue; if (!Utf8FitTo(name, wNamePart)) continue; if (maxResults && count++ == maxResults) { handler->PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults); return true; } bool known = target && target->HasSpell(id); bool learn = (spellInfo->Effects[0].Effect == SPELL_EFFECT_LEARN_SPELL); SpellInfo const* learnSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[0].TriggerSpell); uint32 talentCost = GetTalentSpellCost(id); bool talent = (talentCost > 0); bool passive = spellInfo->IsPassive(); bool active = target && target->HasAura(id); // unit32 used to prevent interpreting uint8 as char at output // find rank of learned spell for learning spell, or talent rank uint32 rank = talentCost ? talentCost : learn && learnSpellInfo ? learnSpellInfo->GetRank() : spellInfo->GetRank(); // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format std::ostringstream ss; if (handler->GetSession()) ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name; else ss << id << " - " << name; // include rank in link name if (rank) ss << handler->GetTrinityString(LANG_SPELL_RANK) << rank; if (handler->GetSession()) ss << "]|h|r"; if (talent) ss << handler->GetTrinityString(LANG_TALENT); if (passive) ss << handler->GetTrinityString(LANG_PASSIVE); if (learn) ss << handler->GetTrinityString(LANG_LEARN); if (known) ss << handler->GetTrinityString(LANG_KNOWN); if (active) ss << handler->GetTrinityString(LANG_ACTIVE); handler->SendSysMessage(ss.str().c_str()); if (!found) found = true; } } if (!found) handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND); return true; }