diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 153f330b4..733ac8258 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -169,9 +169,19 @@ void Networking::Update(RakNet::Packet *packet) break; } - case ID_GAME_UPDATE_SKILLS: + case ID_GAME_ATTRIBUTE: + { + + if (!player->CreatureStats()->mDead) + { + myPacket->Read(player); + myPacket->Send(player, true); + } + + break; + } + case ID_GAME_SKILL: { - DEBUG_PRINTF("ID_GAME_UPDATE_SKILLS\n"); if (!player->CreatureStats()->mDead) { diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 35b81e653..14db9b527 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -50,6 +50,7 @@ void LocalPlayer::Update() updateDeadState(); updateInventory(); updateBaseStats(); + updateAttributesAndSkills(); } MWWorld::Ptr LocalPlayer::GetPlayerPtr() @@ -89,6 +90,40 @@ void LocalPlayer::updateBaseStats(bool forceUpdate) } } +void LocalPlayer::updateAttributesAndSkills(bool forceUpdate) +{ + MWWorld::Ptr player = GetPlayerPtr(); + + const MWMechanics::NpcStats &_npcStats = player.getClass().getNpcStats(player); + + bool isUpdatingSkills = false; + bool isUpdatingAttributes = false; + + for (int i = 0; i < 27; ++i) { + + if (_npcStats.getSkill(i).getBase() != NpcStats()->mSkills[i].mBase) { + _npcStats.getSkill(i).writeState(NpcStats()->mSkills[i]); + isUpdatingSkills = true; + } + } + + for (int i = 0; i < 8; ++i) { + + if (_npcStats.getAttribute(i).getBase() != CreatureStats()->mAttributes[i].mBase) { + _npcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]); + isUpdatingAttributes = true; + } + } + + if (isUpdatingSkills) { + GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); + } + + if (isUpdatingAttributes) { + GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this); + } +} + void LocalPlayer::updatePosition(bool forceUpdate) { MWBase::World *world = MWBase::Environment::get().getWorld(); @@ -276,19 +311,6 @@ void LocalPlayer::updateDeadState(bool forceUpdate) isDead = false; } -void LocalPlayer::updateAttributesAndSkills(bool forceUpdate) -{ - MWWorld::Ptr player = GetPlayerPtr(); - - const MWMechanics::NpcStats &_npcStats = player.getClass().getNpcStats(player); - - for (int i = 0; i < PacketAttributesAndStats::StatsCount; ++i) - _npcStats.getSkill(i).writeState( NpcStats()->mSkills[i]); - - for (int i = 0; i < PacketAttributesAndStats::AttributesCount; ++i) - _npcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]); -} - Networking *LocalPlayer::GetNetworking() { return mwmp::Main::get().getNetworking();