1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 21:19:40 +00:00

Split updateClassStats in 3 and add handling of level progress

This commit is contained in:
David Cernat 2016-09-30 04:52:21 +03:00
parent 2ab619b0e3
commit a0e9a672a5
6 changed files with 69 additions and 28 deletions

View file

@ -150,6 +150,22 @@ void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept
player->CreatureStats()->mLevel = value; player->CreatureStats()->mLevel = value;
} }
int StatsFunctions::GetLevelProgress(unsigned short pid) noexcept
{
Player *player;
GET_PLAYER(pid, player, 0.0f);
return player->NpcStats()->mLevelProgress;
}
void StatsFunctions::SetLevelProgress(unsigned short pid, int value) noexcept
{
Player *player;
GET_PLAYER(pid, player, );
player->NpcStats()->mLevelProgress = value;
}
double StatsFunctions::GetHealthBase(unsigned short pid) noexcept double StatsFunctions::GetHealthBase(unsigned short pid) noexcept
{ {
Player *player; Player *player;

View file

@ -96,6 +96,8 @@ public:
static int GetLevel(unsigned short pid) noexcept; static int GetLevel(unsigned short pid) noexcept;
static void SetLevel(unsigned short pid, int value) noexcept; static void SetLevel(unsigned short pid, int value) noexcept;
static int GetLevelProgress(unsigned short pid) noexcept;
static void SetLevelProgress(unsigned short pid, int value) noexcept;
static double GetHealthBase(unsigned short pid) noexcept; static double GetHealthBase(unsigned short pid) noexcept;
static void SetHealthBase(unsigned short pid, double value) noexcept; static void SetHealthBase(unsigned short pid, double value) noexcept;

View file

@ -50,7 +50,9 @@ void LocalPlayer::Update()
updateDeadState(); updateDeadState();
updateInventory(); updateInventory();
updateDynamicStats(); updateDynamicStats();
updateClassStats(); updateAttributes();
updateSkills();
updateLevel();
} }
MWWorld::Ptr LocalPlayer::GetPlayerPtr() MWWorld::Ptr LocalPlayer::GetPlayerPtr()
@ -92,21 +94,40 @@ void LocalPlayer::updateDynamicStats(bool forceUpdate)
} }
} }
void LocalPlayer::updateClassStats(bool forceUpdate) void LocalPlayer::updateAttributes(bool forceUpdate)
{ {
MWWorld::Ptr player = GetPlayerPtr(); MWWorld::Ptr player = GetPlayerPtr();
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player); const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
bool isUpdating = false;
for (int i = 0; i < 8; ++i)
{
if (ptrNpcStats.getAttribute(i).getBase() != CreatureStats()->mAttributes[i].mBase)
{
ptrNpcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]);
isUpdating = true;
}
}
if (isUpdating || forceUpdate)
{
GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this);
}
}
void LocalPlayer::updateSkills(bool forceUpdate)
{
MWWorld::Ptr player = GetPlayerPtr();
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
bool isUpdating = false;
bool isUpdatingSkills = false;
bool isUpdatingAttributes = false;
for (int i = 0; i < 27; ++i) for (int i = 0; i < 27; ++i)
{ {
if (ptrNpcStats.getSkill(i).getBase() != NpcStats()->mSkills[i].mBase) if (ptrNpcStats.getSkill(i).getBase() != NpcStats()->mSkills[i].mBase)
{ {
ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]); ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
isUpdatingSkills = true; isUpdating = true;
} }
// If we only have skill progress, update the state for relevant skills // If we only have skill progress, update the state for relevant skills
// but don't send a packet just because of this (to avoid spam) // but don't send a packet just because of this (to avoid spam)
@ -116,30 +137,23 @@ void LocalPlayer::updateClassStats(bool forceUpdate)
} }
} }
for (int i = 0; i < 8; ++i) if (isUpdating || forceUpdate)
{ {
if (ptrNpcStats.getAttribute(i).getBase() != CreatureStats()->mAttributes[i].mBase) NpcStats()->mLevelProgress = ptrNpcStats.getLevelProgress();
{ GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this);
ptrNpcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]);
isUpdatingAttributes = true;
}
} }
}
if (ptrNpcStats.getLevel() != CreatureStats()->mLevel) void LocalPlayer::updateLevel(bool forceUpdate)
{
MWWorld::Ptr player = GetPlayerPtr();
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
if (ptrNpcStats.getLevel() != CreatureStats()->mLevel || forceUpdate)
{ {
CreatureStats()->mLevel = ptrNpcStats.getLevel(); CreatureStats()->mLevel = ptrNpcStats.getLevel();
GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this); GetNetworking()->GetPacket(ID_GAME_LEVEL)->Send(this);
} }
if (isUpdatingSkills)
{
GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this);
}
if (isUpdatingAttributes)
{
GetNetworking()->GetPacket(ID_GAME_ATTRIBUTE)->Send(this);
}
} }
void LocalPlayer::updatePosition(bool forceUpdate) void LocalPlayer::updatePosition(bool forceUpdate)
@ -510,6 +524,9 @@ void LocalPlayer::updateCell(bool forceUpdate)
RakNet::BitStream bs; RakNet::BitStream bs;
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true); GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true);
GetNetworking()->SendData(&bs); GetNetworking()->SendData(&bs);
// Also update skill progress
updateSkills(true);
} }
} }
@ -607,7 +624,9 @@ bool LocalPlayer::CharGenThread() // ToDo: need fix
if (CharGenStage()->end != 1) if (CharGenStage()->end != 1)
{ {
updateDynamicStats(true); updateDynamicStats(true);
updateClassStats(true); updateAttributes(true);
updateSkills(true);
updateLevel(true);
SendClass(); SendClass();
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this); GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
} }

View file

@ -25,7 +25,9 @@ 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 updateClassStats(bool forceUpdate = false); void updateAttributes(bool forceUpdate = false);
void updateSkills(bool forceUpdate = false);
void updateLevel(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

@ -480,7 +480,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
{ {
if (packet->length == myPacket->headerSize()) if (packet->length == myPacket->headerSize())
{ {
getLocalPlayer()->updateClassStats(true); getLocalPlayer()->updateAttributes(true);
} }
else else
{ {
@ -510,7 +510,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
{ {
if (packet->length == myPacket->headerSize()) if (packet->length == myPacket->headerSize())
{ {
getLocalPlayer()->updateClassStats(true); getLocalPlayer()->updateSkills(true);
} }
else else
{ {
@ -540,7 +540,7 @@ void Networking::ReceiveMessage(RakNet::Packet *packet)
{ {
if (packet->length == myPacket->headerSize()) if (packet->length == myPacket->headerSize())
{ {
getLocalPlayer()->updateClassStats(true); getLocalPlayer()->updateLevel(true);
} }
else else
{ {

View file

@ -20,4 +20,6 @@ void PacketSkill::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
for (int i = 0; i < StatsCount; ++i) for (int i = 0; i < StatsCount; ++i)
RW(player->NpcStats()->mSkills[i], send); RW(player->NpcStats()->mSkills[i], send);
RW(player->NpcStats()->mLevelProgress, send);
} }