fix services and botgen level being null

This commit is contained in:
CWX
2025-01-14 18:02:14 +00:00
parent 826a463289
commit 0d1feb8017
4 changed files with 20 additions and 14 deletions
+16 -10
View File
@@ -43,7 +43,8 @@ public class BotLevelGenerator
// Get random level based on the exp table.
int exp = 0;
var level = int.Parse(ChooseBotLevel(botLevelRange.Min.Value, botLevelRange.Max.Value, 1, 1.15).ToString()); // TODO - nasty double to string to int conversion
var level = int.Parse(ChooseBotLevel(botLevelRange.Min.Value, botLevelRange.Max.Value, 1, 1.15)
.ToString()); // TODO - nasty double to string to int conversion
for (var i = 0; i < level; i++)
{
exp += expTable[i].Experience.Value;
@@ -55,7 +56,7 @@ public class BotLevelGenerator
exp += _randomUtil.GetInt(0, expTable[level].Experience.Value - 1);
}
return new RandomisedBotLevelResult{ Level = level, Exp = exp };
return new RandomisedBotLevelResult { Level = level, Exp = exp };
}
public double ChooseBotLevel(double min, double max, int shift, double number)
@@ -76,24 +77,29 @@ public class BotLevelGenerator
var pmcOverride = botGenerationDetails.LocationSpecificPmcLevelOverride;
var minPossibleLevel = isPmc && pmcOverride is not null
? Math.Min(
Math.Max(levelDetails.Min.Value, pmcOverride.Min.Value), // Biggest between json min and the botgen min
maxAvailableLevel // Fallback if value above is crazy (default is 79)
)
: Math.Min(levelDetails.Min.Value, maxAvailableLevel); // Not pmc with override or non-pmc
? Math.Min(
Math.Max(levelDetails.Min.Value, pmcOverride.Min.Value), // Biggest between json min and the botgen min
maxAvailableLevel // Fallback if value above is crazy (default is 79)
)
: Math.Min(levelDetails.Min.Value, maxAvailableLevel); // Not pmc with override or non-pmc
var maxPossibleLevel = isPmc && pmcOverride is not null
? Math.Min(pmcOverride.Max.Value, maxAvailableLevel) // Was a PMC and they have a level override
: Math.Min(levelDetails.Max.Value, maxAvailableLevel); // Not pmc with override or non-pmc
var minLevel = botGenerationDetails.PlayerLevel.Value - botGenerationDetails.BotRelativeLevelDeltaMin.Value;
var maxLevel = botGenerationDetails.PlayerLevel.Value + botGenerationDetails.BotRelativeLevelDeltaMin.Value;
var minLevel = botGenerationDetails.PlayerLevel.HasValue
? botGenerationDetails.PlayerLevel.Value
: 0 - botGenerationDetails.BotRelativeLevelDeltaMin.Value;
var maxLevel = botGenerationDetails.PlayerLevel.HasValue
? botGenerationDetails.PlayerLevel.Value
: 0 + botGenerationDetails.BotRelativeLevelDeltaMin.Value;
// Bound the level to the min/max possible
maxLevel = Math.Min(Math.Max(maxLevel, minPossibleLevel), maxPossibleLevel);
minLevel = Math.Min(Math.Max(minLevel, minPossibleLevel), maxPossibleLevel);
return new MinMax{
return new MinMax
{
Min = minLevel,
Max = maxLevel,
};
+2 -2
View File
@@ -1044,9 +1044,9 @@ public class ItemHelper
throw new NotImplementedException();
}
public bool IsOfBaseclass(string valueEncyclopedia, string weapon)
public bool IsOfBaseclass(string tpl, List<string> baseClassTpls)
{
throw new NotImplementedException();
return _itemBaseClassService.ItemHasBaseClass(tpl, baseClassTpls);
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ public class PresetHelper
var tempPresets = _databaseService.GetGlobals().ItemPresets;
tempPresets = tempPresets.Where(p =>
p.Value.Encyclopedia != null &&
_itemHelper.IsOfBaseclass(p.Value.Encyclopedia, BaseClasses.WEAPON)).ToDictionary();
_itemHelper.IsOfBaseclass(p.Value.Encyclopedia, [BaseClasses.WEAPON])).ToDictionary();
}
return _defaultWeaponPresets;
+1 -1
View File
@@ -450,7 +450,7 @@ public class MailSendService
}
// Boxes can contain sub-items
if (_itemHelper.IsOfBaseclass(itemTemplate.Id, BaseClasses.AMMO_BOX))
if (_itemHelper.IsOfBaseclass(itemTemplate.Id, [BaseClasses.AMMO_BOX]))
{
var boxAndCartridges = new List<Item>();
boxAndCartridges.Add(reward);