From 6650b7449809a448e593dba8c62f7252c0ee1794 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 30 Sep 2016 07:15:59 +0300 Subject: [PATCH] Add handling of skill increases --- apps/openmw-mp/Script/Functions/Stats.cpp | 12 ++++++------ apps/openmw/mwmp/LocalPlayer.cpp | 12 ++++++++++++ components/openmw-mp/Packets/PacketAttribute.cpp | 2 +- components/openmw-mp/Packets/PacketAttribute.hpp | 2 +- components/openmw-mp/Packets/PacketSkill.cpp | 5 ++++- components/openmw-mp/Packets/PacketSkill.hpp | 3 ++- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index 95dff9446..7a7131f5d 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -424,26 +424,26 @@ void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skill, player->NpcStats()->mSkills[skill].mProgress = value; } -int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int pos) noexcept +int StatsFunctions::GetSkillIncrease(unsigned short pid, unsigned int attribute) noexcept { Player *player; GET_PLAYER(pid, player, 0); - if (pos > 7) + if (attribute > Attribute::Length) return 0; - return player->NpcStats()->mSkillIncrease[pos]; + return player->NpcStats()->mSkillIncrease[attribute]; } -void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int pos, int value) noexcept // TODO: need packet for transmit it +void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute, int value) noexcept // TODO: need packet for transmit it { Player *player; GET_PLAYER(pid, player,); - if (pos > 7) + if (attribute > Attribute::Length) return; - player->NpcStats()->mSkillIncrease[pos] = value; + player->NpcStats()->mSkillIncrease[attribute] = value; } void StatsFunctions::SetCharGenStage(unsigned short pid, int start, int end) noexcept diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 7781f9323..4644f5f3d 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -134,6 +134,13 @@ void LocalPlayer::updateSkills(bool forceUpdate) else if (ptrNpcStats.getSkill(i).getProgress() != NpcStats()->mSkills[i].mProgress) { ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]); + } + } + + for (int i = 0; i < 8; i++) + { + if (ptrNpcStats.getSkillIncrease(i) != NpcStats()->mSkillIncrease[i]) { + NpcStats()->mSkillIncrease[i] = ptrNpcStats.getSkillIncrease(i); } } @@ -301,6 +308,11 @@ void LocalPlayer::setSkills() ptrNpcStats->setSkill(i, skillValue); } + for (int i = 0; i < 8; ++i) + { + ptrNpcStats->setSkillIncrease(i, NpcStats()->mSkillIncrease[i]); + } + ptrNpcStats->setLevelProgress(NpcStats()->mLevelProgress); } diff --git a/components/openmw-mp/Packets/PacketAttribute.cpp b/components/openmw-mp/Packets/PacketAttribute.cpp index 9fccf3279..7a82359da 100644 --- a/components/openmw-mp/Packets/PacketAttribute.cpp +++ b/components/openmw-mp/Packets/PacketAttribute.cpp @@ -16,6 +16,6 @@ void PacketAttribute::Packet(RakNet::BitStream *bs, BasePlayer *player, bool sen { BasePacket::Packet(bs, player, send); - for (int i = 0; i < AttributesCount; ++i) + for (int i = 0; i < AttributeCount; ++i) RW(player->CreatureStats()->mAttributes[i], send); } diff --git a/components/openmw-mp/Packets/PacketAttribute.hpp b/components/openmw-mp/Packets/PacketAttribute.hpp index 407127b0f..b50f49588 100644 --- a/components/openmw-mp/Packets/PacketAttribute.hpp +++ b/components/openmw-mp/Packets/PacketAttribute.hpp @@ -12,7 +12,7 @@ namespace mwmp class PacketAttribute : public BasePacket { public: - const static int AttributesCount = 8; + const static int AttributeCount = 8; PacketAttribute(RakNet::RakPeerInterface *peer); virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); diff --git a/components/openmw-mp/Packets/PacketSkill.cpp b/components/openmw-mp/Packets/PacketSkill.cpp index 829e59bfe..f4ff175de 100644 --- a/components/openmw-mp/Packets/PacketSkill.cpp +++ b/components/openmw-mp/Packets/PacketSkill.cpp @@ -18,8 +18,11 @@ void PacketSkill::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) { BasePacket::Packet(bs, player, send); - for (int i = 0; i < StatsCount; ++i) + for (int i = 0; i < SkillCount; ++i) RW(player->NpcStats()->mSkills[i], send); + for (int i = 0; i < AttributeCount; ++i) + RW(player->NpcStats()->mSkillIncrease[i], send); + RW(player->NpcStats()->mLevelProgress, send); } diff --git a/components/openmw-mp/Packets/PacketSkill.hpp b/components/openmw-mp/Packets/PacketSkill.hpp index 6b7831580..ebf684104 100644 --- a/components/openmw-mp/Packets/PacketSkill.hpp +++ b/components/openmw-mp/Packets/PacketSkill.hpp @@ -13,7 +13,8 @@ namespace mwmp class PacketSkill : public BasePacket { public: - const static int StatsCount = 27; + const static int SkillCount = 27; + const static int AttributeCount = 8; PacketSkill(RakNet::RakPeerInterface *peer); virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send);