From fbbecbf350c9a92285376bd10a03ab45c5693271 Mon Sep 17 00:00:00 2001 From: Leonid Pospelov Date: Wed, 27 Nov 2024 13:30:27 +0000 Subject: [PATCH] . --- .../cpp/server_guest_lib/EvaluateTemplate.h | 10 +- .../cpp/server_guest_lib/MpActor.cpp | 100 +++++++++--------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/skymp5-server/cpp/server_guest_lib/EvaluateTemplate.h b/skymp5-server/cpp/server_guest_lib/EvaluateTemplate.h index df8ae62e7..bad42eb3d 100644 --- a/skymp5-server/cpp/server_guest_lib/EvaluateTemplate.h +++ b/skymp5-server/cpp/server_guest_lib/EvaluateTemplate.h @@ -9,8 +9,7 @@ template auto EvaluateTemplate(WorldState* worldState, uint32_t baseId, const std::vector& templateChain, - const Callback& callback, - std::string* outError = nullptr) + const Callback& callback) { const std::vector chainDefault = { FormDesc::FromFormId( baseId, worldState->espmFiles) }; @@ -64,10 +63,5 @@ auto EvaluateTemplate(WorldState* worldState, uint32_t baseId, ss << ", templateFlag=" << TemplateFlag; ss << ", detailedLog=" << detailedLog.str(); - if (outError) { - *outError = ss.str(); - return {}; - } else { - throw std::runtime_error(ss.str()); - } + throw std::runtime_error(ss.str()); } diff --git a/skymp5-server/cpp/server_guest_lib/MpActor.cpp b/skymp5-server/cpp/server_guest_lib/MpActor.cpp index fcab55ec4..9f6391818 100644 --- a/skymp5-server/cpp/server_guest_lib/MpActor.cpp +++ b/skymp5-server/cpp/server_guest_lib/MpActor.cpp @@ -334,8 +334,8 @@ void MpActor::VisitProperties(const PropertiesVisitor& visitor, // this "if" is needed for unit testing: tests can call VisitProperties // without espm attached, which will cause tests to fail if (worldState && worldState->HasEspm()) { - baseActorValues = GetBaseActorValues(worldState, baseId, raceId, - ChangeForm().templateChain); + baseActorValues = + GetBaseActorValues(worldState, baseId, raceId, templateChain); } MpChangeForm changeForm = GetChangeForm(); @@ -780,7 +780,7 @@ espm::ObjectBounds MpActor::GetBounds() const const std::vector& MpActor::GetTemplateChain() const { - return ChangeForm().templateChain; + return templateChain; } bool MpActor::IsCreatedAsPlayer() const @@ -888,7 +888,9 @@ void MpActor::EnsureTemplateChainEvaluated(espm::Loader& loader, return; } - if (!ChangeForm().templateChain.empty()) { + const auto& templateChain = ChangeForm().templateChain; + + if (!templateChain.empty()) { std::string errorTraits; std::string errorStats; @@ -904,57 +906,57 @@ void MpActor::EnsureTemplateChainEvaluated(espm::Loader& loader, std::string errorAttackData; std::string errorKeywords; - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorTraits); + auto doNothing = [](const auto&, const auto&) { return; }; + + auto evaluateTemplateChecked = + [](WorldState* worldState, uint32_t baseId, + const std::vector& templateChain, + const auto& callback, std::string* error) { + try { + EvaluateTemplate(worldState, baseId, templateChain, callback); + } catch (std::exception& e) { + *error = e.what(); + } + }; + + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorTraits); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorStats); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorStats); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorFactions); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorFactions); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorSpelllist); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorSpelllist); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorAIData); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorAIData); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorAIPackages); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorAIPackages); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorUnused); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorUnused); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorBaseData); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorBaseData); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorInventory); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorInventory); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorScript); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorScript); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorDefPackList); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorDefPackList); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorAttackData); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorAttackData); - EvaluateTemplate( - worldState, baseId, ChangeForm().templateChain, - [](const auto&, const auto&) { return; }, &errorKeywords); + evaluateTemplateChecked( + worldState, baseId, templateChain, doNothing, &errorKeywords); if (errorTraits.empty() && errorStats.empty() && errorFactions.empty() && errorSpelllist.empty() && errorAIData.empty() && @@ -1043,7 +1045,7 @@ std::map MpActor::EvaluateDeathItem() } uint32_t baseId = base.ToGlobalId(base.rec->GetId()); - auto& templateChain = ChangeForm().templateChain; + auto& templateChain = templateChain; uint32_t deathItemId = EvaluateTemplate( worldState, baseId, templateChain, @@ -1361,7 +1363,7 @@ void MpActor::DamageActorValue(espm::ActorValue av, float value) BaseActorValues MpActor::GetBaseValues() { return GetBaseActorValues(GetParent(), GetBaseId(), GetRaceId(), - ChangeForm().templateChain); + templateChain); } BaseActorValues MpActor::GetMaximumValues() @@ -1707,8 +1709,8 @@ void MpActor::ApplyMagicEffects(std::vector& effects, void MpActor::RemoveMagicEffect(const espm::ActorValue actorValue) noexcept { - const ActorValues baseActorValues = GetBaseActorValues( - GetParent(), GetBaseId(), GetRaceId(), ChangeForm().templateChain); + const ActorValues baseActorValues = + GetBaseActorValues(GetParent(), GetBaseId(), GetRaceId(), templateChain); const float baseActorValue = baseActorValues.GetValue(actorValue); SetActorValue(actorValue, baseActorValue); EditChangeForm([actorValue](MpChangeForm& changeForm) { @@ -1718,8 +1720,8 @@ void MpActor::RemoveMagicEffect(const espm::ActorValue actorValue) noexcept void MpActor::RemoveAllMagicEffects() noexcept { - const ActorValues baseActorValues = GetBaseActorValues( - GetParent(), GetBaseId(), GetRaceId(), ChangeForm().templateChain); + const ActorValues baseActorValues = + GetBaseActorValues(GetParent(), GetBaseId(), GetRaceId(), templateChain); SetActorValues(baseActorValues); EditChangeForm( [](MpChangeForm& changeForm) { changeForm.activeMagicEffects.Clear(); });