mirror of
https://github.com/Milxnor/Project-Reboot-3.0.git
synced 2026-01-13 19:02:21 +01:00
level
level showing up on items now, fix s19, improve performance, fix big issue on s5
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <map>
|
||||
@@ -49,6 +50,18 @@ public:
|
||||
return *(int*)(__int64(this) + LootPackageCategoryOffset);
|
||||
}
|
||||
|
||||
int& GetMinWorldLevel()
|
||||
{
|
||||
static auto MinWorldLevelOffset = FindOffsetStruct("/Script/FortniteGame.FortLootPackageData", "MinWorldLevel");
|
||||
return *(int*)(__int64(this) + MinWorldLevelOffset);
|
||||
}
|
||||
|
||||
int& GetMaxWorldLevel()
|
||||
{
|
||||
static auto MaxWorldLevelOffset = FindOffsetStruct("/Script/FortniteGame.FortLootPackageData", "MaxWorldLevel");
|
||||
return *(int*)(__int64(this) + MaxWorldLevelOffset);
|
||||
}
|
||||
|
||||
FString& GetAnnotation()
|
||||
{
|
||||
static auto AnnotationOffset = FindOffsetStruct("/Script/FortniteGame.FortLootPackageData", "Annotation");
|
||||
@@ -140,9 +153,12 @@ FORCEINLINE static ValueType PickWeightedElement(const std::map<KeyType, ValueTy
|
||||
TotalWeight = std::accumulate(Elements.begin(), Elements.end(), 0.0f, [&](float acc, const std::pair<KeyType, ValueType>& p) {
|
||||
auto Weight = GetWeightFn(p.second);
|
||||
|
||||
if (bPrint && Weight != 0)
|
||||
if (bPrint)
|
||||
{
|
||||
LOG_INFO(LogLoot, "Adding weight: {}", Weight);
|
||||
// if (Weight != 0)
|
||||
{
|
||||
LOG_INFO(LogLoot, "Adding weight {}", Weight);
|
||||
}
|
||||
}
|
||||
|
||||
return acc + Weight;
|
||||
@@ -154,7 +170,7 @@ FORCEINLINE static ValueType PickWeightedElement(const std::map<KeyType, ValueTy
|
||||
|
||||
if (bPrint)
|
||||
{
|
||||
LOG_INFO(LogLoot, "RandomNumber: {} TotalWeight: {}", RandomNumber, TotalWeight);
|
||||
LOG_INFO(LogLoot, "RandomNumber: {} TotalWeight: {} Elements.size(): {}", RandomNumber, TotalWeight, Elements.size());
|
||||
}
|
||||
|
||||
for (auto& Element : Elements)
|
||||
@@ -181,4 +197,62 @@ FORCEINLINE static ValueType PickWeightedElement(const std::map<KeyType, ValueTy
|
||||
return ValueType();
|
||||
}
|
||||
|
||||
std::vector<LootDrop> PickLootDrops(FName TierGroupName, int ForcedLootTier = -1, bool bPrint = false, int recursive = 0);
|
||||
|
||||
template <typename KeyType, typename ValueType>
|
||||
FORCEINLINE static ValueType PickWeightedElement(const std::unordered_map<KeyType, ValueType>& Elements,
|
||||
std::function<float(ValueType)> GetWeightFn,
|
||||
std::function<float(float)> RandomFloatGenerator = RandomFloatForLoot,
|
||||
float TotalWeightParam = -1, bool bCheckIfWeightIsZero = false, int RandMultiplier = 1, KeyType* OutName = nullptr, bool bPrint = false, bool bKeepGoingUntilWeGetValue = false)
|
||||
{
|
||||
float TotalWeight = TotalWeightParam;
|
||||
|
||||
if (TotalWeight == -1)
|
||||
{
|
||||
TotalWeight = std::accumulate(Elements.begin(), Elements.end(), 0.0f, [&](float acc, const std::pair<KeyType, ValueType>& p) {
|
||||
auto Weight = GetWeightFn(p.second);
|
||||
|
||||
if (bPrint)
|
||||
{
|
||||
// if (Weight != 0)
|
||||
{
|
||||
LOG_INFO(LogLoot, "Adding weight {}", Weight);
|
||||
}
|
||||
}
|
||||
|
||||
return acc + Weight;
|
||||
});
|
||||
}
|
||||
|
||||
float RandomNumber = // UKismetMathLibrary::RandomFloatInRange(0, TotalWeight);
|
||||
RandMultiplier * RandomFloatGenerator(TotalWeight);
|
||||
|
||||
if (bPrint)
|
||||
{
|
||||
LOG_INFO(LogLoot, "RandomNumber: {} TotalWeight: {} Elements.size(): {}", RandomNumber, TotalWeight, Elements.size());
|
||||
}
|
||||
|
||||
for (auto& Element : Elements)
|
||||
{
|
||||
float Weight = GetWeightFn(Element.second);
|
||||
|
||||
if (bCheckIfWeightIsZero && Weight == 0)
|
||||
continue;
|
||||
|
||||
if (RandomNumber <= Weight)
|
||||
{
|
||||
if (OutName)
|
||||
*OutName = Element.first;
|
||||
|
||||
return Element.second;
|
||||
}
|
||||
|
||||
RandomNumber -= Weight;
|
||||
}
|
||||
|
||||
if (bKeepGoingUntilWeGetValue)
|
||||
return PickWeightedElement<KeyType, ValueType>(Elements, GetWeightFn, RandomFloatGenerator, TotalWeightParam, bCheckIfWeightIsZero, RandMultiplier, OutName, bPrint, bKeepGoingUntilWeGetValue);
|
||||
|
||||
return ValueType();
|
||||
}
|
||||
|
||||
std::vector<LootDrop> PickLootDrops(FName TierGroupName, int WorldLevel, int ForcedLootTier = -1, bool bPrint = false, int recursive = 0);
|
||||
Reference in New Issue
Block a user