存奇怪的植物
This commit is contained in:
@@ -189,6 +189,7 @@
|
||||
<Compile Include="Pawn_Comps\ARA_TrainingWork\JobPlant\ThinkNode_ConditionalAnimalShouldDoGrowingWork.cs" />
|
||||
<Compile Include="Pawn_Comps\ARA_TrainingWork\JobPlant\WorkGiver_ArachnaeSow.cs" />
|
||||
<Compile Include="Pawn_Comps\ARA_TrainingWork\TrainingSystem_Patcher.cs" />
|
||||
<Compile Include="Plants\Plant_Transforming.cs" />
|
||||
<Compile Include="Thing_Comps\ARA_CustomUniqueWeapon\CompCustomUniqueWeapon.cs" />
|
||||
<Compile Include="Thing_Comps\ARA_CustomUniqueWeapon\CompProperties_CustomUniqueWeapon.cs" />
|
||||
<Compile Include="Thing_Comps\ARA_IngestionOutcomeDoer_GiveHediff\IngestionOutcomeDoer_GiveHediffByRace.cs" />
|
||||
|
||||
75
Source/ArachnaeSwarm/Plants/Plant_Transforming.cs
Normal file
75
Source/ArachnaeSwarm/Plants/Plant_Transforming.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
// Define a DefModExtension to hold our custom properties in XML
|
||||
public class PlantTransformExtension : DefModExtension
|
||||
{
|
||||
public ThingDef buildingDef;
|
||||
public float transformAtGrowth = 0.8f;
|
||||
}
|
||||
|
||||
public class Plant_Transforming : Plant
|
||||
{
|
||||
private PlantTransformExtension extension;
|
||||
private bool transformed = false;
|
||||
|
||||
// Caching the extension for performance
|
||||
public PlantTransformExtension Extension
|
||||
{
|
||||
get
|
||||
{
|
||||
if (extension == null)
|
||||
{
|
||||
extension = this.def.GetModExtension<PlantTransformExtension>();
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
}
|
||||
|
||||
public override void ExposeData()
|
||||
{
|
||||
base.ExposeData();
|
||||
Scribe_Values.Look(ref transformed, "transformed", false);
|
||||
}
|
||||
|
||||
public override void TickLong()
|
||||
{
|
||||
base.TickLong(); // Execute base plant logic first
|
||||
|
||||
if (transformed || this.Destroyed || Extension == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.Growth >= Extension.transformAtGrowth)
|
||||
{
|
||||
TryTransform();
|
||||
transformed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void TryTransform()
|
||||
{
|
||||
if (this.Destroyed || Extension.buildingDef == null) return;
|
||||
|
||||
Map map = this.Map;
|
||||
IntVec3 position = this.Position;
|
||||
|
||||
Faction factionToSet = null;
|
||||
Zone zone = map.zoneManager.ZoneAt(position);
|
||||
if (zone is Zone_Growing) factionToSet = Faction.OfPlayer;
|
||||
if (factionToSet == null && map.IsPlayerHome) factionToSet = Faction.OfPlayer;
|
||||
|
||||
Thing building = ThingMaker.MakeThing(Extension.buildingDef, null);
|
||||
if (factionToSet != null && building.def.CanHaveFaction)
|
||||
{
|
||||
building.SetFaction(factionToSet);
|
||||
}
|
||||
|
||||
this.Destroy(DestroyMode.Vanish);
|
||||
GenSpawn.Spawn(building, position, map, WipeMode.Vanish);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user