mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 06:15:32 +00:00
[General] Implement PlayerReputation packet
This commit is contained in:
parent
88ae0772cf
commit
989f6e6b51
6 changed files with 87 additions and 11 deletions
|
@ -79,6 +79,14 @@ void QuestFunctions::AddKill(unsigned short pid, const char* refId, int number)
|
|||
player->killChanges.kills.push_back(kill);
|
||||
}
|
||||
|
||||
void QuestFunctions::SetReputation(unsigned short pid, int value) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
player->npcStats.mReputation = value;
|
||||
}
|
||||
|
||||
const char *QuestFunctions::GetJournalItemQuest(unsigned short pid, unsigned int i) noexcept
|
||||
{
|
||||
Player *player;
|
||||
|
@ -133,6 +141,14 @@ int QuestFunctions::GetKillNumber(unsigned short pid, unsigned int i) noexcept
|
|||
return player->killChanges.kills.at(i).number;
|
||||
}
|
||||
|
||||
int QuestFunctions::GetReputation(unsigned short pid) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, 0);
|
||||
|
||||
return player->npcStats.mReputation;
|
||||
}
|
||||
|
||||
void QuestFunctions::SendJournalChanges(unsigned short pid, bool toOthers) noexcept
|
||||
{
|
||||
Player *player;
|
||||
|
@ -150,3 +166,12 @@ void QuestFunctions::SendKillChanges(unsigned short pid, bool toOthers) noexcept
|
|||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->setPlayer(player);
|
||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->Send(toOthers);
|
||||
}
|
||||
|
||||
void QuestFunctions::SendReputation(unsigned short pid, bool toOthers) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player, );
|
||||
|
||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION)->setPlayer(player);
|
||||
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_REPUTATION)->Send(toOthers);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
{"AddJournalIndex", QuestFunctions::AddJournalIndex},\
|
||||
{"AddKill", QuestFunctions::AddKill},\
|
||||
\
|
||||
{"SetReputation", QuestFunctions::SetReputation},\
|
||||
\
|
||||
{"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\
|
||||
{"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\
|
||||
{"GetJournalItemType", QuestFunctions::GetJournalItemType},\
|
||||
|
@ -19,8 +21,11 @@
|
|||
{"GetKillRefId", QuestFunctions::GetKillRefId},\
|
||||
{"GetKillNumber", QuestFunctions::GetKillNumber},\
|
||||
\
|
||||
{"GetReputation", QuestFunctions::GetReputation},\
|
||||
\
|
||||
{"SendJournalChanges", QuestFunctions::SendJournalChanges},\
|
||||
{"SendKillChanges", QuestFunctions::SendKillChanges}
|
||||
{"SendKillChanges", QuestFunctions::SendKillChanges},\
|
||||
{"SendReputation", QuestFunctions::SendReputation}
|
||||
|
||||
class QuestFunctions
|
||||
{
|
||||
|
@ -93,6 +98,15 @@ public:
|
|||
*/
|
||||
static void AddKill(unsigned short pid, const char* refId, int number) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Set the reputation of a certain player.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \param value The reputation.
|
||||
* \return void
|
||||
*/
|
||||
static void SetReputation(unsigned short pid, int value) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Get the quest at a certain index in a player's latest journal changes.
|
||||
*
|
||||
|
@ -149,6 +163,14 @@ public:
|
|||
*/
|
||||
static int GetKillNumber(unsigned short pid, unsigned int i) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Get the a certain player's reputation.
|
||||
*
|
||||
* \param pid The player ID.
|
||||
* \return The reputation.
|
||||
*/
|
||||
static int GetReputation(unsigned short pid) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Send a PlayerJournal packet with a player's recorded journal changes.
|
||||
*
|
||||
|
@ -169,6 +191,16 @@ public:
|
|||
*/
|
||||
static void SendKillChanges(unsigned short pid, bool toOthers = false) noexcept;
|
||||
|
||||
/**
|
||||
* \brief Send a PlayerReputation packet with a player's recorded reputation.
|
||||
*
|
||||
* \param pid The player ID whose reputation should be used.
|
||||
* \param toOthers Whether this packet should be sent only to other players or
|
||||
* only to the player it is about.
|
||||
* \return void
|
||||
*/
|
||||
static void SendReputation(unsigned short pid, bool toOthers) noexcept;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
|
|
@ -105,6 +105,7 @@ void LocalPlayer::update()
|
|||
updateSkills();
|
||||
updateLevel();
|
||||
updateBounty();
|
||||
updateReputation();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,6 +329,19 @@ void LocalPlayer::updateBounty(bool forceUpdate)
|
|||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::updateReputation(bool forceUpdate)
|
||||
{
|
||||
MWWorld::Ptr ptrPlayer = getPlayerPtr();
|
||||
const MWMechanics::NpcStats &ptrNpcStats = ptrPlayer.getClass().getNpcStats(ptrPlayer);
|
||||
|
||||
if (ptrNpcStats.getReputation() != npcStats.mReputation || forceUpdate)
|
||||
{
|
||||
npcStats.mReputation = ptrNpcStats.getReputation();
|
||||
getNetworking()->getPlayerPacket(ID_PLAYER_REPUTATION)->setPlayer(this);
|
||||
getNetworking()->getPlayerPacket(ID_PLAYER_REPUTATION)->Send();
|
||||
}
|
||||
}
|
||||
|
||||
void LocalPlayer::updatePosition(bool forceUpdate)
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
@ -928,6 +942,15 @@ void LocalPlayer::setBounty()
|
|||
ptrNpcStats->setBounty(npcStats.mBounty);
|
||||
}
|
||||
|
||||
void LocalPlayer::setReputation()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
MWWorld::Ptr ptrPlayer = world->getPlayerPtr();
|
||||
|
||||
MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer);
|
||||
ptrNpcStats->setReputation(npcStats.mReputation);
|
||||
}
|
||||
|
||||
void LocalPlayer::setPosition()
|
||||
{
|
||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace mwmp
|
|||
void updateSkills(bool forceUpdate = false);
|
||||
void updateLevel(bool forceUpdate = false);
|
||||
void updateBounty(bool forceUpdate = false);
|
||||
void updateReputation(bool forceUpdate = false);
|
||||
void updatePosition(bool forceUpdate = false);
|
||||
void updateCell(bool forceUpdate = false);
|
||||
void updateChar();
|
||||
|
@ -56,6 +57,7 @@ namespace mwmp
|
|||
void setSkills();
|
||||
void setLevel();
|
||||
void setBounty();
|
||||
void setReputation();
|
||||
void setPosition();
|
||||
void setCell();
|
||||
void setClass();
|
||||
|
|
|
@ -16,19 +16,13 @@ namespace mwmp
|
|||
|
||||
virtual void Do(PlayerPacket &packet, BasePlayer *player)
|
||||
{
|
||||
if (isLocal())
|
||||
if (isRequest())
|
||||
{
|
||||
//if (isRequest())
|
||||
// static_cast<LocalPlayer *>(player)->updateReputation(true);
|
||||
//else
|
||||
// static_cast<LocalPlayer *>(player)->setReputation();
|
||||
static_cast<LocalPlayer *>(player)->updateReputation(true);
|
||||
}
|
||||
else if (player != 0)
|
||||
{
|
||||
MWWorld::Ptr ptrPlayer = static_cast<DedicatedPlayer *>(player)->getPtr();
|
||||
MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer);
|
||||
|
||||
ptrNpcStats->setReputation(player->npcStats.mReputation);
|
||||
static_cast<LocalPlayer *>(player)->setReputation();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,5 +12,5 @@ void PacketPlayerReputation::Packet(RakNet::BitStream *bs, bool send)
|
|||
{
|
||||
PlayerPacket::Packet(bs, send);
|
||||
|
||||
// Placeholder
|
||||
RW(player->npcStats.mReputation, send);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue