Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++
1.2 KB
Raw Blame
#ifndef OPENMW_PROCESSORPLAYERSPELLBOOK_HPP
#define OPENMW_PROCESSORPLAYERSPELLBOOK_HPP


#include "../PlayerProcessor.hpp"

namespace mwmp
{
    class ProcessorPlayerSpellbook final: public PlayerProcessor
    {
    public:
        ProcessorPlayerSpellbook()
        {
            BPP_INIT(ID_PLAYER_SPELLBOOK)
        }

        virtual void Do(PlayerPacket &packet, BasePlayer *player)
        {
            if (!isLocal()) return;

            LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_SPELLBOOK about LocalPlayer from server");

            if (isRequest())
                static_cast<LocalPlayer*>(player)->sendSpellbook();
            else
            {
                LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
                
                int spellbookAction = localPlayer.spellbookChanges.action;

                if (spellbookAction == SpellbookChanges::ADD)
                    localPlayer.addSpells();
                else if (spellbookAction == SpellbookChanges::REMOVE)
                    localPlayer.removeSpells();
                else // SpellbookChanges::SET
                    localPlayer.setSpellbook();
            }
        }
    };
}

#endif //OPENMW_PROCESSORPLAYERSPELLBOOK_HPP