2016-11-21 18:37:04 +00:00
|
|
|
#include "Spells.hpp"
|
|
|
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
|
2017-07-07 06:25:48 +00:00
|
|
|
void SpellFunctions::InitializeSpellbookChanges(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
|
|
|
player->spellbookChanges.spells.clear();
|
|
|
|
player->spellbookChanges.action = SpellbookChanges::SET;
|
|
|
|
}
|
|
|
|
|
2017-01-20 10:43:05 +00:00
|
|
|
unsigned int SpellFunctions::GetSpellbookChangesSize(unsigned short pid) noexcept
|
2016-11-21 18:37:04 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
2017-01-20 10:43:05 +00:00
|
|
|
return player->spellbookChanges.count;
|
2016-11-21 18:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-02-16 12:23:27 +00:00
|
|
|
unsigned int SpellFunctions::GetSpellbookAction(unsigned short pid) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
|
|
|
|
return player->spellbookChanges.action;
|
|
|
|
}
|
|
|
|
|
2016-11-21 18:37:04 +00:00
|
|
|
void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2016-12-29 13:19:26 +00:00
|
|
|
ESM::Spell spell;
|
|
|
|
spell.mId = spellId;
|
2016-11-21 18:37:04 +00:00
|
|
|
|
2017-07-07 06:25:48 +00:00
|
|
|
player->spellbookChanges.spells.push_back(spell);
|
|
|
|
player->spellbookChanges.action = SpellbookChanges::ADD;
|
2016-11-21 18:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpellFunctions::RemoveSpell(unsigned short pid, const char* spellId) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
|
|
|
|
2016-12-29 13:19:26 +00:00
|
|
|
ESM::Spell spell;
|
|
|
|
spell.mId = spellId;
|
2016-11-21 18:37:04 +00:00
|
|
|
|
2017-07-07 06:25:48 +00:00
|
|
|
player->spellbookChanges.spells.push_back(spell);
|
|
|
|
player->spellbookChanges.action = SpellbookChanges::REMOVE;
|
2016-11-21 18:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept
|
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, "");
|
|
|
|
|
2017-01-20 10:43:05 +00:00
|
|
|
if (i >= player->spellbookChanges.count)
|
2016-11-21 18:37:04 +00:00
|
|
|
return "invalid";
|
|
|
|
|
2017-01-20 10:43:05 +00:00
|
|
|
return player->spellbookChanges.spells.at(i).mId.c_str();
|
2016-11-21 18:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-07-07 06:25:48 +00:00
|
|
|
void SpellFunctions::SendSpellbookChanges(unsigned short pid, bool toOthers) noexcept
|
2016-11-21 18:37:04 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player, );
|
2016-12-29 13:19:26 +00:00
|
|
|
|
2017-04-09 05:51:28 +00:00
|
|
|
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK)->setPlayer(player);
|
2017-07-07 06:25:48 +00:00
|
|
|
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SPELLBOOK)->Send(toOthers);
|
2016-11-21 18:37:04 +00:00
|
|
|
}
|