Fixing drop/pickup stacking
All checks were successful
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Character API / deploy (push) Successful in 47s
Deploy Promiscuity Inventory API / deploy (push) Successful in 59s
Deploy Promiscuity Locations API / deploy (push) Successful in 46s
k8s smoke test / test (push) Successful in 9s
All checks were successful
Deploy Promiscuity Auth API / deploy (push) Successful in 47s
Deploy Promiscuity Character API / deploy (push) Successful in 47s
Deploy Promiscuity Inventory API / deploy (push) Successful in 59s
Deploy Promiscuity Locations API / deploy (push) Successful in 46s
k8s smoke test / test (push) Successful in 9s
This commit is contained in:
parent
525f9442c3
commit
c5e692c051
@ -678,8 +678,7 @@ func _on_inventory_pickup_pressed() -> void:
|
|||||||
_inventory_status_label.text = "Current location is missing an id."
|
_inventory_status_label.text = "Current location is missing an id."
|
||||||
return
|
return
|
||||||
var quantity := int(_quantity_spin_box.value)
|
var quantity := int(_quantity_spin_box.value)
|
||||||
var to_slot := int(_target_slot_spin_box.value)
|
_transfer_item_async(_selected_ground_item_id, "location", location_id, "character", _character_id, null, quantity, "Picked up item.")
|
||||||
_transfer_item_async(_selected_ground_item_id, "location", location_id, "character", _character_id, to_slot, quantity, "Picked up item.")
|
|
||||||
|
|
||||||
|
|
||||||
func _on_inventory_refresh_pressed() -> void:
|
func _on_inventory_refresh_pressed() -> void:
|
||||||
|
|||||||
@ -328,13 +328,28 @@ public class InventoryStore
|
|||||||
if (definition is null)
|
if (definition is null)
|
||||||
return new InventoryMutationResult { Status = InventoryMutationStatus.Invalid };
|
return new InventoryMutationResult { Status = InventoryMutationStatus.Invalid };
|
||||||
|
|
||||||
var toSlot = req.ToSlot ?? await FindFirstOpenSlotAsync(toOwner.OwnerType, toOwner.OwnerId);
|
InventoryItem? target = null;
|
||||||
if (toSlot is null)
|
int? toSlot = req.ToSlot;
|
||||||
return new InventoryMutationResult { Status = InventoryMutationStatus.Conflict };
|
if (toSlot is not null)
|
||||||
|
{
|
||||||
|
target = await FindItemBySlotAsync(toOwner.OwnerType, toOwner.OwnerId, toSlot.Value);
|
||||||
|
if (target is not null && !CanMerge(item, target, definition))
|
||||||
|
return new InventoryMutationResult { Status = InventoryMutationStatus.Conflict };
|
||||||
|
}
|
||||||
|
else if (definition.Stackable)
|
||||||
|
{
|
||||||
|
target = await FindMergeTargetAsync(toOwner.OwnerType, toOwner.OwnerId, item.ItemKey, definition.MaxStackSize);
|
||||||
|
if (target is not null)
|
||||||
|
toSlot = target.Slot;
|
||||||
|
}
|
||||||
|
|
||||||
var target = await FindItemBySlotAsync(toOwner.OwnerType, toOwner.OwnerId, toSlot.Value);
|
if (toSlot is null)
|
||||||
if (target is not null && !CanMerge(item, target, definition))
|
{
|
||||||
return new InventoryMutationResult { Status = InventoryMutationStatus.Conflict };
|
toSlot = await FindFirstOpenSlotAsync(toOwner.OwnerType, toOwner.OwnerId);
|
||||||
|
if (toSlot is null)
|
||||||
|
return new InventoryMutationResult { Status = InventoryMutationStatus.Conflict };
|
||||||
|
target = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (target is not null)
|
if (target is not null)
|
||||||
{
|
{
|
||||||
@ -521,6 +536,20 @@ public class InventoryStore
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<InventoryItem?> FindMergeTargetAsync(string ownerType, string ownerId, string itemKey, int maxStackSize)
|
||||||
|
{
|
||||||
|
var normalizedItemKey = NormalizeItemKey(itemKey);
|
||||||
|
return await _items.Find(i =>
|
||||||
|
i.OwnerType == ownerType &&
|
||||||
|
i.OwnerId == ownerId &&
|
||||||
|
i.ItemKey == normalizedItemKey &&
|
||||||
|
i.EquippedSlot == null &&
|
||||||
|
i.Slot != null &&
|
||||||
|
i.Quantity < maxStackSize)
|
||||||
|
.SortBy(i => i.Slot)
|
||||||
|
.FirstOrDefaultAsync();
|
||||||
|
}
|
||||||
|
|
||||||
private Task<InventoryItem?> FindItemBySlotAsync(string ownerType, string ownerId, int slot, IClientSessionHandle? session = null)
|
private Task<InventoryItem?> FindItemBySlotAsync(string ownerType, string ownerId, int slot, IClientSessionHandle? session = null)
|
||||||
=> session is null
|
=> session is null
|
||||||
? FindItemBySlotNoSessionAsync(ownerType, ownerId, slot)
|
? FindItemBySlotNoSessionAsync(ownerType, ownerId, slot)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user