1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 10:49:57 +00:00
openmw-tes3mp/apps/openmw/mwmp/processors/player/ProcessorPlayerResurrect.hpp
David Cernat e70faf1016 [Client] Fix crashes in PlayerProcessors from NULL players
Also rename ProcessorPlayerDrawState into ProcessorPlayerAnimFlags
2017-04-24 01:46:27 +03:00

67 lines
2.4 KiB
C++

//
// Created by koncord on 16.04.17.
//
#ifndef OPENMW_PROCESSORPLAYERRESURRECT_HPP
#define OPENMW_PROCESSORPLAYERRESURRECT_HPP
#include "apps/openmw/mwmp/PlayerProcessor.hpp"
#include "apps/openmw/mwmp/Main.hpp"
#include "apps/openmw/mwmp/Networking.hpp"
namespace mwmp
{
class ProcessorPlayerResurrect : public PlayerProcessor
{
public:
ProcessorPlayerResurrect()
{
BPP_INIT(ID_PLAYER_RESURRECT)
avoidReading = true;
}
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Received ID_PLAYER_RESURRECT from server");
if (isLocal())
{
LOG_APPEND(Log::LOG_INFO, "- Packet was about me");
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr();
playerPtr.getClass().getCreatureStats(playerPtr).resurrect();
// If this player had a weapon or spell readied when dying, they will
// still have it readied but be unable to use it unless we clear it here
playerPtr.getClass().getNpcStats(playerPtr).setDrawState(MWMechanics::DrawState_Nothing);
packet.setPlayer(player);
packet.Send(serverAddr);
static_cast<LocalPlayer*>(player)->updateStatsDynamic(true);
Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player);
Main::get().getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(serverAddr);
}
else if (player != 0)
{
LOG_APPEND(Log::LOG_INFO, "- Packet was about %s", player->npc.mName.c_str());
player->creatureStats.mDead = false;
if (player->creatureStats.mDynamic[0].mMod < 1)
player->creatureStats.mDynamic[0].mMod = 1;
player->creatureStats.mDynamic[0].mCurrent = player->creatureStats.mDynamic[0].mMod;
MWWorld::Ptr ptr = static_cast<DedicatedPlayer*>(player)->getPtr();
ptr.getClass().getCreatureStats(ptr).resurrect();
MWMechanics::DynamicStat<float> health;
health.readState(player->creatureStats.mDynamic[0]);
ptr.getClass().getCreatureStats(ptr).setHealth(health);
}
}
};
}
#endif //OPENMW_PROCESSORPLAYERRESURRECT_HPP