mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 22:19:54 +00:00
84 lines
2.1 KiB
C++
84 lines
2.1 KiB
C++
#include "Spells.hpp"
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
using namespace mwmp;
|
|
|
|
void SpellFunctions::ClearSpellbookChanges(unsigned short pid) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
player->spellbookChanges.spells.clear();
|
|
}
|
|
|
|
unsigned int SpellFunctions::GetSpellbookChangesSize(unsigned short pid) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
return player->spellbookChanges.spells.size();
|
|
}
|
|
|
|
unsigned int SpellFunctions::GetSpellbookChangesAction(unsigned short pid) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
return player->spellbookChanges.action;
|
|
}
|
|
|
|
void SpellFunctions::SetSpellbookChangesAction(unsigned short pid, unsigned char action) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
player->spellbookChanges.action = action;
|
|
}
|
|
|
|
void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
ESM::Spell spell;
|
|
spell.mId = spellId;
|
|
|
|
player->spellbookChanges.spells.push_back(spell);
|
|
}
|
|
|
|
const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int index) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, "");
|
|
|
|
if (index >= player->spellbookChanges.spells.size())
|
|
return "invalid";
|
|
|
|
return player->spellbookChanges.spells.at(index).mId.c_str();
|
|
}
|
|
|
|
void SpellFunctions::SendSpellbookChanges(unsigned short pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK);
|
|
packet->setPlayer(player);
|
|
|
|
if (!skipAttachedPlayer)
|
|
packet->Send(false);
|
|
if (sendToOtherPlayers)
|
|
packet->Send(true);
|
|
}
|
|
|
|
// All methods below are deprecated versions of methods from above
|
|
|
|
void SpellFunctions::InitializeSpellbookChanges(unsigned short pid) noexcept
|
|
{
|
|
ClearSpellbookChanges(pid);
|
|
}
|