diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll index eff3aecb..018a9314 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/1.6/Defs/HediffDefs/WULA_Hediffs_MechCarrier.xml b/1.6/1.6/Defs/HediffDefs/WULA_Hediffs_MechCarrier.xml new file mode 100644 index 00000000..6f6c5da3 --- /dev/null +++ b/1.6/1.6/Defs/HediffDefs/WULA_Hediffs_MechCarrier.xml @@ -0,0 +1,14 @@ + + + + + WULA_MechCarrierSwitchHediff + + 此单位的自动生产功能已被抑制。 + HediffWithComps + false + (0.6, 0.6, 0.6) + false + + + \ No newline at end of file diff --git a/1.6/1.6/Defs/ThingDefs_Races/WULA_Race_Mech_Warqueen_Example.xml b/1.6/1.6/Defs/ThingDefs_Races/WULA_Race_Mech_Warqueen_Example.xml index a34f2a8f..f565d3ac 100644 --- a/1.6/1.6/Defs/ThingDefs_Races/WULA_Race_Mech_Warqueen_Example.xml +++ b/1.6/1.6/Defs/ThingDefs_Races/WULA_Race_Mech_Warqueen_Example.xml @@ -70,24 +70,32 @@
  • - true - true - 900 + true + WULA_MechCarrierSwitchHediff + Steel + 500 + 500 + 999 + 9999
  • Mech_WarUrchin 2 + 600 + 10
  • Mech_Lancer 1 + 1200 + 25
  • WarqueenWarUrchinsSpawned WarUrchinSpawned
  • - WULA_Penetrating_BeamTurret + Gun_ChargeBlasterTurret -90 false @@ -112,40 +120,6 @@ - - WULA_Penetrating_BeamTurret - - A small charge blaster designed for use on a defense turret. - None - true - - Things/Item/Equipment/WeaponRanged/ChargeBlasterTurret - Graphic_Single - - - 2.6 - 0.60 - 0.80 - 0.90 - 0.85 - - -
  • - Verb_Shoot - Bullet_WULA_RW_Penetrating_Beam_Ranged - 44.9 - 30 - Shot_ChargeBlaster - GunTail_Heavy - 9 - 2.5 - BulbTurret - true - 50 -
  • - - - WULA_Mech_Warqueen @@ -155,6 +129,10 @@ 3 true false + +
  • WULA_GiveSwitchHediff
  • +
  • WULA_RemoveSwitchHediff
  • +
  • @@ -184,4 +162,63 @@ 0.7 + + + WULA_RemoveSwitchHediff + + 重启自动生产机械体。 + Wula/UI/Abilities/WULA_WeaponSwitchAbility + 601 + false + true + false + + Verb_CastAbility + 0 + false + false + false + + true + + + + +
  • + WulaFallenEmpire.CompAbilityEffect_RemoveSwitchHediff + WULA_MechCarrierSwitchHediff + true +
  • +
    + + + + + WULA_GiveSwitchHediff + + 停止自动生产机械体。 + Wula/UI/Abilities/WULA_WeaponSwitchAbility + 601 + false + true + false + + Verb_CastAbility + 0 + false + false + false + + true + + + +
  • + WulaFallenEmpire.CompAbilityEffect_GiveSwitchHediff + WULA_MechCarrierSwitchHediff + true +
  • +
    +
    + \ No newline at end of file diff --git a/Source/WulaFallenEmpire/CompAbilityEffect_GiveSwitchHediff.cs b/Source/WulaFallenEmpire/CompAbilityEffect_GiveSwitchHediff.cs new file mode 100644 index 00000000..d5f19f39 --- /dev/null +++ b/Source/WulaFallenEmpire/CompAbilityEffect_GiveSwitchHediff.cs @@ -0,0 +1,32 @@ +using RimWorld; +using Verse; + +namespace WulaFallenEmpire +{ + public class CompAbilityEffect_GiveSwitchHediff : CompAbilityEffect + { + public new CompProperties_AbilityGiveHediff Props => (CompProperties_AbilityGiveHediff)props; + + public override void Apply(LocalTargetInfo target, LocalTargetInfo dest) + { + base.Apply(target, dest); + if (Props.hediffDef != null) + { + parent.pawn.health.AddHediff(Props.hediffDef); + } + } + + public override bool ShouldHideGizmo + { + get + { + // 如果父级Pawn已经有了这个Hediff,就隐藏“给予”按钮 + if (parent.pawn?.health.hediffSet.HasHediff(Props.hediffDef) ?? false) + { + return true; + } + return base.ShouldHideGizmo; + } + } + } +} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/CompAbilityEffect_RemoveSwitchHediff.cs b/Source/WulaFallenEmpire/CompAbilityEffect_RemoveSwitchHediff.cs new file mode 100644 index 00000000..0b5ddae2 --- /dev/null +++ b/Source/WulaFallenEmpire/CompAbilityEffect_RemoveSwitchHediff.cs @@ -0,0 +1,33 @@ +using RimWorld; +using Verse; + +namespace WulaFallenEmpire +{ + public class CompAbilityEffect_RemoveSwitchHediff : CompAbilityEffect + { + public new CompProperties_AbilityRemoveHediff Props => (CompProperties_AbilityRemoveHediff)props; + + public override void Apply(LocalTargetInfo target, LocalTargetInfo dest) + { + base.Apply(target, dest); + Hediff firstHediffOfDef = parent.pawn.health.hediffSet.GetFirstHediffOfDef(Props.hediffDef); + if (firstHediffOfDef != null) + { + parent.pawn.health.RemoveHediff(firstHediffOfDef); + } + } + + public override bool ShouldHideGizmo + { + get + { + // 如果父级Pawn没有这个Hediff,就隐藏“移除”按钮 + if (!parent.pawn?.health.hediffSet.HasHediff(Props.hediffDef) ?? true) + { + return true; + } + return base.ShouldHideGizmo; + } + } + } +} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/CompAutoMechCarrier.cs b/Source/WulaFallenEmpire/CompAutoMechCarrier.cs index 9e9a600a..9da24794 100644 --- a/Source/WulaFallenEmpire/CompAutoMechCarrier.cs +++ b/Source/WulaFallenEmpire/CompAutoMechCarrier.cs @@ -10,8 +10,6 @@ namespace WulaFallenEmpire { public class CompAutoMechCarrier : CompMechCarrier { - private bool isAutoSpawning; - #region Reflected Fields private static FieldInfo spawnedPawnsField; private static FieldInfo cooldownTicksRemainingField; @@ -64,28 +62,17 @@ namespace WulaFallenEmpire return SpawnedPawns.Count(p => p.kindDef == kind); } - public override void PostSpawnSetup(bool respawningAfterLoad) - { - base.PostSpawnSetup(respawningAfterLoad); - if (!respawningAfterLoad) - { - isAutoSpawning = AutoProps.startsAsAutoSpawn; - } - } - - public override void PostExposeData() - { - base.PostExposeData(); - Scribe_Values.Look(ref isAutoSpawning, "isAutoSpawning", AutoProps.startsAsAutoSpawn); - } - private AcceptanceReport CanSpawnNow(PawnKindDef kind) { if (parent is Pawn pawn && (pawn.IsSelfShutdown() || !pawn.Awake() || pawn.Downed || pawn.Dead || !pawn.Spawned)) return false; if (CooldownTicksRemaining > 0) return "CooldownTime".Translate() + " " + CooldownTicksRemaining.ToStringSecondsFromTicks(); - if (!AutoProps.freeProduction && InnerContainer.TotalStackCountOfDef(Props.fixedIngredient) < Props.costPerPawn) + + PawnProductionEntry entry = AutoProps.productionQueue.First(e => e.pawnKind == kind); + int cost = entry.cost ?? Props.costPerPawn; + + if (!AutoProps.freeProduction && InnerContainer.TotalStackCountOfDef(Props.fixedIngredient) < cost) return "MechCarrierNotEnoughResources".Translate(); return true; } @@ -102,7 +89,9 @@ namespace WulaFallenEmpire if (!AutoProps.freeProduction) { - int costLeft = Props.costPerPawn; + PawnProductionEntry entry = AutoProps.productionQueue.First(e => e.pawnKind == kind); + int costLeft = entry.cost ?? Props.costPerPawn; + List things = new List(InnerContainer); for (int j = 0; j < things.Count; j++) { @@ -112,8 +101,10 @@ namespace WulaFallenEmpire if (costLeft <= 0) break; } } + + PawnProductionEntry spawnEntry = AutoProps.productionQueue.First(e => e.pawnKind == kind); + CooldownTicksRemaining = spawnEntry.cooldownTicks ?? Props.cooldownTicks; - CooldownTicksRemaining = Props.cooldownTicks; if (Props.spawnedMechEffecter != null) EffecterTrigger(Props.spawnedMechEffecter, Props.attachSpawnedMechEffecter, pawn); if (Props.spawnEffecter != null) @@ -130,10 +121,35 @@ namespace WulaFallenEmpire public override void CompTick() { base.CompTick(); - if (isAutoSpawning && parent.IsHashIntervalTick(60)) // 每秒检查一次 + + if (parent.IsHashIntervalTick(60)) // 每秒检查一次 { + // 检查是否有抑制生产的Hediff + if (AutoProps.disableHediff != null && (parent as Pawn)?.health.hediffSet.HasHediff(AutoProps.disableHediff) == true) + { + return; // 有Hediff,停止生产 + } + + // 1. 先检查是否满员 + bool isFull = true; + foreach (var entry in AutoProps.productionQueue) + { + if (LiveSpawnedPawnsCount(entry.pawnKind) < entry.count) + { + isFull = false; + break; + } + } + + if (isFull) + { + return; // 如果已满员,则不进行任何操作,包括冷却计时 + } + + // 2. 如果未满员,才检查冷却时间 if (CooldownTicksRemaining > 0) return; + // 3. 寻找空位并生产 foreach (var entry in AutoProps.productionQueue) { if (LiveSpawnedPawnsCount(entry.pawnKind) < entry.count) @@ -141,7 +157,7 @@ namespace WulaFallenEmpire if (CanSpawnNow(entry.pawnKind).Accepted) { TrySpawnPawn(entry.pawnKind); - break; // 每次只生产一个,然后等待下一次冷却 + break; // 每次只生产一个 } } } @@ -150,40 +166,8 @@ namespace WulaFallenEmpire public override IEnumerable CompGetGizmosExtra() { - // 拦截并改造基类的Gizmo - foreach (var gizmo in base.CompGetGizmosExtra()) - { - // 通过图标来稳定地识别目标按钮 - if (gizmo is Command_ActionWithCooldown command && command.icon == ContentFinder.Get("UI/Gizmos/ReleaseWarUrchins")) - { - // 我们只改造这个按钮,其他按钮原样返回 - var modifiedCommand = new Command_ActionWithCooldown - { - // 保留冷却进度条的逻辑 - cooldownPercentGetter = command.cooldownPercentGetter, - // 保留原版图标 - icon = command.icon, - // 修改功能为切换自动生产 - action = () => { isAutoSpawning = !isAutoSpawning; }, - // 修改标签和描述 - defaultLabel = "WULA_AutoSpawn_Label".Translate(), - defaultDesc = "WULA_AutoSpawn_Desc".Translate() - }; - - // 如果自动生产开启,则禁用按钮并显示红叉 - if (isAutoSpawning) - { - modifiedCommand.Disable("WULA_AutoSpawn_On_Reason".Translate()); - } - - yield return modifiedCommand; - } - else - { - // 其他按钮(如开发者按钮)原样返回 - yield return gizmo; - } - } + // 移除所有Gizmo逻辑 + return Enumerable.Empty(); } public override string CompInspectStringExtra() diff --git a/Source/WulaFallenEmpire/CompProperties_AutoMechCarrier.cs b/Source/WulaFallenEmpire/CompProperties_AutoMechCarrier.cs index 6ba1a6d6..8dea8a67 100644 --- a/Source/WulaFallenEmpire/CompProperties_AutoMechCarrier.cs +++ b/Source/WulaFallenEmpire/CompProperties_AutoMechCarrier.cs @@ -6,12 +6,12 @@ namespace WulaFallenEmpire { public class CompProperties_AutoMechCarrier : CompProperties_MechCarrier { - // XML中定义,初始是否为自动生产模式 - public bool startsAsAutoSpawn = false; - // XML中定义,生产是否消耗资源 public bool freeProduction = false; + // 如果单位拥有这个Hediff,则停止生产 + public HediffDef disableHediff; + // 定义生产队列 public List productionQueue = new List(); diff --git a/Source/WulaFallenEmpire/PawnProductionEntry.cs b/Source/WulaFallenEmpire/PawnProductionEntry.cs index 4978648f..99bc76c8 100644 --- a/Source/WulaFallenEmpire/PawnProductionEntry.cs +++ b/Source/WulaFallenEmpire/PawnProductionEntry.cs @@ -13,5 +13,11 @@ namespace WulaFallenEmpire // The maximum number of this kind of unit to maintain. public int count = 1; + + // Optional: specific cooldown for this entry. If not set, the parent comp's cooldown is used. + public int? cooldownTicks; + + // Optional: specific cost for this entry. If not set, the parent comp's costPerPawn is used. + public int? cost; } } \ No newline at end of file diff --git a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj index 0e11552b..d93c48f6 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj +++ b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj @@ -73,6 +73,8 @@ + +