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

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

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

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

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