AddItemToTrade
pavlicekdominik opened this issue · 0 comments
pavlicekdominik commented
Function: AddItemToTrade
Purpose
To add a specific item stack from a party's inventory to the current trading transaction. This includes handling both entirely new items and additions to items that are already part of the trade.
Inputs
- FInventoryItemSlotStack ItemStack: The stack indicating the item and its quantity we wish to add to the trade.
- TScriptInterface PartyInventory: The inventory of the party (either player or trader) from which the item is coming.
Outputs
- bool: Whether the item was successfully added to the trade or not.
Pseudocode
Function AddItemToTrade(FInventoryItemSlotStack ItemStack, TScriptInterface<IMounteaInventoryInterface> PartyInventory) -> bool:
// Check PartyInventory
If not PartyInventory.IsValid():
Return false
// Check if the item is valid
If not ItemStack.IsValid():
Return false
// Check whether we are updating Player's or Trader's Tradings
IsTrader = PartyInventory is equal OwningInventory
// Go Other party path (usually Player's)
If not IsTrader:
// If the item is tradeable and not already in the transient trade slots:
If not TradingTransaction.PlayerItemsForTrading.Contains(ItemStack.OwningSlot):
// Add the item slot to the transient trade slots in the Trading Transaction
NewSlot = new FInventoryItemSlot
NewSlot.Stacks.Add(ItemStack)
TradingTransaction.PlayerItemsForTrading.Add(NewSlot)
Return true
// If the item is tradeable and already in the transient trade slots:
Else:
// Add to the existing stack in the transient trade slots for the item
ExistingSlot = TradingTransaction.PlayerItemsForTrading.Find(ItemStack.OwningSlot)
ExistingSlot.Stacks.Add(ItemStack)
Return true
End If
// Go Trader's path
Else:
// If the item is tradeable and not already in the transient trade slots:
If not TradingTransaction.TraderItemsForTrading.Contains(ItemStack.OwningSlot):
// Add the item slot to the transient trade slots in the Trading Transaction
NewSlot = new FInventoryItemSlot
NewSlot.Stacks.Add(ItemStack)
TradingTransaction.TraderItemsForTrading.Add(NewSlot)
Return true
// If the item is tradeable and already in the transient trade slots:
Else:
// Add to the existing stack in the transient trade slots for the item
ExistingSlot = TradingTransaction.TraderItemsForTrading.Find(ItemStack.OwningSlot)
ExistingSlot.Stacks.Add(ItemStack)
Return true
End If
End If
Return false
End Function