2017-04-30 11:57:43 +00:00
|
|
|
#include <components/openmw-mp/Log.hpp>
|
2017-05-01 14:54:43 +00:00
|
|
|
#include <apps/openmw/mwclass/creature.hpp>
|
2017-04-30 11:57:43 +00:00
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
|
|
|
|
#include "../mwclass/npc.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
#include "../mwworld/worldimp.hpp"
|
|
|
|
|
|
|
|
#include "PlayerList.hpp"
|
|
|
|
#include "Main.hpp"
|
|
|
|
#include "DedicatedPlayer.hpp"
|
|
|
|
#include "CellController.hpp"
|
|
|
|
#include "GUIController.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace mwmp;
|
|
|
|
using namespace std;
|
|
|
|
|
2017-05-01 14:54:43 +00:00
|
|
|
std::map <RakNet::RakNetGUID, DedicatedPlayer *> PlayerList::players;
|
2017-04-30 11:57:43 +00:00
|
|
|
|
|
|
|
void PlayerList::update(float dt)
|
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
for (auto &p : players)
|
2017-04-30 11:57:43 +00:00
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
DedicatedPlayer *player = p.second;
|
2017-04-30 11:57:43 +00:00
|
|
|
if (player == 0) continue;
|
|
|
|
|
|
|
|
player->update(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DedicatedPlayer *PlayerList::newPlayer(RakNet::RakNetGUID guid)
|
|
|
|
{
|
2018-04-08 07:56:33 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %s", guid.ToString());
|
2017-04-30 11:57:43 +00:00
|
|
|
|
|
|
|
players[guid] = new DedicatedPlayer(guid);
|
|
|
|
players[guid]->state = 0;
|
|
|
|
return players[guid];
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerList::disconnectPlayer(RakNet::RakNetGUID guid)
|
|
|
|
{
|
|
|
|
if (players[guid]->state > 1)
|
|
|
|
{
|
|
|
|
players[guid]->state = 1;
|
|
|
|
|
|
|
|
// Remove player's marker
|
|
|
|
players[guid]->setMarkerState(false);
|
|
|
|
|
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
world->disable(players[guid]->getPtr());
|
|
|
|
|
|
|
|
// Move player to exterior 0,0
|
|
|
|
ESM::Position newPos;
|
|
|
|
newPos.pos[0] = newPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
|
|
|
newPos.pos[2] = 0;
|
|
|
|
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
|
|
|
|
|
|
|
world->moveObject(players[guid]->getPtr(), cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayerList::cleanUp()
|
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
for (auto &p : players)
|
|
|
|
delete p.second;
|
2017-04-30 11:57:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DedicatedPlayer *PlayerList::getPlayer(RakNet::RakNetGUID guid)
|
|
|
|
{
|
|
|
|
return players[guid];
|
|
|
|
}
|
|
|
|
|
|
|
|
DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
for (auto &p : players)
|
2017-04-30 11:57:43 +00:00
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
if (p.second == 0 || p.second->getPtr().mRef == 0)
|
2017-04-30 11:57:43 +00:00
|
|
|
continue;
|
|
|
|
string refid = ptr.getCellRef().getRefId();
|
2017-06-27 14:24:34 +00:00
|
|
|
if (p.second->getPtr().getCellRef().getRefId() == refid)
|
|
|
|
return p.second;
|
2017-04-30 11:57:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
2017-06-27 14:49:28 +00:00
|
|
|
if (ptr.mRef == nullptr)
|
2017-04-30 11:57:43 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return (getPlayer(ptr) != 0);
|
|
|
|
}
|
2017-05-30 05:20:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Go through all DedicatedPlayers checking if their mHitAttemptActorId matches this one
|
|
|
|
and set it to -1 if it does
|
|
|
|
|
|
|
|
This resets the combat target for a DedicatedPlayer's followers in Actors::update()
|
|
|
|
*/
|
|
|
|
void PlayerList::clearHitAttemptActorId(int actorId)
|
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
for (auto &p : players)
|
2017-05-30 05:20:45 +00:00
|
|
|
{
|
2017-06-27 14:24:34 +00:00
|
|
|
if (p.second == 0 || p.second->getPtr().mRef == 0)
|
2017-05-30 05:20:45 +00:00
|
|
|
continue;
|
|
|
|
|
2017-06-27 14:24:34 +00:00
|
|
|
MWMechanics::CreatureStats &playerCreatureStats = p.second->getPtr().getClass().getCreatureStats(p.second->getPtr());
|
2017-05-30 05:20:45 +00:00
|
|
|
|
2017-06-27 14:24:34 +00:00
|
|
|
if (playerCreatureStats.getHitAttemptActorId() == actorId)
|
|
|
|
playerCreatureStats.setHitAttemptActorId(-1);
|
2017-05-30 05:20:45 +00:00
|
|
|
}
|
|
|
|
}
|