[General] Implement player scale as part of PlayerShapeshift

0.6.3
David Cernat 7 years ago
parent aa448523f8
commit 029dfc56ba

@ -34,6 +34,7 @@ void Players::newPlayer(RakNet::RakNetGUID guid)
players[guid]->npcStats.blank(); players[guid]->npcStats.blank();
players[guid]->creatureStats.blank(); players[guid]->creatureStats.blank();
players[guid]->charClass.blank(); players[guid]->charClass.blank();
players[guid]->scale = 1;
players[guid]->isWerewolf = false; players[guid]->isWerewolf = false;
for (unsigned int i = 0; i < mwmp::Networking::get().maxConnections(); i++) 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]; 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 bool MechanicsFunctions::IsWerewolf(unsigned short pid) noexcept
{ {
Player *player; Player *player;
@ -103,7 +111,15 @@ void MechanicsFunctions::SetMarkRot(unsigned short pid, double x, double z) noex
player->markPosition.rot[2] = z; 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; Player *player;
GET_PLAYER(pid, player, ); GET_PLAYER(pid, player, );

@ -13,12 +13,14 @@
{"GetMarkRotX", MechanicsFunctions::GetMarkRotX},\ {"GetMarkRotX", MechanicsFunctions::GetMarkRotX},\
{"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\ {"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\
\ \
{"GetScale", MechanicsFunctions::GetScale},\
{"IsWerewolf", MechanicsFunctions::IsWerewolf},\ {"IsWerewolf", MechanicsFunctions::IsWerewolf},\
\ \
{"SetMarkCell", MechanicsFunctions::SetMarkCell},\ {"SetMarkCell", MechanicsFunctions::SetMarkCell},\
{"SetMarkPos", MechanicsFunctions::SetMarkPos},\ {"SetMarkPos", MechanicsFunctions::SetMarkPos},\
{"SetMarkRot", MechanicsFunctions::SetMarkRot},\ {"SetMarkRot", MechanicsFunctions::SetMarkRot},\
\ \
{"SetScale", MechanicsFunctions::SetScale},\
{"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\
\ \
{"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\
@ -87,6 +89,14 @@ public:
*/ */
static double GetMarkRotZ(unsigned short pid) noexcept; 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. * \brief Check whether a player is a werewolf.
* *
@ -139,6 +149,18 @@ public:
*/ */
static void SetMarkRot(unsigned short pid, double x, double z) noexcept; 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. * \brief Set the werewolf state of a player.
* *
@ -149,7 +171,7 @@ public:
* \param bool The new werewolf state. * \param bool The new werewolf state.
* \return void * \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. * \brief Send a PlayerMiscellaneous packet with a Mark location to a player.

@ -243,6 +243,7 @@ void DedicatedPlayer::setCell()
void DedicatedPlayer::setShapeshift() void DedicatedPlayer::setShapeshift()
{ {
MWBase::Environment::get().getWorld()->scaleObject(ptr, scale);
MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, isWerewolf); MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptr, isWerewolf);
} }

@ -64,6 +64,7 @@ LocalPlayer::LocalPlayer()
jailProgressText = ""; jailProgressText = "";
jailEndText = ""; jailEndText = "";
scale = 1;
isWerewolf = false; isWerewolf = false;
diedSinceArrestAttempt = false; diedSinceArrestAttempt = false;
@ -1266,6 +1267,8 @@ void LocalPlayer::setMapExplored()
void LocalPlayer::setShapeshift() void LocalPlayer::setShapeshift()
{ {
MWWorld::Ptr ptrPlayer = getPlayerPtr(); MWWorld::Ptr ptrPlayer = getPlayerPtr();
MWBase::Environment::get().getWorld()->scaleObject(ptrPlayer, scale);
MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptrPlayer, isWerewolf); MWBase::Environment::get().getMechanicsManager()->setWerewolf(ptrPlayer, isWerewolf);
} }
@ -1553,7 +1556,17 @@ void LocalPlayer::sendBook(const std::string& bookId)
getNetworking()->getPlayerPacket(ID_PLAYER_BOOK)->Send(); 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; isWerewolf = werewolfState;

@ -89,7 +89,8 @@ namespace mwmp
void sendTopic(const std::string& topic); void sendTopic(const std::string& topic);
void sendKill(const std::string& refId, int number); void sendKill(const std::string& refId, int number);
void sendBook(const std::string& bookId); 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 sendMarkLocation(const ESM::Cell& newMarkCell, const ESM::Position& newMarkPosition);
void clearCellStates(); void clearCellStates();

@ -1231,7 +1231,7 @@ namespace MWScript
When the player's werewolf state changes, send an ID_PLAYER_SHAPESHIFT packet When the player's werewolf state changes, send an ID_PLAYER_SHAPESHIFT packet
*/ */
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
mwmp::Main::get().getLocalPlayer()->sendShapeshift(set); mwmp::Main::get().getLocalPlayer()->sendWerewolfState(set);
/* /*
End of tes3mp addition End of tes3mp addition
*/ */

@ -8,6 +8,8 @@
#include <components/openmw-mp/Log.hpp> #include <components/openmw-mp/Log.hpp>
#include "../mwmp/Main.hpp" #include "../mwmp/Main.hpp"
#include "../mwmp/Networking.hpp" #include "../mwmp/Networking.hpp"
#include "../mwmp/LocalPlayer.hpp"
#include "../mwmp/PlayerList.hpp"
#include "../mwmp/WorldEvent.hpp" #include "../mwmp/WorldEvent.hpp"
/* /*
End of tes3mp addition End of tes3mp addition
@ -57,16 +59,26 @@ namespace MWScript
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_OBJECT_SCALE every time an object's scale is changed Send an ID_PLAYER_SHAPESHIFT every time a player changes
through a script their own scale
Otherwise, send an ID_OBJECT_SCALE every time an object's
scale is changed through a script
*/ */
if (ptr.isInCell() && (ptr.getCellRef().getScale() != scale)) 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
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); if (mwmp::PlayerList::isDedicatedPlayer(ptr))
worldEvent->reset(); return;
worldEvent->addObjectScale(ptr, scale); else
worldEvent->sendObjectScale(); {
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->reset();
worldEvent->addObjectScale(ptr, scale);
worldEvent->sendObjectScale();
}
} }
/* /*
End of tes3mp addition End of tes3mp addition

@ -283,6 +283,7 @@ namespace mwmp
std::string sound; std::string sound;
Animation animation; Animation animation;
float scale;
bool isWerewolf; bool isWerewolf;
std::string creatureModel; std::string creatureModel;
bool useCreatureName; bool useCreatureName;

@ -12,5 +12,6 @@ void PacketPlayerShapeshift::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->scale, send);
RW(player->isWerewolf, send); RW(player->isWerewolf, send);
} }

Loading…
Cancel
Save