扫地和hediff
This commit is contained in:
Binary file not shown.
@@ -182,9 +182,6 @@
|
||||
<value>8.0</value>
|
||||
</li>
|
||||
</moveSpeedFactorByTerrainTag>
|
||||
<techHediffsRequired>
|
||||
<li>ARA_HiveMindWorker</li>
|
||||
</techHediffsRequired>
|
||||
</PawnKindDef>
|
||||
<PawnKindDef ParentName="ARA_InsectKindBase">
|
||||
<defName>ArachnaeBase_Race_Slavey</defName>
|
||||
|
||||
@@ -61,6 +61,15 @@
|
||||
<workerClass>DeathActionWorker_Vanish</workerClass>
|
||||
</deathAction> -->
|
||||
</race>
|
||||
<comps>
|
||||
<li Class="ArachnaeSwarm.CompProperties_HediffGiver">
|
||||
<hediffs>
|
||||
<li>ARA_HiveMindWorker</li>
|
||||
</hediffs>
|
||||
<addChance>1.0</addChance>
|
||||
<allowDuplicates>false</allowDuplicates>
|
||||
</li>
|
||||
</comps>
|
||||
</ThingDef>
|
||||
<ThingDef ParentName="ArachnaeBase_Race">
|
||||
<defName>ArachnaeBase_Race_Slavey</defName>
|
||||
|
||||
45
Source/ArachnaeSwarm/ARA_CompHediffGiver/CompHediffGiver.cs
Normal file
45
Source/ArachnaeSwarm/ARA_CompHediffGiver/CompHediffGiver.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class CompHediffGiver : ThingComp
|
||||
{
|
||||
public CompProperties_HediffGiver Props => (CompProperties_HediffGiver)this.props;
|
||||
|
||||
public override void PostSpawnSetup(bool respawningAfterLoad)
|
||||
{
|
||||
base.PostSpawnSetup(respawningAfterLoad);
|
||||
|
||||
// 只有当thing是pawn时才添加hediff
|
||||
if (this.parent is Pawn pawn)
|
||||
{
|
||||
AddHediffsToPawn(pawn);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddHediffsToPawn(Pawn pawn)
|
||||
{
|
||||
// 检查是否有hediff列表
|
||||
if (Props.hediffs == null || Props.hediffs.Count == 0)
|
||||
return;
|
||||
|
||||
// 检查概率
|
||||
if (Props.addChance < 1.0f && Rand.Value > Props.addChance)
|
||||
return;
|
||||
|
||||
// 为每个hediff添加到pawn
|
||||
foreach (HediffDef hediffDef in Props.hediffs)
|
||||
{
|
||||
// 检查是否允许重复添加
|
||||
if (!Props.allowDuplicates && pawn.health.hediffSet.HasHediff(hediffDef))
|
||||
continue;
|
||||
|
||||
// 添加hediff
|
||||
pawn.health.AddHediff(hediffDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class CompProperties_HediffGiver : CompProperties
|
||||
{
|
||||
// 要添加的hediff列表
|
||||
public List<HediffDef> hediffs;
|
||||
|
||||
// 添加hediff的概率(0-1之间)
|
||||
public float addChance = 1.0f;
|
||||
|
||||
// 是否允许重复添加相同的hediff
|
||||
public bool allowDuplicates = false;
|
||||
|
||||
public CompProperties_HediffGiver()
|
||||
{
|
||||
this.compClass = typeof(CompHediffGiver);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,13 +36,16 @@ namespace ArachnaeSwarm
|
||||
if (filthJob != null) return filthJob;
|
||||
}
|
||||
|
||||
// If no filth, find the closest snow/sand to clear
|
||||
// If no filth, check if there's any snow to clear at all before searching
|
||||
if (pawn.Map.areaManager.SnowOrSandClear.TrueCount > 0)
|
||||
{
|
||||
IntVec3 closestSnowCell = _workGiver.FindClosestSnow(pawn);
|
||||
if (closestSnowCell.IsValid)
|
||||
{
|
||||
Job snowJob = _workGiver.JobOnCell(pawn, closestSnowCell);
|
||||
if (snowJob != null) return snowJob;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -62,14 +62,31 @@ namespace ArachnaeSwarm
|
||||
|
||||
public IntVec3 FindClosestSnow(Pawn pawn)
|
||||
{
|
||||
return CellFinder.RandomClosewalkCellNear(pawn.Position, pawn.Map, 100,
|
||||
c => HasJobOnCell(pawn, c) && pawn.CanReach(c, PathEndMode.Touch, Danger.Deadly));
|
||||
IntVec3 bestCell = IntVec3.Invalid;
|
||||
float bestDistSq = float.MaxValue;
|
||||
|
||||
// Efficiently iterate through the designated snow clear area
|
||||
foreach (IntVec3 cell in pawn.Map.areaManager.SnowOrSandClear.ActiveCells)
|
||||
{
|
||||
// Check for a valid job on the cell first
|
||||
if (HasJobOnCell(pawn, cell))
|
||||
{
|
||||
float distSq = pawn.Position.DistanceToSquared(cell);
|
||||
if (distSq < bestDistSq && pawn.CanReach(cell, PathEndMode.Touch, Danger.Deadly))
|
||||
{
|
||||
bestDistSq = distSq;
|
||||
bestCell = cell;
|
||||
}
|
||||
}
|
||||
}
|
||||
return bestCell;
|
||||
}
|
||||
|
||||
public override bool HasJobOnCell(Pawn pawn, IntVec3 c, bool forced = false)
|
||||
{
|
||||
// The check for SnowOrSandClear area is implicitly handled by the caller (FindClosestSnow)
|
||||
// We only need to check the snow depth and reservation status.
|
||||
if (pawn.Map.snowGrid.GetDepth(c) < 0.2f) return false;
|
||||
if (!pawn.Map.areaManager.SnowOrSandClear[c]) return false; // Must be in the clear zone
|
||||
if (!pawn.CanReserve(c, 1, -1, null, forced)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,6 +85,8 @@
|
||||
<Compile Include="ARA_SpawnPawnFromList\JobGiver_MaintainBuildings.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ARA_CompHediffGiver\CompHediffGiver.cs" />
|
||||
<Compile Include="ARA_CompHediffGiver\CompProperties_HediffGiver.cs" />
|
||||
<Compile Include="ARA_CompMilkableArachnae\CompMilkableArachnae.cs" />
|
||||
<Compile Include="ARA_CompMilkableArachnae\CompProperties_MilkableArachnae.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user