Improved types for item purchasing
Fixed purchased items lacking inserts
This commit is contained in:
@@ -23,7 +23,6 @@ public class BotCallbacks(
|
||||
/// <param name="info"></param>
|
||||
/// <param name="sessionID"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public string GetBotLimit(string url, EmptyRequestData info, string sessionID)
|
||||
{
|
||||
var splitUrl = url.Split('/');
|
||||
|
||||
@@ -442,7 +442,7 @@ public class HideoutController(
|
||||
|
||||
AddItemDirectRequest request = new AddItemDirectRequest
|
||||
{
|
||||
ItemWithModsToAdd = [itemToReturn],
|
||||
ItemWithModsToAdd = [itemToReturn.ConvertToItem()],
|
||||
FoundInRaid = itemToReturn.Upd?.SpawnedInSession,
|
||||
Callback = null,
|
||||
UseSortingTable = false,
|
||||
|
||||
@@ -127,7 +127,7 @@ public class PrestigeController(
|
||||
var item = prePrestigePmc.Inventory.Items.FirstOrDefault((item) => item.Id == transferRequest.Id);
|
||||
var addItemRequest = new AddItemDirectRequest
|
||||
{
|
||||
ItemWithModsToAdd = [item.ConvertToHideoutItem(item)],
|
||||
ItemWithModsToAdd = [item],
|
||||
FoundInRaid = item.Upd?.SpawnedInSession,
|
||||
UseSortingTable = false,
|
||||
Callback = null,
|
||||
|
||||
@@ -69,7 +69,7 @@ public class InventoryHelper(
|
||||
{
|
||||
var addItemRequest = new AddItemDirectRequest
|
||||
{
|
||||
ItemWithModsToAdd = itemToAdd.Select(x => x.ConvertToHideoutItem(x)).ToList(),
|
||||
ItemWithModsToAdd = itemToAdd,
|
||||
FoundInRaid = request.FoundInRaid,
|
||||
UseSortingTable = request.UseSortingTable,
|
||||
Callback = request.Callback
|
||||
@@ -95,14 +95,12 @@ public class InventoryHelper(
|
||||
ItemEventRouterResponse output)
|
||||
{
|
||||
var itemWithModsToAddClone = _cloner.Clone(request.ItemWithModsToAdd);
|
||||
var hideoutItemsConvertedToItems = itemWithModsToAddClone.Select(x => x.ConvertToItem(x)).ToList();
|
||||
var rootItemToAdd = hideoutItemsConvertedToItems.FirstOrDefault();
|
||||
|
||||
// Get stash layouts ready for use
|
||||
var stashFS2D = GetStashSlotMap(pmcData, sessionId);
|
||||
if (stashFS2D is null)
|
||||
{
|
||||
_logger.Error("Unable to get stash map for players: { sessionId} stash");
|
||||
_logger.Error($"Unable to get stash map for players: {sessionId} stash");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +111,7 @@ public class InventoryHelper(
|
||||
PlaceItemInInventory(
|
||||
stashFS2D,
|
||||
sortingTableFS2D,
|
||||
hideoutItemsConvertedToItems,
|
||||
itemWithModsToAddClone,
|
||||
pmcData.Inventory,
|
||||
request.UseSortingTable.GetValueOrDefault(false),
|
||||
output
|
||||
@@ -123,16 +121,16 @@ public class InventoryHelper(
|
||||
return;
|
||||
|
||||
// Apply/remove FiR to item + mods
|
||||
SetFindInRaidStatusForItem(hideoutItemsConvertedToItems, request.FoundInRaid.GetValueOrDefault(false));
|
||||
SetFindInRaidStatusForItem(itemWithModsToAddClone, request.FoundInRaid.GetValueOrDefault(false));
|
||||
|
||||
// Remove trader properties from root item
|
||||
RemoveTraderRagfairRelatedUpdProperties(rootItemToAdd.Upd);
|
||||
RemoveTraderRagfairRelatedUpdProperties(itemWithModsToAddClone[0].Upd);
|
||||
|
||||
// Run callback
|
||||
try
|
||||
{
|
||||
if (request.Callback is not null)
|
||||
request.Callback((int) (rootItemToAdd.Upd.StackObjectsCount ?? 0));
|
||||
request.Callback((int)(itemWithModsToAddClone[0].Upd.StackObjectsCount ?? 0));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -147,11 +145,11 @@ public class InventoryHelper(
|
||||
// Add item + mods to output and profile inventory
|
||||
|
||||
output.ProfileChanges[sessionId]
|
||||
.Items.NewItems.AddRange(hideoutItemsConvertedToItems);
|
||||
pmcData.Inventory.Items.AddRange(hideoutItemsConvertedToItems);
|
||||
.Items.NewItems.AddRange(itemWithModsToAddClone);
|
||||
pmcData.Inventory.Items.AddRange(itemWithModsToAddClone);
|
||||
|
||||
_logger.Debug(
|
||||
$"Added {rootItemToAdd.Upd?.StackObjectsCount ?? 1} item: {rootItemToAdd.Template} with: {hideoutItemsConvertedToItems.Count - 1} mods to inventory"
|
||||
$"Added {itemWithModsToAddClone[0].Upd?.StackObjectsCount ?? 1} item: {itemWithModsToAddClone[0].Template} with: {itemWithModsToAddClone.Count - 1} mods to inventory"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -920,7 +918,7 @@ public class InventoryHelper(
|
||||
/// <param name="pmcData">Player profile</param>
|
||||
/// <param name="sessionID">session id</param>
|
||||
/// <returns>2-dimensional array</returns>
|
||||
protected int[][] GetStashSlotMap(PmcData pmcData, string sessionID)
|
||||
protected int[][]? GetStashSlotMap(PmcData pmcData, string sessionID)
|
||||
{
|
||||
var playerStashSize = GetPlayerStashSize(sessionID);
|
||||
return GetContainerMap(
|
||||
|
||||
@@ -1851,12 +1851,9 @@ public class ItemHelper(
|
||||
// Optional: new id to use
|
||||
// Returns New root id
|
||||
|
||||
public string RemapRootItemId(List<Item> itemWithChildren, string newId = null)
|
||||
public string RemapRootItemId(List<Item> itemWithChildren, string? newId = null)
|
||||
{
|
||||
if (newId is null)
|
||||
{
|
||||
newId = _hashUtil.Generate();
|
||||
}
|
||||
newId ??= _hashUtil.Generate();
|
||||
|
||||
var rootItemExistingId = itemWithChildren[0].Id;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Transactions;
|
||||
using SptCommon.Annotations;
|
||||
using Core.Models.Eft.Common;
|
||||
@@ -72,7 +72,7 @@ public class TradeHelper(
|
||||
var assortHasBuyRestrictions = _itemHelper.HasBuyRestrictions(itemPurchased);
|
||||
if (assortHasBuyRestrictions)
|
||||
{
|
||||
this.checkPurchaseIsWithinTraderItemLimit(
|
||||
CheckPurchaseIsWithinTraderItemLimit(
|
||||
sessionID,
|
||||
pmcData,
|
||||
buyRequestData.TransactionId,
|
||||
@@ -82,7 +82,7 @@ public class TradeHelper(
|
||||
);
|
||||
|
||||
// Decrement trader item count
|
||||
PurchaseDetails itemPurchaseDetails = new PurchaseDetails()
|
||||
PurchaseDetails itemPurchaseDetails = new PurchaseDetails
|
||||
{
|
||||
Items =
|
||||
[
|
||||
@@ -144,7 +144,7 @@ public class TradeHelper(
|
||||
if (assortHasBuyRestrictions)
|
||||
{
|
||||
// Will throw error if check fails
|
||||
this.checkPurchaseIsWithinTraderItemLimit(
|
||||
CheckPurchaseIsWithinTraderItemLimit(
|
||||
sessionID,
|
||||
pmcData,
|
||||
buyRequestData.TransactionId,
|
||||
@@ -272,7 +272,7 @@ public class TradeHelper(
|
||||
if (sellRequest.TransactionId == Traders.RAGMAN)
|
||||
{
|
||||
// Edge case, `Circulate` quest needs to track when certain items are sold to him
|
||||
this.incrementCirculateSoldToTraderCounter(profileWithItemsToSell, profileToReceiveMoney, sellRequest);
|
||||
IncrementCirculateSoldToTraderCounter(profileWithItemsToSell, profileToReceiveMoney, sellRequest);
|
||||
}
|
||||
|
||||
var pattern = @"\s+";
|
||||
@@ -311,7 +311,7 @@ public class TradeHelper(
|
||||
_paymentService.GiveProfileMoney(profileToReceiveMoney, sellRequest.Price, sellRequest, output, sessionID);
|
||||
}
|
||||
|
||||
protected void incrementCirculateSoldToTraderCounter(
|
||||
protected void IncrementCirculateSoldToTraderCounter(
|
||||
PmcData profileWithItemsToSell,
|
||||
PmcData profileToReceiveMoney,
|
||||
ProcessSellTradeRequestData sellRequest
|
||||
@@ -396,7 +396,7 @@ public class TradeHelper(
|
||||
/// <param name="assortBeingPurchased">the item from trader being bought</param>
|
||||
/// <param name="assortId">Id of assort being purchased</param>
|
||||
/// <param name="count">How many of the item are being bought</param>
|
||||
protected void checkPurchaseIsWithinTraderItemLimit(
|
||||
protected void CheckPurchaseIsWithinTraderItemLimit(
|
||||
string sessionId,
|
||||
PmcData pmcData,
|
||||
string traderId,
|
||||
|
||||
@@ -52,13 +52,13 @@ public record HideoutItem
|
||||
[JsonPropertyName("count")]
|
||||
public double? Count { get; set; }
|
||||
|
||||
public Item ConvertToItem(HideoutItem hideoutItem)
|
||||
public Item ConvertToItem()
|
||||
{
|
||||
return new Item()
|
||||
return new Item
|
||||
{
|
||||
Id = hideoutItem.Id,
|
||||
Template = hideoutItem.Template,
|
||||
Upd = hideoutItem.Upd,
|
||||
Id = Id,
|
||||
Template = Template,
|
||||
Upd = Upd,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public record AddItemDirectRequest
|
||||
/// Item and child mods to add to player inventory
|
||||
/// </summary>
|
||||
[JsonPropertyName("itemWithModsToAdd")]
|
||||
public List<HideoutItem>? ItemWithModsToAdd { get; set; }
|
||||
public List<Item>? ItemWithModsToAdd { get; set; }
|
||||
|
||||
[JsonPropertyName("foundInRaid")]
|
||||
public bool? FoundInRaid { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user