扫地和hediff
This commit is contained in:
Binary file not shown.
@@ -182,9 +182,6 @@
|
|||||||
<value>8.0</value>
|
<value>8.0</value>
|
||||||
</li>
|
</li>
|
||||||
</moveSpeedFactorByTerrainTag>
|
</moveSpeedFactorByTerrainTag>
|
||||||
<techHediffsRequired>
|
|
||||||
<li>ARA_HiveMindWorker</li>
|
|
||||||
</techHediffsRequired>
|
|
||||||
</PawnKindDef>
|
</PawnKindDef>
|
||||||
<PawnKindDef ParentName="ARA_InsectKindBase">
|
<PawnKindDef ParentName="ARA_InsectKindBase">
|
||||||
<defName>ArachnaeBase_Race_Slavey</defName>
|
<defName>ArachnaeBase_Race_Slavey</defName>
|
||||||
|
|||||||
@@ -61,6 +61,15 @@
|
|||||||
<workerClass>DeathActionWorker_Vanish</workerClass>
|
<workerClass>DeathActionWorker_Vanish</workerClass>
|
||||||
</deathAction> -->
|
</deathAction> -->
|
||||||
</race>
|
</race>
|
||||||
|
<comps>
|
||||||
|
<li Class="ArachnaeSwarm.CompProperties_HediffGiver">
|
||||||
|
<hediffs>
|
||||||
|
<li>ARA_HiveMindWorker</li>
|
||||||
|
</hediffs>
|
||||||
|
<addChance>1.0</addChance>
|
||||||
|
<allowDuplicates>false</allowDuplicates>
|
||||||
|
</li>
|
||||||
|
</comps>
|
||||||
</ThingDef>
|
</ThingDef>
|
||||||
<ThingDef ParentName="ArachnaeBase_Race">
|
<ThingDef ParentName="ArachnaeBase_Race">
|
||||||
<defName>ArachnaeBase_Race_Slavey</defName>
|
<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 (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);
|
IntVec3 closestSnowCell = _workGiver.FindClosestSnow(pawn);
|
||||||
if (closestSnowCell.IsValid)
|
if (closestSnowCell.IsValid)
|
||||||
{
|
{
|
||||||
Job snowJob = _workGiver.JobOnCell(pawn, closestSnowCell);
|
Job snowJob = _workGiver.JobOnCell(pawn, closestSnowCell);
|
||||||
if (snowJob != null) return snowJob;
|
if (snowJob != null) return snowJob;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,14 +62,31 @@ namespace ArachnaeSwarm
|
|||||||
|
|
||||||
public IntVec3 FindClosestSnow(Pawn pawn)
|
public IntVec3 FindClosestSnow(Pawn pawn)
|
||||||
{
|
{
|
||||||
return CellFinder.RandomClosewalkCellNear(pawn.Position, pawn.Map, 100,
|
IntVec3 bestCell = IntVec3.Invalid;
|
||||||
c => HasJobOnCell(pawn, c) && pawn.CanReach(c, PathEndMode.Touch, Danger.Deadly));
|
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)
|
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.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;
|
if (!pawn.CanReserve(c, 1, -1, null, forced)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,8 @@
|
|||||||
<Compile Include="ARA_SpawnPawnFromList\JobGiver_MaintainBuildings.cs" />
|
<Compile Include="ARA_SpawnPawnFromList\JobGiver_MaintainBuildings.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<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\CompMilkableArachnae.cs" />
|
||||||
<Compile Include="ARA_CompMilkableArachnae\CompProperties_MilkableArachnae.cs" />
|
<Compile Include="ARA_CompMilkableArachnae\CompProperties_MilkableArachnae.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user