fix ShopStorage.Sell

This commit is contained in:
ShabOl 2024-04-17 01:07:56 +04:00
parent b81bb26b41
commit 81b4335193

View File

@ -87,15 +87,16 @@ namespace AutoWorkshopFileImplement.Implements
if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue)
return false;
int RemainingSpace = _source.Shops
int TotalRepairsNum = _source.Shops
.Select(x => x.Repairs.ContainsKey(Model.RepairId.Value) ? x.Repairs[Model.RepairId.Value] : 0)
.Sum();
if (RemainingSpace < Model.Count)
if (TotalRepairsNum < Model.Count)
return false;
var ShopsWithDesiredRepair = _source.Shops
.Where(x => x.Repairs.ContainsKey(Model.RepairId.Value))
.OrderByDescending(x => x.Repairs[Model.RepairId.Value]).ToList();
.OrderByDescending(x => x.Repairs[Model.RepairId.Value])
.ToList();
foreach (var Shop in ShopsWithDesiredRepair)
{
@ -128,7 +129,13 @@ namespace AutoWorkshopFileImplement.Implements
public bool RestockingShops(SupplyBindingModel Model)
{
if (Model == null || _source.Shops.Select(x => x.RepairsMaxCount - x.ShopRepairs.Select(y => y.Value.Item2).Sum()).Sum() < Model.Count)
int TotalFreeSpaceNum = _source.Shops
.Select(x => x.RepairsMaxCount - x.ShopRepairs
.Select(y => y.Value.Item2)
.Sum())
.Sum();
if (TotalFreeSpaceNum < Model.Count)
return false;
foreach (Shop Shop in _source.Shops)
@ -137,7 +144,7 @@ namespace AutoWorkshopFileImplement.Implements
if (FreeSpaceNum <= 0)
continue;
FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count);
Model.Count -= FreeSpaceNum;