This commit is contained in:
2025-09-22 12:35:38 +08:00
parent 59857fda42
commit 6e40cbb817
5 changed files with 199 additions and 0 deletions

Binary file not shown.

View File

@@ -196,4 +196,61 @@
<li Class="HediffCompProperties_DisappearsOnDeath"/>
</comps>
</HediffDef>
<HediffDef>
<defName>ARA_ChainReload</defName>
<label>链式装填</label>
<description>使用的武器拥有链式装填能力, 装填速度将随每次射击后提升。</description>
<defaultLabelColor>(0.52, 1, 0.95)</defaultLabelColor>
<hediffClass>HediffWithComps</hediffClass>
<comps>
<li Class="HediffCompProperties_DisappearsOnDeath" />
<li Class="HediffCompProperties_Disappears">
<disappearsAfterTicks>1800</disappearsAfterTicks> <!-- 30 seconds -->
<showRemainingTime>true</showRemainingTime>
</li>
</comps>
<stages>
<li>
<label>等级1/5</label>
<becomeVisible>true</becomeVisible>
<statFactors>
<AimingDelayFactor>0.9</AimingDelayFactor>
<RangedCooldownFactor>0.9</RangedCooldownFactor>
</statFactors>
</li>
<li>
<label>等级2/5</label>
<minSeverity>4</minSeverity>
<statFactors>
<AimingDelayFactor>0.8</AimingDelayFactor>
<RangedCooldownFactor>0.8</RangedCooldownFactor>
</statFactors>
</li>
<li>
<label>等级3/5</label>
<minSeverity>8</minSeverity>
<statFactors>
<AimingDelayFactor>0.65</AimingDelayFactor>
<RangedCooldownFactor>0.65</RangedCooldownFactor>
</statFactors>
</li>
<li>
<label>等级4/5</label>
<minSeverity>12</minSeverity>
<statFactors>
<AimingDelayFactor>0.45</AimingDelayFactor>
<RangedCooldownFactor>0.45</RangedCooldownFactor>
</statFactors>
</li>
<li>
<label>等级5/5</label>
<minSeverity>16</minSeverity>
<statFactors>
<AimingDelayFactor>0.25</AimingDelayFactor>
<RangedCooldownFactor>0.25</RangedCooldownFactor>
</statFactors>
</li>
</stages>
</HediffDef>
</Defs>

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<!-- spawn -->
<ThingDef ParentName="BaseHumanMakeableGun">
<defName>ARA_RW_Basic_SniperCannon_Gun</defName>
<label>武装器官"链式棘刺"</label>
<description>阿拉克涅虫群的生物武器</description>
<tickerType>Normal</tickerType>
<techLevel>Animal</techLevel>
<descriptionHyperlinks>
<ThingDef>ARA_Cocoon_Weapon_1Stage</ThingDef>
</descriptionHyperlinks>
<graphicData>
<texPath>ArachnaeSwarm/Weapon/ARA_RW_Basic_Acid_Bladder_Gun</texPath>
<graphicClass>Graphic_Single</graphicClass>
<drawSize>1.2</drawSize>
</graphicData>
<soundInteract>SpitterSpawn</soundInteract>
<recipeMaker>
<recipeUsers Inherit="False" />
<researchPrerequisite>ARA_Technology_6SPV</researchPrerequisite>
<unfinishedThingDef>UnfinishedWeapon</unfinishedThingDef>
</recipeMaker>
<statBases>
<WorkToMake>1300</WorkToMake>
<!-- <MarketValue>370</MarketValue> -->
<Mass>3.5</Mass>
<AccuracyTouch>0.22</AccuracyTouch>
<AccuracyShort>0.33</AccuracyShort>
<AccuracyMedium>0.44</AccuracyMedium>
<AccuracyLong>0.95</AccuracyLong>
<RangedWeapon_Cooldown>3.2</RangedWeapon_Cooldown>
</statBases>
<verbs>
<li>
<verbClass>Verb_Shoot</verbClass>
<hasStandardCommand>true</hasStandardCommand>
<defaultProjectile>Bullet_TurretSniper</defaultProjectile>
<warmupTime>3.5</warmupTime>
<minRange>5.9</minRange>
<range>45.9</range>
<burstShotCount>1</burstShotCount>
<soundCast>Shot_TurretSniper</soundCast>
<soundCastTail>GunTail_Heavy</soundCastTail>
<muzzleFlashScale>18</muzzleFlashScale>
</li>
</verbs>
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T1</li>
</weaponTags>
<thingSetMakerTags>
<li>RewardStandardQualitySuper</li>
</thingSetMakerTags>
<comps>
<li Class="ArachnaeSwarm.CompProperties_GiveHediffOnShot">
<hediffDef>ARA_ChainReload</hediffDef>
<severityToAdd>0.5</severityToAdd>
</li>
</comps>
</ThingDef>
</Defs>

View File

@@ -154,6 +154,7 @@
<Compile Include="Hediffs\WULA_HediffDamgeShield\DRMDamageShield.cs" />
<Compile Include="Hediffs\WULA_HediffDamgeShield\Hediff_DamageShield.cs" />
<Compile Include="MainHarmony.cs" />
<Compile Include="CompAndPatch_GiveHediffOnShot.cs" />
<Compile Include="Pawn_Comps\ARA_AutoMechCarrier\CompAutoMechCarrier.cs" />
<Compile Include="Pawn_Comps\ARA_AutoMechCarrier\CompProperties_AutoMechCarrier.cs" />
<Compile Include="Pawn_Comps\ARA_AutoMechCarrier\PawnProductionEntry.cs" />

View File

@@ -0,0 +1,75 @@
using HarmonyLib;
using RimWorld;
using Verse;
namespace ArachnaeSwarm
{
// 1. 定义CompProperties来存储我们的数据
public class CompProperties_GiveHediffOnShot : CompProperties
{
public HediffDef hediffDef;
public float severityToAdd = 0.1f;
public CompProperties_GiveHediffOnShot()
{
compClass = typeof(CompGiveHediffOnShot);
}
}
// 2. 创建一个简单的Comp来挂载到武器上它只负责持有数据
public class CompGiveHediffOnShot : ThingComp
{
public CompProperties_GiveHediffOnShot Props => (CompProperties_GiveHediffOnShot)props;
}
// 3. 创建Harmony补丁
// 补丁目标为 Verb_Shoot.TryCastShot。这是所有射击动作的通用入口。
[HarmonyPatch(typeof(Verb_Shoot), "TryCastShot")]
public static class Patch_Verb_Shoot_TryCastShot
{
// 使用[HarmonyPostfix]特性来创建一个在原方法执行后运行的补丁
// 添加一个bool类型的返回值`__result`,它代表了原方法的返回值
public static void Postfix(Verb_Shoot __instance, bool __result)
{
// __result 是原方法 TryCastShot 的返回值。
// 如果 __result 为 false意味着射击动作因某些原因如目标无效、没有弹药失败了我们就不应该添加Hediff。
if (!__result)
{
return;
}
// __instance是原方法的实例对象也就是那个Verb_Shoot
// 检查这个Verb是否来源于一个装备武器
if (__instance.EquipmentSource == null || __instance.CasterPawn == null)
{
return;
}
// 尝试从武器上获取我们自定义的Comp
CompGiveHediffOnShot comp = __instance.EquipmentSource.GetComp<CompGiveHediffOnShot>();
if (comp == null)
{
return;
}
// 检查XML中是否配置了hediffDef
if (comp.Props.hediffDef == null)
{
Log.ErrorOnce($"[ArachnaeSwarm] CompGiveHediffOnShot on {__instance.EquipmentSource.def.defName} has null hediffDef.", __instance.EquipmentSource.def.GetHashCode());
return;
}
// 为射击者CasterPawn添加或增加Hediff的严重性
Hediff hediff = __instance.CasterPawn.health.GetOrAddHediff(comp.Props.hediffDef);
hediff.Severity += comp.Props.severityToAdd;
// 检查Hediff是否带有HediffComp_Disappears组件
HediffComp_Disappears disappearsComp = hediff.TryGetComp<HediffComp_Disappears>();
if (disappearsComp != null)
{
// 如果有,则调用正确的方法重置它的消失计时器
disappearsComp.ResetElapsedTicks();
}
}
}
}