[Client] Make ActiveSpells::removeSpellByTimestamp() return a boolean

Add logging to LocalPlayer::removeSpellsActive() to track when a player's active spell hasn't been removed due to an invalid timestamp.
pull/600/head
David Cernat 3 years ago
parent ed9a85f13b
commit f2d95dc84d

@ -308,8 +308,10 @@ namespace MWMechanics
Remove the spell with a certain ID and a certain timestamp, useful
when there are stacked spells with the same ID
Returns a boolean that indicates whether the corresponding spell was found
*/
void ActiveSpells::removeSpellByTimestamp(const std::string& id, MWWorld::TimeStamp timestamp)
bool ActiveSpells::removeSpellByTimestamp(const std::string& id, MWWorld::TimeStamp timestamp)
{
for (TContainer::iterator spell = mSpells.begin(); spell != mSpells.end(); ++spell)
{
@ -319,10 +321,12 @@ namespace MWMechanics
{
spell->second.mEffects.clear();
mSpellsChanged = true;
break;
return true;
}
}
}
return false;
}
/*
End of tes3mp addition

@ -107,7 +107,7 @@ namespace MWMechanics
Remove the spell with a certain ID and a certain timestamp, useful
when there are stacked spells with the same ID
*/
void removeSpellByTimestamp(const std::string& id, MWWorld::TimeStamp timestamp);
bool removeSpellByTimestamp(const std::string& id, MWWorld::TimeStamp timestamp);
/*
End of tes3mp addition
*/

@ -824,11 +824,18 @@ void LocalPlayer::removeSpellsActive()
for (const auto& activeSpell : spellsActiveChanges.activeSpells)
{
LOG_APPEND(TimedLog::LOG_INFO, "- removing %sstacking active spell %s", activeSpell.isStackingSpell ? "" : "non-", activeSpell.id.c_str());
// Remove stacking spells based on their timestamps
if (activeSpell.isStackingSpell)
{
MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay);
activeSpells.removeSpellByTimestamp(activeSpell.id, timestamp);
bool foundSpell = activeSpells.removeSpellByTimestamp(activeSpell.id, timestamp);
if (!foundSpell)
{
LOG_APPEND(TimedLog::LOG_INFO, "-- spell with this ID and timestamp could not be found!");
}
}
else
{

Loading…
Cancel
Save