diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 2518ed11d..5195044e6 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -357,6 +357,9 @@ void StatsFunctions::SetHealthBase(unsigned short pid, double value) noexcept GET_PLAYER(pid, player,); player->creatureStats.mDynamic[0].mBase = value; + + if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 0)) + player->skillIndexChanges.push_back(0); } void StatsFunctions::SetHealthCurrent(unsigned short pid, double value) noexcept @@ -365,6 +368,9 @@ void StatsFunctions::SetHealthCurrent(unsigned short pid, double value) noexcept GET_PLAYER(pid, player,); player->creatureStats.mDynamic[0].mCurrent = value; + + if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 0)) + player->skillIndexChanges.push_back(0); } void StatsFunctions::SetMagickaBase(unsigned short pid, double value) noexcept @@ -373,6 +379,9 @@ void StatsFunctions::SetMagickaBase(unsigned short pid, double value) noexcept GET_PLAYER(pid, player,); player->creatureStats.mDynamic[1].mBase = value; + + if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 1)) + player->skillIndexChanges.push_back(1); } void StatsFunctions::SetMagickaCurrent(unsigned short pid, double value) noexcept @@ -381,6 +390,9 @@ void StatsFunctions::SetMagickaCurrent(unsigned short pid, double value) noexcep GET_PLAYER(pid, player,); player->creatureStats.mDynamic[1].mCurrent = value; + + if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 1)) + player->skillIndexChanges.push_back(1); } void StatsFunctions::SetFatigueBase(unsigned short pid, double value) noexcept @@ -389,6 +401,9 @@ void StatsFunctions::SetFatigueBase(unsigned short pid, double value) noexcept GET_PLAYER(pid, player,); player->creatureStats.mDynamic[2].mBase = value; + + if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 2)) + player->skillIndexChanges.push_back(2); } void StatsFunctions::SetFatigueCurrent(unsigned short pid, double value) noexcept @@ -397,6 +412,9 @@ void StatsFunctions::SetFatigueCurrent(unsigned short pid, double value) noexcep GET_PLAYER(pid, player,); player->creatureStats.mDynamic[2].mCurrent = value; + + if (!Utils::vectorContains(&player->statsDynamicIndexChanges, 2)) + player->skillIndexChanges.push_back(2); } void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attributeId, int value) noexcept @@ -522,6 +540,8 @@ void StatsFunctions::SendStatsDynamic(unsigned short pid) noexcept mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(player); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(true); + + player->statsDynamicIndexChanges.clear(); } void StatsFunctions::SendAttributes(unsigned short pid) noexcept diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 1dc50d1dd..98ec6bc0b 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -212,8 +212,16 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate) || abs(oldVal.getCurrent() - newVal.getCurrent()) >= limit); }; - if (forceUpdate || needUpdate(oldHealth, health, 3) || needUpdate(oldMagicka, magicka, 7) || - needUpdate(oldFatigue, fatigue, 7)) + if (needUpdate(oldHealth, health, 2)) + statsDynamicIndexChanges.push_back(0); + + if (needUpdate(oldMagicka, magicka, 4)) + statsDynamicIndexChanges.push_back(1); + + if (needUpdate(oldFatigue, fatigue, 4)) + statsDynamicIndexChanges.push_back(2); + + if (statsDynamicIndexChanges.size() > 0 || forceUpdate) { oldHealth = health; oldMagicka = magicka; @@ -225,6 +233,7 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate) getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(); + statsDynamicIndexChanges.clear(); } } diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 219d8e76f..569e6d79c 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -251,6 +251,10 @@ namespace mwmp // with the skill values themselves being stored in npcStats.mSkills std::vector skillIndexChanges; + // Track only the indexes of the dynamic states that have been changed, + // with the dynamicStats themselves being stored in creatureStats.mDynamic + std::vector statsDynamicIndexChanges; + // Track only the indexes of the equipment items that have been changed, // with the items themselves being stored in equipmentItems std::vector equipmentIndexChanges; diff --git a/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp b/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp index 97b1c5846..97b1fe589 100644 --- a/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp +++ b/components/openmw-mp/Packets/Player/PacketPlayerStatsDynamic.cpp @@ -1,7 +1,3 @@ -// -// Created by koncord on 13.01.16. -// - #include "PacketPlayerStatsDynamic.hpp" #include @@ -15,5 +11,23 @@ PacketPlayerStatsDynamic::PacketPlayerStatsDynamic(RakNet::RakPeerInterface *pee void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send) { PlayerPacket::Packet(bs, send); - RW(player->creatureStats.mDynamic, send); + + uint32_t count; + if (send) + count = static_cast(player->statsDynamicIndexChanges.size()); + + RW(count, send); + + if (!send) + { + player->statsDynamicIndexChanges.clear(); + player->statsDynamicIndexChanges.resize(count); + } + + for (auto &&statsDynamicIndex : player->statsDynamicIndexChanges) + { + RW(statsDynamicIndex, send); + + RW(player->creatureStats.mDynamic[statsDynamicIndex], send); + } }