Add packet for player levels

coverity_scan^2
David Cernat 8 years ago
parent 3e2fec973d
commit 046a1ea899

@ -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<Script::CallbackIdentity("OnPlayerChangeLevel")>(player->GetID());
}
break;
}
case ID_GAME_UPDATE_EQUIPED:
{
DEBUG_PRINTF("ID_GAME_UPDATE_EQUIPED\n");

@ -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

@ -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;

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

@ -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);
}

@ -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);

@ -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)

@ -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

@ -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,

@ -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);
}

@ -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

@ -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<PacketCharGen>(&packets, peer);
AddPacket<PacketAttribute>(&packets, peer);
AddPacket<PacketSkill>(&packets, peer);
AddPacket<PacketLevel>(&packets, peer);
AddPacket<PacketHandshake>(&packets, peer);
AddPacket<PacketGUIBoxes>(&packets, peer);

Loading…
Cancel
Save