Exemplo n.º 1
0
 static List <ThingStuffPair> AllApparelPairs()
 {
     if (_allApparelPairs == null)
     {
         _allApparelPairs = ThingStuffPair.AllWith((ThingDef td) => td.IsApparel)
                            .Where(pair =>
         {
             var def = pair.thing;
             if (def.IsApparel == false)
             {
                 return(false);
             }
             if (def.IsZombieDef())
             {
                 return(false);
             }
             if (def == ThingDefOf.Apparel_ShieldBelt)
             {
                 return(false);
             }
             if (def == ThingDefOf.Apparel_SmokepopBelt)
             {
                 return(false);
             }
             var path = def.apparel.wornGraphicPath;
             return(path != null && path.Length > 0);
         })
                            .ToList();
     }
     return(_allApparelPairs);
 }
Exemplo n.º 2
0
        public static Thing MakeThingWithoutID(this ThingStuffPair pair)
        {
            if (pair.thing.MadeFromStuff && pair.stuff == null)
            {
                pair.stuff = AwesomeInventoryStuffDefOf.AwesomeInventoryGenericResource;
            }

            if (pair.stuff != null && !pair.stuff.IsStuff)
            {
                Log.Error("MakeThing error: Tried to make " + pair.thing + " from " + pair.stuff + " which is not a stuff. Assigning default.");
                pair.stuff = GenStuff.DefaultStuffFor(pair.thing);
            }

            if (!pair.thing.MadeFromStuff && pair.stuff != null)
            {
                Log.Error("MakeThing error: " + pair.thing + " is not madeFromStuff but stuff=" + pair.stuff + ". Setting to null.");
                pair.stuff = null;
            }

            Thing thing = (Thing)Activator.CreateInstance(pair.thing.thingClass);

            thing.def = pair.thing;
            thing.SetStuffDirect(pair.stuff);
            if (thing.def.useHitPoints)
            {
                thing.HitPoints = thing.MaxHitPoints;
            }

            if (thing is ThingWithComps thingWithComps)
            {
                thingWithComps.InitializeComps();
            }

            return(thing);
        }
 public static void Postfix(ThingStuffPair __instance, ref float __result)
 {
     if (__instance.stuff != null)
     {
         __result = ModifyCommonalityOf(__instance.thing, __instance.stuff, __result);
     }
 }
        public static void Reset()
        {
            Predicate <ThingDef> isShield = (ThingDef td) => td.GetCompProperties <CompProperties_Shield>() is CompProperties_Shield shieldProps && !shieldProps.shieldTags.NullOrEmpty();

            allShieldPairs = ThingStuffPair.AllWith(isShield);
            using (IEnumerator <ThingDef> enumerator = (from td in DefDatabase <ThingDef> .AllDefs where isShield(td) select td).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ThingDef thingDef = enumerator.Current;
                    float    num      = (from pa in allShieldPairs where pa.thing == thingDef select pa).Sum((ThingStuffPair pa) => pa.Commonality);
                    float    num2     = thingDef.generateCommonality / num;
                    if (num2 != 1f)
                    {
                        for (int i = 0; i < allShieldPairs.Count; i++)
                        {
                            ThingStuffPair thingStuffPair = allShieldPairs[i];
                            if (thingStuffPair.thing == thingDef)
                            {
                                allShieldPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                            }
                        }
                    }
                }
                enumerator.Dispose();
            }
        }
Exemplo n.º 5
0
 public static void FillPossibleObjectLists()
 {
     if (GenList.NullOrEmpty <ThingStuffPair>(MapGenUtility.weapons))
     {
         MapGenUtility.weapons = ThingStuffPair.AllWith((ThingDef td) => td.IsWeapon && !GenList.NullOrEmpty <string>(td.weaponTags));
     }
 }
        // Copied from PawnWeaponGenerator.Reset() - 1:1 COPY!!! (Plus Shields)
        public static void Reset()
        {
            // Initialize weapons
            Predicate <ThingDef> isWeapon = (ThingDef td) => td.equipmentType == EquipmentType.Primary && !td.weaponTags.NullOrEmpty <string>();

            allWeaponPairs = ThingStuffPair.AllWith(isWeapon);
            foreach (ThingDef thingDef in from td in DefDatabase <ThingDef> .AllDefs
                     where isWeapon(td)
                     select td)
            {
                float num  = allWeaponPairs.Where((ThingStuffPair pa) => pa.thing == thingDef).Sum((ThingStuffPair pa) => pa.Commonality);
                float num2 = thingDef.generateCommonality / num;
                if (num2 != 1f)
                {
                    for (int i = 0; i < allWeaponPairs.Count; i++)
                    {
                        ThingStuffPair thingStuffPair = allWeaponPairs[i];
                        if (thingStuffPair.thing == thingDef)
                        {
                            allWeaponPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                        }
                    }
                }
            }

            // Initialize shields
            allShieldPairs = ThingStuffPair.AllWith(td => td.thingClass == typeof(Apparel_Shield));
        }
Exemplo n.º 7
0
 public static void getHeaviestWeapons(out float weightMelee, out float weightRanged)
 {
     weightMelee  = float.MinValue;
     weightRanged = float.MinValue;
     foreach (ThingStuffPair weapon in ThingStuffPair.AllWith(t => t.IsWeapon))
     {
         if (!weapon.thing.PlayerAcquirable)
         {
             continue;
         }
         float mass = weapon.thing.GetStatValueAbstract(StatDefOf.Mass);
         if (weapon.thing.IsRangedWeapon)
         {
             if (mass > weightRanged)
             {
                 weightRanged = mass;
             }
         }
         else if (weapon.thing.IsMeleeWeapon)
         {
             if (mass > weightMelee)
             {
                 weightMelee = mass;
             }
         }
     }
 }
Exemplo n.º 8
0
        public static void Reset()
        {
            //Log.Message("reset called");
            hasBeenReset = true;
            Predicate <ThingDef> isWeapon = (ThingDef td) => td.equipmentType == EquipmentType.Primary && !td.weaponTags.NullOrEmpty <string>();

            allWeaponPairs = ThingStuffPair.AllWith(isWeapon);
            foreach (ThingDef thingDef in from td in DefDatabase <ThingDef> .AllDefs
                     where isWeapon(td)
                     select td)
            {
                float num  = allWeaponPairs.Where((ThingStuffPair pa) => pa.thing == thingDef).Sum((ThingStuffPair pa) => pa.Commonality);
                float num2 = thingDef.generateCommonality / num;
                if (num2 != 1f)
                {
                    for (int i = 0; i < allWeaponPairs.Count; i++)
                    {
                        ThingStuffPair thingStuffPair = allWeaponPairs[i];
                        if (thingStuffPair.thing == thingDef)
                        {
                            allWeaponPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Resets the shield generator.
        /// </summary>
        public static void Reset()
        {
            Predicate <ThingDef> isShield = (ThingDef td) => td.equipmentType != EquipmentType.Primary && td.canBeSpawningInventory && td.HasComp(typeof(CompShield));

            allShieldPairs = ThingStuffPair.AllWith(isShield);

            using (IEnumerator <ThingDef> enumerator = (from td in DefDatabase <ThingDef> .AllDefs
                                                        where isShield(td)
                                                        select td).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    ThingDef thingDef = enumerator.Current;
                    float    num      = (from pa in allShieldPairs
                                         where pa.thing == thingDef
                                         select pa).Sum((ThingStuffPair pa) => pa.Commonality);
                    float num2 = thingDef.generateCommonality / num;
                    if (num2 != 1f)
                    {
                        for (int i = 0; i < allShieldPairs.Count; i++)
                        {
                            ThingStuffPair thingStuffPair = allShieldPairs[i];
                            if (thingStuffPair.thing == thingDef)
                            {
                                allShieldPairs[i] = new ThingStuffPair(thingStuffPair.thing, thingStuffPair.stuff, thingStuffPair.commonalityMultiplier * num2);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
        public bool IsCurrentWeaponForced(bool alsoCountPreferredOrDefault)
        {
            if (Owner == null || Owner.Dead || Owner.equipment == null)
            {
                return(false);
            }
            ThingStuffPair?currentWeaponN = Owner.equipment.Primary?.toThingStuffPair();

            if (currentWeaponN == null)
            {
                if (Owner.Drafted && ForcedUnarmedWhileDrafted)
                {
                    return(true);
                }
                else if (ForcedUnarmed)
                {
                    return(true);
                }
                else if (alsoCountPreferredOrDefault && PreferredUnarmed)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                ThingStuffPair currentWeapon = currentWeaponN.Value;
                if (Owner.Drafted && ForcedWeaponWhileDrafted == currentWeapon)
                {
                    return(true);
                }
                else if (ForcedWeapon == currentWeapon)
                {
                    return(true);
                }
                else if (alsoCountPreferredOrDefault)
                {
                    if (currentWeapon.thing.IsMeleeWeapon && PreferredMeleeWeapon == currentWeapon)
                    {
                        return(true);
                    }
                    else if (currentWeapon.thing.IsRangedWeapon && DefaultRangedWeapon == currentWeapon)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 11
0
        public static bool DrawIconForWeapon(ThingStuffPair weapon, Rect contentRect, Vector2 iconOffset, int buttonID, bool isBackground = false)
        {
            var     iconTex  = weapon.thing.uiIcon;
            Graphic g        = weapon.thing.graphicData.Graphic;
            Color   color    = weapon.getDrawColor();
            Color   colorTwo = weapon.getDrawColorTwo();
            Graphic g2       = weapon.thing.graphicData.Graphic.GetColoredVersion(g.Shader, color, colorTwo);

            var iconRect = new Rect(contentRect.x + iconOffset.x, contentRect.y + iconOffset.y, IconSize, IconSize);

            if (!contentRect.Contains(iconRect))
            {
                return(false);
            }

            if (!isBackground)
            {
                string label = weapon.getLabelCap();

                TooltipHandler.TipRegion(iconRect, label);
                MouseoverSounds.DoRegion(iconRect, SoundDefOf.Mouseover_Command);
                if (Mouse.IsOver(iconRect))
                {
                    GUI.color = iconMouseOverColor;
                    GUI.DrawTexture(iconRect, TextureResources.drawPocket);
                    //Graphics.DrawTexture(iconRect, TextureResources.drawPocket, new Rect(0, 0, 1f, 1f), 0, 0, 0, 0, iconMouseOverColor);
                }
                else
                {
                    GUI.color = iconBaseColor;
                    GUI.DrawTexture(iconRect, TextureResources.drawPocket);
                    //Graphics.DrawTexture(iconRect, TextureResources.drawPocket, new Rect(0, 0, 1f, 1f), 0, 0, 0, 0, iconBaseColor);
                }
            }

            Texture resolvedIcon;

            if (!weapon.thing.uiIconPath.NullOrEmpty())
            {
                resolvedIcon = weapon.thing.uiIcon;
            }
            else
            {
                resolvedIcon = g2.MatSingle.mainTexture;
            }
            GUI.color = color;
            GUI.DrawTexture(iconRect, resolvedIcon);
            GUI.color = Color.white;

            if (!isBackground)
            {
                if (Widgets.ButtonInvisible(iconRect, true))
                {
                    Event.current.button = buttonID;
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 12
0
 public void SetRangedWeaponTypeAsDefault(ThingStuffPair rangedWeapon)
 {
     this.DefaultRangedWeapon = rangedWeapon;
     if (this.ForcedWeapon != null && this.ForcedWeapon != rangedWeapon && this.ForcedWeapon.Value.thing.IsRangedWeapon)
     {
         UnsetForcedWeapon(false);
     }
 }
Exemplo n.º 13
0
 public static IEnumerable <ThingStuffPair> getValidWeapons()
 {
     if (pregenedValidWeapons == null)
     {
         pregenedValidWeapons = ThingStuffPair.AllWith(t => t.IsWeapon && t.weaponTags != null && t.PlayerAcquirable);
     }
     return(pregenedValidWeapons);
 }
Exemplo n.º 14
0
 public static Color getDrawColorTwo(this ThingStuffPair pair)
 {
     if (pair.thing.graphicData != null)
     {
         return(pair.thing.graphicData.colorTwo);
     }
     return(Color.white);
 }
Exemplo n.º 15
0
 internal static void excludeNeolithic(List <ThingStuffPair> list)
 {
     for (int i = list.Count - 1; i >= 0; i--)
     {
         ThingStuffPair weapon = list[i];
         if (weapon.thing.weaponTags.Contains("NeolithicMelee") | weapon.thing.weaponTags.Contains("NeolithicRanged") | weapon.thing.weaponTags.Contains("Neolithic"))
         {
             list.RemoveAt(i);
         }
     }
 }
Exemplo n.º 16
0
 public static bool isSpeciallyDisallowed(this ThingStuffPair pair)
 {
     if (
         pair.thing.defName == "Gun_Fire_Ext" ||
         pair.thing.defName == "VWE_Gun_FireExtinguisher"
         )
     {
         return(true);
     }
     return(false);
 }
Exemplo n.º 17
0
 public static string getLabel(this ThingStuffPair pair)
 {
     if (pair.stuff != null)
     {
         return(pair.stuff.LabelAsStuff + " " + pair.thing.label);
     }
     else
     {
         return(pair.thing.label);
     }
 }
Exemplo n.º 18
0
 private static float GetWeaponCommonalityFromIdeo(Pawn pawn, ThingStuffPair pair)
 {
     if (pawn.Ideo == null)
     {
         return(1f);
     }
     return(pawn.Ideo.GetDispositionForWeapon(pair.thing) switch
     {
         IdeoWeaponDisposition.Noble => WeaponSelectFactor_NobleByIdeo,
         IdeoWeaponDisposition.Despised => WeaponSelectFactor_DespisedByIdeo,
         _ => 1f,
     });
Exemplo n.º 19
0
        // Token: 0x0600000A RID: 10 RVA: 0x000022B0 File Offset: 0x000004B0
        public static void PawnWeaponGenerator_TryGenerateWeaponFor_PostFix(Pawn pawn)
        {
            HugsLib.Settings.SettingHandle <int> chance = Traverse.Create(typeof(DualWield.Base)).Field("NPCDualWieldChance").GetValue <HugsLib.Settings.SettingHandle <int> >();
            bool alwaysDW = (pawn.kindDef.weaponTags != null && pawn.kindDef.weaponTags.Contains("AlwaysDualWield"));

            Rand.PushState();
            bool flag = !pawn.RaceProps.Humanlike && pawn.RaceProps.ToolUser && pawn.RaceProps.FleshType != FleshTypeDefOf.Mechanoid && pawn.equipment != null && (Rand.Chance((float)chance / 100f) || alwaysDW);

            Rand.PopState();
            if (flag)
            {
                float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;
                List <ThingStuffPair> allWeaponPairs = Traverse.Create(typeof(PawnWeaponGenerator)).Field("allWeaponPairs").GetValue <List <ThingStuffPair> >();
                List <ThingStuffPair> workingWeapons = Traverse.Create(typeof(PawnWeaponGenerator)).Field("workingWeapons").GetValue <List <ThingStuffPair> >();
                if (pawn.equipment != null && pawn.equipment.Primary != null && pawn.equipment.Primary.def.IsTwoHand())
                {
                    return;
                }
                if (pawn.equipment == null || pawn.equipment.Primary == null)
                {
                    return;
                }
                for (int i = 0; i < allWeaponPairs.Count; i++)
                {
                    ThingStuffPair w = allWeaponPairs[i];
                    if (w.Price <= randomInRange)
                    {
                        if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag)))
                        {
                            Rand.PushState();
                            if (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ (int)w.thing.shortHash ^ 28554824))
                            {
                                workingWeapons.Add(w);
                            }
                            Rand.PopState();
                        }
                    }
                }
                if (workingWeapons.Count == 0)
                {
                    return;
                }
                IEnumerable <ThingStuffPair> matchingWeapons = workingWeapons.Where((ThingStuffPair tsp) =>
                                                                                    tsp.thing.CanBeOffHand() &&
                                                                                    !tsp.thing.IsTwoHand());
                if (matchingWeapons != null && matchingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out ThingStuffPair thingStuffPair))
                {
                    ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                    PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                    AddOffHandEquipment(pawn.equipment, thingWithComps);
                }
            }
        }
Exemplo n.º 20
0
 public static Color getDrawColor(this ThingStuffPair pair)
 {
     if (pair.stuff != null)
     {
         return(pair.stuff.stuffProps.color);
     }
     if (pair.thing.graphicData != null)
     {
         return(pair.thing.graphicData.color);
     }
     return(Color.white);
 }
        // Token: 0x0600005A RID: 90 RVA: 0x000045A8 File Offset: 0x000027A8
        public static void TryGenerateWeaponFor_Prefix(Pawn pawn)
        {
            List <ThingStuffPair> value  = Traverse.Create(typeof(PawnWeaponGenerator)).Field("workingWeapons").GetValue <List <ThingStuffPair> >();
            List <ThingStuffPair> value2 = Traverse.Create(typeof(PawnWeaponGenerator)).Field("allWeaponPairs").GetValue <List <ThingStuffPair> >();

            value.Clear();
            bool flag = pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0;

            if (!flag)
            {
                bool flag2 = !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
                if (!flag2)
                {
                    bool flag3 = pawn.story != null && pawn.WorkTagIsDisabled(WorkTags.Violent);
                    if (!flag3)
                    {
                        float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;
                        for (int i = 0; i < value2.Count; i++)
                        {
                            ThingStuffPair w     = value2[i];
                            bool           flag4 = w.Price <= randomInRange;
                            if (flag4)
                            {
                                bool flag5 = pawn.kindDef.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag));
                                if (flag5)
                                {
                                    bool flag6 = w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance;
                                    if (flag6)
                                    {
                                        value.Add(w);
                                    }
                                }
                            }
                        }
                        bool flag7 = value.Count == 0;
                        if (!flag7)
                        {
                            pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish);
                            ThingStuffPair thingStuffPair;
                            bool           flag8 = value.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair);
                            if (flag8)
                            {
                                ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                                PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                                pawn.equipment.AddEquipment(thingWithComps);
                            }
                            value.Clear();
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
 public void SetWeaponAsForced(ThingStuffPair weapon, bool drafted)
 {
     if (drafted)
     {
         ForcedUnarmedWhileDrafted = false;
         ForcedWeaponWhileDrafted  = weapon;
     }
     else
     {
         ForcedUnarmed = false;
         ForcedWeapon  = weapon;
     }
 }
Exemplo n.º 23
0
 public void SetMeleeWeaponTypeAsPreferred(ThingStuffPair meleeWeapon)
 {
     this.preferredUnarmedEx   = false;
     this.PreferredMeleeWeapon = meleeWeapon;
     if (this.ForcedWeapon != null && this.ForcedWeapon != meleeWeapon && this.ForcedWeapon.Value.thing.IsMeleeWeapon)
     {
         UnsetForcedWeapon(false);
     }
     if (ForcedUnarmed)
     {
         UnsetUnarmedAsForced(false);
     }
 }
Exemplo n.º 24
0
 public static void SelfConsume(Verb_ShootOneUse __instance)
 {
     if (__instance.caster is Pawn)
     {
         Pawn           pawn         = (__instance.caster as Pawn);
         ThingStuffPair weapon       = __instance.EquipmentSource.toThingStuffPair();
         bool           anotherFound = WeaponAssingment.equipSpecificWeaponTypeFromInventory(pawn, weapon, false, false);
         if (!anotherFound)
         {
             WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, DroppingModeEnum.UsedUp);
         }
     }
 }
Exemplo n.º 25
0
        public static bool equipSpecificWeaponTypeFromInventory(Pawn pawn, ThingStuffPair weapon, bool dropCurrent, bool intentionalDrop)
        {
            ThingWithComps match = pawn.inventory.innerContainer.Where(t => { return(t is ThingWithComps && t.toThingStuffPair() == weapon); }).OrderByDescending(t => t.MarketValue).FirstOrDefault() as ThingWithComps;

            if (match != null)
            {
                return(equipSpecificWeaponFromInventory(pawn, match, dropCurrent, intentionalDrop));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// This postfix is applied to (generally) 2 predicates used by AddFreeWarmthAsNeeded() in order to get those predicates to consider if the pawn
 /// should get that apparel or not.
 /// </summary>
 /// <param name="__result">bool result of the Predicate thus far, we only need to do something if this starts out as true in which case gets set to false.</param>
 /// <param name="pa">ThingStuffPair, the apparel that the patched Predicate is considering.</param>
 /// <remarks>
 /// Because this is a postfix we only need to consider the pawn and apparel tags if the result so far is true as a false value indicates one of the
 /// other parts of the predicate didn't pass.
 /// </remarks>
 static void Postfix(ref bool __result, ref ThingStuffPair pa)
 {
     if (active && consideredPawn == null)
     {
         active = false;
         Log.Error(string.Concat(logPrefix, "Error while examining pawn for apparel tags, pawn is null.  Likely cause is pawn retrieval patch failed or",
                                 "was overridden by another Harmony patch.\n apparel tags will no longer be filtered and pawns may show up using gear they shouldn't."));
     }
     if (active && __result && !pa.thing.apparel.tags.Intersect(consideredPawn.kindDef.apparelTags).Any())
     {
         __result = false;
     }
 }
Exemplo n.º 27
0
        // Token: 0x06000004 RID: 4 RVA: 0x00002084 File Offset: 0x00000284
        public static float GetMinWeaponValue(PawnKindDef PKD)
        {
            var min = PKD.weaponMoney.min;
            var num = PKD.weaponMoney.max;

            if (PKD.weaponTags == null || PKD.weaponTags.Count == 0)
            {
                return(min);
            }

            var list = allWeaponPairs.Count > 0 ? allWeaponPairs : ThingStuffPair.AllWith(t => t.IsWeapon);

            if (list.Count > 0)
            {
                allWeaponPairs = list;
            }

            if (PKD.defaultFactionType == null)
            {
                return(min);
            }

            var minCompareTechLevel = GetMinCompareTechLevel(PKD.defaultFactionType.techLevel);

            if (GetAdjVal(minCompareTechLevel, out _, out var num4, out _) && num4 != 0f)
            {
                num = Math.Max(num * ((num4 + 100f) / 100f), 0f);
            }

            if (!(num > 0f))
            {
                return(min);
            }

            var num2 = num;

            foreach (var thingStuffPair in allWeaponPairs)
            {
                if (thingStuffPair.thing.techLevel == minCompareTechLevel && num2 > thingStuffPair.Price)
                {
                    num2 = thingStuffPair.Price;
                }
            }

            if (num2 <= num && num2 > min)
            {
                return(num2);
            }

            return(min);
        }
        private void TryGenerateWeaponWithAmmoFor(Pawn pawn, CompInventory inventory, SidearmOption option)
        {
            if (option.weaponTags.NullOrEmpty() || !Rand.Chance(option.generateChance))
            {
                return;
            }
            // Generate weapon - mostly based on PawnWeaponGenerator.TryGenerateWeaponFor()
            // START 1:1 COPY
            float randomInRange = pawn.kindDef.weaponMoney.RandomInRange;

            for (int i = 0; i < allWeaponPairs.Count; i++)
            {
                ThingStuffPair w = allWeaponPairs[i];
                if (w.Price <= randomInRange)
                {
                    if (option.weaponTags == null || option.weaponTags.Any((string tag) => w.thing.weaponTags.Contains(tag)))
                    {
                        if (w.thing.generateAllowChance >= 1f || Rand.ChanceSeeded(w.thing.generateAllowChance, pawn.thingIDNumber ^ (int)w.thing.shortHash ^ 28554824))
                        {
                            workingWeapons.Add(w);
                        }
                    }
                }
            }
            if (workingWeapons.Count == 0)
            {
                return;
            }
            // END 1:1 COPY
            // pawn.equipment.DestroyAllEquipment(DestroyMode.Vanish); --removed compared to sourcecode
            // Some 1:1 COPY below
            ThingStuffPair thingStuffPair;

            if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price, out thingStuffPair))
            {
                // Create the actual weapon and put it into inventory
                ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                LoadWeaponWithRandAmmo(thingWithComps);                     //Custom
                int count;                                                  //Custom
                if (inventory.CanFitInInventory(thingWithComps, out count)) //Custom
                {
                    PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                    if (inventory.container.TryAdd(thingWithComps))                                                          //Custom
                    {
                        TryGenerateAmmoFor(thingWithComps, inventory, Mathf.RoundToInt(option.magazineCount.RandomInRange)); //Custom
                    }
                }
            }
            workingWeapons.Clear();
        }
Exemplo n.º 29
0
        static bool CanWear(Zombie zombie, ThingStuffPair pair)
        {
            if (pair.thing == null)
            {
                return(false);
            }

            if (zombie.isMiner && PawnApparelGenerator.IsHeadgear(pair.thing))
            {
                return(false);
            }

            return(ApparelUtility.HasPartsToWear(zombie, pair.thing));
        }
Exemplo n.º 30
0
        public static bool matchesThingStuffPair(this Thing thing, ThingStuffPair pair, bool allowPartialMatch = false)
        {
            bool retVal   = false;
            var  thisPair = thing.toThingStuffPair();

            if (thisPair.thing == pair.thing && thisPair.stuff == pair.stuff)
            {
                retVal = true;
            }
            else if (allowPartialMatch && thisPair.thing == pair.thing)
            {
                retVal = true;
            }

            return(retVal);
        }