[General] Implement PlayerReputation packet

0.6.3
David Cernat 7 years ago
parent 88ae0772cf
commit 989f6e6b51

@ -79,6 +79,14 @@ void QuestFunctions::AddKill(unsigned short pid, const char* refId, int number)
player->killChanges.kills.push_back(kill); 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 const char *QuestFunctions::GetJournalItemQuest(unsigned short pid, unsigned int i) noexcept
{ {
Player *player; Player *player;
@ -133,6 +141,14 @@ int QuestFunctions::GetKillNumber(unsigned short pid, unsigned int i) noexcept
return player->killChanges.kills.at(i).number; 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 void QuestFunctions::SendJournalChanges(unsigned short pid, bool toOthers) noexcept
{ {
Player *player; 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)->setPlayer(player);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_KILL_COUNT)->Send(toOthers); 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},\ {"AddJournalIndex", QuestFunctions::AddJournalIndex},\
{"AddKill", QuestFunctions::AddKill},\ {"AddKill", QuestFunctions::AddKill},\
\ \
{"SetReputation", QuestFunctions::SetReputation},\
\
{"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\ {"GetJournalItemQuest", QuestFunctions::GetJournalItemQuest},\
{"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\ {"GetJournalItemIndex", QuestFunctions::GetJournalItemIndex},\
{"GetJournalItemType", QuestFunctions::GetJournalItemType},\ {"GetJournalItemType", QuestFunctions::GetJournalItemType},\
@ -19,8 +21,11 @@
{"GetKillRefId", QuestFunctions::GetKillRefId},\ {"GetKillRefId", QuestFunctions::GetKillRefId},\
{"GetKillNumber", QuestFunctions::GetKillNumber},\ {"GetKillNumber", QuestFunctions::GetKillNumber},\
\ \
{"GetReputation", QuestFunctions::GetReputation},\
\
{"SendJournalChanges", QuestFunctions::SendJournalChanges},\ {"SendJournalChanges", QuestFunctions::SendJournalChanges},\
{"SendKillChanges", QuestFunctions::SendKillChanges} {"SendKillChanges", QuestFunctions::SendKillChanges},\
{"SendReputation", QuestFunctions::SendReputation}
class QuestFunctions class QuestFunctions
{ {
@ -93,6 +98,15 @@ public:
*/ */
static void AddKill(unsigned short pid, const char* refId, int number) noexcept; 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. * \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; 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. * \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; 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: private:
}; };

@ -105,6 +105,7 @@ void LocalPlayer::update()
updateSkills(); updateSkills();
updateLevel(); updateLevel();
updateBounty(); 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) void LocalPlayer::updatePosition(bool forceUpdate)
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
@ -928,6 +942,15 @@ void LocalPlayer::setBounty()
ptrNpcStats->setBounty(npcStats.mBounty); 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() void LocalPlayer::setPosition()
{ {
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();

@ -30,6 +30,7 @@ namespace mwmp
void updateSkills(bool forceUpdate = false); void updateSkills(bool forceUpdate = false);
void updateLevel(bool forceUpdate = false); void updateLevel(bool forceUpdate = false);
void updateBounty(bool forceUpdate = false); void updateBounty(bool forceUpdate = false);
void updateReputation(bool forceUpdate = false);
void updatePosition(bool forceUpdate = false); void updatePosition(bool forceUpdate = false);
void updateCell(bool forceUpdate = false); void updateCell(bool forceUpdate = false);
void updateChar(); void updateChar();
@ -56,6 +57,7 @@ namespace mwmp
void setSkills(); void setSkills();
void setLevel(); void setLevel();
void setBounty(); void setBounty();
void setReputation();
void setPosition(); void setPosition();
void setCell(); void setCell();
void setClass(); void setClass();

@ -16,19 +16,13 @@ namespace mwmp
virtual void Do(PlayerPacket &packet, BasePlayer *player) virtual void Do(PlayerPacket &packet, BasePlayer *player)
{ {
if (isLocal()) if (isRequest())
{ {
//if (isRequest()) static_cast<LocalPlayer *>(player)->updateReputation(true);
// static_cast<LocalPlayer *>(player)->updateReputation(true);
//else
// static_cast<LocalPlayer *>(player)->setReputation();
} }
else if (player != 0) else if (player != 0)
{ {
MWWorld::Ptr ptrPlayer = static_cast<DedicatedPlayer *>(player)->getPtr(); static_cast<LocalPlayer *>(player)->setReputation();
MWMechanics::NpcStats *ptrNpcStats = &ptrPlayer.getClass().getNpcStats(ptrPlayer);
ptrNpcStats->setReputation(player->npcStats.mReputation);
} }
} }
}; };

@ -12,5 +12,5 @@ void PacketPlayerReputation::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
// Placeholder RW(player->npcStats.mReputation, send);
} }

Loading…
Cancel
Save