Skip to content

Commit

Permalink
Sync UIControlPanelObjectEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
starfi5h committed Sep 5, 2024
1 parent 701f4bb commit 99df583
Show file tree
Hide file tree
Showing 17 changed files with 1,247 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using UnityEngine;

namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPAdvancedMinerEntryUpdate
{
public LCPAdvancedMinerEntryUpdate() { }

public void Set(int index, StationComponent station, PlanetFactory factory)
{
Index = index;

if (!station.isCollector)
{
var powerSystem = factory.powerSystem;
var powerConsumerComponent = powerSystem.consumerPool[station.pcId];
var networkId = powerConsumerComponent.networkId;
var powerNetwork = powerSystem.netPool[networkId];
ConsumerRatio = (float)powerNetwork.consumerRatio;
RequirePower = (long)((powerConsumerComponent.requiredEnergy * 60L) * ConsumerRatio);
WorkEnergyPerTick = powerSystem.consumerPool[station.pcId].workEnergyPerTick;
PowerRound = station.energy / (float)station.energyMax;
}

var minerComponent = factory.factorySystem.minerPool[station.minerId];
if (minerComponent.id == station.minerId)
{
var veinPool = factory.veinPool;
var lowVeinCount = 0;
var emptyVeinCount = 0;
if (minerComponent.veinCount > 0)
{
for (var i = 0; i < minerComponent.veinCount; i++)
{
var id = minerComponent.veins[i];
if (id > 0 && veinPool[id].id == id)
{
var amount = veinPool[id].amount;
if (amount < 1000)
{
if (amount > 0)
{
lowVeinCount++;
}
else
{
emptyVeinCount++;
}
}
}
}
}
VeinCount = (short)minerComponent.veinCount;
LowVeinCount = (short)lowVeinCount;
EmptyVeinCount = (short)emptyVeinCount;

var veinId = ((minerComponent.veinCount == 0) ? 0 : minerComponent.veins[minerComponent.currentVeinIndex]);
VeinProtoId = (int)veinPool[veinId].type;
var veinProto = LDB.veins.Select((int)veinPool[veinId].type);
if (veinProto != null)
{
minerComponent.GetTotalVeinAmount(veinPool);
TotalVeinAmount = minerComponent.totalVeinAmount;
}
}

ItemId = 0;
if (station.storage == null || station.storage.Length == 0) return;
ref var store = ref station.storage[0];
ItemId = store.itemId;
ItemCount = store.count;
LocalOrder = (short)Mathf.Clamp(store.localOrder, -20000, 20000);
RemoteOrder = (short)Mathf.Clamp(store.remoteOrder, -20000, 20000);
StoreMax = store.max;
LocalLogic = (byte)store.localLogic;
RemoteLogic = (byte)store.remoteLogic;
}

public static readonly LCPAdvancedMinerEntryUpdate Instance = new();

public int Index { get; set; }
public float ConsumerRatio { get; set; }
public long RequirePower { get; set; }
public long WorkEnergyPerTick { get; set; }
public float PowerRound { get; set; }

public int VeinProtoId { get; set; }
public long TotalVeinAmount { get; set; }
public short VeinCount { get; set; }
public short LowVeinCount { get; set; }
public short EmptyVeinCount { get; set; }

public int ItemId { get; set; }
public int ItemCount { get; set; }
public short LocalOrder { get; set; }
public short RemoteOrder { get; set; }
public int StoreMax { get; set; }
public byte LocalLogic { get; set; }
public byte RemoteLogic { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPDispenserEntryUpdate
{
public LCPDispenserEntryUpdate() { }

public void Set(int index, DispenserComponent dispenser, PlanetFactory factory)
{
Index = index;

var powerSystem = factory.powerSystem;
var powerConsumerComponent = powerSystem.consumerPool[dispenser.pcId];
var networkId = powerConsumerComponent.networkId;
var powerNetwork = powerSystem.netPool[networkId];
ConsumerRatio = (float)powerNetwork.consumerRatio;
RequirePower = (long)((powerConsumerComponent.requiredEnergy * 60L) * ConsumerRatio);
WorkEnergyPerTick = powerSystem.consumerPool[dispenser.pcId].workEnergyPerTick;
PowerRound = dispenser.energy / (float)dispenser.energyMax;

Filter = dispenser.filter;
PlayerMode = (short)dispenser.playerMode;
StorageMode = (short)dispenser.storageMode;
IdleCourierCount = dispenser.idleCourierCount;
WorkCourierCount = dispenser.workCourierCount;

var status = 0;
if (dispenser.playerMode == EPlayerDeliveryMode.None && dispenser.storageMode == EStorageDeliveryMode.None)
{
status = 1;
}
else if (dispenser.filter == 0)
{
status = 2;
}
else if (dispenser.idleCourierCount + dispenser.workCourierCount == 0)
{
status = 3;
}
else if (dispenser.holdupItemCount > 0)
{
status = 5;
}
else if (ConsumerRatio < 0.0001f && dispenser.energy < 100000L)
{
status = 4;
}
WarningFlag = status > 0;

var count = 0;
var inc = 0;
var loop = 0;
if (dispenser.storage != null && dispenser.filter > 0)
{
var storageComponent = dispenser.storage;
do
{
count += storageComponent.GetItemCount(dispenser.filter, out var num);
inc += num;
storageComponent = storageComponent.previousStorage;
if (loop++ > 20) break;
}
while (storageComponent != null);
}
ItemCount = count;
}

public static readonly LCPDispenserEntryUpdate Instance = new();

public int Index { get; set; }
public float ConsumerRatio { get; set; }
public long RequirePower { get; set; }
public long WorkEnergyPerTick { get; set; }
public float PowerRound { get; set; }

public int Filter { get; set; }
public short PlayerMode { get; set; }
public short StorageMode { get; set; }
public int IdleCourierCount { get; set; }
public int WorkCourierCount { get; set; }
public bool WarningFlag { get; set; }
public int ItemCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPObjectEntryEntityInfo
{
public LCPObjectEntryEntityInfo() { }

public void Set(int index, int protoId, int id, string name)
{
Index = index;
ProtoId = protoId;
Id = id;
Name = name;
}

public static readonly LCPObjectEntryEntityInfo Instance = new();

public int Index { get; set; }
public int ProtoId { get; set; }
public int Id { get; set; }
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPObjectEntryRequest
{
public LCPObjectEntryRequest() { }

public void Set(UIControlPanelObjectEntry controlPanelFilter, bool isInit = false)
{
// isInit: Request for entityData.protoId, name
Index = controlPanelFilter.index;
EntryType = (short)controlPanelFilter.entryType;
AstroId = controlPanelFilter.target.astroId;
// Use sign of ObjId to note the state of request
ObjId = isInit ? -controlPanelFilter.target.objId : controlPanelFilter.target.objId;
}

public static readonly LCPObjectEntryRequest Instance = new();

public int Index { get; set; }
public short EntryType { get; set; }
public int AstroId { get; set; }
public int ObjId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using UnityEngine;

namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPStationEntryUpdate
{
public LCPStationEntryUpdate() { }

public void Set(int index, StationComponent station, PlanetFactory factory)
{
Index = index;

if (!station.isCollector)
{
var powerSystem = factory.powerSystem;
var powerConsumerComponent = powerSystem.consumerPool[station.pcId];
var networkId = powerConsumerComponent.networkId;
var powerNetwork = powerSystem.netPool[networkId];
ConsumerRatio = (float)powerNetwork.consumerRatio;
RequirePower = (long)((powerConsumerComponent.requiredEnergy * 60L) * ConsumerRatio);
WorkEnergyPerTick = powerSystem.consumerPool[station.pcId].workEnergyPerTick;
PowerRound = station.energy / (float)station.energyMax;
}
else
{
ConsumerRatio = 1.0f;
RequirePower = 0;
WorkEnergyPerTick = 0;
PowerRound = 0;
}

IdleDroneCount = (short)station.idleDroneCount;
WorkDroneCount = (short)station.workDroneCount;
IdleShipCount = (short)station.idleShipCount;
WorkShipCount = (short)station.workShipCount;
WarperCount = (short)station.warperCount;

if (ItemId == null)
{
ItemId = new int[5];
ItemCount = new int[5];
LocalOrder = new short[5];
RemoteOrder = new short[5];
StoreMax = new int[5];
LocalLogic = new byte[5];
RemoteLogic = new byte[5];
}
var i = 0;
if (station.storage != null)
{
var storeLength = station.storage.Length;
if (storeLength > 5) storeLength = 5;
for (; i < storeLength; i++)
{
ref var store = ref station.storage[i];
ItemId[i] = store.itemId;
ItemCount[i] = store.count;
LocalOrder[i] = (short)Mathf.Clamp(store.localOrder, -20000, 20000);
RemoteOrder[i] = (short)Mathf.Clamp(store.remoteOrder, -20000, 20000);
StoreMax[i] = store.max;
LocalLogic[i] = (byte)store.localLogic;
RemoteLogic[i] = (byte)store.remoteLogic;
}
}
for (; i < 5; i++)
{
ItemId[i] = 0;
ItemCount[i] = 0;
}
}

public static readonly LCPStationEntryUpdate Instance = new();

public int Index { get; set; }
public float ConsumerRatio { get; set; }
public long RequirePower { get; set; }
public long WorkEnergyPerTick { get; set; }
public float PowerRound { get; set; }

public short IdleDroneCount { get; set; }
public short WorkDroneCount { get; set; }
public short IdleShipCount { get; set; }
public short WorkShipCount { get; set; }
public short WarperCount { get; set; }

public int[] ItemId { get; set; }
public int[] ItemCount { get; set; }
public short[] LocalOrder { get; set; }
public short[] RemoteOrder { get; set; }
public int[] StoreMax { get; set; }
public byte[] LocalLogic { get; set; }
public byte[] RemoteLogic { get; set; }
}
Loading

0 comments on commit 99df583

Please sign in to comment.