diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index d748fd68b..95dff9446 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -150,6 +150,22 @@ void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept player->CreatureStats()->mLevel = value; } +int StatsFunctions::GetLevelProgress(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->NpcStats()->mLevelProgress; +} + +void StatsFunctions::SetLevelProgress(unsigned short pid, int value) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->NpcStats()->mLevelProgress = value; +} + double StatsFunctions::GetHealthBase(unsigned short pid) noexcept { Player *player; diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index d456294c1..7a2668688 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -96,6 +96,8 @@ public: static int GetLevel(unsigned short pid) noexcept; static void SetLevel(unsigned short pid, int value) noexcept; + static int GetLevelProgress(unsigned short pid) noexcept; + static void SetLevelProgress(unsigned short pid, int value) noexcept; static double GetHealthBase(unsigned short pid) noexcept; static void SetHealthBase(unsigned short pid, double value) noexcept; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index c02e010b4..642f07e55 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -50,7 +50,9 @@ void LocalPlayer::Update() updateDeadState(); updateInventory(); updateDynamicStats(); - updateClassStats(); + updateAttributes(); + updateSkills(); + updateLevel(); } MWWorld::Ptr LocalPlayer::GetPlayerPtr() @@ -92,21 +94,40 @@ void LocalPlayer::updateDynamicStats(bool forceUpdate) } } -void LocalPlayer::updateClassStats(bool forceUpdate) +void LocalPlayer::updateAttributes(bool forceUpdate) { MWWorld::Ptr player = GetPlayerPtr(); + const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + bool isUpdating = false; + + for (int i = 0; i < 8; ++i) + { + if (ptrNpcStats.getAttribute(i).getBase() != CreatureStats()->mAttributes[i].mBase) + { + ptrNpcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]); + isUpdating = true; + } + } + if (isUpdating || forceUpdate) + { + GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this); + } +} + +void LocalPlayer::updateSkills(bool forceUpdate) +{ + MWWorld::Ptr player = GetPlayerPtr(); const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); + bool isUpdating = false; - bool isUpdatingSkills = false; - bool isUpdatingAttributes = false; for (int i = 0; i < 27; ++i) { if (ptrNpcStats.getSkill(i).getBase() != NpcStats()->mSkills[i].mBase) { ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]); - isUpdatingSkills = true; + isUpdating = true; } // If we only have skill progress, update the state for relevant skills // but don't send a packet just because of this (to avoid spam) @@ -116,30 +137,23 @@ void LocalPlayer::updateClassStats(bool forceUpdate) } } - for (int i = 0; i < 8; ++i) + if (isUpdating || forceUpdate) { - if (ptrNpcStats.getAttribute(i).getBase() != CreatureStats()->mAttributes[i].mBase) - { - ptrNpcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]); - isUpdatingAttributes = true; - } + NpcStats()->mLevelProgress = ptrNpcStats.getLevelProgress(); + GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); } +} + +void LocalPlayer::updateLevel(bool forceUpdate) +{ + MWWorld::Ptr player = GetPlayerPtr(); + const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); - if (ptrNpcStats.getLevel() != CreatureStats()->mLevel) + if (ptrNpcStats.getLevel() != CreatureStats()->mLevel || forceUpdate) { CreatureStats()->mLevel = ptrNpcStats.getLevel(); GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this); } - - if (isUpdatingSkills) - { - GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); - } - - if (isUpdatingAttributes) - { - GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this); - } } void LocalPlayer::updatePosition(bool forceUpdate) @@ -510,6 +524,9 @@ void LocalPlayer::updateCell(bool forceUpdate) RakNet::BitStream bs; GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true); GetNetworking()->SendData(&bs); + + // Also update skill progress + updateSkills(true); } } @@ -607,7 +624,9 @@ bool LocalPlayer::CharGenThread() // ToDo: need fix if (CharGenStage()->end != 1) { updateDynamicStats(true); - updateClassStats(true); + updateAttributes(true); + updateSkills(true); + updateLevel(true); SendClass(); GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); } diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 5e1e2527b..19a644006 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -25,7 +25,9 @@ namespace mwmp void updateInventory(bool forceUpdate = false); void updateAttackState(bool forceUpdate = false); void updateDeadState(bool forceUpdate = false); - void updateClassStats(bool forceUpdate = false); + void updateAttributes(bool forceUpdate = false); + void updateSkills(bool forceUpdate = false); + void updateLevel(bool forceUpdate = false); void updateCell(bool forceUpdate = false); void updateDrawStateAndFlags(bool forceUpdate = false); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index df8cb417c..41d95253c 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -480,7 +480,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) { if (packet->length == myPacket->headerSize()) { - getLocalPlayer()->updateClassStats(true); + getLocalPlayer()->updateAttributes(true); } else { @@ -510,7 +510,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) { if (packet->length == myPacket->headerSize()) { - getLocalPlayer()->updateClassStats(true); + getLocalPlayer()->updateSkills(true); } else { @@ -540,7 +540,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) { if (packet->length == myPacket->headerSize()) { - getLocalPlayer()->updateClassStats(true); + getLocalPlayer()->updateLevel(true); } else { diff --git a/components/openmw-mp/Packets/PacketSkill.cpp b/components/openmw-mp/Packets/PacketSkill.cpp index 662f8294b..829e59bfe 100644 --- a/components/openmw-mp/Packets/PacketSkill.cpp +++ b/components/openmw-mp/Packets/PacketSkill.cpp @@ -20,4 +20,6 @@ void PacketSkill::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) for (int i = 0; i < StatsCount; ++i) RW(player->NpcStats()->mSkills[i], send); + + RW(player->NpcStats()->mLevelProgress, send); }