Files
ArachnaeSwarm/Source/ArachnaeSwarm/ARA_CompMilkableArachnae/CompMilkableArachnae.cs
2025-09-05 12:52:17 +08:00

80 lines
2.4 KiB
C#

using RimWorld;
using Verse;
using UnityEngine;
namespace ArachnaeSwarm
{
public class CompMilkableArachnae : CompHasGatherableBodyResource
{
protected override int GatherResourcesIntervalDays => Props.milkIntervalDays;
protected override int ResourceAmount => Props.milkAmount;
protected override ThingDef ResourceDef => Props.milkDef;
protected override string SaveKey => "milkFullness";
public CompProperties_MilkableArachnae Props => (CompProperties_MilkableArachnae)props;
protected override bool Active
{
get
{
if (!base.Active)
{
return false;
}
Pawn pawn = parent as Pawn;
if (Props.milkFemaleOnly && pawn != null && pawn.gender != Gender.Female)
{
return false;
}
if (pawn != null && !pawn.ageTracker.CurLifeStage.milkable)
{
return false;
}
if (ModsConfig.AnomalyActive && pawn.IsShambler)
{
return false;
}
return true;
}
}
public override string CompInspectStringExtra()
{
if (!Active)
{
return null;
}
return "MilkFullness".Translate() + ": " + base.Fullness.ToStringPercent();
}
public override void CompTick()
{
base.CompTick();
// 检查是否活跃且fullness已满
if (Active && fullness >= 1.0f)
{
// 检查parent是否是Pawn且在普通地图上
if (parent is Pawn pawn && pawn.Map != null)
{
// 自动生成资源并掉落到地上
int num = ResourceAmount;
while (num > 0)
{
int num2 = Mathf.Clamp(num, 1, ResourceDef.stackLimit);
num -= num2;
Thing thing = ThingMaker.MakeThing(ResourceDef);
thing.stackCount = num2;
GenPlace.TryPlaceThing(thing, pawn.Position, pawn.Map, ThingPlaceMode.Near);
}
// 重置挤奶进度
fullness = 0f;
}
}
}
}
}