diff --git a/cmake/sourcelist.cmake b/cmake/sourcelist.cmake index 16fcd7d5d..5cc7139a9 100644 --- a/cmake/sourcelist.cmake +++ b/cmake/sourcelist.cmake @@ -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 diff --git a/include/RE/T/TESValueForm.h b/include/RE/T/TESValueForm.h index 75bd7c0f3..6a86886e1 100644 --- a/include/RE/T/TESValueForm.h +++ b/include/RE/T/TESValueForm.h @@ -4,6 +4,8 @@ namespace RE { + class TESForm; + class TESValueForm : public BaseFormComponent { public: @@ -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 diff --git a/src/RE/B/BGSConstructibleObject.cpp b/src/RE/B/BGSConstructibleObject.cpp index dbf60d2f5..6992a20f7 100644 --- a/src/RE/B/BGSConstructibleObject.cpp +++ b/src/RE/B/BGSConstructibleObject.cpp @@ -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 { @@ -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(itemValue) * data.numConstructed : 1.0f; return std::powf(value, "fConstructibleSkilluseExp"_gs.value_or(0.5f)) * "fConstructibleSkillUseMult"_gs.value_or(1.0f) + diff --git a/src/RE/T/TESValueForm.cpp b/src/RE/T/TESValueForm.cpp new file mode 100644 index 000000000..5587f99f5 --- /dev/null +++ b/src/RE/T/TESValueForm.cpp @@ -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(a_form)) { + return valueForm->value; + } + + if (const auto magicItem = skyrim_cast(a_form)) { + return static_cast(magicItem->CalculateMagickaCost(nullptr)); + } + + return -1; + } +}