Example #1
0
        public int countMissingRangedWeapons(CompSidearmMemory pawnMemory, Pawn pawn)
        {
            if (pawnMemory == null)
            {
                return(0);
            }

            int count = 0;

            Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();
            var weaponMemories = rangedWeaponMemories.ToList();
            var grouped        = weaponMemories.GroupBy(m => m);

            foreach (var group in grouped)
            {
                var weapon     = group.Key;
                var stackCount = group.Count();

                if (!dupeCounters.ContainsKey(weapon))
                {
                    dupeCounters[weapon] = 0;
                }

                var missingWeapons = pawn.missingCountWeaponsOfType(weapon, stackCount, dupeCounters[weapon]);
                if (missingWeapons > 0)
                {
                    count++;
                }

                dupeCounters[weapon] += stackCount;
            }

            return(count);
        }
Example #2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    ThingWithComps thingWithComps = (ThingWithComps)this.job.targetA.Thing;
                    ThingWithComps thingWithComps2;
                    if (thingWithComps.def.stackLimit > 1 && thingWithComps.stackCount > 1)
                    {
                        thingWithComps2 = (ThingWithComps)thingWithComps.SplitOff(1);
                    }
                    else
                    {
                        if (thingWithComps.Spawned)
                        {
                            thingWithComps.DeSpawn(DestroyMode.Vanish);
                        }

                        if (thingWithComps.holdingOwner != null)
                        {
                            thingWithComps.holdingOwner.Remove(thingWithComps);
                        }

                        thingWithComps2 = thingWithComps;
                    }
                    bool success = this.pawn.inventory.innerContainer.TryAdd(thingWithComps2);
                    if (thingWithComps.def.soundInteract != null)
                    {
                        thingWithComps.def.soundInteract.PlayOneShot(new TargetInfo(this.pawn.Position, this.pawn.Map, false));
                    }
                    if (success)
                    {
                        CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(this.pawn);
                        if (pawnMemory == null)
                        {
                            return;
                        }
                        if (MemorizeOnPickup)
                        {
                            pawnMemory.InformOfAddedSidearm(thingWithComps2);
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            Toil onFinish = OnFinish();

            if (onFinish != null)
            {
                yield return(onFinish);
            }
        }
Example #3
0
        public override float GetWidth(float maxWidth)
        {
            CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(parent);

            if (pawnMemory == null)
            {
                return(75);
            }
            int biggerCount = Math.Max(
                carriedRangedWeapons.Count() + countMissingRangedWeapons(pawnMemory, parent),
                carriedMeleeWeapons.Count() + countMissingMeleeWeapons(pawnMemory, parent) + 1
                );
            float width = SelectorPanelWidth + ContentPadding + (IconSize * biggerCount) + IconGap * (biggerCount - 1) + ContentPadding;

            return(Math.Min(Math.Max(width, MinGizmoSize), maxWidth));
        }
Example #4
0
        public static CompSidearmMemory GetMemoryCompForPawn(Pawn pawn, bool fillExistingIfCreating = true)
        {
            if (pawn == null)
            {
                return(null);
            }
            if (!pawn.def.race.Humanlike)
            {
                Log.Warning("CompSidearmMemory accessed for non-humanlike pawn " + pawn.Label);
                return(null);
            }
            CompSidearmMemory memory = pawn.TryGetComp <CompSidearmMemory>();

            if (memory == null)
            {
                return(null);
            }

            return(memory);
        }
Example #5
0
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }
            else
            {
                if (!pawn.IsValidSidearmsCarrier())
                {
                    return(null);
                }

                CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                if (pawnMemory.IsUsingAutotool(true, false))
                {
                    pawnMemory.currentJobWeaponReequipDelayed = true;
                    return(null);
                }
                else
                {
                    pawnMemory.currentJobWeaponReequipDelayed = false;
                }

                //Log.Message(pawn.Label+" considering switching weapons on the run");
                WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, DroppingModeEnum.Calm);

                //yes, I realise that this never actually results in a job.
                //I might at some point in the future decide to make switching weapons non-instaneous, which will happen here.

                return(null);
            }
        }
Example #6
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
        {
            interactionWeaponIsDuplicate = false;
            interactionWeapon            = null;
            interactionWeaponType        = null;

            var gizmoRect = new Rect(topLeft.x, topLeft.y, GetWidth(maxWidth), MinGizmoSize);

            if (Mouse.IsOver(gizmoRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsBasic, OpportunityType.Important);
            }

            var contentRect = gizmoRect.ContractedBy(ContentPadding);

            Widgets.DrawWindowBackground(gizmoRect);

            CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(parent);

            if (pawnMemory == null)
            {
                return(new GizmoResult(GizmoState.Clear));
            }

            int total = 0;
            Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();

            {
                var rangedWeapons = carriedRangedWeapons.ToList();
                rangedWeapons.SortStable((a, b) => { return((int)((b.MarketValue - a.MarketValue) * 1000)); });

                int i = 0;
                foreach (var weapon in rangedWeapons)
                {
                    ThingDefStuffDefPair weaponMemory = weapon.toThingDefStuffDefPair();
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    bool isDupe     = dupeCounters[weaponMemory] > 0;
                    var  iconOffset = new Vector2((IconSize * i) + IconGap * (i - 1) + SelectorPanelWidth, 0);
                    DrawIconForWeapon(parent, pawnMemory, weapon, isDupe, contentRect, iconOffset);

                    i++;
                    dupeCounters[weaponMemory] += weapon.stackCount;
                }
                total += i;
            }

            dupeCounters.Clear();

            if (pawnMemory != null)
            {
                var rangedWeaponMemoriesSorted = rangedWeaponMemories.ToList();
                rangedWeaponMemoriesSorted.SortStable((a, b) => { return((int)((b.Price - a.Price) * 1000)); });
                var grouped = rangedWeaponMemoriesSorted.GroupBy(m => m);

                int j = 0;
                foreach (var group in grouped)
                {
                    var weaponMemory = group.Key;
                    var stackCount   = group.Count();

                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    int missingCount = parent.missingCountWeaponsOfType(weaponMemory, stackCount, dupeCounters[weaponMemory]);
                    if (missingCount > 0)
                    {
                        bool isDupe     = dupeCounters[weaponMemory] > 0;
                        var  iconOffset = new Vector2((IconSize * (total + j)) + IconGap * ((total + j) - 1) + SelectorPanelWidth, 0);
                        DrawIconForWeaponMemory(parent, pawnMemory, weaponMemory, missingCount, isDupe, contentRect, iconOffset);
                        j++;
                    }
                    dupeCounters[weaponMemory] += stackCount;
                }
            }

            dupeCounters.Clear();
            total = 0;

            {
                var meleeWeapons = carriedMeleeWeapons.ToList();
                meleeWeapons.SortStable((a, b) => { return((int)((b.MarketValue - a.MarketValue) * 1000)); });
                int i = 0;
                foreach (var weapon in meleeWeapons)
                {
                    ThingDefStuffDefPair weaponMemory = weapon.toThingDefStuffDefPair();
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    bool isDupe     = dupeCounters[weaponMemory] > 0;
                    var  iconOffset = new Vector2((IconSize * i) + IconGap * (i - 1) + SelectorPanelWidth, IconSize + IconGap);
                    DrawIconForWeapon(parent, pawnMemory, weapon, isDupe, contentRect, iconOffset);

                    i++;
                    dupeCounters[weaponMemory] += weapon.stackCount;
                }
                total += i;
            }

            dupeCounters.Clear();

            if (pawnMemory != null)
            {
                var meleeWeaponMemoriesSorted = meleeWeaponMemories.ToList();
                meleeWeaponMemoriesSorted.SortStable((a, b) => { return((int)((b.Price - a.Price) * 1000)); });
                var grouped = meleeWeaponMemoriesSorted.GroupBy(m => m);

                int j = 0;
                foreach (var group in grouped)
                {
                    var weaponMemory = group.Key;
                    var stackCount   = group.Count();
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    int missingCount = parent.missingCountWeaponsOfType(weaponMemory, stackCount, dupeCounters[weaponMemory]);
                    if (missingCount > 0)
                    {
                        bool isDupe     = dupeCounters[weaponMemory] > 0;
                        var  iconOffset = new Vector2((IconSize * (total + j)) + IconGap * ((total + j) - 1) + SelectorPanelWidth, IconSize + IconGap);
                        DrawIconForWeaponMemory(parent, pawnMemory, weaponMemory, missingCount, isDupe, contentRect, iconOffset);
                        j++;
                    }
                    dupeCounters[weaponMemory] += stackCount;
                }
                total += j;
            }

            var unarmedIconOffset = new Vector2((IconSize * total) + IconGap * (total - 1) + SelectorPanelWidth, IconSize + IconGap);

            DrawIconForUnarmed(parent, pawnMemory, contentRect, unarmedIconOffset);

            Rect selectorPanel = new Rect(gizmoRect.x + ContentPadding, gizmoRect.y + ContentPadding, SelectorPanelWidth - ContentPadding * 2, MinGizmoSize - ContentPadding * 2);

            DrawPreferenceSelector(parent, pawnMemory, selectorPanel);

            UIHighlighter.HighlightOpportunity(gizmoRect, "SidearmList");

            if (parent.IsColonistPlayerControlled)
            {
                DrawGizmoLabel(defaultLabel, gizmoRect);
            }
            else
            {
                DrawGizmoLabel(defaultLabel + " (godmode)", gizmoRect);
            }
            return(interactedWith != SidearmsListInteraction.None ? new GizmoResult(GizmoState.Interacted, Event.current) : new GizmoResult(GizmoState.Clear));
        }
Example #7
0
        public void handleInteraction(SidearmsListInteraction interaction, Event ev)
        {
            CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(parent);

            if (pawnMemory == null)
            {
                return;
            }

            var dropMode = parent.Drafted ? DroppingModeEnum.Combat : DroppingModeEnum.Calm;


            if (ev.button == LEFT_CLICK)
            {
                switch (interaction)
                {
                case SidearmsListInteraction.SelectorRanged:
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsPreference, KnowledgeAmount.SpecificInteraction);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                    pawnMemory.primaryWeaponMode = PrimaryWeaponMode.Ranged;
                    break;

                case SidearmsListInteraction.SelectorSkill:
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsPreference, KnowledgeAmount.SpecificInteraction);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                    pawnMemory.primaryWeaponMode = PrimaryWeaponMode.BySkill;
                    break;

                case SidearmsListInteraction.SelectorMelee:
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsPreference, KnowledgeAmount.SpecificInteraction);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                    pawnMemory.primaryWeaponMode = PrimaryWeaponMode.Melee;
                    break;

                case SidearmsListInteraction.Weapon:
                    Thing weapon = interactionWeapon;
                    ThingDefStuffDefPair weaponType = weapon.toThingDefStuffDefPair();
                    if (parent.Drafted)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedDrafted, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.SetWeaponAsForced(weaponType, true);
                        if (parent.equipment.Primary != weapon && weapon is ThingWithComps)
                        {
                            WeaponAssingment.equipSpecificWeaponTypeFromInventory(parent, weaponType, MiscUtils.shouldDrop(dropMode), false);
                        }
                    }
                    else if (pawnMemory.DefaultRangedWeapon == weaponType || pawnMemory.PreferredMeleeWeapon == weaponType || weaponType.isToolNotWeapon())
                    {
                        if (weaponType.thing.IsRangedWeapon)
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                        }
                        else
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                        }
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.SetWeaponAsForced(weaponType, false);
                        if (parent.equipment.Primary != weapon && weapon is ThingWithComps)
                        {
                            WeaponAssingment.equipSpecificWeaponTypeFromInventory(parent, weaponType, MiscUtils.shouldDrop(dropMode), false);
                        }
                    }
                    else
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                        if (weaponType.thing.IsRangedWeapon)
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                            pawnMemory.SetRangedWeaponTypeAsDefault(weaponType);
                        }
                        else
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                            pawnMemory.SetMeleeWeaponTypeAsPreferred(weaponType);
                        }
                    }
                    break;

                case SidearmsListInteraction.WeaponMemory:

                    ThingDefStuffDefPair weaponMemory = interactionWeaponType.Value;
                    if (parent.Drafted)
                    {
                        //allow nothing
                    }
                    else
                    {
                        if (weaponMemory.thing.IsRangedWeapon)
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                            pawnMemory.SetRangedWeaponTypeAsDefault(weaponMemory);
                        }
                        else
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                            pawnMemory.SetMeleeWeaponTypeAsPreferred(weaponMemory);
                        }
                    }
                    break;

                case SidearmsListInteraction.Unarmed:
                    if (parent.Drafted)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedDrafted, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.SetUnarmedAsForced(true);
                        if (parent.equipment.Primary != null)
                        {
                            WeaponAssingment.equipSpecificWeapon(parent, null, MiscUtils.shouldDrop(dropMode), false);
                        }
                    }
                    else if (pawnMemory.PreferredUnarmed)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.SetUnarmedAsForced(false);
                        if (parent.equipment.Primary != null)
                        {
                            WeaponAssingment.equipSpecificWeapon(parent, null, MiscUtils.shouldDrop(dropMode), false);
                        }
                    }
                    else
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.SetUnarmedAsPreferredMelee();
                    }
                    break;

                case SidearmsListInteraction.None:
                default:
                    return;

                    break;
                }
            }
            else if (ev.button == RIGHT_CLICK)
            {
                switch (interaction)
                {
                case SidearmsListInteraction.SelectorRanged:
                case SidearmsListInteraction.SelectorSkill:
                case SidearmsListInteraction.SelectorMelee:
                    break;

                case SidearmsListInteraction.Weapon:
                    Thing weapon = interactionWeapon;
                    ThingDefStuffDefPair weaponType = weapon.toThingDefStuffDefPair();

                    if (interactionWeaponIsDuplicate)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsDropping, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        WeaponAssingment.dropSidearm(parent, weapon, true);
                    }
                    else
                    {
                        if (parent.Drafted)
                        {
                            if (pawnMemory.ForcedWeaponWhileDrafted == weaponType)
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedDrafted, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetForcedWeapon(true);
                            }
                        }
                        else
                        {
                            if (pawnMemory.ForcedWeapon == weaponType)
                            {
                                if (weaponType.thing.IsRangedWeapon)
                                {
                                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                                }
                                else
                                {
                                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                                }
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetForcedWeapon(false);
                            }
                            else if (weaponType.thing.IsRangedWeapon & pawnMemory.DefaultRangedWeapon == weaponType)
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetRangedWeaponDefault();
                            }
                            else if (pawnMemory.PreferredMeleeWeapon == weaponType)
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetMeleeWeaponPreference();
                            }
                            else
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsDropping, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                WeaponAssingment.dropSidearm(parent, weapon, true);
                            }
                        }
                    }

                    break;

                case SidearmsListInteraction.WeaponMemory:
                    ThingDefStuffDefPair weaponMemory = interactionWeaponType.Value;

                    if (interactionWeaponIsDuplicate)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsMissing, KnowledgeAmount.SmallInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.ForgetSidearmMemory(weaponMemory);
                    }
                    else
                    {
                        if (parent.Drafted)
                        {
                            if (pawnMemory.ForcedWeaponWhileDrafted == weaponMemory)
                            {
                                if (weaponMemory.thing.IsRangedWeapon)
                                {
                                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                                }
                                else
                                {
                                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                                }
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetForcedWeapon(true);
                            }
                        }
                        else
                        {
                            if (pawnMemory.ForcedWeapon == weaponMemory)
                            {
                                if (weaponMemory.thing.IsRangedWeapon)
                                {
                                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                                }
                                else
                                {
                                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                                }
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetForcedWeapon(false);
                            }
                            else if (weaponMemory.thing.IsRangedWeapon & pawnMemory.DefaultRangedWeapon == weaponMemory)
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetRangedWeaponDefault();
                            }
                            else if (pawnMemory.PreferredMeleeWeapon == weaponMemory)
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.UnsetMeleeWeaponPreference();
                            }
                            else
                            {
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsMissing, KnowledgeAmount.SpecificInteraction);
                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                                pawnMemory.ForgetSidearmMemory(weaponMemory);
                            }
                        }
                    }

                    break;

                case SidearmsListInteraction.Unarmed:
                    if (parent.Drafted && pawnMemory.ForcedUnarmedWhileDrafted)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedDrafted, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.UnsetUnarmedAsForced(true);
                    }
                    else if (pawnMemory.ForcedUnarmed)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.UnsetUnarmedAsForced(false);
                    }
                    else if (pawnMemory.PreferredUnarmed)
                    {
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);

                        pawnMemory.UnsetMeleeWeaponPreference();
                    }
                    break;

                case SidearmsListInteraction.None:
                default:
                    return;

                    break;
                }
            }
        }
Example #8
0
        public void DrawIconForUnarmed(Pawn pawn, CompSidearmMemory pawnMemory, Rect contentRect, Vector2 iconOffset)
        {
            var iconRect = new Rect(contentRect.x + iconOffset.x, contentRect.y + iconOffset.y, IconSize, IconSize);
            //var iconColor = iconBaseColor;

            string hoverText;

            if (pawn.Drafted)
            {
                if (pawnMemory.ForcedUnarmedWhileDrafted)
                {
                    hoverText = "DrawSidearm_gizmoTooltipUnarmedForcedWhileDrafted";
                }
                else
                {
                    hoverText = "DrawSidearm_gizmoTooltipUnarmedWhileDrafted";
                }
            }
            else
            {
                if (pawnMemory.ForcedUnarmed)
                {
                    hoverText = "DrawSidearm_gizmoTooltipUnarmedForced";
                }
                else if (pawnMemory.PreferredUnarmed)
                {
                    hoverText = "DrawSidearm_gizmoTooltipUnarmedPreferred";
                }
                else
                {
                    hoverText = "DrawSidearm_gizmoTooltipUnarmed";
                }
            }

            TooltipHandler.TipRegion(iconRect, hoverText.Translate());
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.Mouseover_Command);

            Texture2D drawPocket = TextureResources.drawPocket;

            if (Mouse.IsOver(iconRect))
            {
                GUI.color = iconMouseOverColor;
                GUI.DrawTexture(iconRect, drawPocket);
                //Graphics.DrawTexture(iconRect, TextureResources.drawPocket, new Rect(0, 0, 1f, 1f), 0, 0, 0, 0, iconMouseOverColor);
            }
            else
            {
                GUI.color = iconBaseColor;
                GUI.DrawTexture(iconRect, drawPocket);
                //Graphics.DrawTexture(iconRect, TextureResources.drawPocket, new Rect(0, 0, 1f, 1f), 0, 0, 0, 0, iconBaseColor);
            }

            Texture resolvedIcon = TexCommand.AttackMelee;

            GUI.color = Color.white;
            GUI.DrawTexture(iconRect, resolvedIcon);
            GUI.color = Color.white;

            GUI.color = Color.white;

            if (pawnMemory.ForcedUnarmedWhileDrafted)
            {
                GUI.DrawTexture(iconRect, TextureResources.forcedDrafted);
            }

            if (pawnMemory.ForcedUnarmed)
            {
                GUI.DrawTexture(iconRect, TextureResources.forcedAlways);
            }

            if (pawnMemory.PreferredUnarmed)
            {
                GUI.DrawTexture(iconRect, TextureResources.preferredMelee);
            }
            else
            {
                GUI.color = Color.white;
            }

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                interactedWith = SidearmsListInteraction.Unarmed;
            }
        }
Example #9
0
        public void DrawIconForWeapon(Pawn pawn, CompSidearmMemory pawnMemory, ThingWithComps weapon, bool isDuplicate, Rect contentRect, Vector2 iconOffset)
        {
            if (weapon is null || weapon.def is null || weapon.def.uiIcon is null)
            {
                return;
            }

            ThingDefStuffDefPair weaponType = weapon.toThingDefStuffDefPair();

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

            string hoverText;

            if (pawn.Drafted)
            {
                if (pawnMemory.ForcedWeaponWhileDrafted == weapon.toThingDefStuffDefPair())
                {
                    hoverText = "DrawSidearm_gizmoTooltipForcedWhileDrafted";
                }
                else
                {
                    hoverText = "DrawSidearm_gizmoTooltipWhileDrafted";
                }
            }
            else
            {
                if (pawnMemory.ForcedWeapon == weapon.toThingDefStuffDefPair())
                {
                    hoverText = "DrawSidearm_gizmoTooltipForced";
                }
                else
                {
                    if (weapon.def.IsRangedWeapon)
                    {
                        if (pawnMemory.DefaultRangedWeapon == weaponType)
                        {
                            hoverText = "DrawSidearm_gizmoTooltipRangedDefault";
                        }
                        else
                        {
                            hoverText = "DrawSidearm_gizmoTooltipRanged";
                        }
                    }
                    else
                    {
                        if (pawnMemory.PreferredMeleeWeapon == weaponType)
                        {
                            hoverText = "DrawSidearm_gizmoTooltipMeleePreferred";
                        }
                        else
                        {
                            hoverText = "DrawSidearm_gizmoTooltipMelee";
                        }
                    }
                }
            }

            TooltipHandler.TipRegion(iconRect, string.Format(hoverText.Translate(), weapon.toThingDefStuffDefPair().getLabel()));
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.Mouseover_Command);

            Texture2D drawPocket;

            if (pawnMemory.RememberedWeapons.Contains(weapon.toThingDefStuffDefPair()))
            {
                drawPocket = TextureResources.drawPocket;
            }
            else
            {
                drawPocket = TextureResources.drawPocketTemp;
            }

            if (Mouse.IsOver(iconRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SidearmsDropping, OpportunityType.GoodToKnow);

                if (pawn.Drafted)
                {
                    LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsAdvancedDrafted, OpportunityType.GoodToKnow);
                }
                else
                {
                    if (weapon.def.IsRangedWeapon)
                    {
                        LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsAdvancedRanged, OpportunityType.GoodToKnow);
                    }
                    else
                    {
                        LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsAdvancedMelee, OpportunityType.GoodToKnow);
                    }
                }

                GUI.color = iconMouseOverColor;
                GUI.DrawTexture(iconRect, drawPocket);
                //Graphics.DrawTexture(iconRect, TextureResources.drawPocket, new Rect(0, 0, 1f, 1f), 0, 0, 0, 0, iconMouseOverColor);
            }
            else
            {
                GUI.color = iconBaseColor;
                GUI.DrawTexture(iconRect, drawPocket);
                //Graphics.DrawTexture(iconRect, TextureResources.drawPocket, new Rect(0, 0, 1f, 1f), 0, 0, 0, 0, iconBaseColor);
            }

            Graphic outerGraphic = weaponType.thing.graphic;

            if (outerGraphic is Graphic_StackCount)
            {
                outerGraphic = (outerGraphic as Graphic_StackCount).SubGraphicForStackCount(weapon.stackCount, weaponType.thing);
            }

            Material material     = outerGraphic.ExtractInnerGraphicFor(null).MatAt(weaponType.thing.defaultPlacingRot, null);
            Texture  resolvedIcon = (Texture2D)material.mainTexture;

            GUI.color = weapon.DrawColor;
            GUI.DrawTexture(iconRect, resolvedIcon);
            GUI.color = Color.white;

            if (weapon.stackCount > 1)
            {
                var store = Text.Anchor;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(iconRect, weapon.stackCount.ToString());
                Text.Anchor = store;
            }

            if (!isDuplicate)
            {
                GUI.color = Color.white;


                if (pawnMemory.ForcedWeaponWhileDrafted == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.forcedDrafted);
                }

                if (pawnMemory.ForcedWeapon == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.forcedAlways);
                }

                if (weaponType.thing.IsRangedWeapon & pawnMemory.DefaultRangedWeapon == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.defaultRanged);
                }
                else if (pawnMemory.PreferredMeleeWeapon == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.preferredMelee);
                }

                GUI.color = Color.white;
            }

            UIHighlighter.HighlightOpportunity(iconRect, "SidearmInInventory");
            if (weapon.def.IsRangedWeapon)
            {
                UIHighlighter.HighlightOpportunity(iconRect, "SidearmInInventoryRanged");
            }
            else
            {
                UIHighlighter.HighlightOpportunity(iconRect, "SidearmInInventoryMelee");
            }

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                interactedWith               = SidearmsListInteraction.Weapon;
                interactionWeapon            = weapon;
                interactionWeaponIsDuplicate = isDuplicate;
            }
        }
Example #10
0
        public void DrawIconForWeaponMemory(Pawn pawn, CompSidearmMemory pawnMemory, ThingDefStuffDefPair weaponType, int stackCount, bool isDuplicate, Rect contentRect, Vector2 iconOffset)
        {
            Graphic g = weaponType.thing.graphicData.Graphic;

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

            Texture2D drawPocket;

            drawPocket = TextureResources.drawPocketMemory;

            if (pawn.Drafted)
            {
                TooltipHandler.TipRegion(iconRect, string.Format("DrawSidearm_gizmoTooltipMemoryWhileDrafted".Translate(), weaponType.getLabel()));
            }
            else
            {
                TooltipHandler.TipRegion(iconRect, string.Format("DrawSidearm_gizmoTooltipMemory".Translate(), weaponType.getLabel()));
            }
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.Mouseover_Command);
            if (Mouse.IsOver(iconRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SidearmsMissing, OpportunityType.GoodToKnow);

                GUI.color = iconMouseOverColor;
                GUI.DrawTexture(iconRect, drawPocket);
            }
            else
            {
                GUI.color = iconBaseColor;
                GUI.DrawTexture(iconRect, drawPocket);
            }

            Graphic outerGraphic = weaponType.thing.graphic;

            if (outerGraphic is Graphic_StackCount)
            {
                outerGraphic = (outerGraphic as Graphic_StackCount).SubGraphicForStackCount(stackCount, weaponType.thing);
            }

            Material material     = outerGraphic.ExtractInnerGraphicFor(null).MatAt(weaponType.thing.defaultPlacingRot, null);
            Texture  resolvedIcon = (Texture2D)material.mainTexture;

            GUI.color = weaponType.getDrawColor();
            GUI.DrawTexture(iconRect, resolvedIcon);
            GUI.color = Color.white;

            if (stackCount > 1)
            {
                var store = Text.Anchor;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(iconRect, stackCount.ToString());
                Text.Anchor = store;
            }

            if (!isDuplicate)
            {
                GUI.color = Color.white;

                if (pawnMemory.ForcedWeapon == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.forcedAlways);
                }

                if (weaponType.thing.IsRangedWeapon & pawnMemory.DefaultRangedWeapon == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.defaultRanged);
                }
                else if (pawnMemory.PreferredMeleeWeapon == weaponType)
                {
                    GUI.DrawTexture(iconRect, TextureResources.preferredMelee);
                }

                GUI.color = Color.white;
            }

            UIHighlighter.HighlightOpportunity(iconRect, "SidearmMissing");

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                interactedWith               = SidearmsListInteraction.WeaponMemory;
                interactionWeaponType        = weaponType;
                interactionWeaponIsDuplicate = isDuplicate;
            }
        }
Example #11
0
        public void DrawPreferenceSelector(Pawn pawn, CompSidearmMemory pawnMemory, Rect contentRect)
        {
            var rangedIconRect = new Rect(contentRect.x, contentRect.y, PreferenceIconWidth, PreferenceIconHeight);
            var skillIconRect  = new Rect(contentRect.x, contentRect.y + PreferenceIconHeight + IconGap, PreferenceIconWidth, PreferenceIconHeight);
            var meleeIconRect  = new Rect(contentRect.x, contentRect.y + (PreferenceIconHeight + IconGap) * 2, PreferenceIconWidth, PreferenceIconHeight);

            var skillPref = pawn.getSkillWeaponPreference();

            if (Mouse.IsOver(contentRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsBasic, OpportunityType.Important);
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SimpleSidearmsPreference, OpportunityType.Important);
            }

            if (Mouse.IsOver(rangedIconRect))
            {
                if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.Ranged)
                {
                    GUI.color = preferenceHighlightSet;
                }
                else
                {
                    GUI.color = preferenceHighlight;
                }
                GUI.DrawTexture(rangedIconRect, TextureResources.preferRanged);
                TooltipHandler.TipRegion(rangedIconRect, string.Format("SidearmPreference_Ranged".Translate()));
                MouseoverSounds.DoRegion(rangedIconRect, SoundDefOf.Mouseover_Command);
            }
            else
            {
                if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.Ranged)
                {
                    GUI.color = preferenceSet;
                }
                else if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.BySkill && skillPref == PrimaryWeaponMode.Ranged)
                {
                    GUI.color = preferenceOfSkill;
                }
                else
                {
                    GUI.color = preferenceBase;
                }
                GUI.DrawTexture(rangedIconRect, TextureResources.preferRanged);
            }

            if (Mouse.IsOver(skillIconRect))
            {
                if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.BySkill)
                {
                    GUI.color = preferenceHighlightSet;
                }
                else
                {
                    GUI.color = preferenceHighlight;
                }
                GUI.DrawTexture(skillIconRect, TextureResources.preferSkilled);
                TooltipHandler.TipRegion(skillIconRect, string.Format("SidearmPreference_Skill".Translate()));
                MouseoverSounds.DoRegion(skillIconRect, SoundDefOf.Mouseover_Command);
            }
            else
            {
                if (pawn.skills != null)
                {
                    if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.BySkill)
                    {
                        GUI.color = preferenceSet;
                    }
                    else
                    {
                        GUI.color = preferenceBase;
                    }
                    GUI.DrawTexture(skillIconRect, TextureResources.preferSkilled);
                }
            }

            if (Mouse.IsOver(meleeIconRect))
            {
                if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.Melee)
                {
                    GUI.color = preferenceHighlightSet;
                }
                else
                {
                    GUI.color = preferenceHighlight;
                }
                GUI.DrawTexture(meleeIconRect, TextureResources.preferMelee);
                TooltipHandler.TipRegion(meleeIconRect, string.Format("SidearmPreference_Melee".Translate()));
                MouseoverSounds.DoRegion(meleeIconRect, SoundDefOf.Mouseover_Command);
            }
            else
            {
                if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.Melee)
                {
                    GUI.color = preferenceSet;
                }
                else if (pawnMemory.primaryWeaponMode == PrimaryWeaponMode.BySkill && skillPref == PrimaryWeaponMode.Melee)
                {
                    GUI.color = preferenceOfSkill;
                }
                else
                {
                    GUI.color = preferenceBase;
                }
                GUI.DrawTexture(meleeIconRect, TextureResources.preferMelee);
            }

            UIHighlighter.HighlightOpportunity(rangedIconRect, "SidearmPreferenceButton");
            UIHighlighter.HighlightOpportunity(skillIconRect, "SidearmPreferenceButton");
            UIHighlighter.HighlightOpportunity(meleeIconRect, "SidearmPreferenceButton");

            if (Widgets.ButtonInvisible(rangedIconRect, true))
            {
                interactedWith = SidearmsListInteraction.SelectorRanged;
            }
            if (Widgets.ButtonInvisible(skillIconRect, true))
            {
                interactedWith = SidearmsListInteraction.SelectorSkill;
            }
            if (Widgets.ButtonInvisible(meleeIconRect, true))
            {
                interactedWith = SidearmsListInteraction.SelectorMelee;
            }
        }
Example #12
0
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (!Settings.ReEquipOutOfCombat)
            {
                return(null);
            }
            if (!Settings.ReEquipInCombat && inCombat)
            {
                return(null);
            }
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }
            else
            {
                if (!pawn.IsValidSidearmsCarrier())
                {
                    return(null);
                }

                CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                //if (pawnMemory.IsUsingAutotool(true))
                //    return null;

                //WeaponAssingment.equipBestWeaponFromInventoryByPreference(pawn, Globals.DroppingModeEnum.Calm);

                if (pawnMemory.RememberedWeapons is null)
                {
                    Log.Warning("pawnMemory of " + pawn.Label + " is missing remembered weapons");
                }

                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();

                foreach (ThingDefStuffDefPair weaponMemory in pawnMemory.RememberedWeapons)
                {
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    if (!pawn.hasWeaponType(weaponMemory, dupeCounters[weaponMemory]))
                    {
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer)
                        {
                            maxDist = 30f;
                        }
                        if (inCombat)
                        {
                            maxDist = 12f;
                        }

                        bool bladelinkable = weaponMemory.thing.HasComp(typeof(CompBladelinkWeapon));
                        bool biocodeable   = weaponMemory.thing.HasComp(typeof(CompBiocodable));

                        IEnumerable <ThingWithComps> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).OfType <ThingWithComps>().Where(t => t.Stuff == weaponMemory.stuff);
                        if (bladelinkable)
                        {
                            matchingWeapons = matchingWeapons.Where(t =>
                            {
                                CompBladelinkWeapon bladelink = t.GetComp <CompBladelinkWeapon>();
                                return(bladelink != null && bladelink.Biocoded && bladelink.CodedPawn == pawn);
                            });
                        }
                        if (biocodeable)
                        {
                            matchingWeapons = matchingWeapons.Where(t =>
                            {
                                CompBiocodable biocode = t.GetComp <CompBiocodable>();
                                if (biocode == null)
                                {
                                    return(true); //not sure how this could ever happen...
                                }
                                if (biocode.Biocoded && biocode.CodedPawn != pawn)
                                {
                                    return(false);
                                }
                                return(true);
                            });
                        }

                        Thing thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, matchingWeapons, PathEndMode.OnCell, TraverseParms.For(pawn), maxDist,
                                                                               (Thing t) => !t.IsForbidden(pawn) && pawn.CanReserve(t),
                                                                               (Thing t) => Settings.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0);
                        //this works properly because better ranged weapons also happen to be better at pistolwhipping
                        //okay past me, WHAT? Why?

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondary, thing));
                        }
                        else
                        {
                            return(JobMaker.MakeJob(SidearmsDefOf.ReequipSecondaryCombat, thing, pawn.Position));
                        }
                    }

                    dupeCounters[weaponMemory]++;
                }

                return(null);
            }
        }
        //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);
            }
        }