mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-31 16:36:42 +00:00
[General] Implement PlayerSpellsActive packet, part 2
The packet can now set the active spells of DedicatedPlayers.
This commit is contained in:
parent
30b179c2dd
commit
58c04530e7
3 changed files with 67 additions and 10 deletions
|
@ -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 (isLocal())
|
||||
{
|
||||
LOG_APPEND(TimedLog::LOG_INFO, "- Packet was about me");
|
||||
|
||||
if (isRequest())
|
||||
static_cast<LocalPlayer*>(player)->sendSpellsActive();
|
||||
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…
Reference in a new issue