Various code quality improvements
This commit is contained in:
@@ -1730,7 +1730,7 @@ public class ItemHelper(
|
||||
var oldRootId = itemWithChildren[0].Id;
|
||||
Dictionary<string, MongoId> idMappings = [];
|
||||
|
||||
idMappings[oldRootId.ToString()] = rootItem.Id;
|
||||
idMappings[oldRootId] = rootItem.Id;
|
||||
|
||||
foreach (var mod in itemWithChildren)
|
||||
{
|
||||
@@ -1805,44 +1805,13 @@ public class ItemHelper(
|
||||
public int GetRandomisedAmmoStackSize(TemplateItem ammoItemTemplate, int maxLimit = 60)
|
||||
{
|
||||
return ammoItemTemplate.Properties?.StackMaxSize == 1
|
||||
? 1
|
||||
? 1 // Max is one, nothing to randomise
|
||||
: randomUtil.GetInt(
|
||||
ammoItemTemplate.Properties?.StackMinRandom ?? 1,
|
||||
Math.Min(ammoItemTemplate.Properties?.StackMaxRandom ?? 1, maxLimit)
|
||||
);
|
||||
}
|
||||
|
||||
public MongoId? GetItemBaseType(MongoId tpl, bool rootOnly = true)
|
||||
{
|
||||
var result = GetItem(tpl);
|
||||
if (!result.Key)
|
||||
// Not an item
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var currentItem = result.Value;
|
||||
while (currentItem is not null)
|
||||
{
|
||||
if (currentItem.Type == "Node" && !rootOnly)
|
||||
// Hit first base type
|
||||
{
|
||||
return currentItem.Id;
|
||||
}
|
||||
|
||||
if (currentItem.Parent.IsEmpty())
|
||||
// No parent, reached root
|
||||
{
|
||||
return currentItem.Id;
|
||||
}
|
||||
|
||||
// Get parent item and start loop again
|
||||
currentItem = GetItem(tpl).Value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a 2D grid of a container's item slots
|
||||
/// </summary>
|
||||
|
||||
@@ -32,24 +32,6 @@ public class RepeatableQuestHelper(
|
||||
return repeatableConfig.QuestConfig.Elimination.FirstOrDefault(x => pmcLevel >= x.LevelRange.Min && pmcLevel <= x.LevelRange.Max);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the repeatable template ids for the provided side
|
||||
/// </summary>
|
||||
/// <param name="playerGroup">Side to get the templates for</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
public Dictionary<string, MongoId> GetRepeatableQuestTemplatesByGroup(PlayerGroup playerGroup)
|
||||
{
|
||||
var templates = QuestConfig.RepeatableQuestTemplates;
|
||||
|
||||
return playerGroup switch
|
||||
{
|
||||
PlayerGroup.Pmc => templates.Pmc,
|
||||
PlayerGroup.Scav => templates.Scav,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(playerGroup), playerGroup, null),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a cloned repeatable quest template for the provided type with a unique id
|
||||
/// </summary>
|
||||
@@ -59,12 +41,13 @@ public class RepeatableQuestHelper(
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
public RepeatableQuest? GetClonedQuestTemplateForType(RepeatableQuestType type, MongoId traderId)
|
||||
{
|
||||
var repeatableQuestTemplates = databaseService.GetTemplates().RepeatableQuests.Templates;
|
||||
var quest = type switch
|
||||
{
|
||||
RepeatableQuestType.Elimination => cloner.Clone(databaseService.GetTemplates().RepeatableQuests?.Templates?.Elimination),
|
||||
RepeatableQuestType.Completion => cloner.Clone(databaseService.GetTemplates().RepeatableQuests?.Templates?.Completion),
|
||||
RepeatableQuestType.Exploration => cloner.Clone(databaseService.GetTemplates().RepeatableQuests?.Templates?.Exploration),
|
||||
RepeatableQuestType.Pickup => cloner.Clone(databaseService.GetTemplates().RepeatableQuests?.Templates?.Pickup),
|
||||
RepeatableQuestType.Elimination => cloner.Clone(repeatableQuestTemplates?.Elimination),
|
||||
RepeatableQuestType.Completion => cloner.Clone(repeatableQuestTemplates?.Completion),
|
||||
RepeatableQuestType.Exploration => cloner.Clone(repeatableQuestTemplates?.Exploration),
|
||||
RepeatableQuestType.Pickup => cloner.Clone(repeatableQuestTemplates?.Pickup),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
@@ -100,28 +83,24 @@ public class RepeatableQuestHelper(
|
||||
)
|
||||
{
|
||||
var questData = GetClonedQuestTemplateForType(type, traderId);
|
||||
|
||||
if (questData is null)
|
||||
{
|
||||
logger.Error(serverLocalisationService.GetText("repeatable-quest_helper_template_not_found", type));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get template id from config based on side and type of quest
|
||||
var typeIds = GetRepeatableQuestTemplatesByGroup(playerGroup);
|
||||
|
||||
var templateName = Enum.GetName(type);
|
||||
|
||||
if (templateName is null)
|
||||
{
|
||||
logger.Error(serverLocalisationService.GetText("repeatable-quest_helper_template_name_not_found", type));
|
||||
return null;
|
||||
}
|
||||
|
||||
questData.TemplateId = typeIds[templateName];
|
||||
// Get template id from config based on side and type of quest
|
||||
var typeIds = GetRepeatableQuestTemplatesByGroup(playerGroup);
|
||||
questData.TemplateId = typeIds.GetValueOrDefault(templateName);
|
||||
|
||||
// Force REF templates to use prapors ID - solves missing text issue
|
||||
// TODO: Get rid of this new mongoid generation, needs handled in `Traders` but can't be done right now.
|
||||
var desiredTraderId = traderId == Traders.REF ? Traders.PRAPOR : traderId;
|
||||
|
||||
// In locale, these id correspond to the text of quests
|
||||
@@ -175,6 +154,24 @@ public class RepeatableQuestHelper(
|
||||
return questData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the repeatable template ids for the provided side
|
||||
/// </summary>
|
||||
/// <param name="playerGroup">Side to get the templates for</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
protected Dictionary<string, MongoId> GetRepeatableQuestTemplatesByGroup(PlayerGroup playerGroup)
|
||||
{
|
||||
var templates = QuestConfig.RepeatableQuestTemplates;
|
||||
|
||||
return playerGroup switch
|
||||
{
|
||||
PlayerGroup.Pmc => templates.Pmc,
|
||||
PlayerGroup.Scav => templates.Scav,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(playerGroup), playerGroup, null),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a raw location string into a location code can read (e.g. factory4_day into 55f2d3fd4bdc2d5f408b4567)
|
||||
/// </summary>
|
||||
|
||||
@@ -33,7 +33,7 @@ public class RewardHelper(
|
||||
/// Apply the given rewards to the passed in profile.
|
||||
/// </summary>
|
||||
/// <param name="rewards">List of rewards to apply.</param>
|
||||
/// <param name="source">The source of the rewards (Achievement, quest).</param>
|
||||
/// <param name="rewardSource">The source of the rewards (Achievement, quest).</param>
|
||||
/// <param name="fullProfile">The full profile to apply the rewards to.</param>
|
||||
/// <param name="profileData">The profile data (could be the scav profile).</param>
|
||||
/// <param name="rewardSourceId">The quest or achievement ID, used for finding production unlocks.</param>
|
||||
@@ -41,7 +41,7 @@ public class RewardHelper(
|
||||
/// <returns>List of items that is the reward.</returns>
|
||||
public List<Item> ApplyRewards(
|
||||
IEnumerable<Reward> rewards,
|
||||
string source,
|
||||
string rewardSource,
|
||||
SptProfile fullProfile,
|
||||
PmcData profileData,
|
||||
MongoId rewardSourceId,
|
||||
@@ -118,7 +118,7 @@ public class RewardHelper(
|
||||
profileHelper.ReplaceProfilePocketTpl(pmcProfile, reward.Target);
|
||||
break;
|
||||
case RewardType.CustomizationDirect:
|
||||
profileHelper.AddHideoutCustomisationUnlock(fullProfile, reward, source);
|
||||
profileHelper.AddHideoutCustomisationUnlock(fullProfile, reward, rewardSource);
|
||||
notificationSendHelper.SendMessage(
|
||||
sessionId.Value,
|
||||
new WsNotificationEvent
|
||||
@@ -208,11 +208,10 @@ public class RewardHelper(
|
||||
// Add above match to pmc profile + client response
|
||||
var matchingCraftId = matchingProductions[0].Id;
|
||||
pmcData.UnlockedInfo.UnlockedProductionRecipe.Add(matchingCraftId);
|
||||
if (response is not null)
|
||||
{
|
||||
response.ProfileChanges[sessionID].RecipeUnlocked ??= new Dictionary<string, bool>();
|
||||
response.ProfileChanges[sessionID].RecipeUnlocked[matchingCraftId] = true;
|
||||
}
|
||||
|
||||
// Update Inform client of change
|
||||
response.ProfileChanges[sessionID].RecipeUnlocked ??= new();
|
||||
response.ProfileChanges[sessionID].RecipeUnlocked[matchingCraftId] = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -91,7 +91,7 @@ public record ProfileChange
|
||||
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
|
||||
[JsonPropertyName("recipeUnlocked")]
|
||||
public Dictionary<string, bool>? RecipeUnlocked { get; set; }
|
||||
public Dictionary<MongoId, bool>? RecipeUnlocked { get; set; }
|
||||
|
||||
[JsonPropertyName("changedHideoutStashes")]
|
||||
public Dictionary<string, HideoutStashItem>? ChangedHideoutStashes { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user