Inventory Events
Added an event system allowing the UI to subscribe to changes in entity cargo, hardpoints or on specific items Fixed bugs in colony tab caused by recent refactoring
This commit is contained in:
parent
d8d542f438
commit
39ce6809c0
11 changed files with 370 additions and 249 deletions
|
|
@ -47,14 +47,11 @@ public class Factory : IBehavior, IPersistentBehavior
|
|||
_blueprint = value;
|
||||
RetoolingTime = ToolingTime;
|
||||
_retooling = true;
|
||||
OnProductionUpdate?.Invoke();
|
||||
OnProductionUpdate = null;
|
||||
Item.Change();
|
||||
ItemName = Context.Cache.Get<BlueprintData>(value).Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public event Action OnProductionUpdate;
|
||||
|
||||
private FactoryData _data;
|
||||
|
||||
|
|
@ -87,7 +84,7 @@ public class Factory : IBehavior, IPersistentBehavior
|
|||
if (_retooling)
|
||||
{
|
||||
_retooling = false;
|
||||
OnProductionUpdate?.Invoke();
|
||||
Item.Change();
|
||||
}
|
||||
|
||||
if (ItemUnderConstruction != Guid.Empty)
|
||||
|
|
@ -106,6 +103,7 @@ public class Factory : IBehavior, IPersistentBehavior
|
|||
Entity.AddCargo(craftedItemInstance);
|
||||
Entity.IncompleteCargo.Remove(ItemUnderConstruction);
|
||||
ItemUnderConstruction = Guid.Empty;
|
||||
Item.Change();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -117,7 +115,8 @@ public class Factory : IBehavior, IPersistentBehavior
|
|||
(pow(Context.Random.NextFloat(), blueprint.RandomExponent) +
|
||||
pow(Context.Random.NextFloat(), blueprint.RandomExponent)) / 2, ItemName);
|
||||
|
||||
OnProductionUpdate?.Invoke();
|
||||
if(ItemUnderConstruction!=Guid.Empty)
|
||||
Item.Change();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,13 +99,14 @@ public class MiningController : ControllerBase, IBehavior, IPersistentBehavior,
|
|||
foreach (var item in _entity.Cargo
|
||||
.Select(id => _context.Cache.Get<ItemInstance>(id))
|
||||
.Where(item => item is SimpleCommodity)
|
||||
.Cast<SimpleCommodity>())
|
||||
.Cast<SimpleCommodity>()
|
||||
.ToArray())
|
||||
{
|
||||
int supportedQuantity = (int) ((homeEntity.Capacity - homeEntity.OccupiedCapacity) / item.ItemData.Size);
|
||||
var newItem = _entity.RemoveCargo(item, supportedQuantity);
|
||||
int quantity = min((int) ((homeEntity.Capacity - homeEntity.OccupiedCapacity) / item.ItemData.Size), item.Quantity);
|
||||
var newItem = _entity.RemoveCargo(item, quantity);
|
||||
homeEntity.AddCargo(newItem);
|
||||
|
||||
if (supportedQuantity < item.Quantity)
|
||||
if (quantity < item.Quantity)
|
||||
{
|
||||
homeEntity.SetMessage("Colony is out of cargo space. Closing Mining Task.");
|
||||
FinishTask();
|
||||
|
|
|
|||
Loading…
Reference in a new issue