public static bool PlayerOrItemStashHas(ThingDef thingDef)
        {
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                if (maps[i].listerThings.ThingsOfDef(thingDef).Count > 0)
                {
                    return(true);
                }
            }
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int j = 0; j < caravans.Count; j++)
            {
                if (caravans[j].IsPlayerControlled)
                {
                    List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravans[j]);
                    for (int k = 0; k < list.Count; k++)
                    {
                        if (list[k].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(PlayerItemAccessibilityUtility.ItemStashHas(thingDef));
        }
예제 #2
0
        public override float ExtraSelectionWeightFactor(ThingSetMakerParams parms)
        {
            int  num  = 0;
            bool flag = false;

            foreach (ResearchProjectDef allDef in DefDatabase <ResearchProjectDef> .AllDefs)
            {
                if (!allDef.IsFinished && allDef.PrerequisitesCompleted)
                {
                    if (!allDef.TechprintRequirementMet && !PlayerItemAccessibilityUtility.PlayerOrQuestRewardHas(allDef.Techprint, allDef.techprintCount - allDef.TechprintsApplied))
                    {
                        flag = true;
                    }
                    else
                    {
                        num++;
                    }
                }
            }
            if (!flag)
            {
                return(1f);
            }
            return(Mathf.RoundToInt(ResearchableProjectsCountToSelectionWeightCurve.Evaluate(num)));
        }
 private float GetSelectionWeight(Option option, ThingSetMakerParams parms)
 {
     if (option.weightIfPlayerHasNoItem.HasValue && !PlayerItemAccessibilityUtility.PlayerOrQuestRewardHas(option.weightIfPlayerHasNoItemItem))
     {
         return(option.weightIfPlayerHasNoItem.Value * option.thingSetMaker.ExtraSelectionWeightFactor(parms));
     }
     return(option.weight * option.thingSetMaker.ExtraSelectionWeightFactor(parms));
 }
        private static bool TryFindRandomRequestedThingDef(Map map, out ThingDef thingDef, out int count)
        {
            IncidentWorker_QuestTradeRequest.requestCountDict.Clear();
            Func <ThingDef, bool> globalValidator = delegate(ThingDef td)
            {
                bool result2;
                if (td.BaseMarketValue / td.BaseMass < 5f)
                {
                    result2 = false;
                }
                else if (!td.alwaysHaulable)
                {
                    result2 = false;
                }
                else
                {
                    CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>();
                    if (compProperties != null && compProperties.daysToRotStart < 10f)
                    {
                        result2 = false;
                    }
                    else if (td.ingestible != null && td.ingestible.HumanEdible)
                    {
                        result2 = false;
                    }
                    else if (td == ThingDefOf.Silver)
                    {
                        result2 = false;
                    }
                    else if (!td.PlayerAcquirable)
                    {
                        result2 = false;
                    }
                    else
                    {
                        int num = IncidentWorker_QuestTradeRequest.RandomRequestCount(td, map);
                        IncidentWorker_QuestTradeRequest.requestCountDict.Add(td, num);
                        result2 = PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map);
                    }
                }
                return(result2);
            };
            bool result;

            if ((from td in ThingSetMakerUtility.allGeneratableItems
                 where globalValidator(td)
                 select td).TryRandomElement(out thingDef))
            {
                count  = IncidentWorker_QuestTradeRequest.requestCountDict[thingDef];
                result = true;
            }
            else
            {
                count  = 0;
                result = false;
            }
            return(result);
        }
예제 #5
0
        private static bool TryFindRandomRequestedThingDef(Map map, out ThingDef thingDef, out int count)
        {
            requestCountDict.Clear();
            Func <ThingDef, bool> globalValidator = delegate(ThingDef td)
            {
                if (td.BaseMarketValue / td.BaseMass < 5f)
                {
                    return(false);
                }
                if (!td.alwaysHaulable)
                {
                    return(false);
                }
                CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>();
                if (compProperties != null && compProperties.daysToRotStart < 10f)
                {
                    return(false);
                }
                if (td.ingestible != null && td.ingestible.HumanEdible)
                {
                    return(false);
                }
                if (td == ThingDefOf.Silver)
                {
                    return(false);
                }
                if (!td.PlayerAcquirable)
                {
                    return(false);
                }
                int num = RandomRequestCount(td, map);
                requestCountDict.Add(td, num);
                if (!PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map))
                {
                    return(false);
                }
                if (!PlayerItemAccessibilityUtility.PlayerCanMake(td, map))
                {
                    return(false);
                }
                if (td.thingSetMakerTags != null && td.thingSetMakerTags.Contains("RewardSpecial"))
                {
                    return(false);
                }
                return(true);
            };

            if ((from td in ThingSetMakerUtility.allGeneratableItems
                 where globalValidator(td)
                 select td).TryRandomElement(out thingDef))
            {
                count = requestCountDict[thingDef];
                return(true);
            }
            count = 0;
            return(false);
        }
예제 #6
0
        private float GetSelectionWeight(ThingSetMaker_RandomOption.Option option, ThingSetMakerParams parms)
        {
            float?weightIfPlayerHasNoItem = option.weightIfPlayerHasNoItem;

            if (weightIfPlayerHasNoItem != null && !PlayerItemAccessibilityUtility.PlayerOrQuestRewardHas(option.weightIfPlayerHasNoItemItem))
            {
                return(option.weightIfPlayerHasNoItem.Value);
            }
            return(option.weight);
        }
예제 #7
0
        private static DiaOption RequestAICoreQuest(Map map, Faction faction, Pawn negotiator)
        {
            TaggedString taggedString = "RequestAICoreInformation".Translate(ThingDefOf.AIPersonaCore.label, 1500.ToString());

            if (faction.PlayerGoodwill < 40)
            {
                DiaOption diaOption = new DiaOption(taggedString);
                diaOption.Disable("NeedGoodwill".Translate(40.ToString("F0")));
                return(diaOption);
            }
            bool  num   = PlayerItemAccessibilityUtility.ItemStashHas(ThingDefOf.AIPersonaCore);
            Slate slate = new Slate();

            slate.Set("points", StorytellerUtility.DefaultThreatPointsNow(Find.World));
            slate.Set("asker", faction.leader);
            slate.Set("itemStashSingleThing", ThingDefOf.AIPersonaCore);
            bool flag = QuestScriptDefOf.OpportunitySite_ItemStash.CanRun(slate);

            if (num || !flag)
            {
                DiaOption diaOption2 = new DiaOption(taggedString);
                diaOption2.Disable("NoKnownAICore".Translate(1500));
                return(diaOption2);
            }
            if (AmountSendableSilver(map) < 1500)
            {
                DiaOption diaOption3 = new DiaOption(taggedString);
                diaOption3.Disable("NeedSilverLaunchable".Translate(1500));
                return(diaOption3);
            }
            return(new DiaOption(taggedString)
            {
                action = delegate
                {
                    Quest quest = QuestUtility.GenerateQuestAndMakeAvailable(QuestScriptDefOf.OpportunitySite_ItemStash, slate);
                    if (!quest.hidden)
                    {
                        QuestUtility.SendLetterQuestAvailable(quest);
                    }
                    TradeUtility.LaunchThingsOfType(ThingDefOf.Silver, 1500, map, null);
                    Current.Game.GetComponent <GameComponent_OnetimeNotification>().sendAICoreRequestReminder = false;
                },
                link = new DiaNode("RequestAICoreInformationResult".Translate(faction.leader).CapitalizeFirst())
                {
                    options =
                    {
                        OKToRoot(faction, negotiator)
                    }
                }
            });
        }
        public static bool Accessible(ThingDef thing, int count, Map map)
        {
            PlayerItemAccessibilityUtility.CacheAccessibleThings(map.Tile);
            int num = 0;

            for (int i = 0; i < PlayerItemAccessibilityUtility.cachedAccessibleThings.Count; i++)
            {
                if (PlayerItemAccessibilityUtility.cachedAccessibleThings[i].def == thing)
                {
                    num += PlayerItemAccessibilityUtility.cachedAccessibleThings[i].stackCount;
                }
            }
            return(num >= count);
        }
예제 #9
0
        private static DiaOption RequestAICoreQuest(Map map, Faction faction, Pawn negotiator)
        {
            string text = "RequestAICoreInformation".Translate(ThingDefOf.AIPersonaCore.label, 1500.ToString());

            if (faction.PlayerGoodwill < 40)
            {
                DiaOption diaOption = new DiaOption(text);
                diaOption.Disable("NeedGoodwill".Translate(40.ToString("F0")));
                return(diaOption);
            }
            IncidentDef   def  = IncidentDefOf.Quest_ItemStashAICore;
            bool          flag = PlayerItemAccessibilityUtility.ItemStashHas(ThingDefOf.AIPersonaCore);
            IncidentParms coreIncidentParms = StorytellerUtility.DefaultParmsNow(IncidentCategoryDefOf.Misc, Find.World);

            coreIncidentParms.faction = faction;
            bool flag2 = def.Worker.CanFireNow(coreIncidentParms, false);

            if (flag || !flag2)
            {
                DiaOption diaOption2 = new DiaOption(text);
                diaOption2.Disable("NoKnownAICore".Translate(1500));
                return(diaOption2);
            }
            if (FactionDialogMaker.AmountSendableSilver(map) < 1500)
            {
                DiaOption diaOption3 = new DiaOption(text);
                diaOption3.Disable("NeedSilverLaunchable".Translate(1500));
                return(diaOption3);
            }
            DiaOption diaOption4 = new DiaOption(text);

            diaOption4.action = delegate
            {
                if (def.Worker.TryExecute(coreIncidentParms))
                {
                    TradeUtility.LaunchThingsOfType(ThingDefOf.Silver, 1500, map, null);
                }
                Current.Game.GetComponent <GameComponent_OnetimeNotification>().sendAICoreRequestReminder = false;
            };
            string text2 = "RequestAICoreInformationResult".Translate(faction.leader).CapitalizeFirst();

            diaOption4.link = new DiaNode(text2)
            {
                options =
                {
                    FactionDialogMaker.OKToRoot(faction, negotiator)
                }
            };
            return(diaOption4);
        }
        private static bool TryFindRandomRequestedThingDef(Map map, out ThingDef thingDef, out int count)
        {
            IncidentWorker_CaravanRequest.requestCountDict.Clear();
            Func <ThingDef, bool> globalValidator = delegate(ThingDef td)
            {
                if (td.BaseMarketValue / td.BaseMass < 5.0)
                {
                    return(false);
                }
                if (!td.alwaysHaulable)
                {
                    return(false);
                }
                CompProperties_Rottable compProperties = td.GetCompProperties <CompProperties_Rottable>();
                if (compProperties != null && compProperties.daysToRotStart < 10.0)
                {
                    return(false);
                }
                if (td.ingestible != null && td.ingestible.HumanEdible)
                {
                    return(false);
                }
                if (td == ThingDefOf.Silver)
                {
                    return(false);
                }
                if (!td.PlayerAcquirable)
                {
                    return(false);
                }
                int num = IncidentWorker_CaravanRequest.RandomRequestCount(td, map);
                IncidentWorker_CaravanRequest.requestCountDict.Add(td, num);
                if (!PlayerItemAccessibilityUtility.PossiblyAccessible(td, num, map))
                {
                    return(false);
                }
                return(true);
            };

            if ((from td in ItemCollectionGeneratorUtility.allGeneratableItems
                 where globalValidator(td)
                 select td).TryRandomElement <ThingDef>(out thingDef))
            {
                count = IncidentWorker_CaravanRequest.requestCountDict[thingDef];
                return(true);
            }
            count = 0;
            return(false);
        }
        private float GetSelectionWeight(ThingSetMaker_RandomOption.Option option)
        {
            float?weightIfPlayerHasNoSuchItem = option.weightIfPlayerHasNoSuchItem;
            float result;

            if (weightIfPlayerHasNoSuchItem != null && !PlayerItemAccessibilityUtility.PlayerOrItemStashHas(option.thingSetMaker.fixedParams.filter))
            {
                result = option.weightIfPlayerHasNoSuchItem.Value;
            }
            else
            {
                result = option.weight;
            }
            return(result);
        }
        public static bool PossiblyAccessible(ThingDef thing, int count, Map map)
        {
            if (PlayerItemAccessibilityUtility.Accessible(thing, count, map))
            {
                return(true);
            }
            PlayerItemAccessibilityUtility.CacheAccessibleThings(map.Tile);
            int num = 0;

            for (int i = 0; i < PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings.Count; i++)
            {
                if (PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings[i].ThingDef == thing)
                {
                    num += PlayerItemAccessibilityUtility.cachedPossiblyAccessibleThings[i].Count;
                }
            }
            return(num >= count);
        }
예제 #13
0
 public static bool PlayerCanMake(ThingDef thing, Map map)
 {
     PlayerItemAccessibilityUtility.CacheAccessibleThings(map.Tile);
     return(PlayerItemAccessibilityUtility.cachedMakeableItemDefs.Contains(thing));
 }