This commit is contained in:
2025-10-14 18:47:56 +08:00
parent 4d4c0a1da7
commit 226ef22fb7
10 changed files with 38 additions and 225 deletions

Binary file not shown.

View File

@@ -59,6 +59,7 @@
<ThingDef>ARA_Cocoon_Cloth_1Stage</ThingDef>
</descriptionHyperlinks>
<thingClass>ArachnaeSwarm.ARA_PowerArmor</thingClass>
<tickerType>Normal</tickerType>
<modExtensions>
<li Class="ArachnaeSwarm.PowerArmorExtension">
<structurePointsMax>500</structurePointsMax>
@@ -119,7 +120,8 @@
<initialFuelPercent>1</initialFuelPercent>
<autoRefuelPercent>0.5</autoRefuelPercent>
<showFuelGizmo>true</showFuelGizmo>
<consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed>
<showAllowAutoRefuelToggle>false</showAllowAutoRefuelToggle>
<targetFuelLevelConfigurable>false</targetFuelLevelConfigurable>
</li>
</comps>
</ThingDef>

View File

@@ -1152,7 +1152,7 @@
<arcHeightFactor>1</arcHeightFactor>
<explosionRadius>3.5</explosionRadius>
<flyOverhead>true</flyOverhead>
<soundExplode>SpitterSpitLands</soundExplode>
<soundExplode>ThumpCannon_Impact</soundExplode>
<filth>Filth_SpentAcid</filth>
<filthCount>4</filthCount>
<explosionEffect>Shell_AcidSpitImpact</explosionEffect>

View File

@@ -397,10 +397,10 @@
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<statBases>
<AccuracyTouch>0.35</AccuracyTouch>
<AccuracyShort>0.5</AccuracyShort>
<AccuracyMedium>0.85</AccuracyMedium>
<AccuracyLong>1</AccuracyLong>
<AccuracyTouch>0.60</AccuracyTouch>
<AccuracyShort>0.70</AccuracyShort>
<AccuracyMedium>0.65</AccuracyMedium>
<AccuracyLong>0.55</AccuracyLong>
<RangedWeapon_Cooldown>2.2</RangedWeapon_Cooldown>
</statBases>
<verbs>

View File

@@ -1,133 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<!-- 动力甲 - 建筑形态 (基类) -->
<ThingDef Name="ARA_PowerArmorBuilding_Base" ParentName="BuildingBase" Abstract="True">
<thingClass>Building</thingClass>
<graphicData>
<graphicClass>Graphic_Multi</graphicClass>
<drawSize>(3,3)</drawSize>
</graphicData>
<altitudeLayer>Building</altitudeLayer>
<passability>PassThroughOnly</passability>
<pathCost>70</pathCost>
<castEdgeShadows>true</castEdgeShadows>
<fillPercent>0.5</fillPercent>
<canOverlapZones>false</canOverlapZones>
<size>(2,2)</size>
<designationCategory>Misc</designationCategory>
<rotatable>true</rotatable>
<selectable>true</selectable>
<tickerType>Never</tickerType>
<drawerType>MapMeshAndRealTime</drawerType>
<statBases>
<MaxHitPoints>250</MaxHitPoints>
<WorkToBuild>2000</WorkToBuild>
<Mass>50</Mass>
<Flammability>0.5</Flammability>
</statBases>
</ThingDef>
<!-- 动力甲 - 服装形态 (基类) -->
<ThingDef Name="ARA_PowerArmorApparel_Base" ParentName="ApparelBase" Abstract="True">
<thingClass>ArachnaeSwarm.ARA_PowerArmor</thingClass>
<graphicData>
<drawSize>2</drawSize>
</graphicData>
<statBases>
<MaxHitPoints>250</MaxHitPoints>
<Mass>30</Mass>
<Flammability>0</Flammability>
<ArmorRating_Sharp>0.85</ArmorRating_Sharp>
<ArmorRating_Blunt>0.80</ArmorRating_Blunt>
<ArmorRating_Heat>0.90</ArmorRating_Heat>
<Insulation_Cold>40</Insulation_Cold>
<Insulation_Heat>20</Insulation_Heat>
</statBases>
<equippedStatOffsets>
<MoveSpeed>-0.5</MoveSpeed>
</equippedStatOffsets>
<apparel>
<bodyPartGroups>
<li>Torso</li>
<li>Neck</li>
<li>Shoulders</li>
<li>Arms</li>
<li>Legs</li>
</bodyPartGroups>
<layers>
<li>Shell</li>
<li>Middle</li>
</layers>
<blocksVision>false</blocksVision>
</apparel>
</ThingDef>
<!-- 示例: 蜘蛛初号机 (具体实现) -->
<ThingDef ParentName="ARA_PowerArmorApparel_Base">
<defName>ARA_Apparel_SpiderOne</defName>
<label>Spider-I Power Armor</label>
<description>A prototype power armor with an arachnid design.</description>
<graphicData>
<texPath>Things/Pawn/Humanlike/Apparel/SpiderArmor/SpiderArmor</texPath>
</graphicData>
<modExtensions>
<li Class="ArachnaeSwarm.PowerArmorExtension">
<buildingDef>ARA_Building_SpiderOne</buildingDef>
<structurePointsMax>625</structurePointsMax>
<hediffOnEmptyFuel>ARA_PowerArmor_NoFuel</hediffOnEmptyFuel>
<fuelConsumptionRate>0.5</fuelConsumptionRate>
</li>
</modExtensions>
<comps>
<li Class="ArachnaeSwarm.CompProperties_RefuelableNutrition">
<fuelCapacity>10.0</fuelCapacity>
<fuelFilter>
<thingDefs>
<li>Meat_Human</li>
</thingDefs>
<categories>
<li>FoodMeals</li>
<li>FoodRaw</li>
</categories>
</fuelFilter>
<initialFuelPercent>1</initialFuelPercent>
<autoRefuelPercent>0.5</autoRefuelPercent>
<showFuelGizmo>true</showFuelGizmo>
<consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed>
</li>
</comps>
</ThingDef>
<ThingDef ParentName="ARA_PowerArmorBuilding_Base">
<defName>ARA_Building_SpiderOne</defName>
<label>Spider-I Power Armor (Station)</label>
<description>A stationary housing for the Spider-I Power Armor.</description>
<graphicData>
<texPath>Things/Building/PowerArmorStation</texPath>
</graphicData>
<comps>
<li Class="ArachnaeSwarm.CompProperties_PowerArmorStation">
<apparelDef>ARA_Apparel_SpiderOne</apparelDef>
</li>
<li Class="ArachnaeSwarm.CompProperties_RefuelableNutrition">
<fuelCapacity>10.0</fuelCapacity>
<fuelFilter>
<thingDefs>
<li>Meat_Human</li>
</thingDefs>
<categories>
<li>FoodMeals</li>
<li>FoodRaw</li>
</categories>
</fuelFilter>
<initialFuelPercent>1</initialFuelPercent>
<autoRefuelPercent>0.5</autoRefuelPercent>
<showFuelGizmo>true</showFuelGizmo>
</li>
</comps>
</ThingDef>
</Defs>

View File

@@ -271,7 +271,6 @@
<Compile Include="PowerArmor\CompPowerArmorStation.cs" />
<Compile Include="PowerArmor\Gizmo_StructurePanel.cs" />
<Compile Include="PowerArmor\JobDriver_EnterPowerArmor.cs" />
<Compile Include="PowerArmor\Gizmo_FuelPanel.cs" />
<Compile Include="PowerArmor\Harmony_ThingWithComps_GetFloatMenuOptions.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -56,28 +56,23 @@ namespace ArachnaeSwarm
#region Ticker
protected override void Tick()
{
base.Tick(); // Call Apparel's Tick
if (this.Wearer == null) return; // Only tick if worn
base.Tick();
if (this.Wearer == null) return;
var fuelComp = this.GetComp<CompRefuelableNutrition>();
if (fuelComp != null)
{
// Explicitly call the component's Tick method to ensure fuel consumption logic is executed.
// This is needed because Apparel's base Tick does not automatically call component Ticks.
// First, update consumption rate and hediffs
if (this.Wearer.IsHashIntervalTick(60)) // Check every second
// Set the consumption rate on every tick. This value is then used by CompRefuelableNutrition's CompTick.
// We use the value from our PowerArmorExtension, ensuring it's always active.
fuelComp.currentConsumptionRate = Ext?.fuelConsumptionRate ?? 0f;
// We must explicitly call the component's Tick, as Apparel's base Tick does not.
// This will trigger the consumption logic inside CompRefuelableNutrition.
fuelComp.CompTick();
// Handle hediff for empty fuel, checked frequently for responsiveness.
if (this.Wearer.IsHashIntervalTick(60))
{
if (this.Wearer.pather != null && this.Wearer.pather.MovingNow)
{
fuelComp.currentConsumptionRate = Ext?.fuelConsumptionRate ?? 0.5f;
}
else
{
fuelComp.currentConsumptionRate = 0f;
}
// Handle hediff for empty fuel
var hediffDef = Ext?.hediffOnEmptyFuel;
if (hediffDef != null)
{
@@ -98,10 +93,8 @@ namespace ArachnaeSwarm
}
}
}
// Then, explicitly call the component's Tick method to ensure fuel consumption logic is executed with the UPDATED rate.
fuelComp.CompTick();
}
} // Correctly close the Tick method
}
#endregion
#region Data
@@ -125,11 +118,15 @@ namespace ArachnaeSwarm
// Yield our custom structure points gizmo.
yield return new Gizmo_StructurePanel(this);
// Yield our custom fuel panel gizmo.
// Yield the default gizmos from the CompRefuelable component.
// This will provide the standard RimWorld fuel gizmo.
var fuelComp = this.GetComp<CompRefuelableNutrition>();
if (fuelComp != null)
{
yield return new Gizmo_FuelPanel(fuelComp);
foreach (var gizmo in fuelComp.CompGetGizmosExtra())
{
yield return gizmo;
}
}
}
#endregion
@@ -183,9 +180,12 @@ namespace ArachnaeSwarm
GenPlace.TryPlaceThing(building, pawn.Position, pawn.Map, ThingPlaceMode.Near);
Log.Message($"[PA_Debug] Notify_Unequipped: After spawning building (ID: {building.thingIDNumber}) - HitPoints: {building.HitPoints}, StackCount: {building.stackCount}");
// Destroy the apparel to prevent duplication
this.Destroy(DestroyMode.Vanish);
Log.Message($"[PA_Debug] Notify_Unequipped: Apparel {this.Label} (ID: {this.thingIDNumber}) destroyed.");
// To prevent the game from spawning a duplicate item, we must destroy the apparel.
// However, using DestroyMode.Vanish or Kill can cause "Spawning destroyed thing" errors
// if called directly within Notify_Unequipped.
// DestroyMode.QuestLogic is the correct way: it marks the thing as destroyed
// but defers the actual cleanup until the end of the current tick, avoiding race conditions.
this.Destroy(DestroyMode.QuestLogic);
}
#endregion

View File

@@ -1,55 +0,0 @@
using UnityEngine;
using Verse;
using RimWorld; // For SolidColorMaterials
namespace ArachnaeSwarm
{
[StaticConstructorOnStartup]
public class Gizmo_FuelPanel : Gizmo
{
private static readonly Texture2D FullBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.9f, 0.7f, 0.2f)); // Orange for fuel
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.1f, 0.1f, 0.1f));
private CompRefuelableNutrition fuelComp;
public Gizmo_FuelPanel(CompRefuelableNutrition fuelComp)
{
this.fuelComp = fuelComp;
this.Order = -90f; // Slightly higher order than structure panel
}
public override float GetWidth(float maxWidth)
{
return 140f;
}
public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth, GizmoRenderParms parms)
{
Rect overRect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), 75f);
Find.WindowStack.ImmediateWindow(984989, overRect, WindowLayer.GameUI, delegate
{
Rect rect = overRect.AtZero().ContractedBy(6f);
// Draw label
Rect labelRect = rect;
labelRect.height = overRect.height / 2f;
Text.Font = GameFont.Tiny;
Widgets.Label(labelRect, "Fuel".Translate()); // Use "Fuel" or custom text
// Draw bar
Rect barRect = rect;
barRect.yMin = overRect.height / 2f;
float fillPercent = fuelComp.FuelPercentOfMax;
Widgets.FillableBar(barRect, fillPercent, FullBarTex, EmptyBarTex, false);
// Draw text on bar
Text.Font = GameFont.Small;
Text.Anchor = TextAnchor.MiddleCenter;
Widgets.Label(barRect, $"{fuelComp.Fuel:F0} / {fuelComp.Props.fuelCapacity:F0}");
Text.Anchor = TextAnchor.UpperLeft;
});
return new GizmoResult(GizmoState.Clear);
}
}
}

View File

@@ -6,9 +6,8 @@ namespace ArachnaeSwarm
[StaticConstructorOnStartup]
public class Gizmo_StructurePanel : Gizmo
{
private static readonly Texture2D FullBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.2f, 0.8f, 0.2f));
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.1f, 0.1f, 0.1f));
private static readonly Texture2D UnderflowBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.9f, 0.1f, 0.1f));
private static readonly Texture2D FullBarTex = SolidColorMaterials.NewSolidColorTexture(new Color(0.2f, 0.2f, 0.24f));
private static readonly Texture2D EmptyBarTex = SolidColorMaterials.NewSolidColorTexture(Color.clear);
private IStructurePoints armor;
@@ -41,6 +40,7 @@ namespace ArachnaeSwarm
barRect.yMin = overRect.height / 2f;
float fillPercent = armor.StructurePointsPercent;
// Use the colors from the Exosuit example
Widgets.FillableBar(barRect, fillPercent, FullBarTex, EmptyBarTex, false);
// Draw text on bar

View File

@@ -50,8 +50,8 @@ namespace ArachnaeSwarm
apparelFuelComp.ReceiveFuel(buildingFuelComp.Fuel);
}
// Wear the apparel
actor.apparel.Wear(apparel, true, true);
// Wear the apparel, ensuring it's not locked.
actor.apparel.Wear(apparel, false, true);
// Despawn the building
building.DeSpawn();