2021-08-27 20:07:50 +02:00
|
|
|
#include "spelleffects.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2022-09-08 21:08:59 +02:00
|
|
|
#include <components/esm3/loadcrea.hpp>
|
2022-09-05 19:35:15 +02:00
|
|
|
#include <components/esm3/loadench.hpp>
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/loadmgef.hpp>
|
2022-09-08 21:08:59 +02:00
|
|
|
#include <components/esm3/loadstat.hpp>
|
2022-06-29 00:32:11 +02:00
|
|
|
#include <components/misc/resourcehelpers.hpp>
|
2021-08-27 20:07:50 +02:00
|
|
|
#include <components/misc/rng.hpp>
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/mechanicsmanager.hpp"
|
|
|
|
#include "../mwbase/soundmanager.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
|
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
#include "../mwmechanics/aifollow.hpp"
|
|
|
|
#include "../mwmechanics/npcstats.hpp"
|
|
|
|
#include "../mwmechanics/spellresistance.hpp"
|
2021-10-10 16:28:45 +02:00
|
|
|
#include "../mwmechanics/spellutil.hpp"
|
2021-08-27 20:07:50 +02:00
|
|
|
#include "../mwmechanics/summoning.hpp"
|
|
|
|
|
|
|
|
#include "../mwrender/animation.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/actionequip.hpp"
|
|
|
|
#include "../mwworld/actionteleport.hpp"
|
|
|
|
#include "../mwworld/cellstore.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
#include "../mwworld/inventorystore.hpp"
|
|
|
|
#include "../mwworld/player.hpp"
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
float roll(const ESM::ActiveEffect& effect)
|
|
|
|
{
|
|
|
|
if (effect.mMinMagnitude == effect.mMaxMagnitude)
|
|
|
|
return effect.mMinMagnitude;
|
2022-03-06 21:56:02 +02:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
|
|
|
return effect.mMinMagnitude + Misc::Rng::rollDice(effect.mMaxMagnitude - effect.mMinMagnitude + 1, prng);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
|
2022-07-16 16:37:31 +02:00
|
|
|
void modifyAiSetting(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect,
|
|
|
|
ESM::MagicEffect::Effects creatureEffect, MWMechanics::AiSetting setting, float magnitude, bool& invalid)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
if (target == MWMechanics::getPlayer() || (effect.mEffectId == creatureEffect) == target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
auto stat = creatureStats.getAiSetting(setting);
|
2022-01-03 19:17:56 +01:00
|
|
|
stat.setModifier(static_cast<int>(stat.getModifier() + magnitude));
|
2021-08-27 20:07:50 +02:00
|
|
|
creatureStats.setAiSetting(setting, stat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void adjustDynamicStat(const MWWorld::Ptr& target, int index, float magnitude, bool allowDecreaseBelowZero = false,
|
|
|
|
bool allowIncreaseAboveModified = false)
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
auto stat = creatureStats.getDynamic(index);
|
|
|
|
stat.setCurrent(stat.getCurrent() + magnitude, allowDecreaseBelowZero, allowIncreaseAboveModified);
|
|
|
|
creatureStats.setDynamic(index, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void modDynamicStat(const MWWorld::Ptr& target, int index, float magnitude)
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
auto stat = creatureStats.getDynamic(index);
|
|
|
|
float current = stat.getCurrent();
|
2022-02-10 20:32:59 +01:00
|
|
|
stat.setBase(std::max(0.f, stat.getBase() + magnitude));
|
2021-10-06 17:14:00 +02:00
|
|
|
stat.setCurrent(current + magnitude);
|
2021-08-27 20:07:50 +02:00
|
|
|
creatureStats.setDynamic(index, stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void damageAttribute(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, float magnitude)
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
auto attr = creatureStats.getAttribute(effect.mArg);
|
2022-01-27 19:56:27 +01:00
|
|
|
if (effect.mEffectId == ESM::MagicEffect::DamageAttribute)
|
|
|
|
magnitude = std::min(attr.getModified(), magnitude);
|
2021-08-27 20:07:50 +02:00
|
|
|
attr.damage(magnitude);
|
|
|
|
creatureStats.setAttribute(effect.mArg, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void restoreAttribute(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, float magnitude)
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
auto attr = creatureStats.getAttribute(effect.mArg);
|
|
|
|
attr.restore(magnitude);
|
|
|
|
creatureStats.setAttribute(effect.mArg, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fortifyAttribute(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, float magnitude)
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
auto attr = creatureStats.getAttribute(effect.mArg);
|
|
|
|
attr.setModifier(attr.getModifier() + magnitude);
|
|
|
|
creatureStats.setAttribute(effect.mArg, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void damageSkill(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, float magnitude)
|
|
|
|
{
|
|
|
|
auto& npcStats = target.getClass().getNpcStats(target);
|
|
|
|
auto& skill = npcStats.getSkill(effect.mArg);
|
2022-01-27 19:56:27 +01:00
|
|
|
if (effect.mEffectId == ESM::MagicEffect::DamageSkill)
|
|
|
|
magnitude = std::min(skill.getModified(), magnitude);
|
2021-08-27 20:07:50 +02:00
|
|
|
skill.damage(magnitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
void restoreSkill(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, float magnitude)
|
|
|
|
{
|
|
|
|
auto& npcStats = target.getClass().getNpcStats(target);
|
|
|
|
auto& skill = npcStats.getSkill(effect.mArg);
|
|
|
|
skill.restore(magnitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
void fortifySkill(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect, float magnitude)
|
|
|
|
{
|
|
|
|
auto& npcStats = target.getClass().getNpcStats(target);
|
|
|
|
auto& skill = npcStats.getSkill(effect.mArg);
|
|
|
|
skill.setModifier(skill.getModifier() + magnitude);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool disintegrateSlot(const MWWorld::Ptr& ptr, int slot, float disintegrate)
|
|
|
|
{
|
|
|
|
MWWorld::InventoryStore& inv = ptr.getClass().getInventoryStore(ptr);
|
|
|
|
MWWorld::ContainerStoreIterator item = inv.getSlot(slot);
|
|
|
|
|
|
|
|
if (item != inv.end()
|
|
|
|
&& (item.getType() == MWWorld::ContainerStore::Type_Armor
|
|
|
|
|| item.getType() == MWWorld::ContainerStore::Type_Weapon))
|
|
|
|
{
|
|
|
|
if (!item->getClass().hasItemHealth(*item))
|
|
|
|
return false;
|
|
|
|
int charge = item->getClass().getItemHealth(*item);
|
|
|
|
if (charge == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Store remainder of disintegrate amount (automatically subtracted if > 1)
|
|
|
|
item->getCellRef().applyChargeRemainderToBeSubtracted(disintegrate - std::floor(disintegrate));
|
|
|
|
|
|
|
|
charge = item->getClass().getItemHealth(*item);
|
|
|
|
charge -= std::min(static_cast<int>(disintegrate), charge);
|
|
|
|
item->getCellRef().setCharge(charge);
|
|
|
|
|
|
|
|
if (charge == 0)
|
|
|
|
{
|
|
|
|
// Will unequip the broken item and try to find a replacement
|
|
|
|
if (ptr != MWMechanics::getPlayer())
|
2023-01-16 23:51:04 +01:00
|
|
|
inv.autoEquip();
|
2021-08-27 20:07:50 +02:00
|
|
|
else
|
2023-01-16 23:51:04 +01:00
|
|
|
inv.unequipItem(*item);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getBoundItemSlot(const MWWorld::Ptr& boundPtr)
|
|
|
|
{
|
|
|
|
const auto [slots, _] = boundPtr.getClass().getEquipmentSlots(boundPtr);
|
|
|
|
if (!slots.empty())
|
|
|
|
return slots[0];
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
void addBoundItem(const ESM::RefId& itemId, const MWWorld::Ptr& actor)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
2023-01-16 23:51:04 +01:00
|
|
|
MWWorld::Ptr boundPtr = *store.MWWorld::ContainerStore::add(itemId, 1);
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
int slot = getBoundItemSlot(boundPtr);
|
|
|
|
auto prevItem = slot >= 0 ? store.getSlot(slot) : store.end();
|
|
|
|
|
|
|
|
MWWorld::ActionEquip action(boundPtr);
|
|
|
|
action.execute(actor);
|
|
|
|
|
|
|
|
if (actor != MWMechanics::getPlayer())
|
|
|
|
return;
|
|
|
|
|
|
|
|
MWWorld::Ptr newItem;
|
|
|
|
auto it = slot >= 0 ? store.getSlot(slot) : store.end();
|
|
|
|
// Equip can fail because beast races cannot equip boots/helmets
|
|
|
|
if (it != store.end())
|
|
|
|
newItem = *it;
|
|
|
|
|
|
|
|
if (newItem.isEmpty() || boundPtr != newItem)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
|
|
|
|
|
|
|
// change draw state only if the item is in player's right hand
|
|
|
|
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
2022-07-17 19:36:48 +03:00
|
|
|
player.setDrawState(MWMechanics::DrawState::Weapon);
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
if (prevItem != store.end())
|
|
|
|
player.setPreviousItem(itemId, prevItem->getCellRef().getRefId());
|
|
|
|
}
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
void removeBoundItem(const ESM::RefId& itemId, const MWWorld::Ptr& actor)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
2022-10-18 09:26:55 +02:00
|
|
|
auto item = std::find_if(
|
|
|
|
store.begin(), store.end(), [&](const auto& it) { return it.getCellRef().getRefId() == itemId; });
|
2021-08-27 20:07:50 +02:00
|
|
|
if (item == store.end())
|
|
|
|
return;
|
|
|
|
int slot = getBoundItemSlot(*item);
|
|
|
|
|
|
|
|
auto currentItem = store.getSlot(slot);
|
|
|
|
|
2022-10-18 09:26:55 +02:00
|
|
|
bool wasEquipped = currentItem != store.end() && currentItem->getCellRef().getRefId() == itemId;
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2022-11-10 01:17:52 +03:00
|
|
|
if (wasEquipped)
|
2023-01-16 23:51:04 +01:00
|
|
|
store.remove(*currentItem, 1);
|
2022-11-10 01:17:52 +03:00
|
|
|
else
|
2023-01-16 23:51:04 +01:00
|
|
|
store.remove(itemId, 1);
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2022-11-10 01:17:52 +03:00
|
|
|
if (actor != MWMechanics::getPlayer())
|
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
// Equip a replacement
|
|
|
|
if (!wasEquipped)
|
|
|
|
return;
|
|
|
|
|
2021-10-11 11:46:21 +00:00
|
|
|
auto type = currentItem->getType();
|
|
|
|
if (type != ESM::Weapon::sRecordId && type != ESM::Armor::sRecordId && type != ESM::Clothing::sRecordId)
|
2021-08-27 20:07:50 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (actor.getClass().getCreatureStats(actor).isDead())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!actor.getClass().hasInventoryStore(actor))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
|
|
|
|
return;
|
|
|
|
|
2023-01-16 23:51:04 +01:00
|
|
|
actor.getClass().getInventoryStore(actor).autoEquip();
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
ESM::RefId prevItemId = player.getPreviousItem(itemId);
|
2021-08-27 20:07:50 +02:00
|
|
|
player.erasePreviousItem(itemId);
|
|
|
|
|
|
|
|
if (!prevItemId.empty() && wasEquipped)
|
|
|
|
{
|
|
|
|
// Find previous item (or its replacement) by id.
|
|
|
|
// we should equip previous item only if expired bound item was equipped.
|
|
|
|
MWWorld::Ptr prevItem = store.findReplacement(prevItemId);
|
|
|
|
if (!prevItem.isEmpty())
|
|
|
|
{
|
|
|
|
MWWorld::ActionEquip action(prevItem);
|
|
|
|
action.execute(actor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCorprusEffect(const MWMechanics::ActiveSpells::ActiveEffect& effect, bool harmfulOnly = false)
|
|
|
|
{
|
|
|
|
if (effect.mFlags & ESM::ActiveEffect::Flag_Applied && effect.mEffectId != ESM::MagicEffect::Corprus)
|
|
|
|
{
|
|
|
|
const auto* magicEffect
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effect.mEffectId);
|
|
|
|
if (magicEffect->mData.mFlags & ESM::MagicEffect::Flags::AppliedOnce
|
|
|
|
&& (!harmfulOnly || magicEffect->mData.mFlags & ESM::MagicEffect::Flags::Harmful))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
void absorbSpell(const ESM::RefId& spellId, const MWWorld::Ptr& caster, const MWWorld::Ptr& target)
|
2021-10-10 16:28:45 +02:00
|
|
|
{
|
|
|
|
const auto& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
const ESM::Static* absorbStatic = esmStore.get<ESM::Static>().find(ESM::RefId::stringRefId("VFX_Absorb"));
|
2021-10-10 16:28:45 +02:00
|
|
|
MWRender::Animation* animation = MWBase::Environment::get().getWorld()->getAnimation(target);
|
|
|
|
if (animation && !absorbStatic->mModel.empty())
|
2022-06-29 00:32:11 +02:00
|
|
|
{
|
|
|
|
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
animation->addEffect(Misc::ResourceHelpers::correctMeshPath(absorbStatic->mModel, vfs),
|
2022-08-23 18:25:25 +02:00
|
|
|
ESM::MagicEffect::SpellAbsorption, false);
|
2022-06-29 00:32:11 +02:00
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
const ESM::Spell* spell = esmStore.get<ESM::Spell>().search(spellId);
|
|
|
|
int spellCost = 0;
|
|
|
|
if (spell)
|
|
|
|
{
|
|
|
|
spellCost = MWMechanics::calcSpellCost(*spell);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const ESM::Enchantment* enchantment = esmStore.get<ESM::Enchantment>().search(spellId);
|
|
|
|
if (enchantment)
|
|
|
|
spellCost = MWMechanics::getEffectiveEnchantmentCastCost(
|
|
|
|
static_cast<float>(enchantment->mData.mCost), caster);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Magicka is increased by the cost of the spell
|
|
|
|
auto& stats = target.getClass().getCreatureStats(target);
|
|
|
|
auto magicka = stats.getMagicka();
|
|
|
|
magicka.setCurrent(magicka.getCurrent() + spellCost);
|
|
|
|
stats.setMagicka(magicka);
|
|
|
|
}
|
|
|
|
|
2022-09-03 19:49:59 +02:00
|
|
|
MWMechanics::MagicApplicationResult::Type applyProtections(const MWWorld::Ptr& target, const MWWorld::Ptr& caster,
|
2021-10-10 16:28:45 +02:00
|
|
|
const MWMechanics::ActiveSpells::ActiveSpellParams& spellParams, ESM::ActiveEffect& effect,
|
|
|
|
const ESM::MagicEffect* magicEffect)
|
|
|
|
{
|
|
|
|
auto& stats = target.getClass().getCreatureStats(target);
|
|
|
|
auto& magnitudes = stats.getMagicEffects();
|
|
|
|
// Apply reflect and spell absorption
|
|
|
|
if (target != caster && spellParams.getType() != ESM::ActiveSpells::Type_Enchantment
|
|
|
|
&& spellParams.getType() != ESM::ActiveSpells::Type_Permanent)
|
|
|
|
{
|
2022-09-03 20:02:58 +02:00
|
|
|
bool canReflect = !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable)
|
|
|
|
&& !(effect.mFlags & ESM::ActiveEffect::Flag_Ignore_Reflect)
|
|
|
|
&& magnitudes.get(ESM::MagicEffect::Reflect).getMagnitude() > 0.f && !caster.isEmpty();
|
2021-10-10 16:28:45 +02:00
|
|
|
bool canAbsorb = !(effect.mFlags & ESM::ActiveEffect::Flag_Ignore_SpellAbsorption)
|
|
|
|
&& magnitudes.get(ESM::MagicEffect::SpellAbsorption).getMagnitude() > 0.f;
|
|
|
|
if (canReflect || canAbsorb)
|
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
2021-10-10 16:28:45 +02:00
|
|
|
for (const auto& activeParam : stats.getActiveSpells())
|
|
|
|
{
|
|
|
|
for (const auto& activeEffect : activeParam.getEffects())
|
|
|
|
{
|
|
|
|
if (!(activeEffect.mFlags & ESM::ActiveEffect::Flag_Applied))
|
|
|
|
continue;
|
|
|
|
if (activeEffect.mEffectId == ESM::MagicEffect::Reflect)
|
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
if (canReflect && Misc::Rng::roll0to99(prng) < activeEffect.mMagnitude)
|
2021-10-10 16:28:45 +02:00
|
|
|
{
|
2022-09-03 19:49:59 +02:00
|
|
|
return MWMechanics::MagicApplicationResult::Type::REFLECTED;
|
2021-10-10 16:28:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (activeEffect.mEffectId == ESM::MagicEffect::SpellAbsorption)
|
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
if (canAbsorb && Misc::Rng::roll0to99(prng) < activeEffect.mMagnitude)
|
2021-10-10 16:28:45 +02:00
|
|
|
{
|
|
|
|
absorbSpell(spellParams.getId(), caster, target);
|
2022-09-03 19:49:59 +02:00
|
|
|
return MWMechanics::MagicApplicationResult::Type::REMOVED;
|
2021-10-10 16:28:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Notify the target actor they've been hit
|
|
|
|
bool isHarmful = magicEffect->mData.mFlags & ESM::MagicEffect::Harmful;
|
|
|
|
if (target.getClass().isActor() && target != caster && !caster.isEmpty() && isHarmful)
|
|
|
|
target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true);
|
|
|
|
// Apply resistances
|
|
|
|
if (!(effect.mFlags & ESM::ActiveEffect::Flag_Ignore_Resistances))
|
|
|
|
{
|
|
|
|
const ESM::Spell* spell = nullptr;
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Temporary)
|
|
|
|
spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellParams.getId());
|
|
|
|
float magnitudeMult
|
|
|
|
= MWMechanics::getEffectMultiplier(effect.mEffectId, target, caster, spell, &magnitudes);
|
|
|
|
if (magnitudeMult == 0)
|
|
|
|
{
|
|
|
|
// Fully resisted, show message
|
|
|
|
if (target == MWMechanics::getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}");
|
|
|
|
else if (caster == MWMechanics::getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}");
|
2022-09-03 19:49:59 +02:00
|
|
|
return MWMechanics::MagicApplicationResult::Type::REMOVED;
|
2021-10-10 16:28:45 +02:00
|
|
|
}
|
|
|
|
effect.mMinMagnitude *= magnitudeMult;
|
|
|
|
effect.mMaxMagnitude *= magnitudeMult;
|
|
|
|
}
|
2022-09-03 19:49:59 +02:00
|
|
|
return MWMechanics::MagicApplicationResult::Type::APPLIED;
|
2021-10-10 16:28:45 +02:00
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
static const std::map<int, std::string> sBoundItemsMap{
|
|
|
|
{ ESM::MagicEffect::BoundBattleAxe, "sMagicBoundBattleAxeID" },
|
|
|
|
{ ESM::MagicEffect::BoundBoots, "sMagicBoundBootsID" },
|
|
|
|
{ ESM::MagicEffect::BoundCuirass, "sMagicBoundCuirassID" },
|
|
|
|
{ ESM::MagicEffect::BoundDagger, "sMagicBoundDaggerID" },
|
|
|
|
{ ESM::MagicEffect::BoundGloves, "sMagicBoundLeftGauntletID" },
|
|
|
|
{ ESM::MagicEffect::BoundHelm, "sMagicBoundHelmID" },
|
|
|
|
{ ESM::MagicEffect::BoundLongbow, "sMagicBoundLongbowID" },
|
|
|
|
{ ESM::MagicEffect::BoundLongsword, "sMagicBoundLongswordID" },
|
|
|
|
{ ESM::MagicEffect::BoundMace, "sMagicBoundMaceID" },
|
|
|
|
{ ESM::MagicEffect::BoundShield, "sMagicBoundShieldID" },
|
2022-09-14 00:08:19 +02:00
|
|
|
{ ESM::MagicEffect::BoundSpear, "sMagicBoundSpearID" },
|
2021-08-27 20:07:50 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
|
2022-09-03 19:49:59 +02:00
|
|
|
void applyMagicEffect(const MWWorld::Ptr& target, const MWWorld::Ptr& caster,
|
|
|
|
const ActiveSpells::ActiveSpellParams& spellParams, ESM::ActiveEffect& effect, bool& invalid,
|
|
|
|
bool& receivedMagicDamage, bool& affectedHealth, bool& recalculateMagicka)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
|
|
|
bool godmode = target == getPlayer() && world->getGodModeState();
|
|
|
|
switch (effect.mEffectId)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::CureCommonDisease:
|
|
|
|
target.getClass().getCreatureStats(target).getSpells().purgeCommonDisease();
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::CureBlightDisease:
|
|
|
|
target.getClass().getCreatureStats(target).getSpells().purgeBlightDisease();
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::RemoveCurse:
|
|
|
|
target.getClass().getCreatureStats(target).getSpells().purgeCurses();
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::CureCorprusDisease:
|
|
|
|
target.getClass().getCreatureStats(target).getActiveSpells().purgeEffect(
|
|
|
|
target, ESM::MagicEffect::Corprus);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::CurePoison:
|
|
|
|
target.getClass().getCreatureStats(target).getActiveSpells().purgeEffect(
|
|
|
|
target, ESM::MagicEffect::Poison);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::CureParalyzation:
|
|
|
|
target.getClass().getCreatureStats(target).getActiveSpells().purgeEffect(
|
|
|
|
target, ESM::MagicEffect::Paralyze);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::Dispel:
|
|
|
|
// Dispel removes entire spells at once
|
|
|
|
target.getClass().getCreatureStats(target).getActiveSpells().purge(
|
|
|
|
[magnitude = effect.mMagnitude](const ActiveSpells::ActiveSpellParams& params) {
|
|
|
|
if (params.getType() == ESM::ActiveSpells::Type_Temporary)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
const ESM::Spell* spell
|
|
|
|
= MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(
|
|
|
|
params.getId());
|
2022-03-06 21:56:02 +02:00
|
|
|
if (spell && spell->mData.mType == ESM::Spell::ST_Spell)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
|
|
|
return Misc::Rng::roll0to99(prng) < magnitude;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
return false;
|
2022-09-22 21:26:05 +03:00
|
|
|
},
|
|
|
|
target);
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::AlmsiviIntervention:
|
|
|
|
case ESM::MagicEffect::DivineIntervention:
|
|
|
|
if (target != getPlayer())
|
|
|
|
invalid = true;
|
|
|
|
else if (world->isTeleportingEnabled())
|
|
|
|
{
|
|
|
|
std::string_view marker
|
|
|
|
= (effect.mEffectId == ESM::MagicEffect::DivineIntervention) ? "divinemarker" : "templemarker";
|
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type
The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID
Slowly going through all the changes to make, still hundreds of errors
a lot of functions/structures use std::string or stringview to designate an ID. So it takes time
Continues slowly replacing ids. There are technically more and more compilation errors
I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type
Continue moving forward, changes to the stores
slowly moving along
Starting to see the fruit of those changes.
still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type.
More replacements. Things are starting to get easier
I can see more and more often the issue is that the function is awaiting a RefId, but is given a string
there is less need to go down functions and to fix a long list of them.
Still moving forward, and for the first time error count is going down!
Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably
Cells are back to using string for the name, haven't fixed everything yet. Many other changes
Under the bar of 400 compilation errors.
more good progress <100 compile errors!
More progress
Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string
some more progress on other fronts
Mostly game settings clean
one error opened a lot of other errors. Down to 18, but more will prbably appear
only link errors left??
Fixed link errors
OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
|
|
|
world->teleportToClosestMarker(target, ESM::RefId::stringRefId(marker));
|
2022-03-06 21:56:02 +02:00
|
|
|
if (!caster.isEmpty())
|
|
|
|
{
|
|
|
|
MWRender::Animation* anim = world->getAnimation(caster);
|
2021-08-27 20:07:50 +02:00
|
|
|
anim->removeEffect(effect.mEffectId);
|
2022-10-18 09:26:55 +02:00
|
|
|
const ESM::Static* fx
|
|
|
|
= world->getStore().get<ESM::Static>().search(ESM::RefId::stringRefId("VFX_Summon_end"));
|
2022-09-22 21:26:05 +03:00
|
|
|
if (fx)
|
|
|
|
{
|
2022-03-06 21:56:02 +02:00
|
|
|
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
|
|
|
|
anim->addEffect(Misc::ResourceHelpers::correctMeshPath(fx->mModel, vfs), -1);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2022-03-06 21:56:02 +02:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
else if (caster == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sTeleportDisabled}");
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::Mark:
|
|
|
|
if (target != getPlayer())
|
|
|
|
invalid = true;
|
|
|
|
else if (world->isTeleportingEnabled())
|
2022-08-27 13:07:59 +02:00
|
|
|
world->getPlayer().markPosition(target.getCell(), target.getRefData().getPosition());
|
|
|
|
else if (caster == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sTeleportDisabled}");
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2022-08-27 13:07:59 +02:00
|
|
|
case ESM::MagicEffect::Recall:
|
2021-08-27 20:07:50 +02:00
|
|
|
if (target != getPlayer())
|
|
|
|
invalid = true;
|
|
|
|
else if (world->isTeleportingEnabled())
|
|
|
|
{
|
|
|
|
MWWorld::CellStore* markedCell = nullptr;
|
|
|
|
ESM::Position markedPosition;
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
world->getPlayer().getMarkedPosition(markedCell, markedPosition);
|
|
|
|
if (markedCell)
|
2022-06-29 00:32:11 +02:00
|
|
|
{
|
2023-01-19 17:31:45 +01:00
|
|
|
std::string_view dest;
|
2022-06-29 00:32:11 +02:00
|
|
|
if (!markedCell->isExterior())
|
2023-01-28 12:07:47 +01:00
|
|
|
dest = markedCell->getCell()->getNameId();
|
2022-12-01 19:37:35 +01:00
|
|
|
MWWorld::ActionTeleport action(dest, markedPosition, false);
|
2022-06-29 00:32:11 +02:00
|
|
|
action.execute(target);
|
|
|
|
if (!caster.isEmpty())
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-06-29 00:32:11 +02:00
|
|
|
MWRender::Animation* anim = world->getAnimation(caster);
|
|
|
|
anim->removeEffect(effect.mEffectId);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2022-06-29 00:32:11 +02:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
else if (caster == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sTeleportDisabled}");
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::CommandCreature:
|
|
|
|
case ESM::MagicEffect::CommandHumanoid:
|
|
|
|
if (caster.isEmpty() || !caster.getClass().isActor() || target == getPlayer()
|
|
|
|
|| (effect.mEffectId == ESM::MagicEffect::CommandCreature) == target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else if (effect.mMagnitude >= target.getClass().getCreatureStats(target).getLevel())
|
|
|
|
{
|
|
|
|
MWMechanics::AiFollow package(caster, true);
|
|
|
|
target.getClass().getCreatureStats(target).getAiSequence().stack(package, target);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::ExtraSpell:
|
|
|
|
if (target.getClass().hasInventoryStore(target))
|
|
|
|
{
|
|
|
|
auto& store = target.getClass().getInventoryStore(target);
|
2023-01-16 23:51:04 +01:00
|
|
|
store.unequipAll();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
else
|
|
|
|
invalid = true;
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::TurnUndead:
|
|
|
|
if (target.getClass().isNpc()
|
|
|
|
|| target.get<ESM::Creature>()->mBase->mData.mType != ESM::Creature::Undead)
|
|
|
|
invalid = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
Stat<int> stat = creatureStats.getAiSetting(AiSetting::Flee);
|
|
|
|
stat.setModifier(static_cast<int>(stat.getModifier() + effect.mMagnitude));
|
2022-09-03 19:49:59 +02:00
|
|
|
creatureStats.setAiSetting(AiSetting::Flee, stat);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::FrenzyCreature:
|
|
|
|
case ESM::MagicEffect::FrenzyHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::FrenzyCreature, AiSetting::Fight, effect.mMagnitude, invalid);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::CalmCreature:
|
|
|
|
case ESM::MagicEffect::CalmHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::CalmCreature, AiSetting::Fight, -effect.mMagnitude, invalid);
|
2021-08-27 20:07:50 +02:00
|
|
|
if (!invalid && effect.mMagnitude > 0)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
creatureStats.getAiSequence().stopCombat();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DemoralizeCreature:
|
|
|
|
case ESM::MagicEffect::DemoralizeHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
2021-08-27 20:07:50 +02:00
|
|
|
target, effect, ESM::MagicEffect::DemoralizeCreature, AiSetting::Flee, effect.mMagnitude, invalid);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::RallyCreature:
|
|
|
|
case ESM::MagicEffect::RallyHumanoid:
|
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::RallyCreature, AiSetting::Flee, -effect.mMagnitude, invalid);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2022-09-05 18:04:31 +02:00
|
|
|
case ESM::MagicEffect::Sound:
|
2021-10-10 16:28:45 +02:00
|
|
|
if (target == getPlayer())
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
const auto& magnitudes = target.getClass().getCreatureStats(target).getMagicEffects();
|
2022-09-05 18:04:31 +02:00
|
|
|
float volume = std::clamp(
|
2021-08-27 20:07:50 +02:00
|
|
|
(magnitudes.get(effect.mEffectId).getModifier() + effect.mMagnitude) / 100.f, 0.f, 1.f);
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(target,
|
|
|
|
ESM::RefId::stringRefId("magic sound"), volume, 1.f, MWSound::Type::Sfx,
|
|
|
|
MWSound::PlayMode::LoopNoEnv);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::SummonScamp:
|
|
|
|
case ESM::MagicEffect::SummonClannfear:
|
|
|
|
case ESM::MagicEffect::SummonDaedroth:
|
|
|
|
case ESM::MagicEffect::SummonDremora:
|
|
|
|
case ESM::MagicEffect::SummonAncestralGhost:
|
|
|
|
case ESM::MagicEffect::SummonSkeletalMinion:
|
|
|
|
case ESM::MagicEffect::SummonBonewalker:
|
|
|
|
case ESM::MagicEffect::SummonGreaterBonewalker:
|
|
|
|
case ESM::MagicEffect::SummonBonelord:
|
|
|
|
case ESM::MagicEffect::SummonWingedTwilight:
|
|
|
|
case ESM::MagicEffect::SummonHunger:
|
|
|
|
case ESM::MagicEffect::SummonGoldenSaint:
|
|
|
|
case ESM::MagicEffect::SummonFlameAtronach:
|
|
|
|
case ESM::MagicEffect::SummonFrostAtronach:
|
|
|
|
case ESM::MagicEffect::SummonStormAtronach:
|
|
|
|
case ESM::MagicEffect::SummonCenturionSphere:
|
|
|
|
case ESM::MagicEffect::SummonFabricant:
|
|
|
|
case ESM::MagicEffect::SummonWolf:
|
|
|
|
case ESM::MagicEffect::SummonBear:
|
|
|
|
case ESM::MagicEffect::SummonBonewolf:
|
|
|
|
case ESM::MagicEffect::SummonCreature04:
|
|
|
|
case ESM::MagicEffect::SummonCreature05:
|
2022-08-19 14:51:52 +00:00
|
|
|
if (!target.isInCell())
|
2021-08-27 20:07:50 +02:00
|
|
|
invalid = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2021-08-27 20:07:50 +02:00
|
|
|
effect.mArg = summonCreature(effect.mEffectId, target);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::BoundGloves:
|
|
|
|
if (!target.getClass().hasInventoryStore(target))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
invalid = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
|
|
|
}
|
2022-10-18 09:26:55 +02:00
|
|
|
addBoundItem(ESM::RefId::stringRefId(world->getStore()
|
|
|
|
.get<ESM::GameSetting>()
|
|
|
|
.find("sMagicBoundRightGauntletID")
|
|
|
|
->mValue.getString()),
|
2022-09-22 21:26:05 +03:00
|
|
|
target);
|
2021-08-27 20:07:50 +02:00
|
|
|
// left gauntlet added below
|
|
|
|
[[fallthrough]];
|
|
|
|
case ESM::MagicEffect::BoundDagger:
|
|
|
|
case ESM::MagicEffect::BoundLongsword:
|
|
|
|
case ESM::MagicEffect::BoundMace:
|
|
|
|
case ESM::MagicEffect::BoundBattleAxe:
|
|
|
|
case ESM::MagicEffect::BoundSpear:
|
|
|
|
case ESM::MagicEffect::BoundLongbow:
|
|
|
|
case ESM::MagicEffect::BoundCuirass:
|
|
|
|
case ESM::MagicEffect::BoundHelm:
|
|
|
|
case ESM::MagicEffect::BoundBoots:
|
|
|
|
case ESM::MagicEffect::BoundShield:
|
|
|
|
if (!target.getClass().hasInventoryStore(target))
|
|
|
|
invalid = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
const std::string& item = sBoundItemsMap.at(effect.mEffectId);
|
2022-10-18 09:26:55 +02:00
|
|
|
addBoundItem(ESM::RefId::stringRefId(
|
|
|
|
world->getStore().get<ESM::GameSetting>().find(item)->mValue.getString()),
|
|
|
|
target);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::FireDamage:
|
|
|
|
case ESM::MagicEffect::ShockDamage:
|
|
|
|
case ESM::MagicEffect::FrostDamage:
|
|
|
|
case ESM::MagicEffect::DamageHealth:
|
|
|
|
case ESM::MagicEffect::Poison:
|
|
|
|
case ESM::MagicEffect::DamageMagicka:
|
|
|
|
case ESM::MagicEffect::DamageFatigue:
|
|
|
|
if (!godmode)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
if (effect.mEffectId == ESM::MagicEffect::DamageMagicka)
|
|
|
|
index = 1;
|
|
|
|
else if (effect.mEffectId == ESM::MagicEffect::DamageFatigue)
|
|
|
|
index = 2;
|
|
|
|
// Damage "Dynamic" abilities reduce the base value
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
2021-10-06 17:14:00 +02:00
|
|
|
modDynamicStat(target, index, -effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
static const bool uncappedDamageFatigue
|
|
|
|
= Settings::Manager::getBool("uncapped damage fatigue", "Game");
|
|
|
|
adjustDynamicStat(target, index, -effect.mMagnitude, index == 2 && uncappedDamageFatigue);
|
|
|
|
if (index == 0)
|
2022-09-03 19:49:59 +02:00
|
|
|
receivedMagicDamage = affectedHealth = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::DamageAttribute:
|
|
|
|
if (!godmode)
|
|
|
|
damageAttribute(target, effect, effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::DamageSkill:
|
|
|
|
if (!target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else if (!godmode)
|
|
|
|
{
|
|
|
|
// Damage Skill abilities reduce base skill :todd:
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto& npcStats = target.getClass().getNpcStats(target);
|
|
|
|
SkillValue& skill = npcStats.getSkill(effect.mArg);
|
|
|
|
// Damage Skill abilities reduce base skill :todd:
|
|
|
|
skill.setBase(std::max(skill.getBase() - effect.mMagnitude, 0.f));
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
else
|
2021-08-27 20:07:50 +02:00
|
|
|
damageSkill(target, effect, effect.mMagnitude);
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::RestoreAttribute:
|
|
|
|
restoreAttribute(target, effect, effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::RestoreSkill:
|
|
|
|
if (!target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else
|
|
|
|
restoreSkill(target, effect, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::RestoreHealth:
|
2022-09-03 19:49:59 +02:00
|
|
|
affectedHealth = true;
|
|
|
|
[[fallthrough]];
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::RestoreMagicka:
|
|
|
|
case ESM::MagicEffect::RestoreFatigue:
|
|
|
|
adjustDynamicStat(target, effect.mEffectId - ESM::MagicEffect::RestoreHealth, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::SunDamage:
|
|
|
|
{
|
|
|
|
// isInCell shouldn't be needed, but updateActor called during game start
|
2022-08-19 14:51:52 +00:00
|
|
|
if (!target.isInCell() || !(target.getCell()->isExterior() || target.getCell()->isQuasiExterior())
|
|
|
|
|| godmode)
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
2022-09-19 19:05:22 +02:00
|
|
|
const float sunRisen = world->getSunPercentage();
|
2021-08-27 20:07:50 +02:00
|
|
|
static float fMagicSunBlockedMult
|
|
|
|
= world->getStore().get<ESM::GameSetting>().find("fMagicSunBlockedMult")->mValue.getFloat();
|
2022-09-19 19:05:22 +02:00
|
|
|
const float damageScale = std::clamp(
|
|
|
|
std::max(world->getSunVisibility() * sunRisen, fMagicSunBlockedMult * sunRisen), 0.f, 1.f);
|
2021-08-27 20:07:50 +02:00
|
|
|
float damage = effect.mMagnitude * damageScale;
|
|
|
|
adjustDynamicStat(target, 0, -damage);
|
|
|
|
if (damage > 0.f)
|
2022-09-03 19:49:59 +02:00
|
|
|
receivedMagicDamage = affectedHealth = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DrainHealth:
|
|
|
|
case ESM::MagicEffect::DrainMagicka:
|
|
|
|
case ESM::MagicEffect::DrainFatigue:
|
|
|
|
if (!godmode)
|
|
|
|
{
|
|
|
|
static const bool uncappedDamageFatigue
|
|
|
|
= Settings::Manager::getBool("uncapped damage fatigue", "Game");
|
|
|
|
int index = effect.mEffectId - ESM::MagicEffect::DrainHealth;
|
|
|
|
adjustDynamicStat(target, index, -effect.mMagnitude, uncappedDamageFatigue && index == 2);
|
|
|
|
if (index == 0)
|
2022-09-03 19:49:59 +02:00
|
|
|
receivedMagicDamage = affectedHealth = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifyHealth:
|
|
|
|
case ESM::MagicEffect::FortifyMagicka:
|
|
|
|
case ESM::MagicEffect::FortifyFatigue:
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
|
|
|
modDynamicStat(target, effect.mEffectId - ESM::MagicEffect::FortifyHealth, effect.mMagnitude);
|
|
|
|
else
|
|
|
|
adjustDynamicStat(
|
|
|
|
target, effect.mEffectId - ESM::MagicEffect::FortifyHealth, effect.mMagnitude, false, true);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DrainAttribute:
|
|
|
|
if (!godmode)
|
|
|
|
damageAttribute(target, effect, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifyAttribute:
|
|
|
|
// Abilities affect base stats, but not for drain
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
AttributeValue attr = creatureStats.getAttribute(effect.mArg);
|
|
|
|
attr.setBase(attr.getBase() + effect.mMagnitude);
|
|
|
|
creatureStats.setAttribute(effect.mArg, attr);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
else
|
2021-08-27 20:07:50 +02:00
|
|
|
fortifyAttribute(target, effect, effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::DrainSkill:
|
|
|
|
if (!target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else if (!godmode)
|
|
|
|
damageSkill(target, effect, effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::FortifySkill:
|
|
|
|
if (!target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
// Abilities affect base stats, but not for drain
|
|
|
|
auto& npcStats = target.getClass().getNpcStats(target);
|
|
|
|
auto& skill = npcStats.getSkill(effect.mArg);
|
|
|
|
skill.setBase(skill.getBase() + effect.mMagnitude);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fortifySkill(target, effect, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifyMaximumMagicka:
|
2021-10-25 16:54:50 +02:00
|
|
|
recalculateMagicka = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::AbsorbHealth:
|
|
|
|
case ESM::MagicEffect::AbsorbMagicka:
|
|
|
|
case ESM::MagicEffect::AbsorbFatigue:
|
|
|
|
if (!godmode)
|
|
|
|
{
|
|
|
|
int index = effect.mEffectId - ESM::MagicEffect::AbsorbHealth;
|
|
|
|
adjustDynamicStat(target, index, -effect.mMagnitude);
|
|
|
|
if (!caster.isEmpty())
|
|
|
|
adjustDynamicStat(caster, index, effect.mMagnitude);
|
|
|
|
if (index == 0)
|
2022-09-03 19:49:59 +02:00
|
|
|
receivedMagicDamage = affectedHealth = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::AbsorbAttribute:
|
|
|
|
if (!godmode)
|
|
|
|
{
|
|
|
|
damageAttribute(target, effect, effect.mMagnitude);
|
|
|
|
if (!caster.isEmpty())
|
|
|
|
fortifyAttribute(caster, effect, effect.mMagnitude);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::AbsorbSkill:
|
|
|
|
if (!target.getClass().isNpc())
|
|
|
|
invalid = true;
|
|
|
|
else if (!godmode)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
damageSkill(target, effect, effect.mMagnitude);
|
|
|
|
if (!caster.isEmpty())
|
|
|
|
fortifySkill(caster, effect, effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::DisintegrateArmor:
|
|
|
|
{
|
|
|
|
if (!target.getClass().hasInventoryStore(target))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
invalid = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
if (godmode)
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
static const std::array<int, 9> priorities{
|
|
|
|
MWWorld::InventoryStore::Slot_CarriedLeft,
|
|
|
|
MWWorld::InventoryStore::Slot_Cuirass,
|
|
|
|
MWWorld::InventoryStore::Slot_LeftPauldron,
|
|
|
|
MWWorld::InventoryStore::Slot_RightPauldron,
|
|
|
|
MWWorld::InventoryStore::Slot_LeftGauntlet,
|
|
|
|
MWWorld::InventoryStore::Slot_RightGauntlet,
|
|
|
|
MWWorld::InventoryStore::Slot_Helmet,
|
|
|
|
MWWorld::InventoryStore::Slot_Greaves,
|
2022-09-14 00:08:19 +02:00
|
|
|
MWWorld::InventoryStore::Slot_Boots,
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
2021-08-27 20:07:50 +02:00
|
|
|
for (const int priority : priorities)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (disintegrateSlot(target, priority, effect.mMagnitude))
|
|
|
|
break;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
case ESM::MagicEffect::DisintegrateWeapon:
|
|
|
|
if (!target.getClass().hasInventoryStore(target))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
invalid = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
if (!godmode)
|
|
|
|
disintegrateSlot(target, MWWorld::InventoryStore::Slot_CarriedRight, effect.mMagnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
bool shouldRemoveEffect(const MWWorld::Ptr& target, const ESM::ActiveEffect& effect)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
2021-12-10 18:51:37 +01:00
|
|
|
switch (effect.mEffectId)
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
|
|
|
case ESM::MagicEffect::Levitate:
|
|
|
|
{
|
2021-12-10 18:51:37 +01:00
|
|
|
if (!world->isLevitationEnabled())
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (target == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sLevitateDisabled}");
|
|
|
|
return true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ESM::MagicEffect::Recall:
|
|
|
|
case ESM::MagicEffect::DivineIntervention:
|
|
|
|
case ESM::MagicEffect::AlmsiviIntervention:
|
|
|
|
{
|
|
|
|
return effect.mFlags & ESM::ActiveEffect::Flag_Applied;
|
|
|
|
}
|
|
|
|
case ESM::MagicEffect::WaterWalking:
|
|
|
|
{
|
|
|
|
if (target.getClass().isPureWaterCreature(target) && world->isSwimming(target))
|
|
|
|
return true;
|
2021-12-10 18:51:37 +01:00
|
|
|
if (effect.mFlags & ESM::ActiveEffect::Flag_Applied)
|
2022-09-22 21:26:05 +03:00
|
|
|
break;
|
2021-12-10 18:51:37 +01:00
|
|
|
if (!world->isWaterWalkingCastableOnTarget(target))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (target == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInvalidEffect}");
|
2021-12-10 18:51:37 +01:00
|
|
|
return true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-12-10 18:51:37 +01:00
|
|
|
MagicApplicationResult applyMagicEffect(const MWWorld::Ptr& target, const MWWorld::Ptr& caster,
|
|
|
|
ActiveSpells::ActiveSpellParams& spellParams, ESM::ActiveEffect& effect, float dt)
|
|
|
|
{
|
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
2021-08-27 20:07:50 +02:00
|
|
|
bool invalid = false;
|
2021-12-10 18:51:37 +01:00
|
|
|
bool receivedMagicDamage = false;
|
|
|
|
bool recalculateMagicka = false;
|
2022-09-03 19:49:59 +02:00
|
|
|
bool affectedHealth = false;
|
2021-12-10 18:51:37 +01:00
|
|
|
if (effect.mEffectId == ESM::MagicEffect::Corprus && spellParams.shouldWorsen())
|
|
|
|
{
|
|
|
|
spellParams.worsen();
|
|
|
|
for (auto& otherEffect : spellParams.getEffects())
|
|
|
|
{
|
|
|
|
if (isCorprusEffect(otherEffect))
|
|
|
|
applyMagicEffect(target, caster, spellParams, otherEffect, invalid, receivedMagicDamage,
|
|
|
|
affectedHealth, recalculateMagicka);
|
|
|
|
}
|
2021-10-10 16:28:45 +02:00
|
|
|
if (target == getPlayer())
|
2021-08-27 20:07:50 +02:00
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicCorprusWorsens}");
|
2021-12-10 18:51:37 +01:00
|
|
|
return { MagicApplicationResult::Type::APPLIED, receivedMagicDamage, affectedHealth };
|
|
|
|
}
|
|
|
|
else if (shouldRemoveEffect(target, effect))
|
|
|
|
{
|
|
|
|
onMagicEffectRemoved(target, spellParams, effect);
|
|
|
|
return { MagicApplicationResult::Type::REMOVED, receivedMagicDamage, affectedHealth };
|
|
|
|
}
|
|
|
|
const auto* magicEffect = world->getStore().get<ESM::MagicEffect>().find(effect.mEffectId);
|
|
|
|
if (effect.mFlags & ESM::ActiveEffect::Flag_Applied)
|
|
|
|
{
|
|
|
|
if (magicEffect->mData.mFlags & ESM::MagicEffect::Flags::AppliedOnce)
|
|
|
|
{
|
|
|
|
effect.mTimeLeft -= dt;
|
|
|
|
return { MagicApplicationResult::Type::APPLIED, receivedMagicDamage, affectedHealth };
|
|
|
|
}
|
2021-08-31 20:07:30 +02:00
|
|
|
else if (!dt)
|
2021-12-10 18:51:37 +01:00
|
|
|
return { MagicApplicationResult::Type::APPLIED, receivedMagicDamage, affectedHealth };
|
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
if (effect.mEffectId == ESM::MagicEffect::Lock)
|
|
|
|
{
|
|
|
|
if (target.getClass().canLock(target))
|
|
|
|
{
|
|
|
|
MWRender::Animation* animation = world->getAnimation(target);
|
2021-10-10 16:28:45 +02:00
|
|
|
if (animation)
|
2021-08-27 20:07:50 +02:00
|
|
|
animation->addSpellCastGlow(magicEffect);
|
|
|
|
int magnitude = static_cast<int>(roll(effect));
|
|
|
|
if (target.getCellRef().getLockLevel()
|
|
|
|
< magnitude) // If the door is not already locked to a higher value, lock it to spell magnitude
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (caster == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicLockSuccess}");
|
|
|
|
target.getCellRef().lock(magnitude);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2021-08-27 20:07:50 +02:00
|
|
|
invalid = true;
|
|
|
|
}
|
|
|
|
else if (effect.mEffectId == ESM::MagicEffect::Open)
|
|
|
|
{
|
|
|
|
if (target.getClass().canLock(target))
|
|
|
|
{
|
|
|
|
// Use the player instead of the caster for vanilla crime compatibility
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->unlockAttempted(getPlayer(), target);
|
2022-09-22 21:26:05 +03:00
|
|
|
|
2021-08-27 20:07:50 +02:00
|
|
|
MWRender::Animation* animation = world->getAnimation(target);
|
2021-10-10 16:28:45 +02:00
|
|
|
if (animation)
|
2021-08-27 20:07:50 +02:00
|
|
|
animation->addSpellCastGlow(magicEffect);
|
|
|
|
int magnitude = static_cast<int>(roll(effect));
|
|
|
|
if (target.getCellRef().getLockLevel() <= magnitude)
|
|
|
|
{
|
|
|
|
if (target.getCellRef().getLockLevel() > 0)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(
|
|
|
|
target, ESM::RefId::stringRefId("Open Lock"), 1.f, 1.f);
|
2021-08-27 20:07:50 +02:00
|
|
|
|
|
|
|
if (caster == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicOpenSuccess}");
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
target.getCellRef().unlock();
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->playSound3D(
|
|
|
|
target, ESM::RefId::stringRefId("Open Lock Fail"), 1.f, 1.f);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
invalid = true;
|
|
|
|
}
|
|
|
|
else if (!target.getClass().isActor())
|
|
|
|
{
|
2022-09-03 19:49:59 +02:00
|
|
|
invalid = true;
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
2021-12-10 18:51:37 +01:00
|
|
|
else
|
|
|
|
{
|
2023-01-18 19:57:05 +01:00
|
|
|
// Morrowind.exe doesn't apply magic effects while the menu is open, we do because we like to see stats
|
|
|
|
// updated instantly. We don't want to teleport instantly though
|
|
|
|
if (!dt
|
|
|
|
&& (effect.mEffectId == ESM::MagicEffect::Recall
|
|
|
|
|| effect.mEffectId == ESM::MagicEffect::DivineIntervention
|
|
|
|
|| effect.mEffectId == ESM::MagicEffect::AlmsiviIntervention))
|
|
|
|
return { MagicApplicationResult::Type::APPLIED, receivedMagicDamage, affectedHealth };
|
2021-12-10 18:51:37 +01:00
|
|
|
auto& stats = target.getClass().getCreatureStats(target);
|
|
|
|
auto& magnitudes = stats.getMagicEffects();
|
|
|
|
if (spellParams.getType() != ESM::ActiveSpells::Type_Ability
|
2021-08-27 20:07:50 +02:00
|
|
|
&& !(effect.mFlags & ESM::ActiveEffect::Flag_Applied))
|
|
|
|
{
|
|
|
|
MagicApplicationResult::Type result
|
|
|
|
= applyProtections(target, caster, spellParams, effect, magicEffect);
|
|
|
|
if (result != MagicApplicationResult::Type::APPLIED)
|
|
|
|
return { result, receivedMagicDamage, affectedHealth };
|
|
|
|
}
|
|
|
|
float oldMagnitude = 0.f;
|
|
|
|
if (effect.mFlags & ESM::ActiveEffect::Flag_Applied)
|
|
|
|
oldMagnitude = effect.mMagnitude;
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2021-08-27 20:07:50 +02:00
|
|
|
{
|
2021-12-27 22:30:25 +01:00
|
|
|
if (spellParams.getType() != ESM::ActiveSpells::Type_Enchantment)
|
|
|
|
playEffects(target, *magicEffect,
|
|
|
|
spellParams.getType() == ESM::ActiveSpells::Type_Consumable
|
|
|
|
|| spellParams.getType() == ESM::ActiveSpells::Type_Temporary);
|
2021-08-27 20:07:50 +02:00
|
|
|
if (effect.mEffectId == ESM::MagicEffect::Soultrap && !target.getClass().isNpc()
|
2021-12-10 18:51:37 +01:00
|
|
|
&& target.getType() == ESM::Creature::sRecordId
|
|
|
|
&& target.get<ESM::Creature>()->mBase->mData.mSoul == 0 && caster == getPlayer())
|
|
|
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicInvalidTarget}");
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-31 20:07:30 +02:00
|
|
|
float magnitude = roll(effect);
|
2021-08-27 20:07:50 +02:00
|
|
|
// Note that there's an early out for Flag_Applied AppliedOnce effects so we don't have to exclude them here
|
2021-08-31 20:07:30 +02:00
|
|
|
effect.mMagnitude = magnitude;
|
|
|
|
if (!(magicEffect->mData.mFlags
|
2021-08-27 20:07:50 +02:00
|
|
|
& (ESM::MagicEffect::Flags::NoMagnitude | ESM::MagicEffect::Flags::AppliedOnce)))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (effect.mDuration != 0)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
float mult = dt;
|
2021-12-27 22:30:25 +01:00
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Consumable
|
|
|
|
|| spellParams.getType() == ESM::ActiveSpells::Type_Temporary)
|
2021-08-27 20:07:50 +02:00
|
|
|
mult = std::min(effect.mTimeLeft, dt);
|
2021-10-10 16:28:45 +02:00
|
|
|
effect.mMagnitude *= mult;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2022-09-05 18:04:31 +02:00
|
|
|
if (effect.mMagnitude == 0)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-10-16 21:40:41 +02:00
|
|
|
effect.mMagnitude = oldMagnitude;
|
2021-08-27 20:07:50 +02:00
|
|
|
effect.mFlags |= ESM::ActiveEffect::Flag_Applied | ESM::ActiveEffect::Flag_Remove;
|
|
|
|
effect.mTimeLeft -= dt;
|
2022-09-03 19:49:59 +02:00
|
|
|
return { MagicApplicationResult::Type::APPLIED, receivedMagicDamage, affectedHealth };
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
if (effect.mEffectId == ESM::MagicEffect::Corprus)
|
|
|
|
spellParams.worsen();
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
2022-09-03 19:49:59 +02:00
|
|
|
applyMagicEffect(target, caster, spellParams, effect, invalid, receivedMagicDamage, affectedHealth,
|
|
|
|
recalculateMagicka);
|
2021-08-31 20:07:30 +02:00
|
|
|
effect.mMagnitude = magnitude;
|
2021-08-27 20:07:50 +02:00
|
|
|
magnitudes.add(EffectKey(effect.mEffectId, effect.mArg), EffectParam(effect.mMagnitude - oldMagnitude));
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
effect.mTimeLeft -= dt;
|
|
|
|
if (invalid)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
effect.mTimeLeft = 0;
|
|
|
|
effect.mFlags |= ESM::ActiveEffect::Flag_Remove;
|
|
|
|
auto anim = world->getAnimation(target);
|
2022-09-22 21:26:05 +03:00
|
|
|
if (anim)
|
2021-08-27 20:07:50 +02:00
|
|
|
anim->removeEffect(effect.mEffectId);
|
|
|
|
}
|
|
|
|
else
|
2022-09-03 19:49:59 +02:00
|
|
|
effect.mFlags |= ESM::ActiveEffect::Flag_Applied | ESM::ActiveEffect::Flag_Remove;
|
|
|
|
if (recalculateMagicka)
|
|
|
|
target.getClass().getCreatureStats(target).recalculateMagicka();
|
|
|
|
return { MagicApplicationResult::Type::APPLIED, receivedMagicDamage, affectedHealth };
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void removeMagicEffect(
|
|
|
|
const MWWorld::Ptr& target, ActiveSpells::ActiveSpellParams& spellParams, const ESM::ActiveEffect& effect)
|
|
|
|
{
|
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
|
|
|
auto& magnitudes = target.getClass().getCreatureStats(target).getMagicEffects();
|
|
|
|
bool invalid;
|
|
|
|
switch (effect.mEffectId)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::CommandCreature:
|
|
|
|
case ESM::MagicEffect::CommandHumanoid:
|
|
|
|
if (magnitudes.get(effect.mEffectId).getMagnitude() <= 0.f)
|
|
|
|
{
|
|
|
|
auto& seq = target.getClass().getCreatureStats(target).getAiSequence();
|
2022-02-12 23:50:41 +00:00
|
|
|
seq.erasePackageIf([&](const auto& package) {
|
2021-08-27 20:07:50 +02:00
|
|
|
return package->getTypeId() == MWMechanics::AiPackageTypeId::Follow
|
|
|
|
&& static_cast<const MWMechanics::AiFollow*>(package.get())->isCommanded();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::ExtraSpell:
|
|
|
|
if (magnitudes.get(effect.mEffectId).getMagnitude() <= 0.f)
|
2023-01-16 23:51:04 +01:00
|
|
|
target.getClass().getInventoryStore(target).autoEquip();
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::TurnUndead:
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
2022-07-16 16:37:31 +02:00
|
|
|
Stat<int> stat = creatureStats.getAiSetting(AiSetting::Flee);
|
2021-08-27 20:07:50 +02:00
|
|
|
stat.setModifier(static_cast<int>(stat.getModifier() - effect.mMagnitude));
|
2022-07-16 16:37:31 +02:00
|
|
|
creatureStats.setAiSetting(AiSetting::Flee, stat);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FrenzyCreature:
|
|
|
|
case ESM::MagicEffect::FrenzyHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::FrenzyCreature, AiSetting::Fight, -effect.mMagnitude, invalid);
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::CalmCreature:
|
|
|
|
case ESM::MagicEffect::CalmHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::CalmCreature, AiSetting::Fight, effect.mMagnitude, invalid);
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DemoralizeCreature:
|
|
|
|
case ESM::MagicEffect::DemoralizeHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::DemoralizeCreature, AiSetting::Flee, -effect.mMagnitude, invalid);
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
2022-09-05 20:21:19 +02:00
|
|
|
case ESM::MagicEffect::NightEye:
|
|
|
|
{
|
|
|
|
const MWMechanics::EffectParam nightEye = magnitudes.get(effect.mEffectId);
|
|
|
|
if (nightEye.getMagnitude() < 0.f && nightEye.getBase() < 0)
|
|
|
|
{
|
|
|
|
// The PCVisionBonus functions are different from every other magic effect function in that they
|
|
|
|
// clamp the value to [0, 1]. Morrowind.exe applies the same clamping to the night-eye effect, which
|
|
|
|
// can create situations where an effect is still active (i.e. shown in the menu) but the screen is
|
|
|
|
// no longer bright. Modifying the base value here should prevent that while preserving their
|
|
|
|
// function.
|
|
|
|
float delta = std::clamp(-nightEye.getMagnitude(), 0.f, -static_cast<float>(nightEye.getBase()));
|
|
|
|
magnitudes.modifyBase(effect.mEffectId, static_cast<int>(delta));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::RallyCreature:
|
|
|
|
case ESM::MagicEffect::RallyHumanoid:
|
2022-07-16 16:37:31 +02:00
|
|
|
modifyAiSetting(
|
|
|
|
target, effect, ESM::MagicEffect::RallyCreature, AiSetting::Flee, effect.mMagnitude, invalid);
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
2022-09-05 18:04:31 +02:00
|
|
|
case ESM::MagicEffect::Sound:
|
|
|
|
if (magnitudes.get(effect.mEffectId).getModifier() <= 0.f && target == getPlayer())
|
2022-10-18 09:26:55 +02:00
|
|
|
MWBase::Environment::get().getSoundManager()->stopSound3D(
|
|
|
|
target, ESM::RefId::stringRefId("magic sound"));
|
2022-09-05 18:04:31 +02:00
|
|
|
break;
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::SummonScamp:
|
|
|
|
case ESM::MagicEffect::SummonClannfear:
|
|
|
|
case ESM::MagicEffect::SummonDaedroth:
|
|
|
|
case ESM::MagicEffect::SummonDremora:
|
|
|
|
case ESM::MagicEffect::SummonAncestralGhost:
|
|
|
|
case ESM::MagicEffect::SummonSkeletalMinion:
|
|
|
|
case ESM::MagicEffect::SummonBonewalker:
|
|
|
|
case ESM::MagicEffect::SummonGreaterBonewalker:
|
|
|
|
case ESM::MagicEffect::SummonBonelord:
|
|
|
|
case ESM::MagicEffect::SummonWingedTwilight:
|
|
|
|
case ESM::MagicEffect::SummonHunger:
|
|
|
|
case ESM::MagicEffect::SummonGoldenSaint:
|
|
|
|
case ESM::MagicEffect::SummonFlameAtronach:
|
|
|
|
case ESM::MagicEffect::SummonFrostAtronach:
|
|
|
|
case ESM::MagicEffect::SummonStormAtronach:
|
|
|
|
case ESM::MagicEffect::SummonCenturionSphere:
|
|
|
|
case ESM::MagicEffect::SummonFabricant:
|
|
|
|
case ESM::MagicEffect::SummonWolf:
|
|
|
|
case ESM::MagicEffect::SummonBear:
|
|
|
|
case ESM::MagicEffect::SummonBonewolf:
|
|
|
|
case ESM::MagicEffect::SummonCreature04:
|
|
|
|
case ESM::MagicEffect::SummonCreature05:
|
|
|
|
{
|
|
|
|
if (effect.mArg != -1)
|
|
|
|
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(target, effect.mArg);
|
|
|
|
auto& summons = target.getClass().getCreatureStats(target).getSummonedCreatureMap();
|
|
|
|
auto [begin, end] = summons.equal_range(effect.mEffectId);
|
|
|
|
for (auto it = begin; it != end; ++it)
|
|
|
|
{
|
|
|
|
if (it->second == effect.mArg)
|
|
|
|
{
|
|
|
|
summons.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::BoundGloves:
|
2022-10-18 09:26:55 +02:00
|
|
|
removeBoundItem(ESM::RefId::stringRefId(world->getStore()
|
|
|
|
.get<ESM::GameSetting>()
|
|
|
|
.find("sMagicBoundRightGauntletID")
|
|
|
|
->mValue.getString()),
|
2021-08-27 20:07:50 +02:00
|
|
|
target);
|
2021-10-03 21:58:10 +02:00
|
|
|
[[fallthrough]];
|
2021-08-27 20:07:50 +02:00
|
|
|
case ESM::MagicEffect::BoundDagger:
|
|
|
|
case ESM::MagicEffect::BoundLongsword:
|
|
|
|
case ESM::MagicEffect::BoundMace:
|
|
|
|
case ESM::MagicEffect::BoundBattleAxe:
|
|
|
|
case ESM::MagicEffect::BoundSpear:
|
|
|
|
case ESM::MagicEffect::BoundLongbow:
|
|
|
|
case ESM::MagicEffect::BoundCuirass:
|
|
|
|
case ESM::MagicEffect::BoundHelm:
|
|
|
|
case ESM::MagicEffect::BoundBoots:
|
|
|
|
case ESM::MagicEffect::BoundShield:
|
|
|
|
{
|
|
|
|
const std::string& item = sBoundItemsMap.at(effect.mEffectId);
|
2022-10-18 09:26:55 +02:00
|
|
|
removeBoundItem(
|
|
|
|
ESM::RefId::stringRefId(world->getStore().get<ESM::GameSetting>().find(item)->mValue.getString()),
|
|
|
|
target);
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DrainHealth:
|
|
|
|
case ESM::MagicEffect::DrainMagicka:
|
|
|
|
case ESM::MagicEffect::DrainFatigue:
|
|
|
|
adjustDynamicStat(target, effect.mEffectId - ESM::MagicEffect::DrainHealth, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifyHealth:
|
|
|
|
case ESM::MagicEffect::FortifyMagicka:
|
|
|
|
case ESM::MagicEffect::FortifyFatigue:
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
|
|
|
modDynamicStat(target, effect.mEffectId - ESM::MagicEffect::FortifyHealth, -effect.mMagnitude);
|
|
|
|
else
|
|
|
|
adjustDynamicStat(
|
|
|
|
target, effect.mEffectId - ESM::MagicEffect::FortifyHealth, -effect.mMagnitude, true);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DrainAttribute:
|
|
|
|
restoreAttribute(target, effect, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifyAttribute:
|
|
|
|
// Abilities affect base stats, but not for drain
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
|
|
|
{
|
|
|
|
auto& creatureStats = target.getClass().getCreatureStats(target);
|
|
|
|
AttributeValue attr = creatureStats.getAttribute(effect.mArg);
|
|
|
|
attr.setBase(attr.getBase() - effect.mMagnitude);
|
|
|
|
creatureStats.setAttribute(effect.mArg, attr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fortifyAttribute(target, effect, -effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::DrainSkill:
|
|
|
|
restoreSkill(target, effect, effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifySkill:
|
|
|
|
// Abilities affect base stats, but not for drain
|
|
|
|
if (spellParams.getType() == ESM::ActiveSpells::Type_Ability)
|
|
|
|
{
|
|
|
|
auto& npcStats = target.getClass().getNpcStats(target);
|
|
|
|
auto& skill = npcStats.getSkill(effect.mArg);
|
|
|
|
skill.setBase(skill.getBase() - effect.mMagnitude);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fortifySkill(target, effect, -effect.mMagnitude);
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::FortifyMaximumMagicka:
|
2021-10-25 16:54:50 +02:00
|
|
|
target.getClass().getCreatureStats(target).recalculateMagicka();
|
2021-08-27 20:07:50 +02:00
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::AbsorbAttribute:
|
|
|
|
{
|
|
|
|
const auto caster = world->searchPtrViaActorId(spellParams.getCasterActorId());
|
|
|
|
restoreAttribute(target, effect, effect.mMagnitude);
|
|
|
|
if (!caster.isEmpty())
|
|
|
|
fortifyAttribute(caster, effect, -effect.mMagnitude);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::AbsorbSkill:
|
|
|
|
{
|
|
|
|
const auto caster = world->searchPtrViaActorId(spellParams.getCasterActorId());
|
|
|
|
restoreSkill(target, effect, effect.mMagnitude);
|
|
|
|
if (!caster.isEmpty())
|
|
|
|
fortifySkill(caster, effect, -effect.mMagnitude);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ESM::MagicEffect::Corprus:
|
|
|
|
{
|
|
|
|
int worsenings = spellParams.getWorsenings();
|
|
|
|
spellParams.resetWorsenings();
|
|
|
|
if (worsenings > 0)
|
|
|
|
{
|
|
|
|
for (const auto& otherEffect : spellParams.getEffects())
|
|
|
|
{
|
|
|
|
if (isCorprusEffect(otherEffect, true))
|
|
|
|
{
|
|
|
|
for (int i = 0; i < worsenings; i++)
|
|
|
|
removeMagicEffect(target, spellParams, otherEffect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Note that we remove the effects, but keep the params
|
|
|
|
target.getClass().getCreatureStats(target).getActiveSpells().purge(
|
|
|
|
[&spellParams](
|
|
|
|
const ActiveSpells::ActiveSpellParams& params, const auto&) { return &spellParams == ¶ms; },
|
|
|
|
target);
|
|
|
|
}
|
|
|
|
break;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void onMagicEffectRemoved(
|
|
|
|
const MWWorld::Ptr& target, ActiveSpells::ActiveSpellParams& spellParams, const ESM::ActiveEffect& effect)
|
2021-10-16 21:40:41 +02:00
|
|
|
{
|
2021-08-27 20:07:50 +02:00
|
|
|
if (!(effect.mFlags & ESM::ActiveEffect::Flag_Applied))
|
2022-09-22 21:26:05 +03:00
|
|
|
return;
|
2021-08-27 20:07:50 +02:00
|
|
|
auto& magnitudes = target.getClass().getCreatureStats(target).getMagicEffects();
|
2021-10-16 21:40:41 +02:00
|
|
|
magnitudes.add(EffectKey(effect.mEffectId, effect.mArg), EffectParam(-effect.mMagnitude));
|
2021-08-27 20:07:50 +02:00
|
|
|
removeMagicEffect(target, spellParams, effect);
|
2021-10-16 21:40:41 +02:00
|
|
|
if (magnitudes.get(effect.mEffectId).getMagnitude() <= 0.f)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2021-10-16 21:40:41 +02:00
|
|
|
auto anim = MWBase::Environment::get().getWorld()->getAnimation(target);
|
|
|
|
if (anim)
|
|
|
|
anim->removeEffect(effect.mEffectId);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2021-10-16 21:40:41 +02:00
|
|
|
}
|
2021-08-27 20:07:50 +02:00
|
|
|
|
2021-10-11 11:46:21 +00:00
|
|
|
}
|