forked from mirror/openmw-tes3mp
Add spell script functions to tes3mp server
parent
8aeb3a6cc6
commit
c81b58e1be
@ -0,0 +1,80 @@
|
||||
#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;
|
||||
|
||||
unsigned int SpellFunctions::GetSpellbookSize(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, 0);
|
||||
|
||||
return player->spellbook.count;
|
||||
}
|
||||
|
||||
void SpellFunctions::AddSpell(unsigned short pid, const char* spellId) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
Spell spell;
|
||||
spell.id = spellId;
|
||||
|
||||
player->spellbookSendBuffer.spells.push_back(spell);
|
||||
player->spellbookSendBuffer.action = Spellbook::ADD;
|
||||
}
|
||||
|
||||
void SpellFunctions::RemoveSpell(unsigned short pid, const char* spellId) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
Spell spell;
|
||||
spell.id = spellId;
|
||||
|
||||
player->spellbookSendBuffer.spells.push_back(spell);
|
||||
player->spellbookSendBuffer.action = Spellbook::REMOVE;
|
||||
}
|
||||
|
||||
void SpellFunctions::ClearSpellbook(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
player->spellbookSendBuffer.spells.clear();
|
||||
player->spellbookSendBuffer.action = Spellbook::UPDATE;
|
||||
}
|
||||
|
||||
bool SpellFunctions::HasSpell(unsigned short pid, const char* spellId)
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, false);
|
||||
|
||||
for (int i = 0; i < player->spellbook.count; i++)
|
||||
if (Misc::StringUtils::ciEqual(player->spellbook.spells.at(i).id, spellId))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *SpellFunctions::GetSpellId(unsigned short pid, unsigned int i) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, "");
|
||||
|
||||
if (i >= player->spellbook.count)
|
||||
return "invalid";
|
||||
|
||||
return player->spellbook.spells.at(i).id.c_str();
|
||||
}
|
||||
|
||||
void SpellFunctions::SendSpellbook(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
std::swap(player->spellbook, player->spellbookSendBuffer);
|
||||
mwmp::Networking::get().getPlayerController()->GetPacket(ID_GAME_SPELLBOOK)->Send(player, false);
|
||||
player->spellbook = std::move(player->spellbookSendBuffer);
|
||||
player->spellbookSendBuffer.spells.clear();
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef OPENMW_SPELLS_HPP
|
||||
#define OPENMW_SPELLS_HPP
|
||||
|
||||
#define SPELLAPI \
|
||||
{"GetSpellbookSize", SpellFunctions::GetSpellbookSize},\
|
||||
\
|
||||
{"AddSpell", SpellFunctions::AddSpell},\
|
||||
{"RemoveSpell", SpellFunctions::RemoveSpell},\
|
||||
{"ClearSpellbook", SpellFunctions::ClearInventory},\
|
||||
\
|
||||
{"HasSpell", SpellFunctions::HasSpell},\
|
||||
{"GetSpellId", SpellFunctions::GetSpellId},\
|
||||
\
|
||||
{"SendSpellbook", SpellFunctions::SendSpellbook}
|
||||
|
||||
class SpellFunctions
|
||||
{
|
||||
public:
|
||||
|
||||
static unsigned int GetSpellbookSize(unsigned short pid) noexcept;
|
||||
|
||||
static void AddSpell(unsigned short pid, const char* spellId) noexcept;
|
||||
static void RemoveSpell(unsigned short pid, const char* spellId) noexcept;
|
||||
static void ClearSpellbook(unsigned short pid) noexcept;
|
||||
|
||||
static bool HasSpell(unsigned short pid, const char* itemName);
|
||||
static const char *GetSpellId(unsigned short pid, unsigned int i) noexcept;
|
||||
|
||||
static void SendSpellbook(unsigned short pid) noexcept;
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif //OPENMW_SPELLS_HPP
|
Loading…
Reference in New Issue