[General] Simplify storing of attribute and skill index changes

new-script-api
David Cernat 7 years ago
parent 711bdf187a
commit bd9e8bd10f

@ -165,7 +165,7 @@ void Player::update()
packet->Send(false);
packet->Send(true);
attributeChanges.attributeIndexes.clear();
attributeIndexChanges.clear();
}
if (skillsChanged)
@ -175,7 +175,7 @@ void Player::update()
packet->Send(false);
packet->Send(true);
skillChanges.skillIndexes.clear();
skillIndexChanges.clear();
}
if (inventory.isEquipmentChanged())
@ -493,8 +493,8 @@ void Player::setAttribute(unsigned short attributeId, int base, int current)
creatureStats.mAttributes[attributeId].mBase = base;
creatureStats.mAttributes[attributeId].mCurrent = current;
if (!Utils::vectorContains(&attributeChanges.attributeIndexes, attributeId))
attributeChanges.attributeIndexes.push_back(attributeId);
if (!Utils::vectorContains(&attributeIndexChanges, attributeId))
attributeIndexChanges.push_back(attributeId);
attributesChanged = true;
}
@ -519,8 +519,8 @@ void Player::setSkill(unsigned short skillId, int base, int current, float progr
skill.mCurrent = current;
skill.mProgress = progress;
if (!Utils::vectorContains(&skillChanges.skillIndexes, skillId))
skillChanges.skillIndexes.push_back(skillId);
if (!Utils::vectorContains(&skillIndexChanges, skillId))
skillIndexChanges.push_back(skillId);
skillsChanged = true;
}
@ -537,8 +537,8 @@ void Player::setSkillIncrease(unsigned short attributeId, int increase)
npcStats.mSkillIncrease[attributeId] = increase;
if (!Utils::vectorContains(&attributeChanges.attributeIndexes, attributeId))
attributeChanges.attributeIndexes.push_back(attributeId);
if (!Utils::vectorContains(&attributeIndexChanges, attributeId))
attributeIndexChanges.push_back(attributeId);
attributesChanged = true;
}

@ -237,15 +237,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();
}
}
@ -266,15 +266,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();
}
}

@ -79,20 +79,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;
};
// 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;
};
struct JournalChanges
{
std::vector<JournalItem> journalItems;
@ -238,8 +224,13 @@ namespace mwmp
GUIWindow guiWindow;
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;
SpellbookChanges spellbookChanges;
JournalChanges journalChanges;

@ -15,17 +15,17 @@ void PacketPlayerAttribute::Packet(RakNet::BitStream *bs, bool send)
uint32_t count;
if (send)
count = static_cast<uint32_t>(player->attributeChanges.attributeIndexes.size());
count = static_cast<uint32_t>(player->attributeIndexChanges.size());
RW(count, send);
if (!send)
{
player->attributeChanges.attributeIndexes.clear();
player->attributeChanges.attributeIndexes.resize(count);
player->attributeIndexChanges.clear();
player->attributeIndexChanges.resize(count);
}
for (auto &&attributeIndex : player->attributeChanges.attributeIndexes)
for (auto &&attributeIndex : player->attributeIndexChanges)
{
RW(attributeIndex, send);

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

Loading…
Cancel
Save