Esempio n. 1
0
        protected override void ScatterAt(IntVec3 loc, Map map, int count = 1)
        {
            CellRect      cellRect      = CellRect.CenteredOn(loc, 7, 7).ClipInsideMap(map);
            ResolveParams resolveParams = default(ResolveParams);

            resolveParams.rect    = cellRect;
            resolveParams.faction = map.ParentFaction;
            ItemStashContentsComp component = map.info.parent.GetComponent <ItemStashContentsComp>();

            if (component != null && component.contents.Any)
            {
                resolveParams.stockpileConcreteContents = component.contents;
            }
            else
            {
                resolveParams.stockpileMarketValue = new float?(this.totalValueRange.RandomInRange);
                if (this.itemCollectionGeneratorDefs != null)
                {
                    resolveParams.itemCollectionGeneratorDef = this.itemCollectionGeneratorDefs.RandomElement <ItemCollectionGeneratorDef>();
                }
            }
            BaseGen.globalSettings.map = map;
            BaseGen.symbolStack.Push("storage", resolveParams);
            BaseGen.Generate();
            MapGenerator.SetVar <CellRect>("RectOfInterest", cellRect);
        }
        protected override void ScatterAt(IntVec3 loc, Map map, GenStepParams parms, int count = 1)
        {
            CellRect cellRect = CellRect.CenteredOn(loc, 7, 7).ClipInsideMap(map);

            if (!MapGenerator.TryGetVar <List <CellRect> >("UsedRects", out var var))
            {
                var = new List <CellRect>();
                MapGenerator.SetVar("UsedRects", var);
            }
            ResolveParams resolveParams = default(ResolveParams);

            resolveParams.rect    = cellRect;
            resolveParams.faction = map.ParentFaction;
            if (parms.sitePart != null && parms.sitePart.things != null && parms.sitePart.things.Any)
            {
                resolveParams.stockpileConcreteContents = parms.sitePart.things;
            }
            else
            {
                ItemStashContentsComp component = map.Parent.GetComponent <ItemStashContentsComp>();
                if (component != null && component.contents.Any)
                {
                    resolveParams.stockpileConcreteContents = component.contents;
                }
                else
                {
                    resolveParams.thingSetMakerDef = thingSetMakerDef ?? ThingSetMakerDefOf.MapGen_DefaultStockpile;
                }
            }
            RimWorld.BaseGen.BaseGen.globalSettings.map = map;
            RimWorld.BaseGen.BaseGen.symbolStack.Push("storage", resolveParams);
            RimWorld.BaseGen.BaseGen.Generate();
            MapGenerator.SetVar("RectOfInterest", cellRect);
            var.Add(cellRect);
        }
Esempio n. 3
0
        public static bool PlayerOrQuestRewardHas(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);
                        }
                    }
                }
            }
            List <Site> sites = Find.WorldObjects.Sites;

            for (int l = 0; l < sites.Count; l++)
            {
                ItemStashContentsComp component = sites[l].GetComponent <ItemStashContentsComp>();
                if (component != null)
                {
                    ThingOwner contents = component.contents;
                    for (int m = 0; m < contents.Count; m++)
                    {
                        if (contents[m].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
                DefeatAllEnemiesQuestComp component2 = sites[l].GetComponent <DefeatAllEnemiesQuestComp>();
                if (component2 != null)
                {
                    ThingOwner rewards = component2.rewards;
                    for (int n = 0; n < rewards.Count; n++)
                    {
                        if (rewards[n].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        public static bool PlayerOrItemStashHas(ThingFilter thingFilter)
        {
            ThingRequest bestThingRequest = thingFilter.BestThingRequest;
            List <Map>   maps             = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                List <Thing> list = maps[i].listerThings.ThingsMatching(bestThingRequest);
                for (int j = 0; j < list.Count; j++)
                {
                    if (thingFilter.Allows(list[j]))
                    {
                        return(true);
                    }
                }
            }
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int k = 0; k < caravans.Count; k++)
            {
                if (caravans[k].IsPlayerControlled)
                {
                    List <Thing> list2 = CaravanInventoryUtility.AllInventoryItems(caravans[k]);
                    for (int l = 0; l < list2.Count; l++)
                    {
                        if (thingFilter.Allows(list2[l]))
                        {
                            return(true);
                        }
                    }
                }
            }
            List <Site> sites = Find.WorldObjects.Sites;

            for (int m = 0; m < sites.Count; m++)
            {
                ItemStashContentsComp component = sites[m].GetComponent <ItemStashContentsComp>();
                if (component != null)
                {
                    ThingOwner contents = component.contents;
                    for (int n = 0; n < contents.Count; n++)
                    {
                        if (thingFilter.Allows(contents[n]))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 5
0
        public static bool ItemStashHas(ThingDef thingDef)
        {
            List <WorldObject> allWorldObjects = Find.WorldObjects.AllWorldObjects;

            for (int i = 0; i < allWorldObjects.Count; i++)
            {
                ItemStashContentsComp component = allWorldObjects[i].GetComponent <ItemStashContentsComp>();
                if (component != null)
                {
                    ThingOwner contents = component.contents;
                    for (int j = 0; j < contents.Count; j++)
                    {
                        if (contents[j].def == thingDef)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        private bool PlayerOrItemStashHasAIPersonaCore()
        {
            List <Map> maps = Find.Maps;

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

            for (int j = 0; j < caravans.Count; j++)
            {
                if (caravans[j].IsPlayerControlled && CaravanInventoryUtility.HasThings(caravans[j], ThingDefOf.AIPersonaCore, 1, null))
                {
                    return(true);
                }
            }
            List <Site> sites = Find.WorldObjects.Sites;

            for (int k = 0; k < sites.Count; k++)
            {
                ItemStashContentsComp component = ((WorldObject)sites[k]).GetComponent <ItemStashContentsComp>();
                if (component != null)
                {
                    ThingOwner contents = component.contents;
                    for (int l = 0; l < contents.Count; l++)
                    {
                        if (contents[l].def == ThingDefOf.AIPersonaCore)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Esempio n. 7
0
        protected override void ScatterAt(IntVec3 loc, Map map, int count = 1)
        {
            CellRect      cellRect      = CellRect.CenteredOn(loc, 7, 7).ClipInsideMap(map);
            ResolveParams resolveParams = default(ResolveParams);

            resolveParams.rect    = cellRect;
            resolveParams.faction = map.ParentFaction;
            ItemStashContentsComp component = map.Parent.GetComponent <ItemStashContentsComp>();

            if (component != null && component.contents.Any)
            {
                resolveParams.stockpileConcreteContents = component.contents;
            }
            else
            {
                resolveParams.thingSetMakerDef = (this.thingSetMakerDef ?? ThingSetMakerDefOf.MapGen_DefaultStockpile);
            }
            BaseGen.globalSettings.map = map;
            BaseGen.symbolStack.Push("storage", resolveParams);
            BaseGen.Generate();
            MapGenerator.SetVar <CellRect>("RectOfInterest", cellRect);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            int tile = default(int);

            if (!RimWorld.Planet.TileFinder.TryFindNewSiteTile(out tile, distance.min, distance.max, false, true, -1))
            {
                return(false);
            }

            Faction factionEnemies, factionFriends;

            GenStep_Battlefield.TryFindFightingFactions(out factionEnemies, out factionFriends);
            if (factionEnemies == null || factionFriends == null)
            {
                return(false);
            }

            Site site;

            SitePartDef core;
            float       chance = Rand.Value;

            if (chance < 0.10f)
            {
                core = DefDatabase <SitePartDef> .GetNamedSilentFail("BanditCamp");
            }
            if (chance < 0.35f)
            {
                core = DefDatabase <SitePartDef> .GetNamedSilentFail("ItemStash");
            }
            else if (chance < 0.50f)
            {
                core = SitePartDefOf.PreciousLump;
            }
            else if (chance < 0.90f)
            {
                core = null;
            }
            else
            {
                core = DefDatabase <SitePartDef> .AllDefs.RandomElement();
            }

            List <SitePartDef> parts = new List <SitePartDef>();

            if (Rand.Value < 0.40f)
            {
                parts = GetRandomSitePartDefs;
            }
            if (core != null)
            {
                parts.Add(core);
            }

            // And allways add the Misc_Battlefield part
            SitePartDef sitePartDef_Battlefield = (DefDatabase <SitePartDef> .GetNamed("Misc_Battlefield"));

            parts.Add(sitePartDef_Battlefield);

            site = SiteMaker.MakeSite(parts, tile, factionEnemies);

            if (site != null)
            {
                // Try to add a railgun :)
                ThingDef railgunDef = DefDatabase <ThingDef> .GetNamedSilentFail("Gun_RailgunMKI");

                if (railgunDef != null && Rand.Value < 0.35)
                {
                    Thing railgun = null;
                    railgun = ThingMaker.MakeThing(railgunDef);

                    SitePartDef possible1 = DefDatabase <SitePartDef> .GetNamedSilentFail("ItemStash");

                    SitePartDef possible2 = DefDatabase <SitePartDef> .GetNamedSilentFail("BanditCamp");

                    ItemStashContentsComp itemStash = site.GetComponent <ItemStashContentsComp>();
                    if (itemStash != null && parts.Contains(possible1) || parts.Contains(possible2) || parts.Contains(SitePartDefOf.Outpost))
                    {
                        if (railgun != null)
                        {
                            itemStash.contents.TryAdd(railgun);
                        }
                    }
                }

                // Add a site timeout ???
                site.GetComponent <TimeoutComp>().StartTimeout(Rand.RangeInclusive(10, 30) * 60000);

                Find.WorldObjects.Add(site);
                Find.LetterStack.ReceiveLetter("Misc_Incident_Label_Battlefield".Translate(), "Misc_Incident_Message_Battlefield".Translate(), LetterDefOf.NeutralEvent, site);

                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        private void FoundAnomaly()
        {
            int min = AnomalyDistanceMin;
            int max = AnomalyDistanceMax;

            int tile2 = base.parent.Tile;
            int tile  = default(int);

            if (!TryFindNewAnomalyTile(out tile, min, max, false, true, tile2))
            {
                return;
            }

            Site site;
            //bool spacerUsable = false;

            List <SitePartDef> siteParts = new List <SitePartDef>();

            if (Rand.Chance(Props.chanceForNoSitePart))
            {
                siteParts.Add(GetRandomSiteCoreDef());

                site = SiteMaker.TryMakeSite(siteParts, tile, false, null, true);
                //spacerUsable = true;
            }
            else
            {
                siteParts.Add(GetRandomSiteCoreDef());
                siteParts.AddRange(GetRandomSitePartDefs);
                site = SiteMaker.TryMakeSite(siteParts, tile, true, null, false);
            }

            //// if spacerUsable -> 35% chance that the faction is spacer
            //if (site != null && spacerUsable && Rand.Chance(0.35f))
            //{
            //    Faction spacerFaction = null;
            //    if ((from x in Find.FactionManager.AllFactionsListForReading
            //         where x.def == FactionDefOf.Ancients || x.def == FactionDefOf.AncientsHostile
            //         select x).TryRandomElement(out spacerFaction))
            //        site.SetFaction(spacerFaction);
            //}

            if (site != null)
            {
                // Try to add a railgun :)
                Thing    railgun    = null;
                ThingDef railgunDef = DefDatabase <ThingDef> .GetNamedSilentFail(railgunDefName);

                if (railgunDef != null &&
                    site.Faction != null && site.Faction.def.techLevel >= TechLevel.Industrial &&
                    Rand.Value < 0.10)
                {
                    railgun = ThingMaker.MakeThing(railgunDef);
                }


                List <Thing> items = null;
                // Improved Sensors -> Add Items
                if (HasImprovedSensors)
                {
                    ItemStashContentsComp itemStash = site.GetComponent <ItemStashContentsComp>();
                    if (itemStash != null && siteParts.Contains(DefDatabase <SitePartDef> .GetNamedSilentFail(defName_ItemStash)))
                    {
                        items = GenerateItems(site.Faction, StorytellerUtility.DefaultSiteThreatPointsNow());
                        itemStash.contents.TryAddRangeOrTransfer(items);

                        if (railgun != null)
                        {
                            itemStash.contents.TryAdd(railgun);
                        }
                    }
                }

                //site.Tile = tile;

                // Add a site timeout ???
                site.GetComponent <TimeoutComp>().StartTimeout(Rand.RangeInclusive(15, 60) * 60000);

                Find.WorldObjects.Add(site);
                Find.LetterStack.ReceiveLetter("TacticalComputer_LetterLabel_AnomalyFound".Translate(), "TacticalComputer_Message_AnomalyFound".Translate(), LetterDefOf.PositiveEvent, site);
            }
        }
Esempio n. 10
0
        private void FoundAnomaly()
        {
            int tile;

            if (!TryFindNewAnomalyTile(out tile))
            {
                return;
            }

            Site site;
            bool spacerUsable = false;

            if (Rand.Chance(Props.chanceForNoSitePart))
            {
                site         = SiteMaker.TryMakeSite(GetRandomSiteCoreDef(), null, false, null);
                spacerUsable = true;
            }
            else
            {
                site = SiteMaker.TryMakeSite(GetRandomSiteCoreDef(), GetRandomSitePartDefs, true, null);
            }

            // if spacerUsable -> 35% chance that the faction is spacer
            if (site != null && spacerUsable && Rand.Chance(0.35f))
            {
                Faction spacerFaction = null;
                if ((from x in Find.FactionManager.AllFactionsListForReading
                     where x.def == FactionDefOf.Spacer || x.def == FactionDefOf.SpacerHostile
                     select x).TryRandomElement(out spacerFaction))
                {
                    site.SetFaction(spacerFaction);
                }
            }

            if (site != null)
            {
                // Try to add a railgun :)
                Thing    railgun    = null;
                ThingDef railgunDef = DefDatabase <ThingDef> .GetNamedSilentFail(railgunDefName);

                if (railgunDef != null &&
                    site.Faction != null && site.Faction.def.techLevel >= TechLevel.Industrial &&
                    Rand.Value < 0.10)
                {
                    railgun = ThingMaker.MakeThing(railgunDef);
                }


                List <Thing> items = null;
                // Improved Sensors -> Add Items
                if (HasImprovedSensors)
                {
                    ItemStashContentsComp itemStash = site.GetComponent <ItemStashContentsComp>();
                    if (itemStash != null && site.core.defName == defName_ItemStash)
                    {
                        items = GenerateItems(site.Faction);
                        itemStash.contents.TryAddRangeOrTransfer(items);

                        if (railgun != null)
                        {
                            itemStash.contents.TryAdd(railgun);
                        }
                    }
                }


                site.Tile = tile;
                Find.WorldObjects.Add(site);
                Find.LetterStack.ReceiveLetter("TacticalComputer_LetterLabel_AnomalyFound".Translate(), "TacticalComputer_Message_AnomalyFound".Translate(), LetterDefOf.PositiveEvent, site);

                // Add a site timeout ???
                site.GetComponent <TimeoutComp>().StartTimeout(Rand.RangeInclusive(15, 60) * 60000);
            }
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            int tile = default(int);

            if (!RimWorld.Planet.TileFinder.TryFindNewSiteTile(out tile, distance.min, distance.max, false))
            {
                return(false);
            }

            Site site;

            SiteCoreDef core;
            float       chance = Rand.Value;

            if (chance < 0.25f)
            {
                core = SiteCoreDefOf.ItemStash;
            }
            else if (chance < 0.40f)
            {
                core = SiteCoreDefOf.PreciousLump;
            }
            else if (chance < 0.95f)
            {
                core = SiteCoreDefOf.Nothing;
            }
            else
            {
                core = DefDatabase <SiteCoreDef> .AllDefs.RandomElement();
            }

            List <SitePartDef> parts = new List <SitePartDef>();

            if (Rand.Value < 0.40f)
            {
                parts = GetRandomSitePartDefs;
            }

            // And allways add the Misc_Battlefield part
            parts.Add(DefDatabase <SitePartDef> .GetNamed("Misc_Battlefield"));

            site = SiteMaker.TryMakeSite(core, parts, tile, false);

            if (site != null)
            {
                // Try to add a railgun :)
                Thing    railgun    = null;
                ThingDef railgunDef = DefDatabase <ThingDef> .GetNamedSilentFail("Gun_RailgunMKI");

                if (railgunDef != null && Rand.Value < 0.15)
                {
                    railgun = ThingMaker.MakeThing(railgunDef);

                    ItemStashContentsComp itemStash = site.GetComponent <ItemStashContentsComp>();
                    if (itemStash != null && site.core.def == SiteCoreDefOf.ItemStash)
                    {
                        if (railgun != null)
                        {
                            itemStash.contents.TryAdd(railgun);
                        }
                    }
                }

                // Add a site timeout ???
                site.GetComponent <TimeoutComp>().StartTimeout(Rand.RangeInclusive(10, 30) * 60000);

                Find.WorldObjects.Add(site);
                Find.LetterStack.ReceiveLetter("Misc_Incident_Label_Battlefield".Translate(), "Misc_Incident_Message_Battlefield".Translate(), LetterDefOf.NeutralEvent, site);

                return(true);
            }
            return(false);
        }