コード例 #1
0
        /// <summary>
        /// called when this instance impacts the specified thing.
        /// </summary>
        /// <param name="hitThing">The hit thing.</param>
        protected override void Impact(Thing hitThing)
        {
            base.Impact(hitThing);
            Pawn hitPawn;

            if (Def != null && hitThing != null && hitThing is Pawn)
            {
                hitPawn = (Pawn)hitThing; // Already checked above.

                if (!Def.CanAddHediffToPawn(hitPawn))
                {
                    return;                      //if the hediff can't be added to the hit pawn just abort
                }
                float rand = Rand.Value;         // This is a random percentage between 0% and 100%
                if (rand <= Def.AddHediffChance) // If the percentage falls under the chance, success!
                {
                    //This checks to see if the character has a heal differential, or hediff on them already.
                    Hediff etherOnPawn    = hitPawn.health?.hediffSet?.GetFirstHediffOfDef(Def.HediffToAdd);
                    var    randomSeverity = 1f;
                    if (etherOnPawn == null)
                    {
                        //These three lines create a new health differential or Hediff,
                        //put them on the character, and increase its severity by a random amount.
                        Hediff hediff = HediffMaker.MakeHediff(Def.HediffToAdd, hitPawn);
                        hediff.Severity = randomSeverity;
                        hitPawn.health?.AddHediff(hediff);
                        IntermittentMagicSprayer.ThrowMagicPuffDown(hitPawn.Position.ToVector3(), Map);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Tries to apply this hediff giver
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="mutagen">The mutagen.</param>
        public void TryApply(Pawn pawn, Hediff cause, MutagenDef mutagen)
        {
            MutationDef mut   = GetRandomMutation(pawn); //grab a random mutation
            int         mPart = mut.parts?.Count ?? 0;

            int maxCount;

            if (mPart == 0)
            {
                maxCount = 0;
            }
            else
            {
                maxCount = GetMaxCount(pawn, mut.parts);
            }


            if (MutationUtilities.AddMutation(pawn, mut, maxCount))
            {
                IntermittentMagicSprayer.ThrowMagicPuffDown(pawn.Position.ToVector3(), pawn.MapHeld);

                var comp = cause.TryGetComp <HediffComp_Single>();
                if (comp != null)
                {
                    comp.stacks--;
                    if (comp.stacks <= 0)
                    {
                        pawn.health.RemoveHediff(cause);
                    }
                }
            }
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        /// <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);
        }
コード例 #5
0
        /// <summary>Applies the hediff.</summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="map">The map.</param>
        /// <param name="hediff">The hediff.</param>
        /// <param name="chance">The chance.</param>
        public static void ApplyHediff(Pawn pawn, Map map, HediffDef hediff, float chance)
        {
            var rand = Rand.Value;

            if (rand <= chance)
            {
                var etherOnPawn    = pawn.health?.hediffSet?.GetFirstHediffOfDef(hediff);
                var randomSeverity = 1f;
                if (etherOnPawn != null)
                {
                    etherOnPawn.Severity += randomSeverity;
                }
                else
                {
                    Hediff hediffOnPawn = HediffMaker.MakeHediff(hediff, pawn);
                    hediffOnPawn.Severity = randomSeverity;
                    pawn.health?.AddHediff(hediffOnPawn);
                    IntermittentMagicSprayer.ThrowMagicPuffDown(pawn.Position.ToVector3(), map);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// called when this instance impacts the specified thing.
        /// </summary>
        /// <param name="hitThing">The hit thing.</param>
        protected override void Impact(Thing hitThing)
        {
            base.Impact(hitThing);
            Pawn hitPawn;

            if (Def != null && hitThing != null && hitThing is Pawn)
            {
                hitPawn = (Pawn)hitThing; // Already checked above.

                if (!Def.CanAddHediffToPawn(hitPawn))
                {
                    return;                      //if the hediff can't be added to the hit pawn just abort
                }
                float rand = Rand.Value;         // This is a random percentage between 0% and 100%
                if (rand <= Def.AddHediffChance) // If the percentage falls under the chance, success!
                {
                    //This checks to see if the character has a heal differential, or hediff on them already.
                    Hediff etherOnPawn = hitPawn.health?.hediffSet?.GetFirstHediffOfDef(Def.HediffToAdd);

                    if (etherOnPawn == null)
                    {
                        //These three lines create a new health differential or Hediff,
                        //put them on the character, and increase its severity by a random amount.
                        Hediff hediff = HediffMaker.MakeHediff(Def.HediffToAdd, hitPawn);
                        hitPawn.health?.AddHediff(hediff);

                        //this should be an interface
                        var syringeHediff = hediff as SyringeRifleTf;

                        //hacky, want to figure out a better way to find the weapon that will allow turrets as well
                        var weapon = (launcher as Pawn)?.equipment?.Primary;

                        syringeHediff?.Initialize(weapon);

                        IntermittentMagicSprayer.ThrowMagicPuffDown(hitPawn.Position.ToVector3(), Map);
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        ///     Tries to apply this hediff giver
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="mutagen">The mutagen.</param>
        public void TryApply(Pawn pawn, Hediff cause, [NotNull] MutagenDef mutagen)
        {
            if (mutagen == null)
            {
                throw new ArgumentNullException(nameof(mutagen));
            }
            var mut = Mutations[Rand.Range(0, Mutations.Count)]; //grab a random mutation

            if (MutationUtilities.AddMutation(pawn, mut))
            {
                IntermittentMagicSprayer.ThrowMagicPuffDown(pawn.Position.ToVector3(), pawn.MapHeld);
                if (cause.def.HasComp(typeof(HediffComp_Single)))
                {
                    pawn.health.RemoveHediff(cause);
                }
                mutagen.TryApplyAspects(pawn);
                if (mut.mutationTale != null)
                {
                    TaleRecorder.RecordTale(mut.mutationTale, pawn);
                }
            }
        }
コード例 #8
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);
        }
コード例 #9
0
        /// <summary>
        ///     preform the requested transform
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        protected override TransformedPawnSingle TransformImpl(TransformationRequest request)
        {
            Pawn original = request.originals[0];

            if (request.addMutationToOriginal)
            {
                TryAddMutationsToPawn(original, request.cause, request.outputDef);
            }

            var     reactionStatus = original.GetFormerHumanReactionStatus();
            float   newAge         = TransformerUtility.ConvertAge(original, request.outputDef.race.race);
            Faction faction;

            faction = GetFaction(request, original);

            Gender newGender =
                TransformerUtility.GetTransformedGender(original, request.forcedGender, request.forcedGenderChance);


            var pRequest = FormerHumanUtilities.CreateSapientAnimalRequest(request.outputDef, original, faction, fixedGender: newGender);



            Pawn animalToSpawn = PawnGenerator.GeneratePawn(pRequest); //make the temp pawn



            animalToSpawn.needs.food.CurLevel =
                original.needs.food.CurLevel;   // Copies the original pawn's food need to the animal's.
            animalToSpawn.needs.rest.CurLevel =
                original.needs.rest.CurLevel;   // Copies the original pawn's rest need to the animal's.
            animalToSpawn.Name = original.Name; // Copies the original pawn's name to the animal's.
            float sapienceLevel = request.forcedSapienceLevel ?? GetSapienceLevel(original, animalToSpawn);

            if (request.forcedFaction == null && original.Faction != faction && original.Faction != animalToSpawn.Faction && FormerHumanUtilities.GetQuantizedSapienceLevel(sapienceLevel) <= SapienceLevel.MostlySapient)
            {
                //set the faction to the original's if mostly sapient or above
                animalToSpawn.SetFaction(original.Faction);
            }


            GiveTransformedPawnSapienceState(animalToSpawn, sapienceLevel);

            FormerHumanUtilities.InitializeTransformedPawn(original, animalToSpawn, sapienceLevel); //use a normal distribution?

            Pawn spawnedAnimal = SpawnAnimal(original, animalToSpawn);                              // Spawns the animal into the map.

            ReactionsHelper.OnPawnTransforms(original, animalToSpawn, reactionStatus);              //this needs to happen before MakeSapientAnimal because that removes relations

            var rFaction = request.factionResponsible ?? GetFactionResponsible(original);
            var inst     = new TransformedPawnSingle
            {
                original           = original,
                animal             = spawnedAnimal,
                factionResponsible = rFaction,
                reactionStatus     = reactionStatus
            };


            if (original.Spawned)
            {
                for (var i = 0; i < 10; i++) // Create a cloud of magic.
                {
                    IntermittentMagicSprayer.ThrowMagicPuffDown(spawnedAnimal.Position.ToVector3(), spawnedAnimal.MapHeld);
                    IntermittentMagicSprayer.ThrowMagicPuffUp(spawnedAnimal.Position.ToVector3(), spawnedAnimal.MapHeld);
                }
            }

            if (request.tale != null) // If a tale was provided, push it to the tale recorder.
            {
                TaleRecorder.RecordTale(request.tale, original, animalToSpawn);
            }

            Faction oFaction = original.FactionOrExtraHomeFaction;
            Map     oMap     = original.Map;


            //apply any other post tf effects
            ApplyPostTfEffects(original, animalToSpawn, request);

            TransformerUtility
            .CleanUpHumanPawnPostTf(original, request.cause);    //now clean up the original pawn (remove apparel, drop'em, ect)

            //notify the faction that their member has been transformed
            oFaction?.Notify_MemberTransformed(original, animalToSpawn, oMap == null, oMap);

            if (!request.noLetter && reactionStatus == FormerHumanReactionStatus.Colonist || reactionStatus == FormerHumanReactionStatus.Prisoner) //only send the letter for colonists and prisoners
            {
                SendLetter(request, original, spawnedAnimal);
            }

            if (original.Spawned)
            {
                original.DeSpawn(); // Remove the original pawn from the current map.
            }
            DebugLogUtils.Assert(!PrisonBreakUtility.CanParticipateInPrisonBreak(original),
                                 $"{original.Name} has been cleaned up and de-spawned but can still participate in prison breaks");


            return(inst);
        }
コード例 #10
0
        /// <summary>
        /// preform the requested transform
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        protected override MergedPawns TransformImpl(TransformationRequest request)
        {
            Pawn  firstPawn  = request.originals[0];
            Pawn  secondPawn = request.originals[1];
            float averageAge = firstPawn.ageTracker.AgeBiologicalYearsFloat
                               + secondPawn.ageTracker.AgeBiologicalYearsFloat;

            averageAge /= 2;


            float newAge = averageAge * request.outputDef.race.race.lifeExpectancy / firstPawn.RaceProps.lifeExpectancy;

            Faction faction = request.forcedFaction ?? Faction.OfPlayer;

            var pRequest = FormerHumanUtilities.CreateMergedAnimalRequest(request.outputDef, request.originals, faction);



            Pawn meldToSpawn = PawnGenerator.GeneratePawn(pRequest);

            HediffDef hediffToAdd = HediffDef.Named(FORMER_HUMAN_HEDIFF); //make sure hediff is added before spawning meld

            //make them count as former humans
            var tracker = meldToSpawn.GetFormerHumanTracker();

            if (tracker == null)
            {
                Log.Error($"{meldToSpawn.def.defName} is a meld but does not have a former human tracker!");
            }
            else
            {
                tracker.MakeFormerHuman(1);
            }



            Hediff hediff = HediffMaker.MakeHediff(hediffToAdd, meldToSpawn);

            hediff.Severity = Rand.Range(request.minSeverity, request.maxSeverity);
            meldToSpawn.health.AddHediff(hediff);

            Pawn_NeedsTracker needs = meldToSpawn.needs;

            needs.food.CurLevel = firstPawn.needs.food.CurLevel;
            needs.rest.CurLevel = firstPawn.needs.rest.CurLevel;
            meldToSpawn.training.SetWantedRecursive(TrainableDefOf.Obedience, true);
            meldToSpawn.training.Train(TrainableDefOf.Obedience, null, true);
            meldToSpawn.Name = firstPawn.Name;
            var meld = (Pawn)GenSpawn.Spawn(meldToSpawn, firstPawn.PositionHeld, firstPawn.MapHeld);

            for (var i = 0; i < 10; i++)
            {
                IntermittentMagicSprayer.ThrowMagicPuffDown(meld.Position.ToVector3(), meld.MapHeld);
                IntermittentMagicSprayer.ThrowMagicPuffUp(meld.Position.ToVector3(), meld.MapHeld);
            }

            meld.SetFaction(Faction.OfPlayer);

            ReactionsHelper.OnPawnsMerged(firstPawn, firstPawn.IsPrisoner, secondPawn, secondPawn.IsPrisoner, meld);


            TransformerUtility.CleanUpHumanPawnPostTf(firstPawn, null);
            TransformerUtility.CleanUpHumanPawnPostTf(secondPawn, null);

            var inst = new MergedPawns
            {
                originals          = request.originals.ToList(), //we want to make a copy here
                meld               = meld,
                mutagenDef         = def,
                factionResponsible = Faction.OfPlayer
            };

            return(inst);
        }
コード例 #11
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);
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
ファイル: MergeMutagen.cs プロジェクト: ying636/Pawnmorpher
        /// <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);
        }