Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 0 additions & 97 deletions skymp5-server/cpp/server_guest_lib/ActiveMagicEffectsMap.cpp

This file was deleted.

42 changes: 0 additions & 42 deletions skymp5-server/cpp/server_guest_lib/ActiveMagicEffectsMap.h

This file was deleted.

43 changes: 21 additions & 22 deletions skymp5-server/cpp/server_guest_lib/AnimationSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@

AnimationSystem::AnimationSystem()
{
animationCallbacks = {
{
"blockStart",
[this](MpActor* actor) {
constexpr float newRate = 0.f;
actor->SetIsBlockActive(true);
if (hasSweetpie) {
actor->SetActorValue(espm::ActorValue::StaminaRate, newRate);
}
},
},
{
"blockStop",
[this](MpActor* actor) {
actor->SetIsBlockActive(false);
if (hasSweetpie) {
actor->SetActorValue(espm::ActorValue::StaminaRate,
actor->GetBaseValues().staminaRate);
}
},
}
};
animationCallbacks = { {
"blockStart",
[this](MpActor* actor) {
// constexpr float newRate = 0.f;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented-out code inside blockStart callback remains. If magic effect modifications are removed permanently, consider deleting obsolete code instead of commenting it out.

Suggested change
// constexpr float newRate = 0.f;

actor->SetIsBlockActive(true);
// if (hasSweetpie) {
// actor->SetActorValue(espm::ActorValue::StaminaRate,
// newRate);
// }
},
},
{
"blockStop",
[this](MpActor* actor) {
actor->SetIsBlockActive(false);
// if (hasSweetpie) {
// actor->SetActorValue(espm::ActorValue::StaminaRate,
// actor->GetBaseValues().staminaRate);
// }
},
} };
}

void AnimationSystem::Init(WorldState* pWorldState)
Expand Down
161 changes: 0 additions & 161 deletions skymp5-server/cpp/server_guest_lib/MpActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ void MpActor::ApplyChangeForm(const MpChangeForm& newChangeForm)
}
},
Mode::NoRequestSave);
ReapplyMagicEffects();

// We do the same in PartOne::SetUserActor for player characters
if (IsDead() && !IsRespawning()) {
Expand Down Expand Up @@ -1599,166 +1598,6 @@ void MpActor::SetActorValues(const ActorValues& actorValues)
[&](MpChangeForm& changeForm) { changeForm.actorValues = actorValues; });
}

void MpActor::ApplyMagicEffect(espm::Effects::Effect& effect, bool hasSweetpie,
bool durationOverriden)
{
WorldState* worldState = GetParent();
auto data = espm::GetData<espm::MGEF>(effect.effectId, worldState).data;

if (data.effectType == espm::MGEF::EffectType::CureDisease) {
spdlog::trace("Curing all diseases");
auto spells = ChangeForm().learnedSpells.GetLearnedSpells();
for (auto spellId : spells) {
auto spellData = espm::GetData<espm::SPEL>(spellId, worldState);
if (spellData.spellItem->type == espm::SPEL::SpellType::Disease) {
spdlog::trace("Curing disease {:x}", spellId);
RemoveSpell(spellId);
}
}
return;
}

const espm::ActorValue av = data.primaryAV;
const espm::MGEF::EffectType type = data.effectType;
spdlog::trace("Actor value in ApplyMagicEffect(): {}",
static_cast<std::underlying_type_t<espm::ActorValue>>(av));

const bool isValue = av == espm::ActorValue::Health ||
av == espm::ActorValue::Stamina || av == espm::ActorValue::Magicka;
const bool isRate = av == espm::ActorValue::HealRate ||
av == espm::ActorValue::StaminaRate || av == espm::ActorValue::MagickaRate;
const bool isMult =
av == espm::ActorValue::HealRateMult_or_CombatHealthRegenMultMod ||
av == espm::ActorValue::StaminaRateMult ||
av == espm::ActorValue::MagickaRateMult_or_CombatHealthRegenMultPowerMod;

if (isValue) { // other types are unsupported
if (hasSweetpie) {
// this coefficient (workaround) has been added for sake of game
// balance and because of disability to restrict players use potions
// often on client side
constexpr float kMagnitudeCoeff = 100.f;
RestoreActorValuePatched(this, av, effect.magnitude * kMagnitudeCoeff);
} else {
RestoreActorValuePatched(this, av, effect.magnitude);
}
}

if (isRate || isMult) {
MpChangeForm changeForm = GetChangeForm();
BaseActorValues baseValues = GetBaseActorValues(
GetParent(), GetBaseId(), GetRaceId(), changeForm.templateChain);
const ActiveMagicEffectsMap& activeEffects = changeForm.activeMagicEffects;
const float baseValue = baseValues.GetValue(av);
const uint32_t formId = GetFormId();
auto now = std::chrono::system_clock::now();
std::chrono::system_clock::time_point endTime;
std::chrono::milliseconds duration;
if (durationOverriden) {
std::optional effect = GetChangeForm().activeMagicEffects.Get(av);
if (!effect.has_value()) {
spdlog::error(
"MpActor with formId {:x} has no magic effect affecting "
"actor value {}",
GetFormId(),
static_cast<std::underlying_type_t<espm::ActorValue>>(av));
return;
}
endTime = effect.value().get().endTime;
duration =
std::chrono::duration_cast<std::chrono::milliseconds>(endTime - now);
} else {
endTime =
now + Viet::TimeUtils::To<std::chrono::milliseconds>(effect.duration);
duration =
Viet::TimeUtils::To<std::chrono::milliseconds>(effect.duration);
}
uint32_t timerId;
worldState->SetEffectTimer(duration, &timerId)
.Then([formId, actorValue = av, worldState](Viet::Void) {
auto& actor = worldState->GetFormAt<MpActor>(formId);
actor.RemoveMagicEffect(actorValue);
});

ActiveMagicEffectsMap::Entry entry{ timerId, effect, endTime };
if (activeEffects.Has(av)) {
const ActiveMagicEffectsMap::Entry& entry =
activeEffects.Get(av).value().get();
worldState->RemoveEffectTimer(entry.timerId);
}
EditChangeForm([av, pEntry = &entry](MpChangeForm& changeForm) {
changeForm.activeMagicEffects.Add(av, *pEntry);
});
if (isRate) {
SetActorValue(av, effect.magnitude);
} else {
float mult = 1.f;
if (type == espm::MGEF::EffectType::PeakValueMod) {
mult = MathUtils::PercentToMultPos(effect.magnitude);
}

if (type == espm::MGEF::EffectType::ValueMod) {
mult = MathUtils::PercentToMultNeg(effect.magnitude);
}
if (MathUtils::IsNearlyEqual(1.f, mult)) {
spdlog::error(
"Unknown espm::MGEF::EffectType: {}",
static_cast<std::underlying_type_t<espm::MGEF::EffectType>>(type));
}
spdlog::trace("Final multiplicator is {}", mult);
// TODO: proper fix (or effects system) instead of monkey-patching 4x
// higher mult
// https://github.com/skyrim-multiplayer/skymp/pull/1852
spdlog::trace("The result of baseValue * mult is: {}*{}={}", baseValue,
mult, baseValue * (mult * 4));
SetActorValue(av, baseValue * (mult * 4));
}
}
}

void MpActor::ApplyMagicEffects(std::vector<espm::Effects::Effect>& effects,
bool hasSweetpie, bool durationOverriden)
{
for (auto& effect : effects) {
ApplyMagicEffect(effect, hasSweetpie, durationOverriden);
}
}

void MpActor::RemoveMagicEffect(const espm::ActorValue actorValue) noexcept
{
const ActorValues baseActorValues = GetBaseActorValues(
GetParent(), GetBaseId(), GetRaceId(), ChangeForm().templateChain);
const float baseActorValue = baseActorValues.GetValue(actorValue);
SetActorValue(actorValue, baseActorValue);
EditChangeForm([actorValue](MpChangeForm& changeForm) {
changeForm.activeMagicEffects.Remove(actorValue);
});
}

void MpActor::RemoveAllMagicEffects() noexcept
{
const ActorValues baseActorValues = GetBaseActorValues(
GetParent(), GetBaseId(), GetRaceId(), ChangeForm().templateChain);
SetActorValues(baseActorValues);
EditChangeForm(
[](MpChangeForm& changeForm) { changeForm.activeMagicEffects.Clear(); });
}

void MpActor::ReapplyMagicEffects()
{
// TODO: Implement range-based for loop for MagicEffectsMap
std::vector<espm::Effects::Effect> activeEffects =
GetChangeForm().activeMagicEffects.GetAllEffects();
if (activeEffects.empty()) {
return;
}
const std::vector<std::string>& modFiles = GetParent()->espmFiles;
const bool hasSweetpie = std::any_of(
modFiles.begin(), modFiles.end(),
[](std::string_view fileName) { return fileName == "SweetPie.esp"; });
ApplyMagicEffects(activeEffects, hasSweetpie, true);
}

std::array<std::optional<Inventory::Entry>, 2> MpActor::GetEquippedWeapon()
const
{
Expand Down
9 changes: 0 additions & 9 deletions skymp5-server/cpp/server_guest_lib/MpActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,6 @@ class MpActor : public MpObjectReference
void IncreaseBlockCount() noexcept;
void ResetBlockCount() noexcept;
uint32_t GetBlockCount() const noexcept;
void ApplyMagicEffect(espm::Effects::Effect& effect,
bool hasSweetpie = false,
bool durationOverriden = false);
void ApplyMagicEffects(std::vector<espm::Effects::Effect>& effects,
bool hasSweetpie = false,
bool durationOverriden = false);
void RemoveMagicEffect(const espm::ActorValue actorValue) noexcept;
void RemoveAllMagicEffects() noexcept;
void ReapplyMagicEffects();

bool GetConsoleCommandsAllowedFlag() const;
void SetConsoleCommandsAllowedFlag(bool newValue);
Expand Down
Loading