コード例 #1
0
        public override float GetPriority(Pawn pawn)
        {
            DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;

            for (int i = 0; i < currentPolicy.Count; i++)
            {
                if (pawn.drugs.AllowedToTakeToInventory(currentPolicy[i].drug))
                {
                    return(7.5f);
                }
            }
            return(0f);
        }
コード例 #2
0
        public override float GetPriority(Pawn pawn)
        {
            DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;

            for (int i = 0; i < currentPolicy.Count; i++)
            {
                if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug))
                {
                    return(7.5f);
                }
            }
            return(0f);
        }
コード例 #3
0
        protected override Thing BestIngestItem(Pawn pawn, Predicate <Thing> extraValidator)
        {
            Thing result;

            if (pawn.drugs == null)
            {
                result = null;
            }
            else
            {
                Predicate <Thing>  predicate      = (Thing t) => this.CanIngestForJoy(pawn, t) && (extraValidator == null || extraValidator(t));
                ThingOwner <Thing> innerContainer = pawn.inventory.innerContainer;
                for (int i = 0; i < innerContainer.Count; i++)
                {
                    if (predicate(innerContainer[i]))
                    {
                        return(innerContainer[i]);
                    }
                }
                JoyGiver_TakeDrug.takeableDrugs.Clear();
                DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;
                for (int j = 0; j < currentPolicy.Count; j++)
                {
                    if (currentPolicy[j].allowedForJoy)
                    {
                        JoyGiver_TakeDrug.takeableDrugs.Add(currentPolicy[j].drug);
                    }
                }
                JoyGiver_TakeDrug.takeableDrugs.Shuffle <ThingDef>();
                for (int k = 0; k < JoyGiver_TakeDrug.takeableDrugs.Count; k++)
                {
                    List <Thing> list = pawn.Map.listerThings.ThingsOfDef(JoyGiver_TakeDrug.takeableDrugs[k]);
                    if (list.Count > 0)
                    {
                        IntVec3           position       = pawn.Position;
                        Map               map            = pawn.Map;
                        List <Thing>      searchSet      = list;
                        PathEndMode       peMode         = PathEndMode.OnCell;
                        TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
                        Predicate <Thing> validator      = predicate;
                        Thing             thing          = GenClosest.ClosestThing_Global_Reachable(position, map, searchSet, peMode, traverseParams, 9999f, validator, null);
                        if (thing != null)
                        {
                            return(thing);
                        }
                    }
                }
                result = null;
            }
            return(result);
        }
コード例 #4
0
        public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
        {
            if (pawn.drugs == null)
            {
                return;
            }
            int    num   = Mathf.FloorToInt((rect.width - 4f) * 0.714285731f);
            int    num2  = Mathf.FloorToInt((rect.width - 4f) * 0.2857143f);
            float  num3  = rect.x;
            Rect   rect2 = new Rect(num3, rect.y + 2f, (float)num, rect.height - 4f);
            string text  = pawn.drugs.CurrentPolicy.label;

            if (pawn.story != null && pawn.story.traits != null)
            {
                Trait trait = pawn.story.traits.GetTrait(TraitDefOf.DrugDesire);
                if (trait != null)
                {
                    text = text + " (" + trait.Label + ")";
                }
            }
            text = text.Truncate(rect2.width, null);
            if (Widgets.ButtonText(rect2, text, true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (DrugPolicy current in Current.Game.drugPolicyDatabase.AllPolicies)
                {
                    DrugPolicy localAssignedDrugs = current;
                    list.Add(new FloatMenuOption(current.label, delegate
                    {
                        pawn.drugs.CurrentPolicy = localAssignedDrugs;
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list));
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.DrugPolicies, KnowledgeAmount.Total);
            }
            num3 += (float)num;
            num3 += 4f;
            Rect rect3 = new Rect(num3, rect.y + 2f, (float)num2, rect.height - 4f);

            if (Widgets.ButtonText(rect3, "AssignTabEdit".Translate(), true, false, true))
            {
                Find.WindowStack.Add(new Dialog_ManageDrugPolicies(pawn.drugs.CurrentPolicy));
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.DrugPolicies, KnowledgeAmount.Total);
            }
            UIHighlighter.HighlightOpportunity(rect2, "ButtonAssignDrugs");
            UIHighlighter.HighlightOpportunity(rect3, "ButtonAssignDrugs");
            num3 += (float)num2;
        }
コード例 #5
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;

            for (int i = 0; i < currentPolicy.Count; i++)
            {
                if (pawn.drugs.ShouldTryToTakeScheduledNow(currentPolicy[i].drug))
                {
                    Thing thing = FindDrugFor(pawn, currentPolicy[i].drug);
                    if (thing != null)
                    {
                        return(DrugAIUtility.IngestAndTakeToInventoryJob(thing, pawn, 1));
                    }
                }
            }
            return(null);
        }
コード例 #6
0
        public DrugPolicy MakeNewDrugPolicy()
        {
            int arg_40_0;

            if (this.policies.Any <DrugPolicy>())
            {
                arg_40_0 = this.policies.Max((DrugPolicy o) => o.uniqueId) + 1;
            }
            else
            {
                arg_40_0 = 1;
            }
            int        uniqueId   = arg_40_0;
            DrugPolicy drugPolicy = new DrugPolicy(uniqueId, "DrugPolicy".Translate() + " " + uniqueId.ToString());

            this.policies.Add(drugPolicy);
            return(drugPolicy);
        }
コード例 #7
0
        private static bool TryFindIngestibleToNurse(IntVec3 center, Pawn ingester, out Thing ingestible)
        {
            bool result;

            if (ingester.IsTeetotaler())
            {
                ingestible = null;
                result     = false;
            }
            else if (ingester.drugs == null)
            {
                ingestible = null;
                result     = false;
            }
            else
            {
                JoyGiver_SocialRelax.nurseableDrugs.Clear();
                DrugPolicy currentPolicy = ingester.drugs.CurrentPolicy;
                for (int i = 0; i < currentPolicy.Count; i++)
                {
                    if (currentPolicy[i].allowedForJoy && currentPolicy[i].drug.ingestible.nurseable)
                    {
                        JoyGiver_SocialRelax.nurseableDrugs.Add(currentPolicy[i].drug);
                    }
                }
                JoyGiver_SocialRelax.nurseableDrugs.Shuffle <ThingDef>();
                for (int j = 0; j < JoyGiver_SocialRelax.nurseableDrugs.Count; j++)
                {
                    List <Thing> list = ingester.Map.listerThings.ThingsOfDef(JoyGiver_SocialRelax.nurseableDrugs[j]);
                    if (list.Count > 0)
                    {
                        Predicate <Thing> validator = (Thing t) => ingester.CanReserve(t, 1, -1, null, false) && !t.IsForbidden(ingester);
                        ingestible = GenClosest.ClosestThing_Global_Reachable(center, ingester.Map, list, PathEndMode.OnCell, TraverseParms.For(ingester, Danger.Deadly, TraverseMode.ByPawn, false), 40f, validator, null);
                        if (ingestible != null)
                        {
                            return(true);
                        }
                    }
                }
                ingestible = null;
                result     = false;
            }
            return(result);
        }
コード例 #8
0
 private static IEnumerable <Widgets.DropdownMenuElement <DrugPolicy> > Button_GenerateMenu(Pawn pawn)
 {
     using (List <DrugPolicy> .Enumerator enumerator = Current.Game.drugPolicyDatabase.AllPolicies.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             DrugPolicy assignedDrugs = enumerator.Current;
             yield return(new Widgets.DropdownMenuElement <DrugPolicy>
             {
                 option = new FloatMenuOption(assignedDrugs.label, delegate()
                 {
                     pawn.drugs.CurrentPolicy = assignedDrugs;
                 }, MenuOptionPriority.Default, null, null, 0f, null, null),
                 payload = assignedDrugs
             });
         }
     }
     yield break;
 }
コード例 #9
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                bool flag = false;

                switch (num)
                {
                case 0u:
                    enumerator = Current.Game.drugPolicyDatabase.AllPolicies.GetEnumerator();
                    num        = 4294967293u;
                    break;

                case 1u:
                    break;

                default:
                    return(false);
                }
                try
                {
                    switch (num)
                    {
                    }
                    if (enumerator.MoveNext())
                    {
                        DrugPolicy assignedDrugs = enumerator.Current;
                        this.$current = new Widgets.DropdownMenuElement <DrugPolicy>
                        {
                            option = new FloatMenuOption(assignedDrugs.label, delegate()
                            {
                                < Button_GenerateMenu > c__AnonStorey.pawn.drugs.CurrentPolicy = assignedDrugs;
                            }, MenuOptionPriority.Default, null, null, 0f, null, null),
                            payload = assignedDrugs
                        };
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        flag = true;
                        return(true);
                    }
コード例 #10
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            DrugPolicy currentPolicy = pawn.drugs.CurrentPolicy;

            for (int i = 0; i < currentPolicy.Count; i++)
            {
                if (pawn.drugs.AllowedToTakeToInventory(currentPolicy[i].drug))
                {
                    Thing thing = FindDrugFor(pawn, currentPolicy[i].drug);
                    if (thing != null)
                    {
                        Job job = JobMaker.MakeJob(JobDefOf.TakeInventory, thing);
                        job.count = currentPolicy[i].takeToInventory - pawn.inventory.innerContainer.TotalStackCountOfDef(thing.def);
                        return(job);
                    }
                }
            }
            return(null);
        }
コード例 #11
0
 public AcceptanceReport TryDelete(DrugPolicy policy)
 {
     foreach (Pawn allMapsCaravansAndTravelingTransportPod in PawnsFinder.AllMapsCaravansAndTravelingTransportPods)
     {
         if (allMapsCaravansAndTravelingTransportPod.drugs != null && allMapsCaravansAndTravelingTransportPod.drugs.CurrentPolicy == policy)
         {
             return(new AcceptanceReport("DrugPolicyInUse".Translate(allMapsCaravansAndTravelingTransportPod)));
         }
     }
     foreach (Pawn item in PawnsFinder.AllMapsWorldAndTemporary_AliveOrDead)
     {
         if (item.drugs != null && item.drugs.CurrentPolicy == policy)
         {
             item.drugs.CurrentPolicy = null;
         }
     }
     this.policies.Remove(policy);
     return(AcceptanceReport.WasAccepted);
 }
コード例 #12
0
 public AcceptanceReport TryDelete(DrugPolicy policy)
 {
     foreach (Pawn current in PawnsFinder.AllMapsCaravansAndTravelingTransportPods)
     {
         if (current.drugs != null && current.drugs.CurrentPolicy == policy)
         {
             return(new AcceptanceReport("DrugPolicyInUse".Translate(new object[]
             {
                 current
             })));
         }
     }
     foreach (Pawn current2 in PawnsFinder.AllMapsWorldAndTemporary_AliveOrDead)
     {
         if (current2.drugs != null && current2.drugs.CurrentPolicy == policy)
         {
             current2.drugs.CurrentPolicy = null;
         }
     }
     this.policies.Remove(policy);
     return(AcceptanceReport.WasAccepted);
 }
コード例 #13
0
        private static bool TryFindIngestibleToNurse(IntVec3 center, Pawn ingester, out Thing ingestible)
        {
            if (ingester.IsTeetotaler())
            {
                ingestible = null;
                return(false);
            }
            if (ingester.drugs == null)
            {
                ingestible = null;
                return(false);
            }
            nurseableDrugs.Clear();
            DrugPolicy currentPolicy = ingester.drugs.CurrentPolicy;

            for (int i = 0; i < currentPolicy.Count; i++)
            {
                if (currentPolicy[i].allowedForJoy && currentPolicy[i].drug.ingestible.nurseable)
                {
                    nurseableDrugs.Add(currentPolicy[i].drug);
                }
            }
            nurseableDrugs.Shuffle();
            for (int j = 0; j < nurseableDrugs.Count; j++)
            {
                List <Thing> list = ingester.Map.listerThings.ThingsOfDef(nurseableDrugs[j]);
                if (list.Count > 0)
                {
                    Predicate <Thing> validator = (Thing t) => ingester.CanReserve(t) && !t.IsForbidden(ingester);
                    ingestible = GenClosest.ClosestThing_Global_Reachable(center, ingester.Map, list, PathEndMode.OnCell, TraverseParms.For(ingester), 40f, validator);
                    if (ingestible != null)
                    {
                        return(true);
                    }
                }
            }
            ingestible = null;
            return(false);
        }
コード例 #14
0
        private static IEnumerable <Widgets.DropdownMenuElement <DrugPolicy> > Button_GenerateMenu(Pawn pawn)
        {
            using (List <DrugPolicy> .Enumerator enumerator = Current.Game.drugPolicyDatabase.AllPolicies.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    DrugPolicy assignedDrugs = enumerator.Current;
                    yield return(new Widgets.DropdownMenuElement <DrugPolicy>
                    {
                        option = new FloatMenuOption(assignedDrugs.label, delegate
                        {
                            pawn.drugs.CurrentPolicy = assignedDrugs;
                        }),
                        payload = assignedDrugs
                    });

                    /*Error: Unable to find new state assignment for yield return*/;
                }
            }
            yield break;
IL_0141:
            /*Error near IL_0142: Unexpected return in MoveNext()*/;
        }
コード例 #15
0
        private void DoPolicyConfigArea(Rect rect)
        {
            Rect rect2 = rect;

            rect2.height = 54f;
            Rect rect3 = rect;

            rect3.yMin    = rect2.yMax;
            rect3.height -= 50f;
            Rect rect4 = rect;

            rect4.yMin = rect4.yMax - 50f;
            this.DoColumnLabels(rect2);
            Widgets.DrawMenuSection(rect3);
            if (this.SelectedPolicy.Count == 0)
            {
                GUI.color   = Color.grey;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect3, "NoDrugs".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            else
            {
                float height   = (float)this.SelectedPolicy.Count * 35f;
                Rect  viewRect = new Rect(0f, 0f, rect3.width - 16f, height);
                Widgets.BeginScrollView(rect3, ref this.scrollPosition, viewRect, true);
                DrugPolicy selectedPolicy = this.SelectedPolicy;
                for (int i = 0; i < selectedPolicy.Count; i++)
                {
                    Rect rect5 = new Rect(0f, (float)i * 35f, viewRect.width, 35f);
                    this.DoEntryRow(rect5, selectedPolicy[i]);
                }
                Widgets.EndScrollView();
            }
        }
コード例 #16
0
 private static int <MakeNewDrugPolicy> m__0(DrugPolicy o)
 {
     return(o.uniqueId);
 }
コード例 #17
0
        public override void DoWindowContents(Rect inRect)
        {
            float num  = 0f;
            Rect  rect = new Rect(0f, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect, "SelectDrugPolicy".Translate(), true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (DrugPolicy localAssignedDrugs3 in Current.Game.drugPolicyDatabase.AllPolicies)
                {
                    DrugPolicy localAssignedDrugs = localAssignedDrugs3;
                    list.Add(new FloatMenuOption(localAssignedDrugs.label, delegate()
                    {
                        this.SelectedPolicy = localAssignedDrugs;
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
            num += 10f;
            Rect rect2 = new Rect(num, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect2, "NewDrugPolicy".Translate(), true, false, true))
            {
                this.SelectedPolicy = Current.Game.drugPolicyDatabase.MakeNewDrugPolicy();
            }
            num += 10f;
            Rect rect3 = new Rect(num, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect3, "DeleteDrugPolicy".Translate(), true, false, true))
            {
                List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                foreach (DrugPolicy localAssignedDrugs2 in Current.Game.drugPolicyDatabase.AllPolicies)
                {
                    DrugPolicy localAssignedDrugs = localAssignedDrugs2;
                    list2.Add(new FloatMenuOption(localAssignedDrugs.label, delegate()
                    {
                        AcceptanceReport acceptanceReport = Current.Game.drugPolicyDatabase.TryDelete(localAssignedDrugs);
                        if (!acceptanceReport.Accepted)
                        {
                            Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.RejectInput, false);
                        }
                        else if (localAssignedDrugs == this.SelectedPolicy)
                        {
                            this.SelectedPolicy = null;
                        }
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list2));
            }
            Rect rect4 = new Rect(0f, 40f, inRect.width, inRect.height - 40f - this.CloseButSize.y).ContractedBy(10f);

            if (this.SelectedPolicy == null)
            {
                GUI.color   = Color.grey;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect4, "NoDrugPolicySelected".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            else
            {
                GUI.BeginGroup(rect4);
                Rect rect5 = new Rect(0f, 0f, 200f, 30f);
                Dialog_ManageDrugPolicies.DoNameInputRect(rect5, ref this.SelectedPolicy.label);
                Rect rect6 = new Rect(0f, 40f, rect4.width, rect4.height - 45f - 10f);
                this.DoPolicyConfigArea(rect6);
                GUI.EndGroup();
            }
        }
コード例 #18
0
        public override void DoWindowContents(Rect inRect)
        {
            float num  = 0f;
            Rect  rect = new Rect(0f, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect, "SelectDrugPolicy".Translate()))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (DrugPolicy allPolicy in Current.Game.drugPolicyDatabase.AllPolicies)
                {
                    DrugPolicy localAssignedDrugs = allPolicy;
                    list.Add(new FloatMenuOption(localAssignedDrugs.label, delegate
                    {
                        SelectedPolicy = localAssignedDrugs;
                    }));
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
            num += 10f;
            Rect rect2 = new Rect(num, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect2, "NewDrugPolicy".Translate()))
            {
                SelectedPolicy = Current.Game.drugPolicyDatabase.MakeNewDrugPolicy();
            }
            num += 10f;
            Rect rect3 = new Rect(num, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect3, "DeleteDrugPolicy".Translate()))
            {
                List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                foreach (DrugPolicy allPolicy2 in Current.Game.drugPolicyDatabase.AllPolicies)
                {
                    DrugPolicy localAssignedDrugs2 = allPolicy2;
                    list2.Add(new FloatMenuOption(localAssignedDrugs2.label, delegate
                    {
                        AcceptanceReport acceptanceReport = Current.Game.drugPolicyDatabase.TryDelete(localAssignedDrugs2);
                        if (!acceptanceReport.Accepted)
                        {
                            Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.RejectInput, historical: false);
                        }
                        else if (localAssignedDrugs2 == SelectedPolicy)
                        {
                            SelectedPolicy = null;
                        }
                    }));
                }
                Find.WindowStack.Add(new FloatMenu(list2));
            }
            float   width        = inRect.width;
            float   num2         = inRect.height - 40f;
            Vector2 closeButSize = CloseButSize;
            Rect    rect4        = new Rect(0f, 40f, width, num2 - closeButSize.y).ContractedBy(10f);

            if (SelectedPolicy == null)
            {
                GUI.color   = Color.grey;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect4, "NoDrugPolicySelected".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
            }
            else
            {
                GUI.BeginGroup(rect4);
                Rect rect5 = new Rect(0f, 0f, 200f, 30f);
                DoNameInputRect(rect5, ref SelectedPolicy.label);
                Rect rect6 = new Rect(0f, 40f, rect4.width, rect4.height - 45f - 10f);
                DoPolicyConfigArea(rect6);
                GUI.EndGroup();
            }
        }