diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 5af775a7d..8b895f026 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -213,6 +213,19 @@ void Networking::Update(RakNet::Packet *packet) break; } + case ID_GAME_LEVEL: + { + + if (!player->CreatureStats()->mDead) + { + myPacket->Read(player); + myPacket->Send(player, true); + + Script::Call(player->GetID()); + } + + break; + } case ID_GAME_UPDATE_EQUIPED: { DEBUG_PRINTF("ID_GAME_UPDATE_EQUIPED\n"); diff --git a/apps/openmw-mp/Script/Functions/Stats.cpp b/apps/openmw-mp/Script/Functions/Stats.cpp index bced4b91f..d37b8a92a 100644 --- a/apps/openmw-mp/Script/Functions/Stats.cpp +++ b/apps/openmw-mp/Script/Functions/Stats.cpp @@ -96,7 +96,6 @@ const char *StatsFunctions::GetHead(unsigned short pid) noexcept Player *player; GET_PLAYER(pid, player, 0); - return player->Npc()->mHead.c_str(); } @@ -109,7 +108,6 @@ void StatsFunctions::SetHairstyle(unsigned short pid, const char *style) noexcep return; player->Npc()->mHair = style; - } const char *StatsFunctions::GetHairstyle(unsigned short pid) noexcept @@ -126,7 +124,6 @@ int StatsFunctions::GetIsMale(unsigned short pid) noexcept GET_PLAYER(pid, player,false); return player->Npc()->isMale(); - } void StatsFunctions::SetIsMale(unsigned short pid, int value) noexcept @@ -137,6 +134,21 @@ void StatsFunctions::SetIsMale(unsigned short pid, int value) noexcept player->Npc()->setIsMale(value == true); } +int StatsFunctions::GetLevel(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.f); + + return player->CreatureStats()->mLevel; +} + +void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->CreatureStats()->mLevel = value; +} float StatsFunctions::GetHealth(unsigned short pid) noexcept { @@ -144,7 +156,6 @@ float StatsFunctions::GetHealth(unsigned short pid) noexcept GET_PLAYER(pid, player,0.f); return player->CreatureStats()->mDynamic[0].mBase; - } void StatsFunctions::SetHealth(unsigned short pid, float value) noexcept @@ -209,7 +220,6 @@ float StatsFunctions::GetFatigue(unsigned short pid) noexcept GET_PLAYER(pid, player,0.f); return player->CreatureStats()->mDynamic[2].mBase; - } void StatsFunctions::SetFatigue(unsigned short pid, float value) noexcept @@ -338,7 +348,6 @@ void StatsFunctions::SetSkill(unsigned short pid, unsigned short skill, int valu player->NpcStats()->mSkills[skill].mBase = value; //DEBUG_PRINTF("SetSkill(%d, %d, %d)\n", pid, skill, value); - } int StatsFunctions::GetCurrentSkill(unsigned short pid, unsigned short skill) noexcept diff --git a/apps/openmw-mp/Script/Functions/Stats.hpp b/apps/openmw-mp/Script/Functions/Stats.hpp index 1ee21be4a..5e4d178a3 100644 --- a/apps/openmw-mp/Script/Functions/Stats.hpp +++ b/apps/openmw-mp/Script/Functions/Stats.hpp @@ -21,6 +21,9 @@ {"GetIsMale", StatsFunctions::GetIsMale},\ {"SetIsMale", StatsFunctions::SetIsMale},\ \ + {"GetLevel", StatsFunctions::GetLevel},\ + {"SetLevel", StatsFunctions::SetLevel},\ + \ {"GetBirthsign", StatsFunctions::GetBirthsign},\ {"SetBirthsign", StatsFunctions::SetBirthsign},\ \ @@ -86,20 +89,23 @@ public: static void SetIsMale(unsigned short pid, int male) noexcept; static int GetIsMale(unsigned short pid) noexcept; + static int GetLevel(unsigned short pid) noexcept; + static void SetLevel(unsigned short pid, int value) noexcept; + static float GetHealth(unsigned short pid) noexcept; - static void SetHealth(unsigned short pid, float health) noexcept; + static void SetHealth(unsigned short pid, float value) noexcept; static float GetCurrentHealth(unsigned short pid) noexcept; - static void SetCurrentHealth(unsigned short pid, float health) noexcept; + static void SetCurrentHealth(unsigned short pid, float value) noexcept; static float GetMagicka(unsigned short pid) noexcept; - static void SetMagicka(unsigned short pid, float magicka) noexcept; + static void SetMagicka(unsigned short pid, float value) noexcept; static float GetCurrentMagicka(unsigned short pid) noexcept; - static void SetCurrentMagicka(unsigned short pid, float magicka) noexcept; + static void SetCurrentMagicka(unsigned short pid, float value) noexcept; static float GetFatigue(unsigned short pid) noexcept; - static void SetFatigue(unsigned short pid, float fatigue) noexcept; + static void SetFatigue(unsigned short pid, float value) noexcept; static float GetCurrentFatigue(unsigned short pid) noexcept; - static void SetCurrentFatigue(unsigned short pid, float fatigue) noexcept; + static void SetCurrentFatigue(unsigned short pid, float value) noexcept; static int GetAttributeId(const char *name) noexcept; static int GetSkillId(const char *name) noexcept; diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index 643bc1f63..796139c99 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -93,20 +93,21 @@ public: }; static constexpr ScriptCallbackData callbacks[]{ - {"Main", Function()}, - {"OnServerInit", Function()}, - {"OnServerExit", Function()}, - {"OnPlayerConnect", Function()}, - {"OnPlayerDisconnect", Function()}, - {"OnPlayerDeath", Function()}, - {"OnPlayerResurrect", Function()}, - {"OnPlayerChangeCell", Function()}, + {"Main", Function()}, + {"OnServerInit", Function()}, + {"OnServerExit", Function()}, + {"OnPlayerConnect", Function()}, + {"OnPlayerDisconnect", Function()}, + {"OnPlayerDeath", Function()}, + {"OnPlayerResurrect", Function()}, + {"OnPlayerChangeCell", Function()}, {"OnPlayerChangeAttributes", Function()}, - {"OnPlayerChangeSkills", Function()}, - {"OnPlayerUpdateEquiped", Function()}, - {"OnPlayerSendMessage", Function()}, - {"OnPlayerEndCharGen", Function()}, - {"OnGUIAction", Function()} + {"OnPlayerChangeSkills", Function()}, + {"OnPlayerChangeLevel", Function()}, + {"OnPlayerUpdateEquiped", Function()}, + {"OnPlayerSendMessage", Function()}, + {"OnPlayerEndCharGen", Function()}, + {"OnGUIAction", Function()} }; }; diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 44ba11c0d..95a7c9ce6 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -50,7 +50,7 @@ void LocalPlayer::Update() updateDeadState(); updateInventory(); updateBaseStats(); - updateAttributesAndSkills(); + updateClassStats(); } MWWorld::Ptr LocalPlayer::GetPlayerPtr() @@ -90,7 +90,7 @@ void LocalPlayer::updateBaseStats(bool forceUpdate) } } -void LocalPlayer::updateAttributesAndSkills(bool forceUpdate) +void LocalPlayer::updateClassStats(bool forceUpdate) { MWWorld::Ptr player = GetPlayerPtr(); @@ -115,6 +115,9 @@ void LocalPlayer::updateAttributesAndSkills(bool forceUpdate) } } + if (_npcStats.getLevel() != CreatureStats()->mLevel) + GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this); + if (isUpdatingSkills) { GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); } @@ -536,7 +539,7 @@ bool LocalPlayer::CharGenThread() // ToDo: need fix if (CharGenStage()->end != 1) { updateBaseStats(true); - updateAttributesAndSkills(true); + updateClassStats(true); SendClass(); GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); } diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 9d8f7953c..0c7bb15d9 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -25,7 +25,7 @@ namespace mwmp void updateInventory(bool forceUpdate = false); void updateAttackState(bool forceUpdate = false); void updateDeadState(bool forceUpdate = false); - void updateAttributesAndSkills(bool forceUpdate = false); + void updateClassStats(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 a3692e4d2..1dca90bdb 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -468,6 +468,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) case ID_GAME_ATTRIBUTE: { + // Ignore requests for this packet if (packet->length == myPacket->headerSize()) return; @@ -486,10 +487,10 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) else return; - MWMechanics::AttributeValue attributeValue; - myPacket->Packet(&bsIn, __pl, false); + MWMechanics::AttributeValue attributeValue; + for (int i = 0; i < 8; ++i) { attributeValue.readState(__pl->CreatureStats()->mAttributes[i]); @@ -500,6 +501,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) case ID_GAME_SKILL: { + // Ignore requests for this packet if (packet->length == myPacket->headerSize()) return; @@ -518,10 +520,10 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) else return; - MWMechanics::SkillValue skillValue; - myPacket->Packet(&bsIn, __pl, false); + MWMechanics::SkillValue skillValue; + for (int i = 0; i < 27; ++i) { skillValue.readState(__pl->NpcStats()->mSkills[i]); @@ -531,6 +533,35 @@ void Networking::ReceiveMessage(RakNet::Packet *packet) break; } + + case ID_GAME_LEVEL: + { + // Ignore requests for this packet + if (packet->length == myPacket->headerSize()) + return; + + BasePlayer *__pl = nullptr; + MWWorld::Ptr __pl_ptr; + if (id == myid) + { + __pl = getLocalPlayer(); + __pl_ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); + } + else if (pl != 0) + { + __pl = pl; + __pl_ptr = pl->getPtr(); + } + else + return; + + myPacket->Packet(&bsIn, __pl, false); + + __pl_ptr.getClass().getCreatureStats(__pl_ptr).setLevel(__pl->CreatureStats()->mLevel); + + break; + } + case ID_GUI_MESSAGEBOX: { if (id == myid) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 76b397c6c..d6addc297 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -150,8 +150,8 @@ add_component_dir (openmw-mp PacketsController Packets/BasePacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquiped Packets/PacketAttack Packets/PacketMainStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage Packets/PacketCharGen - Packets/PacketAttribute Packets/PacketSkill Packets/PacketHandshake Packets/PacketGUIBoxes Packets/PacketClass - Packets/PacketTime) + Packets/PacketAttribute Packets/PacketSkill Packets/PacketLevel Packets/PacketHandshake Packets/PacketGUIBoxes + Packets/PacketClass Packets/PacketTime) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 08832a176..be7f90dd5 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -28,6 +28,7 @@ enum GameMessages ID_GAME_STATS, ID_GAME_ATTRIBUTE, ID_GAME_SKILL, + ID_GAME_LEVEL, ID_GAME_CHARCLASS, ID_GAME_SKILLPRIORITY, ID_HANDSHAKE, diff --git a/components/openmw-mp/Packets/PacketLevel.cpp b/components/openmw-mp/Packets/PacketLevel.cpp new file mode 100644 index 000000000..9a614039e --- /dev/null +++ b/components/openmw-mp/Packets/PacketLevel.cpp @@ -0,0 +1,20 @@ +// +// Created by David Cernat on 25.09.16. +// + +#include "PacketLevel.hpp" +#include + +using namespace mwmp; + +PacketLevel::PacketLevel(RakNet::RakPeerInterface *peer) : BasePacket(peer) +{ + packetID = ID_GAME_LEVEL; +} + +void PacketLevel::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send) +{ + BasePacket::Packet(bs, player, send); + + RW(player->CreatureStats()->mLevel, send); +} diff --git a/components/openmw-mp/Packets/PacketLevel.hpp b/components/openmw-mp/Packets/PacketLevel.hpp new file mode 100644 index 000000000..e424bd61e --- /dev/null +++ b/components/openmw-mp/Packets/PacketLevel.hpp @@ -0,0 +1,21 @@ +// +// Created by David Cernat on 25.09.16. +// + +#ifndef OPENMW_PACKETLEVEL_HPP +#define OPENMW_PACKETLEVEL_HPP + +#include + +namespace mwmp +{ + class PacketLevel : public BasePacket + { + public: + PacketLevel(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send); + }; +} + +#endif //OPENMW_PACKETLEVEL_HPP diff --git a/components/openmw-mp/PacketsController.cpp b/components/openmw-mp/PacketsController.cpp index 84f3e0315..09afcaff2 100644 --- a/components/openmw-mp/PacketsController.cpp +++ b/components/openmw-mp/PacketsController.cpp @@ -22,6 +22,7 @@ #include "Packets/PacketCharGen.hpp" #include "Packets/PacketAttribute.hpp" #include "Packets/PacketSkill.hpp" +#include "Packets/PacketLevel.hpp" #include "Packets/PacketHandshake.hpp" #include "Packets/PacketGUIBoxes.hpp" #include "Packets/PacketTime.hpp" @@ -57,6 +58,7 @@ mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer) AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); AddPacket(&packets, peer);