big-and-small-unofficial-ad.../Source/MBS_Anomaly/PsychicRitualToil_Megaphagy.cs
maciek f390de6ce3
initial commit
first working version
a little late since i didn't expect this to be big enough to require source control 😵‍💫
2025-02-27 19:40:35 +01:00

96 lines
4.2 KiB
C#

/*
Copyright 2025 Maciej Pawłowski
This file is part of "Maciek's Big and Small unofficial addon - Anomaly".
"Maciek's Big and Small unofficial addon - Anomaly" is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
"Maciek's Big and Small unofficial addon - Anomaly" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with "Maciek's Big and Small unofficial addon - Anomaly". If not, see <https://www.gnu.org/licenses/>.
*/
using System.Linq;
using MBS_Anomaly;
using RimWorld;
namespace Verse.AI.Group;
public class PsychicRitualToil_Megaphagy : PsychicRitualToil
{
public PsychicRitualRoleDef targetRole;
public PsychicRitualRoleDef invokerRole;
public FloatRange sizeTransferredFromQualityRange;
protected PsychicRitualToil_Megaphagy()
{
}
public PsychicRitualToil_Megaphagy(PsychicRitualRoleDef invokerRole, PsychicRitualRoleDef targetRole, FloatRange sizeTransferredFromQualityRange)
{
this.invokerRole = invokerRole;
this.targetRole = targetRole;
this.sizeTransferredFromQualityRange = sizeTransferredFromQualityRange;
}
public override void Start(PsychicRitual psychicRitual, PsychicRitualGraph parent)
{
Pawn pawn = psychicRitual.assignments.FirstAssignedPawn(invokerRole);
Pawn pawn2 = psychicRitual.assignments.FirstAssignedPawn(targetRole);
float size = sizeTransferredFromQualityRange.LerpThroughRange(psychicRitual.PowerPercent) * psychicRitual.assignments.FirstAssignedPawn(targetRole).BodySize;
if (pawn != null && pawn2 != null)
{
ApplyOutcome(psychicRitual, pawn, pawn2, size);
}
}
private void ApplyOutcome(PsychicRitual psychicRitual, Pawn invoker, Pawn target, float size)
{
// ReverseAgePawn(invoker, years, out var removedHediffs, out var pawnAgeDelta);
// AgePawn(psychicRitual, target, years, out var gainedHediffs, out var diedOfOldAge, out var diedOfBrainDamage);
size *= target.BodySize;
HediffSizeOffset hediff;
if (invoker.health.hediffSet.TryGetHediff<HediffSizeOffset>(out hediff))
{
hediff.SizeOffset += size;
BigAndSmall.HumanoidPawnScaler.LazyGetCache(invoker);
} else
{
hediff = (HediffSizeOffset)HediffMaker.MakeHediff(MBSADefs.MBSA_BodySizeTransferred, invoker);
hediff.SizeOffset = size;
}
invoker.health.AddHediff(hediff);
if (target.health.hediffSet.TryGetHediff<HediffSizeOffset>(out hediff))
{
hediff.SizeOffset -= size;
BigAndSmall.HumanoidPawnScaler.LazyGetCache(target);
} else
{
hediff = (HediffSizeOffset)HediffMaker.MakeHediff(MBSADefs.MBSA_BodySizeTransferred, target);
hediff.SizeOffset = -size;
}
target.health.AddHediff(hediff);
Hediff shock = HediffMaker.MakeHediff(HediffDefOf.DarkPsychicShock, target);
target.health.AddHediff(shock);
target.needs?.mood?.thoughts?.memories?.TryGainMemory(ThoughtDefOf.PsychicRitualVictim);
foreach (Pawn item in psychicRitual.assignments.AllAssignedPawns.Except(target))
{
target.needs?.mood?.thoughts?.memories?.TryGainMemory(ThoughtDefOf.UsedMeForPsychicRitual, item);
}
if (target.Dead)
{
PsychicRitualUtility.RegisterAsExecutionIfPrisoner(target, invoker);
}
PsychicRitualUtility.AddPsychicRitualGuiltToPawns(psychicRitual.def, psychicRitual.Map.mapPawns.FreeColonistsSpawned.Where((p) => p != target));
}
public override void ExposeData()
{
base.ExposeData();
Scribe_Defs.Look(ref invokerRole, "invokerRole");
Scribe_Defs.Look(ref targetRole, "targetRole");
Scribe_Values.Look(ref sizeTransferredFromQualityRange, "sizeTransferredFromQualityRange");
}
}