Beispiel #1
0
 public void SetRangedWeaponTypeAsDefault(ThingDefStuffDefPair rangedWeapon)
 {
     this.DefaultRangedWeapon = rangedWeapon;
     if (this.ForcedWeapon != null && this.ForcedWeapon != rangedWeapon && this.ForcedWeapon.Value.thing.IsRangedWeapon)
     {
         UnsetForcedWeapon(false);
     }
 }
        public void InformOfAddedSidearm(Thing weapon)
        {
            ThingDefStuffDefPair weaponType = weapon.toThingDefStuffDefPair();
            var carriedOfType    = Owner.getCarriedWeapons(includeTools: true).Where(w => w.toThingDefStuffDefPair() == weaponType);
            var rememberedOfType = rememberedWeapons.Where(w => w == weaponType);

            if (rememberedOfType.Count() < carriedOfType.Count())
            {
                rememberedWeapons.Add(weapon.toThingDefStuffDefPair());
            }
        }
Beispiel #3
0
        public void generateRememberedWeaponsFromEquipped()
        {
            this.rememberedWeapons = new List <ThingDefStuffDefPair>();
            IEnumerable <ThingWithComps> carriedWeapons = Owner.getCarriedWeapons(includeTools: true);

            foreach (ThingWithComps weapon in carriedWeapons)
            {
                ThingDefStuffDefPair pair = new ThingDefStuffDefPair(weapon.def, weapon.Stuff);
                rememberedWeapons.Add(pair);
            }
        }
Beispiel #4
0
 public void SetMeleeWeaponTypeAsPreferred(ThingDefStuffDefPair meleeWeapon)
 {
     this.preferredUnarmedEx   = false;
     this.PreferredMeleeWeapon = meleeWeapon;
     if (this.ForcedWeapon != null && this.ForcedWeapon != meleeWeapon && this.ForcedWeapon.Value.thing.IsMeleeWeapon)
     {
         UnsetForcedWeapon(false);
     }
     if (ForcedUnarmed)
     {
         UnsetUnarmedAsForced(false);
     }
 }
Beispiel #5
0
 public void SetWeaponAsForced(ThingDefStuffDefPair weapon, bool drafted)
 {
     if (drafted)
     {
         ForcedUnarmedWhileDrafted = false;
         ForcedWeaponWhileDrafted  = weapon;
     }
     else
     {
         ForcedUnarmed = false;
         ForcedWeapon  = weapon;
     }
 }
Beispiel #6
0
        public void ForgetSidearmMemory(ThingDefStuffDefPair weaponMemory)
        {
            if (rememberedWeapons.Contains(weaponMemory))
            {
                rememberedWeapons.Remove(weaponMemory);
            }

            if (!rememberedWeapons.Contains(weaponMemory)) //only remove if this was the last instance
            {
                if (weaponMemory == ForcedWeapon)
                {
                    ForcedWeapon = null;
                }
                if (weaponMemory == PreferredMeleeWeapon)
                {
                    PreferredMeleeWeapon = null;
                }
                if (weaponMemory == DefaultRangedWeapon)
                {
                    PreferredMeleeWeapon = null;
                }
            }
        }
Beispiel #7
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));
        }
Beispiel #8
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;
                }
            }
        }
Beispiel #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;
            }
        }
Beispiel #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;
            }
        }
        //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);
            }
        }
        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);

            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(parent);

            int i = 0;
            {
                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();
                var rangedWeapons = carriedRangedWeapons.ToList();
                rangedWeapons.SortStable((a, b) => { return((int)((b.MarketValue - a.MarketValue) * 1000)); });
                for (i = 0; i < rangedWeapons.Count(); i++)
                {
                    ThingDefStuffDefPair weaponMemory = rangedWeapons[i].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, rangedWeapons[i], isDupe, contentRect, iconOffset);

                    dupeCounters[weaponMemory]++;
                }
            }

            int j = 0;

            if (pawnMemory != null)
            {
                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();
                var rangedWeaponMemoriesSorted = rangedWeaponMemories.ToList();
                rangedWeaponMemoriesSorted.SortStable((a, b) => { return((int)((b.Price - a.Price) * 1000)); });
                foreach (ThingDefStuffDefPair weaponMemory in rangedWeaponMemoriesSorted)
                {
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

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

                    dupeCounters[weaponMemory]++;
                }
            }

            {
                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();
                var meleeWeapons = carriedMeleeWeapons.ToList();
                meleeWeapons.SortStable((a, b) => { return((int)((b.MarketValue - a.MarketValue) * 1000)); });
                for (i = 0; i < meleeWeapons.Count(); i++)
                {
                    ThingDefStuffDefPair weaponMemory = meleeWeapons[i].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, meleeWeapons[i], isDupe, contentRect, iconOffset);

                    dupeCounters[weaponMemory]++;
                }
            }


            j = 0;
            if (pawnMemory != null)
            {
                Dictionary <ThingDefStuffDefPair, int> dupeCounters = new Dictionary <ThingDefStuffDefPair, int>();
                var meleeWeaponMemoriesSorted = meleeWeaponMemories.ToList();
                meleeWeaponMemoriesSorted.SortStable((a, b) => { return((int)((b.Price - a.Price) * 1000)); });
                foreach (ThingDefStuffDefPair weaponMemory in meleeWeaponMemoriesSorted)
                {
                    if (!dupeCounters.ContainsKey(weaponMemory))
                    {
                        dupeCounters[weaponMemory] = 0;
                    }

                    if (!parent.hasWeaponSomewhere(weaponMemory, dupeCounters[weaponMemory]))
                    {
                        bool isDupe     = dupeCounters[weaponMemory] > 0;
                        var  iconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + SelectorPanelWidth, IconSize + IconGap);

                        DrawIconForWeaponMemory(parent, pawnMemory, weaponMemory, isDupe, contentRect, iconOffset);

                        dupeCounters[weaponMemory]++;
                        j++;
                    }
                }
            }

            var unarmedIconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 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));
        }
        public void DrawIconForWeaponMemory(Pawn pawn, GoldfishModule pawnMemory, ThingDefStuffDefPair weaponType, 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);
            }

            Texture resolvedIcon = weaponType.thing.uiIcon;

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

            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;
            }
        }