Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove committed Nov 12, 2023
1 parent 08c7a49 commit 6be5a57
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
26 changes: 1 addition & 25 deletions skymp5-server/cpp/server_guest_lib/MpActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include "TeleportMessage.h"
#include "UpdateEquipmentMessage.h"

#include "SpSnippet.h"
#include "SpSnippetFunctionGen.h"

struct MpActor::Impl
{
std::map<uint32_t, Viet::Promise<VarValue>> snippetPromises;
Expand Down Expand Up @@ -151,39 +148,18 @@ void MpActor::EquipBestWeapon()
}
}

void MpActor::AddSpell(const uint32_t spellId, const bool verbose)
void MpActor::AddSpell(const uint32_t spellId)
{
EditChangeForm([&](MpChangeForm& changeForm) {
changeForm.learnedSpells.LearnSpell(spellId);
});

auto spell = GetParent()->GetEspm().GetBrowser().LookupById(spellId);

std::vector<VarValue> arguments(2);
arguments[0] = VarValue(std::make_shared<EspmGameObject>(spell));
arguments[1] = VarValue(verbose);

SpSnippet spSnippet(
"Actor", "AddSpell",
SpSnippetFunctionGen::SerializeArguments(arguments).data(), GetFormId());
spSnippet.Execute(this);
}

void MpActor::RemoveSpell(const uint32_t spellId)
{
EditChangeForm([&](MpChangeForm& changeForm) {
changeForm.learnedSpells.ForgetSpell(spellId);
});

auto spell = GetParent()->GetEspm().GetBrowser().LookupById(spellId);

std::vector<VarValue> arguments(1);
arguments[0] = VarValue(std::make_shared<EspmGameObject>(spell));

SpSnippet spSnippet(
"Actor", "RemoveSpell",
SpSnippetFunctionGen::SerializeArguments(arguments).data(), GetFormId());
spSnippet.Execute(this);
}

void MpActor::SetRaceMenuOpen(bool isOpen)
Expand Down
2 changes: 1 addition & 1 deletion skymp5-server/cpp/server_guest_lib/MpActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class MpActor : public MpObjectReference
bool MpApiCraft(uint32_t craftedItemBaseId, uint32_t count,
uint32_t recipeId);

void AddSpell(uint32_t spellId, bool verbose);
void AddSpell(uint32_t spellId);
void RemoveSpell(uint32_t spellId);

private:
Expand Down
16 changes: 13 additions & 3 deletions skymp5-server/cpp/server_guest_lib/script_classes/PapyrusActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ VarValue PapyrusActor::AddSpell(VarValue self,
"Actor.AddSpell requires at least two arguments");
}

const bool verbose = static_cast<bool>(arguments[1]);

const auto& spell = GetRecordPtr(arguments[0]);
if (!spell.rec) {
spdlog::error("Actor.AddSpell - invalid spell form");
Expand All @@ -284,7 +282,13 @@ VarValue PapyrusActor::AddSpell(VarValue self,
uint32_t spellId = spell.ToGlobalId(spell.rec->GetId());

if (!actor->IsSpellLearned(spellId)) {
actor->AddSpell(spellId, verbose);
actor->AddSpell(spellId);

SpSnippet(GetName(), "AddSpell",
SpSnippetFunctionGen::SerializeArguments(arguments).data(),
actor->GetFormId())
.Execute(actor);

return VarValue(true);
}
}
Expand Down Expand Up @@ -323,6 +327,12 @@ VarValue PapyrusActor::RemoveSpell(VarValue self,
spdlog::warn("Actor.RemoveSpell - spell already removed/not learned");
} else {
actor->RemoveSpell(spellId);

SpSnippet(GetName(), "RemoveSpell",
SpSnippetFunctionGen::SerializeArguments(arguments).data(),
actor->GetFormId())
.Execute(actor);

return VarValue(true);
}
}
Expand Down

0 comments on commit 6be5a57

Please sign in to comment.