コード例 #1
0
 public static void Init()
 {
     GettersFilters.getHeaviestWeapons(out maxWeightMelee, out maxWeightRanged);
     maxWeightMelee  += 1;
     maxWeightRanged += 1;
     maxWeightTotal   = Math.Max(maxWeightMelee, maxWeightRanged);
 }
コード例 #2
0
 public GoldfishModule(Pawn owner, bool fillExisting)
 {
     this.Owner = owner;
     if (fillExisting)
     {
         List <Thing> meleeWeapons;
         List <Thing> rangedWeapons;
         GettersFilters.getWeaponLists(out meleeWeapons, out rangedWeapons, Owner.inventory);
         foreach (Thing weapon in meleeWeapons)
         {
             AddSidearm(weapon.def);
         }
         foreach (Thing weapon in rangedWeapons)
         {
             AddSidearm(weapon.def);
         }
         if (owner.equipment != null && owner.equipment.Primary != null)
         {
             AddSidearm(owner.equipment.Primary.def);
             SetPrimary(owner.equipment.Primary.def, true);
         }
         else
         {
             SetPrimaryEmpty(true);
         }
     }
 }
コード例 #3
0
ファイル: Intercepts_UI.cs プロジェクト: Nylux/SimpleSidearms
        private static void GetGizmos(Pawn __instance, ref IEnumerable <Gizmo> __result)
        {
            if (__instance.IsColonistPlayerControlled)
            {
                if (__instance.inventory != null)
                {
                    List <Thing> rangedWeapons;
                    List <Thing> meleeWeapons;
                    GettersFilters.getWeaponLists(out rangedWeapons, out meleeWeapons, __instance.inventory);

                    GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(__instance);
                    //if (pawnMemory == null)
                    //    return;

                    if (rangedWeapons.Count > 0 || meleeWeapons.Count > 0 || (pawnMemory != null && pawnMemory.weapons.Count > 0))
                    {
                        List <ThingDef> rangedWeaponMemories = new List <ThingDef>();
                        List <ThingDef> meleeWeaponMemories  = new List <ThingDef>();

                        if (pawnMemory != null)
                        {
                            foreach (string weapon in pawnMemory.weapons)
                            {
                                ThingDef wepDef = DefDatabase <ThingDef> .GetNamedSilentFail(weapon);

                                if (wepDef == null)
                                {
                                    continue;
                                }

                                if (wepDef.IsMeleeWeapon)
                                {
                                    meleeWeaponMemories.Add(wepDef);
                                }
                                else if (wepDef.IsRangedWeapon)
                                {
                                    rangedWeaponMemories.Add(wepDef);
                                }
                            }
                        }

                        Gizmo_SidearmsList advanced = new Gizmo_SidearmsList(__instance, rangedWeapons, meleeWeapons, rangedWeaponMemories, meleeWeaponMemories);
                        advanced.defaultLabel = "DrawSidearm_gizmoTitle".Translate();
                        //draft.hotKey = KeyBindingDefOf.CommandColonistDraft;
                        advanced.defaultDesc = "DrawSidearm_gizmoTooltip".Translate();

                        List <Gizmo> results = new List <Gizmo>();
                        foreach (Gizmo gizmo in __result)
                        {
                            results.Add(gizmo);
                        }
                        results.Add(advanced);
                        __result = results;
                    }
                }
            }
        }
コード例 #4
0
        public static bool CustomDrawer_MatchingWeapons_passive(Rect wholeRect, SettingHandle <WeaponListKind> setting, float weightLimit, string label, Color background)
        {
            drawBackground(wholeRect, background);
            Rect offsetRect = new Rect(wholeRect);

            offsetRect.height   = wholeRect.height - TextMargin + BottomMargin;
            offsetRect.position = new Vector2(offsetRect.position.x, offsetRect.position.y);

            DrawLabel(label, offsetRect, TextMargin);

            offsetRect.position = new Vector2(offsetRect.position.x, offsetRect.position.y + TextMargin);

            IEnumerable <ThingDefStuffDefPair> validSidearms = GettersFilters.getValidSidearms();

            List <ThingDefStuffDefPair> matchingSidearms = GettersFilters.filterForWeaponKind(validSidearms, MiscUtils.LimitTypeToListType(setting.Value)).ToList();

            matchingSidearms = matchingSidearms.OrderBy(t => t.thing.GetStatValueAbstract(StatDefOf.Mass, t.stuff)).ToList();

            List <ThingDefStuffDefPair> matchingSidearmsUnderLimit = new List <ThingDefStuffDefPair>();

            for (int i = 0; i < matchingSidearms.Count; i++)
            {
                float mass = matchingSidearms[i].thing.GetStatValueAbstract(StatDefOf.Mass);
                if (mass > weightLimit)
                {
                    break;
                }
                else
                {
                    matchingSidearmsUnderLimit.Add(matchingSidearms[i]);
                }
            }

            int iconsPerRow = (int)(offsetRect.width / (IconGap + IconSize));

            int biggerRows = ((matchingSidearmsUnderLimit.Count - 1) / iconsPerRow) + 1;

            setting.CustomDrawerHeight = (biggerRows * IconSize) + ((biggerRows) * IconGap) + TextMargin;

            for (int i = 0; i < matchingSidearmsUnderLimit.Count; i++)
            {
                int  collum     = (i % iconsPerRow);
                int  row        = (i / iconsPerRow);
                bool interacted = DrawIconForWeapon(matchingSidearmsUnderLimit[i], offsetRect, new Vector2(IconSize * collum + collum * IconGap, IconSize * row + row * IconGap), i);
                if (interacted)
                {
                    //nothing, since this is the passive list
                }
            }
            return(false);
        }
コード例 #5
0
        public static bool CustomDrawer_MatchingWeapons_active(Rect wholeRect, SettingHandle <ThingDefHashSetHandler> setting, WeaponListKind kind, Color background, string yesText = "Sidearms", string noText = "Not sidearms")
        {
            drawBackground(wholeRect, background);
            if (setting.Value == null)
            {
                setting.Value = new ThingDefHashSetHandler();
            }

            GUI.color = Color.white;

            Rect leftRect = new Rect(wholeRect);

            leftRect.width    = leftRect.width / 2;
            leftRect.height   = wholeRect.height - TextMargin + BottomMargin;
            leftRect.position = new Vector2(leftRect.position.x, leftRect.position.y);
            Rect rightRect = new Rect(wholeRect);

            rightRect.width    = rightRect.width / 2;
            leftRect.height    = wholeRect.height - TextMargin + BottomMargin;
            rightRect.position = new Vector2(rightRect.position.x + leftRect.width, rightRect.position.y);

            DrawLabel(yesText, leftRect, TextMargin);
            DrawLabel(noText, rightRect, TextMargin);

            leftRect.position  = new Vector2(leftRect.position.x, leftRect.position.y + TextMargin);
            rightRect.position = new Vector2(rightRect.position.x, rightRect.position.y + TextMargin);

            int iconsPerRow = (int)(leftRect.width / (IconGap + IconSize));

            IEnumerable <ThingDef> matchingSidearmsEnumerable;
            IEnumerable <ThingDef> allSidearmsEnumerable = GettersFilters.getValidWeaponsThingDefsOnly();

            switch (kind)
            {
            case WeaponListKind.Melee:
                matchingSidearmsEnumerable = allSidearmsEnumerable.Where(t => t.IsMeleeWeapon);
                break;

            case WeaponListKind.Ranged:
                matchingSidearmsEnumerable = allSidearmsEnumerable.Where(t => t.IsRangedWeapon);
                break;

            case WeaponListKind.Both:
            default:
                matchingSidearmsEnumerable = allSidearmsEnumerable;
                break;
            }


            List <ThingDef> matchingSidearms = matchingSidearmsEnumerable.ToList();
            List <ThingDef> allSidearms      = allSidearmsEnumerable.ToList();

            matchingSidearms = matchingSidearms.OrderBy(t => t.GetStatValueAbstract(StatDefOf.Mass)).ToList();

            List <ThingDef> selectedSidearms = setting.Value.InnerList.ToList();

            List <ThingDef> unselectedSidearms = new List <ThingDef>();

            for (int i = 0; i < matchingSidearms.Count; i++)
            {
                if (!selectedSidearms.Contains(matchingSidearms[i]))
                {
                    unselectedSidearms.Add(matchingSidearms[i]);
                }
            }

            bool change = false;

            int biggerRows = Math.Max((selectedSidearms.Count - 1) / iconsPerRow, (unselectedSidearms.Count - 1) / iconsPerRow) + 1;

            setting.CustomDrawerHeight = (biggerRows * IconSize) + ((biggerRows) * IconGap) + TextMargin;

            for (int i = 0; i < selectedSidearms.Count; i++)
            {
                int  collum     = (i % iconsPerRow);
                int  row        = (i / iconsPerRow);
                bool interacted = DrawIconForWeapon(selectedSidearms[i], leftRect, new Vector2(IconSize * collum + collum * IconGap, IconSize * row + row * IconGap), i);
                if (interacted)
                {
                    change = true;
                    setting.Value.InnerList.Remove(selectedSidearms[i]);
                }
            }

            for (int i = 0; i < unselectedSidearms.Count; i++)
            {
                int  collum     = (i % iconsPerRow);
                int  row        = (i / iconsPerRow);
                bool interacted = DrawIconForWeapon(unselectedSidearms[i], rightRect, new Vector2(IconSize * collum + collum * IconGap, IconSize * row + row * IconGap), i);
                if (interacted)
                {
                    change = true;
                    setting.Value.InnerList.Add(unselectedSidearms[i]);
                }
            }
            return(change);
        }
コード例 #6
0
        internal static bool CustomDrawer_MatchingWeapons_active(Rect wholeRect, SettingHandle <StringHashSetHandler> setting, WeaponListKind kind, Color background, string yesText = "Sidearms", string noText = "Not sidearms", bool excludeNeolithic = false)
        {
            drawBackground(wholeRect, background);
            if (setting.Value == null)
            {
                setting.Value = new StringHashSetHandler();
            }

            GUI.color = Color.white;

            Rect leftRect = new Rect(wholeRect);

            leftRect.width    = leftRect.width / 2;
            leftRect.height   = wholeRect.height - TextMargin + BottomMargin;
            leftRect.position = new Vector2(leftRect.position.x, leftRect.position.y);
            Rect rightRect = new Rect(wholeRect);

            rightRect.width    = rightRect.width / 2;
            leftRect.height    = wholeRect.height - TextMargin + BottomMargin;
            rightRect.position = new Vector2(rightRect.position.x + leftRect.width, rightRect.position.y);

            DrawLabel(yesText, leftRect, TextMargin);
            DrawLabel(noText, rightRect, TextMargin);

            leftRect.position  = new Vector2(leftRect.position.x, leftRect.position.y + TextMargin);
            rightRect.position = new Vector2(rightRect.position.x, rightRect.position.y + TextMargin);

            int iconsPerRow = (int)(leftRect.width / (IconGap + IconSize));

            HashSet <string> selection = setting.Value.InnerList;

            List <ThingStuffPair> matchingSidearms;
            List <ThingStuffPair> allSidearms = GettersFilters.filterForType(PawnSidearmsGenerator.getWeaponsList(), WeaponSearchType.Both, false);

            switch (kind)
            {
            case WeaponListKind.Melee:
                matchingSidearms = GettersFilters.filterForType(allSidearms, WeaponSearchType.Melee, false);
                break;

            case WeaponListKind.Ranged:
                matchingSidearms = GettersFilters.filterForType(allSidearms, WeaponSearchType.Ranged, false);
                break;

            case WeaponListKind.Both:
            default:
                matchingSidearms = allSidearms;
                break;
            }

            if (excludeNeolithic)
            {
                GettersFilters.excludeNeolithic(matchingSidearms);
            }

            matchingSidearms.Sort(new MassComparer());

            List <string> selectionAsList = selection.ToList();

            ThingDef[] selectionThingDefs = new ThingDef[selectionAsList.Count];
            for (int i = 0; i < allSidearms.Count; i++)
            {
                for (int j = 0; j < selectionThingDefs.Length; j++)
                {
                    if (selectionAsList[j].Equals(allSidearms[i].thing.defName))
                    {
                        selectionThingDefs[j] = allSidearms[i].thing;
                    }
                }
            }

            List <ThingStuffPair> unselectedSidearms = new List <ThingStuffPair>();

            for (int i = 0; i < matchingSidearms.Count; i++)
            {
                if (!selection.Contains(matchingSidearms[i].thing.defName))
                {
                    unselectedSidearms.Add(matchingSidearms[i]);
                }
            }

            bool change = false;

            int biggerRows = Math.Max((selection.Count - 1) / iconsPerRow, (unselectedSidearms.Count - 1) / iconsPerRow) + 1;

            setting.CustomDrawerHeight = (biggerRows * IconSize) + ((biggerRows) * IconGap) + TextMargin;

            for (int i = 0; i < selectionAsList.Count; i++)
            {
                if (selectionThingDefs[i] == null)
                {
                    continue;
                }
                int  collum     = (i % iconsPerRow);
                int  row        = (i / iconsPerRow);
                bool interacted = DrawIconForWeapon(selectionThingDefs[i], leftRect, new Vector2(IconSize * collum + collum * IconGap, IconSize * row + row * IconGap), i);
                if (interacted)
                {
                    change = true;
                    selection.Remove(selectionAsList[i]);
                }
            }

            for (int i = 0; i < unselectedSidearms.Count; i++)
            {
                int  collum     = (i % iconsPerRow);
                int  row        = (i / iconsPerRow);
                bool interacted = DrawIconForWeapon(unselectedSidearms[i].thing, rightRect, new Vector2(IconSize * collum + collum * IconGap, IconSize * row + row * IconGap), i);
                if (interacted)
                {
                    change = true;
                    selection.Add(unselectedSidearms[i].thing.defName);
                }
            }
            if (change)
            {
                setting.Value.InnerList = selection;
            }
            return(change);
        }
コード例 #7
0
        private static bool CustomDrawer_MatchingWeapons_passive(Rect wholeRect, SettingHandle <WeaponListKind> setting, float weightLimit, string label, Color background)
        {
            drawBackground(wholeRect, background);
            Rect offsetRect = new Rect(wholeRect);

            offsetRect.height   = wholeRect.height - TextMargin + BottomMargin;
            offsetRect.position = new Vector2(offsetRect.position.x, offsetRect.position.y);

            DrawLabel(label, offsetRect, TextMargin);

            offsetRect.position = new Vector2(offsetRect.position.x, offsetRect.position.y + TextMargin);

            List <ThingStuffPair> matchingSidearms;

            switch (setting.Value)
            {
            case WeaponListKind.Melee:
                matchingSidearms = GettersFilters.filterForType(PawnSidearmsGenerator.getWeaponsList(), WeaponSearchType.Melee, false);
                break;

            case WeaponListKind.Ranged:
                matchingSidearms = GettersFilters.filterForType(PawnSidearmsGenerator.getWeaponsList(), WeaponSearchType.Ranged, false);
                break;

            case WeaponListKind.Both:
            default:
                matchingSidearms = GettersFilters.filterForType(PawnSidearmsGenerator.getWeaponsList(), WeaponSearchType.Both, false);
                break;
            }
            matchingSidearms.Sort(new MassComparer());
            List <ThingStuffPair> matchingSidearmsUnderLimit = new List <ThingStuffPair>();

            for (int i = 0; i < matchingSidearms.Count; i++)
            {
                float mass = matchingSidearms[i].thing.GetStatValueAbstract(StatDefOf.Mass);
                if (mass > weightLimit)
                {
                    break;
                }
                else
                {
                    matchingSidearmsUnderLimit.Add(matchingSidearms[i]);
                }
            }

            int iconsPerRow = (int)(offsetRect.width / (IconGap + IconSize));

            int biggerRows = ((matchingSidearmsUnderLimit.Count - 1) / iconsPerRow) + 1;

            setting.CustomDrawerHeight = (biggerRows * IconSize) + ((biggerRows) * IconGap) + TextMargin;

            for (int i = 0; i < matchingSidearmsUnderLimit.Count; i++)
            {
                int  collum     = (i % iconsPerRow);
                int  row        = (i / iconsPerRow);
                bool interacted = DrawIconForWeapon(matchingSidearmsUnderLimit[i].thing, offsetRect, new Vector2(IconSize * collum + collum * IconGap, IconSize * row + row * IconGap), i);
                if (interacted)
                {
                    //nothing, since this is the passive list
                }
            }
            return(false);
        }
コード例 #8
0
        public static void TryGenerateSidearmsFor(Pawn pawn)
        {
            if (SimpleSidearms.SidearmSpawnChance.Value < 0.01f)
            {
                return;
            }

            if (!hasBeenReset)
            {
                Reset();
            }


            if (Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) >= SimpleSidearms.SidearmSpawnChance.Value)
            {
                return;
            }
            if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0)
            {
                return;
            }
            if (!pawn.RaceProps.ToolUser)
            {
                return;
            }
            if (!pawn.RaceProps.Humanlike)
            {
                return;
            }
            if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                return;
            }
            if (pawn.story != null && pawn.story.WorkTagIsDisabled(WorkTags.Violent))
            {
                return;
            }
            if (pawn.equipment.Primary == null)
            {
                return;
            }

            bool meleeOnly = pawn.equipment.Primary.def.IsMeleeWeapon || (pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler));
            bool neolithic = true;

            foreach (string wepTag in pawn.kindDef.weaponTags)
            {
                if (wepTag.Contains("Neolithic"))
                {
                    neolithic = false;
                    break;
                }
            }

            List <string> sidearmTags = GettersFilters.weaponTagsToSidearmTags(pawn.kindDef.weaponTags);

            float money = pawn.kindDef.weaponMoney.min;

            money /= 5f;

            for (int i = 0; i < allWeaponPairs.Count; i++)
            {
                ThingStuffPair w = allWeaponPairs[i];

                if (!StatCalculator.canCarrySidearm(w.thing, pawn))
                {
                    continue;
                }
                if (w.Price > money)
                {
                    continue;
                }
                if (meleeOnly && w.thing.IsRangedWeapon)
                {
                    continue;
                }
                if (neolithic)
                {
                    bool isNeolithic = true;
                    #region nestedMonstrosity
                    foreach (string wepTag in pawn.kindDef.weaponTags)
                    {
                        if (!wepTag.Contains("Neolithic"))
                        {
                            //check if the weapon is allowed despite not being neolithic
                            bool getsAPass = false;
                            foreach (string weapon in SimpleSidearms.SidearmsNeolithicExtension.Value.InnerList)
                            {
                                if (weapon.Equals(w.thing.defName))
                                {
                                    getsAPass = true;
                                    break;
                                }
                            }
                            if (!getsAPass)
                            {
                                isNeolithic = false;
                            }
                        }
                        if (!isNeolithic)
                        {
                            break;
                        }
                    }
                    #endregion
                    if (!isNeolithic)
                    {
                        continue;
                    }
                }

                if (sidearmTags.Any((string tag) => w.thing.weaponTags.Contains(tag)))
                {
                    if (w.thing.generateAllowChance >= 1f || Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824) <= w.thing.generateAllowChance)
                    {
                        workingWeapons.Add(w);
                    }
                }
            }
            if (workingWeapons.Count == 0)
            {
                return;
            }
            ThingStuffPair thingStuffPair;
            if (workingWeapons.TryRandomElementByWeight((ThingStuffPair w) => w.Commonality * w.Price / w.thing.BaseMass, out thingStuffPair))
            {
                ThingWithComps thingWithComps = (ThingWithComps)ThingMaker.MakeThing(thingStuffPair.thing, thingStuffPair.stuff);
                PawnGenerator.PostProcessGeneratedGear(thingWithComps, pawn);
                pawn.inventory.innerContainer.TryAdd(thingWithComps);
                //pawn.equipment.AddEquipment(thingWithComps);
            }
            workingWeapons.Clear();
        }
コード例 #9
0
        //reworked to use my own code instead of generator code nicked from vanilla Rimworld
        public static bool TryGenerateSidearmFor(Pawn pawn, float chance, float budgetMultiplier, PawnGenerationRequest request)
        {
            if (
                !(Current.ProgramState == ProgramState.Playing) || !pawn.IsValidSidearmsCarrier() ||
                chance < 0.01f ||
                pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0 ||
                pawn.equipment.Primary == null ||
                !pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) ||
                (pawn.story != null && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0))
                )
            {
                /*
                 * Log.Message("sidearm viability conditions not met");
                 *
                 * if (pawn is null)
                 *  Log.Message("pawn is null");
                 * if (SimpleSidearms.configData is null)
                 *  Log.Message("configData null");
                 * if (chance < 0.01f)
                 *  Log.Message("chance < 0.01");
                 * if (pawn.kindDef.weaponTags == null || pawn.kindDef.weaponTags.Count == 0)
                 *  Log.Message("weapon tags null or empty");
                 * if (pawn.equipment == null || pawn.equipment.Primary == null)
                 *  Log.Message("equipment null or no primary");
                 * if (!pawn.RaceProps.ToolUser)
                 *  Log.Message("not a toolUser");
                 * if (!pawn.RaceProps.Humanlike)
                 *  Log.Message("not humanlike");
                 * if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                 *  Log.Message("not capable of manipulation");
                 * if ((pawn.story != null && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0)))
                 *  Log.Message("disabled violent work tags, tags:"+pawn.CombinedDisabledWorkTags);
                 */
                return(false);
            }
            else
            {
                //bool primarySingleUse = pawn.equipment.Primary.GetComp<CompEquippable>().PrimaryVerb is Verb_ShootOneUse;

                ThingDefStuffDefPair primaryBase = new ThingDefStuffDefPair(pawn.equipment.Primary.def, pawn.equipment.Primary.Stuff);

                var sidearmChanceRoll = Rand.ValueSeeded(pawn.thingIDNumber ^ 28554824);
                if (sidearmChanceRoll >= chance)
                {
                    return(false); //rolled no sidearm
                }
                IEnumerable <ThingDefStuffDefPair> validSidearms = GettersFilters.getValidSidearms();

                IEnumerable <string> weaponTags = generateWeaponTags(pawn.kindDef.weaponTags);

                validSidearms = validSidearms.Where(t =>
                {
                    foreach (string tag in t.thing.weaponTags)
                    {
                        if (t == null || t.thing == null || t.thing.weaponTags == null)
                        {
                            continue;
                        }
                        if (weaponTags.Contains(tag))
                        {
                            return(true);
                        }
                    }
                    return(false);
                });

                //filter out nonsensical material weapons
                validSidearms = validSidearms.Where(w => w.stuff == null || (w.stuff != ThingDefOf.Gold && w.stuff != ThingDefOf.Silver && w.stuff != ThingDefOf.Uranium));
                //filter out weapons the pawn cant carry
                validSidearms = validSidearms.Where(w => StatCalculator.canCarrySidearmType(w, pawn, out _));

                bool onlyMelee  = (pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler));
                bool onlyRanged = (pawn.story != null && pawn.story.traits.HasTrait(TraitDef.Named("Wimp"))); //wimp has no defOf

                if (onlyMelee)
                {
                    validSidearms = validSidearms.Where(w => w.thing.IsMeleeWeapon);
                }
                if (onlyRanged)
                {
                    validSidearms = validSidearms.Where(w => w.thing.IsRangedWeapon);
                }

                //listWeapons("budget " + pawn.kindDef.weaponMoney.max* budgetMultiplier + " to " + pawn.kindDef.weaponMoney.min* budgetMultiplier + ", main "+ pawn.equipment.Primary.MarketValue +" selecting from:", validSidearms);

                //use the value of primary to limit budget maximum (but of the base to match pre-degradation value) to prevent sidearms being better than the primary weapon
                float budget = Math.Min(pawn.kindDef.weaponMoney.RandomInRange, primaryBase.Price) * budgetMultiplier;
                validSidearms = validSidearms.Where(t => t.Price <= budget);

                //listWeapons("post select:", validSidearms);

                if (validSidearms.Count() == 0)
                {
                    return(false);
                }

                ThingDefStuffDefPair rolledWeaponThingDefStuffDefPair;

                validSidearms.TryRandomElementByWeight(t => { return(t.Commonality * t.Price); }, out rolledWeaponThingDefStuffDefPair);

                ThingWithComps rolledWeaponFinal = (ThingWithComps)ThingMaker.MakeThing(rolledWeaponThingDefStuffDefPair.thing, rolledWeaponThingDefStuffDefPair.stuff);
                PawnGenerator.PostProcessGeneratedGear(rolledWeaponFinal, pawn);

                float num = (request.BiocodeWeaponChance > 0f) ? request.BiocodeWeaponChance : pawn.kindDef.biocodeWeaponChance;
                if (Rand.Value < num)
                {
                    CompBiocodable compBiocodableWeapon = rolledWeaponFinal.TryGetComp <CompBiocodable>();
                    if (compBiocodableWeapon != null)
                    {
                        compBiocodableWeapon.CodeFor(pawn);
                    }
                }

                bool success = pawn.inventory.innerContainer.TryAdd(rolledWeaponFinal);
                if (success)
                {
                    CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                    if (pawnMemory != null)
                    {
                        pawnMemory.InformOfAddedSidearm(rolledWeaponFinal);
                    }
                }
                else
                {
                    Log.Warning("Failed to add generated sidearm to inventory");
                }

                return(true);
            }
        }
コード例 #10
0
        public void ApplyBaseSettings()
        {
            ToolAutoSwitch         = true;
            OptimalMelee           = true;
            CQCAutoSwitch          = true;
            CQCTargetOnly          = false;
            RangedCombatAutoSwitch = true;

            RangedCombatAutoSwitchMaxWarmup = 0.75f;

            SpeedSelectionBiasMelee  = 1f;
            SpeedSelectionBiasRanged = 1.1f;

            SeparateModes   = false;
            LimitModeSingle = LimitModeSingleSidearm.None;
            LimitModeAmount = LimitModeAmountOfSidearms.None;

            LimitModeSingleMelee  = LimitModeSingleSidearm.None;
            LimitModeAmountMelee  = LimitModeAmountOfSidearms.None;
            LimitModeSingleRanged = LimitModeSingleSidearm.None;
            LimitModeAmountRanged = LimitModeAmountOfSidearms.None;
            LimitModeAmountTotal  = LimitModeAmountOfSidearms.None;

            #region LimitModeSingle
            LimitModeSingle_AbsoluteMass = 1.9f;
            LimitModeSingle_RelativeMass = 0.25f;
            LimitModeSingle_Selection    = GettersFilters.getValidWeaponsThingDefsOnly().Where(w => w.GetStatValueAbstract(StatDefOf.Mass) <= LimitModeSingle_AbsoluteMass).ToHashSet();
            #endregion
            #region LimitModeAmount
            LimitModeAmount_AbsoluteMass = 10f;
            LimitModeAmount_RelativeMass = 0.5f;
            LimitModeAmount_Slots        = 2;
            #endregion

            #region LimitModeSingleMelee
            LimitModeSingleMelee_AbsoluteMass = 1.9f;
            LimitModeSingleMelee_RelativeMass = 0.25f;
            LimitModeSingleMelee_Selection    = GettersFilters.filterForWeaponKind(GettersFilters.getValidWeaponsThingDefsOnly(), WeaponSearchType.Melee).Where(w => w.GetStatValueAbstract(StatDefOf.Mass) <= LimitModeSingleMelee_AbsoluteMass).ToHashSet();
            #endregion
            #region LimitModeAmountMelee
            LimitModeAmountMelee_AbsoluteMass = 10f;
            LimitModeAmountMelee_RelativeMass = 0.5f;
            LimitModeAmountMelee_Slots        = 2;
            #endregion

            #region LimitModeSingleRanged
            LimitModeSingleRanged_AbsoluteMass = 2.55f;
            LimitModeSingleRanged_RelativeMass = 0.25f;
            LimitModeSingleRanged_Selection    = GettersFilters.filterForWeaponKind(GettersFilters.getValidWeaponsThingDefsOnly(), WeaponSearchType.Ranged).Where(w => w.GetStatValueAbstract(StatDefOf.Mass) <= LimitModeSingleRanged_AbsoluteMass).ToHashSet();
            #endregion
            #region LimitModeAmountRanged
            LimitModeAmountRanged_AbsoluteMass = 10f;
            LimitModeAmountRanged_RelativeMass = 0.5f;
            LimitModeAmountRanged_Slots        = 2;
            #endregion

            #region LimitModeAmountTotal
            LimitModeAmountTotal_AbsoluteMass = 10f;
            LimitModeAmountTotal_RelativeMass = 0.5f;
            LimitModeAmountTotal_Slots        = 4;
            #endregion

            SidearmSpawnChance        = 0.5f;
            SidearmSpawnChanceDropoff = 0.25f;
            SidearmBudgetMultiplier   = 0.5f;
            SidearmBudgetDropoff      = 0.25f;

            ColonistDefaultWeaponMode = PrimaryWeaponMode.BySkill;
            NPCDefaultWeaponMode      = PrimaryWeaponMode.ByGenerated;

            FumbleMode           = FumbleModeOptionsEnum.InDistress;
            FumbleRecoveryChance = new SimpleCurve(defaultFumbleRecoveryChancePoints);
            ReEquipOutOfCombat   = true;
            ReEquipBest          = true;
            ReEquipInCombat      = true;

            PreserveInventoryInCaravans  = true;
            HideSidearmsInCaravanDialogs = true;
        }