New Inventory System + Overhaul
Removed universal GameContext references Refactored GameContext: It's now only responsible for item management. As such it's now called ItemManager GlobalData is gone, relevant settings are distributed amongst specialized settings classes Entities are no longer database entries, references to them are now direct - Zone is reponsible for storing them in ZonePacks Controller subtypes are now generic classes, class argument is task type Inventory is now a 2D grid instead of a list Entity temperature is now a 2D grid instead of a number Item sizes are now arbitrary shapes instead of a number Hardpoints are now arbitrary shapes instead Equipped items have their own temperatures Map view now displays sunlight colors Integrated Allegorithmic Substance Plugin Imported Djinni ship and assigned Substance materials Removed Node Editor framework (might come back later but needs work to integrate with behavior system)
This commit is contained in:
parent
53a91351b7
commit
f643f6cc8a
330 changed files with 24242 additions and 2830 deletions
|
|
@ -12,136 +12,121 @@ public class HaulingControllerData : ControllerData
|
|||
{
|
||||
[InspectableField, JsonProperty("targetDistance"), Key(6)]
|
||||
public float DockTime = 2;
|
||||
public override IBehavior CreateInstance(GameContext context, Entity entity, Gear item)
|
||||
public override IBehavior CreateInstance(ItemManager context, Entity entity, EquippedItem item)
|
||||
{
|
||||
return new HaulingController(context, this, entity, item);
|
||||
}
|
||||
}
|
||||
|
||||
public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
||||
public class HaulingController : ControllerBase<HaulingTask>, IBehavior, IPersistentBehavior
|
||||
{
|
||||
public override TaskType TaskType => TaskType.Haul;
|
||||
public BehaviorData Data => _data;
|
||||
|
||||
private HaulingControllerData _data;
|
||||
private GameContext _context;
|
||||
private Entity _entity;
|
||||
private Gear _item;
|
||||
|
||||
private ItemManager ItemManager { get; }
|
||||
private Entity Entity { get; }
|
||||
private EquippedItem Item { get; }
|
||||
|
||||
private bool _taskStarted;
|
||||
private int _itemsDelivered;
|
||||
private int _itemsCarried;
|
||||
private SimpleCommodity _simpleCommodityDelivery;
|
||||
private List<CraftedItemInstance> _craftedItemDelivery = new List<CraftedItemInstance>();
|
||||
|
||||
public HaulingController(GameContext context, HaulingControllerData data, Entity entity, Gear item) : base(context, data, entity)
|
||||
public HaulingController(ItemManager itemManager, HaulingControllerData data, Entity entity, EquippedItem item) : base(itemManager, data, entity)
|
||||
{
|
||||
_context = context;
|
||||
ItemManager = itemManager;
|
||||
_data = data;
|
||||
_entity = entity;
|
||||
_item = item;
|
||||
Entity = entity;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public new bool Update(float delta)
|
||||
{
|
||||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
if (haulingTask != null)
|
||||
if (Task != null)
|
||||
{
|
||||
if (!_taskStarted)
|
||||
{
|
||||
MoveTo(haulingTask.Zone, OnOriginZoneArrival);
|
||||
MoveTo(Task.Origin, true, OnPickup);
|
||||
//MoveTo(haulingTask.Zone, OnOriginZoneArrival);
|
||||
_taskStarted = true;
|
||||
}
|
||||
}
|
||||
return base.Update(delta);
|
||||
}
|
||||
|
||||
void OnOriginZoneArrival()
|
||||
{
|
||||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
|
||||
_entity.SetMessage("Entering pickup phase.");
|
||||
|
||||
MoveTo(_context.Cache.Get<Entity>(haulingTask.Origin), true, OnPickup);
|
||||
}
|
||||
// void OnOriginZoneArrival()
|
||||
// {
|
||||
// var haulingTask = _context.ItemData.Get<HaulingTask>(Task);
|
||||
//
|
||||
// _entity.SetMessage("Entering pickup phase.");
|
||||
//
|
||||
// MoveTo(_context.ItemData.Get<Entity>(haulingTask.Origin), true, OnPickup);
|
||||
// }
|
||||
|
||||
void OnPickup()
|
||||
{
|
||||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
var target = Zone.Entities[haulingTask.Origin] as OrbitalEntity;
|
||||
Entity.SetParent(Task.Origin);
|
||||
|
||||
_itemsCarried = Task.Origin.TryTransferItems(Entity, Task.ItemType, Task.Quantity - _itemsDelivered);
|
||||
|
||||
if (_itemsCarried == 0)
|
||||
{
|
||||
FinishTask();
|
||||
return;
|
||||
}
|
||||
|
||||
_entity.SetParent(target);
|
||||
var itemData = _context.Cache.Get<ItemData>(haulingTask.ItemType);
|
||||
int quantity = min((int) ((_entity.Capacity - _entity.OccupiedCapacity) / itemData.Size), haulingTask.Quantity - _itemsDelivered);
|
||||
if (itemData is SimpleCommodityData)
|
||||
{
|
||||
var itemMatch = target.Cargo
|
||||
.Select(id => _context.Cache.Get<SimpleCommodity>(id))
|
||||
.FirstOrDefault(ii => ii != null && ii.Data == haulingTask.ItemType);
|
||||
if(itemMatch==null)
|
||||
FinishTask();
|
||||
_simpleCommodityDelivery = _entity.AddCargo(target.RemoveCargo(itemMatch, quantity));
|
||||
}
|
||||
else if (itemData is CraftedItemData)
|
||||
{
|
||||
var itemMatches = target.Cargo
|
||||
.Select(id => _context.Cache.Get<CraftedItemInstance>(id))
|
||||
.Where(ii => ii != null && ii.Data == haulingTask.ItemType)
|
||||
.ToArray();
|
||||
if(!itemMatches.Any())
|
||||
FinishTask();
|
||||
foreach (var match in itemMatches)
|
||||
_craftedItemDelivery.Add(_entity.AddCargo(target.RemoveCargo(match)));
|
||||
}
|
||||
Wait(_data.DockTime, OnItemObtained);
|
||||
}
|
||||
|
||||
void OnItemObtained()
|
||||
{
|
||||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
_entity.SetMessage("Entering delivery phase.");
|
||||
Entity.SetMessage("Entering delivery phase.");
|
||||
|
||||
var target = _context.Cache.Get<Entity>(haulingTask.Target);
|
||||
|
||||
MoveTo(target.Zone.Data.ID, OnTargetZoneArrival);
|
||||
MoveTo(Task.Target, true, OnDelivery);
|
||||
//MoveTo(target.Zone.Data.ID, OnTargetZoneArrival);
|
||||
}
|
||||
|
||||
void OnTargetZoneArrival()
|
||||
{
|
||||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
|
||||
MoveTo(_context.Cache.Get<Entity>(haulingTask.Target), true, OnDelivery);
|
||||
}
|
||||
// void OnTargetZoneArrival()
|
||||
// {
|
||||
// var haulingTask = _context.ItemData.Get<HaulingTask>(Task);
|
||||
//
|
||||
// MoveTo(_context.ItemData.Get<Entity>(haulingTask.Target), true, OnDelivery);
|
||||
// }
|
||||
|
||||
void OnDelivery()
|
||||
{
|
||||
var haulingTask = _context.Cache.Get<HaulingTask>(Task);
|
||||
var target = Zone.Entities[haulingTask.Target] as OrbitalEntity;
|
||||
|
||||
_entity.SetParent(target);
|
||||
|
||||
var itemData = _context.Cache.Get<ItemData>(haulingTask.ItemType);
|
||||
if (itemData is SimpleCommodityData)
|
||||
{
|
||||
target.AddCargo(_entity.RemoveCargo(_simpleCommodityDelivery, _simpleCommodityDelivery.Quantity));
|
||||
_itemsDelivered += _simpleCommodityDelivery.Quantity;
|
||||
_simpleCommodityDelivery = null;
|
||||
}
|
||||
else if (itemData is CraftedItemData)
|
||||
{
|
||||
foreach (var item in _craftedItemDelivery)
|
||||
target.AddCargo(_entity.RemoveCargo(item));
|
||||
_itemsDelivered += _craftedItemDelivery.Count;
|
||||
_craftedItemDelivery.Clear();
|
||||
}
|
||||
|
||||
Entity.SetParent(Task.Target);
|
||||
|
||||
var itemsDelivered = Entity.TryTransferItems(Task.Target, Task.ItemType, _itemsCarried);
|
||||
_itemsCarried -= itemsDelivered;
|
||||
_itemsDelivered += itemsDelivered;
|
||||
|
||||
Wait(_data.DockTime, () =>
|
||||
{
|
||||
if(_itemsDelivered == haulingTask.Quantity)
|
||||
// We were unable to transfer all onboard items to target entity, cargo is probably full. Bring back the surplus and end the mission
|
||||
if(_itemsCarried > 0)
|
||||
MoveTo(Task.Origin, true, ReturnSurplusToOrigin);
|
||||
// We have delivered the target quantity of items, end the mission
|
||||
else if(_itemsDelivered >= Task.Quantity)
|
||||
FinishTask();
|
||||
// We aren't done yet. Resetting the task will make us go for another delivery run
|
||||
else
|
||||
_taskStarted = false;
|
||||
});
|
||||
}
|
||||
|
||||
void ReturnSurplusToOrigin()
|
||||
{
|
||||
Entity.SetParent(Task.Origin);
|
||||
|
||||
Entity.TryTransferItems(Task.Origin, Task.ItemType, _itemsCarried);
|
||||
|
||||
Wait(_data.DockTime, OnItemObtained);
|
||||
|
||||
FinishTask();
|
||||
}
|
||||
|
||||
public PersistentBehaviorData Store()
|
||||
{
|
||||
return new HaulingControllerPersistence
|
||||
|
|
@ -160,5 +145,5 @@ public class HaulingController : ControllerBase, IBehavior, IPersistentBehavior
|
|||
public class HaulingControllerPersistence : PersistentBehaviorData
|
||||
{
|
||||
[JsonProperty("task"), Key(0)]
|
||||
public Guid Task;
|
||||
public HaulingTask Task;
|
||||
}
|
||||
Loading…
Reference in a new issue