1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-06 09:15:32 +00:00

Add packet for player levels

This commit is contained in:
David Cernat 2016-09-25 14:28:25 +03:00
parent 3e2fec973d
commit 046a1ea899
12 changed files with 142 additions and 35 deletions

View file

@ -213,6 +213,19 @@ void Networking::Update(RakNet::Packet *packet)
break; break;
} }
case ID_GAME_LEVEL:
{
if (!player->CreatureStats()->mDead)
{
myPacket->Read(player);
myPacket->Send(player, true);
Script::Call<Script::CallbackIdentity("OnPlayerChangeLevel")>(player->GetID());
}
break;
}
case ID_GAME_UPDATE_EQUIPED: case ID_GAME_UPDATE_EQUIPED:
{ {
DEBUG_PRINTF("ID_GAME_UPDATE_EQUIPED\n"); DEBUG_PRINTF("ID_GAME_UPDATE_EQUIPED\n");

View file

@ -96,7 +96,6 @@ const char *StatsFunctions::GetHead(unsigned short pid) noexcept
Player *player; Player *player;
GET_PLAYER(pid, player, 0); GET_PLAYER(pid, player, 0);
return player->Npc()->mHead.c_str(); return player->Npc()->mHead.c_str();
} }
@ -109,7 +108,6 @@ void StatsFunctions::SetHairstyle(unsigned short pid, const char *style) noexcep
return; return;
player->Npc()->mHair = style; player->Npc()->mHair = style;
} }
const char *StatsFunctions::GetHairstyle(unsigned short pid) noexcept const char *StatsFunctions::GetHairstyle(unsigned short pid) noexcept
@ -126,7 +124,6 @@ int StatsFunctions::GetIsMale(unsigned short pid) noexcept
GET_PLAYER(pid, player,false); GET_PLAYER(pid, player,false);
return player->Npc()->isMale(); return player->Npc()->isMale();
} }
void StatsFunctions::SetIsMale(unsigned short pid, int value) noexcept 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); 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 float StatsFunctions::GetHealth(unsigned short pid) noexcept
{ {
@ -144,7 +156,6 @@ float StatsFunctions::GetHealth(unsigned short pid) noexcept
GET_PLAYER(pid, player,0.f); GET_PLAYER(pid, player,0.f);
return player->CreatureStats()->mDynamic[0].mBase; return player->CreatureStats()->mDynamic[0].mBase;
} }
void StatsFunctions::SetHealth(unsigned short pid, float value) noexcept 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); GET_PLAYER(pid, player,0.f);
return player->CreatureStats()->mDynamic[2].mBase; return player->CreatureStats()->mDynamic[2].mBase;
} }
void StatsFunctions::SetFatigue(unsigned short pid, float value) noexcept 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; player->NpcStats()->mSkills[skill].mBase = value;
//DEBUG_PRINTF("SetSkill(%d, %d, %d)\n", pid, skill, value); //DEBUG_PRINTF("SetSkill(%d, %d, %d)\n", pid, skill, value);
} }
int StatsFunctions::GetCurrentSkill(unsigned short pid, unsigned short skill) noexcept int StatsFunctions::GetCurrentSkill(unsigned short pid, unsigned short skill) noexcept

View file

@ -21,6 +21,9 @@
{"GetIsMale", StatsFunctions::GetIsMale},\ {"GetIsMale", StatsFunctions::GetIsMale},\
{"SetIsMale", StatsFunctions::SetIsMale},\ {"SetIsMale", StatsFunctions::SetIsMale},\
\ \
{"GetLevel", StatsFunctions::GetLevel},\
{"SetLevel", StatsFunctions::SetLevel},\
\
{"GetBirthsign", StatsFunctions::GetBirthsign},\ {"GetBirthsign", StatsFunctions::GetBirthsign},\
{"SetBirthsign", StatsFunctions::SetBirthsign},\ {"SetBirthsign", StatsFunctions::SetBirthsign},\
\ \
@ -86,20 +89,23 @@ public:
static void SetIsMale(unsigned short pid, int male) noexcept; static void SetIsMale(unsigned short pid, int male) noexcept;
static int GetIsMale(unsigned short pid) 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 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 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 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 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 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 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 GetAttributeId(const char *name) noexcept;
static int GetSkillId(const char *name) noexcept; static int GetSkillId(const char *name) noexcept;

View file

@ -93,20 +93,21 @@ public:
}; };
static constexpr ScriptCallbackData callbacks[]{ static constexpr ScriptCallbackData callbacks[]{
{"Main", Function<int, int, int>()}, {"Main", Function<int, int, int>()},
{"OnServerInit", Function<void>()}, {"OnServerInit", Function<void>()},
{"OnServerExit", Function<void, bool>()}, {"OnServerExit", Function<void, bool>()},
{"OnPlayerConnect", Function<bool, unsigned short>()}, {"OnPlayerConnect", Function<bool, unsigned short>()},
{"OnPlayerDisconnect", Function<void, unsigned short>()}, {"OnPlayerDisconnect", Function<void, unsigned short>()},
{"OnPlayerDeath", Function<void, unsigned short>()}, {"OnPlayerDeath", Function<void, unsigned short>()},
{"OnPlayerResurrect", Function<void, unsigned short>()}, {"OnPlayerResurrect", Function<void, unsigned short>()},
{"OnPlayerChangeCell", Function<void, unsigned short>()}, {"OnPlayerChangeCell", Function<void, unsigned short>()},
{"OnPlayerChangeAttributes", Function<void, unsigned short>()}, {"OnPlayerChangeAttributes", Function<void, unsigned short>()},
{"OnPlayerChangeSkills", Function<void, unsigned short>()}, {"OnPlayerChangeSkills", Function<void, unsigned short>()},
{"OnPlayerUpdateEquiped", Function<void, unsigned short>()}, {"OnPlayerChangeLevel", Function<void, unsigned short>()},
{"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()}, {"OnPlayerUpdateEquiped", Function<void, unsigned short>()},
{"OnPlayerEndCharGen", Function<void, unsigned short>()}, {"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()},
{"OnGUIAction", Function<void, unsigned short, int, const char*>()} {"OnPlayerEndCharGen", Function<void, unsigned short>()},
{"OnGUIAction", Function<void, unsigned short, int, const char*>()}
}; };
}; };

View file

@ -50,7 +50,7 @@ void LocalPlayer::Update()
updateDeadState(); updateDeadState();
updateInventory(); updateInventory();
updateBaseStats(); updateBaseStats();
updateAttributesAndSkills(); updateClassStats();
} }
MWWorld::Ptr LocalPlayer::GetPlayerPtr() 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(); 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) { if (isUpdatingSkills) {
GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this); GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this);
} }
@ -536,7 +539,7 @@ bool LocalPlayer::CharGenThread() // ToDo: need fix
if (CharGenStage()->end != 1) if (CharGenStage()->end != 1)
{ {
updateBaseStats(true); updateBaseStats(true);
updateAttributesAndSkills(true); updateClassStats(true);
SendClass(); SendClass();
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
} }

View file

@ -25,7 +25,7 @@ namespace mwmp
void updateInventory(bool forceUpdate = false); void updateInventory(bool forceUpdate = false);
void updateAttackState(bool forceUpdate = false); void updateAttackState(bool forceUpdate = false);
void updateDeadState(bool forceUpdate = false); void updateDeadState(bool forceUpdate = false);
void updateAttributesAndSkills(bool forceUpdate = false); void updateClassStats(bool forceUpdate = false);
void updateCell(bool forceUpdate = false); void updateCell(bool forceUpdate = false);
void updateDrawStateAndFlags(bool forceUpdate = false); void updateDrawStateAndFlags(bool forceUpdate = false);

View file

@ -468,6 +468,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
case ID_GAME_ATTRIBUTE: case ID_GAME_ATTRIBUTE:
{ {
// Ignore requests for this packet
if (packet->length == myPacket->headerSize()) if (packet->length == myPacket->headerSize())
return; return;
@ -486,10 +487,10 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
else else
return; return;
MWMechanics::AttributeValue attributeValue;
myPacket->Packet(&bsIn, __pl, false); myPacket->Packet(&bsIn, __pl, false);
MWMechanics::AttributeValue attributeValue;
for (int i = 0; i < 8; ++i) for (int i = 0; i < 8; ++i)
{ {
attributeValue.readState(__pl->CreatureStats()->mAttributes[i]); attributeValue.readState(__pl->CreatureStats()->mAttributes[i]);
@ -500,6 +501,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
case ID_GAME_SKILL: case ID_GAME_SKILL:
{ {
// Ignore requests for this packet
if (packet->length == myPacket->headerSize()) if (packet->length == myPacket->headerSize())
return; return;
@ -518,10 +520,10 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
else else
return; return;
MWMechanics::SkillValue skillValue;
myPacket->Packet(&bsIn, __pl, false); myPacket->Packet(&bsIn, __pl, false);
MWMechanics::SkillValue skillValue;
for (int i = 0; i < 27; ++i) for (int i = 0; i < 27; ++i)
{ {
skillValue.readState(__pl->NpcStats()->mSkills[i]); skillValue.readState(__pl->NpcStats()->mSkills[i]);
@ -531,6 +533,35 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
break; 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: case ID_GUI_MESSAGEBOX:
{ {
if (id == myid) if (id == myid)

View file

@ -150,8 +150,8 @@ add_component_dir (openmw-mp
PacketsController PacketsController
Packets/BasePacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquiped Packets/PacketAttack Packets/BasePacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquiped Packets/PacketAttack
Packets/PacketMainStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage Packets/PacketCharGen Packets/PacketMainStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage Packets/PacketCharGen
Packets/PacketAttribute Packets/PacketSkill Packets/PacketHandshake Packets/PacketGUIBoxes Packets/PacketClass Packets/PacketAttribute Packets/PacketSkill Packets/PacketLevel Packets/PacketHandshake Packets/PacketGUIBoxes
Packets/PacketTime) Packets/PacketClass Packets/PacketTime)
add_component_dir (fallback add_component_dir (fallback
fallback validate fallback validate

View file

@ -28,6 +28,7 @@ enum GameMessages
ID_GAME_STATS, ID_GAME_STATS,
ID_GAME_ATTRIBUTE, ID_GAME_ATTRIBUTE,
ID_GAME_SKILL, ID_GAME_SKILL,
ID_GAME_LEVEL,
ID_GAME_CHARCLASS, ID_GAME_CHARCLASS,
ID_GAME_SKILLPRIORITY, ID_GAME_SKILLPRIORITY,
ID_HANDSHAKE, ID_HANDSHAKE,

View file

@ -0,0 +1,20 @@
//
// Created by David Cernat on 25.09.16.
//
#include "PacketLevel.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
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);
}

View file

@ -0,0 +1,21 @@
//
// Created by David Cernat on 25.09.16.
//
#ifndef OPENMW_PACKETLEVEL_HPP
#define OPENMW_PACKETLEVEL_HPP
#include <components/openmw-mp/Packets/BasePacket.hpp>
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

View file

@ -22,6 +22,7 @@
#include "Packets/PacketCharGen.hpp" #include "Packets/PacketCharGen.hpp"
#include "Packets/PacketAttribute.hpp" #include "Packets/PacketAttribute.hpp"
#include "Packets/PacketSkill.hpp" #include "Packets/PacketSkill.hpp"
#include "Packets/PacketLevel.hpp"
#include "Packets/PacketHandshake.hpp" #include "Packets/PacketHandshake.hpp"
#include "Packets/PacketGUIBoxes.hpp" #include "Packets/PacketGUIBoxes.hpp"
#include "Packets/PacketTime.hpp" #include "Packets/PacketTime.hpp"
@ -57,6 +58,7 @@ mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer)
AddPacket<PacketCharGen>(&packets, peer); AddPacket<PacketCharGen>(&packets, peer);
AddPacket<PacketAttribute>(&packets, peer); AddPacket<PacketAttribute>(&packets, peer);
AddPacket<PacketSkill>(&packets, peer); AddPacket<PacketSkill>(&packets, peer);
AddPacket<PacketLevel>(&packets, peer);
AddPacket<PacketHandshake>(&packets, peer); AddPacket<PacketHandshake>(&packets, peer);
AddPacket<PacketGUIBoxes>(&packets, peer); AddPacket<PacketGUIBoxes>(&packets, peer);