Split updateClassStats in 3 and add handling of level progress

coverity_scan^2
David Cernat 8 years ago
parent 2ab619b0e3
commit a0e9a672a5

@ -150,6 +150,22 @@ void StatsFunctions::SetLevel(unsigned short pid, int value) noexcept
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
{
Player *player;

@ -96,6 +96,8 @@ public:
static int GetLevel(unsigned short pid) 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 void SetHealthBase(unsigned short pid, double value) noexcept;

@ -50,7 +50,9 @@ void LocalPlayer::Update()
updateDeadState();
updateInventory();
updateDynamicStats();
updateClassStats();
updateAttributes();
updateSkills();
updateLevel();
}
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();
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)
{
if (ptrNpcStats.getSkill(i).getBase() != NpcStats()->mSkills[i].mBase)
{
ptrNpcStats.getSkill(i).writeState(NpcStats()->mSkills[i]);
isUpdatingSkills = true;
isUpdating = true;
}
// 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)
@ -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)
{
ptrNpcStats.getAttribute(i).writeState(CreatureStats()->mAttributes[i]);
isUpdatingAttributes = true;
}
NpcStats()->mLevelProgress = ptrNpcStats.getLevelProgress();
GetNetworking()->GetPacket(ID_GAME_SKILL)->Send(this);
}
}
void LocalPlayer::updateLevel(bool forceUpdate)
{
MWWorld::Ptr player = GetPlayerPtr();
const MWMechanics::NpcStats &ptrNpcStats = player.getClass().getNpcStats(player);
if (ptrNpcStats.getLevel() != CreatureStats()->mLevel)
if (ptrNpcStats.getLevel() != CreatureStats()->mLevel || forceUpdate)
{
CreatureStats()->mLevel = ptrNpcStats.getLevel();
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)
@ -510,6 +524,9 @@ void LocalPlayer::updateCell(bool forceUpdate)
RakNet::BitStream bs;
GetNetworking()->GetPacket((RakNet::MessageID) ID_GAME_CELL)->Packet(&bs, this, true);
GetNetworking()->SendData(&bs);
// Also update skill progress
updateSkills(true);
}
}
@ -607,7 +624,9 @@ bool LocalPlayer::CharGenThread() // ToDo: need fix
if (CharGenStage()->end != 1)
{
updateDynamicStats(true);
updateClassStats(true);
updateAttributes(true);
updateSkills(true);
updateLevel(true);
SendClass();
GetNetworking()->GetPacket(ID_GAME_CHARGEN)->Send(this);
}

@ -25,7 +25,9 @@ namespace mwmp
void updateInventory(bool forceUpdate = false);
void updateAttackState(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 updateDrawStateAndFlags(bool forceUpdate = false);

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

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

Loading…
Cancel
Save