[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;
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId))
player->attributeChanges.attributeIndexes.push_back(attributeId);
if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId))
player->attributeIndexChanges.push_back(attributeId);
}
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;
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId))
player->attributeChanges.attributeIndexes.push_back(attributeId);
if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId))
player->attributeIndexChanges.push_back(attributeId);
}
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;
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId))
player->skillChanges.skillIndexes.push_back(skillId);
if (!Utils::vectorContains(&player->skillIndexChanges, skillId))
player->skillIndexChanges.push_back(skillId);
}
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;
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId))
player->skillChanges.skillIndexes.push_back(skillId);
if (!Utils::vectorContains(&player->skillIndexChanges, skillId))
player->skillIndexChanges.push_back(skillId);
}
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;
if (!Utils::vectorContains(&player->skillChanges.skillIndexes, skillId))
player->skillChanges.skillIndexes.push_back(skillId);
if (!Utils::vectorContains(&player->skillIndexChanges, skillId))
player->skillIndexChanges.push_back(skillId);
}
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;
if (!Utils::vectorContains(&player->attributeChanges.attributeIndexes, attributeId))
player->attributeChanges.attributeIndexes.push_back(attributeId);
if (!Utils::vectorContains(&player->attributeIndexChanges, attributeId))
player->attributeIndexChanges.push_back(attributeId);
}
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(true);
player->attributeChanges.attributeIndexes.clear();
player->attributeIndexChanges.clear();
}
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(true);
player->skillChanges.skillIndexes.clear();
player->skillIndexChanges.clear();
}
void StatsFunctions::SendLevel(unsigned short pid) noexcept

@ -246,15 +246,15 @@ void LocalPlayer::updateAttributes(bool forceUpdate)
{
ptrNpcStats.getAttribute(i).writeState(creatureStats.mAttributes[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)->Send();
attributeChanges.attributeIndexes.clear();
attributeIndexChanges.clear();
}
}
@ -275,15 +275,15 @@ void LocalPlayer::updateSkills(bool forceUpdate)
forceUpdate)
{
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)->Send();
skillChanges.skillIndexes.clear();
skillIndexChanges.clear();
}
}

@ -95,22 +95,6 @@ namespace mwmp
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
{
std::vector<JournalItem> journalItems;
@ -259,8 +243,13 @@ namespace mwmp
int day;
double hour;
AttributeChanges attributeChanges;
SkillChanges skillChanges;
// Track only the indexes of the attributes that have been changed,
// 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;
SpellbookChanges spellbookChanges;

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

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

Loading…
Cancel
Save