2016-01-12 03:41:44 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 05.01.16.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef OPENMW_PLAYER_HPP
|
|
|
|
#define OPENMW_PLAYER_HPP
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2016-10-30 11:19:48 +00:00
|
|
|
#include <chrono>
|
2016-01-12 03:41:44 +00:00
|
|
|
#include <RakNetTypes.h>
|
|
|
|
|
|
|
|
#include <components/esm/npcstats.hpp>
|
|
|
|
#include <components/esm/cellid.hpp>
|
|
|
|
#include <components/esm/loadnpc.hpp>
|
|
|
|
#include <components/esm/loadcell.hpp>
|
|
|
|
|
2016-08-18 22:32:39 +00:00
|
|
|
#include <components/openmw-mp/Log.hpp>
|
2016-01-12 03:41:44 +00:00
|
|
|
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
2017-02-19 08:38:47 +00:00
|
|
|
#include <components/openmw-mp/Packets/Player/PlayerPacket.hpp>
|
2017-02-19 05:26:42 +00:00
|
|
|
#include "Cell.hpp"
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
struct Player;
|
2016-11-17 05:11:42 +00:00
|
|
|
typedef std::map<RakNet::RakNetGUID, Player*> TPlayers;
|
2016-01-12 03:41:44 +00:00
|
|
|
typedef std::map<unsigned short, Player*> TSlots;
|
|
|
|
|
|
|
|
class Players
|
|
|
|
{
|
|
|
|
public:
|
2016-11-16 00:05:14 +00:00
|
|
|
static void newPlayer(RakNet::RakNetGUID guid);
|
|
|
|
static void deletePlayer(RakNet::RakNetGUID guid);
|
|
|
|
static Player *getPlayer(RakNet::RakNetGUID guid);
|
|
|
|
static Player *getPlayer(unsigned short id);
|
|
|
|
static TPlayers *getPlayers();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static TPlayers players;
|
|
|
|
static TSlots slots;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Player : public mwmp::BasePlayer
|
|
|
|
{
|
2017-02-19 05:26:42 +00:00
|
|
|
friend class Cell;
|
2016-01-12 03:41:44 +00:00
|
|
|
unsigned short id;
|
|
|
|
public:
|
|
|
|
|
2016-09-18 07:52:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
NOTLOADED=0,
|
|
|
|
LOADED,
|
|
|
|
POSTLOADED
|
|
|
|
};
|
2016-10-26 12:55:34 +00:00
|
|
|
Player(RakNet::RakNetGUID guid);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
unsigned short getId();
|
|
|
|
void setId(unsigned short id);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
bool isHandshaked();
|
2016-11-16 00:05:14 +00:00
|
|
|
void setHandshake();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-16 00:05:14 +00:00
|
|
|
void setLoadState(int state);
|
|
|
|
int getLoadState();
|
2016-09-18 03:48:08 +00:00
|
|
|
|
2016-10-30 11:19:48 +00:00
|
|
|
void setLastAttackerId(unsigned short pid);
|
2016-10-08 07:15:43 +00:00
|
|
|
void resetLastAttacker();
|
2016-10-30 11:19:48 +00:00
|
|
|
unsigned short getLastAttackerId();
|
|
|
|
|
|
|
|
void setLastAttackerTime(std::chrono::steady_clock::time_point time);
|
|
|
|
std::chrono::steady_clock::time_point getLastAttackerTime();
|
2016-10-08 07:15:43 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
virtual ~Player();
|
2016-11-21 18:37:04 +00:00
|
|
|
|
2017-02-20 12:43:51 +00:00
|
|
|
CellController::TContainer *getCells();
|
2017-02-19 12:37:26 +00:00
|
|
|
void sendToLoaded(mwmp::PlayerPacket *myPacket);
|
2017-02-19 05:26:42 +00:00
|
|
|
|
2017-02-19 13:32:25 +00:00
|
|
|
void forEachLoaded(std::function<void(Player *pl, Player *other)> func);
|
2017-02-19 09:42:39 +00:00
|
|
|
|
Implement inventory functions
AddItem, RemoveItem, GetItemName, GetItemCount, GetItemHealth, GetInventorySize SendInventory
Example:
```lua
tes3mp.AddItem(pid, "glass dagger", 1, 50)
tes3mp.AddItem(pid, "glass dagger", 1, -1)
tes3mp.SendInventory(pid)
tes3mp.RemoveItem(pid, "glass dagger", 1)
tes3mp.SendInventory(pid)
local invSize = tes3mp.GetInventorySize(pid) - 1
for i = 0, invSize do
print(("%s %d %d"):format(tes3mp.GetItemName(pid, i), tes3mp.GetItemCount(pid, i), tes3mp.GetItemHealth(pid, i)))
end
```
2016-10-22 18:57:37 +00:00
|
|
|
public:
|
2017-01-20 10:43:05 +00:00
|
|
|
mwmp::InventoryChanges inventoryChangesBuffer;
|
|
|
|
mwmp::SpellbookChanges spellbookChangesBuffer;
|
2017-01-24 17:32:25 +00:00
|
|
|
mwmp::JournalChanges journalChangesBuffer;
|
2016-11-21 18:37:04 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
private:
|
2017-02-19 05:26:42 +00:00
|
|
|
CellController::TContainer cells;
|
2016-11-16 00:05:14 +00:00
|
|
|
bool handshakeState;
|
|
|
|
int loadState;
|
2016-10-08 07:15:43 +00:00
|
|
|
unsigned short lastAttacker;
|
2016-10-30 11:19:48 +00:00
|
|
|
std::chrono::steady_clock::time_point lastAttackerTime;
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //OPENMW_PLAYER_HPP
|