mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-07-12 13:51:42 +00:00
[General] Track casters of spells in SpellsActive packets
Also simplify sending of SpellsActive packets slightly.
This commit is contained in:
parent
4492a7a768
commit
3f3fe66fde
10 changed files with 56 additions and 20 deletions
|
@ -229,18 +229,13 @@ namespace MWMechanics
|
|||
{
|
||||
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())
|
||||
{
|
||||
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()))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
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();
|
||||
|
|
|
@ -491,9 +491,10 @@ void DedicatedPlayer::addSpellsActive()
|
|||
for (const auto& activeSpell : spellsActiveChanges.activeSpells)
|
||||
{
|
||||
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
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
if (id.find("$dynamic") != std::string::npos)
|
||||
|
@ -293,12 +293,16 @@ void LocalActor::sendSpellsActiveAddition(const std::string id, bool isStackingS
|
|||
|
||||
spellsActiveChanges.activeSpells.clear();
|
||||
|
||||
const MWWorld::Ptr& caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(params.mCasterActorId);
|
||||
|
||||
mwmp::ActiveSpell spell;
|
||||
spell.id = id;
|
||||
spell.isStackingSpell = isStackingSpell;
|
||||
spell.timestampDay = timestamp.getDay();
|
||||
spell.timestampHour = timestamp.getHour();
|
||||
spell.params = params;
|
||||
spell.caster = MechanicsHelper::getTarget(caster);
|
||||
spell.timestampDay = params.mTimeStamp.getDay();
|
||||
spell.timestampHour = params.mTimeStamp.getHour();
|
||||
spell.params.mEffects = params.mEffects;
|
||||
spell.params.mDisplayName = params.mDisplayName;
|
||||
spellsActiveChanges.activeSpells.push_back(spell);
|
||||
|
||||
spellsActiveChanges.action = mwmp::SpellsActiveChanges::ADD;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <components/openmw-mp/Base/BaseActor.hpp>
|
||||
#include "../mwmechanics/creaturestats.hpp"
|
||||
#include "../mwmechanics/activespells.hpp"
|
||||
#include "../mwworld/manualref.hpp"
|
||||
#include "../mwworld/timestamp.hpp"
|
||||
|
||||
|
@ -27,7 +28,7 @@ namespace mwmp
|
|||
void updateAttackOrCast();
|
||||
|
||||
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 sendDeath(char newDeathState);
|
||||
|
||||
|
|
|
@ -719,9 +719,10 @@ void LocalPlayer::addSpellsActive()
|
|||
for (const auto& activeSpell : spellsActiveChanges.activeSpells)
|
||||
{
|
||||
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
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
if (id.find("$dynamic") != std::string::npos)
|
||||
|
@ -1625,12 +1626,17 @@ void LocalPlayer::sendSpellsActiveAddition(const std::string id, bool isStacking
|
|||
|
||||
spellsActiveChanges.activeSpells.clear();
|
||||
|
||||
|
||||
MWWorld::Ptr caster = MWBase::Environment::get().getWorld()->searchPtrViaActorId(params.mCasterActorId);
|
||||
|
||||
mwmp::ActiveSpell spell;
|
||||
spell.id = id;
|
||||
spell.isStackingSpell = isStackingSpell;
|
||||
spell.timestampDay = timestamp.getDay();
|
||||
spell.timestampHour = timestamp.getHour();
|
||||
spell.params = params;
|
||||
spell.caster = MechanicsHelper::getTarget(caster);
|
||||
spell.timestampDay = params.mTimeStamp.getDay();
|
||||
spell.timestampHour = params.mTimeStamp.getHour();
|
||||
spell.params.mEffects = params.mEffects;
|
||||
spell.params.mDisplayName = params.mDisplayName;
|
||||
spellsActiveChanges.activeSpells.push_back(spell);
|
||||
|
||||
LOG_MESSAGE_SIMPLE(TimedLog::LOG_INFO, "Sending active spell addition with stacking %s, timestamp %i %f",
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define OPENMW_LOCALPLAYER_HPP
|
||||
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
#include "../mwmechanics/activespells.hpp"
|
||||
#include "../mwworld/ptr.hpp"
|
||||
#include "../mwworld/timestamp.hpp"
|
||||
#include <RakNetTypes.h>
|
||||
|
@ -93,7 +94,7 @@ namespace mwmp
|
|||
void sendSpellbook();
|
||||
void sendSpellChange(std::string id, unsigned int action);
|
||||
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 sendCooldownChange(std::string id, int startTimestampDay, float startTimestampHour);
|
||||
void sendQuickKey(unsigned short slot, int type, const std::string& itemId = "");
|
||||
|
|
|
@ -173,6 +173,7 @@ namespace mwmp
|
|||
bool isStackingSpell;
|
||||
int timestampDay;
|
||||
double timestampHour;
|
||||
Target caster;
|
||||
ESM::ActiveSpells::ActiveSpellParams params;
|
||||
};
|
||||
|
||||
|
|
|
@ -34,6 +34,19 @@ void PacketActorSpellsActive::Actor(BaseActor &actor, bool send)
|
|||
RW(activeSpell.timestampHour, send);
|
||||
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;
|
||||
|
||||
if (send)
|
||||
|
|
|
@ -35,6 +35,19 @@ void PacketPlayerSpellsActive::Packet(RakNet::BitStream *newBitstream, bool send
|
|||
RW(activeSpell.timestampHour, send);
|
||||
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;
|
||||
|
||||
if (send)
|
||||
|
|
Loading…
Reference in a new issue