Beispiel #1
0
        public override void CompTick()
        {
            //fix the bug with the wrong site and comp
            base.CompTick();

            if (ranDebug != true)
            {
                List <WorldObject> wObjects = Find.WorldObjects.AllWorldObjects;
                foreach (WorldObject obj in wObjects)
                {
                    DefeatAllEnemiesQuestComp comp = obj.GetComponent <DefeatAllEnemiesQuestComp>();
                    if (comp != null)
                    {
                        if (comp.requestingFaction == null)
                        {
                            comp.StopQuest();
                        }
                    }
                }
            }

            /*
             * MapParent mapParent = this.parent as MapParent;
             * if (mapParent != null)
             * {
             *  DefeatAllEnemiesQuestComp comp = mapParent.GetComponent<DefeatAllEnemiesQuestComp>();
             *  if (comp != null)
             *  {
             *      comp.StopQuest();
             *  }
             * }
             */
        }
Beispiel #2
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);
        }
Beispiel #3
0
        private bool AnyQuestExistsFrom(Faction faction)
        {
            List <Site> sites = Find.WorldObjects.Sites;

            for (int i = 0; i < sites.Count; i++)
            {
                DefeatAllEnemiesQuestComp component = sites[i].GetComponent <DefeatAllEnemiesQuestComp>();
                if (component != null && component.Active && component.requestingFaction == faction)
                {
                    return(true);
                }
            }
            return(false);
        }
        public static bool PlayerOrQuestRewardHas(ThingDef thingDef, int count = 1)
        {
            if (count <= 0)
            {
                return(true);
            }
            int        num  = 0;
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                if (count == 1)
                {
                    if (maps[i].listerThings.ThingsOfDef(thingDef).Count > 0)
                    {
                        return(true);
                    }
                    continue;
                }
                num += Mathf.Max(maps[i].resourceCounter.GetCount(thingDef), maps[i].listerThings.ThingsOfDef(thingDef).Count);
                if (num >= count)
                {
                    return(true);
                }
            }
            List <Caravan> caravans = Find.WorldObjects.Caravans;

            for (int j = 0; j < caravans.Count; j++)
            {
                if (!caravans[j].IsPlayerControlled)
                {
                    continue;
                }
                List <Thing> list = CaravanInventoryUtility.AllInventoryItems(caravans[j]);
                for (int k = 0; k < list.Count; k++)
                {
                    if (list[k].def == thingDef)
                    {
                        num += list[k].stackCount;
                        if (num >= count)
                        {
                            return(true);
                        }
                    }
                }
            }
            List <Site> sites = Find.WorldObjects.Sites;

            for (int l = 0; l < sites.Count; l++)
            {
                for (int m = 0; m < sites[l].parts.Count; m++)
                {
                    SitePart sitePart = sites[l].parts[m];
                    if (sitePart.things == null)
                    {
                        continue;
                    }
                    for (int n = 0; n < sitePart.things.Count; n++)
                    {
                        if (sitePart.things[n].def == thingDef)
                        {
                            num += sitePart.things[n].stackCount;
                            if (num >= count)
                            {
                                return(true);
                            }
                        }
                    }
                }
                DefeatAllEnemiesQuestComp component = sites[l].GetComponent <DefeatAllEnemiesQuestComp>();
                if (component == null)
                {
                    continue;
                }
                ThingOwner rewards = component.rewards;
                for (int num2 = 0; num2 < rewards.Count; num2++)
                {
                    if (rewards[num2].def == thingDef)
                    {
                        num += rewards[num2].stackCount;
                        if (num >= count)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        public static bool PlayerOrQuestRewardHas(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)
                {
                    continue;
                }
                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++)
            {
                for (int n = 0; n < sites[m].parts.Count; n++)
                {
                    SitePart sitePart = sites[m].parts[n];
                    if (sitePart.things == null)
                    {
                        continue;
                    }
                    for (int num = 0; num < sitePart.things.Count; num++)
                    {
                        if (thingFilter.Allows(sitePart.things[num]))
                        {
                            return(true);
                        }
                    }
                }
                DefeatAllEnemiesQuestComp component = sites[m].GetComponent <DefeatAllEnemiesQuestComp>();
                if (component == null)
                {
                    continue;
                }
                ThingOwner rewards = component.rewards;
                for (int num2 = 0; num2 < rewards.Count; num2++)
                {
                    if (thingFilter.Allows(rewards[num2]))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }