Exemplo n.º 1
0
        public bool AllowedToTakeToInventory(ThingDef thingDef)
        {
            if (!thingDef.IsIngestible)
            {
                Log.Error(thingDef + " is not ingestible.");
                return(false);
            }
            if (!thingDef.IsDrug)
            {
                Log.Error("AllowedToTakeScheduledEver on non-drug " + thingDef);
                return(false);
            }
            if (thingDef.IsNonMedicalDrug && pawn.IsTeetotaler())
            {
                return(false);
            }
            DrugPolicyEntry drugPolicyEntry = CurrentPolicy[thingDef];

            if (drugPolicyEntry.allowScheduled)
            {
                return(false);
            }
            if (drugPolicyEntry.takeToInventory > 0)
            {
                return(!pawn.inventory.innerContainer.Contains(thingDef));
            }
            return(false);
        }
Exemplo n.º 2
0
        public bool ShouldTryToTakeScheduledNow(ThingDef ingestible)
        {
            if (!ingestible.IsDrug)
            {
                return(false);
            }
            if (!AllowedToTakeScheduledNow(ingestible))
            {
                return(false);
            }
            Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.DrugOverdose);

            if (firstHediffOfDef != null && firstHediffOfDef.Severity > 0.5f && CanCauseOverdose(ingestible))
            {
                int num = LastTicksWhenTakenDrugWhichCanCauseOverdose();
                if (Find.TickManager.TicksGame - num < 1250)
                {
                    return(false);
                }
            }
            DrugTakeRecord drugTakeRecord = drugTakeRecords.Find((DrugTakeRecord x) => x.drug == ingestible);

            if (drugTakeRecord == null)
            {
                return(true);
            }
            DrugPolicyEntry drugPolicyEntry = CurrentPolicy[ingestible];

            if (drugPolicyEntry.daysFrequency < 1f)
            {
                int   num2 = Mathf.RoundToInt(1f / drugPolicyEntry.daysFrequency);
                float num3 = 1f / (float)(num2 + 1);
                int   num4 = 0;
                float dayPercentNotSleeping = DayPercentNotSleeping;
                for (int i = 0; i < num2; i++)
                {
                    if (dayPercentNotSleeping > (float)(i + 1) * num3 - num3 * 0.5f)
                    {
                        num4++;
                    }
                }
                if (drugTakeRecord.TimesTakenThisDay >= num4)
                {
                    return(false);
                }
                if (drugTakeRecord.TimesTakenThisDay != 0 && (float)(Find.TickManager.TicksGame - drugTakeRecord.lastTakenTicks) / (HoursPerDayNotSleeping * 2500f) < 0.6f * num3)
                {
                    return(false);
                }
                return(true);
            }
            float dayPercentNotSleeping2 = DayPercentNotSleeping;

            Rand.PushState();
            Rand.Seed = Gen.HashCombineInt(GenDate.DaysPassed, pawn.thingIDNumber);
            bool result = dayPercentNotSleeping2 >= Rand.Range(0.1f, 0.35f);

            Rand.PopState();
            return(result);
        }
        public bool AllowedToTakeScheduledNow(ThingDef thingDef)
        {
            bool result;

            if (!thingDef.IsIngestible)
            {
                Log.Error(thingDef + " is not ingestible.", false);
                result = false;
            }
            else if (!thingDef.IsDrug)
            {
                Log.Error("AllowedToTakeScheduledEver on non-drug " + thingDef, false);
                result = false;
            }
            else if (!this.AllowedToTakeScheduledEver(thingDef))
            {
                result = false;
            }
            else
            {
                DrugPolicyEntry drugPolicyEntry = this.CurrentPolicy[thingDef];
                if (drugPolicyEntry.onlyIfMoodBelow < 1f && this.pawn.needs.mood != null && this.pawn.needs.mood.CurLevelPercentage >= drugPolicyEntry.onlyIfMoodBelow)
                {
                    result = false;
                }
                else if (drugPolicyEntry.onlyIfJoyBelow < 1f && this.pawn.needs.joy != null && this.pawn.needs.joy.CurLevelPercentage >= drugPolicyEntry.onlyIfJoyBelow)
                {
                    result = false;
                }
                else
                {
                    DrugTakeRecord drugTakeRecord = this.drugTakeRecords.Find((DrugTakeRecord x) => x.drug == thingDef);
                    if (drugTakeRecord != null)
                    {
                        if (drugPolicyEntry.daysFrequency < 1f)
                        {
                            int num = Mathf.RoundToInt(1f / drugPolicyEntry.daysFrequency);
                            if (drugTakeRecord.TimesTakenThisDay >= num)
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            int num2 = Mathf.Abs(GenDate.DaysPassed - drugTakeRecord.LastTakenDays);
                            int num3 = Mathf.RoundToInt(drugPolicyEntry.daysFrequency);
                            if (num2 < num3)
                            {
                                return(false);
                            }
                        }
                    }
                    result = true;
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        public static Job IngestAndTakeToInventoryJob(Thing drug, Pawn pawn, int maxNumToCarry = 9999)
        {
            Job job = JobMaker.MakeJob(JobDefOf.Ingest, drug);

            job.count = Mathf.Min(drug.stackCount, drug.def.ingestible.maxNumToIngestAtOnce, maxNumToCarry);
            if (drug.Spawned && pawn.drugs != null && !pawn.inventory.innerContainer.Contains(drug.def))
            {
                DrugPolicyEntry drugPolicyEntry = pawn.drugs.CurrentPolicy[drug.def];
                if (drugPolicyEntry.allowScheduled)
                {
                    job.takeExtraIngestibles = drugPolicyEntry.takeToInventory;
                }
            }
            return(job);
        }
        private void DoEntryRow(Rect rect, DrugPolicyEntry entry)
        {
            float num  = default(float);
            float num2 = default(float);
            float num3 = default(float);
            float num4 = default(float);
            float num5 = default(float);
            float num6 = default(float);
            float num7 = default(float);
            float num8 = default(float);

            this.CalculateColumnsWidths(rect, out num, out num2, out num3, out num4, out num5, out num6, out num7, out num8);
            Text.Anchor = TextAnchor.MiddleLeft;
            float x = rect.x;

            Widgets.Label(new Rect(x, rect.y, num4, rect.height).ContractedBy(4f), entry.drug.LabelCap);
            float   num9   = x;
            Vector2 vector = Text.CalcSize(entry.drug.LabelCap);

            Widgets.InfoCardButton((float)(num9 + vector.x + 5.0), (float)(rect.y + (rect.height - 24.0) / 2.0), entry.drug);
            x += num4;
            if (entry.drug.IsAddictiveDrug)
            {
                Widgets.Checkbox(x, rect.y, ref entry.allowedForAddiction, 24f, false);
            }
            x += num;
            if (entry.drug.IsPleasureDrug)
            {
                Widgets.Checkbox(x, rect.y, ref entry.allowedForJoy, 24f, false);
            }
            x += num2;
            Widgets.Checkbox(x, rect.y, ref entry.allowScheduled, 24f, false);
            x += num3;
            if (entry.allowScheduled)
            {
                entry.daysFrequency = Widgets.FrequencyHorizontalSlider(new Rect(x, rect.y, num5, rect.height).ContractedBy(4f), entry.daysFrequency, 0.1f, 25f, true);
                x += num5;
                string label = (!(entry.onlyIfMoodBelow < 1.0)) ? "NoDrugUseRequirement".Translate() : entry.onlyIfMoodBelow.ToStringPercent();
                entry.onlyIfMoodBelow = Widgets.HorizontalSlider(new Rect(x, rect.y, num6, rect.height).ContractedBy(4f), entry.onlyIfMoodBelow, 0.01f, 1f, true, label, null, null, -1f);
                x += num6;
                string label2 = (!(entry.onlyIfJoyBelow < 1.0)) ? "NoDrugUseRequirement".Translate() : entry.onlyIfJoyBelow.ToStringPercent();
                entry.onlyIfJoyBelow = Widgets.HorizontalSlider(new Rect(x, rect.y, num7, rect.height).ContractedBy(4f), entry.onlyIfJoyBelow, 0.01f, 1f, true, label2, null, null, -1f);
                x += num7;
                Widgets.TextFieldNumeric <int>(new Rect(x, rect.y, num8, rect.height).ContractedBy(4f), ref entry.takeToInventory, ref entry.takeToInventoryTempBuffer, 0f, 15f);
                x += num8;
            }
            Text.Anchor = TextAnchor.UpperLeft;
        }
        public bool AllowedToTakeScheduledEver(ThingDef thingDef)
        {
            if (!thingDef.IsIngestible)
            {
                Log.Error(thingDef + " is not ingestible.", false);
                return(false);
            }
            if (!thingDef.IsDrug)
            {
                Log.Error("AllowedToTakeScheduledEver on non-drug " + thingDef, false);
                return(false);
            }
            DrugPolicyEntry drugPolicyEntry = this.CurrentPolicy[thingDef];

            return(drugPolicyEntry.allowScheduled && (!thingDef.IsNonMedicalDrug || !this.pawn.IsTeetotaler()));
        }
Exemplo n.º 7
0
 public void InitializeIfNeeded()
 {
     if (entriesInt == null)
     {
         entriesInt = new List <DrugPolicyEntry>();
         List <ThingDef> allDefsListForReading = DefDatabase <ThingDef> .AllDefsListForReading;
         for (int i = 0; i < allDefsListForReading.Count; i++)
         {
             if (allDefsListForReading[i].category == ThingCategory.Item && allDefsListForReading[i].IsDrug)
             {
                 DrugPolicyEntry drugPolicyEntry = new DrugPolicyEntry();
                 drugPolicyEntry.drug = allDefsListForReading[i];
                 drugPolicyEntry.allowedForAddiction = true;
                 entriesInt.Add(drugPolicyEntry);
             }
         }
         entriesInt.SortBy((DrugPolicyEntry e) => e.drug.GetCompProperties <CompProperties_Drug>().listOrder);
     }
 }
Exemplo n.º 8
0
        private void DoEntryRow(Rect rect, DrugPolicyEntry entry)
        {
            CalculateColumnsWidths(rect, out var addictionWidth, out var allowJoyWidth, out var scheduledWidth, out var drugNameWidth, out var frequencyWidth, out var moodThresholdWidth, out var joyThresholdWidth, out var takeToInventoryWidth);
            Text.Anchor = TextAnchor.MiddleLeft;
            float x = rect.x;

            Widgets.Label(new Rect(x, rect.y, drugNameWidth, rect.height).ContractedBy(4f), entry.drug.LabelCap);
            Widgets.InfoCardButton(x + Text.CalcSize(entry.drug.LabelCap).x + 5f, rect.y + (rect.height - 24f) / 2f, entry.drug);
            x += drugNameWidth;
            Widgets.TextFieldNumeric(new Rect(x, rect.y, takeToInventoryWidth, rect.height).ContractedBy(4f), ref entry.takeToInventory, ref entry.takeToInventoryTempBuffer, 0f, 15f);
            x += takeToInventoryWidth;
            if (entry.drug.IsAddictiveDrug)
            {
                Widgets.Checkbox(x, rect.y, ref entry.allowedForAddiction, 24f, disabled: false, paintable: true);
            }
            x += addictionWidth;
            if (entry.drug.IsPleasureDrug)
            {
                Widgets.Checkbox(x, rect.y, ref entry.allowedForJoy, 24f, disabled: false, paintable: true);
            }
            x += allowJoyWidth;
            Widgets.Checkbox(x, rect.y, ref entry.allowScheduled, 24f, disabled: false, paintable: true);
            x += scheduledWidth;
            if (entry.allowScheduled)
            {
                entry.daysFrequency = Widgets.FrequencyHorizontalSlider(new Rect(x, rect.y, frequencyWidth, rect.height).ContractedBy(4f), entry.daysFrequency, 0.1f, 25f, roundToInt: true);
                x += frequencyWidth;
                entry.onlyIfMoodBelow = Widgets.HorizontalSlider(label: (!(entry.onlyIfMoodBelow < 1f)) ? ((string)"NoDrugUseRequirement".Translate()) : entry.onlyIfMoodBelow.ToStringPercent(), rect: new Rect(x, rect.y, moodThresholdWidth, rect.height).ContractedBy(4f), value: entry.onlyIfMoodBelow, leftValue: 0.01f, rightValue: 1f, middleAlignment: true);
                x += moodThresholdWidth;
                entry.onlyIfJoyBelow = Widgets.HorizontalSlider(label: (!(entry.onlyIfJoyBelow < 1f)) ? ((string)"NoDrugUseRequirement".Translate()) : entry.onlyIfJoyBelow.ToStringPercent(), rect: new Rect(x, rect.y, joyThresholdWidth, rect.height).ContractedBy(4f), value: entry.onlyIfJoyBelow, leftValue: 0.01f, rightValue: 1f, middleAlignment: true);
                x += joyThresholdWidth;
            }
            else
            {
                x += frequencyWidth + moodThresholdWidth + joyThresholdWidth;
            }
            Text.Anchor = TextAnchor.UpperLeft;
        }
Exemplo n.º 9
0
        public bool AllowedToTakeScheduledEver(ThingDef thingDef)
        {
            if (!thingDef.IsIngestible)
            {
                Log.Error(thingDef + " is not ingestible.");
                return(false);
            }
            if (!thingDef.IsDrug)
            {
                Log.Error("AllowedToTakeScheduledEver on non-drug " + thingDef);
                return(false);
            }
            DrugPolicyEntry drugPolicyEntry = CurrentPolicy[thingDef];

            if (!drugPolicyEntry.allowScheduled)
            {
                return(false);
            }
            if (thingDef.IsNonMedicalDrug && pawn.IsTeetotaler())
            {
                return(false);
            }
            return(true);
        }
        private void DoEntryRow(Rect rect, DrugPolicyEntry entry)
        {
            float num;
            float num2;
            float num3;
            float num4;
            float num5;
            float num6;
            float num7;
            float num8;

            this.CalculateColumnsWidths(rect, out num, out num2, out num3, out num4, out num5, out num6, out num7, out num8);
            Text.Anchor = TextAnchor.MiddleLeft;
            float num9 = rect.x;

            Widgets.Label(new Rect(num9, rect.y, num4, rect.height).ContractedBy(4f), entry.drug.LabelCap);
            Widgets.InfoCardButton(num9 + Text.CalcSize(entry.drug.LabelCap).x + 5f, rect.y + (rect.height - 24f) / 2f, entry.drug);
            num9 += num4;
            if (entry.drug.IsAddictiveDrug)
            {
                Widgets.Checkbox(num9, rect.y, ref entry.allowedForAddiction, 24f, false, true, null, null);
            }
            num9 += num;
            if (entry.drug.IsPleasureDrug)
            {
                Widgets.Checkbox(num9, rect.y, ref entry.allowedForJoy, 24f, false, true, null, null);
            }
            num9 += num2;
            Widgets.Checkbox(num9, rect.y, ref entry.allowScheduled, 24f, false, true, null, null);
            num9 += num3;
            if (entry.allowScheduled)
            {
                entry.daysFrequency = Widgets.FrequencyHorizontalSlider(new Rect(num9, rect.y, num5, rect.height).ContractedBy(4f), entry.daysFrequency, 0.1f, 25f, true);
                num9 += num5;
                string label;
                if (entry.onlyIfMoodBelow < 1f)
                {
                    label = entry.onlyIfMoodBelow.ToStringPercent();
                }
                else
                {
                    label = "NoDrugUseRequirement".Translate();
                }
                entry.onlyIfMoodBelow = Widgets.HorizontalSlider(new Rect(num9, rect.y, num6, rect.height).ContractedBy(4f), entry.onlyIfMoodBelow, 0.01f, 1f, true, label, null, null, -1f);
                num9 += num6;
                string label2;
                if (entry.onlyIfJoyBelow < 1f)
                {
                    label2 = entry.onlyIfJoyBelow.ToStringPercent();
                }
                else
                {
                    label2 = "NoDrugUseRequirement".Translate();
                }
                entry.onlyIfJoyBelow = Widgets.HorizontalSlider(new Rect(num9, rect.y, num7, rect.height).ContractedBy(4f), entry.onlyIfJoyBelow, 0.01f, 1f, true, label2, null, null, -1f);
                num9 += num7;
                Widgets.TextFieldNumeric <int>(new Rect(num9, rect.y, num8, rect.height).ContractedBy(4f), ref entry.takeToInventory, ref entry.takeToInventoryTempBuffer, 0f, 15f);
                num9 += num8;
            }
            Text.Anchor = TextAnchor.UpperLeft;
        }
Exemplo n.º 11
0
 private static float <InitializeIfNeeded> m__0(DrugPolicyEntry e)
 {
     return(e.drug.GetCompProperties <CompProperties_Drug>().listOrder);
 }