diff --git a/1.6/1.6/Assemblies/ArachnaeSwarm.dll b/1.6/1.6/Assemblies/ArachnaeSwarm.dll index 5005dc5..32b1e44 100644 Binary files a/1.6/1.6/Assemblies/ArachnaeSwarm.dll and b/1.6/1.6/Assemblies/ArachnaeSwarm.dll differ diff --git a/1.6/1.6/Defs/JobDefs/ARA_Jobs.xml b/1.6/1.6/Defs/JobDefs/ARA_Jobs.xml index 2083d1a..76740e7 100644 --- a/1.6/1.6/Defs/JobDefs/ARA_Jobs.xml +++ b/1.6/1.6/Defs/JobDefs/ARA_Jobs.xml @@ -12,4 +12,11 @@ 将 TargetA 带到 TargetB. false + + + ARA_EnterPowerArmor + ArachnaeSwarm.JobDriver_EnterPowerArmor + entering TargetA. + true + \ No newline at end of file diff --git a/1.6/1.6/Defs/Thing_Misc/ARA_PowerArmor_Defs.xml b/1.6/1.6/Defs/Thing_Misc/ARA_PowerArmor_Defs.xml new file mode 100644 index 0000000..8bab52c --- /dev/null +++ b/1.6/1.6/Defs/Thing_Misc/ARA_PowerArmor_Defs.xml @@ -0,0 +1,103 @@ + + + + + + Building + + Graphic_Multi + (3,3) + + Building + PassThroughOnly + 70 + true + 0.5 + false + (2,2) + Misc + true + true + Never + MapMeshAndRealTime + + 500 + 2000 + 50 + 0.5 + + + + + ARA_SpiderOne_PowerArmor + + 阿拉克涅动力装甲 + + ARA_Cocoon_Cloth_1Stage + + ArachnaeSwarm.ARA_PowerArmor + +
  • + 500 + ARA_Building_SpiderOne +
  • +
    + + + ARA_Technology_6DIL + UnfinishedArmor + + + 25 + + + ArachnaeSwarm/Apparel/ARA_Bunny_Girl_Uniform + + + +
  • Torso
  • +
  • Shoulders
  • +
  • Arms
  • +
  • Legs
  • +
    + + +
  • Middle
  • +
    + ArachnaeSwarm/Apparel/ARA_Bunny_Girl_Uniform +
    + + 120 + 2.5 + + + + 0 + +
  • + ARA_TerrainMoveSpeedHediff +
  • +
  • + +
  • ARA_Cocoon_Cloth_1Stage
  • +
  • ARA_BioforgeIncubator_Thing
  • + + +
    +
    + + + ARA_Building_SpiderOne + + 阿拉克涅动力装甲 + + ArachnaeSwarm/Apparel/ARA_Bunny_Girl_Uniform + + +
  • + ARA_SpiderOne_PowerArmor +
  • +
    +
    + +
    \ No newline at end of file diff --git a/1.6/Defs/Thing_Misc/ARA_PowerArmor_Defs.xml b/1.6/Defs/Thing_Misc/ARA_PowerArmor_Defs.xml new file mode 100644 index 0000000..dae3ae4 --- /dev/null +++ b/1.6/Defs/Thing_Misc/ARA_PowerArmor_Defs.xml @@ -0,0 +1,98 @@ + + + + + + Building + + Graphic_Multi + (3,3) + + Building + PassThroughOnly + 70 + true + 0.5 + false + (2,2) + Misc + true + true + Never + MapMeshAndRealTime + + 250 + 2000 + 50 + 0.5 + + + + + + ArachnaeSwarm.ARA_PowerArmor + + 2 + + + 250 + 30 + 0 + 0.85 + 0.80 + 0.90 + 40 + 20 + + + -0.5 + + + +
  • Torso
  • +
  • Neck
  • +
  • Shoulders
  • +
  • Arms
  • +
  • Legs
  • +
    + +
  • Shell
  • +
  • Middle
  • +
    + false +
    +
    + + + + + + ARA_Apparel_SpiderOne + + A prototype power armor with an arachnid design. + + Things/Pawn/Humanlike/Apparel/SpiderArmor/SpiderArmor + + +
  • + ARA_Building_SpiderOne + 625 +
  • +
    +
    + + + ARA_Building_SpiderOne + + A stationary housing for the Spider-I Power Armor. + + Things/Building/PowerArmorStation + + +
  • + ARA_Apparel_SpiderOne +
  • +
    +
    + +
    \ No newline at end of file diff --git a/Languages/ChineseSimplified/Keyed/PowerArmor_Keys.xml b/Languages/ChineseSimplified/Keyed/PowerArmor_Keys.xml new file mode 100644 index 0000000..73a35af --- /dev/null +++ b/Languages/ChineseSimplified/Keyed/PowerArmor_Keys.xml @@ -0,0 +1,13 @@ + + + + + 进入动力甲 + + + 结构点 + + + {0} 已被摧毁!驾驶员 {1} 被暴露在外。 + + \ No newline at end of file diff --git a/Source/ArachnaeSwarm/ArachnaeSwarm.csproj b/Source/ArachnaeSwarm/ArachnaeSwarm.csproj index 2702294..8f2de33 100644 --- a/Source/ArachnaeSwarm/ArachnaeSwarm.csproj +++ b/Source/ArachnaeSwarm/ArachnaeSwarm.csproj @@ -267,6 +267,10 @@ + + + + diff --git a/Source/ArachnaeSwarm/PowerArmor/ARA_PowerArmor.cs b/Source/ArachnaeSwarm/PowerArmor/ARA_PowerArmor.cs new file mode 100644 index 0000000..cf72454 --- /dev/null +++ b/Source/ArachnaeSwarm/PowerArmor/ARA_PowerArmor.cs @@ -0,0 +1,153 @@ +using RimWorld; +using UnityEngine; +using Verse; +using System.Collections.Generic; + +namespace ArachnaeSwarm +{ + public interface IStructurePoints + { + float StructurePoints { get; } + float StructurePointsMax { get; } + float StructurePointsPercent { get; } + string Label { get; } + } + + public class PowerArmorExtension : DefModExtension + { + public ThingDef buildingDef; + public float structurePointsMax = 500f; + } + + [StaticConstructorOnStartup] + public class ARA_PowerArmor : Apparel, IStructurePoints + { + #region Properties + private PowerArmorExtension ext; + public PowerArmorExtension Ext => ext ??= def.GetModExtension(); + public override string Label => base.Label; + + private float structurePoints = -1f; + public float StructurePointsMax => Ext?.structurePointsMax ?? 500f; + + public float StructurePoints + { + get + { + if (structurePoints < 0) + { + structurePoints = StructurePointsMax; + } + return structurePoints; + } + set + { + structurePoints = Mathf.Clamp(value, 0, StructurePointsMax); + } + } + + public float StructurePointsPercent => StructurePoints / StructurePointsMax; + + public Building sourceBuilding; + #endregion + + #region Data + public override void ExposeData() + { + base.ExposeData(); + Scribe_Values.Look(ref structurePoints, "structurePoints", -1f); + Scribe_References.Look(ref sourceBuilding, "sourceBuilding"); + } + #endregion + + #region Gizmo + public override IEnumerable GetWornGizmos() + { + foreach (var gizmo in base.GetWornGizmos()) + { + yield return gizmo; + } + yield return new Gizmo_StructurePanel(this); + } + #endregion + + #region State-Switching + public override void Notify_Unequipped(Pawn pawn) + { + base.Notify_Unequipped(pawn); + + ThingDef buildingToSpawn = sourceBuilding?.def ?? Ext?.buildingDef; + + if (buildingToSpawn == null) + { + Log.Error($"[ArachnaeSwarm] Power Armor {this.def.defName} unequipped, but has no buildingDef defined in its PowerArmorExtension or a source building."); + return; + } + + Building building = (Building)ThingMaker.MakeThing(buildingToSpawn); + building.HitPoints = Mathf.RoundToInt(this.StructurePoints); + GenPlace.TryPlaceThing(building, pawn.Position, pawn.Map, ThingPlaceMode.Near); + } + #endregion + + #region Damage Handling - THE FINAL, CORRECT IMPLEMENTATION + public override bool CheckPreAbsorbDamage(DamageInfo dinfo) + { + if (this.Wearer == null || !dinfo.Def.harmsHealth || dinfo.Amount <= 0.001f) + { + return false; + } + + float finalDamage = GetPostArmorDamage(ref dinfo); + + if (finalDamage > 0) + { + this.StructurePoints -= finalDamage; + EffecterDefOf.DamageDiminished_Metal.SpawnAttached(this.Wearer, this.Wearer.Map, 1f); + + if (this.StructurePoints <= 0) + { + Messages.Message("PowerArmorBroken".Translate(this.Label, this.Wearer.LabelShort), this, MessageTypeDefOf.NegativeEvent); + this.Destroy(DestroyMode.KillFinalize); + } + } + else + { + EffecterDefOf.Deflect_Metal_Bullet.SpawnAttached(this.Wearer, this.Wearer.Map, 1f); + } + + // By returning true, we tell the game the damage has been fully handled and should not proceed to the pawn. + return true; + } + + private float GetPostArmorDamage(ref DamageInfo dinfo) + { + float amount = dinfo.Amount; + if (dinfo.Def.armorCategory != null) + { + StatDef armorRatingStat = dinfo.Def.armorCategory.armorRatingStat; + float armorRating = this.GetStatValue(armorRatingStat); + + float armorPenetration = dinfo.ArmorPenetrationInt; + float num = Mathf.Max(armorRating - armorPenetration, 0f); + float value = Rand.Value; + float num2 = num * 0.5f; + float num3 = num; + if (value < num2) + { + amount = 0f; + } + else if (value < num3) + { + amount = GenMath.RoundRandom(amount / 2f); + if (dinfo.Def.armorCategory == DamageArmorCategoryDefOf.Sharp) + { + dinfo.Def = DamageDefOf.Blunt; + } + } + } + return amount; + } + #endregion + } +} \ No newline at end of file diff --git a/Source/ArachnaeSwarm/PowerArmor/CompPowerArmorStation.cs b/Source/ArachnaeSwarm/PowerArmor/CompPowerArmorStation.cs new file mode 100644 index 0000000..7515614 --- /dev/null +++ b/Source/ArachnaeSwarm/PowerArmor/CompPowerArmorStation.cs @@ -0,0 +1,20 @@ +using RimWorld; +using Verse; + +namespace ArachnaeSwarm +{ + public class CompProperties_PowerArmorStation : CompProperties + { + public ThingDef apparelDef; + + public CompProperties_PowerArmorStation() + { + compClass = typeof(CompPowerArmorStation); + } + } + + public class CompPowerArmorStation : ThingComp + { + public CompProperties_PowerArmorStation Props => (CompProperties_PowerArmorStation)props; + } +} \ No newline at end of file diff --git a/Source/ArachnaeSwarm/PowerArmor/Gizmo_StructurePanel.cs b/Source/ArachnaeSwarm/PowerArmor/Gizmo_StructurePanel.cs new file mode 100644 index 0000000..fc5f566 --- /dev/null +++ b/Source/ArachnaeSwarm/PowerArmor/Gizmo_StructurePanel.cs @@ -0,0 +1,55 @@ +using UnityEngine; +using Verse; + +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 IStructurePoints armor; + + public Gizmo_StructurePanel(IStructurePoints armor) + { + this.armor = armor; + this.Order = -100f; // Correctly use the 'Order' property + } + + 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(984988, 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, armor.Label); + + // Draw bar + Rect barRect = rect; + barRect.yMin = overRect.height / 2f; + float fillPercent = armor.StructurePointsPercent; + + Widgets.FillableBar(barRect, fillPercent, FullBarTex, EmptyBarTex, false); + + // Draw text on bar + Text.Font = GameFont.Small; + Text.Anchor = TextAnchor.MiddleCenter; + Widgets.Label(barRect, $"{armor.StructurePoints:F0} / {armor.StructurePointsMax:F0}"); + Text.Anchor = TextAnchor.UpperLeft; + }); + return new GizmoResult(GizmoState.Clear); + } + } +} \ No newline at end of file diff --git a/Source/ArachnaeSwarm/PowerArmor/JobDriver_EnterPowerArmor.cs b/Source/ArachnaeSwarm/PowerArmor/JobDriver_EnterPowerArmor.cs new file mode 100644 index 0000000..5d494aa --- /dev/null +++ b/Source/ArachnaeSwarm/PowerArmor/JobDriver_EnterPowerArmor.cs @@ -0,0 +1,60 @@ +using RimWorld; +using System.Collections.Generic; +using Verse; +using Verse.AI; + +namespace ArachnaeSwarm +{ + public class JobDriver_EnterPowerArmor : JobDriver + { + private const TargetIndex BuildingInd = TargetIndex.A; + private Building PowerArmorBuilding => (Building)job.GetTarget(BuildingInd).Thing; + + public override bool TryMakePreToilReservations(bool errorOnFailed) + { + return pawn.Reserve(PowerArmorBuilding, job, 1, -1, null, errorOnFailed); + } + + protected override IEnumerable MakeNewToils() + { + this.FailOnDespawnedNullOrForbidden(BuildingInd); + this.FailOnSomeonePhysicallyInteracting(BuildingInd); + + yield return Toils_Goto.GotoThing(BuildingInd, PathEndMode.InteractionCell); + yield return Toils_General.Wait(120, BuildingInd).WithProgressBarToilDelay(BuildingInd); + + Toil enter = new Toil(); + enter.initAction = () => + { + Pawn actor = enter.actor; + var building = (Building)actor.CurJob.GetTarget(BuildingInd).Thing; + + // Get the CompProperties from the building's new component + var compProps = building.GetComp()?.Props; + if (compProps != null && compProps.apparelDef != null) + { + // Create the apparel + ARA_PowerArmor apparel = (ARA_PowerArmor)ThingMaker.MakeThing(compProps.apparelDef); + + // CRITICAL STEP: Link the apparel back to the building + apparel.sourceBuilding = building; + + // Sync health from building to apparel + apparel.StructurePoints = building.HitPoints; + + // Wear the apparel + actor.apparel.Wear(apparel, true, true); + + // Despawn the building + building.DeSpawn(); + } + else + { + Log.Error($"[ArachnaeSwarm] Power Armor Building {building.def.defName} is missing CompProperties_PowerArmorStation or apparelDef."); + } + }; + enter.defaultCompleteMode = ToilCompleteMode.Instant; + yield return enter; + } + } +} \ No newline at end of file