forked from mirror/openmw-tes3mp
[General] Implement player scale as part of PlayerShapeshift
This commit is contained in:
parent
aa448523f8
commit
029dfc56ba
10 changed files with 82 additions and 14 deletions
|
@ -34,6 +34,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
|
|||
players[guid]->npcStats.blank();
|
||||
players[guid]->creatureStats.blank();
|
||||
players[guid]->charClass.blank();
|
||||
players[guid]->scale = 1;
|
||||
players[guid]->isWerewolf = false;
|
||||
|
||||
for (unsigned int i = 0; i < mwmp::Networking::get().maxConnections(); i++)
|
||||
|
|
|
@ -68,6 +68,14 @@ double MechanicsFunctions::GetMarkRotZ(unsigned short pid) noexcept
|
|||
return player->markPosition.rot[2];
|
||||
}
|
||||
|
||||
double MechanicsFunctions::GetScale(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, 0.0f);
|
||||
|
||||
return player->scale;
|
||||
}
|
||||
|
||||
bool MechanicsFunctions::IsWerewolf(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
|
@ -103,7 +111,15 @@ void MechanicsFunctions::SetMarkRot(unsigned short pid, double x, double z) noex
|
|||
player->markPosition.rot[2] = z;
|
||||
}
|
||||
|
||||
void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf)
|
||||
void MechanicsFunctions::SetScale(unsigned short pid, double scale) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
player->scale = scale;
|
||||
}
|
||||
|
||||
void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
|
|
@ -13,12 +13,14 @@
|
|||
{"GetMarkRotX", MechanicsFunctions::GetMarkRotX},\
|
||||
{"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\
|
||||
\
|
||||
{"GetScale", MechanicsFunctions::GetScale},\
|
||||
{"IsWerewolf", MechanicsFunctions::IsWerewolf},\
|
||||
\
|
||||
{"SetMarkCell", MechanicsFunctions::SetMarkCell},\
|
||||
{"SetMarkPos", MechanicsFunctions::SetMarkPos},\
|
||||
{"SetMarkRot", MechanicsFunctions::SetMarkRot},\
|
||||
\
|
||||
{"SetScale", MechanicsFunctions::SetScale},\
|
||||
{"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\
|
||||
\
|
||||
{"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\
|
||||
|
@ -87,6 +89,14 @@ public:
|
|||
*/
|
||||
static double GetMarkRotZ(unsigned short pid) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Get the scale of a player.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \return The scale.
|
||||
*/
|
||||
static double GetScale(unsigned short pid) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Check whether a player is a werewolf.
|
||||
*
|
||||
|
@ -139,6 +149,18 @@ public:
|
|||
*/
|
||||
static void SetMarkRot(unsigned short pid, double x, double z) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the scale of a player.
|
||||
*
|
||||
* This changes the scale recorded for that player in the server memory, but
|
||||
* does not by itself send a packet.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \param bool The new scale.
|
||||
* \return void
|
||||
*/
|
||||
static void SetScale(unsigned short pid, double scale) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the werewolf state of a player.
|
||||
*
|
||||
|
@ -149,7 +171,7 @@ public:
|
|||
* \param bool The new werewolf state.
|
||||
* \return void
|
||||
*/
|
||||
static void SetWerewolfState(unsigned short pid, bool isWerewolf);
|
||||
static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Send a PlayerMiscellaneous packet with a Mark location to a player.
|
||||
|
|
|
@ -243,6 +243,7 @@ void DedicatedPlayer::setCell()
|
|||
|
||||
void DedicatedPlayer::setShapeshift()
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->scaleObject(ptr, scale);
|
||||
MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, isWerewolf);
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ LocalPlayer::LocalPlayer()
|
|||
jailProgressText = "";
|
||||
jailEndText = "";
|
||||
|
||||
scale = 1;
|
||||
isWerewolf = false;
|
||||
|
||||
diedSinceArrestAttempt = false;
|
||||
|
@ -1266,6 +1267,8 @@ void LocalPlayer::setMapExplored()
|
|||
void LocalPlayer::setShapeshift()
|
||||
{
|
||||
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
||||
|
||||
MWBase::Environment::get().getWorld()->scaleObject(ptrPlayer, scale);
|
||||
MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptrPlayer, isWerewolf);
|
||||
}
|
||||
|
||||
|
@ -1553,7 +1556,17 @@ void LocalPlayer::sendBook(const std::string& bookId)
|
|||
getNetworking()->getPlayerPacket(ID_PLAYER_BOOK)->Send();
|
||||
}
|
||||
|
||||
void LocalPlayer::sendShapeshift(bool werewolfState)
|
||||
void LocalPlayer::sendScale(float newScale)
|
||||
{
|
||||
scale = newScale;
|
||||
|
||||
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Sending ID_PLAYER_SHAPESHIFT with scale of %f", scale);
|
||||
|
||||
getNetworking()->getPlayerPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(this);
|
||||
getNetworking()->getPlayerPacket(ID_PLAYER_SHAPESHIFT)->Send();
|
||||
}
|
||||
|
||||
void LocalPlayer::sendWerewolfState(bool werewolfState)
|
||||
{
|
||||
isWerewolf = werewolfState;
|
||||
|
||||
|
|
|
@ -89,7 +89,8 @@ namespace mwmp
|
|||
void sendTopic(const std::string& topic);
|
||||
void sendKill(const std::string& refId, int number);
|
||||
void sendBook(const std::string& bookId);
|
||||
void sendShapeshift(bool isWerewolf);
|
||||
void sendScale(float newScale);
|
||||
void sendWerewolfState(bool isWerewolf);
|
||||
void sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition);
|
||||
|
||||
void clearCellStates();
|
||||
|
|
|
@ -1231,7 +1231,7 @@ namespace MWScript
|
|||
When the player's werewolf state changes, send an ID_PLAYER_SHAPESHIFT packet
|
||||
*/
|
||||
if (ptr == MWMechanics::getPlayer())
|
||||
mwmp::Main::get().getLocalPlayer()->sendShapeshift(set);
|
||||
mwmp::Main::get().getLocalPlayer()->sendWerewolfState(set);
|
||||
/*
|
||||
End of tes3mp addition
|
||||
*/
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <components/openmw-mp/Log.hpp>
|
||||
#include "../mwmp/Main.hpp"
|
||||
#include "../mwmp/Networking.hpp"
|
||||
#include "../mwmp/LocalPlayer.hpp"
|
||||
#include "../mwmp/PlayerList.hpp"
|
||||
#include "../mwmp/WorldEvent.hpp"
|
||||
/*
|
||||
End of tes3mp addition
|
||||
|
@ -57,16 +59,26 @@ namespace MWScript
|
|||
/*
|
||||
Start of tes3mp addition
|
||||
|
||||
Send an ID_OBJECT_SCALE every time an object's scale is changed
|
||||
through a script
|
||||
*/
|
||||
if (ptr.isInCell() && (ptr.getCellRef().getScale() != scale))
|
||||
{
|
||||
Send an ID_PLAYER_SHAPESHIFT every time a player changes
|
||||
their own scale
|
||||
|
||||
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||
worldEvent->reset();
|
||||
worldEvent->addObjectScale(ptr, scale);
|
||||
worldEvent->sendObjectScale();
|
||||
Otherwise, send an ID_OBJECT_SCALE every time an object's
|
||||
scale is changed through a script
|
||||
*/
|
||||
if (ptr == MWMechanics::getPlayer())
|
||||
mwmp::Main::get().getLocalPlayer()->sendScale(scale);
|
||||
else if (ptr.isInCell() && (ptr.getCellRef().getScale() != scale))
|
||||
{
|
||||
// Ignore attempts to change another player's scale
|
||||
if (mwmp::PlayerList::isDedicatedPlayer(ptr))
|
||||
return;
|
||||
else
|
||||
{
|
||||
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
|
||||
worldEvent->reset();
|
||||
worldEvent->addObjectScale(ptr, scale);
|
||||
worldEvent->sendObjectScale();
|
||||
}
|
||||
}
|
||||
/*
|
||||
End of tes3mp addition
|
||||
|
|
|
@ -283,6 +283,7 @@ namespace mwmp
|
|||
std::string sound;
|
||||
Animation animation;
|
||||
|
||||
float scale;
|
||||
bool isWerewolf;
|
||||
std::string creatureModel;
|
||||
bool useCreatureName;
|
||||
|
|
|
@ -12,5 +12,6 @@ void PacketPlayerShapeshift::Packet(RakNet::BitStream *bs, bool send)
|
|||
{
|
||||
PlayerPacket::Packet(bs, send);
|
||||
|
||||
RW(player->scale, send);
|
||||
RW(player->isWerewolf, send);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue