2016-01-12 03:41:44 +00:00
|
|
|
//
|
|
|
|
// Created by koncord on 02.01.16.
|
|
|
|
//
|
|
|
|
|
2017-04-10 15:24:30 +00:00
|
|
|
#include <boost/algorithm/clamp.hpp>
|
|
|
|
#include <components/openmw-mp/Log.hpp>
|
2017-02-26 23:02:59 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "../mwbase/environment.hpp"
|
2017-04-08 09:54:38 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "../mwgui/windowmanagerimp.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "../mwclass/npc.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
|
2017-04-08 09:54:38 +00:00
|
|
|
#include "../mwinput/inputmanagerimp.hpp"
|
|
|
|
|
2016-11-12 11:39:04 +00:00
|
|
|
#include "../mwmechanics/actor.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
#include "../mwmechanics/aitravel.hpp"
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
#include "../mwmechanics/mechanicsmanagerimp.hpp"
|
2017-02-27 21:01:33 +00:00
|
|
|
#include "../mwmechanics/spellcasting.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
|
2017-04-08 09:54:38 +00:00
|
|
|
#include "../mwstate/statemanagerimp.hpp"
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
#include "../mwworld/action.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
#include "../mwworld/customdata.hpp"
|
2017-04-10 15:24:30 +00:00
|
|
|
#include "../mwworld/inventorystore.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
#include "../mwworld/worldimp.hpp"
|
|
|
|
|
2017-04-10 15:24:30 +00:00
|
|
|
#include "DedicatedPlayer.hpp"
|
2016-10-22 09:06:26 +00:00
|
|
|
#include "Main.hpp"
|
2016-12-16 08:59:15 +00:00
|
|
|
#include "GUIController.hpp"
|
2017-04-05 09:00:21 +00:00
|
|
|
#include "CellController.hpp"
|
2017-04-17 11:37:19 +00:00
|
|
|
#include "MechanicsHelper.hpp"
|
2017-02-26 23:02:59 +00:00
|
|
|
|
2017-04-10 15:24:30 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
using namespace mwmp;
|
|
|
|
using namespace std;
|
|
|
|
|
2017-04-17 16:10:33 +00:00
|
|
|
std::map<RakNet::RakNetGUID, DedicatedPlayer *> PlayerList::players;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
DedicatedPlayer::DedicatedPlayer(RakNet::RakNetGUID guid) : BasePlayer(guid)
|
|
|
|
{
|
2017-01-25 15:06:15 +00:00
|
|
|
attack.pressed = 0;
|
|
|
|
creatureStats.mDead = false;
|
2016-01-12 03:41:44 +00:00
|
|
|
movementFlags = 0;
|
|
|
|
}
|
|
|
|
DedicatedPlayer::~DedicatedPlayer()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
void PlayerList::update(float dt)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-04-17 16:34:32 +00:00
|
|
|
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
|
|
|
|
{
|
|
|
|
DedicatedPlayer *pl = it->second;
|
|
|
|
if (pl == 0) continue;
|
|
|
|
|
|
|
|
MWMechanics::NpcStats *ptrNpcStats = &pl->ptr.getClass().getNpcStats(pl->getPtr());
|
|
|
|
|
|
|
|
MWMechanics::DynamicStat<float> value;
|
|
|
|
|
|
|
|
if (pl->creatureStats.mDead)
|
|
|
|
{
|
|
|
|
value.readState(pl->creatureStats.mDynamic[0]);
|
|
|
|
ptrNpcStats->setHealth(value);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
value.readState(pl->creatureStats.mDynamic[0]);
|
|
|
|
ptrNpcStats->setHealth(value);
|
|
|
|
value.readState(pl->creatureStats.mDynamic[1]);
|
|
|
|
ptrNpcStats->setMagicka(value);
|
|
|
|
value.readState(pl->creatureStats.mDynamic[2]);
|
|
|
|
ptrNpcStats->setFatigue(value);
|
|
|
|
|
|
|
|
if (ptrNpcStats->isDead())
|
|
|
|
ptrNpcStats->resurrect();
|
|
|
|
|
|
|
|
ptrNpcStats->setAttacked(false);
|
|
|
|
|
|
|
|
ptrNpcStats->getAiSequence().stopCombat();
|
|
|
|
|
|
|
|
ptrNpcStats->setAlarmed(false);
|
|
|
|
ptrNpcStats->setAiSetting(MWMechanics::CreatureStats::AI_Alarm, 0);
|
|
|
|
ptrNpcStats->setAiSetting(MWMechanics::CreatureStats::AI_Fight, 0);
|
|
|
|
ptrNpcStats->setAiSetting(MWMechanics::CreatureStats::AI_Flee, 0);
|
|
|
|
ptrNpcStats->setAiSetting(MWMechanics::CreatureStats::AI_Hello, 0);
|
|
|
|
|
|
|
|
ptrNpcStats->setBaseDisposition(255);
|
|
|
|
pl->move(dt);
|
|
|
|
pl->updateAnimFlags();
|
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:10:33 +00:00
|
|
|
void PlayerList::createPlayer(RakNet::RakNetGUID guid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-02-26 23:45:27 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Setting up character info");
|
2016-08-18 19:29:54 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
MWWorld::Ptr player = world->getPlayerPtr();
|
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
ESM::NPC npc = *player.get<ESM::NPC>()->mBase;
|
2016-11-19 20:16:21 +00:00
|
|
|
DedicatedPlayer *dedicPlayer = players[guid];
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-02-26 23:45:27 +00:00
|
|
|
// To avoid freezes caused by invalid races, only set race if we find it
|
|
|
|
// on our client
|
|
|
|
if (world->getStore().get<ESM::Race>().search(dedicPlayer->npc.mRace) != 0)
|
|
|
|
npc.mRace = dedicPlayer->npc.mRace;
|
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
npc.mHead = dedicPlayer->npc.mHead;
|
|
|
|
npc.mHair = dedicPlayer->npc.mHair;
|
|
|
|
npc.mClass = dedicPlayer->npc.mClass;
|
|
|
|
npc.mName = dedicPlayer->npc.mName;
|
|
|
|
npc.mFlags = dedicPlayer->npc.mFlags;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
if (dedicPlayer->state == 0)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-09-29 09:05:44 +00:00
|
|
|
npc.mId = "Dedicated Player";
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
std::string recid = world->createRecord(npc)->mId;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
dedicPlayer->reference = new MWWorld::ManualRef(world->getStore(), recid, 1);
|
2016-08-16 22:06:50 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-02-26 23:02:59 +00:00
|
|
|
// Temporarily spawn or move player to the center of exterior 0,0 whenever setting base info
|
2017-02-25 21:18:50 +00:00
|
|
|
ESM::Position spawnPos;
|
2017-04-05 09:00:21 +00:00
|
|
|
spawnPos.pos[0] = spawnPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
2017-02-26 23:02:59 +00:00
|
|
|
spawnPos.pos[2] = 0;
|
2017-02-25 21:18:50 +00:00
|
|
|
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
if (dedicPlayer->state == 0)
|
2016-08-16 22:06:50 +00:00
|
|
|
{
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Creating new reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
2016-08-18 19:29:54 +00:00
|
|
|
|
2017-02-25 21:18:50 +00:00
|
|
|
MWWorld::Ptr tmp = world->placeObject(dedicPlayer->reference->getPtr(), cellStore, spawnPos);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
dedicPlayer->ptr.mCell = tmp.mCell;
|
|
|
|
dedicPlayer->ptr.mRef = tmp.mRef;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
dedicPlayer->cell = *dedicPlayer->ptr.getCell()->getCell();
|
2017-01-25 15:06:15 +00:00
|
|
|
dedicPlayer->position = dedicPlayer->ptr.getRefData().getPosition();
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Updating reference pointer for %s", dedicPlayer->npc.mName.c_str());
|
2016-08-18 19:29:54 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
dedicPlayer->ptr.getBase()->canChangeCell = true;
|
2017-02-25 21:18:50 +00:00
|
|
|
dedicPlayer->updatePtr(world->moveObject(dedicPlayer->ptr, cellStore, spawnPos.pos[0], spawnPos.pos[1], spawnPos.pos[2]));
|
2016-08-16 22:06:50 +00:00
|
|
|
|
2016-11-19 20:16:21 +00:00
|
|
|
npc.mId = players[guid]->ptr.get<ESM::NPC>()->mBase->mId;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
|
|
|
MWWorld::ESMStore *store = const_cast<MWWorld::ESMStore *>(&world->getStore());
|
|
|
|
MWWorld::Store<ESM::NPC> *esm_store = const_cast<MWWorld::Store<ESM::NPC> *> (&store->get<ESM::NPC>());
|
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
esm_store->insert(npc);
|
2016-08-16 22:06:50 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
dedicPlayer->updateCell();
|
2016-10-24 18:08:47 +00:00
|
|
|
|
2016-10-26 12:55:34 +00:00
|
|
|
ESM::CustomMarker mEditingMarker = Main::get().getGUIController()->CreateMarker(guid);
|
2016-10-24 18:08:47 +00:00
|
|
|
dedicPlayer->marker = mEditingMarker;
|
|
|
|
dedicPlayer->setMarkerState(true);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 12:55:34 +00:00
|
|
|
dedicPlayer->guid = guid;
|
2016-09-29 09:05:44 +00:00
|
|
|
dedicPlayer->state = 2;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-02-23 02:35:07 +00:00
|
|
|
// Give this new character a fatigue of at least 1 so it doesn't spawn
|
|
|
|
// on the ground
|
|
|
|
dedicPlayer->creatureStats.mDynamic[2].mBase = 1;
|
|
|
|
|
2016-11-19 20:16:21 +00:00
|
|
|
world->enable(players[guid]->ptr);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
DedicatedPlayer *PlayerList::newPlayer(RakNet::RakNetGUID guid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-04-17 16:34:32 +00:00
|
|
|
LOG_APPEND(Log::LOG_INFO, "- Creating new DedicatedPlayer with guid %lu", guid.g);
|
|
|
|
|
|
|
|
players[guid] = new DedicatedPlayer(guid);
|
|
|
|
players[guid]->state = 0;
|
|
|
|
return players[guid];
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:10:33 +00:00
|
|
|
void PlayerList::disconnectPlayer(RakNet::RakNetGUID guid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-19 20:16:21 +00:00
|
|
|
if (players[guid]->state > 1)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2016-11-19 20:16:21 +00:00
|
|
|
players[guid]->state = 1;
|
2016-10-24 12:10:32 +00:00
|
|
|
|
|
|
|
// Remove player's marker
|
2016-11-19 20:16:21 +00:00
|
|
|
players[guid]->setMarkerState(false);
|
2016-10-24 12:10:32 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2016-11-19 20:16:21 +00:00
|
|
|
world->disable(players[guid]->getPtr());
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-02-25 21:18:50 +00:00
|
|
|
// Move player to exterior 0,0
|
2016-09-29 09:05:44 +00:00
|
|
|
ESM::Position newPos;
|
2017-04-05 09:00:21 +00:00
|
|
|
newPos.pos[0] = newPos.pos[1] = Main::get().getCellController()->getCellSize() / 2;
|
2017-02-26 23:02:59 +00:00
|
|
|
newPos.pos[2] = 0;
|
2017-02-25 21:18:50 +00:00
|
|
|
MWWorld::CellStore *cellStore = world->getExterior(0, 0);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-19 20:16:21 +00:00
|
|
|
players[guid]->getPtr().getBase()->canChangeCell = true;
|
2017-02-25 21:18:50 +00:00
|
|
|
world->moveObject(players[guid]->getPtr(), cellStore, newPos.pos[0], newPos.pos[1], newPos.pos[2]);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
void PlayerList::cleanUp()
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-04-17 16:34:32 +00:00
|
|
|
for (std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin(); it != players.end(); it++)
|
|
|
|
delete it->second;
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
DedicatedPlayer *PlayerList::getPlayer(RakNet::RakNetGUID guid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-04-17 16:34:32 +00:00
|
|
|
return players[guid];
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
DedicatedPlayer *PlayerList::getPlayer(const MWWorld::Ptr &ptr)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-04-17 16:34:32 +00:00
|
|
|
std::map <RakNet::RakNetGUID, DedicatedPlayer *>::iterator it = players.begin();
|
|
|
|
|
|
|
|
for (; it != players.end(); it++)
|
|
|
|
{
|
|
|
|
if (it->second == 0 || it->second->getPtr().mRef == 0)
|
|
|
|
continue;
|
|
|
|
string refid = ptr.getCellRef().getRefId();
|
|
|
|
if (it->second->getPtr().getCellRef().getRefId() == refid)
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
return 0;
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 17:36:20 +00:00
|
|
|
bool PlayerList::isDedicatedPlayer(const MWWorld::Ptr &ptr)
|
|
|
|
{
|
2017-04-19 19:06:04 +00:00
|
|
|
if (ptr.mRef == NULL)
|
2017-04-18 15:07:39 +00:00
|
|
|
return false;
|
2017-04-17 17:36:20 +00:00
|
|
|
|
2017-04-18 15:07:39 +00:00
|
|
|
return (getPlayer(ptr) != 0);
|
2017-04-17 17:36:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 19:54:06 +00:00
|
|
|
void DedicatedPlayer::move(float dt)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
if (state != 2) return;
|
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
ESM::Position refPos = ptr.getRefData().getPosition();
|
2016-01-12 03:41:44 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
|
|
|
|
{
|
2017-03-04 06:21:37 +00:00
|
|
|
static const int timeMultiplier = 15;
|
2017-04-17 11:37:19 +00:00
|
|
|
osg::Vec3f lerp = Main::get().getMechanicsHelper()->getLinearInterpolation(refPos.asVec3(), position.asVec3(), dt * timeMultiplier);
|
2016-09-29 09:05:44 +00:00
|
|
|
refPos.pos[0] = lerp.x();
|
|
|
|
refPos.pos[1] = lerp.y();
|
|
|
|
refPos.pos[2] = lerp.z();
|
2017-02-27 21:01:33 +00:00
|
|
|
|
2016-09-29 09:05:44 +00:00
|
|
|
world->moveObject(ptr, refPos.pos[0], refPos.pos[1], refPos.pos[2]);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MWMechanics::Movement *move = &ptr.getClass().getMovementSettings(ptr);
|
2017-01-25 15:06:15 +00:00
|
|
|
move->mPosition[0] = direction.pos[0];
|
|
|
|
move->mPosition[1] = direction.pos[1];
|
|
|
|
move->mPosition[2] = direction.pos[2];
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
world->rotateObject(ptr, position.rot[0], position.rot[1], position.rot[2]);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
void DedicatedPlayer::updateAnimFlags()
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-04-17 16:34:32 +00:00
|
|
|
using namespace MWMechanics;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
// Until we figure out a better workaround for disabling player gravity,
|
|
|
|
// simply cast Levitate over and over on a player that's supposed to be flying
|
|
|
|
if (!isFlying)
|
|
|
|
{
|
|
|
|
ptr.getClass().getCreatureStats(ptr).getActiveSpells().purgeEffect(ESM::MagicEffect::Levitate);
|
|
|
|
}
|
|
|
|
else if (isFlying && !world->isFlying(ptr))
|
|
|
|
{
|
|
|
|
MWMechanics::CastSpell cast(ptr, ptr);
|
|
|
|
cast.mHitPosition = ptr.getRefData().getPosition().asVec3();
|
|
|
|
cast.mAlwaysSucceed = true;
|
|
|
|
cast.cast("Levitate");
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
if (drawState == 0)
|
|
|
|
ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Nothing);
|
|
|
|
else if (drawState == 1)
|
|
|
|
ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Weapon);
|
|
|
|
else if (drawState == 2)
|
|
|
|
ptr.getClass().getNpcStats(ptr).setDrawState(DrawState_Spell);
|
2016-08-18 19:29:54 +00:00
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
MWMechanics::NpcStats *ptrNpcStats = &ptr.getClass().getNpcStats(ptr);
|
|
|
|
ptrNpcStats->setMovementFlag(CreatureStats::Flag_Run, (movementFlags & CreatureStats::Flag_Run) != 0);
|
|
|
|
ptrNpcStats->setMovementFlag(CreatureStats::Flag_Sneak, (movementFlags & CreatureStats::Flag_Sneak) != 0);
|
|
|
|
ptrNpcStats->setMovementFlag(CreatureStats::Flag_ForceJump, (movementFlags & CreatureStats::Flag_ForceJump) != 0);
|
|
|
|
ptrNpcStats->setMovementFlag(CreatureStats::Flag_ForceMoveJump, (movementFlags & CreatureStats::Flag_ForceMoveJump) != 0);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 20:33:30 +00:00
|
|
|
void DedicatedPlayer::updateEquipment()
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore(ptr);
|
|
|
|
for (int slot = 0; slot < MWWorld::InventoryStore::Slots; ++slot)
|
|
|
|
{
|
|
|
|
MWWorld::ContainerStoreIterator it = invStore.getSlot(slot);
|
|
|
|
|
2017-02-05 07:01:33 +00:00
|
|
|
const string &dedicItem = equipedItems[slot].refId;
|
2016-01-12 03:41:44 +00:00
|
|
|
std::string item = "";
|
|
|
|
bool equal = false;
|
2016-08-17 15:20:36 +00:00
|
|
|
if (it != invStore.end())
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
item = it->getCellRef().getRefId();
|
2016-08-17 15:20:36 +00:00
|
|
|
if (!Misc::StringUtils::ciEqual(item, dedicItem)) // if other item equiped
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
MWWorld::ContainerStore &store = ptr.getClass().getContainerStore(ptr);
|
|
|
|
store.remove(item, store.count(item), ptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
equal = true;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:04:35 +00:00
|
|
|
if (dedicItem.empty() || equal)
|
2016-01-12 03:41:44 +00:00
|
|
|
continue;
|
|
|
|
|
2017-01-25 15:06:15 +00:00
|
|
|
const int count = equipedItems[slot].count;
|
2016-01-12 03:41:44 +00:00
|
|
|
ptr.getClass().getContainerStore(ptr).add(dedicItem, count, ptr);
|
|
|
|
|
|
|
|
for (MWWorld::ContainerStoreIterator it2 = invStore.begin(); it2 != invStore.end(); ++it2)
|
|
|
|
{
|
|
|
|
if (::Misc::StringUtils::ciEqual(it2->getCellRef().getRefId(), dedicItem)) // equip item
|
|
|
|
{
|
|
|
|
boost::shared_ptr<MWWorld::Action> action = it2->getClass().use(*it2);
|
|
|
|
action->execute(ptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DedicatedPlayer::updateCell()
|
|
|
|
{
|
2016-08-17 04:27:40 +00:00
|
|
|
// Prevent cell update when player hasn't been instantiated yet
|
|
|
|
if (state == 0)
|
|
|
|
return;
|
2016-08-16 22:06:50 +00:00
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
|
|
|
MWWorld::CellStore *cellStore;
|
2016-08-17 04:27:40 +00:00
|
|
|
|
2016-08-18 19:29:54 +00:00
|
|
|
|
2017-03-04 06:55:35 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Server says %s (%s) moved to %s", ptr.getBase()->mRef.getRefId().c_str(),
|
2017-04-17 16:34:32 +00:00
|
|
|
this->npc.mName.c_str(), cell.getDescription().c_str());
|
2016-11-04 18:53:19 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (cell.isExterior())
|
|
|
|
cellStore = world->getExterior(cell.mData.mX, cell.mData.mY);
|
|
|
|
else
|
|
|
|
cellStore = world->getInterior(cell.mName);
|
|
|
|
}
|
|
|
|
// If the intended cell doesn't exist on this client, use ToddTest as a replacement
|
|
|
|
catch (std::exception&)
|
|
|
|
{
|
|
|
|
cellStore = world->getInterior("ToddTest");
|
|
|
|
LOG_APPEND(Log::LOG_INFO, "%s", "- Cell doesn't exist on this client");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cellStore) return;
|
2016-07-20 00:26:25 +00:00
|
|
|
|
2016-11-04 18:53:19 +00:00
|
|
|
// Allow this player's reference to move across a cell now that a manual cell
|
|
|
|
// update has been called
|
2016-07-20 00:26:25 +00:00
|
|
|
ptr.getBase()->canChangeCell = true;
|
2017-01-25 15:06:15 +00:00
|
|
|
updatePtr(world->moveObject(ptr, cellStore, position.pos[0], position.pos[1], position.pos[2]));
|
2017-04-10 15:24:30 +00:00
|
|
|
|
|
|
|
// If this player is now in a cell that is active for us, we should send them all
|
|
|
|
// NPC data in that cell
|
|
|
|
if (MWBase::Environment::get().getWorld()->isCellActive(cellStore))
|
|
|
|
{
|
|
|
|
if (Main::get().getCellController()->isActiveCell(cell))
|
|
|
|
Main::get().getCellController()->getCell(cell)->updateLocal(true);
|
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
2016-10-22 09:06:26 +00:00
|
|
|
|
|
|
|
void DedicatedPlayer::updateMarker()
|
|
|
|
{
|
|
|
|
if (!markerEnabled)
|
|
|
|
return;
|
2016-10-24 13:26:51 +00:00
|
|
|
|
2016-10-22 09:06:26 +00:00
|
|
|
GUIController *gui = Main::get().getGUIController();
|
2016-10-24 13:26:51 +00:00
|
|
|
|
2016-10-30 14:39:59 +00:00
|
|
|
if (gui->mPlayerMarkers.contains(marker))
|
2016-10-22 09:06:26 +00:00
|
|
|
{
|
|
|
|
gui->mPlayerMarkers.deleteMarker(marker);
|
|
|
|
marker = gui->CreateMarker(guid);
|
|
|
|
gui->mPlayerMarkers.addMarker(marker);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gui->mPlayerMarkers.addMarker(marker, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DedicatedPlayer::removeMarker()
|
|
|
|
{
|
|
|
|
if (!markerEnabled)
|
|
|
|
return;
|
2016-10-24 13:26:51 +00:00
|
|
|
|
2016-10-22 09:06:26 +00:00
|
|
|
markerEnabled = false;
|
|
|
|
Main::get().getGUIController()->mPlayerMarkers.deleteMarker(marker);
|
|
|
|
}
|
|
|
|
|
2016-10-24 12:10:32 +00:00
|
|
|
void DedicatedPlayer::setMarkerState(bool state)
|
2016-10-22 09:06:26 +00:00
|
|
|
{
|
2016-10-24 12:10:32 +00:00
|
|
|
if (state)
|
2016-10-24 13:26:51 +00:00
|
|
|
{
|
|
|
|
markerEnabled = true;
|
2016-10-22 09:06:26 +00:00
|
|
|
updateMarker();
|
2016-10-24 13:26:51 +00:00
|
|
|
}
|
2016-10-22 09:06:26 +00:00
|
|
|
else
|
|
|
|
removeMarker();
|
|
|
|
}
|
2016-11-12 11:39:04 +00:00
|
|
|
|
2017-04-17 16:34:32 +00:00
|
|
|
MWWorld::Ptr DedicatedPlayer::getPtr()
|
|
|
|
{
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::Ptr DedicatedPlayer::getLiveCellPtr()
|
|
|
|
{
|
|
|
|
return reference->getPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::ManualRef *DedicatedPlayer::getRef()
|
|
|
|
{
|
|
|
|
return reference;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DedicatedPlayer::updatePtr(MWWorld::Ptr newPtr)
|
|
|
|
{
|
|
|
|
ptr.mCell = newPtr.mCell;
|
|
|
|
ptr.mRef = newPtr.mRef;
|
|
|
|
ptr.mContainerStore = newPtr.mContainerStore;
|
|
|
|
|
|
|
|
// Disallow this player's reference from moving across cells until
|
|
|
|
// the correct packet is sent by the player
|
|
|
|
ptr.getBase()->canChangeCell = false;
|
|
|
|
}
|