Skip to content

Commit

Permalink
Fix constructible object skill use
Browse files Browse the repository at this point in the history
  • Loading branch information
Exit-9B committed Oct 26, 2024
1 parent 4671b5b commit bd10370
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ set(SOURCES
src/RE/T/TESRace.cpp
src/RE/T/TESTopic.cpp
src/RE/T/TESTopicInfo.cpp
src/RE/T/TESValueForm.cpp
src/RE/T/TESWorldSpace.cpp
src/RE/T/TaskQueueInterface.cpp
src/RE/T/ThumbstickEvent.cpp
Expand Down
4 changes: 4 additions & 0 deletions include/RE/T/TESValueForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace RE
{
class TESForm;

class TESValueForm : public BaseFormComponent
{
public:
Expand All @@ -16,6 +18,8 @@ namespace RE
void ClearDataComponent() override; // 02 - { return; }
void CopyComponent(BaseFormComponent* a_rhs) override; // 03

[[nodiscard]] static std::int32_t GetFormValue(const TESForm* a_form);

// members
std::int32_t value; // 08
std::uint32_t pad0C; // 0C
Expand Down
8 changes: 4 additions & 4 deletions src/RE/B/BGSConstructibleObject.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "RE/B/BGSConstructibleObject.h"

#include "RE/G/GameSettingCollection.h"
#include "RE/I/InventoryChanges.h"
#include "RE/P/PlayerCharacter.h"
#include "RE/T/TESFurniture.h"
#include "RE/T/TESValueForm.h"

namespace RE
{
Expand All @@ -24,10 +26,8 @@ namespace RE

float BGSConstructibleObject::CalcSkillUse() const
{
float value = createdItem ? createdItem->GetGoldValue() : 0.0f;
if (value <= 0.0f) {
value = 1.0f;
}
const std::int32_t itemValue = createdItem ? TESValueForm::GetFormValue(createdItem) : 0;
const float value = itemValue > 0 ? static_cast<float>(itemValue) * data.numConstructed : 1.0f;

return std::powf(value, "fConstructibleSkilluseExp"_gs.value_or(0.5f)) *
"fConstructibleSkillUseMult"_gs.value_or(1.0f) +
Expand Down
22 changes: 22 additions & 0 deletions src/RE/T/TESValueForm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "RE/T/TESValueForm.h"

#include "RE/A/AlchemyItem.h"
#include "RE/M/MagicItem.h"
#include "RE/RTTI.h"
#include "RE/T/TESForm.h"

namespace RE
{
std::int32_t TESValueForm::GetFormValue(const TESForm* a_form)
{
if (const auto valueForm = skyrim_cast<const TESValueForm*>(a_form)) {
return valueForm->value;
}

if (const auto magicItem = skyrim_cast<const MagicItem*>(a_form)) {
return static_cast<std::int32_t>(magicItem->CalculateMagickaCost(nullptr));
}

return -1;
}
}

0 comments on commit bd10370

Please sign in to comment.