[General] Track casters of spells in SpellsActive packets

Also simplify sending of SpellsActive packets slightly.
pull/593/head
David Cernat 4 years ago
parent 4492a7a768
commit 3f3fe66fde

@ -229,18 +229,13 @@ namespace MWMechanics
{ {
bool isStackingSpell = it == end() || stack; bool isStackingSpell = it == end() || stack;
ESM::ActiveSpells::ActiveSpellParams esmParams;
esmParams.mEffects = effects;
esmParams.mDisplayName = displayName;
esmParams.mCasterActorId = casterActorId;
if (this == &MWMechanics::getPlayer().getClass().getCreatureStats(MWMechanics::getPlayer()).getActiveSpells()) if (this == &MWMechanics::getPlayer().getClass().getCreatureStats(MWMechanics::getPlayer()).getActiveSpells())
{ {
mwmp::Main::get().getLocalPlayer()->sendSpellsActiveAddition(id, isStackingSpell, esmParams, params.mTimeStamp); mwmp::Main::get().getLocalPlayer()->sendSpellsActiveAddition(id, isStackingSpell, params);
} }
else if (mwmp::Main::get().getCellController()->isLocalActor(MechanicsHelper::getCurrentActor())) else if (mwmp::Main::get().getCellController()->isLocalActor(MechanicsHelper::getCurrentActor()))
{ {
mwmp::Main::get().getCellController()->getLocalActor(MechanicsHelper::getCurrentActor())->sendSpellsActiveAddition(id, isStackingSpell, esmParams, params.mTimeStamp); mwmp::Main::get().getCellController()->getLocalActor(MechanicsHelper::getCurrentActor())->sendSpellsActiveAddition(id, isStackingSpell, params);
} }
} }
/* /*

@ -366,9 +366,10 @@ void DedicatedActor::addSpellsActive()
for (const auto& activeSpell : spellsActiveChanges.activeSpells) for (const auto& activeSpell : spellsActiveChanges.activeSpells)
{ {
MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay); MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay);
int casterActorId = MechanicsHelper::getActorId(activeSpell.caster);
// Don't do a check for a spell's existence, because active effects from potions need to be applied here too // Don't do a check for a spell's existence, because active effects from potions need to be applied here too
activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1, timestamp, false); activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, casterActorId, timestamp, false);
} }
reloadPtr(); reloadPtr();

@ -491,9 +491,10 @@ void DedicatedPlayer::addSpellsActive()
for (const auto& activeSpell : spellsActiveChanges.activeSpells) for (const auto& activeSpell : spellsActiveChanges.activeSpells)
{ {
MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay); MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay);
int casterActorId = MechanicsHelper::getActorId(activeSpell.caster);
// Don't do a check for a spell's existence, because active effects from potions need to be applied here too // Don't do a check for a spell's existence, because active effects from potions need to be applied here too
activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1, timestamp, false); activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, casterActorId, timestamp, false);
} }
} }

@ -285,7 +285,7 @@ void LocalActor::sendEquipment()
Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->Send(); Main::get().getNetworking()->getActorPacket(ID_ACTOR_EQUIPMENT)->Send();
} }
void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp) void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params)
{ {
// Skip any bugged spells that somehow have clientside-only dynamic IDs // Skip any bugged spells that somehow have clientside-only dynamic IDs
if (id.find("$dynamic") != std::string::npos) if (id.find("$dynamic") != std::string::npos)
@ -293,12 +293,16 @@ void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingS
spellsActiveChanges.activeSpells.clear(); spellsActiveChanges.activeSpells.clear();
const MWWorld::Ptr& caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(params.mCasterActorId);
mwmp::ActiveSpell spell; mwmp::ActiveSpell spell;
spell.id = id; spell.id = id;
spell.isStackingSpell = isStackingSpell; spell.isStackingSpell = isStackingSpell;
spell.timestampDay = timestamp.getDay(); spell.caster = MechanicsHelper::getTarget(caster);
spell.timestampHour = timestamp.getHour(); spell.timestampDay = params.mTimeStamp.getDay();
spell.params = params; spell.timestampHour = params.mTimeStamp.getHour();
spell.params.mEffects = params.mEffects;
spell.params.mDisplayName = params.mDisplayName;
spellsActiveChanges.activeSpells.push_back(spell); spellsActiveChanges.activeSpells.push_back(spell);
spellsActiveChanges.action = mwmp::SpellsActiveChanges::ADD; spellsActiveChanges.action = mwmp::SpellsActiveChanges::ADD;

@ -3,6 +3,7 @@
#include <components/openmw-mp/Base/BaseActor.hpp> #include <components/openmw-mp/Base/BaseActor.hpp>
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/activespells.hpp"
#include "../mwworld/manualref.hpp" #include "../mwworld/manualref.hpp"
#include "../mwworld/timestamp.hpp" #include "../mwworld/timestamp.hpp"
@ -27,7 +28,7 @@ namespace mwmp
void updateAttackOrCast(); void updateAttackOrCast();
void sendEquipment(); void sendEquipment();
void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp); void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params);
void sendSpellsActiveRemoval(const std::string id, bool isStackingSpell, MWWorld::TimeStamp timestamp); void sendSpellsActiveRemoval(const std::string id, bool isStackingSpell, MWWorld::TimeStamp timestamp);
void sendDeath(char newDeathState); void sendDeath(char newDeathState);

@ -719,9 +719,10 @@ void LocalPlayer::addSpellsActive()
for (const auto& activeSpell : spellsActiveChanges.activeSpells) for (const auto& activeSpell : spellsActiveChanges.activeSpells)
{ {
MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay); MWWorld::TimeStamp timestamp = MWWorld::TimeStamp(activeSpell.timestampHour, activeSpell.timestampDay);
int casterActorId = MechanicsHelper::getActorId(activeSpell.caster);
// Don't do a check for a spell's existence, because active effects from potions need to be applied here too // Don't do a check for a spell's existence, because active effects from potions need to be applied here too
activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, 1, timestamp, false); activeSpells.addSpell(activeSpell.id, activeSpell.isStackingSpell, activeSpell.params.mEffects, activeSpell.params.mDisplayName, casterActorId, timestamp, false);
} }
} }
@ -1617,7 +1618,7 @@ void LocalPlayer::sendSpellsActive()
getNetworking()->getPlayerPacket(ID_PLAYER_SPELLS_ACTIVE)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_SPELLS_ACTIVE)->Send();
} }
void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp) void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params)
{ {
// Skip any bugged spells that somehow have clientside-only dynamic IDs // Skip any bugged spells that somehow have clientside-only dynamic IDs
if (id.find("$dynamic") != std::string::npos) if (id.find("$dynamic") != std::string::npos)
@ -1625,12 +1626,17 @@ void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStacking
spellsActiveChanges.activeSpells.clear(); spellsActiveChanges.activeSpells.clear();
MWWorld::Ptr caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(params.mCasterActorId);
mwmp::ActiveSpell spell; mwmp::ActiveSpell spell;
spell.id = id; spell.id = id;
spell.isStackingSpell = isStackingSpell; spell.isStackingSpell = isStackingSpell;
spell.timestampDay = timestamp.getDay(); spell.caster = MechanicsHelper::getTarget(caster);
spell.timestampHour = timestamp.getHour(); spell.timestampDay = params.mTimeStamp.getDay();
spell.params = params; spell.timestampHour = params.mTimeStamp.getHour();
spell.params.mEffects = params.mEffects;
spell.params.mDisplayName = params.mDisplayName;
spellsActiveChanges.activeSpells.push_back(spell); spellsActiveChanges.activeSpells.push_back(spell);
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending active spell addition with stacking %s, timestamp %i %f", LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending active spell addition with stacking %s, timestamp %i %f",

@ -2,6 +2,7 @@
#define OPENMW_LOCALPLAYER_HPP #define OPENMW_LOCALPLAYER_HPP
#include <components/openmw-mp/Base/BasePlayer.hpp> #include <components/openmw-mp/Base/BasePlayer.hpp>
#include "../mwmechanics/activespells.hpp"
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/timestamp.hpp" #include "../mwworld/timestamp.hpp"
#include <RakNetTypes.h> #include <RakNetTypes.h>
@ -93,7 +94,7 @@ namespace mwmp
void sendSpellbook(); void sendSpellbook();
void sendSpellChange(std::string id, unsigned int action); void sendSpellChange(std::string id, unsigned int action);
void sendSpellsActive(); void sendSpellsActive();
void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, ESM::ActiveSpells::ActiveSpellParams params, MWWorld::TimeStamp timestamp); void sendSpellsActiveAddition(const std::string id, bool isStackingSpell, const MWMechanics::ActiveSpells::ActiveSpellParams& params);
void sendSpellsActiveRemoval(const std::string id, bool isStackingSpell, MWWorld::TimeStamp timestamp); void sendSpellsActiveRemoval(const std::string id, bool isStackingSpell, MWWorld::TimeStamp timestamp);
void sendCooldownChange(std::string id, int startTimestampDay, float startTimestampHour); void sendCooldownChange(std::string id, int startTimestampDay, float startTimestampHour);
void sendQuickKey(unsigned short slot, int type, const std::string& itemId = ""); void sendQuickKey(unsigned short slot, int type, const std::string& itemId = "");

@ -173,6 +173,7 @@ namespace mwmp
bool isStackingSpell; bool isStackingSpell;
int timestampDay; int timestampDay;
double timestampHour; double timestampHour;
Target caster;
ESM::ActiveSpells::ActiveSpellParams params; ESM::ActiveSpells::ActiveSpellParams params;
}; };

@ -34,6 +34,19 @@ void PacketActorSpellsActive::Actor(BaseActor &actor, bool send)
RW(activeSpell.timestampHour, send); RW(activeSpell.timestampHour, send);
RW(activeSpell.params.mDisplayName, send, true); RW(activeSpell.params.mDisplayName, send, true);
RW(activeSpell.caster.isPlayer, send);
if (activeSpell.caster.isPlayer)
{
RW(activeSpell.caster.guid, send);
}
else
{
RW(activeSpell.caster.refId, send, true);
RW(activeSpell.caster.refNum, send);
RW(activeSpell.caster.mpNum, send);
}
uint32_t effectCount; uint32_t effectCount;
if (send) if (send)

@ -35,6 +35,19 @@ void PacketPlayerSpellsActive::Packet(RakNet::BitStream *newBitstream, bool send
RW(activeSpell.timestampHour, send); RW(activeSpell.timestampHour, send);
RW(activeSpell.params.mDisplayName, send, true); RW(activeSpell.params.mDisplayName, send, true);
RW(activeSpell.caster.isPlayer, send);
if (activeSpell.caster.isPlayer)
{
RW(activeSpell.caster.guid, send);
}
else
{
RW(activeSpell.caster.refId, send, true);
RW(activeSpell.caster.refNum, send);
RW(activeSpell.caster.mpNum, send);
}
uint32_t effectCount; uint32_t effectCount;
if (send) if (send)

Loading…
Cancel
Save