Jump to content
  • Learning Spells higher than your level


    NightHunter69
    • Main Category: Core / Mangos Daemon
      Sub-Category: Spell
      Version: 22.x (Current Master Branch)

    Hi, I just started a linux mangos three build a few days ago and I came across this annoying bug (great bug for players!) that you can learn all spells from your class trainer regardless of your level. Everytime you re-opened/talk to trainer you can learn the spell if you have enough money.


    User Feedback

    Recommended Comments

    NightHunter69

    Posted

    Temp Fix modified the HandleTrainerBuySpellOpcode function :

    void WorldSession::HandleTrainerBuySpellOpcode(WorldPacket& recv_data)
    {
        ObjectGuid guid;
        uint32 spellId = 0, TrainerTemplateId = 0;

        recv_data >> guid >> TrainerTemplateId >> spellId;
        DEBUG_LOG("WORLD: Received opcode CMSG_TRAINER_BUY_SPELL Trainer: %s, learn spell id is: %u", guid.GetString().c_str(), spellId);

        Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_TRAINER);
        if (!unit)
        {
            DEBUG_LOG("WORLD: HandleTrainerBuySpellOpcode - %s not found or you can't interact with him.", guid.GetString().c_str());
            return;
        }

        WorldPacket sendData(SMSG_TRAINER_SERVICE, 16);
        uint32 trainState = 2;

        if (!unit->IsTrainerOf(_player, true))
            trainState = 1;

        TrainerSpellData const* cSpells = unit->GetTrainerSpells();
        TrainerSpellData const* tSpells = unit->GetTrainerTemplateSpells();

        if (!cSpells && !tSpells)
            trainState = 1;

        TrainerSpell const* trainer_spell = cSpells ? cSpells->Find(spellId) : NULL;

        if (!trainer_spell && tSpells)
            trainer_spell = tSpells->Find(spellId);

        if (!trainer_spell)
            trainState = 1;

        uint32 reqLevel = 0;
        if (!_player->IsSpellFitByClassAndRace(trainer_spell->learnedSpell, &reqLevel))
            trainState = 1;

        reqLevel = trainer_spell->isProvidedReqLevel ? trainer_spell->reqLevel : std::max(reqLevel, trainer_spell->reqLevel);

        if (_player->GetTrainerSpellState(trainer_spell, reqLevel) != TRAINER_SPELL_GREEN)
            trainState = 1;

        uint32 nSpellCost = uint32(floor(trainer_spell->spellCost * _player->GetReputationPriceDiscount(unit)));

        if (_player->GetMoney() < nSpellCost && trainState > 1)
            trainState = 0;

        // Final hard-level check before spell is learned, money is removed, or visuals sent
        if (_player->getLevel() < reqLevel)
        {
            ChatHandler(this).PSendSysMessage("You must be level %u to learn this spell.", reqLevel);

            sendData << ObjectGuid(guid);
            sendData << uint32(spellId);
            sendData << uint32(1); // 1 = TRAIN_STATE_NOT_LEARNABLE
            SendPacket(&sendData);
            return;
        }

        if (trainState != 2)
        {
            sendData << ObjectGuid(guid);
            sendData << uint32(spellId);
            sendData << uint32(trainState);
            SendPacket(&sendData);
        }
        else
        {
            _player->ModifyMoney(-int64(nSpellCost));

            // visual effect on trainer
            WorldPacket data;
            unit->BuildSendPlayVisualPacket(&data, 0xB3, false);
            SendPacket(&data);

            // visual effect on player
            _player->BuildSendPlayVisualPacket(&data, 0x016A, true);
            SendPacket(&data);

            // learn explicitly or cast explicitly
            if (trainer_spell->IsCastable())
            {
                _player->CastSpell(_player, trainer_spell->spell, true);
            }
            else
            {
                _player->learnSpell(spellId, false);
            }

            sendData << ObjectGuid(guid);
            sendData << uint32(spellId);
            sendData << uint32(trainState);
            SendPacket(&sendData);
        }
    }
     



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use