public static ThingDef TryFindRandomShellDef(ThingDef turret, bool allowEMP = true, bool mustHarmHealth = true, TechLevel techLevel = TechLevel.Undefined, bool allowAntigrainWarhead = false, float maxMarketValue = -1f)
        {
            ThingDef result;

            if (!TurretGunUtility.NeedsShells(turret))
            {
                result = null;
            }
            else
            {
                ThingFilter fixedFilter = turret.building.turretGunDef.building.fixedStorageSettings.filter;
                ThingDef    thingDef;
                if ((from x in DefDatabase <ThingDef> .AllDefsListForReading
                     where fixedFilter.Allows(x) && (allowEMP || x.projectileWhenLoaded.projectile.damageDef != DamageDefOf.EMP) && (!mustHarmHealth || x.projectileWhenLoaded.projectile.damageDef.harmsHealth) && (techLevel == TechLevel.Undefined || x.techLevel <= techLevel) && (allowAntigrainWarhead || x != ThingDefOf.Shell_AntigrainWarhead) && (maxMarketValue < 0f || x.BaseMarketValue <= maxMarketValue)
                     select x).TryRandomElement(out thingDef))
                {
                    result = thingDef;
                }
                else
                {
                    result = null;
                }
            }
            return(result);
        }
Beispiel #2
0
        public override void LordToilTick()
        {
            base.LordToilTick();
            LordToilData_Siege data = Data;

            if (lord.ticksInToil == 450)
            {
                lord.CurLordToil.UpdateAllDuties();
            }
            if (lord.ticksInToil > 450 && lord.ticksInToil % 500 == 0)
            {
                UpdateAllDuties();
            }
            if (Find.TickManager.TicksGame % 500 != 0)
            {
                return;
            }
            if (!Frames.Where((Frame frame) => !frame.Destroyed).Any() && !data.blueprints.Where((Blueprint blue) => !blue.Destroyed).Any() && !base.Map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial).Any((Thing b) => b.Faction == lord.faction && b.def.building.buildingTags.Contains("Artillery")))
            {
                lord.ReceiveMemo("NoArtillery");
                return;
            }
            int num  = GenRadial.NumCellsInRadius(20f);
            int num2 = 0;
            int num3 = 0;

            for (int i = 0; i < num; i++)
            {
                IntVec3 c = data.siegeCenter + GenRadial.RadialPattern[i];
                if (!c.InBounds(base.Map))
                {
                    continue;
                }
                List <Thing> thingList = c.GetThingList(base.Map);
                for (int j = 0; j < thingList.Count; j++)
                {
                    if (thingList[j].def.IsShell)
                    {
                        num2 += thingList[j].stackCount;
                    }
                    if (thingList[j].def == ThingDefOf.MealSurvivalPack)
                    {
                        num3 += thingList[j].stackCount;
                    }
                }
            }
            if (num2 < 4)
            {
                ThingDef thingDef = TurretGunUtility.TryFindRandomShellDef(ThingDefOf.Turret_Mortar, allowEMP: false, mustHarmHealth: true, lord.faction.def.techLevel, allowAntigrainWarhead: false, 250f);
                if (thingDef != null)
                {
                    DropSupplies(thingDef, 6);
                }
            }
            if (num3 < 5)
            {
                DropSupplies(ThingDefOf.MealSurvivalPack, 12);
            }
        }
        public override void Init()
        {
            base.Init();
            LordToilData_Siege data = this.Data;

            data.baseRadius = Mathf.InverseLerp(14f, 25f, (float)this.lord.ownedPawns.Count / 50f);
            data.baseRadius = Mathf.Clamp(data.baseRadius, 14f, 25f);
            List <Thing> list = new List <Thing>();

            foreach (Blueprint_Build current in SiegeBlueprintPlacer.PlaceBlueprints(data.siegeCenter, base.Map, this.lord.faction, data.blueprintPoints))
            {
                data.blueprints.Add(current);
                foreach (ThingDefCountClass cost in current.MaterialsNeeded())
                {
                    Thing thing = list.FirstOrDefault((Thing t) => t.def == cost.thingDef);
                    if (thing != null)
                    {
                        thing.stackCount += cost.count;
                    }
                    else
                    {
                        Thing thing2 = ThingMaker.MakeThing(cost.thingDef, null);
                        thing2.stackCount = cost.count;
                        list.Add(thing2);
                    }
                }
                ThingDef thingDef = current.def.entityDefToBuild as ThingDef;
                if (thingDef != null)
                {
                    ThingDef  turret    = thingDef;
                    bool      allowEMP  = false;
                    TechLevel techLevel = this.lord.faction.def.techLevel;
                    ThingDef  thingDef2 = TurretGunUtility.TryFindRandomShellDef(turret, allowEMP, true, techLevel, false, 250f);
                    if (thingDef2 != null)
                    {
                        Thing thing3 = ThingMaker.MakeThing(thingDef2, null);
                        thing3.stackCount = 5;
                        list.Add(thing3);
                    }
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                list[i].stackCount = Mathf.CeilToInt((float)list[i].stackCount * Rand.Range(1f, 1.2f));
            }
            List <List <Thing> > list2 = new List <List <Thing> >();

            for (int j = 0; j < list.Count; j++)
            {
                while (list[j].stackCount > list[j].def.stackLimit)
                {
                    int   num    = Mathf.CeilToInt((float)list[j].def.stackLimit * Rand.Range(0.9f, 0.999f));
                    Thing thing4 = ThingMaker.MakeThing(list[j].def, null);
                    thing4.stackCount   = num;
                    list[j].stackCount -= num;
                    list.Add(thing4);
                }
            }
            List <Thing> list3 = new List <Thing>();

            for (int k = 0; k < list.Count; k++)
            {
                list3.Add(list[k]);
                if (k % 2 == 1 || k == list.Count - 1)
                {
                    list2.Add(list3);
                    list3 = new List <Thing>();
                }
            }
            List <Thing> list4 = new List <Thing>();
            int          num2  = Mathf.RoundToInt(LordToil_Siege.MealCountRangePerRaider.RandomInRange * (float)this.lord.ownedPawns.Count);

            for (int l = 0; l < num2; l++)
            {
                Thing item = ThingMaker.MakeThing(ThingDefOf.MealSurvivalPack, null);
                list4.Add(item);
            }
            list2.Add(list4);
            DropPodUtility.DropThingGroupsNear(data.siegeCenter, base.Map, list2, 110, false, false, true);
            data.desiredBuilderFraction = LordToil_Siege.BuilderCountFraction.RandomInRange;
        }
        public override void LordToilTick()
        {
            base.LordToilTick();
            LordToilData_Siege data = this.Data;

            if (this.lord.ticksInToil == 450)
            {
                this.lord.CurLordToil.UpdateAllDuties();
            }
            if (this.lord.ticksInToil > 450 && this.lord.ticksInToil % 500 == 0)
            {
                this.UpdateAllDuties();
            }
            if (Find.TickManager.TicksGame % 500 == 0)
            {
                if (!(from frame in this.Frames
                      where !frame.Destroyed
                      select frame).Any <Frame>())
                {
                    if (!(from blue in data.blueprints
                          where !blue.Destroyed
                          select blue).Any <Blueprint>() && !base.Map.listerThings.ThingsInGroup(ThingRequestGroup.BuildingArtificial).Any((Thing b) => b.Faction == this.lord.faction && b.def.building.buildingTags.Contains("Artillery")))
                    {
                        this.lord.ReceiveMemo("NoArtillery");
                        return;
                    }
                }
                int num  = GenRadial.NumCellsInRadius(20f);
                int num2 = 0;
                int num3 = 0;
                for (int i = 0; i < num; i++)
                {
                    IntVec3 c = data.siegeCenter + GenRadial.RadialPattern[i];
                    if (c.InBounds(base.Map))
                    {
                        List <Thing> thingList = c.GetThingList(base.Map);
                        for (int j = 0; j < thingList.Count; j++)
                        {
                            if (thingList[j].def.IsShell)
                            {
                                num2 += thingList[j].stackCount;
                            }
                            if (thingList[j].def == ThingDefOf.MealSurvivalPack)
                            {
                                num3 += thingList[j].stackCount;
                            }
                        }
                    }
                }
                if (num2 < 4)
                {
                    ThingDef  turret_Mortar = ThingDefOf.Turret_Mortar;
                    bool      allowEMP      = false;
                    TechLevel techLevel     = this.lord.faction.def.techLevel;
                    ThingDef  thingDef      = TurretGunUtility.TryFindRandomShellDef(turret_Mortar, allowEMP, true, techLevel, false, 250f);
                    if (thingDef != null)
                    {
                        this.DropSupplies(thingDef, 10);
                    }
                }
                if (num3 < 5)
                {
                    this.DropSupplies(ThingDefOf.MealSurvivalPack, 12);
                }
            }
        }