Part 2 of list to ienumerable

This commit is contained in:
Chomp
2025-07-23 15:55:28 +01:00
parent 0faa65a560
commit a1e0dadd08
29 changed files with 166 additions and 162 deletions
@@ -87,29 +87,29 @@ public class BuildController(
/// Handle client/builds/weapon/save
/// </summary>
/// <param name="sessionId">Session/Player id</param>
/// <param name="body"></param>
public void SaveWeaponBuild(MongoId sessionId, PresetBuildActionRequestData body)
/// <param name="request"></param>
public void SaveWeaponBuild(MongoId sessionId, PresetBuildActionRequestData request)
{
var pmcData = profileHelper.GetPmcProfile(sessionId);
// Replace duplicate Id's. The first item is the base item.
// The root ID and the base item ID need to match.
body.Items = itemHelper.ReplaceIDs(body.Items, pmcData);
body.Root = body.Items.FirstOrDefault().Id;
request.Items = itemHelper.ReplaceIDs(request.Items, pmcData);
request.Root = request.Items.FirstOrDefault().Id;
// Create new object ready to save into profile userbuilds.weaponBuilds
var newBuild = new WeaponBuild
{
Id = body.Id,
Name = body.Name,
Root = body.Root,
Items = body.Items,
Id = request.Id,
Name = request.Name,
Root = request.Root,
Items = request.Items.ToList(),
};
var profile = profileHelper.GetFullProfile(sessionId);
var savedWeaponBuilds = profile.UserBuildData.WeaponBuilds;
var existingBuild = savedWeaponBuilds.FirstOrDefault(x => x.Id == body.Id);
var existingBuild = savedWeaponBuilds.FirstOrDefault(x => x.Id == request.Id);
if (existingBuild is not null)
{
// exists, replace
@@ -146,8 +146,8 @@ public class BuildController(
Id = request.Id,
Name = request.Name,
BuildType = EquipmentBuildType.Custom,
Root = request.Items[0].Id,
Items = request.Items,
Root = request.Items.First().Id,
Items = request.Items.ToList(),
};
var existingBuild = existingSavedEquipmentBuilds?.FirstOrDefault(build =>
@@ -66,7 +66,7 @@ public class InsuranceController(
var insuranceDetails = FilterInsuredItems(sessionId);
// Skip profile if no insured items to process
if (insuranceDetails.Count == 0)
if (!insuranceDetails.Any())
{
return;
}
@@ -80,7 +80,7 @@ public class InsuranceController(
/// <param name="sessionId">Session/Player id</param>
/// <param name="time">The time to check ready status against. Current time by default</param>
/// <returns>All insured items that are ready to be processed</returns>
protected List<Insurance> FilterInsuredItems(MongoId sessionId, long? time = null)
protected IEnumerable<Insurance> FilterInsuredItems(MongoId sessionId, long? time = null)
{
// Use the current time by default.
var insuranceTime = time ?? timeUtil.GetTimeStamp();
@@ -96,9 +96,7 @@ public class InsuranceController(
}
}
return profileInsuranceDetails
.Where(insured => insuranceTime >= insured.ScheduledTime)
.ToList();
return profileInsuranceDetails.Where(insured => insuranceTime >= insured.ScheduledTime);
}
/// <summary>
@@ -106,12 +104,12 @@ public class InsuranceController(
/// </summary>
/// <param name="insuranceDetails">The insured items to process</param>
/// <param name="sessionId">session ID that should receive the processed items</param>
protected void ProcessInsuredItems(List<Insurance> insuranceDetails, MongoId sessionId)
protected void ProcessInsuredItems(IEnumerable<Insurance> insuranceDetails, MongoId sessionId)
{
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug(
$"Processing {insuranceDetails.Count} insurance packages, which includes a total of: {CountAllInsuranceItems(insuranceDetails)} items, in profile: {sessionId}"
$"Processing {insuranceDetails.Count()} insurance packages, which includes a total of: {CountAllInsuranceItems(insuranceDetails)} items, in profile: {sessionId}"
);
}
@@ -149,7 +147,7 @@ public class InsuranceController(
/// </summary>
/// <param name="insuranceDetails"></param>
/// <returns>Count of insured items</returns>
protected int CountAllInsuranceItems(List<Insurance> insuranceDetails)
protected int CountAllInsuranceItems(IEnumerable<Insurance> insuranceDetails)
{
return insuranceDetails.Select(ins => ins.Items.Count).Count();
}
@@ -238,13 +236,13 @@ public class InsuranceController(
/// <param name="insured">The insurance object containing the items to evaluate</param>
/// <param name="itemsMap">A Dictionary for quick item look-up by item ID</param>
/// <returns>A dictionary containing parent item IDs to arrays of their attachment items</returns>
protected Dictionary<string, List<Item>> PopulateParentAttachmentsMap(
protected Dictionary<MongoId, List<Item>> PopulateParentAttachmentsMap(
string rootItemParentID,
Insurance insured,
Dictionary<MongoId, Item> itemsMap
)
{
var mainParentToAttachmentsMap = new Dictionary<string, List<Item>>();
var mainParentToAttachmentsMap = new Dictionary<MongoId, List<Item>>();
foreach (var insuredItem in insured.Items)
{
// Use the parent ID from the item to get the parent item.
@@ -335,12 +333,12 @@ public class InsuranceController(
/// <param name="parentAttachmentsMap">Dictionary containing parent item IDs to arrays of their attachment items</param>
/// <param name="itemsMap">Hashset containing parent item IDs to arrays of their attachment items which are not moddable in-raid</param>
/// <returns></returns>
protected Dictionary<string, List<Item>> RemoveNonModdableAttachments(
Dictionary<string, List<Item>> parentAttachmentsMap,
protected Dictionary<MongoId, List<Item>> RemoveNonModdableAttachments(
Dictionary<MongoId, List<Item>> parentAttachmentsMap,
Dictionary<MongoId, Item> itemsMap
)
{
var updatedMap = new Dictionary<string, List<Item>>();
var updatedMap = new Dictionary<MongoId, List<Item>>();
foreach (var map in parentAttachmentsMap)
{
@@ -389,7 +387,7 @@ public class InsuranceController(
protected void ProcessRegularItems(
Insurance insured,
HashSet<MongoId> toDelete,
Dictionary<string, List<Item>> parentAttachmentsMap
Dictionary<MongoId, List<Item>> parentAttachmentsMap
)
{
foreach (var insuredItem in insured.Items)
@@ -436,7 +434,7 @@ public class InsuranceController(
/// <param name="insuredTraderId">Trader ID from the Insurance object</param>
/// <param name="toDelete">Tracked attachment ids to be removed</param>
protected void ProcessAttachments(
Dictionary<string, List<Item>> mainParentToAttachmentsMap,
Dictionary<MongoId, List<Item>> mainParentToAttachmentsMap,
Dictionary<MongoId, Item> itemsMap,
MongoId? insuredTraderId,
HashSet<MongoId> toDelete
@@ -474,7 +472,7 @@ public class InsuranceController(
/// <param name="traderId">ID of the trader to that has ensured these items</param>
/// <param name="toDelete">array that accumulates the IDs of the items to be deleted</param>
protected void ProcessAttachmentByParent(
List<Item> attachments,
IEnumerable<Item> attachments,
MongoId traderId,
HashSet<MongoId> toDelete
)
@@ -522,8 +520,8 @@ public class InsuranceController(
/// <param name="attachments"></param>
/// <param name="attachmentPrices"></param>
protected void LogAttachmentsBeingRemoved(
List<MongoId> attachmentIdsToRemove,
List<Item> attachments,
IEnumerable<MongoId> attachmentIdsToRemove,
IEnumerable<Item> attachments,
Dictionary<MongoId, double> attachmentPrices
)
{
@@ -547,7 +545,7 @@ public class InsuranceController(
/// </summary>
/// <param name="attachments">Item attachments</param>
/// <returns></returns>
protected Dictionary<MongoId, double> WeightAttachmentsByPrice(List<Item> attachments)
protected Dictionary<MongoId, double> WeightAttachmentsByPrice(IEnumerable<Item> attachments)
{
var result = new Dictionary<MongoId, double>();
@@ -183,7 +183,7 @@ public class InventoryController(
{
// The client sends the full list of favorite items, so clear the current favorites
pmcData.Inventory.FavoriteItems = [];
pmcData.Inventory.FavoriteItems.AddRange(request.Items);
pmcData.Inventory.FavoriteItems = pmcData.Inventory.FavoriteItems.Union(request.Items);
}
/// <summary>
@@ -336,7 +336,7 @@ public class TradeController(
/// <returns>Rouble price</returns>
protected int GetPriceOfItemAndChildren(
MongoId parentItemId,
List<Item> items,
IEnumerable<Item> items,
Dictionary<MongoId, int?> handbookPrices,
TraderBase traderDetails
)
@@ -197,7 +197,8 @@ public class BotEquipmentModGenerator(
);
switch (plateSlotFilteringOutcome.Result)
{
case Result.UNKNOWN_FAILURE or Result.NO_DEFAULT_FILTER:
case Result.UNKNOWN_FAILURE
or Result.NO_DEFAULT_FILTER:
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug(
@@ -1125,7 +1126,7 @@ public class BotEquipmentModGenerator(
var parentSlot = request.ParentTemplate.Properties.Slots?.FirstOrDefault(i =>
i.Name == request.ModSlot
);
var weaponTemplate = itemHelper.GetItem(request.Weapon[0].Template).Value;
var weaponTemplate = itemHelper.GetItem(request.Weapon.First().Template).Value;
// It's ammo, use predefined ammo parameter
if (GetAmmoContainers().Contains(request.ModSlot) && request.ModSlot != "mod_magazine")
@@ -1155,7 +1156,7 @@ public class BotEquipmentModGenerator(
if (modPool.Count > 1)
{
modPool = FilterSightsByWeaponType(
request.Weapon[0],
request.Weapon.First(),
modPool,
request.BotWeaponSightWhitelist
);
@@ -1261,7 +1262,7 @@ public class BotEquipmentModGenerator(
if (parentSlot.Required.GetValueOrDefault(false))
{
logger.Warning(
$"Required slot unable to be filled, {request.ModSlot} on {request.ParentTemplate.Name} {request.ParentTemplate.Id} for weapon: {request.Weapon[0].Template}"
$"Required slot unable to be filled, {request.ModSlot} on {request.ParentTemplate.Name} {request.ParentTemplate.Id} for weapon: {request.Weapon.First().Template}"
);
}
@@ -1323,7 +1324,7 @@ public class BotEquipmentModGenerator(
HashSet<MongoId> modPool,
Slot parentSlot,
ModSpawn? choiceTypeEnum,
List<Item> weapon,
IEnumerable<Item> weapon,
string modSlotName
)
{
@@ -1366,7 +1367,7 @@ public class BotEquipmentModGenerator(
public ChooseRandomCompatibleModResult GetCompatibleModFromPool(
HashSet<MongoId> modPool,
ModSpawn? modSpawnType,
List<Item> weapon
IEnumerable<Item> weapon
)
{
// Create exhaustable pool to pick mod item from
@@ -1649,11 +1650,11 @@ public class BotEquipmentModGenerator(
/// <param name="weapon">Array of items that make up a weapon</param>
/// <param name="modTpl">Mod to check compatibility with weapon</param>
/// <returns>True if incompatible</returns>
public bool WeaponModComboIsIncompatible(List<Item> weapon, MongoId modTpl)
public bool WeaponModComboIsIncompatible(IEnumerable<Item> weapon, MongoId modTpl)
{
// STM-9 + AR-15 Lone Star Ion Lite handguard
if (
weapon[0].Template == ItemTpl.SMG_SOYUZTM_STM9_GEN2_9X19_CARBINE
weapon.First().Template == ItemTpl.SMG_SOYUZTM_STM9_GEN2_9X19_CARBINE
&& modTpl == ItemTpl.HANDGUARD_AR15_LONE_STAR_ION_LITE
)
{
@@ -1714,7 +1715,7 @@ public class BotEquipmentModGenerator(
MongoId fallbackModTpl,
Slot parentSlot,
string modSlot,
List<Item> items
IEnumerable<Item> items
)
{
// Find compatible mods and make an array of them
@@ -552,7 +552,7 @@ public class BotLootGenerator(
new()
{
Id = newRootItemId,
Template = itemToAddTemplate?.Id ?? string.Empty,
Template = itemToAddTemplate?.Id ?? MongoId.Empty(),
Upd = botGeneratorHelper.GenerateExtraPropertiesForItem(
itemToAddTemplate,
botRole
@@ -619,7 +619,7 @@ public class BotWeaponGenerator(
/// <param name="botRole">The bot type we are getting the magazine for.</param>
/// <returns>Magazine template string.</returns>
protected MongoId? GetMagazineTemplateFromWeaponTemplate(
List<Item> weaponMods,
IEnumerable<Item> weaponMods,
TemplateItem weaponTemplate,
string botRole
)
@@ -35,7 +35,7 @@ public class FenceBaseAssortGenerator(
public void GenerateFenceBaseAssorts()
{
var blockedSeasonalItems = seasonalEventService.GetInactiveSeasonalEventItems();
var baseFenceAssort = databaseService.GetTrader(Traders.FENCE).Assort;
var baseFenceAssort = databaseService.GetTrader(Traders.FENCE)?.Assort;
foreach (var (itemId, rootItemDb) in databaseService.GetItems())
{
@@ -165,7 +165,7 @@ public class FenceBaseAssortGenerator(
}
// Construct preset + mods
var itemAndChildren = _cloner.Clone(defaultPreset.Items).ReplaceIDs().ToList();
var itemAndChildren = _cloner.Clone(defaultPreset.Items).ReplaceIDs();
// Find root item and add some properties to it
var rootItem = itemAndChildren.FirstOrDefault(item =>
@@ -187,7 +187,7 @@ public class FenceBaseAssortGenerator(
var itemQualityModifier = itemHelper.GetItemQualityModifierForItems(itemAndChildren);
// Multiply weapon+mods rouble price by quality modifier
baseFenceAssort.BarterScheme[itemAndChildren[0].Id] =
baseFenceAssort.BarterScheme[itemAndChildren.First().Id] =
[
new()
{
@@ -199,7 +199,7 @@ public class FenceBaseAssortGenerator(
},
];
baseFenceAssort.LoyalLevelItems[itemAndChildren[0].Id] = 1;
baseFenceAssort.LoyalLevelItems[itemAndChildren.First().Id] = 1;
}
}
@@ -624,8 +624,8 @@ public class LocationLootGenerator(
);
// Update root item properties with result of position finder
items[0].SlotId = "main";
items[0].Location = new ItemLocation
items.First().SlotId = "main";
items.First().Location = new ItemLocation
{
X = result.X,
Y = result.Y,
@@ -1460,7 +1460,7 @@ public record ContainerGroupCount
public class ContainerItem
{
[JsonPropertyName("items")]
public List<Item>? Items { get; set; }
public IEnumerable<Item>? Items { get; set; }
[JsonPropertyName("width")]
public int? Width { get; set; }
@@ -41,7 +41,7 @@ public class RagfairAssortGenerator(
/// Each sub list contains item + children (if any)
/// </summary>
/// <returns> List with children lists of items </returns>
public List<List<Item>> GetAssortItems()
public IEnumerable<List<Item>> GetAssortItems()
{
return GenerateRagfairAssortItems();
}
@@ -50,9 +50,9 @@ public class RagfairAssortGenerator(
/// Generate a list of lists (item + children) the flea can sell
/// </summary>
/// <returns> List of lists (item + children)</returns>
protected List<List<Item>> GenerateRagfairAssortItems()
protected IEnumerable<List<Item>> GenerateRagfairAssortItems()
{
List<List<Item>> results = [];
IEnumerable<List<Item>> results = [];
// Get cloned items from db
var dbItems = databaseService
@@ -76,16 +76,16 @@ public class RagfairAssortGenerator(
// Add presets base item tpl to the processed list so its skipped later on when processing items
processedArmorItems.Add(preset.Items[0].Template);
presetAndModsClone[0].ParentId = "hideout";
presetAndModsClone[0].SlotId = "hideout";
presetAndModsClone[0].Upd = new Upd
presetAndModsClone.First().ParentId = "hideout";
presetAndModsClone.First().SlotId = "hideout";
presetAndModsClone.First().Upd = new Upd
{
StackObjectsCount = 99999999,
UnlimitedCount = true,
SptPresetId = preset.Id,
};
results.Add(presetAndModsClone);
results = results.Union([presetAndModsClone]);
}
foreach (var (id, item) in dbItems)
@@ -105,15 +105,14 @@ public class RagfairAssortGenerator(
continue;
}
if (processedArmorItems.Contains(id))
// Already processed
if (processedArmorItems.Contains(id))
{
continue;
}
var ragfairAssort = CreateRagfairAssortRootItem(id, id); // tpl and id must be the same so hideout recipe rewards work
results.Add([ragfairAssort]);
var assortItemToAdd = new List<Item> { CreateRagfairAssortRootItem(id, id) }; // tpl and id must be the same so hideout recipe rewards work
results = results.Union([assortItemToAdd]);
}
return results;
@@ -362,13 +362,13 @@ public class RagfairOfferGenerator(
stopwatch.Restart();
var tasks = new List<Task>();
foreach (var assortItem in assortItemsToProcess)
foreach (var assortItemWithChildren in assortItemsToProcess)
{
tasks.Add(
Task.Factory.StartNew(() =>
{
CreateOffersFromAssort(
assortItem,
assortItemWithChildren,
replacingExpiredOffers,
ragfairConfig.Dynamic
);
@@ -725,12 +725,12 @@ public class RagfairOfferGenerator(
/// <param name="itemDetails"> DB details of first item</param>
protected void RandomiseOfferItemUpdProperties(
MongoId userID,
List<Item> itemWithMods,
IEnumerable<Item> itemWithMods,
TemplateItem itemDetails
)
{
// Add any missing properties to first item in array
AddMissingConditions(itemWithMods[0]);
AddMissingConditions(itemWithMods.First());
if (!(profileHelper.IsPlayer(userID) || ragfairServerHelper.IsTrader(userID)))
{
@@ -781,11 +781,11 @@ public class RagfairOfferGenerator(
/// <param name="itemDetails"> DB Item details of first item in list </param>
protected void RandomiseItemCondition(
MongoId conditionSettingsId,
List<Item> itemWithMods,
IEnumerable<Item> itemWithMods,
TemplateItem itemDetails
)
{
var rootItem = itemWithMods[0];
var rootItem = itemWithMods.First();
var itemConditionValues = ragfairConfig.Dynamic.Condition[conditionSettingsId];
var maxMultiplier = randomUtil.GetDouble(
@@ -827,7 +827,7 @@ public class RagfairOfferGenerator(
if (itemHelper.IsOfBaseclass(itemDetails.Id, BaseClasses.WEAPON))
{
RandomiseWeaponDurability(
itemWithMods[0],
itemWithMods.First(),
itemDetails,
maxMultiplier,
currentMultiplier
@@ -924,7 +924,7 @@ public class RagfairOfferGenerator(
/// <param name="currentMultiplier"> Chosen multiplier to use for current durability value </param>
/// <param name="maxMultiplier"> Chosen multiplier to use for max durability value </param>
protected void RandomiseArmorDurabilityValues(
List<Item> armorWithMods,
IEnumerable<Item> armorWithMods,
double currentMultiplier,
double maxMultiplier
)
@@ -821,7 +821,7 @@ public class RepeatableQuestRewardGenerator(
MongoId tpl,
HashSet<MongoId> itemTplBlacklist,
HashSet<MongoId> itemTypeBlacklist,
List<MongoId>? itemBaseWhitelist = null
IEnumerable<MongoId>? itemBaseWhitelist = null
)
{
// Return early if not valid item to give as reward
@@ -40,7 +40,7 @@ public class ScavCaseRewardGenerator(
/// </summary>
/// <param name="recipeId">recipe of the scav case craft</param>
/// <returns>Product array</returns>
public List<List<Item>> Generate(MongoId recipeId)
public IEnumerable<List<Item>> Generate(MongoId recipeId)
{
CacheDbItems();
@@ -91,13 +91,9 @@ public class ScavCaseRewardGenerator(
RewardRarity.SuperRare
);
var result = new List<List<Item>>();
result = result.Concat(commonRewards).ToList();
result = result.Concat(rareRewards).ToList();
result = result.Concat(superRareRewards).ToList();
// TODO: please make this better, how merge 2d Lists
var result = commonRewards.Concat(rareRewards).Concat(superRareRewards);
return result.ToList();
return result;
}
/// <summary>
@@ -365,7 +361,7 @@ public class ScavCaseRewardGenerator(
/// <param name="rarity">The rarity desired ammo reward is for</param>
/// <returns>Product array</returns>
protected List<List<Item>> RandomiseContainerItemRewards(
List<TemplateItem> rewardItems,
IEnumerable<TemplateItem> rewardItems,
string rarity
)
{
@@ -130,7 +130,7 @@ public class HandbookHelper(
/// </summary>
/// <param name="items">Items to Sum</param>
/// <returns></returns>
public double GetTemplatePriceForItems(List<Item> items)
public double GetTemplatePriceForItems(IEnumerable<Item> items)
{
var total = 0D;
foreach (var item in items)
@@ -1510,9 +1510,9 @@ public class HideoutHelper(
);
// Get all slotted dogtag items
var activeDogtags = pmcData
.Inventory.Items.Where(item => item?.SlotId?.StartsWith("dogtag") ?? false)
.ToList();
var activeDogtags = pmcData.Inventory.Items.Where(item =>
item?.SlotId?.StartsWith("dogtag") ?? false
);
// Calculate bonus percent (apply hideoutManagement bonus)
var hideoutManagementSkill = pmcData.GetSkillFromProfile(SkillTypes.HideoutManagement);
@@ -1534,7 +1534,7 @@ public class HideoutHelper(
/// <returns>Combat bonus</returns>
protected static double GetDogtagCombatSkillBonusPercent(
PmcData pmcData,
List<Item> activeDogtags
IEnumerable<Item> activeDogtags
)
{
// Not own dogtag
@@ -1542,12 +1542,12 @@ public class HideoutHelper(
var result = 0D;
foreach (var dogtag in activeDogtags)
{
if (dogtag.Upd.Dogtag is null)
if (dogtag.Upd?.Dogtag?.AccountId is null)
{
continue;
}
if (int.Parse(dogtag.Upd.Dogtag?.AccountId) == pmcData.Aid)
if (int.Parse(dogtag.Upd.Dogtag.AccountId) == pmcData.Aid)
{
continue;
}
@@ -110,7 +110,7 @@ public class InRaidHelper(
/// Remove FiR status from items.
/// </summary>
/// <param name="items">Items to process</param>
protected void RemoveFiRStatusFromItems(List<Item> items)
protected void RemoveFiRStatusFromItems(IEnumerable<Item> items)
{
var dbItems = databaseService.GetItems();
@@ -225,40 +225,38 @@ public class InRaidHelper(
/// </summary>
/// <param name="pmcProfile">Profile to get items from</param>
/// <returns>List of items lost on death</returns>
protected List<Item> GetInventoryItemsLostOnDeath(PmcData pmcProfile)
protected IEnumerable<Item> GetInventoryItemsLostOnDeath(PmcData pmcProfile)
{
var inventoryItems = pmcProfile.Inventory.Items ?? [];
var equipmentRootId = pmcProfile?.Inventory?.Equipment;
var questRaidItemContainerId = pmcProfile?.Inventory?.QuestRaidItems;
return inventoryItems
.Where(item =>
return inventoryItems.Where(item =>
{
// Keep items flagged as kept after death
if (IsItemKeptAfterDeath(pmcProfile, item))
{
// Keep items flagged as kept after death
if (IsItemKeptAfterDeath(pmcProfile, item))
{
return false;
}
// Remove normal items or quest raid items
if (item.ParentId == equipmentRootId || item.ParentId == questRaidItemContainerId)
{
return true;
}
// Pocket items are lost on death
// Ensure we don't pick up pocket items from mannequins
if (
item.SlotId.StartsWith("pocket")
&& pmcProfile.DoesItemHaveRootId(item, pmcProfile.Inventory.Equipment)
)
{
return true;
}
return false;
})
.ToList();
}
// Remove normal items or quest raid items
if (item.ParentId == equipmentRootId || item.ParentId == questRaidItemContainerId)
{
return true;
}
// Pocket items are lost on death
// Ensure we don't pick up pocket items from mannequins
if (
item.SlotId.StartsWith("pocket")
&& pmcProfile.DoesItemHaveRootId(item, pmcProfile.Inventory.Equipment)
)
{
return true;
}
return false;
});
}
/// <summary>
@@ -257,10 +257,10 @@ public class InventoryHelper(
/// <param name="containerFS2D">Container grid</param>
/// <param name="itemWithChildren">Item to check fits</param>
/// <returns>True it fits</returns>
public bool CanPlaceItemInContainer(int[,] containerFS2D, List<Item> itemWithChildren)
public bool CanPlaceItemInContainer(int[,] containerFS2D, IEnumerable<Item> itemWithChildren)
{
// Get x/y size of item
var rootItem = itemWithChildren[0];
var rootItem = itemWithChildren.First();
var (sizeX, sizeY) = GetItemSize(rootItem.Template, rootItem.Id, itemWithChildren);
// Look for a place to slot item into
@@ -67,8 +67,12 @@ public class ItemHelper(
ItemTpl.BARTER_DOGTAG_USEC_TUE,
ItemTpl.BARTER_DOGTAG_BEAR_PRESTIGE_1,
ItemTpl.BARTER_DOGTAG_BEAR_PRESTIGE_2,
ItemTpl.BARTER_DOGTAG_BEAR_PRESTIGE_3,
ItemTpl.BARTER_DOGTAG_BEAR_PRESTIGE_4,
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_1,
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_2,
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_3,
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_4,
];
protected static readonly FrozenSet<string> _softInsertIds =
@@ -328,7 +332,7 @@ public class ItemHelper(
/// <param name="tpl">Item to check base classes of</param>
/// <param name="baseClassTpls">Base classes to check for</param>
/// <returns>True if any supplied base classes match</returns>
public bool IsOfBaseclasses(MongoId tpl, ICollection<MongoId> baseClassTpls)
public bool IsOfBaseclasses(MongoId tpl, IEnumerable<MongoId> baseClassTpls)
{
return itemBaseClassService.ItemHasBaseClass(tpl, baseClassTpls);
}
@@ -729,7 +733,7 @@ public class ItemHelper(
/// <param name="itemIdToFind">Template id of item to check for</param>
/// <param name="assort">List of items to check in</param>
/// <returns>List of children of requested item</returns>
public List<Item> FindAndReturnChildrenByAssort(MongoId itemIdToFind, List<Item> assort)
public List<Item> FindAndReturnChildrenByAssort(MongoId itemIdToFind, IEnumerable<Item> assort)
{
List<Item> list = [];
var itemIdToFindString = itemIdToFind.ToString();
@@ -901,8 +905,8 @@ public class ItemHelper(
/// <returns>List of Item objects.</returns>
public List<Item> FindBarterItems(
string by,
List<Item> itemsToSearch,
List<MongoId> desiredBarterItemIds
IEnumerable<Item> itemsToSearch,
IEnumerable<MongoId> desiredBarterItemIds
)
{
// Find required items to take after buying (handles multiple items)
@@ -933,13 +937,13 @@ public class ItemHelper(
/// </summary>
/// <param name="itemWithChildren">Item with mods to update.</param>
/// <param name="newId">New id to add on children of base item.</param>
public void ReplaceRootItemID(List<Item> itemWithChildren, string newId = "")
public void ReplaceRootItemID(IEnumerable<Item> itemWithChildren, MongoId newId)
{
// original id on base item
var oldId = itemWithChildren[0].Id;
var oldId = itemWithChildren.First().Id;
// Update base item to use new id
itemWithChildren[0].Id = newId;
itemWithChildren.First().Id = newId;
// Update all parentIds of items attached to base item to use new id
foreach (var item in itemWithChildren)
@@ -958,7 +962,7 @@ public class ItemHelper(
/// <param name="insuredItems"></param>
public void ReplaceProfileInventoryIds(
BotBaseInventory inventory,
List<InsuredItem>? insuredItems = null
IEnumerable<InsuredItem>? insuredItems = null
)
{
// Blacklist
@@ -1028,10 +1032,10 @@ public class ItemHelper(
/// <param name="insuredItems">Insured items that should not have their IDs replaced</param>
/// <param name="fastPanel">Quick slot panel</param>
/// <returns>Items</returns>
public List<Item> ReplaceIDs(
List<Item> originalItems,
public IEnumerable<Item> ReplaceIDs(
IEnumerable<Item> originalItems,
PmcData? pmcData,
List<InsuredItem>? insuredItems = null,
IEnumerable<InsuredItem>? insuredItems = null,
Dictionary<string, string>? fastPanel = null
)
{
@@ -1090,6 +1094,7 @@ public class ItemHelper(
}
// Update quickslot id
// TODO: i dont think the fast panel key is a mongoid, it should be e.g. "Item4"
if (pmcData.Inventory.FastPanel.ContainsKey(originalId))
{
pmcData.Inventory.FastPanel[originalId] = newId;
@@ -1105,7 +1110,7 @@ public class ItemHelper(
/// Will not flag ammo or currency as FiR
/// </summary>
/// <param name="items">The list of items to mark as FiR</param>
public void SetFoundInRaid(List<Item> items)
public void SetFoundInRaid(IEnumerable<Item> items)
{
foreach (var item in items)
{
@@ -65,7 +65,8 @@ public class PrestigeHelper(
}
else
{
newProfile.CharacterData.PmcData.Skills.Common.Add(skillToCopy);
newProfile.CharacterData.PmcData.Skills.Common =
newProfile.CharacterData.PmcData.Skills.Common.Union([skillToCopy]);
}
}
@@ -84,7 +85,8 @@ public class PrestigeHelper(
}
else
{
newProfile.CharacterData.PmcData.Skills.Mastering.Add(skillToCopy);
newProfile.CharacterData.PmcData.Skills.Mastering =
newProfile.CharacterData.PmcData.Skills.Mastering.Union([skillToCopy]);
}
}
}
@@ -225,8 +225,8 @@ public class TraderHelper(
else
{
pmcData.Info.Bans ??= [];
pmcData.Info.Bans.Add(
new Ban { BanType = BanType.RagFair, DateTime = newBanDateTime }
pmcData.Info.Bans = pmcData.Info.Bans.Union(
[new Ban { BanType = BanType.RagFair, DateTime = newBanDateTime }]
);
}
}
@@ -208,7 +208,7 @@ public record Info
public MemberCategory? SelectedMemberCategory { get; set; }
public List<Ban>? Bans { get; set; }
public IEnumerable<Ban>? Bans { get; set; }
[JsonPropertyName("lockedMoveCommands")]
public bool? LockedMoveCommands { get; set; }
@@ -425,11 +425,14 @@ public record BotBaseInventory
// TODO: key should be EAreaType enum
public Dictionary<string, MongoId>? HideoutAreaStashes { get; set; } // Key = hideout area key as string
/// <summary>
/// key = "Item4", "Item10"
/// </summary>
[JsonPropertyName("fastPanel")]
public Dictionary<string, MongoId>? FastPanel { get; set; }
[JsonPropertyName("favoriteItems")]
public List<MongoId>? FavoriteItems { get; set; }
public IEnumerable<MongoId>? FavoriteItems { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
[JsonPropertyName("hideoutCustomizationStashId")]
@@ -441,9 +444,9 @@ public record Skills
[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }
public List<CommonSkill> Common { get; set; }
public IEnumerable<CommonSkill> Common { get; set; }
public List<MasterySkill>? Mastering { get; set; }
public IEnumerable<MasterySkill>? Mastering { get; set; }
public double? Points { get; set; }
}
@@ -491,9 +494,9 @@ public record EftStats
[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }
public List<string>? CarriedQuestItems { get; set; }
public IEnumerable<string>? CarriedQuestItems { get; set; }
public List<Victim>? Victims { get; set; }
public IEnumerable<Victim>? Victims { get; set; }
public double? TotalSessionExperience { get; set; }
@@ -510,9 +513,9 @@ public record EftStats
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public Aggressor? Aggressor { get; set; }
public List<DroppedItem>? DroppedItems { get; set; }
public IEnumerable<DroppedItem>? DroppedItems { get; set; }
public List<FoundInRaidItem>? FoundInRaidItems { get; set; }
public IEnumerable<FoundInRaidItem>? FoundInRaidItems { get; set; }
public DamageHistory? DamageHistory { get; set; }
@@ -588,7 +591,7 @@ public record SessionCounters
[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }
public List<CounterKeyValue>? Items { get; set; }
public IEnumerable<CounterKeyValue>? Items { get; set; }
}
public record OverallCounters
@@ -604,7 +607,7 @@ public record CounterKeyValue
[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }
public List<string>? Key { get; set; }
public IEnumerable<string>? Key { get; set; }
public double? Value { get; set; }
}
@@ -12,7 +12,7 @@ public record AddItemsDirectRequest
/// Item and child mods to add to player inventory
/// </summary>
[JsonPropertyName("itemsWithModsToAdd")]
public List<List<Item>>? ItemsWithModsToAdd { get; set; }
public IEnumerable<List<Item>>? ItemsWithModsToAdd { get; set; }
[JsonPropertyName("foundInRaid")]
public bool? FoundInRaid { get; set; }
@@ -26,5 +26,5 @@ public record PresetBuildActionRequestData : IRequestData
public string? Root { get; set; }
[JsonPropertyName("Items")]
public List<Item>? Items { get; set; }
public IEnumerable<Item>? Items { get; set; }
}
@@ -48,7 +48,7 @@ public record ModToSpawnRequest
/// List with only weapon tpl in it, ready for mods to be added
/// </summary>
[JsonPropertyName("weapon")]
public List<Item>? Weapon { get; set; }
public IEnumerable<Item>? Weapon { get; set; }
/// <summary>
/// Ammo tpl to use if slot requires a cartridge to be added (e.g. mod_magazine)
@@ -326,13 +326,13 @@ public record TraderWhitelist
/// Quest types this trader can provide: Completion/Exploration/Elimination.
/// </summary>
[JsonPropertyName("questTypes")]
public required List<string> QuestTypes { get; set; }
public required HashSet<string> QuestTypes { get; set; }
/// <summary>
/// Item categories that the reward can be
/// </summary>
[JsonPropertyName("rewardBaseWhitelist")]
public required List<MongoId> RewardBaseWhitelist { get; set; }
public required IEnumerable<MongoId> RewardBaseWhitelist { get; set; }
/// <summary>
/// Can this reward be a weapon?
@@ -1364,15 +1364,13 @@ public class FenceService(
if (!randomUtil.GetChance100(plateExistsChance))
{
// Remove plate from armor
armorItemAndMods = armorItemAndMods
.Where(item =>
!string.Equals(
item.SlotId,
plateSlot.Name,
StringComparison.CurrentCultureIgnoreCase
)
armorItemAndMods = armorItemAndMods.Where(item =>
!string.Equals(
item.SlotId,
plateSlot.Name,
StringComparison.CurrentCultureIgnoreCase
)
.ToList();
);
continue;
}
@@ -68,7 +68,7 @@ public class ItemBaseClassService(
/// <param name="itemTpl"> ItemTpl item to check base classes of </param>
/// <param name="baseClasses"> BaseClass base class to check for </param>
/// <returns> true if item inherits from base class passed in </returns>
public bool ItemHasBaseClass(MongoId itemTpl, ICollection<MongoId> baseClasses)
public bool ItemHasBaseClass(MongoId itemTpl, IEnumerable<MongoId> baseClasses)
{
if (!_cacheGenerated)
{
@@ -960,12 +960,12 @@ public class LocationLifecycleService(
// Must occur AFTER killer messages have been sent
matchBotDetailsCacheService.ClearCache();
var roles = new List<string> { "pmcbear", "pmcusec" };
var roles = new HashSet<string> { "pmcbear", "pmcusec" };
var victims = postRaidProfile
.Stats.Eft.Victims.Where(victim => roles.Contains(victim.Role.ToLowerInvariant()))
.ToList();
if (victims?.Count > 0)
var victims = postRaidProfile.Stats.Eft.Victims.Where(victim =>
roles.Contains(victim.Role.ToLowerInvariant())
);
if (victims is not null && victims.Any())
// Player killed PMCs, send some mail responses to them
{
pmcChatResponseService.SendVictimResponse(sessionId, victims, serverPmcProfile);
@@ -1233,7 +1233,7 @@ public class LocationLifecycleService(
/// Reset the skill points earned in a raid to 0, ready for next raid
/// </summary>
/// <param name="commonSkills"> Profile common skills to update </param>
protected void ResetSkillPointsEarnedDuringRaid(List<CommonSkill> commonSkills)
protected void ResetSkillPointsEarnedDuringRaid(IEnumerable<CommonSkill> commonSkills)
{
foreach (var skill in commonSkills)
{
@@ -35,7 +35,11 @@ public class PmcChatResponseService(
/// <param name="sessionId"> Session ID </param>
/// <param name="pmcVictims"> List of bots killed by player </param>
/// <param name="pmcData"> Player profile </param>
public void SendVictimResponse(MongoId sessionId, List<Victim> pmcVictims, PmcData pmcData)
public void SendVictimResponse(
MongoId sessionId,
IEnumerable<Victim> pmcVictims,
PmcData pmcData
)
{
foreach (var victim in pmcVictims)
{