/// <summary> /// Tries to revert the transformed pawn instance, implementation. /// </summary> /// <param name="transformedPawn">The transformed pawn.</param> /// <returns></returns> protected override bool TryRevertImpl(TransformedPawnSingle transformedPawn) { if (transformedPawn == null) { throw new ArgumentNullException(nameof(transformedPawn)); } if (!transformedPawn.IsValid) { Log.Warning(nameof(SimpleMechaniteMutagen) + " received an invalid transformed pawn to revert"); return(false); } Pawn animal = transformedPawn.animal; if (animal == null) { return(false); } var rFaction = transformedPawn.FactionResponsible; var spawned = (Pawn)GenSpawn.Spawn(transformedPawn.original, animal.PositionHeld, animal.MapHeld); if (spawned.Faction != animal.Faction && rFaction == null) //if the responsible faction is null (no one knows who did it) have the reverted pawn join that faction { spawned.SetFaction(animal.Faction); } for (var i = 0; i < 10; i++) { IntermittentMagicSprayer.ThrowMagicPuffDown(spawned.Position.ToVector3(), spawned.MapHeld); IntermittentMagicSprayer.ThrowMagicPuffUp(spawned.Position.ToVector3(), spawned.MapHeld); } //transfer hediffs from the former human back onto the original pawn FormerHumanUtilities.TransferHediffs(animal, spawned); SetHumanoidSapience(spawned, animal); FixBondRelationship(spawned, animal); FormerHumanUtilities.TransferEverything(animal, spawned); spawned.Faction?.Notify_MemberReverted(spawned, animal, spawned.Map == null, spawned.Map); ReactionsHelper.OnPawnReverted(spawned, animal, transformedPawn.reactionStatus); spawned.health.AddHediff(MorphTransformationDefOf.StabiliserHigh); //add stabilizer on reversion TransformerUtility.CleanUpHumanPawnPostTf(animal, null); animal.Destroy(); return(true); }
/// <summary> /// Tries to revert the transformed pawn instance, implementation. /// </summary> /// <param name="transformedPawn">The transformed pawn.</param> /// <returns></returns> protected override bool TryRevertImpl(TransformedPawnSingle transformedPawn) { if (transformedPawn == null) { throw new ArgumentNullException(nameof(transformedPawn)); } if (!transformedPawn.IsValid) { Log.Warning(nameof(SimpleMechaniteMutagen) + " received an invalid transformed pawn to revert"); return(false); } Pawn animal = transformedPawn.animal; Hediff tfHumanHediff = animal?.health?.hediffSet?.GetFirstHediffOfDef(TfHediffDefOf.TransformedHuman); if (tfHumanHediff == null) { return(false); } var rFaction = transformedPawn.FactionResponsible; Log.Message($"going to spawn {transformedPawn.original.Name} {transformedPawn.original.KindLabel}"); var spawned = (Pawn)GenSpawn.Spawn(transformedPawn.original, animal.PositionHeld, animal.MapHeld); if (spawned.Faction != animal.Faction && rFaction == null) //if the responsible faction is null (no one knows who did it) have the reverted pawn join that faction { spawned.SetFaction(animal.Faction); } for (var i = 0; i < 10; i++) { IntermittentMagicSprayer.ThrowMagicPuffDown(spawned.Position.ToVector3(), spawned.MapHeld); IntermittentMagicSprayer.ThrowMagicPuffUp(spawned.Position.ToVector3(), spawned.MapHeld); } FixBondRelationship(spawned, animal); PawnTransferUtilities.TransferRelations(animal, spawned, r => r != PawnRelationDefOf.Bond); //transfer whatever relations from the animal to the human pawn PawnTransferUtilities.TransferSkills(animal, spawned, PawnTransferUtilities.SkillTransferMode.Max); //keep any skills they learned as an animal //do NOT transfer the bond relationship to humans, Rimworld doesn't like that AddReversionThought(spawned, tfHumanHediff.CurStageIndex); spawned.Faction?.Notify_MemberReverted(spawned, animal, spawned.Map == null, spawned.Map); ReactionsHelper.OnPawnReverted(spawned, animal, transformedPawn.reactionStatus); spawned.health.AddHediff(MorphTransformationDefOf.StabiliserHigh); //add stabilizer on reversion animal.Destroy(); return(true); }
/// <summary> /// Tries to revert the transformed pawn instance, implementation. /// </summary> /// <param name="transformedPawn">The transformed pawn.</param> /// <returns></returns> protected override bool TryRevertImpl(MergedPawns transformedPawn) { if (!transformedPawn.IsValid) { return(false); } if (transformedPawn.originals.Count != 2) { return(false); } HediffDef hDef = HediffDef.Named(FORMER_HUMAN_HEDIFF); Pawn meld = transformedPawn.meld; Hediff formerHumanHediff = meld?.health?.hediffSet?.hediffs?.FirstOrDefault(h => h.def == hDef); if (formerHumanHediff == null) { return(false); } PawnRelationDef mergMateDef = DefDatabase <PawnRelationDef> .GetNamed("MergeMate"); PawnRelationDef mergeMateEx = DefDatabase <PawnRelationDef> .GetNamed("ExMerged"); //TODO put these in a DefOf var firstO = (Pawn)GenSpawn.Spawn(transformedPawn.originals[0], meld.PositionHeld, meld.MapHeld); var secondO = (Pawn)GenSpawn.Spawn(transformedPawn.originals[1], meld.PositionHeld, meld.MapHeld); var thoughtDef = AddRandomThought(firstO, formerHumanHediff.CurStageIndex); AddRandomThought(secondO, formerHumanHediff.CurStageIndex); for (var i = 0; i < 10; i++) { IntermittentMagicSprayer.ThrowMagicPuffDown(meld.Position.ToVector3(), meld.MapHeld); IntermittentMagicSprayer.ThrowMagicPuffUp(meld.Position.ToVector3(), meld.MapHeld); } PawnRelationDef addDef; bool relationIsMergeMate = thoughtDef == def.revertedThoughtGood; addDef = relationIsMergeMate ? mergMateDef : mergeMateEx; //first element is "WasMerged" firstO.relations.AddDirectRelation(addDef, secondO); firstO.SetFaction(Faction.OfPlayer); secondO.SetFaction(Faction.OfPlayer); //TransformerUtility.RemoveAllMutations(firstO); //TransformerUtility.RemoveAllMutations(secondO); ReactionsHelper.OnPawnReverted(firstO, meld); ReactionsHelper.OnPawnReverted(secondO, meld); CheckForBrainDamage(meld, firstO, secondO); meld.DeSpawn(); return(true); }