Make trade delivery spatial and atomic
This commit is contained in:
parent
2e3e4ae55e
commit
5c7a56bd3b
6 changed files with 92 additions and 32 deletions
|
|
@ -1083,27 +1083,32 @@ namespace GameCult.Aetheria.State.Verse
|
|||
Math.Max(0, purchase.TargetCargoIndex),
|
||||
out var targetEntity,
|
||||
out var targetCargoIndex,
|
||||
out _) ||
|
||||
quantity > AetheriaRuntimeCargoCapacityQueries.UnitsThatFit(targetEntity, catalog, itemKey, targetCargoIndex))
|
||||
out _))
|
||||
{
|
||||
return context.Reject(AetheriaRuntimeDaemonRejectionReasons.TradeTargetNoFit);
|
||||
}
|
||||
|
||||
if (!TryRemoveCargoItemQuantity(
|
||||
if (!AetheriaRuntimeRefitTransactions.TryTransferCargo(
|
||||
stationEntity,
|
||||
stationCargoIndex,
|
||||
itemKey,
|
||||
purchase.SourceX,
|
||||
purchase.SourceY,
|
||||
targetEntity,
|
||||
targetCargoIndex,
|
||||
itemKey,
|
||||
quantity,
|
||||
out var purchasedSlot))
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
catalog,
|
||||
out var cargoReason))
|
||||
{
|
||||
return context.Reject(AetheriaRuntimeDaemonRejectionReasons.TradeStockUnavailable);
|
||||
return context.Reject(
|
||||
string.Equals(cargoReason, AetheriaRuntimeDaemonRejectionReasons.InvalidCargoSource, StringComparison.Ordinal)
|
||||
? AetheriaRuntimeDaemonRejectionReasons.TradeStockUnavailable
|
||||
: AetheriaRuntimeDaemonRejectionReasons.TradeTargetNoFit);
|
||||
}
|
||||
|
||||
purchasedSlot.X = 0;
|
||||
purchasedSlot.Y = 0;
|
||||
AddCargoItem(targetEntity, targetCargoIndex, purchasedSlot);
|
||||
run.Credits -= totalPrice;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,9 +173,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
if (remaining > 0)
|
||||
{
|
||||
moved.Item.Quantity = remaining;
|
||||
if (!TryPlaceCargoSlot(destinationItems, bay, item, moved, 0, 0, false, catalog))
|
||||
return Reject(AetheriaRuntimeDaemonRejectionReasons.CargoNoFit, out rejectionReason);
|
||||
var maxStack = item.Stackable ? Math.Max(1, item.MaxStack) : 1;
|
||||
while (remaining > 0)
|
||||
{
|
||||
var placed = CloneSlot(moved);
|
||||
placed.Item.Quantity = Math.Min(remaining, maxStack);
|
||||
if (!TryPlaceCargoSlot(destinationItems, bay, item, placed, 0, 0, false, catalog))
|
||||
return Reject(AetheriaRuntimeDaemonRejectionReasons.CargoNoFit, out rejectionReason);
|
||||
remaining -= placed.Item.Quantity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue