[General] Implement PlayerSpellsActive packet, part 2

The packet can now set the active spells of DedicatedPlayers.
pull/593/head
David Cernat 4 years ago
parent 30b179c2dd
commit 58c04530e7

@ -484,6 +484,41 @@ void DedicatedPlayer::resurrect()
getPtr().getClass().getCreatureStats(getPtr()).setHealth(health);
}
void DedicatedPlayer::addSpellsActive()
{
MWMechanics::ActiveSpells& activeSpells = getPtr().getClass().getCreatureStats(getPtr()).getActiveSpells();
for (const auto& activeSpell : spellsActiveChanges.activeSpells)
{
// Only add spells that are ensured to exist
if (MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(activeSpell.id))
{
activeSpells.addSpell(activeSpell.id, false, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1);
}
else
LOG_APPEND(TimedLog::LOG_INFO, "- Ignored addition of invalid spell %s", activeSpell.id.c_str());
}
}
void DedicatedPlayer::removeSpellsActive()
{
MWMechanics::ActiveSpells& activeSpells = getPtr().getClass().getCreatureStats(getPtr()).getActiveSpells();
for (const auto& activeSpell : spellsActiveChanges.activeSpells)
{
activeSpells.removeEffects(activeSpell.id);
}
}
void DedicatedPlayer::setSpellsActive()
{
MWMechanics::ActiveSpells& activeSpells = getPtr().getClass().getCreatureStats(getPtr()).getActiveSpells();
activeSpells.clear();
// Proceed by adding spells active
addSpellsActive();
}
void DedicatedPlayer::updateMarker()
{
if (!markerEnabled)

@ -49,6 +49,10 @@ namespace mwmp
void die();
void resurrect();
void addSpellsActive();
void removeSpellsActive();
void setSpellsActive();
void updateMarker();
void removeMarker();
void enableMarker();

@ -16,24 +16,42 @@ namespace mwmp
virtual void Do(PlayerPacket &packet, BasePlayer *player)
{
if (!isLocal()) return;
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_SPELLS_ACTIVE from server");
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Received ID_PLAYER_SPELLS_ACTIVE about LocalPlayer from server");
if (isRequest())
static_cast<LocalPlayer*>(player)->sendSpellsActive();
if (isLocal())
{
LOG_APPEND(TimedLog::LOG_INFO, "- Packet was about me");
if (isRequest())
static_cast<LocalPlayer*>(player)->sendSpellsActive();
else
{
LocalPlayer& localPlayer = static_cast<LocalPlayer&>(*player);
int spellsActiveAction = localPlayer.spellsActiveChanges.action;
if (spellsActiveAction == SpellsActiveChanges::ADD)
localPlayer.addSpellsActive();
else if (spellsActiveAction == SpellsActiveChanges::REMOVE)
localPlayer.removeSpellsActive();
else // SpellsActiveChanges::SET
localPlayer.setSpellsActive();
}
}
else
{
LocalPlayer &localPlayer = static_cast<LocalPlayer&>(*player);
int spellsActiveAction = localPlayer.spellsActiveChanges.action;
LOG_APPEND(TimedLog::LOG_INFO, "- Packet was about %s", player->npc.mName.c_str());
DedicatedPlayer& dedicatedPlayer = static_cast<DedicatedPlayer&>(*player);
int spellsActiveAction = dedicatedPlayer.spellsActiveChanges.action;
if (spellsActiveAction == SpellsActiveChanges::ADD)
localPlayer.addSpellsActive();
dedicatedPlayer.addSpellsActive();
else if (spellsActiveAction == SpellsActiveChanges::REMOVE)
localPlayer.removeSpellsActive();
dedicatedPlayer.removeSpellsActive();
else // SpellsActiveChanges::SET
localPlayer.setSpellsActive();
dedicatedPlayer.setSpellsActive();
}
}
};

Loading…
Cancel
Save