Exemplo n.º 1
0
        public static void StripAndDamageBelongings(this StripAndDamage SPD, Corpse corpse)
        {
            Pawn p = corpse.InnerPawn;

            if (SPD.mustStrip || corpse.NegligibleThing() || !corpse.AnythingToStrip())
            {
                return;
            }

            if (SPD.mustDamage)
            {
                if (p.inventory != null & !p.inventory.innerContainer.EnumerableNullOrEmpty())
                {
                    foreach (Thing t in p.inventory.innerContainer)
                    {
                        t.HitPoints = Math.Max(1, (int)(t.HitPoints * SPD.inventoryDamagingRatio.RandomInRange));
                    }
                }

                if (p.equipment != null && !p.equipment.Primary.DestroyedOrNull())
                {
                    p.equipment.Primary.HitPoints = Math.Max(1, (int)(p.equipment.Primary.HitPoints * SPD.primaryDamagingRatio.RandomInRange));
                }

                if (p.apparel != null && !p.apparel.WornApparel.NullOrEmpty())
                {
                    foreach (Thing t in p.apparel.WornApparel)
                    {
                        t.HitPoints = Math.Max(1, (int)(t.HitPoints * SPD.apparelsDamagingRatio.RandomInRange));
                    }
                }
            }

            corpse.Strip();
        }
Exemplo n.º 2
0
        private void doStripCorpse()
        {
            Thing  thing  = this.pawn.CurJob.targetA.Thing;
            Corpse corpse = thing as Corpse;
            bool   flag   = corpse != null && corpse.AnythingToStrip();
            bool   flag2  = flag;

            if (flag2)
            {
                corpse.Strip();
            }
        }
Exemplo n.º 3
0
        public static bool StripCorpse(this HediffComp_RandySpawnUponDeath comp, Corpse corpse)
        {
            bool DidIt = false;

            if (comp.Props.HasParentRedress && comp.Props.redressParent.strip && !corpse.Negligible())
            {
                DidIt = true;
                if (corpse.AnythingToStrip())
                {
                    corpse.Strip();
                }
            }

            return(DidIt);
        }
        private bool PawnDestroy()
        {
            if (Pawn.Dead)
            {
                Tools.Warn(Pawn.LabelShort + " is dead and will get destroyed", myDebug);
                if (Pawn.Corpse == null)
                {
                    Tools.Warn("found no corpse to work with, wont do anything", myDebug);
                    return(false);
                }
                Corpse corpse = Pawn.Corpse;

                if (Props.StripBeforeDeath && corpse.AnythingToStrip())
                {
                    corpse.Strip();
                }

                corpse.DeSpawn();
            }
            else if (Pawn.Downed)
            {
                Tools.Warn(Pawn.LabelShort + " is downed and will get destroyed", myDebug);
                if (Props.StripBeforeDeath && Pawn.AnythingToStrip())
                {
                    Pawn.Strip();
                }

                Pawn.Destroy();
            }
            else
            {
                Tools.Warn("How?", myDebug);
            }

            if (Props.DestroyWeapon && RememberWeapon != null && RememberWeapon.Spawned)
            {
                RememberWeapon.Destroy();
            }

            return(true);
        }
Exemplo n.º 5
0
        private bool PawnSaysGoodBye()
        {
            if (!IsPawn)
            {
                if (MyDebug)
                {
                    Log.Warning("Non pawn tried to say good bye as pawn, wont destroy");
                }
                return(false);
            }

            Lifespan_Utility.RemoveBadMemoriesOfDeadPawn(pawn);

            if (pawn.Dead)
            {
                if (pawn.Corpse == null)
                {
                    if (MyDebug)
                    {
                        Log.Warning("found no corpse to work with, wont do anything");
                    }
                    return(false);
                }


                Corpse corpse = pawn.Corpse;

                if (corpse.AnythingToStrip())
                {
                    corpse.Strip();
                }

                corpse.DeSpawn();
            }
            else
            {
                parent.Destroy();
            }

            return(true);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set what will cause the job to fail:
            this.FailOnDestroyedOrForbidden(CorpseIndex);
            this.FailOnBurningImmobile(CorpseIndex);
            this.FailOn(() => !(pawn is Droid));

            //Reserve the corpse
            yield return(Toils_Reserve.Reserve(CorpseIndex));

            //Go to the corpse
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            Toil toil = new Toil();

            toil.initAction = () =>
            {
                //Check if the pawn is set to strip bodies, if yes then strip it, otherwise skip this step
                Droid           droid  = (Droid)pawn;
                CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>();
                if (worker.StripBodies)
                {
                    Corpse corpse = (Corpse)TargetThingA;
                    if (corpse.AnythingToStrip())
                    {
                        corpse.Strip();
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = 300;
            toil.WithEffect(() => DefDatabase <EffecterDef> .GetNamed("Cremate"), CorpseIndex);
            toil.WithSustainer(() => DefDatabase <SoundDef> .GetNamed("Recipe_Cremate"));
            toil.AddFinishAction(() => TargetA.Thing.Destroy());
            toil.FailOnBurningImmobile(CorpseIndex);
            toil.FailOnDestroyedOrForbidden(CorpseIndex);
            toil.AddEndCondition(() => this.ticksLeftThisToil <= 0 ? JobCondition.Succeeded : JobCondition.Ongoing);
            yield return(toil);
        }
Exemplo n.º 7
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Set what will cause the job to fail:
            this.FailOnDestroyedOrForbidden(CorpseIndex);
            this.FailOnBurningImmobile(CorpseIndex);
            this.FailOn(() => !(pawn is Droid) || TargetA.Thing.TryGetComp <CompRottable>() != null && TargetA.Thing.TryGetComp <CompRottable>().Stage != RotStage.Fresh);
            Droid           droid  = pawn as Droid;
            CremationWorker worker = droid.work.specialist.GetWorker <CremationWorker>();

            //Reserve the corpse
            yield return(Toils_Reserve.Reserve(CorpseIndex));

            //Go to the corpse
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

            //If wanting to strip bodies, then strip it.
            if (worker.StripBodies)
            {
                yield return(Toils_General.Wait(80));

                //Strip the body
                Toil t = new Toil();
                t.initAction = () =>
                {
                    Corpse corpse = (Corpse)TargetA.Thing;
                    if (corpse != null && corpse.AnythingToStrip())
                    {
                        corpse.Strip();
                    }
                };
                yield return(t);
            }

            //Wait the time to do the butchering
            Toil effecterWait = Toils_General.Wait(300);

            effecterWait.WithEffect(() => ((Corpse)TargetA.Thing).innerPawn.RaceProps.isFlesh ? DefDatabase <EffecterDef> .GetNamed("ButcherFlesh") : DefDatabase <EffecterDef> .GetNamed("ButcherMechanoid"), CorpseIndex);
            effecterWait.WithSustainer(() => ((Corpse)TargetA.Thing).innerPawn.RaceProps.isFlesh ? DefDatabase <SoundDef> .GetNamed("Recipe_ButcherCorpseFlesh") : DefDatabase <SoundDef> .GetNamed("Recipe_ButcherCorpseMechanoid"));
            yield return(effecterWait);

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                List <Thing> products;
                Corpse       c = (Corpse)TargetA.Thing;
                if (c != null)
                {
                    float efficiency = Rand.Range(0.9f, 1f);
                    if (c.innerPawn.RaceProps.isFlesh)
                    {
                        products = TargetA.Thing.ButcherProducts(Find.ListerPawns.FreeColonists.RandomElement(), efficiency).ToList();
                    }
                    else
                    {
                        products = c.innerPawn.ButcherProducts(Find.ListerPawns.FreeColonists.RandomElement(), efficiency).ToList();
                    }
                    TargetA.Thing.Destroy();
                    foreach (var thing in products)
                    {
                        if (!GenPlace.TryPlaceThing(thing, pawn.Position, ThingPlaceMode.Near))
                        {
                            Log.Error(string.Concat(new object[] {
                                pawn,
                                " could not drop butcher product ",
                                thing,
                                " near ",
                                pawn.Position
                            }));
                        }
                    }
                }
                else
                {
                    Log.Error(string.Concat(new object[] {
                        pawn,
                        " tried to butcher ",
                        TargetA.Thing,
                        " at ",
                        TargetA.Thing.Position,
                        " which is not a corpse."
                    }));
                    return;
                }
            };
            yield return(toil);
        }
 public static IEnumerable <FloatMenuOption> ExtraFloatMenuOptions(this Droid droid, IntVec3 sq, IEnumerable <FloatMenuOption> options)
 {
     foreach (var thing in sq.GetThingList())
     {
         CompMannable mannable = thing.TryGetComp <CompMannable>();
         if (mannable != null && !mannable.MannedNow)
         {
             yield return(new FloatMenuOption("DroidManThing".Translate(thing.Label), delegate
             {
                 droid.jobs.StartJob(new Job(JobDefOf.ManTurret, thing), JobCondition.InterruptForced);
             }));
         }
         if (droid.equipment != null && (thing.def.IsMeleeWeapon || thing.def.IsRangedWeapon))
         {
             yield return(new FloatMenuOption("Equip".Translate(thing.Label), delegate
             {
                 CompForbiddable f = thing.TryGetComp <CompForbiddable>();
                 if (f != null && f.Forbidden)
                 {
                     f.Forbidden = false;
                 }
                 droid.jobs.StartJob(new Job(JobDefOf.Equip, thing), JobCondition.InterruptForced);
             }));
         }
         if (thing is Pawn)
         {
             Pawn p = thing as Pawn;
             if (p.RaceProps.intelligence >= Intelligence.Humanlike)
             {
                 if (droid.playerController.Drafted && p.CanBeArrested() && droid.CanReserveAndReach(p, PathEndMode.Touch, Danger.Some))
                 {
                     //Try to arrest
                     yield return(new FloatMenuOption("TryToArrest".Translate(p.LabelCap), delegate
                     {
                         Building_Bed bed = Find.ListerBuildings.AllBuildingsColonistOfClass <Building_Bed>().Where((Building_Bed b) => b.ForPrisoners && b.owner == null).FirstOrDefault();
                         if (bed != null)
                         {
                             Job job = new Job(JobDefOf.Arrest, p, bed);
                             job.maxNumToCarry = 1;
                             droid.jobs.StartJob(job, JobCondition.InterruptForced);
                         }
                         else
                         {
                             Messages.Message("DroidArrestNoBedsAvailable".Translate(), MessageSound.RejectInput);
                         }
                     }));
                 }
                 if (p.Downed)
                 {
                     if (droid.work.Contains(WorkTypeDefOf.Doctor) && droid.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                     {
                         if (!p.HostileTo(Faction.OfColony) && p.def.race.intelligence >= Intelligence.Humanlike)
                         {
                             //Rescue a downed colonist or visitor
                             yield return(new FloatMenuOption("Rescue".Translate(p.LabelCap), delegate
                             {
                                 Building_Bed freeBed = Find.ListerBuildings.AllBuildingsColonistOfClass <Building_Bed>().Where(b =>
                                                                                                                                (b.Medical ||
                                                                                                                                 b.owner == p ||
                                                                                                                                 b.owner == null) &&
                                                                                                                                b.CurOccupant == null && !b.ForPrisoners).OrderByDescending(b => (b.def.building != null) ? b.def.building.bed_medicalBonusFactor : 0f).FirstOrDefault();
                                 if (freeBed != null)
                                 {
                                     Job job = new Job(JobDefOf.Rescue, p, freeBed);
                                     job.maxNumToCarry = 1;
                                     droid.jobs.StartJob(job, JobCondition.InterruptForced);
                                 }
                                 else
                                 {
                                     Messages.Message("DroidRescueNoMedicalBedsAvailable".Translate(), MessageSound.RejectInput);
                                 }
                             }));
                         }
                         if (p.HostileTo(Faction.OfColony))
                         {
                             //Capture a downed enemy or broken colonist
                             yield return(new FloatMenuOption("Capture".Translate(p.LabelCap), delegate
                             {
                                 Building_Bed freeBed = Find.ListerBuildings.AllBuildingsColonistOfClass <Building_Bed>().Where(b =>
                                                                                                                                (b.Medical ||
                                                                                                                                 b.owner == p ||
                                                                                                                                 b.owner == null) &&
                                                                                                                                b.CurOccupant == null && b.ForPrisoners).OrderByDescending(b => (b.def.building != null) ? b.def.building.bed_medicalBonusFactor : 0f).FirstOrDefault();
                                 if (freeBed != null)
                                 {
                                     Job job = new Job(JobDefOf.Capture, p, freeBed);
                                     job.maxNumToCarry = 1;
                                     droid.jobs.StartJob(job, JobCondition.InterruptForced);
                                 }
                                 else
                                 {
                                     Messages.Message("DroidArrestNoBedsAvailable".Translate(), MessageSound.RejectInput);
                                 }
                             }));
                         }
                     }
                     if (p.AnythingToStrip())
                     {
                         yield return(new FloatMenuOption("Strip".Translate(p.LabelCap), delegate
                         {
                             droid.jobs.StartJob(new Job(JobDefOf.Strip, p), JobCondition.InterruptForced);
                         }));
                     }
                 }
             }
         }
         if (thing is Corpse)
         {
             Corpse c = thing as Corpse;
             if (c.AnythingToStrip())
             {
                 yield return(new FloatMenuOption("Strip".Translate(c.LabelCap), delegate
                 {
                     droid.jobs.StartJob(new Job(JobDefOf.Strip, c), JobCondition.InterruptForced);
                 }));
             }
         }
     }
     foreach (var o in options)
     {
         yield return(o);
     }
 }