Fix up types, added coversion methods to item and HideoutItem, null guards, add hideoutcontroller Update
This commit is contained in:
@@ -165,8 +165,7 @@ public class HideoutCallbacks(
|
||||
{
|
||||
if (timeSinceLastRun > _hideoutConfig.RunIntervalSeconds)
|
||||
{
|
||||
// TODO
|
||||
// _hideoutController.Update();
|
||||
_hideoutController.Update();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ public class HideoutController(
|
||||
}
|
||||
|
||||
// Upgrade includes a container improvement/addition
|
||||
if (hideoutStage?.Container is not null)
|
||||
if (!string.IsNullOrEmpty(hideoutStage?.Container))
|
||||
{
|
||||
AddContainerImprovementToProfile(
|
||||
output,
|
||||
@@ -365,7 +365,7 @@ public class HideoutController(
|
||||
|
||||
hideoutArea.Slots[hideoutSlotIndex].Items =
|
||||
[
|
||||
new HideoutItem()
|
||||
new HideoutItem
|
||||
{
|
||||
Id = item.inventoryItem.Id,
|
||||
Template = item.inventoryItem.Template,
|
||||
@@ -1286,4 +1286,20 @@ public class HideoutController(
|
||||
{
|
||||
return _databaseService.GetHideout().Qte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function called every `hideoutConfig.runIntervalSeconds` seconds as part of onUpdate event
|
||||
*/
|
||||
public void Update() {
|
||||
foreach (var sessionID in _saveServer.GetProfiles()) {
|
||||
if (sessionID.Value.CharacterData.PmcData.Hideout is not null &&
|
||||
_profileActivityService.ActiveWithinLastMinutes(
|
||||
sessionID.Key,
|
||||
_hideoutConfig.UpdateProfileHideoutWhenActiveWithinMinutes
|
||||
)
|
||||
) {
|
||||
_hideoutHelper.UpdatePlayerHideout(sessionID.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ public class PrestigeController(
|
||||
var item = prePrestigePmc.Inventory.Items.FirstOrDefault((item) => item.Id == transferRequest.Id);
|
||||
var addItemRequest = new AddItemDirectRequest
|
||||
{
|
||||
ItemWithModsToAdd = [item],
|
||||
ItemWithModsToAdd = [item.ConvertToHideoutItem(item)],
|
||||
FoundInRaid = item.Upd?.SpawnedInSession,
|
||||
UseSortingTable = false,
|
||||
Callback = null,
|
||||
|
||||
@@ -69,7 +69,7 @@ public class InventoryHelper(
|
||||
{
|
||||
var addItemRequest = new AddItemDirectRequest
|
||||
{
|
||||
ItemWithModsToAdd = itemToAdd,
|
||||
ItemWithModsToAdd = itemToAdd.Select(x => x.ConvertToHideoutItem(x)).ToList(),
|
||||
FoundInRaid = request.FoundInRaid,
|
||||
UseSortingTable = request.UseSortingTable,
|
||||
Callback = request.Callback
|
||||
@@ -95,7 +95,8 @@ public class InventoryHelper(
|
||||
ItemEventRouterResponse output)
|
||||
{
|
||||
var itemWithModsToAddClone = _cloner.Clone(request.ItemWithModsToAdd);
|
||||
var rootItemToAdd = itemWithModsToAddClone.FirstOrDefault();
|
||||
var hideoutItemsConvertedToItems = itemWithModsToAddClone.Select(x => x.ConvertToItem(x)).ToList();
|
||||
var rootItemToAdd = hideoutItemsConvertedToItems.FirstOrDefault();
|
||||
|
||||
// Get stash layouts ready for use
|
||||
var stashFS2D = GetStashSlotMap(pmcData, sessionId);
|
||||
@@ -112,7 +113,7 @@ public class InventoryHelper(
|
||||
PlaceItemInInventory(
|
||||
stashFS2D,
|
||||
sortingTableFS2D,
|
||||
itemWithModsToAddClone,
|
||||
hideoutItemsConvertedToItems,
|
||||
pmcData.Inventory,
|
||||
request.UseSortingTable.GetValueOrDefault(false),
|
||||
output
|
||||
@@ -122,7 +123,7 @@ public class InventoryHelper(
|
||||
return;
|
||||
|
||||
// Apply/remove FiR to item + mods
|
||||
SetFindInRaidStatusForItem(itemWithModsToAddClone, request.FoundInRaid.GetValueOrDefault(false));
|
||||
SetFindInRaidStatusForItem(hideoutItemsConvertedToItems, request.FoundInRaid.GetValueOrDefault(false));
|
||||
|
||||
// Remove trader properties from root item
|
||||
RemoveTraderRagfairRelatedUpdProperties(rootItemToAdd.Upd);
|
||||
@@ -144,12 +145,13 @@ public class InventoryHelper(
|
||||
}
|
||||
|
||||
// Add item + mods to output and profile inventory
|
||||
|
||||
output.ProfileChanges[sessionId]
|
||||
.Items.NewItems.AddRange(itemWithModsToAddClone.Select(x => x));
|
||||
pmcData.Inventory.Items.AddRange(itemWithModsToAddClone);
|
||||
.Items.NewItems.AddRange(hideoutItemsConvertedToItems);
|
||||
pmcData.Inventory.Items.AddRange(hideoutItemsConvertedToItems);
|
||||
|
||||
_logger.Debug(
|
||||
$"Added {rootItemToAdd.Upd?.StackObjectsCount ?? 1} item: {rootItemToAdd.Template} with: {itemWithModsToAddClone.Count - 1} mods to inventory"
|
||||
$"Added {rootItemToAdd.Upd?.StackObjectsCount ?? 1} item: {rootItemToAdd.Template} with: {hideoutItemsConvertedToItems.Count - 1} mods to inventory"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -665,12 +665,6 @@ public record HideoutSlot
|
||||
public List<HideoutItem>? Items { get; set; }
|
||||
}
|
||||
|
||||
public record HideoutItem : Item
|
||||
{
|
||||
[JsonPropertyName("count")]
|
||||
public double? Count { get; set; }
|
||||
}
|
||||
|
||||
public record LastCompleted
|
||||
{
|
||||
[JsonPropertyName("$oid")]
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace Core.Models.Eft.Common.Tables;
|
||||
public record Item
|
||||
{
|
||||
[JsonPropertyName("_id")]
|
||||
public required string Id { get; set; }
|
||||
public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("_tpl")]
|
||||
public string Template { get; set; }
|
||||
public string? Template { get; set; }
|
||||
|
||||
[JsonPropertyName("parentId")]
|
||||
public string? ParentId { get; set; }
|
||||
@@ -25,6 +25,42 @@ public record Item
|
||||
|
||||
[JsonPropertyName("upd")]
|
||||
public Upd? Upd { get; set; }
|
||||
|
||||
public HideoutItem ConvertToHideoutItem(Item item, double? count = null)
|
||||
{
|
||||
return new HideoutItem()
|
||||
{
|
||||
Id = item.Id,
|
||||
Template = item.Template,
|
||||
Upd = item.Upd,
|
||||
Count = count
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record HideoutItem
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string? Id { get; set; }
|
||||
|
||||
[JsonPropertyName("_tpl")]
|
||||
public string? Template { get; set; }
|
||||
|
||||
[JsonPropertyName("upd")]
|
||||
public Upd? Upd { get; set; }
|
||||
|
||||
[JsonPropertyName("count")]
|
||||
public double? Count { get; set; }
|
||||
|
||||
public Item ConvertToItem(HideoutItem hideoutItem)
|
||||
{
|
||||
return new Item()
|
||||
{
|
||||
Id = hideoutItem.Id,
|
||||
Template = hideoutItem.Template,
|
||||
Upd = hideoutItem.Upd,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public record ItemLocation
|
||||
|
||||
@@ -9,7 +9,7 @@ public record AddItemDirectRequest
|
||||
/// Item and child mods to add to player inventory
|
||||
/// </summary>
|
||||
[JsonPropertyName("itemWithModsToAdd")]
|
||||
public List<Item>? ItemWithModsToAdd { get; set; }
|
||||
public List<HideoutItem>? ItemWithModsToAdd { get; set; }
|
||||
|
||||
[JsonPropertyName("foundInRaid")]
|
||||
public bool? FoundInRaid { get; set; }
|
||||
|
||||
@@ -114,9 +114,9 @@ public class I18nService
|
||||
return rawLocalizedString;
|
||||
}
|
||||
|
||||
public string GetLocalised<T>(string key, T value) where T : IConvertible
|
||||
public string GetLocalised<T>(string key, T? value) where T : IConvertible
|
||||
{
|
||||
var rawLocalizedString = GetLocalised(key);
|
||||
return rawLocalizedString.Replace("%s", value.ToString());
|
||||
return rawLocalizedString.Replace("%s", value?.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ProfileActivityService(
|
||||
public bool ActiveWithinLastMinutes(string sessionId, int minutes)
|
||||
{
|
||||
var currentTimestamp = _timeUtil.GetTimeStamp();
|
||||
var storedActivityTimestamp = profileActivityTimestamps[sessionId];
|
||||
var storedActivityTimestamp = profileActivityTimestamps.GetValueOrDefault(sessionId);
|
||||
|
||||
if (storedActivityTimestamp != null)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user