This commit is contained in:
CWX
2025-01-23 12:10:49 +00:00
3 changed files with 87 additions and 10 deletions
@@ -148,13 +148,13 @@ public class RepeatableQuestGenerator(
var targetKey = targetsConfig.Draw()[0];
var targetDifficulty = 1 / targetsConfig.Probability(targetKey);
var locations = questTypePool.Pool.Elimination.Targets.GetByJsonProp<TargetLocation>(targetKey).Locations;
questTypePool.Pool.Elimination.Targets.TryGetValue(targetKey, out var targetLocationPool);
var locations = targetLocationPool.Locations;
// we use any as location if "any" is in the pool and we do not hit the specific location random
// we use any also if the random condition is not met in case only "any" was in the pool
var locationKey = "any";
if (locations.Contains("any") &&
(eliminationConfig.SpecificLocationProbability < rand.Next() || locations.Count <= 1)
if (locations.Contains("any") && (eliminationConfig.SpecificLocationProbability < rand.Next() || locations.Count <= 1)
)
{
locationKey = "any";
@@ -634,6 +634,7 @@ public class RepeatableQuestGenerator(
/// <returns>object of "Completion"-condition</returns>
protected QuestCondition GenerateCompletionAvailableForFinish(string itemTpl, double value)
{
_logger.Error("NOT IMPLEMENTED - GenerateCompletionAvailableForFinish");
throw new NotImplementedException();
}
@@ -1,7 +1,6 @@
using SptCommon.Annotations;
using Core.Helpers;
using Core.Models.Eft.Common.Tables;
using Core.Models.Eft.Player;
using Core.Models.Enums;
using Core.Models.Spt.Config;
using Core.Models.Spt.Repeatable;
@@ -10,7 +9,8 @@ using Core.Servers;
using Core.Services;
using Core.Utils;
using Core.Utils.Cloners;
using System.Linq;
using Core.Models.Eft.Common;
using Core.Models.Spt.Server;
namespace Core.Generators;
@@ -110,7 +110,7 @@ public class RepeatableQuestRewardGenerator(
if (traderWhitelistDetails?.RewardCanBeWeapon ?? false && _randomUtil.GetChance100(traderWhitelistDetails.WeaponRewardChancePercent ?? 0)
)
{
var chosenWeapon = GetRandomWeaponPresetWithinBudget(itemRewardBudget, rewardIndex);
var chosenWeapon = GetRandomWeaponPresetWithinBudget(itemRewardBudget.Value, rewardIndex);
if (chosenWeapon is not null)
{
rewards.Success.Add(chosenWeapon.Value.Key);
@@ -319,9 +319,81 @@ public class RepeatableQuestRewardGenerator(
}).ToList();
}
private KeyValuePair<Reward, double>? GetRandomWeaponPresetWithinBudget(double? itemRewardBudget, double rewardIndex)
private KeyValuePair<Reward, double>? GetRandomWeaponPresetWithinBudget(double roublesBudget, int rewardIndex)
{
throw new NotImplementedException();
// Add a random default preset weapon as reward
var defaultPresetPool = new ExhaustableArray<Preset>(
_presetHelper.GetDefaultWeaponPresets().Values.ToList(),
_randomUtil,
_cloner);
while (defaultPresetPool.HasValues())
{
var randomPreset = defaultPresetPool.GetRandomValue();
if (randomPreset is null)
{
continue;
}
// Gather all tpls so we can get prices of them
var tpls = randomPreset.Items.Select((item) => item.Template).ToList();
// Does preset items fit our budget
var presetPrice = _itemHelper.GetItemAndChildrenPrice(tpls);
if (presetPrice <= roublesBudget)
{
_logger.Debug("Added weapon: ${ tpls[0]}with price: ${ presetPrice}");
var chosenPreset = _cloner.Clone(randomPreset);
return new KeyValuePair<Reward, double>(GeneratePresetReward(chosenPreset.Encyclopedia, 1, rewardIndex, chosenPreset.Items), presetPrice);
}
}
return null;
}
/**
* Helper to create a reward item structured as required by the client
*
* @param {string} tpl ItemId of the rewarded item
* @param {integer} count Amount of items to give
* @param {integer} index All rewards will be appended to a list, for unknown reasons the client wants the index
* @param preset Optional array of preset items
* @returns {object} Object of "Reward"-item-type
*/
protected Reward GeneratePresetReward(string tpl, int count, int index, List<Item>? preset, bool foundInRaid = true)
{
var id = _hashUtil.Generate();
var questRewardItem = new Reward{
Id = _hashUtil.Generate(),
Unknown = false,
GameMode =[],
AvailableInGameEditions =[],
Index = index,
Target =id,
Value = count,
IsEncoded = false,
FindInRaid =foundInRaid,
Type =RewardType.Item,
Items =[],
};
// Get presets root item
var rootItem = preset.FirstOrDefault((item) => item.Template == tpl);
if (rootItem is null)
{
_logger.Warning($"Root item of preset: ${ tpl} not found");
}
if (rootItem.Upd is not null)
{
rootItem.Upd.SpawnedInSession = foundInRaid;
}
questRewardItem.Items = _itemHelper.ReparentItemAndChildren(rootItem, preset);
questRewardItem.Target = rootItem.Id; // Target property and root items id must match
return questRewardItem;
}
private Reward GenerateItemReward(string tpl, double count, int index, bool foundInRaid = true)
+6 -2
View File
@@ -376,7 +376,7 @@ public class ItemHelper(
public double GetItemAndChildrenPrice(List<string> tpls)
{
// Run getItemPrice for each tpl in tpls array, return sum
return tpls.Aggregate(0, (total, tpl) => total + (int)GetItemPrice(tpl));
return tpls.Aggregate(0, (total, tpl) => total + (int)GetItemPrice(tpl).GetValueOrDefault(0));
}
/// <summary>
@@ -762,7 +762,11 @@ public class ItemHelper(
ItemTpl.BARTER_DOGTAG_BEAR_TUE,
ItemTpl.BARTER_DOGTAG_USEC,
ItemTpl.BARTER_DOGTAG_USEC_EOD,
ItemTpl.BARTER_DOGTAG_USEC_TUE
ItemTpl.BARTER_DOGTAG_USEC_TUE,
ItemTpl.BARTER_DOGTAG_BEAR_PRESTIGE_1,
ItemTpl.BARTER_DOGTAG_BEAR_PRESTIGE_2,
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_1,
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_2
];
return dogTagTpls.Contains(tpl);