public static void ClearBuggedConditioning(Pawn pawn)
        {
            var hediffs = pawn?.health?.hediffSet?.GetHediffs <PS_Hediff_Reconditioned>();

            if (hediffs == null || hediffs.Count() <= 0)
            {
                return;
            }

            foreach (var hediff in hediffs)
            {
                pawn.health.RemoveHediff(hediff);
            }

            pawn.needs.AddOrRemoveNeedsAsAppropriate();

            var pod = PS_PodFinder.FindMyPod(pawn);

            if (pod == null)
            {
                return;
            }

            pod.ForceUnassignPawn(pawn);
        }
Esempio n. 2
0
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            if (billDoer != null)
            {
                if (!CheckSurgeryFail(billDoer, pawn, ingredients, part, bill))
                {
                    TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[] {
                        billDoer,
                        pawn
                    });
                    PS_ConditioningHelper.TryRemoveConditioning(pawn);
                    var brainPart = pawn.RaceProps.body.AllParts.Where(x => x.def.defName == "Brain").FirstOrDefault();
                    if (brainPart == null)
                    {
                        brainPart = part;
                    }

                    pawn.health.AddHediff(HediffMaker.MakeHediff(DefDatabase <HediffDef> .GetNamed("PS_Hediff_NeuralCement"), pawn, brainPart));
                    var pod = PS_PodFinder.FindMyPod(pawn);
                    if (pod != null)
                    {
                        pod.TryUnassignPawn(pawn);
                    }
                }
                else
                {
                }
            }
        }
        // Token: 0x06000026 RID: 38 RVA: 0x000028AC File Offset: 0x00000AAC
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.Downed)
            {
                return(null);
            }

            var currentLevel = PS_ConditioningHelper.GetCurrentNeedLevel(pawn);

            if (currentLevel < 0f || currentLevel > 0.5f)
            {
                return(null);
            }

            var myPod = PS_PodFinder.FindMyPod(pawn);

            if (myPod != null && PS_PodFinder.CanGetToPod(pawn, myPod) && pawn.CanReserve(new LocalTargetInfo(myPod)) && myPod.IsUseable(pawn))
            {
                return(new Job(PS_ReconPodDefsOf.PS_RefreshConditioning, new LocalTargetInfo(myPod)));
            }
            else if (pawn.Map != null)
            {
                var condionallList = pawn.Map.listerThings.ThingsOfDef(DefDatabase <ThingDef> .GetNamed("PS_Drugs_Conditionall"));
                if (condionallList?.Any() ?? false)
                {
                    var avalible = condionallList.Where(x => IsConditionallAvalible(x, pawn)).ToList();
                    if (avalible?.Any() ?? false)
                    {
                        var closest = GetClostest(pawn, avalible);
                        if (closest != null)
                        {
                            try
                            {
                                var job = DrugAIUtility.IngestAndTakeToInventoryJob(closest, pawn, maxNumToCarry: 1);// new Job(JobDefOf.Ingest, new LocalTargetInfo(closest));
                                return(job);
                            }
                            catch (ArgumentException ex)
                            {
                                Log.Error("PS_BadDrugPolicyError".Translate());
                                throw ex;
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }
                        }
                    }
                }
            }

            return(null);
        }
        // Token: 0x060000E0 RID: 224 RVA: 0x00007C08 File Offset: 0x00005E08
        public override void NeedInterval()
        {
            var inPod = (pawn.ParentHolder != null) && (pawn.ParentHolder.GetType() == typeof(PS_Buildings_ReconPod));

            if (!inPod && !base.IsFrozen)
            {
                CurLevel -= FallPerTic * 150f;
            }

            var hediff = pawn.health.hediffSet.GetHediffs <PS_Hediff_Reconditioned>().FirstOrDefault();

            if (hediff == null)
            {
                Log.Error("PS_Needs_Reconditioning: failed to find PS_Hediff_Reconditined");
                return;
            }
            else if (hediff.ConditioningDataList == null || !hediff.ConditioningDataList.Any())
            {
                Log.Error("PS_Needs_Reconditioning: Need interval found hediff but no data. Probably from bad save file. Removeing conditioning.");
                PS_ConditioningHelper.ClearBuggedConditioning(pawn);
                return;
            }


            var map = pawn.Map;

            if (!inPod && !pawn.IsCaravanMember() && map == null)
            {
                Log.Message("PS_Needs_Reconditioning: " + pawn.LabelShort + " is not in a caravan or pod but map is null, not sure what this means but they can't find a pod");
                return;
            }

            // Try to take conditionall in in caravan
            if (CurLevel <= 0.5f && pawn.IsCaravanMember())
            {
                var caravan = pawn.GetCaravan();
                var stack   = caravan.Goods.Where(x => x.def.defName == "PS_Drugs_Conditionall").FirstOrDefault();
                if (stack != null)
                {
                    var pill = stack.SplitOff(1);
                    CurLevel += 0.25f;
                    pill.Destroy(DestroyMode.Vanish);
                }
            }


            if (CurLevel > 0)
            {
                hediff.Severity = CurLevel;
            }
            else if (pawn.InMentalState)
            {
                hediff.Severity = 0.0001f;
            }
            else // Undo Conditioning
            {
                var state = GetMentalState(pawn, hediff.ConditioningDataList);
                if (!pawn.mindState.mentalStateHandler.TryStartMentalState(state, reason: "PS_ReconWoreOffMessage".Translate(), forceWake: true))
                {
                    Log.Error("PS_Need_Recon: Failed to give mental state " + state.defName);
                }

                PS_PodFinder.FindMyPod(pawn).TryUnassignPawn(pawn);
                PS_ConditioningHelper.UndoAllConditioning(pawn);
                Messages.Message(string.Format("PS_Messages_CompletedDeconditioning".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.TaskCompletion);
                hediff.Severity = 0;
            }
        }
Esempio n. 5
0
        // Token: 0x06002514 RID: 9492 RVA: 0x00116FA0 File Offset: 0x001153A0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn pawn)
        {
            foreach (FloatMenuOption o in base.GetFloatMenuOptions(pawn))
            {
                if (o.Label != "EnterCryptosleepCasket".Translate())
                {
                    yield return(o);
                }
            }
            if (this.CheatMod)
            {
                JobDef jobDef    = PS_ReconPodDefsOf.PS_DoConditioning;
                string jobStr    = "PS_PodOption_CheatMode".Translate();
                Action jobAction = delegate()
                {
                    Job job = new Job(jobDef, this);
                    pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                };
                yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(jobStr, jobAction, MenuOptionPriority.Default, null, null, 0f, null, null), pawn, this, "ReservedBy"));

                yield break;
            }

            if (!this.TryGetComp <CompPowerTrader>().PowerOn)
            {
                yield return(new FloatMenuOption("CannotUseNoPower".Translate(), null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            else if (PS_ConditioningHelper.IsCemented(pawn))
            {
                yield return(new FloatMenuOption(string.Format("PS_CementCantUsePod".Translate(), pawn.LabelShort), null, MenuOptionPriority.Default, null, null, 0f, null, null));

                yield break;
            }
            else if (this.PodOwner != null && pawn != this.PodOwner)
            {
                yield return(new FloatMenuOption("PS_OwnedBy".Translate() + this.PodOwner.LabelShort, null, MenuOptionPriority.Default, null, null, 0f, null, null));
            }
            else if (this.innerContainer.Count == 0)
            {
                if (PS_ConditioningHelper.IsReconditioned(pawn) && PS_PodFinder.FindMyPod(pawn) != this && PS_PodFinder.FindMyPod(pawn) != null)
                {
                    yield return(new FloatMenuOption(string.Format("PS_NotOwnedBy".Translate(), pawn.LabelShort), null, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                else if (PS_ConditioningHelper.IsReconditioned(pawn) && PS_PodFinder.FindMyPod(pawn) == null && this.PodOwner == null)
                {
                    JobDef jobDef    = PS_ReconPodDefsOf.PS_RefreshConditioning;
                    string jobStr    = string.Format("PS_PodOption_ClaimPod".Translate(), pawn.LabelShort);
                    Action jobAction = delegate()
                    {
                        this.TryAssignPawn(pawn);
                    };
                    yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(jobStr, jobAction, MenuOptionPriority.Default, null, null, 0f, null, null), pawn, this, "ReservedBy"));
                }
                else if (pawn.CanReach(this, PathEndMode.InteractionCell, Danger.Deadly, false, TraverseMode.ByPawn))
                {
                    if (PS_ConditioningHelper.IsReconditioned(pawn))
                    {
                        JobDef jobDef    = PS_ReconPodDefsOf.PS_RefreshConditioning;
                        string jobStr    = "PS_PodOption_RefreshConditioning".Translate();
                        Action jobAction = delegate()
                        {
                            Job job = new Job(jobDef, this);
                            pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                        };
                        yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(jobStr, jobAction, MenuOptionPriority.Default, null, null, 0f, null, null), pawn, this, "ReservedBy"));

                        JobDef jobDef2    = PS_ReconPodDefsOf.PS_ManageConditioning;
                        string jobStr2    = "PS_PodOption_Decondition".Translate();
                        Action jobAction2 = delegate()
                        {
                            Job job2 = new Job(jobDef2, this);
                            pawn.jobs.TryTakeOrderedJob(job2, JobTag.Misc);
                        };
                        yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(jobStr2, jobAction2, MenuOptionPriority.Default, null, null, 0f, null, null), pawn, this, "ReservedBy"));
                    }
                    else
                    {
                        JobDef jobDef    = PS_ReconPodDefsOf.PS_DoConditioning;
                        string jobStr    = "PS_PodOption_Condition".Translate();
                        Action jobAction = delegate()
                        {
                            Job job = new Job(jobDef, this);
                            pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                        };
                        yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(jobStr, jobAction, MenuOptionPriority.Default, null, null, 0f, null, null), pawn, this, "ReservedBy"));
                    }
                }
            }
            yield break;
        }