forked from mirror/openmw-tes3mp
4ca5da5666
Use LibFFI for Public & Timer APIs Use "PlayerId" type instead "unsigned short" Add GetPluginDir() function
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
#include "Books.h"
|
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <apps/openmw-mp/Script/Callbacks.hpp>
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
using namespace mwmp;
|
|
|
|
extern "C" void BookFunctions::ClearBookChanges(PlayerId pid) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
player->bookChanges.books.clear();
|
|
}
|
|
|
|
extern "C" unsigned int BookFunctions::GetBookChangesSize(PlayerId pid) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, 0);
|
|
|
|
return player->bookChanges.count;
|
|
}
|
|
|
|
extern "C" void BookFunctions::AddBook(PlayerId pid, const char* bookId) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
mwmp::Book book;
|
|
book.bookId = bookId;
|
|
|
|
player->bookChanges.books.push_back(book);
|
|
}
|
|
|
|
extern "C" const char *BookFunctions::GetBookId(PlayerId pid, unsigned int index) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, "");
|
|
|
|
if (index >= player->bookChanges.count)
|
|
return "invalid";
|
|
|
|
return player->bookChanges.books.at(index).bookId.c_str();
|
|
}
|
|
|
|
extern "C" void BookFunctions::SendBookChanges(PlayerId pid, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
|
|
{
|
|
Player *player;
|
|
GET_PLAYER(pid, player, );
|
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
if (!skipAttachedPlayer)
|
|
packet->Send(false);
|
|
if (sendToOtherPlayers)
|
|
packet->Send(true);
|
|
}
|
|
|
|
// All methods below are deprecated versions of methods from above
|
|
|
|
extern "C" void BookFunctions::InitializeBookChanges(PlayerId pid) noexcept
|
|
{
|
|
ClearBookChanges(pid);
|
|
}
|