[General] Simplify storing of attribute and skill index changes

(cherry picked from commit bd9e8bd10f)
0.6.3
David Cernat 7 years ago
parent 2c77d5f498
commit c5b08d6109

@ -409,8 +409,8 @@ void StatsFunctions::SetAttributeBase(unsigned short pid, unsigned short attribu
player->creatureStats.mAttributes[attributeId].mBase = value; player->creatureStats.mAttributes[attributeId].mBase = value;
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId)) if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId))
player->attributeChanges.attributeIndexes.push_back(attributeId); player->attributeIndexChanges.push_back(attributeId);
} }
void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short attributeId) noexcept
@ -423,8 +423,8 @@ void StatsFunctions::ClearAttributeModifier(unsigned short pid, unsigned short a
player->creatureStats.mAttributes[attributeId].mMod = 0; player->creatureStats.mAttributes[attributeId].mMod = 0;
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId)) if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId))
player->attributeChanges.attributeIndexes.push_back(attributeId); player->attributeIndexChanges.push_back(attributeId);
} }
void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, int value) noexcept void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, int value) noexcept
@ -437,8 +437,8 @@ void StatsFunctions::SetSkillBase(unsigned short pid, unsigned short skillId, in
player->npcStats.mSkills[skillId].mBase = value; player->npcStats.mSkills[skillId].mBase = value;
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId)) if (!Utils::vectorContains(&player->skillIndexChanges, skillId))
player->skillChanges.skillIndexes.push_back(skillId); player->skillIndexChanges.push_back(skillId);
} }
void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skillId) noexcept void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skillId) noexcept
@ -451,8 +451,8 @@ void StatsFunctions::ClearSkillModifier(unsigned short pid, unsigned short skill
player->npcStats.mSkills[skillId].mMod = 0; player->npcStats.mSkills[skillId].mMod = 0;
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId)) if (!Utils::vectorContains(&player->skillIndexChanges, skillId))
player->skillChanges.skillIndexes.push_back(skillId); player->skillIndexChanges.push_back(skillId);
} }
void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId, double value) noexcept void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId, double value) noexcept
@ -465,8 +465,8 @@ void StatsFunctions::SetSkillProgress(unsigned short pid, unsigned short skillId
player->npcStats.mSkills[skillId].mProgress = value; player->npcStats.mSkills[skillId].mProgress = value;
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId)) if (!Utils::vectorContains(&player->skillIndexChanges, skillId))
player->skillChanges.skillIndexes.push_back(skillId); player->skillIndexChanges.push_back(skillId);
} }
void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attributeId, int value) noexcept void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attributeId, int value) noexcept
@ -479,8 +479,8 @@ void StatsFunctions::SetSkillIncrease(unsigned short pid, unsigned int attribute
player->npcStats.mSkillIncrease[attributeId] = value; player->npcStats.mSkillIncrease[attributeId] = value;
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId)) if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId))
player->attributeChanges.attributeIndexes.push_back(attributeId); player->attributeIndexChanges.push_back(attributeId);
} }
void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept void StatsFunctions::SetBounty(unsigned short pid, int value) noexcept
@ -533,7 +533,7 @@ void StatsFunctions::SendAttributes(unsigned short pid) noexcept
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(false);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(true); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_ATTRIBUTE)->Send(true);
player->attributeChanges.attributeIndexes.clear(); player->attributeIndexChanges.clear();
} }
void StatsFunctions::SendSkills(unsigned short pid) noexcept void StatsFunctions::SendSkills(unsigned short pid) noexcept
@ -545,7 +545,7 @@ void StatsFunctions::SendSkills(unsigned short pid) noexcept
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(false); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(false);
mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(true); mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SKILL)->Send(true);
player->skillChanges.skillIndexes.clear(); player->skillIndexChanges.clear();
} }
void StatsFunctions::SendLevel(unsigned short pid) noexcept void StatsFunctions::SendLevel(unsigned short pid) noexcept

@ -246,15 +246,15 @@ void LocalPlayer::updateAttributes(bool forceUpdate)
{ {
ptrNpcStats.getAttribute(i).writeState(creatureStats.mAttributes[i]); ptrNpcStats.getAttribute(i).writeState(creatureStats.mAttributes[i]);
npcStats.mSkillIncrease[i] = ptrNpcStats.getSkillIncrease(i); npcStats.mSkillIncrease[i] = ptrNpcStats.getSkillIncrease(i);
attributeChanges.attributeIndexes.push_back(i); attributeIndexChanges.push_back(i);
} }
} }
if (attributeChanges.attributeIndexes.size() > 0) if (attributeIndexChanges.size() > 0)
{ {
getNetworking()->getPlayerPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_ATTRIBUTE)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_ATTRIBUTE)->Send();
attributeChanges.attributeIndexes.clear(); attributeIndexChanges.clear();
} }
} }
@ -275,15 +275,15 @@ void LocalPlayer::updateSkills(bool forceUpdate)
forceUpdate) forceUpdate)
{ {
ptrNpcStats.getSkill(i).writeState(npcStats.mSkills[i]); ptrNpcStats.getSkill(i).writeState(npcStats.mSkills[i]);
skillChanges.skillIndexes.push_back(i); skillIndexChanges.push_back(i);
} }
} }
if (skillChanges.skillIndexes.size() > 0) if (skillIndexChanges.size() > 0)
{ {
getNetworking()->getPlayerPacket(ID_PLAYER_SKILL)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_SKILL)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_SKILL)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_SKILL)->Send();
skillChanges.skillIndexes.clear(); skillIndexChanges.clear();
} }
} }

@ -95,22 +95,6 @@ namespace mwmp
int type; // 0 - Cell load, 1 - Cell unload int type; // 0 - Cell load, 1 - Cell unload
}; };
// Track only the indexes of the attributes that have been changed,
// with the attribute values themselves being stored in creatureStats.mAttributes
struct AttributeChanges
{
std::vector<int> attributeIndexes;
unsigned int count;
};
// Track only the indexes of the skills that have been changed,
// with the skill values themselves being stored in npcStats.mSkills
struct SkillChanges
{
std::vector<int> skillIndexes;
unsigned int count;
};
struct JournalChanges struct JournalChanges
{ {
std::vector<JournalItem> journalItems; std::vector<JournalItem> journalItems;
@ -259,8 +243,13 @@ namespace mwmp
int day; int day;
double hour; double hour;
AttributeChanges attributeChanges; // Track only the indexes of the attributes that have been changed,
SkillChanges skillChanges; // with the attribute values themselves being stored in creatureStats.mAttributes
std::vector<int> attributeIndexChanges;
// Track only the indexes of the skills that have been changed,
// with the skill values themselves being stored in npcStats.mSkills
std::vector<int> skillIndexChanges;
InventoryChanges inventoryChanges; InventoryChanges inventoryChanges;
SpellbookChanges spellbookChanges; SpellbookChanges spellbookChanges;

@ -13,23 +13,23 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count;
if (send) if (send)
player->attributeChanges.count = (unsigned int)(player->attributeChanges.attributeIndexes.size()); count = static_cast<uint32_t>(player->attributeIndexChanges.size());
else
player->attributeChanges.attributeIndexes.clear();
RW(player->attributeChanges.count, send); RW(count, send);
for (unsigned int i = 0; i < player->attributeChanges.count; i++) if (!send)
{ {
int attributeId; player->attributeIndexChanges.clear();
player->attributeIndexChanges.resize(count);
if (send) }
attributeId = player->attributeChanges.attributeIndexes.at(i);
RW(attributeId, send); for (auto &&attributeIndex : player->attributeIndexChanges)
{
RW(attributeIndex, send);
RW(player->creatureStats.mAttributes[attributeId], send); RW(player->creatureStats.mAttributes[attributeIndex], send);
RW(player->npcStats.mSkillIncrease[attributeId], send); RW(player->npcStats.mSkillIncrease[attributeIndex], send);
} }
} }

@ -14,22 +14,22 @@ void PacketPlayerSkill::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
uint32_t count;
if (send) if (send)
player->skillChanges.count = (unsigned int)(player->skillChanges.skillIndexes.size()); count = static_cast<uint32_t>(player->skillIndexChanges.size());
else
player->skillChanges.skillIndexes.clear();
RW(player->skillChanges.count, send); RW(count, send);
for (unsigned int i = 0; i < player->skillChanges.count; i++) if (!send)
{ {
int skillId; player->skillIndexChanges.clear();
player->skillIndexChanges.resize(count);
if (send) }
skillId = player->skillChanges.skillIndexes.at(i);
for (auto &&skillId : player->skillIndexChanges)
{
RW(skillId, send); RW(skillId, send);
RW(player->npcStats.mSkills[skillId], send); RW(player->npcStats.mSkills[skillId], send);
} }
} }

Loading…
Cancel
Save