Exemplo n.º 1
0
        public static void AddAmmoCE(ThingDef Weapon, ref List <ScenPart> parts, int count = -1, int mult = 1, bool logging = false)
        {
            if (logging)
            {
                Log.Message("Trying to add ammo for " + Weapon);
            }
            CombatExtended.CompProperties_AmmoUser ammo = Weapon.GetCompProperties <CombatExtended.CompProperties_AmmoUser>();
            foreach (var item in ammo.ammoSet.ammoTypes)
            {
                CombatExtended.AmmoDef ammoDef = item.ammo;
                if (count == -1)
                {
                    bool hasammo = false;
                    foreach (ScenPart scenpart in parts.Where(x => x.def == ScenPartDefOf.StartingThing_Defined))
                    {
                        ThingDef td = Traverse.Create(scenpart).Field("thingDef").GetValue <ThingDef>();
                        if (td == ammoDef)
                        {
                            hasammo = true;
                            break;
                        }
                    }
                    if (hasammo)
                    {
                        continue;
                    }
                }
                int c = count == -1 ? item.ammo.stackLimit : Math.Min(count, item.ammo.stackLimit);
                if (logging)
                {
                    Log.Message("Trying to add " + mult + " stacks of " + ammoDef + " X " + c);
                }
                for (int i = 0; i < mult; i++)
                {
                    ScenPart_StartingThing_Define _Defined = new ScenPart_StartingThing_Define()
                    {
                        def = ScenPartDefOf.StartingThing_Defined
                    };
                    _Defined.ThingDef = ammoDef;
                    _Defined.Count    = c;
                    if (ammoDef.MadeFromStuff)
                    {
                        ThingDef stuffdef = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsStuff && ammoDef.stuffCategories.Any(y => x.stuffProps.categories.Contains(y))).RandomElement();

                        if (stuffdef != null)
                        {
                            _Defined.ThingDefStuff = stuffdef;
                        }
                    }
                    parts.Add(_Defined);
                    if (count != -1)
                    {
                        break;
                    }
                }
            }
        }
        public static void TryAddTestingWeaponsToScenario(ScenarioDef ScenDef, List <string> tags)
        {
            List <ThingDef> things = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(x => x.IsRangedWeapon && x.defName.StartsWith("OG") && (tags.Any(y => x.weaponTags.ToCommaList().Contains(y)) || tags.Any(y => x.defName.Contains(y))));

            List <ScenPart> parts = ScenDef.scenario.parts;

            foreach (ThingDef Weapon in things)
            {
                bool hasweapon = false;
                foreach (ScenPart scenpart in parts.Where(x => x.def == ScenPartDefOf.StartingThing_Defined))
                {
                    ScenPart_StartingThing_Defined startingThing = scenpart as ScenPart_StartingThing_Defined;
                    if (startingThing != null)
                    {
                        ThingDef td = startingThing.thingDef;//
                        if (td == Weapon)
                        {
                            hasweapon = true;
                            break;
                        }
                    }
                }
                if (hasweapon)
                {
                    continue;
                }
                ScenPart_StartingThing_Define StartingThing = new ScenPart_StartingThing_Define()
                {
                    def = ScenPartDefOf.StartingThing_Defined
                };
                if (Weapon.MadeFromStuff)
                {
                    ThingDef stuffdef = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsStuff && Weapon.stuffCategories.Any(y => x.stuffProps.categories.Contains(y))).RandomElement();

                    if (stuffdef != null)
                    {
                        StartingThing.ThingDefStuff = stuffdef;
                    }
                }
                StartingThing.ThingDef = Weapon;
                parts.Add(StartingThing);
            }
        }
        public static void TryAddLaserWeaponsToScenario(ScenarioDef ScenDef)
        {
            List <ThingDef> things = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(x => x.IsRangedWeapon && x.Verbs.Any(z => z.defaultProjectile as LaserBeamDef != null));

            foreach (ThingDef Weapon in things)
            {
                bool            hasweapon = false;
                List <ScenPart> parts     = ScenDef.scenario.parts;
                foreach (ScenPart scenpart in parts.Where(x => x.def == ScenPartDefOf.StartingThing_Defined))
                {
                    ScenPart_StartingThing_Defined startingThing = scenpart as ScenPart_StartingThing_Defined;
                    if (startingThing != null)
                    {
                        ThingDef td = startingThing.thingDef;//
                        if (td == Weapon)
                        {
                            hasweapon = true;
                            break;
                        }
                    }
                }
                if (hasweapon)
                {
                    continue;
                }
                ScenPart_StartingThing_Define StartingThing = new ScenPart_StartingThing_Define()
                {
                    def = ScenPartDefOf.StartingThing_Defined
                };
                if (Weapon.MadeFromStuff)
                {
                    ThingDef stuffdef = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsStuff && Weapon.stuffCategories.Any(y => x.stuffProps.categories.Contains(y))).RandomElement();

                    if (stuffdef != null)
                    {
                        StartingThing.ThingDefStuff = stuffdef;
                    }
                }
                StartingThing.ThingDef = Weapon;
                parts.Add(StartingThing);
            }
        }
        public static void TryAddWeaponsToScenario(ScenarioDef ScenDef, string Tag)
        {
            List <ThingDef> things = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(x => ((x.PlayerAcquirable || Tag == "TY") && (x.IsWeapon || x.IsApparel) && x.defName.Contains("OG" + Tag) && !x.defName.Contains("TOGGLEDEF_S")));

            foreach (ThingDef Weapon in things)
            {
                bool            hasweapon = false;
                List <ScenPart> parts     = ScenDef.scenario.parts;
                foreach (ScenPart scenpart in parts.Where(x => x.def == ScenPartDefOf.StartingThing_Defined))
                {
                    ScenPart_StartingThing_Defined startingThing = scenpart as ScenPart_StartingThing_Defined;
                    if (startingThing != null)
                    {
                        ThingDef td = startingThing.thingDef;//
                        if (td == Weapon)
                        {
                            hasweapon = true;
                            break;
                        }
                    }
                }
                if (hasweapon)
                {
                    continue;
                }
                ScenPart_StartingThing_Define StartingThing = new ScenPart_StartingThing_Define()
                {
                    def = ScenPartDefOf.StartingThing_Defined
                };
                if (Weapon.MadeFromStuff)
                {
                    ThingDef stuffdef = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsStuff && Weapon.stuffCategories.Any(y => x.stuffProps.categories.Contains(y))).RandomElement();

                    if (stuffdef != null)
                    {
                        StartingThing.ThingDefStuff = stuffdef;
                    }
                }
                StartingThing.ThingDef = Weapon;
                parts.Add(StartingThing);
            }
        }
        public static void TryAddRendingWeaponsToScenario(ScenarioDef ScenDef)
        {
            List <ThingDef> things = DefDatabase <ThingDef> .AllDefsListForReading.FindAll(x => x.IsWeapon && x.rendingWeapon());

            foreach (ThingDef Weapon in things)
            {
                bool            hasweapon = false;
                List <ScenPart> parts     = Traverse.Create(ScenDef.scenario).Field("parts").GetValue <List <ScenPart> >();
                foreach (ScenPart scenpart in parts.Where(x => x.def == ScenPartDefOf.StartingThing_Defined))
                {
                    ThingDef td = Traverse.Create(scenpart).Field("thingDef").GetValue <ThingDef>();
                    if (td == Weapon)
                    {
                        hasweapon = true;
                        break;
                    }
                }
                if (hasweapon)
                {
                    continue;
                }
                ScenPart_StartingThing_Define StartingThing = new ScenPart_StartingThing_Define()
                {
                    def = ScenPartDefOf.StartingThing_Defined
                };
                if (Weapon.MadeFromStuff)
                {
                    ThingDef stuffdef = DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.IsStuff && Weapon.stuffCategories.Any(y => x.stuffProps.categories.Contains(y))).RandomElement();

                    if (stuffdef != null)
                    {
                        StartingThing.ThingDefStuff = stuffdef;
                    }
                }
                StartingThing.ThingDef = Weapon;
                parts.Add(StartingThing);
            }
        }