暂存
This commit is contained in:
@@ -32,12 +32,14 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
|
||||
[StaticConstructorOnStartup]
|
||||
public class CompMaintenancePod : ThingComp, IThingHolder
|
||||
public class CompMaintenancePod : ThingComp, IThingHolder, IStoreSettingsParent
|
||||
{
|
||||
// ===================== Fields =====================
|
||||
private ThingOwner innerContainer;
|
||||
private CompPowerTrader powerComp;
|
||||
private CompRefuelable refuelableComp;
|
||||
private StorageSettings allowedComponentSettings;
|
||||
public float storedComponents = 0f;
|
||||
public int capacity = 50; // Let's define a capacity
|
||||
private int ticksRemaining;
|
||||
private MaintenancePodState state = MaintenancePodState.Idle;
|
||||
|
||||
@@ -57,6 +59,8 @@ namespace WulaFallenEmpire
|
||||
return Props.baseComponentCost + (int)(hediff.Severity * Props.componentCostPerSeverity);
|
||||
}
|
||||
|
||||
public bool CanAcceptComponents(int count) => storedComponents + count <= capacity;
|
||||
|
||||
// ===================== Setup =====================
|
||||
public CompMaintenancePod()
|
||||
{
|
||||
@@ -64,19 +68,31 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
|
||||
|
||||
public override void Initialize(CompProperties props)
|
||||
{
|
||||
base.Initialize(props);
|
||||
allowedComponentSettings = new StorageSettings(this);
|
||||
if (Props.componentDef != null)
|
||||
{
|
||||
allowedComponentSettings.filter = new ThingFilter();
|
||||
allowedComponentSettings.filter.SetAllow(Props.componentDef, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override void PostSpawnSetup(bool respawningAfterLoad)
|
||||
{
|
||||
base.PostSpawnSetup(respawningAfterLoad);
|
||||
powerComp = parent.TryGetComp<CompPowerTrader>();
|
||||
refuelableComp = parent.TryGetComp<CompRefuelable>();
|
||||
}
|
||||
|
||||
public override void PostExposeData()
|
||||
{
|
||||
base.PostExposeData();
|
||||
Scribe_Values.Look(ref state, "state", MaintenancePodState.Idle);
|
||||
Scribe_Values.Look(ref storedComponents, "storedComponents", 0f);
|
||||
Scribe_Values.Look(ref ticksRemaining, "ticksRemaining", 0);
|
||||
Scribe_Deep.Look(ref innerContainer, "innerContainer", this);
|
||||
Scribe_Deep.Look(ref allowedComponentSettings, "allowedComponentSettings", this);
|
||||
}
|
||||
|
||||
// ===================== IThingHolder Implementation =====================
|
||||
@@ -90,6 +106,12 @@ namespace WulaFallenEmpire
|
||||
return innerContainer;
|
||||
}
|
||||
|
||||
// ===================== IStoreSettingsParent Implementation =====================
|
||||
public StorageSettings GetStoreSettings() => allowedComponentSettings;
|
||||
public StorageSettings GetParentStoreSettings() => null; // No parent settings
|
||||
public void Notify_SettingsChanged() { }
|
||||
public bool StorageTabVisible => false; // We show it in the inspect string
|
||||
|
||||
// ===================== Core Logic =====================
|
||||
public override void CompTick()
|
||||
{
|
||||
@@ -119,13 +141,13 @@ namespace WulaFallenEmpire
|
||||
public void StartCycle(Pawn pawn)
|
||||
{
|
||||
float required = RequiredComponents(pawn);
|
||||
if (refuelableComp == null || refuelableComp.Fuel < required)
|
||||
if (storedComponents < required)
|
||||
{
|
||||
Log.Error($"[WulaFallenEmpire] Tried to start maintenance cycle for {pawn.LabelShort} without enough components. This should have been checked earlier.");
|
||||
return;
|
||||
}
|
||||
|
||||
refuelableComp.ConsumeFuel(required);
|
||||
storedComponents -= required;
|
||||
state = MaintenancePodState.Running;
|
||||
ticksRemaining = Props.durationTicks;
|
||||
|
||||
@@ -174,6 +196,13 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
|
||||
|
||||
public void AddComponents(Thing components)
|
||||
{
|
||||
int count = components.stackCount;
|
||||
storedComponents += count;
|
||||
components.Destroy();
|
||||
}
|
||||
|
||||
// ===================== UI & Gizmos =====================
|
||||
public override string CompInspectStringExtra()
|
||||
{
|
||||
@@ -186,10 +215,7 @@ namespace WulaFallenEmpire
|
||||
sb.AppendLine("TimeLeft".Translate() + ": " + ticksRemaining.ToStringTicksToPeriod());
|
||||
}
|
||||
|
||||
if (refuelableComp != null)
|
||||
{
|
||||
sb.AppendLine("WULA_MaintenancePod_StoredComponents".Translate() + ": " + refuelableComp.Fuel.ToString("F0") + " / " + refuelableComp.Props.fuelCapacity.ToString("F0"));
|
||||
}
|
||||
sb.AppendLine("WULA_MaintenancePod_StoredComponents".Translate() + ": " + storedComponents.ToString("F0") + " / " + capacity.ToString("F0"));
|
||||
|
||||
if (!PowerOn)
|
||||
{
|
||||
@@ -217,7 +243,7 @@ namespace WulaFallenEmpire
|
||||
if (p.health.hediffSet.HasHediff(Props.hediffToRemove))
|
||||
{
|
||||
float required = RequiredComponents(p);
|
||||
if (refuelableComp != null && refuelableComp.Fuel >= required)
|
||||
if (storedComponents >= required)
|
||||
{
|
||||
options.Add(new FloatMenuOption(p.LabelShort, () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user