暂存地形刺激
This commit is contained in:
@@ -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