Skip to content

Commit

Permalink
fix: properly update magic equipment
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 30, 2022
1 parent d32f31e commit 197f0cc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
11 changes: 11 additions & 0 deletions Code/client/Games/Skyrim/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,14 @@ MagicEquipment Actor::GetMagicEquipment() const noexcept
return equipment;
}

Inventory Actor::GetEquipment() const noexcept
{
Inventory inventory = GetInventory();
inventory.RemoveByFilter([](const auto& entry) { return !entry.IsWorn(); });
inventory.CurrentMagicEquipment = GetMagicEquipment();
return inventory;
}

int32_t Actor::GetGoldAmount() noexcept
{
TP_THIS_FUNCTION(TGetGoldAmount, int32_t, Actor);
Expand All @@ -328,18 +336,21 @@ void Actor::SetMagicEquipment(const MagicEquipment& acEquipment) noexcept
if (acEquipment.LeftHandSpell)
{
uint32_t mainHandWeaponId = modSystem.GetGameId(acEquipment.LeftHandSpell);
spdlog::debug("Setting left hand spell: {:X}", mainHandWeaponId);
pEquipManager->EquipSpell(this, TESForm::GetById(mainHandWeaponId), 0);
}

if (acEquipment.RightHandSpell)
{
uint32_t secondaryHandWeaponId = modSystem.GetGameId(acEquipment.RightHandSpell);
spdlog::debug("Setting right hand spell: {:X}", secondaryHandWeaponId);
pEquipManager->EquipSpell(this, TESForm::GetById(secondaryHandWeaponId), 1);
}

if (acEquipment.Shout)
{
uint32_t shoutId = modSystem.GetGameId(acEquipment.Shout);
spdlog::debug("Setting shout: {:X}", shoutId);
pEquipManager->EquipShout(this, TESForm::GetById(shoutId));
}
}
Expand Down
1 change: 1 addition & 0 deletions Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ struct Actor : TESObjectREFR
float GetActorPermanentValue(uint32_t aId) const noexcept;
Inventory GetActorInventory() const noexcept;
MagicEquipment GetMagicEquipment() const noexcept;
Inventory GetEquipment() const noexcept;
int32_t GetGoldAmount() noexcept;

Factions GetFactions() const noexcept;
Expand Down
7 changes: 0 additions & 7 deletions Code/client/Games/Skyrim/TESObjectREFR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,6 @@ Inventory TESObjectREFR::GetWornArmor() const noexcept
return wornArmor;
}

Inventory TESObjectREFR::GetEquippedItems() const noexcept
{
Inventory inventory = GetInventory();
inventory.RemoveByFilter([](const auto& entry) { return !entry.IsWorn(); });
return inventory;
}

bool TESObjectREFR::IsItemInInventory(uint32_t aFormID) const noexcept
{
Inventory inventory = GetInventory([aFormID](TESForm& aForm) { return aForm.formID == aFormID; });
Expand Down
1 change: 0 additions & 1 deletion Code/client/Games/Skyrim/TESObjectREFR.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ struct TESObjectREFR : TESForm
Inventory GetInventory(std::function<bool(TESForm&)> aFilter) const noexcept;
Inventory GetArmor() const noexcept;
Inventory GetWornArmor() const noexcept;
Inventory GetEquippedItems() const noexcept;

bool IsItemInInventory(uint32_t aFormID) const noexcept;

Expand Down
2 changes: 1 addition & 1 deletion Code/client/Services/Generic/InventoryService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void InventoryService::OnEquipmentChangeEvent(const EquipmentChangeEvent& acEven
request.IsSpell = acEvent.IsSpell;
request.IsShout = acEvent.IsShout;
request.IsAmmo = acEvent.IsAmmo;
request.CurrentInventory = pActor->GetEquippedItems();
request.CurrentInventory = pActor->GetEquipment();

m_transport.Send(request);
}
Expand Down

0 comments on commit 197f0cc

Please sign in to comment.