[General] Move creature disguises for players to PlayerShapeshift packet

Additionally, make associated variables clearer, and move associated server script functions next to other shapeshifting functions.
0.6.3
David Cernat 7 years ago
parent 34be9383e5
commit c8abd11f5d

@ -92,6 +92,22 @@ bool MechanicsFunctions::IsWerewolf(unsigned short pid) noexcept
return player->isWerewolf;
}
const char *MechanicsFunctions::GetCreatureRefId(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->creatureRefId.c_str();
}
bool MechanicsFunctions::DisplaysCreatureName(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->displayCreatureName;
}
void MechanicsFunctions::SetMarkCell(unsigned short pid, const char *cellDescription) noexcept
{
Player *player;
@ -143,6 +159,15 @@ void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) n
player->isWerewolf = isWerewolf;
}
void MechanicsFunctions::SetCreatureRefId(unsigned short pid, const char *refId, bool displayCreatureName) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
player->creatureRefId = refId;
player->displayCreatureName = displayCreatureName;
}
void MechanicsFunctions::SendMarkLocation(unsigned short pid)
{
Player *player;

@ -16,6 +16,8 @@
\
{"GetScale", MechanicsFunctions::GetScale},\
{"IsWerewolf", MechanicsFunctions::IsWerewolf},\
{"GetCreatureRefId", MechanicsFunctions::GetCreatureRefId},\
{"DisplaysCreatureName", MechanicsFunctions::DisplaysCreatureName},\
\
{"SetMarkCell", MechanicsFunctions::SetMarkCell},\
{"SetMarkPos", MechanicsFunctions::SetMarkPos},\
@ -24,6 +26,7 @@
\
{"SetScale", MechanicsFunctions::SetScale},\
{"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\
{"SetCreatureRefId", MechanicsFunctions::SetCreatureRefId},\
\
{"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\
{"SendSelectedSpell", MechanicsFunctions::SendSelectedSpell},\
@ -118,6 +121,25 @@ public:
*/
static bool IsWerewolf(unsigned short pid) noexcept;
/**
* \brief Get the refId of the creature the player is disguised as.
*
* \param pid The player ID.
* \return The creature refId.
*/
static const char *GetCreatureRefId(unsigned short pid) noexcept;
/**
* \brief Check whether a player's name is replaced by that of the creature they are
* disguised as when other players hover over them.
*
* This is based on the last PlayerShapeshift packet received or sent for that player.
*
* \param pid The player ID.
* \return The creature name display state.
*/
static bool DisplaysCreatureName(unsigned short pid) noexcept;
/**
* \brief Set the Mark cell of a player.
*
@ -196,6 +218,20 @@ public:
*/
static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept;
/**
* \brief Set the refId of the creature a player is disguised as.
*
* This changes the creature refId recorded for that player in the server memory, but
* does not by itself send a packet.
*
* \param pid The player ID.
* \param refId The creature refId.
* \param displaysCreatureName Whether the player's name appears as that of the creature
* when hovered over by others.
* \return void
*/
static void SetCreatureRefId(unsigned short pid, const char *refId, bool displayCreatureName) noexcept;
/**
* \brief Send a PlayerMiscellaneous packet with a Mark location to a player.
*

@ -118,22 +118,6 @@ const char *StatsFunctions::GetBirthsign(unsigned short pid) noexcept
return player->birthsign.c_str();
}
const char *StatsFunctions::GetCreatureModel(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->creatureModel.c_str();
}
bool StatsFunctions::IsCreatureName(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0);
return player->useCreatureName;
}
const char *StatsFunctions::GetDeathReason(unsigned short pid) noexcept
{
Player *player;
@ -346,16 +330,6 @@ void StatsFunctions::SetBirthsign(unsigned short pid, const char *sign) noexcept
player->birthsign = sign;
}
void StatsFunctions::SetCreatureModel(unsigned short pid, const char *name, bool useCreatureName) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
player->creatureModel = name;
player->useCreatureName = useCreatureName;
}
void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept
{
Player *player;

@ -19,8 +19,6 @@
{"GetHair", StatsFunctions::GetHairstyle},\
{"GetIsMale", StatsFunctions::GetIsMale},\
{"GetBirthsign", StatsFunctions::GetBirthsign},\
{"GetCreatureModel", StatsFunctions::GetCreatureModel},\
{"IsCreatureName", StatsFunctions::IsCreatureName},\
{"GetDeathReason", StatsFunctions::GetDeathReason},\
\
{"GetLevel", StatsFunctions::GetLevel},\
@ -51,7 +49,6 @@
{"SetHair", StatsFunctions::SetHairstyle},\
{"SetIsMale", StatsFunctions::SetIsMale},\
{"SetBirthsign", StatsFunctions::SetBirthsign},\
{"SetCreatureModel", StatsFunctions::SetCreatureModel},\
\
{"SetLevel", StatsFunctions::SetLevel},\
{"SetLevelProgress", StatsFunctions::SetLevelProgress},\
@ -98,8 +95,6 @@ public:
static const char *GetHairstyle(unsigned short pid) noexcept;
static int GetIsMale(unsigned short pid) noexcept;
static const char *GetBirthsign(unsigned short pid) noexcept;
static const char *GetCreatureModel(unsigned short pid) noexcept;
static bool IsCreatureName(unsigned short pid) noexcept;
static const char *GetDeathReason(unsigned short pid) noexcept;
static int GetLevel(unsigned short pid) noexcept;
@ -128,7 +123,6 @@ public:
static void SetHairstyle(unsigned short pid, const char *style) noexcept;
static void SetIsMale(unsigned short pid, int male) noexcept;
static void SetBirthsign(unsigned short pid, const char *name) noexcept;
static void SetCreatureModel(unsigned short pid, const char *name, bool useCreatureName) noexcept;
static void SetLevel(unsigned short pid, int value) noexcept;
static void SetLevelProgress(unsigned short pid, int value) noexcept;

@ -44,21 +44,21 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid)
ESM::Creature creature;
ESM::NPC npc;
if (!dedicPlayer->creatureModel.empty())
if (!dedicPlayer->creatureRefId.empty())
{
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(dedicPlayer->creatureModel);
const ESM::Creature *tmpCreature = world->getStore().get<ESM::Creature>().search(dedicPlayer->creatureRefId);
if (tmpCreature == 0)
{
dedicPlayer->creatureModel = "";
dedicPlayer->creatureRefId = "";
createPlayer(guid);
return;
}
creature = *tmpCreature;
creature.mScript = "";
if (!dedicPlayer->useCreatureName)
if (!dedicPlayer->displayCreatureName)
creature.mName = dedicPlayer->npc.mName;
LOG_APPEND(Log::LOG_INFO, "Player %s looks like %s", dedicPlayer->npc.mName.c_str(),
dedicPlayer->creatureModel.c_str());
dedicPlayer->creatureRefId.c_str());
}
else
{
@ -82,8 +82,8 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid)
if (dedicPlayer->reference)
{
bool isNPC = dedicPlayer->reference->getPtr().getTypeName() == typeid(ESM::NPC).name();
if ((!dedicPlayer->creatureModel.empty() && isNPC) ||
(dedicPlayer->creatureModel.empty() && !isNPC))
if ((!dedicPlayer->creatureRefId.empty() && isNPC) ||
(dedicPlayer->creatureRefId.empty() && !isNPC))
{
if (dedicPlayer->reference)
{
@ -106,7 +106,7 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid)
if (dedicPlayer->state == 0)
{
string recid;
if (dedicPlayer->creatureModel.empty())
if (dedicPlayer->creatureRefId.empty())
{
LOG_APPEND(Log::LOG_INFO, "- Creating new NPC record");
npc.mId = "Dedicated Player";
@ -158,7 +158,7 @@ void PlayerList::createPlayer(RakNet::RakNetGUID guid)
MWWorld::Store<ESM::Creature> *creature_store = const_cast<MWWorld::Store<ESM::Creature> *> (&store->get<ESM::Creature>());
MWWorld::Store<ESM::NPC> *npc_store = const_cast<MWWorld::Store<ESM::NPC> *> (&store->get<ESM::NPC>());
if (!dedicPlayer->creatureModel.empty())
if (!dedicPlayer->creatureRefId.empty())
{
if (!npc.mId.empty() || npc.mId != "Dedicated Player")
{

@ -224,7 +224,7 @@ namespace mwmp
inventoryChanges.count = 0;
spellbookChanges.action = 0;
spellbookChanges.count = 0;
useCreatureName = false;
displayCreatureName = false;
}
BasePlayer()
@ -287,8 +287,9 @@ namespace mwmp
float scale;
bool isWerewolf;
std::string creatureModel;
bool useCreatureName;
bool displayCreatureName;
std::string creatureRefId;
bool isChangingRegion;

@ -25,7 +25,4 @@ void PacketPlayerBaseInfo::Packet(RakNet::BitStream *bs, bool send)
RW(player->npc.mFlags, send);
RW(player->birthsign, send, 1);
RW(player->creatureModel, send, 1);
RW(player->useCreatureName, send);
}

@ -14,4 +14,7 @@ void PacketPlayerShapeshift::Packet(RakNet::BitStream *bs, bool send)
RW(player->scale, send);
RW(player->isWerewolf, send);
RW(player->displayCreatureName, send);
RW(player->creatureRefId, send, 1);
}

Loading…
Cancel
Save