暂存地形刺激
This commit is contained in:
61
1.6/1.6/Defs/HediffDefs/ARA_HediffDef_TerrainExample.xml
Normal file
61
1.6/1.6/Defs/HediffDefs/ARA_HediffDef_TerrainExample.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Defs>
|
||||
|
||||
<HediffDef>
|
||||
<defName>ARA_TerrainBasedHediff</defName>
|
||||
<label>菌毯刺激</label>
|
||||
<description>根据所处地形而强化自身。</description>
|
||||
<hediffClass>HediffWithComps</hediffClass>
|
||||
<maxSeverity>1.0</maxSeverity>
|
||||
<minSeverity>-0.01</minSeverity>
|
||||
<isBad>false</isBad>
|
||||
<comps>
|
||||
<li Class="ArachnaeSwarm.HediffCompProperties_TerrainBasedSeverity">
|
||||
<!-- 每60 ticks(1秒)检查一次 -->
|
||||
<interval>60</interval>
|
||||
|
||||
<!-- 目标地形列表 -->
|
||||
<terrainDefs>
|
||||
<!--<li>SterileTile</li> 无菌地砖 -->
|
||||
<!-- 您可以在这里添加更多地形, 比如: -->
|
||||
<li>ARA_InsectCreep</li>
|
||||
</terrainDefs>
|
||||
|
||||
<!-- 站在目标地形上时,每次检查的严重性变化量 -->
|
||||
<severityOnTerrain>0.0167</severityOnTerrain>
|
||||
|
||||
<!-- 不在目标地形上时,每次检查的严重性变化量 (负数表示减少) -->
|
||||
<severityOffTerrain>-0.0083</severityOffTerrain>
|
||||
</li>
|
||||
<li Class="HediffCompProperties_RemoveIfApparelDropped" />
|
||||
</comps>
|
||||
<stages>
|
||||
<li>
|
||||
<becomeVisible>false</becomeVisible>
|
||||
<minSeverity>0</minSeverity>
|
||||
<label>无</label>
|
||||
</li>
|
||||
<li>
|
||||
<minSeverity>0.4</minSeverity>
|
||||
<label>适应</label>
|
||||
<capMods>
|
||||
<li>
|
||||
<capacity>Consciousness</capacity>
|
||||
<offset>0.1</offset>
|
||||
</li>
|
||||
</capMods>
|
||||
</li>
|
||||
<li>
|
||||
<minSeverity>0.8</minSeverity>
|
||||
<label>舒适</label>
|
||||
<capMods>
|
||||
<li>
|
||||
<capacity>Consciousness</capacity>
|
||||
<offset>0.25</offset>
|
||||
</li>
|
||||
</capMods>
|
||||
</li>
|
||||
</stages>
|
||||
</HediffDef>
|
||||
|
||||
</Defs>
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class HediffCompProperties_TerrainBasedSeverity : HediffCompProperties
|
||||
{
|
||||
// 检查效果的时间间隔(以ticks为单位)
|
||||
public int interval = 60;
|
||||
|
||||
// 当角色站在此列表中的任何地形上时,严重性的变化值
|
||||
public float severityOnTerrain = 0f;
|
||||
|
||||
// 当角色不在任何目标地形上时,严重性的变化值
|
||||
public float severityOffTerrain = 0f;
|
||||
|
||||
// 目标地形的defName列表
|
||||
public List<TerrainDef> terrainDefs;
|
||||
|
||||
public HediffCompProperties_TerrainBasedSeverity()
|
||||
{
|
||||
compClass = typeof(HediffComp_TerrainBasedSeverity);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Source/ArachnaeSwarm/HediffComp_TerrainBasedSeverity.cs
Normal file
42
Source/ArachnaeSwarm/HediffComp_TerrainBasedSeverity.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Verse;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class HediffComp_TerrainBasedSeverity : HediffComp
|
||||
{
|
||||
public HediffCompProperties_TerrainBasedSeverity Props => (HediffCompProperties_TerrainBasedSeverity)props;
|
||||
|
||||
public override void CompPostTick(ref float severityAdjustment)
|
||||
{
|
||||
Pawn pawn = parent.pawn;
|
||||
|
||||
// 按照设定的时间间隔执行
|
||||
if (pawn.IsHashIntervalTick(Props.interval))
|
||||
{
|
||||
// 确保角色在地图上
|
||||
if (pawn.Spawned)
|
||||
{
|
||||
// 获取角色当前位置的地形
|
||||
TerrainDef currentTerrain = pawn.Position.GetTerrain(pawn.Map);
|
||||
|
||||
// 检查当前地形是否存在于XML定义的列表中
|
||||
if (Props.terrainDefs != null && Props.terrainDefs.Contains(currentTerrain))
|
||||
{
|
||||
// 如果在目标地形上,增加 severityOnTerrain
|
||||
severityAdjustment += Props.severityOnTerrain;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果不在目标地形上,增加 severityOffTerrain
|
||||
severityAdjustment += Props.severityOffTerrain;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果角色不在地图上(例如在运输舱里),则总是应用 off-terrain 的效果
|
||||
severityAdjustment += Props.severityOffTerrain;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user