This commit is contained in:
2025-08-19 21:08:12 +08:00
parent 0b2efcd559
commit 34bf8beb45
9 changed files with 205 additions and 97 deletions

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<HediffDef>
<defName>WULA_MechCarrierSwitchHediff</defName>
<label>生产抑制</label>
<description>此单位的自动生产功能已被抑制。</description>
<hediffClass>HediffWithComps</hediffClass>
<isBad>false</isBad>
<defaultLabelColor>(0.6, 0.6, 0.6)</defaultLabelColor>
<scenarioCanAdd>false</scenarioCanAdd>
</HediffDef>
</Defs>

View File

@@ -70,24 +70,32 @@
<comps>
<!-- 这里是我们修改的核心部分 -->
<li Class="WulaFallenEmpire.CompProperties_AutoMechCarrier">
<startsAsAutoSpawn>true</startsAsAutoSpawn>
<freeProduction>true</freeProduction>
<cooldownTicks>900</cooldownTicks> <!-- 15 seconds -->
<freeProduction>true</freeProduction> <!-- 改为消耗资源以测试独立成本 -->
<disableHediff>WULA_MechCarrierSwitchHediff</disableHediff>
<fixedIngredient>Steel</fixedIngredient>
<maxIngredientCount>500</maxIngredientCount> <!-- 定义最大资源容量 -->
<startingIngredientCount>500</startingIngredientCount> <!-- 定义初始资源数量 -->
<costPerPawn>999</costPerPawn> <!-- 设置一个很高的全局默认成本,以确保独立成本生效 -->
<cooldownTicks>9999</cooldownTicks> <!-- 设置一个很高的全局默认冷却,以确保独立冷却生效 -->
<productionQueue>
<li>
<pawnKind>Mech_WarUrchin</pawnKind>
<count>2</count>
<cooldownTicks>600</cooldownTicks> <!-- 独立冷却: 10秒 -->
<cost>10</cost> <!-- 独立成本: 10 钢铁 -->
</li>
<li>
<pawnKind>Mech_Lancer</pawnKind>
<count>1</count>
<cooldownTicks>1200</cooldownTicks> <!-- 独立冷却: 20秒 -->
<cost>25</cost> <!-- 独立成本: 25 钢铁 -->
</li>
</productionQueue>
<spawnEffecter>WarqueenWarUrchinsSpawned</spawnEffecter>
<spawnedMechEffecter>WarUrchinSpawned</spawnedMechEffecter>
</li>
<li Class="CompProperties_TurretGun">
<turretDef>WULA_Penetrating_BeamTurret</turretDef>
<turretDef>Gun_ChargeBlasterTurret</turretDef>
<angleOffset>-90</angleOffset>
<autoAttack>false</autoAttack>
<renderNodeProperties>
@@ -112,40 +120,6 @@
</killedLeavingsPlayerHostile>
</ThingDef>
<ThingDef ParentName="BaseWeaponTurret">
<defName>WULA_Penetrating_BeamTurret</defName>
<label>charge blaster turret</label>
<description>A small charge blaster designed for use on a defense turret.</description>
<tradeability>None</tradeability>
<destroyOnDrop>true</destroyOnDrop>
<graphicData>
<texPath>Things/Item/Equipment/WeaponRanged/ChargeBlasterTurret</texPath>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<statBases>
<Mass>2.6</Mass>
<AccuracyTouch>0.60</AccuracyTouch>
<AccuracyShort>0.80</AccuracyShort>
<AccuracyMedium>0.90</AccuracyMedium>
<AccuracyLong>0.85</AccuracyLong>
</statBases>
<verbs>
<li>
<verbClass>Verb_Shoot</verbClass>
<defaultProjectile>Bullet_WULA_RW_Penetrating_Beam_Ranged</defaultProjectile>
<range>44.9</range>
<ticksBetweenBurstShots>30</ticksBetweenBurstShots>
<soundCast>Shot_ChargeBlaster</soundCast>
<soundCastTail>GunTail_Heavy</soundCastTail>
<muzzleFlashScale>9</muzzleFlashScale>
<defaultCooldownTime>2.5</defaultCooldownTime>
<linkedBodyPartsGroup>BulbTurret</linkedBodyPartsGroup>
<ensureLinkedBodyPartsGroupAlwaysUsable>true</ensureLinkedBodyPartsGroupAlwaysUsable>
<ticksBetweenBurstShots>50</ticksBetweenBurstShots>
</li>
</verbs>
</ThingDef>
<PawnKindDef ParentName="HeavyMechanoidKind">
<defName>WULA_Mech_Warqueen</defName> <!-- 修改了defName以避免冲突 -->
<label>war queen (WULA)</label>
@@ -155,6 +129,10 @@
<maxPerGroup>3</maxPerGroup>
<isBoss>true</isBoss>
<allowInMechClusters>false</allowInMechClusters>
<abilities>
<li>WULA_GiveSwitchHediff</li> <!-- 添加“停止生产”技能 -->
<li>WULA_RemoveSwitchHediff</li> <!-- 保留“恢复生产”技能 -->
</abilities>
<lifeStages>
<li>
<bodyGraphicData>
@@ -184,4 +162,63 @@
<controlGroupPortraitZoom>0.7</controlGroupPortraitZoom>
</PawnKindDef>
<!-- 新的技能定义 -->
<AbilityDef>
<defName>WULA_RemoveSwitchHediff</defName>
<label>重启生产</label>
<description>重启自动生产机械体。</description>
<iconPath>Wula/UI/Abilities/WULA_WeaponSwitchAbility</iconPath>
<cooldownTicksRange>601</cooldownTicksRange>
<hostile>false</hostile>
<showOnCharacterCard>true</showOnCharacterCard>
<aiCanUse>false</aiCanUse>
<verbProperties>
<verbClass>Verb_CastAbility</verbClass>
<warmupTime>0</warmupTime>
<drawAimPie>false</drawAimPie>
<requireLineOfSight>false</requireLineOfSight>
<targetable>false</targetable>
<targetParams>
<canTargetSelf>true</canTargetSelf>
</targetParams>
</verbProperties>
<comps>
<!-- 这是正确的用法 -->
<li Class="RimWorld.CompProperties_AbilityRemoveHediff">
<compClass>WulaFallenEmpire.CompAbilityEffect_RemoveSwitchHediff</compClass>
<hediffDef>WULA_MechCarrierSwitchHediff</hediffDef>
<applyToSelf>true</applyToSelf>
</li>
</comps>
</AbilityDef>
<!-- 新增的“施加Hediff”技能定义 -->
<AbilityDef>
<defName>WULA_GiveSwitchHediff</defName>
<label>停止生产</label>
<description>停止自动生产机械体。</description>
<iconPath>Wula/UI/Abilities/WULA_WeaponSwitchAbility</iconPath>
<cooldownTicksRange>601</cooldownTicksRange>
<hostile>false</hostile>
<showOnCharacterCard>true</showOnCharacterCard>
<aiCanUse>false</aiCanUse>
<verbProperties>
<verbClass>Verb_CastAbility</verbClass>
<warmupTime>0</warmupTime>
<drawAimPie>false</drawAimPie>
<requireLineOfSight>false</requireLineOfSight>
<targetable>false</targetable>
<targetParams>
<canTargetSelf>true</canTargetSelf>
</targetParams>
</verbProperties>
<comps>
<li Class="RimWorld.CompProperties_AbilityGiveHediff">
<compClass>WulaFallenEmpire.CompAbilityEffect_GiveSwitchHediff</compClass>
<hediffDef>WULA_MechCarrierSwitchHediff</hediffDef>
<applyToSelf>true</applyToSelf>
</li>
</comps>
</AbilityDef>
</Defs>

View File

@@ -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;
}
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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<Thing> things = new List<Thing>(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<Gizmo> CompGetGizmosExtra()
{
// 拦截并改造基类的Gizmo
foreach (var gizmo in base.CompGetGizmosExtra())
{
// 通过图标来稳定地识别目标按钮
if (gizmo is Command_ActionWithCooldown command && command.icon == ContentFinder<Texture2D>.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<Gizmo>();
}
public override string CompInspectStringExtra()

View File

@@ -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<PawnProductionEntry> productionQueue = new List<PawnProductionEntry>();

View File

@@ -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;
}
}

View File

@@ -73,6 +73,8 @@
<Compile Include="CompAutoMechCarrier.cs" />
<Compile Include="CompProperties_AutoMechCarrier.cs" />
<Compile Include="PawnProductionEntry.cs" />
<Compile Include="CompAbilityEffect_GiveSwitchHediff.cs" />
<Compile Include="CompAbilityEffect_RemoveSwitchHediff.cs" />
<Compile Include="Building_Wula_DarkEnergy_Engine.cs" />
<Compile Include="CompApparelInterceptor.cs" />
<Compile Include="CompCustomUniqueWeapon.cs" />