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();
        }
示例#2
0
        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()
            float money = option.sidearmMoney.RandomInRange;

            foreach (ThingStuffPair cur in allWeaponPairs)
            {
                if (cur.Price <= money &&
                    option.weaponTags.Any(t => cur.thing.weaponTags.Contains(t)) &&
                    (cur.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554635) <= cur.thing.generateAllowChance))
                {
                    workingWeapons.Add(cur);
                }
            }
            if (workingWeapons.Count == 0)
            {
                return;
            }
            ThingStuffPair pair;

            if (workingWeapons.TryRandomElementByWeight(p => p.Commonality * p.Price, out pair))
            {
                // Create the actual weapon and put it into inventory
                var eq = (ThingWithComps)ThingMaker.MakeThing(pair.thing, pair.stuff);
                LoadWeaponWithRandAmmo(eq);
                int count;
                if (inventory.CanFitInInventory(eq, out count))
                {
                    PawnGenerator.PostProcessGeneratedGear(eq, pawn);
                    if (inventory.container.TryAdd(eq))
                    {
                        TryGenerateAmmoFor(eq, inventory, Mathf.RoundToInt(option.magazineCount.RandomInRange));
                    }
                }
            }
            workingWeapons.Clear();
        }