1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-28 21:06:41 +00:00

[General] Implement PlayerSpellsActive packet, part 2

The packet can now set the active spells of DedicatedPlayers.
This commit is contained in:
David Cernat 2020-11-17 13:00:02 +02:00
parent 30b179c2dd
commit 58c04530e7
3 changed files with 67 additions and 10 deletions

View file

@ -484,6 +484,41 @@ void DedicatedPlayer::resurrect()
getPtr().getClass().getCreatureStats(getPtr()).setHealth(health); 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() void DedicatedPlayer::updateMarker()
{ {
if (!markerEnabled) if (!markerEnabled)

View file

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

View file

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