You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3coop/apps/openmw-mp/Books.cpp

60 lines
1.3 KiB
C++

//
// Created by koncord on 15.08.17.
//
#include <components/openmw-mp/NetworkMessages.hpp>
#include "Script/LuaState.hpp"
#include "Networking.hpp"
#include "Books.hpp"
#include "Player.hpp"
void Books::Init(LuaState &lua)
{
lua.getState()->new_usertype<Books>("Books",
"addBook", &Books::addBook,
"getBookId", &Books::getBookId,
"getChanges", &Books::getChanges,
"reset", &Books::reset
);
}
Books::Books(Player *player) : BaseMgr(player)
{
}
void Books::addBook(const std::string &bookId)
{
if (!isChanged())
reset();
player->bookChanges.books.push_back({bookId});
setChanged();
}
std::string Books::getBookId(unsigned i) const
{
if (i >= player->bookChanges.books.size())
return "invalid";
return player->bookChanges.books.at(i).bookId;
}
unsigned Books::getChanges() const
{
return player->bookChanges.books.size();
}
void Books::reset()
{
player->bookChanges.books.clear();
}
void Books::processUpdate()
{
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_BOOK);
packet->setPlayer(player);
packet->Send(/*toOthers*/ false);
}