Esempio n. 1
0
        public void DoCheatModeChange()
        {
            var conData = new PS_Conditioning_Data
            {
                AlterType            = ChangeType,
                OriginalTraitDefName = ToRemove?.def.defName,
                AddedTraitDefName    = ToAdd?.def.defName,
                OriginalDegree       = ToRemove?.Degree ?? 0,
                AddedDegree          = ToAdd?.Degree ?? 0
            };

            PS_ConditioningHelper.DoTraitChange(Pawn, conData);
            if (conData.AlterType == TraitAlterType.Added || conData.AlterType == TraitAlterType.Altered)
            {
                CurrentTraits.Add(ToAdd);
            }

            if (conData.AlterType == TraitAlterType.Removed || conData.AlterType == TraitAlterType.Altered)
            {
                CurrentTraits.Remove(ToRemove);
            }

            UpdateAddableTraits(CurrentTraits);
            UpdateCurrentTraits(CurrentTraits);
        }
Esempio n. 2
0
        public string GetDays()
        {
            if (CheatMode)
            {
                return("CM");
            }



            if (!this.FixingBotch && !this.RemoveingConditioning && this.ChangeType == TraitAlterType.UNSET)
            {
                return("NA");
            }

            if (this.FixingBotch)
            {
                return(DayToSafeTime(1f));
            }

            if (this.RemoveingConditioning)
            {
                return(DayToSafeTime(1f));
            }

            var tempConCount = this.StartingConditioning?.Count() ?? 0;

            if (this.RemoveingConditioning)
            {
                tempConCount--;
            }

            var days = PS_ConditioningHelper.DaysToCondition(tempConCount);

            return(DayToSafeTime(days));
        }
Esempio n. 3
0
        public string GetFailChance()
        {
            if (CheatMode)
            {
                return("CM");
            }

            if (!FixingBotch && !RemoveingConditioning && ChangeType == TraitAlterType.UNSET)
            {
                return("NA");
            }

            if (FixingBotch)
            {
                return("100");
            }

            if (RemoveingConditioning)
            {
                return("100");
            }

            var startConCount = StartingConditioning?.Count() ?? 0;

            return((PS_ConditioningHelper.GetSucessChance(startConCount) * 100f).ToString("0"));
        }
Esempio n. 4
0
        public string GetRefreshRate()
        {
            if (CheatMode)
            {
                return("CM");
            }

            if (this.FixingBotch || (!this.RemoveingConditioning && this.ChangeType == TraitAlterType.UNSET))
            {
                var days = PS_ConditioningHelper.GetRefreshPerDay(this.StartingConditioning?.Count() ?? 0);
                return(DayToSafeTime(days));
            }
            else
            {
                var tempConCount = this.StartingConditioning?.Count() ?? 0;
                if (this.RemoveingConditioning)
                {
                    tempConCount--;
                }
                else if (this.ChangeType != TraitAlterType.UNSET)
                {
                    tempConCount++;
                }

                var days = PS_ConditioningHelper.GetRefreshPerDay(tempConCount);
                return(DayToSafeTime(days));
            }
        }
Esempio n. 5
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
                {
                }
            }
        }
        public static MentalStateDef GetMentalState(Pawn pawn, List <PS_Conditioning_Data> conData)
        {
            // Check if removed trait has break
            var breaksFromRemoved = new List <MentalStateDef>();

            foreach (var data in conData)
            {
                if (data.AlterType == TraitAlterType.Removed)
                {
                    var orgTrait = new Trait(DefDatabase <TraitDef> .GetNamed(data.OriginalTraitDefName));
                    var degree   = PS_TraitHelper.GetDegreeDate(orgTrait);
                    if (degree != null)
                    {
                        var count = degree.theOnlyAllowedMentalBreaks?.Count ?? 0;
                        if (count > 0)
                        {
                            breaksFromRemoved.AddRange(degree.theOnlyAllowedMentalBreaks.Select(x => x.mentalState));
                        }
                    }
                }
            }
            if (breaksFromRemoved.Count() > 0)
            {
                return(breaksFromRemoved[Rand.Range(0, breaksFromRemoved.Count() - 1)]);
            }


            // Check if added trait disallows break
            var breaksFromAdded = new List <MentalStateDef>();

            foreach (var data in conData)
            {
                if (data.AlterType == TraitAlterType.Added)
                {
                    var addTrait = new Trait(DefDatabase <TraitDef> .GetNamed(data.AddedTraitDefName));
                    var degree   = PS_TraitHelper.GetDegreeDate(addTrait);
                    if (degree != null)
                    {
                        var count = degree.disallowedMentalStates?.Count ?? 0;
                        if (count > 0)
                        {
                            breaksFromAdded.AddRange(degree.disallowedMentalStates);
                        }
                    }
                }
            }
            if (breaksFromAdded.Count() > 0)
            {
                return(breaksFromAdded[Rand.Range(0, breaksFromAdded.Count() - 1)]);
            }

            // Otherwise get all allowable mental traits
            var naturalTraits = PS_ConditioningHelper.GetNaturalTraits(pawn);
            var degrees       = naturalTraits.SelectMany(x => x.def.degreeDatas).Distinct();
            var forbiden      = degrees.Where(x => (x.disallowedMentalStates?.Count ?? 0) > 0).SelectMany(x => x.disallowedMentalStates).ToList();
            var allowed       = DefDatabase <MentalStateDef> .AllDefs.Where(x => !forbiden.Contains(x) && x.colonistsOnly && x.Worker.StateCanOccur(pawn)).ToList();

            return(allowed[Rand.Range(0, allowed.Count - 1)]);
        }
 public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe)
 {
     if (PS_ConditioningHelper.IsReconditioned(pawn))
     {
         yield return(pawn.health.hediffSet.GetHediffs <PS_Hediff_Reconditioned>().First().Part);
     }
     yield break;
 }
        public override void Tick()
        {
            base.Tick();

            if (PodOwner != null && PodOwner.Dead)
            {
                ForceEndJobState();
                PodOwner = null;
            }

            if (PodOwner != null && JobState == PS_Conditioning_JobState.Waiting && !PS_ConditioningHelper.IsReconditioned(PodOwner))
            {
                ForceEndJobState();
                PodOwner = null;
            }

            if (JobState == PS_Conditioning_JobState.Waiting) // Do nothing if waiting
            {
                return;
            }

            if (!this.TryGetComp <CompPowerTrader>().PowerOn&& HasAnyContents) // Boot pawn if lose power
            {
                ForceEndJobState();
                EjectContents();
                return;
            }

            var pawn = (Pawn)innerContainer.FirstOrDefault();

            if (pawn != null)
            {
                ResetNeeds(pawn);
            }


            if (ProgressBarEffector != null)
            {
                MoteProgressBar mote = ((SubEffecter_ProgressBar)ProgressBarEffector?.children[0]).mote;
                if (mote != null)
                {
                    mote.progress = Mathf.Clamp01(1f - (CurrentTicksLeft / CurrentMaxTicks));
                    mote.offsetZ  = -0.5f;
                }
            }

            if (JobState != PS_Conditioning_JobState.Waiting)
            {
                CurrentTicksLeft--;
                if (CurrentTicksLeft <= 0)
                {
                    FinishConditioning();
                }
            }
        }
Esempio n. 9
0
        //public override IEnumerable<BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe)
        //{
        //    if (PS_ConditioningHelper.IsReconditioned(pawn))
        //    {
        //        yield return pawn.RaceProps.body.corePart;
        //    }
        //    else
        //        yield break;
        //}

        //public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List<Thing> ingredients, Bill bill)
        //{
        //    if (!PS_ConditioningHelper.IsReconditioned(pawn))
        //        return;

        //    if (!PS_ConditioningHelper.SetCurrentNeedLevel(pawn, 1f))
        //        Log.Error("PS_Recipes_AdministerConditionall: Failed to set need level for unknown reason.");
        //}

        protected override void DoIngestionOutcomeSpecial(Pawn pawn, Thing ingested)
        {
            if (!PS_ConditioningHelper.IsReconditioned(pawn))
            {
                return;
            }

            if (!PS_ConditioningHelper.SetCurrentNeedLevel(pawn, PS_ConditioningHelper.GetCurrentNeedLevel(pawn) + 0.25f))
            {
                Log.Error("PS_Recipes_AdministerConditionall: Failed to set need level for unknown reason.");
            }
        }
        // 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);
        }
Esempio n. 11
0
        private bool RoleForSucessOrHandleFail(Pawn pawn)
        {
            var conCount      = PS_ConditioningHelper.GetConditioningDataFromHediff(pawn, false)?.Count() ?? 0;
            var successChance = PS_ConditioningHelper.GetSucessChance(conCount);
            var roll          = Rand.Range(0f, 1f);

            Log.Message(string.Format("PS_Buildings_ReconPod: Rolled for sucess Chance: {0}, Roll: {1}", successChance, roll));

            //roll = 1.00f;

            // Sucess
            if (roll < successChance)
            {
                return(true);
            }

            roll = Rand.Range(0f, 1f);
            // Fail with no coniquence
            if (roll > 0.3f)
            {
                pawn.needs.mood.thoughts.memories.TryGainMemory(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_FailedConditioned"));
                Messages.Message(string.Format("PS_Messages_FailConditioning".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.NegativeEvent);
            }
            // Botched
            else if (roll > 0.01f)
            {
                var bothedcondata = new PS_Conditioning_Data
                {
                    AlterType         = TraitAlterType.Added,
                    AddedTraitDefName = "PS_Trait_BotchedConditioning",
                    AddedDegree       = -1
                };
                pawn.needs.mood.thoughts.memories.TryGainMemory(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_BotchedConditioned"));
                Messages.Message(string.Format("PS_Messages_BotchedConditioning".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.ThreatBig);
                PS_ConditioningHelper.DoTraitChange(pawn, bothedcondata);
            }
            // Lucky Botched
            else
            {
                var condata = new PS_Conditioning_Data
                {
                    AlterType         = TraitAlterType.Added,
                    AddedTraitDefName = "PS_Trait_BotchedConditioning",
                    AddedDegree       = 1
                };
                pawn.needs.mood.thoughts.memories.TryGainMemory(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_LuckyConditioned"));
                Messages.Message(string.Format("PS_Messages_LuckyConditioning".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.ThreatBig);
                PS_ConditioningHelper.DoTraitChange(pawn, condata);
            }
            return(false);
        }
Esempio n. 12
0
        public static float ConditioningLevel(this Pawn pawn)
        {
            if (!PS_ConditioningHelper.IsReconditioned(pawn))
            {
                return(-1f);
            }

            var need = pawn.needs.TryGetNeed <PS_Needs_Reconditioning>();

            if (need == null)
            {
                Log.Error("PS_Extensions: Tried to GetCurrentConditioningLevel but failed to find need");
                return(-1f);
            }
            return(need.CurLevel);
        }
        // Token: 0x06000025 RID: 37 RVA: 0x00002860 File Offset: 0x00000A60
        public override float GetPriority(Pawn pawn)
        {
            var currentLevel = PS_ConditioningHelper.GetCurrentNeedLevel(pawn);

            if (currentLevel < 0)
            {
                return(0f);
            }

            if (currentLevel < 0.5f)
            {
                return(11.5f);
            }
            else
            {
                return(0f);
            }
        }
        //public bool TryStartConditioning(Pawn pawn, PS_Conditioning_JobState ConditionType)
        //{
        //    if(this.JobState != PS_Conditioning_JobState.Waiting || !this.IsUseable(pawn))
        //    {
        //        return false;
        //    }
        //    else
        //    {
        //        if(this.TryAcceptThing(pawn))
        //        {
        //            this.JobState = ConditionType;
        //            this.CurrentTicksLeft = this.TotalTicksPerAction;
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        // Token: 0x060024DC RID: 9436 RVA: 0x00118724 File Offset: 0x00116B24
        public override string GetInspectString()
        {
            var    flag = ParentHolder != null && !(ParentHolder is Map);
            string result;

            if (flag)
            {
                result = base.GetInspectString();
            }
            else
            {
                var stringBuilder = new StringBuilder(base.GetInspectString());
                stringBuilder.AppendLine();
                if (PodOwner == null) //string.IsNullOrEmpty(this.PodOwnerId))
                {
                    stringBuilder.AppendLine("Owner".Translate() + ": " + "Nobody".Translate());
                }
                else
                {
                    stringBuilder.AppendLine("Owner".Translate() + ": " + PodOwner.Label);
                }

                if (JobState == PS_Conditioning_JobState.Waiting)
                {
                    stringBuilder.AppendLine("PS_Status".Translate() + ": " + GetStatusString());
                }
                else
                {
                    var completion = (1f - (CurrentTicksLeft / CurrentMaxTicks)) * 100f;
                    stringBuilder.AppendLine("PS_Status".Translate() + ": " + GetStatusString() + " (" + completion.ToString("0.00") + "%)");
                }

                if (Prefs.DevMode && PodOwner != null)
                {
                    stringBuilder.AppendLine("(Dev) Pawn need: " + PS_ConditioningHelper.GetCurrentNeedLevel(PodOwner));
                }

                result = stringBuilder.ToString().TrimEndNewlines();
            }
            return(result);
        }
Esempio n. 15
0
        public void StartReconditioning(Pawn pawn, PS_Conditioning_Data conData)
        {
            if (this.PodOwner != null && this.PodOwner != pawn)//!string.IsNullOrEmpty(this.PodOwnerId) && pawn.ThingID != this.PodOwnerId)
            {
                Log.Error("PS_Buildings_ReconPod: Tried to start conditioning on a pawn that was not the owner");
                return;
            }
            this.SaveNeeds(pawn.needs.AllNeeds);
            pawn.DeSpawn(DestroyMode.Vanish);
            if (this.TryAcceptThing(pawn))
            {
                this.ConditioningData = conData;
                this.CurrentMaxTicks  = PS_ConditioningHelper.DaysToCondition(pawn) * this.TicksPerDay;
                this.CurrentTicksLeft = CurrentMaxTicks;
                this.JobState         = PS_Conditioning_JobState.Reconditioning;
                this.TryAssignPawn(pawn);

                EffecterDef progressBar = EffecterDefOf.ProgressBar;
                ProgressBarEffector = progressBar.Spawn();
                var target = new TargetInfo(this);
                ProgressBarEffector.EffectTick(target, TargetInfo.Invalid);
            }
        }
Esempio n. 16
0
        public void SetPawnAndPod(Pawn pawn, PS_Buildings_ReconPod Pod)
        {
            this.ToolTipFunc = (t => t);
            this.Pod         = Pod;
            this.Pawn        = pawn;

            this.StartTraits   = pawn.story.traits.allTraits;
            this.CurrentTraits = new List <Trait>();
            foreach (var t in StartTraits)
            {
                CurrentTraits.Add(t);
            }

            this.StartingConditioning = new List <PS_Conditioning_Data>();
            if (PS_ConditioningHelper.IsReconditioned(pawn))
            {
                var condata = PS_ConditioningHelper.GetConditioningDataFromHediff(pawn);
                this.StartingConditioning = condata;
            }


            this.CheatMode = Pod.CheatMod;
        }
Esempio n. 17
0
        public override IEnumerable <Gizmo> GetGizmos()
        {
            foreach (Gizmo g in base.GetGizmos())
            {
                yield return(g);
            }
            //if (this.def.building.bed_humanlike && base.Faction == Faction.OfPlayer)
            //{
            //    Command_Toggle pris = new Command_Toggle();

            //    if (this.innerContainer != null)
            //    {
            //        Command_Action eject = new Command_Action();
            //        eject.action = new Action(this.EjectContents);
            //        eject.defaultLabel = "CommandPodEject".Translate();
            //        eject.defaultDesc = "CommandPodEjectDesc".Translate();
            //        if (this.innerContainer.Count == 0)
            //        {
            //            eject.Disable("CommandPodEjectFailEmpty".Translate());
            //        }
            //        eject.hotKey = KeyBindingDefOf.Misc1;
            //        eject.icon = ContentFinder<Texture2D>.Get("UI/Commands/PodEject", true);
            //        yield return eject;
            //    }
            //}
            if (Prefs.DevMode)
            {
                var toggleCheat = new Command_Toggle();
                toggleCheat.defaultLabel = "Cheat Mode";
                toggleCheat.defaultDesc  = "PS_CheatModeString".Translate();
                toggleCheat.icon         = ContentFinder <Texture2D> .Get("UI/CheatMode", true);

                toggleCheat.isActive     = (() => this.CheatMod);
                toggleCheat.toggleAction = delegate(){ this.CheatMod = !this.CheatMod; };
                yield return(toggleCheat);

                if (this.JobState != PS_Conditioning_JobState.Waiting)
                {
                    yield return new Command_Action
                           {
                               defaultLabel = "Dev: Insta Complete",
                               action       = delegate()
                               {
                                   if (this.JobState != PS_Conditioning_JobState.Waiting)
                                   {
                                       this.CurrentTicksLeft = 0;
                                   }
                               },
                               icon = ContentFinder <Texture2D> .Get("UI/DevInstComplete", true)
                           }
                }
                ;
                if (this.PodOwner != null)
                {
                    yield return(new Command_Action
                    {
                        defaultLabel = "Dev: Down Pawn Need",
                        action = delegate()
                        {
                            PS_ConditioningHelper.SetCurrentNeedLevel(this.PodOwner, this.PodOwner.ConditioningLevel() - 0.1f);
                        },
                        icon = ContentFinder <Texture2D> .Get("UI/DevDown", true)
                    });

                    yield return(new Command_Action
                    {
                        defaultLabel = "Dev: Fill Pawn Need",
                        action = delegate()
                        {
                            PS_ConditioningHelper.SetCurrentNeedLevel(this.PodOwner, 1f);
                        },
                        icon = ContentFinder <Texture2D> .Get("UI/DevFull", true)
                    });

                    yield return(new Command_Action
                    {
                        defaultLabel = "Dev: Half Pawn Need",
                        action = delegate()
                        {
                            PS_ConditioningHelper.SetCurrentNeedLevel(this.PodOwner, 0.5f);
                        },
                        icon = ContentFinder <Texture2D> .Get("UI/DevHalf", true)
                    });
                }
            }
            yield break;
        }
Esempio n. 18
0
        private void FinishConditioning()
        {
            var pawn = (Pawn)this.innerContainer.FirstOrDefault();

            if (pawn == null)
            {
                Log.Error("PS_Bulding_ReconPod: Finsihed conditioning put held pawn is null");
                this.EjectContents();
                this.ForceEndJobState();
                return;
            }

            switch (this.JobState)
            {
            case PS_Conditioning_JobState.Waiting:
                return;

            case PS_Conditioning_JobState.Reconditioning:
                if (RoleForSucessOrHandleFail(pawn))
                {
                    PS_ConditioningHelper.DoConditioning(pawn, this, this.ConditioningData);
                    this.TryAssignPawn(pawn);
                    pawn.needs.mood.thoughts.memories.TryGainMemory(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_Reconditioned"));
                    PS_ConditioningHelper.DirtyNeedFall(pawn);
                    PS_ConditioningHelper.SetCurrentNeedLevel(pawn, PS_ConditioningHelper.GetCurrentNeedLevel(pawn) + 1f);
                    Messages.Message(string.Format("PS_Messages_CompletedReconditioning".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.TaskCompletion);
                }
                this.Open();
                break;

            case PS_Conditioning_JobState.Refreshing:
                PS_ConditioningHelper.SetCurrentNeedLevel(pawn, PS_ConditioningHelper.GetCurrentNeedLevel(pawn) + 0.6f);
                PS_ConditioningHelper.DirtyNeedFall(pawn);
                this.Open();
                break;

            case PS_Conditioning_JobState.Deconditioning:
                var lastConditioning = (PS_ConditioningHelper.GetConditioningDataFromHediff(pawn)?.Count() ?? 0) <= 1;
                PS_ConditioningHelper.UndoConditioning(pawn, this, this.ConditioningData);
                if (lastConditioning)
                {
                    pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_Reconditioned"));
                    pawn.needs.mood.thoughts.memories.TryGainMemory(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_Deconditioned"));

                    this.TryUnassignPawn(pawn);
                }
                else
                {
                    PS_ConditioningHelper.DirtyNeedFall(pawn);
                    PS_ConditioningHelper.SetCurrentNeedLevel(pawn, PS_ConditioningHelper.GetCurrentNeedLevel(pawn) + 1f);
                }
                this.Open();
                Messages.Message(string.Format("PS_Messages_CompletedDeconditioning".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.TaskCompletion);
                break;

            case PS_Conditioning_JobState.FixingBotch:
                PS_ConditioningHelper.RemoveBotch(pawn);
                pawn.needs.mood.thoughts.memories.RemoveMemoriesOfDef(DefDatabase <ThoughtDef> .GetNamed("PS_Thoughts_Memory_BotchedConditioned"));
                if (PS_ConditioningHelper.IsReconditioned(pawn))
                {
                    PS_ConditioningHelper.DirtyNeedFall(pawn);
                    PS_ConditioningHelper.SetCurrentNeedLevel(pawn, PS_ConditioningHelper.GetCurrentNeedLevel(pawn) + 1f);
                }
                this.Open();
                Messages.Message(string.Format("PS_Messages_CompletedFixingBotched".Translate(), pawn.LabelShort), new LookTargets(pawn), MessageTypeDefOf.TaskCompletion);
                break;
            }

            if (ProgressBarEffector != null)
            {
                ProgressBarEffector.Cleanup();
                ProgressBarEffector = null;
            }
            this.JobState = PS_Conditioning_JobState.Waiting;

            // Move hediff to brain if it's not, fix for old version
            if (!this.CheckedHediffPart)
            {
                var hediff = pawn.health.hediffSet.GetHediffs <PS_Hediff_Reconditioned>().FirstOrDefault();
                if (hediff != null)
                {
                    var currentPart = hediff.Part;
                    var brain       = pawn.RaceProps.body.AllParts.Where(x => x.def.defName == "Brain").FirstOrDefault();
                    if (brain != null && currentPart != brain)
                    {
                        hediff.Part = brain;
                    }
                }
                this.CheckedHediffPart = true;
            }
        }
Esempio n. 19
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;
        }
        // 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;
            }
        }