示例#1
0
        /// <summary>
        ///     Tries to revert the given pawn.
        /// </summary>
        /// <param name="transformedPawn">The transformed pawn.</param>
        /// <returns></returns>
        public override bool TryRevert(Pawn transformedPawn)
        {
            if (transformedPawn == null)
            {
                throw new ArgumentNullException(nameof(transformedPawn));
            }

            Tuple <TransformedPawn, TransformedStatus> status = GameComp.GetTransformedPawnContaining(transformedPawn);

            if (status != null)
            {
                if (status.Item2 != TransformedStatus.Transformed)
                {
                    return(false);
                }

                if (status.Item1 is MergedPawns merged)
                {
                    if (merged.mutagenDef != def)
                    {
                        return(false);
                    }

                    if (TryRevertImpl(merged))
                    {
                        GameComp.RemoveInstance(merged);
                        return(true);
                    }
                }

                return(false);
            }

            HediffDef formerDef = HediffDef.Named(FORMER_HUMAN_HEDIFF);

            if (transformedPawn.health.hediffSet.HasHediff(formerDef))
            {
                Hediff     formerHediff = transformedPawn.health.hediffSet.hediffs.First(h => h.def == formerDef);
                ThoughtDef thoughtDef   = null;

                for (var i = 0; i < 2; i++)
                {
                    PawnGenerationRequest request = TransformerUtility.GenerateRandomPawnFromAnimal(transformedPawn);
                    Pawn pawnTf = PawnGenerator.GeneratePawn(request);
                    pawnTf.needs.food.CurLevel = transformedPawn.needs.food.CurInstantLevel;
                    pawnTf.needs.rest.CurLevel = transformedPawn.needs.rest.CurLevel;

                    var spawnedPawn = (Pawn)GenSpawn.Spawn(pawnTf, transformedPawn.PositionHeld, transformedPawn.MapHeld);
                    spawnedPawn.apparel.DestroyAll();
                    spawnedPawn.equipment.DestroyAllEquipment();
                    for (var j = 0; j < 10; j++)
                    {
                        IntermittentMagicSprayer.ThrowMagicPuffDown(spawnedPawn.Position.ToVector3(), spawnedPawn.MapHeld);
                        IntermittentMagicSprayer.ThrowMagicPuffUp(spawnedPawn.Position.ToVector3(), spawnedPawn.MapHeld);
                    }

                    thoughtDef       = AddRandomThought(spawnedPawn, formerHediff.CurStageIndex);
                    _scratchArray[i] = spawnedPawn;
                }
                PawnRelationDef relationDef;
                bool            relationIsMergeMate = thoughtDef == def.revertedThoughtGood;
                relationDef = relationIsMergeMate ? TfRelationDefOf.MergeMate : TfRelationDefOf.ExMerged;
                _scratchArray[0].relations.AddDirectRelation(relationDef, _scratchArray[1]);

                CheckForBrainDamage(transformedPawn, _scratchArray[0], _scratchArray[1]);
                transformedPawn.Destroy();



                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>
        ///     Tries to revert the given pawn.
        /// </summary>
        /// <param name="transformedPawn">The transformed pawn.</param>
        /// <returns></returns>
        public override bool TryRevert(Pawn transformedPawn)
        {
            var pawnStatus = GameComp.GetTransformedPawnContaining(transformedPawn);

            if (pawnStatus != null)
            {
                if (pawnStatus.Value.status != TransformedStatus.Transformed)
                {
                    return(false);
                }
                if (pawnStatus.Value.pawn is TransformedPawnSingle inst)
                {
                    if (TryRevertImpl(inst))
                    {
                        GameComp.RemoveInstance(inst);
                        return(true);
                    }
                    else
                    {
                        Log.Warning($"could not revert original pawn instance {inst}");
                    }
                }
                else
                {
                    Log.Warning($"{nameof(SimpleMechaniteMutagen)} received \"{pawnStatus.Value.pawn?.GetType()?.Name ??"NULL"}\" but was expecting \"{nameof(TransformedPawnSingle)}\"");
                }
                return(false);
            }
            else
            {
                Log.Warning($"unable to find status for transformed pawn {transformedPawn.ThingID}");
            }



            PawnGenerationRequest request = TransformerUtility.GenerateRandomPawnFromAnimal(transformedPawn);



            Pawn pawnTf = PawnGenerator.GeneratePawn(request);

            pawnTf.needs.food.CurLevel = transformedPawn.needs.food.CurLevel;
            pawnTf.needs.rest.CurLevel = transformedPawn.needs.rest.CurLevel;
            Log.Message($"going to spawn {pawnTf.Name} {pawnTf.KindLabel}");
            var spawned = (Pawn)GenSpawn.Spawn(pawnTf, transformedPawn.GetCorrectPosition(), transformedPawn.GetCorrectMap());

            spawned.equipment.DestroyAllEquipment();
            spawned.apparel.DestroyAll();

            if (transformedPawn.Name is NameTriple nT)
            {
                spawned.Name = nT; //give the new random pawn the same name as the former human
            }


            for (var i = 0; i < 10; i++)
            {
                IntermittentMagicSprayer.ThrowMagicPuffDown(spawned.GetCorrectPosition().ToVector3(), spawned.GetCorrectMap());
                IntermittentMagicSprayer.ThrowMagicPuffUp(spawned.GetCorrectPosition().ToVector3(), spawned.GetCorrectMap());
            }


            AddReversionThought(spawned);



            transformedPawn.Destroy();
            return(true);
        }
示例#3
0
        /// <summary>
        ///     Tries to revert the given pawn.
        /// </summary>
        /// <param name="transformedPawn">The transformed pawn.</param>
        /// <returns></returns>
        public override bool TryRevert(Pawn transformedPawn)
        {
            if (transformedPawn == null)
            {
                throw new ArgumentNullException(nameof(transformedPawn));
            }

            var pawnStatus = GameComp.GetTransformedPawnContaining(transformedPawn);
            var sState     = transformedPawn.GetSapienceState();

            if (sState == null)
            {
                return(false);
            }
            if (pawnStatus != null)
            {
                if (pawnStatus.Value.status != TransformedStatus.Transformed)
                {
                    return(false);
                }
                if (pawnStatus.Value.pawn is MergedPawns merged)
                {
                    if (sState.StateDef != def.transformedSapienceState)
                    {
                        return(false);
                    }

                    if (TryRevertImpl(merged))
                    {
                        GameComp.RemoveInstance(merged);
                        return(true);
                    }
                }

                return(false);
            }


            if (sState.StateDef == def.transformedSapienceState)
            {
                ThoughtDef thoughtDef = null;

                for (var i = 0; i < 2; i++)
                {
                    PawnGenerationRequest request = TransformerUtility.GenerateRandomPawnFromAnimal(transformedPawn);
                    Pawn pawnTf = PawnGenerator.GeneratePawn(request);
                    pawnTf.needs.food.CurLevel = transformedPawn.needs.food.CurInstantLevel;
                    pawnTf.needs.rest.CurLevel = transformedPawn.needs.rest.CurLevel;

                    var spawnedPawn = (Pawn)GenSpawn.Spawn(pawnTf, transformedPawn.PositionHeld, transformedPawn.MapHeld);
                    spawnedPawn.apparel.DestroyAll();
                    spawnedPawn.equipment.DestroyAllEquipment();
                    for (var j = 0; j < 10; j++)
                    {
                        IntermittentMagicSprayer.ThrowMagicPuffDown(spawnedPawn.Position.ToVector3(), spawnedPawn.MapHeld);
                        IntermittentMagicSprayer.ThrowMagicPuffUp(spawnedPawn.Position.ToVector3(), spawnedPawn.MapHeld);
                    }

                    _scratchArray[i] = spawnedPawn;
                }
                PawnRelationDef relationDef;
                bool            relationIsMergeMate = thoughtDef == def.revertedThoughtGood;
                relationDef = relationIsMergeMate ? TfRelationDefOf.MergeMate : TfRelationDefOf.ExMerged;
                _scratchArray[0].relations.AddDirectRelation(relationDef, _scratchArray[1]);

                CheckForBrainDamage(transformedPawn, _scratchArray[0], _scratchArray[1]);
                transformedPawn.Destroy();



                return(true);
            }

            return(false);
        }