[General] Implement ActorSpellsActive packet, part 2

Additions and removals of actors' active spells can now be saved to and loaded from the server.
pull/593/head
David Cernat 4 years ago
parent ea6d5c68ae
commit 1eeee29d51

@ -17,6 +17,7 @@ BaseActorList writeActorList;
BaseActor tempActor;
const BaseActor emptyActor = {};
std::vector<ESM::ActiveEffect> storedActorActiveEffects;
static std::string tempCellDescription;
@ -224,6 +225,56 @@ unsigned int ActorFunctions::GetActorDeathState(unsigned int index) noexcept
return readActorList->baseActors.at(index).deathState;
}
unsigned int ActorFunctions::GetActorSpellsActiveChangesSize(unsigned int actorIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.size();
}
unsigned int ActorFunctions::GetActorSpellsActiveChangesAction(unsigned int actorIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.action;
}
const char* ActorFunctions::GetActorSpellsActiveId(unsigned int actorIndex, unsigned int spellIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).id.c_str();
}
const char* ActorFunctions::GetActorSpellsActiveDisplayName(unsigned int actorIndex, unsigned int spellIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mDisplayName.c_str();
}
unsigned int ActorFunctions::GetActorSpellsActiveEffectCount(unsigned int actorIndex, unsigned int spellIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.size();
}
unsigned int ActorFunctions::GetActorSpellsActiveEffectId(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mEffectId;
}
int ActorFunctions::GetActorSpellsActiveEffectArg(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mArg;
}
double ActorFunctions::GetActorSpellsActiveEffectMagnitude(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mMagnitude;
}
double ActorFunctions::GetActorSpellsActiveEffectDuration(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mDuration;
}
double ActorFunctions::GetActorSpellsActiveEffectTimeLeft(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept
{
return readActorList->baseActors.at(actorIndex).spellsActiveChanges.activeSpells.at(spellIndex).params.mEffects.at(effectIndex).mTimeLeft;
}
bool ActorFunctions::DoesActorHavePosition(unsigned int index) noexcept
{
return readActorList->baseActors.at(index).hasPositionData;
@ -338,6 +389,11 @@ void ActorFunctions::SetActorDeathInstant(bool isInstant) noexcept
tempActor.isInstantDeath = isInstant;
}
void ActorFunctions::SetActorSpellsActiveAction(unsigned char action) noexcept
{
tempActor.spellsActiveChanges.action = action;
}
void ActorFunctions::SetActorAIAction(unsigned int action) noexcept
{
tempActor.aiAction = action;
@ -398,6 +454,30 @@ void ActorFunctions::UnequipActorItem(unsigned short slot) noexcept
ActorFunctions::EquipActorItem(slot, "", 0, -1, -1);
}
void ActorFunctions::AddActorSpellActive(const char* spellId, const char* displayName) noexcept
{
mwmp::ActiveSpell spell;
spell.id = spellId;
spell.params.mDisplayName = displayName;
spell.params.mEffects = storedActorActiveEffects;
tempActor.spellsActiveChanges.activeSpells.push_back(spell);
storedActorActiveEffects.clear();
}
void ActorFunctions::AddActorSpellActiveEffect(int effectId, double magnitude, double duration, double timeLeft, int arg) noexcept
{
ESM::ActiveEffect effect;
effect.mEffectId = effectId;
effect.mMagnitude = magnitude;
effect.mDuration = duration;
effect.mTimeLeft = timeLeft;
effect.mArg = arg;
storedActorActiveEffects.push_back(effect);
}
void ActorFunctions::AddActor() noexcept
{
writeActorList.baseActors.push_back(tempActor);
@ -486,6 +566,25 @@ void ActorFunctions::SendActorEquipment(bool sendToOtherVisitors, bool skipAttac
}
}
void ActorFunctions::SendActorSpellsActiveChanges(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept
{
mwmp::ActorPacket* actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_SPELLS_ACTIVE);
actorPacket->setActorList(&writeActorList);
if (!skipAttachedPlayer)
actorPacket->Send(writeActorList.guid);
if (sendToOtherVisitors)
{
Cell* serverCell = CellController::get()->getCell(&writeActorList.cell);
if (serverCell != nullptr)
{
serverCell->sendToLoaded(actorPacket, &writeActorList);
}
}
}
void ActorFunctions::SendActorSpeech(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept
{
mwmp::ActorPacket *actorPacket = mwmp::Networking::get().getActorPacketController()->GetPacket(ID_ACTOR_SPEECH);

@ -48,6 +48,17 @@
{"GetActorKillerName", ActorFunctions::GetActorKillerName},\
{"GetActorDeathState", ActorFunctions::GetActorDeathState},\
\
{"GetActorSpellsActiveChangesSize", ActorFunctions::GetActorSpellsActiveChangesSize},\
{"GetActorSpellsActiveChangesAction", ActorFunctions::GetActorSpellsActiveChangesAction},\
{"GetActorSpellsActiveId", ActorFunctions::GetActorSpellsActiveId},\
{"GetActorSpellsActiveDisplayName", ActorFunctions::GetActorSpellsActiveDisplayName},\
{"GetActorSpellsActiveEffectCount", ActorFunctions::GetActorSpellsActiveEffectCount},\
{"GetActorSpellsActiveEffectId", ActorFunctions::GetActorSpellsActiveEffectId},\
{"GetActorSpellsActiveEffectArg", ActorFunctions::GetActorSpellsActiveEffectArg},\
{"GetActorSpellsActiveEffectMagnitude", ActorFunctions::GetActorSpellsActiveEffectMagnitude},\
{"GetActorSpellsActiveEffectDuration", ActorFunctions::GetActorSpellsActiveEffectDuration},\
{"GetActorSpellsActiveEffectTimeLeft", ActorFunctions::GetActorSpellsActiveEffectTimeLeft},\
\
{"DoesActorHavePosition", ActorFunctions::DoesActorHavePosition},\
{"DoesActorHaveStatsDynamic", ActorFunctions::DoesActorHaveStatsDynamic},\
\
@ -75,6 +86,7 @@
{"SetActorDeathState", ActorFunctions::SetActorDeathState},\
{"SetActorDeathInstant", ActorFunctions::SetActorDeathInstant},\
{"SetActorSound", ActorFunctions::SetActorSound},\
{"SetActorSpellsActiveAction", ActorFunctions::SetActorSpellsActiveAction},\
\
{"SetActorAIAction", ActorFunctions::SetActorAIAction},\
{"SetActorAITargetToPlayer", ActorFunctions::SetActorAITargetToPlayer},\
@ -87,6 +99,9 @@
{"EquipActorItem", ActorFunctions::EquipActorItem},\
{"UnequipActorItem", ActorFunctions::UnequipActorItem},\
\
{"AddActorSpellActive", ActorFunctions::AddActorSpellActive},\
{"AddActorSpellActiveEffect", ActorFunctions::AddActorSpellActiveEffect},\
\
{"AddActor", ActorFunctions::AddActor},\
\
{"SendActorList", ActorFunctions::SendActorList},\
@ -94,6 +109,7 @@
{"SendActorPosition", ActorFunctions::SendActorPosition},\
{"SendActorStatsDynamic", ActorFunctions::SendActorStatsDynamic},\
{"SendActorEquipment", ActorFunctions::SendActorEquipment},\
{"SendActorSpellsActiveChanges", ActorFunctions::SendActorSpellsActiveChanges},\
{"SendActorSpeech", ActorFunctions::SendActorSpeech},\
{"SendActorDeath", ActorFunctions::SendActorDeath},\
{"SendActorAI", ActorFunctions::SendActorAI},\
@ -414,6 +430,99 @@ public:
*/
static unsigned int GetActorDeathState(unsigned int index) noexcept;
/**
* \brief Get the number of indexes in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \return The number of indexes for spells active changes.
*/
static unsigned int GetActorSpellsActiveChangesSize(unsigned int actorIndex) noexcept;
/**
* \brief Get the action type used in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \return The action type (0 for SET, 1 for ADD, 2 for REMOVE).
*/
static unsigned int GetActorSpellsActiveChangesAction(unsigned int actorIndex) noexcept;
/**
* \brief Get the spell id at a certain index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \return The spell id.
*/
static const char* GetActorSpellsActiveId(unsigned int actorIndex, unsigned int spellIndex) noexcept;
/**
* \brief Get the spell display name at a certain index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \return The spell display name.
*/
static const char* GetActorSpellsActiveDisplayName(unsigned int actorIndex, unsigned int spellIndex) noexcept;
/**
* \brief Get the number of effects at an index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \return The number of effects.
*/
static unsigned int GetActorSpellsActiveEffectCount(unsigned int actorIndex, unsigned int spellIndex) noexcept;
/**
* \brief Get the id for an effect index at a spell index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \param effectIndex The index of the effect.
* \return The id of the effect.
*/
static unsigned int GetActorSpellsActiveEffectId(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept;
/**
* \brief Get the arg for an effect index at a spell index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \param effectIndex The index of the effect.
* \return The arg of the effect.
*/
static int GetActorSpellsActiveEffectArg(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept;
/**
* \brief Get the magnitude for an effect index at a spell index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \param effectIndex The index of the effect.
* \return The magnitude of the effect.
*/
static double GetActorSpellsActiveEffectMagnitude(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept;
/**
* \brief Get the duration for an effect index at a spell index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \param effectIndex The index of the effect.
* \return The duration of the effect.
*/
static double GetActorSpellsActiveEffectDuration(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept;
/**
* \brief Get the time left for an effect index at a spell index in an actor's latest spells active changes.
*
* \param actorIndex The index of the actor.
* \param spellIndex The index of the spell.
* \param effectIndex The index of the effect.
* \return The time left for the effect.
*/
static double GetActorSpellsActiveEffectTimeLeft(unsigned int actorIndex, unsigned int spellIndex, unsigned int effectIndex) noexcept;
/**
* \brief Check whether there is any positional data for the actor at a certain index in
* the read actor list.
@ -610,6 +719,15 @@ public:
*/
static void SetActorDeathInstant(bool isInstant) noexcept;
/**
* \brief Set the action type in the spells active changes of the temporary actor
* stored on the server.
*
* \param action The action (0 for SET, 1 for ADD, 2 for REMOVE).
* \return void
*/
static void SetActorSpellsActiveAction(unsigned char action) noexcept;
/**
* \brief Set the AI action of the temporary actor stored on the server.
*
@ -693,6 +811,30 @@ public:
*/
static void UnequipActorItem(unsigned short slot) noexcept;
/**
* \brief Add a new active spell to the spells active changes for the temporary actor stored,
* on the server, using the temporary effect values stored so far.
*
* \param spellId The spellId of the spell.
* \param displayName The displayName of the spell.
* \return void
*/
static void AddActorSpellActive(const char* spellId, const char* displayName) noexcept;
/**
* \brief Add a new effect to the next active spell that will be added to the temporary actor
* stored on the server.
*
* \param effectId The id of the effect.
* \param magnitude The magnitude of the effect.
* \param duration The duration of the effect.
* \param timeLeft The timeLeft for the effect.
* \param arg The arg of the effect when applicable, e.g. the skill used for Fortify Skill or the attribute
* used for Fortify Attribute.
* \return void
*/
static void AddActorSpellActiveEffect(int effectId, double magnitude, double duration, double timeLeft, int arg) noexcept;
/**
* \brief Add a copy of the server's temporary actor to the server's temporary actor list.
*
@ -760,6 +902,18 @@ public:
*/
static void SendActorEquipment(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept;
/**
* \brief Send an ActorSpellsActive packet.
*
* \param sendToOtherVisitors Whether this packet should be sent to cell visitors other
* than the player attached to the packet (false by default).
* \param skipAttachedPlayer Whether the packet should skip being sent to the player attached
* to the packet (false by default).
*
* \return void
*/
static void SendActorSpellsActiveChanges(bool sendToOtherVisitors, bool skipAttachedPlayer) noexcept;
/**
* \brief Send an ActorSpeech packet.
*

Loading…
Cancel
Save