Example #1
0
        private int calcUnmatchedRangedWeapons(GoldfishModule pawnMemory, Pawn pawn)
        {
            if (pawnMemory == null)
            {
                return(0);
            }

            int count = 0;

            foreach (string weapon in pawnMemory.weapons)
            {
                ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(weapon);

                if (def == null)
                {
                    continue;
                }
                if (!def.IsRangedWeapon)
                {
                    continue;
                }
                if (!pawn.hasWeaponSomewhere(def))
                {
                    count++;
                }
            }
            return(count);
        }
Example #2
0
        public static GoldfishModule GetGoldfishForPawn(Pawn pawn, bool fillExistingIfCreating = true)
        {
            if (pawn == null)
            {
                return(null);
            }
            if (SimpleSidearms.CEOverride)
            {
                return(null);
            }
            if (SimpleSidearms.configData == null)
            {
                return(null);
            }
            var            pawnId = pawn.thingIDNumber;
            GoldfishModule memory;

            if (!SimpleSidearms.configData.memories.TryGetValue(pawnId, out memory))
            {
                memory = new GoldfishModule(pawn, fillExistingIfCreating);
                SimpleSidearms.configData.memories.Add(pawnId, memory);
            }
            else
            {
                memory.NullChecks(pawn);
            }
            return(memory);
        }
Example #3
0
        public int countMissingRangedWeapons(GoldfishModule pawnMemory, Pawn pawn)
        {
            if (pawnMemory == null)
            {
                return(0);
            }

            int count = 0;

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

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

                if (!weapon.thing.IsRangedWeapon)
                {
                    continue;
                }
                if (!pawn.hasWeaponSomewhere(weapon, dupeCounters[weapon]))
                {
                    count++;
                }

                dupeCounters[weapon]++;
            }
            return(count);
        }
Example #4
0
        private bool DrawIconForWeapon(GoldfishModule pawnMemory, Thing weapon, Rect contentRect, Vector2 iconOffset)
        {
            var   iconTex = weapon.def.uiIcon;
            Color color   = weapon.DrawColor;

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

            //var iconColor = iconBaseColor;

            TooltipHandler.TipRegion(iconRect, string.Format("DrawSidearm_gizmoTooltip".Translate(), weapon.LabelShort));
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.MouseoverCommand);

            Texture2D drawPocket;

            if (pawnMemory.IsCurrentPrimary(weapon.def.defName))
            {
                drawPocket = TextureResources.drawPocketPrimary;
            }
            else
            {
                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;

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

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        public override float GetWidth(float maxWidth)
        {
            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(parent);
            //if (pawnMemory == null)
            //    return 75;
            int   biggerCount = Math.Max(rangedWeapons.Count + calcUnmatchedRangedWeapons(pawnMemory, parent), meleeWeapons.Count + calcUnmatchedMeleeWeapons(pawnMemory, parent) + 1);
            float width       = ContentPadding * 2 + (IconSize * biggerCount) + IconGap * (biggerCount - 1) + LockPanelWidth;

            return(Math.Min(width, maxWidth));
        }
Example #6
0
        public override float GetWidth(float maxWidth)
        {
            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(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 #7
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
                    {
                        thingWithComps2 = thingWithComps;
                        thingWithComps2.DeSpawn();
                    }
                    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)
                    {
                        GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(this.pawn);
                        if (pawnMemory == null)
                        {
                            return;
                        }
                        if (MemorizeOnPickup)
                        {
                            pawnMemory.InformOfAddedSidearm(thingWithComps2);
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            Toil onFinish = OnFinish();

            if (onFinish != null)
            {
                yield return(onFinish);
            }
        }
Example #8
0
        public void backfillFromGoldfish(GoldfishModule obsoleteMemory)
        {
            this.rememberedWeapons = obsoleteMemory.rememberedWeapons;

            this.forcedWeaponEx              = obsoleteMemory.forcedWeaponEx;
            this.forcedUnarmedEx             = obsoleteMemory.forcedUnarmedEx;
            this.forcedWeaponWhileDraftedEx  = obsoleteMemory.forcedWeaponWhileDraftedEx;
            this.forcedUnarmedWhileDraftedEx = obsoleteMemory.forcedUnarmedWhileDraftedEx;

            this.preferredUnarmedEx     = obsoleteMemory.preferredUnarmedEx;
            this.defaultRangedWeaponEx  = obsoleteMemory.defaultRangedWeaponEx;
            this.preferredMeleeWeaponEx = obsoleteMemory.preferredMeleeWeaponEx;

            this.primaryWeaponMode = obsoleteMemory.primaryWeaponMode;
        }
Example #9
0
        public static GoldfishModule GetGoldfishForPawn(Pawn pawn)
        {
            if (SimpleSidearms.saveData == null)
            {
                return(null);
            }
            var            pawnId = pawn.thingIDNumber;
            GoldfishModule memory;

            if (!SimpleSidearms.saveData.memories.TryGetValue(pawnId, out memory))
            {
                memory = new GoldfishModule(pawn, true);
                SimpleSidearms.saveData.memories.Add(pawnId, memory);
            }
            return(memory);
        }
Example #10
0
        public void DrawIconForWeapon(Pawn pawn, GoldfishModule pawnMemory, ThingWithComps weapon, bool isDuplicate, Rect contentRect, Vector2 iconOffset)
        {
            if (weapon is null || weapon.def is null || weapon.def.uiIcon is null)
            {
                return;
            }

            ThingStuffPair weaponType = weapon.toThingStuffPair();

            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.toThingStuffPair())
                {
                    hoverText = "DrawSidearm_gizmoTooltipForcedWhileDrafted";
                }
                else
                {
                    hoverText = "DrawSidearm_gizmoTooltipWhileDrafted";
                }
            }
            else
            {
                if (pawnMemory.ForcedWeapon == weapon.toThingStuffPair())
                {
                    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.toThingStuffPair().getLabel()));
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.Mouseover_Command);

            Texture2D drawPocket;

            if (pawnMemory.RememberedWeapons.Contains(weapon.toThingStuffPair()))
            {
                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);
            }

            Texture resolvedIcon;

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


            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 #11
0
        public void DrawIconForWeaponMemory(Pawn pawn, GoldfishModule pawnMemory, ThingStuffPair 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;
            }
        }
Example #12
0
        public void DrawPreferenceSelector(Pawn pawn, GoldfishModule 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 == GoldfishModule.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 == GoldfishModule.PrimaryWeaponMode.Ranged)
                {
                    GUI.color = preferenceSet;
                }
                else if (pawnMemory.primaryWeaponMode == GoldfishModule.PrimaryWeaponMode.BySkill && skillPref == GoldfishModule.PrimaryWeaponMode.Ranged)
                {
                    GUI.color = preferenceOfSkill;
                }
                else
                {
                    GUI.color = preferenceBase;
                }
                GUI.DrawTexture(rangedIconRect, TextureResources.preferRanged);
            }

            if (Mouse.IsOver(skillIconRect))
            {
                if (pawnMemory.primaryWeaponMode == GoldfishModule.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 (pawnMemory.primaryWeaponMode == GoldfishModule.PrimaryWeaponMode.BySkill)
                {
                    GUI.color = preferenceSet;
                }
                else
                {
                    GUI.color = preferenceBase;
                }
                GUI.DrawTexture(skillIconRect, TextureResources.preferSkilled);
            }

            if (Mouse.IsOver(meleeIconRect))
            {
                if (pawnMemory.primaryWeaponMode == GoldfishModule.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 == GoldfishModule.PrimaryWeaponMode.Melee)
                {
                    GUI.color = preferenceSet;
                }
                else if (pawnMemory.primaryWeaponMode == GoldfishModule.PrimaryWeaponMode.BySkill && skillPref == GoldfishModule.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;
            }
        }
        private bool DrawIconForWeapon(GoldfishModule pawnMemory, Thing weapon, Rect contentRect, Vector2 iconOffset)
        {
            var   iconTex = weapon.def.uiIcon;
            Color color   = weapon.DrawColor;

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

            //var iconColor = iconBaseColor;

            TooltipHandler.TipRegion(iconRect, string.Format("DrawSidearm_gizmoTooltip".Translate(), weapon.LabelShort));
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.Mouseover_Command);

            Texture2D drawPocket = TextureResources.drawPocketTemp;

            if (pawnMemory != null && pawnMemory.IsCurrentPrimary(weapon.def.defName))
            {
                drawPocket = TextureResources.drawPocketPrimary;
            }
            else
            {
                if (pawnMemory != null)
                {
                    foreach (string weaponName in pawnMemory.weapons)
                    {
                        if (weaponName.Equals(weapon.def.defName))
                        {
                            drawPocket = TextureResources.drawPocket;
                            break;
                        }
                    }
                }
            }

            if (Mouse.IsOver(iconRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SidearmsInInventory, OpportunityType.GoodToKnow);
                if (pawnMemory != null && pawnMemory.IsCurrentPrimary(weapon.def.defName))
                {
                    LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SidearmsPrimary, 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);
            }

            Texture resolvedIcon;

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

            UIHighlighter.HighlightOpportunity(iconRect, "SidearmInInventory");
            if (pawnMemory != null && pawnMemory.IsCurrentPrimary(weapon.def.defName))
            {
                UIHighlighter.HighlightOpportunity(iconRect, "SidearmPrimary");
            }

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #14
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            //Log.Message("retrieval precheck for " + pawn.LabelShort);
            if (pawn.Faction != Faction.OfPlayer)
            {
                return(null);
            }

            if (pawn.Drafted)
            {
                return(null);
            }

            /*if (Find.TickManager.TicksGame > GetNextTryTick(pawn))
             * {
             *  return null;
             * }
             * else*/
            {
                //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax));

                //Log.Message("retrieval check for " + pawn.LabelShort);

                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory);

                foreach (string wepName in pawnMemory.weapons)
                {
                    //Log.Message("checking "+wepName);
                    ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName);

                    if (def == null)
                    {
                        continue;
                    }

                    if (!pawn.hasWeaponSomewhere(wepName))
                    {
                        //Log.Message("looking for");
                        ThingRequest request = new ThingRequest();
                        request.singleDef = def;
                        Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 1000f, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false));

                        if (thing == null)
                        {
                            continue;
                        }

                        return(new Job(SidearmsJobDefOf.EquipSecondary, thing));
                    }
                }

                return(null);
            }
        }
Example #15
0
        public void handleInteraction(SidearmsListInteraction interaction, Event ev)
        {
            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(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 = GoldfishModule.PrimaryWeaponMode.Ranged;
                    break;

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

                    pawnMemory.primaryWeaponMode = GoldfishModule.PrimaryWeaponMode.BySkill;
                    break;

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

                    pawnMemory.primaryWeaponMode = GoldfishModule.PrimaryWeaponMode.Melee;
                    break;

                case SidearmsListInteraction.Weapon:
                    Thing          weapon     = interactionWeapon;
                    ThingStuffPair weaponType = weapon.toThingStuffPair();
                    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)
                    {
                        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:

                    ThingStuffPair 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;
                    ThingStuffPair weaponType = weapon.toThingStuffPair();

                    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:
                    ThingStuffPair 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 #16
0
        public void DrawIconForUnarmed(Pawn pawn, GoldfishModule 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 #17
0
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }

            {
                //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax));


                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory);

                foreach (string wepName in pawnMemory.weapons)
                {
                    ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName);

                    if (def == null)
                    {
                        continue;
                    }

                    if (!pawn.hasWeaponSomewhere(wepName))
                    {
                        ThingRequest request = new ThingRequest();
                        request.singleDef = def;
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer || inCombat)
                        {
                            maxDist = 30f;
                        }
                        Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), maxDist, (Thing x) => (!x.IsForbidden(pawn)) && pawn.CanReserve(x, 1, -1, null, false));

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(new Job(SidearmsDefOf.EquipSecondary, thing));
                        }
                        else
                        {
                            return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position));
                        }
                    }
                }

                return(null);
            }
        }
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }
            else
            {
                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                if (SimpleSidearms.ToolAutoSwitch && ((Find.TickManager.TicksGame - pawnMemory.delayIdleSwitchTimestamp) < 60))
                {
                    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.hasWeaponSomewhere(weaponMemory, dupeCounters[weaponMemory]))
                    {
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer)
                        {
                            maxDist = 30f;
                        }
                        if (inCombat)
                        {
                            maxDist = 12f;
                        }
                        IEnumerable <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(weaponMemory.thing).Where(t => t.Stuff == weaponMemory.stuff);

                        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) => SimpleSidearms.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);
            }
        }
Example #19
0
        private static bool DrawIconForWeaponMemory(GoldfishModule pawnMemory, ThingDef weapon, Rect contentRect, Vector2 iconOffset)
        {
            var     iconTex  = weapon.uiIcon;
            Graphic g        = weapon.graphicData.Graphic;
            Color   color    = getColor(weapon);
            Color   colorTwo = getColor(weapon);
            Graphic g2       = weapon.graphicData.Graphic.GetColoredVersion(g.Shader, color, colorTwo);

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

            string label = weapon.label;

            Texture2D drawPocket;

            if (pawnMemory.IsCurrentPrimary(weapon.defName))
            {
                drawPocket = TextureResources.drawPocketMemoryPrimary;
            }
            else
            {
                drawPocket = TextureResources.drawPocketMemory;
            }

            TooltipHandler.TipRegion(iconRect, string.Format("DrawSidearm_gizmoTooltipMemory".Translate(), weapon.label));
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.MouseoverCommand);
            if (Mouse.IsOver(iconRect))
            {
                LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SidearmsMissing, OpportunityType.GoodToKnow);
                if (pawnMemory.IsCurrentPrimary(weapon.defName))
                {
                    LessonAutoActivator.TeachOpportunity(SidearmsDefOf.Concept_SidearmsPrimary, OpportunityType.GoodToKnow);
                }
                GUI.color = iconMouseOverColor;
                GUI.DrawTexture(iconRect, drawPocket);
            }
            else
            {
                GUI.color = iconBaseColor;
                GUI.DrawTexture(iconRect, drawPocket);
            }

            Texture resolvedIcon;

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

            UIHighlighter.HighlightOpportunity(iconRect, "SidearmMissing");
            if (pawnMemory.IsCurrentPrimary(weapon.defName))
            {
                UIHighlighter.HighlightOpportunity(iconRect, "SidearmPrimary");
            }

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #20
0
        public override GizmoResult GizmoOnGUI(Vector2 topLeft)
        {
            var gizmoRect = new Rect(topLeft.x, topLeft.y, Width, MinGizmoSize);

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

            var contentRect = gizmoRect.ContractedBy(ContentPadding);

            Widgets.DrawWindowBackground(gizmoRect);

            var globalInteracted = false;

            interactedWeapon       = null;
            interactedWeaponMemory = null;
            interactedRanged       = false;
            interactedUnarmed      = false;

            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(parent);
            //if (pawnMemory == null)
            //    return new GizmoResult(GizmoState.Clear);

            int i = 0;

            for (i = 0; i < rangedWeapons.Count; i++)
            {
                var  iconOffset = new Vector2((IconSize * i) + IconGap * (i - 1) + LockPanelWidth, 0);
                bool interacted = DrawIconForWeapon(pawnMemory, rangedWeapons[i], contentRect, iconOffset);
                if (interacted)
                {
                    interactedWeapon = rangedWeapons[i];
                }
                if (interacted)
                {
                    interactedRanged = true;
                }
                globalInteracted |= interacted;
            }

            int j = 0;

            if (pawnMemory != null)
            {
                foreach (ThingDef def in rangedWeaponMemories)
                {
                    if (!parent.hasWeaponSomewhere(def))
                    {
                        var  iconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + LockPanelWidth, 0);
                        bool interacted = DrawIconForWeaponMemory(pawnMemory, def, contentRect, iconOffset);
                        if (interacted)
                        {
                            interactedWeaponMemory = def;
                        }
                        if (interacted)
                        {
                            interactedRanged = true;
                        }
                        globalInteracted |= interacted;
                        j++;
                    }
                }
            }

            for (i = 0; i < meleeWeapons.Count; i++)
            {
                var  iconOffset = new Vector2((IconSize * i) + IconGap * (i - 1) + LockPanelWidth, IconSize + IconGap);
                bool interacted = DrawIconForWeapon(pawnMemory, meleeWeapons[i], contentRect, iconOffset);
                if (interacted)
                {
                    interactedWeapon = meleeWeapons[i];
                }
                if (interacted)
                {
                    interactedRanged = false;
                }
                globalInteracted |= interacted;
            }

            j = 0;
            if (pawnMemory != null)
            {
                foreach (ThingDef def in meleeWeaponMemories)
                {
                    if (!parent.hasWeaponSomewhere(def))
                    {
                        var  iconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + LockPanelWidth, IconSize + IconGap);
                        bool interacted = DrawIconForWeaponMemory(pawnMemory, def, contentRect, iconOffset);
                        if (interacted)
                        {
                            interactedWeaponMemory = def;
                        }
                        if (interacted)
                        {
                            interactedRanged = false;
                        }
                        globalInteracted |= interacted;
                        j++;
                    }
                }
            }

            var unarmedIconOffset = new Vector2((IconSize * (i + j)) + IconGap * ((i + j) - 1) + LockPanelWidth, IconSize + IconGap);

            interactedUnarmed = DrawIconForUnarmed(parent, contentRect, unarmedIconOffset);
            globalInteracted |= interactedUnarmed;

            Rect locksPanel = new Rect(gizmoRect.x + ContentPadding, gizmoRect.y, LockPanelWidth - ContentPadding, MinGizmoSize);
            //locksPanel = locksPanel.ContractedBy(LockPanelPadding);

            SwapControlsHandler handler = SwapControlsHandler.GetHandlerForPawn(parent);

            Rect lockPanel     = new Rect(locksPanel.x, locksPanel.y + (locksPanel.height / 2f) - locksPanel.width - LockIconsOffset, locksPanel.width, locksPanel.width);
            Rect locklockPanel = new Rect(locksPanel.x, locksPanel.y + (locksPanel.height / 2f) + LockIconsOffset, locksPanel.width, locksPanel.width);

            DrawLock(handler, lockPanel);
            UIHighlighter.HighlightOpportunity(lockPanel, "SidearmListButton");
            DrawLocklock(handler, locklockPanel);
            UIHighlighter.HighlightOpportunity(locklockPanel, "SidearmListButton");

            UIHighlighter.HighlightOpportunity(gizmoRect, "SidearmList");

            DrawGizmoLabel(defaultLabel, gizmoRect);
            return(globalInteracted ? new GizmoResult(GizmoState.Interacted, Event.current) : new GizmoResult(GizmoState.Clear));
        }
Example #21
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);

            GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(parent);

            int i = 0;
            {
                Dictionary <ThingStuffPair, int> dupeCounters = new Dictionary <ThingStuffPair, int>();
                var rangedWeapons = carriedRangedWeapons.ToList();
                rangedWeapons.SortStable((a, b) => { return((int)((b.MarketValue - a.MarketValue) * 1000)); });
                for (i = 0; i < rangedWeapons.Count(); i++)
                {
                    ThingStuffPair weaponMemory = rangedWeapons[i].toThingStuffPair();
                    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 <ThingStuffPair, int> dupeCounters = new Dictionary <ThingStuffPair, int>();
                var rangedWeaponMemoriesSorted = rangedWeaponMemories.ToList();
                rangedWeaponMemoriesSorted.SortStable((a, b) => { return((int)((b.Price - a.Price) * 1000)); });
                foreach (ThingStuffPair 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 <ThingStuffPair, int> dupeCounters = new Dictionary <ThingStuffPair, int>();
                var meleeWeapons = carriedMeleeWeapons.ToList();
                meleeWeapons.SortStable((a, b) => { return((int)((b.MarketValue - a.MarketValue) * 1000)); });
                for (i = 0; i < meleeWeapons.Count(); i++)
                {
                    ThingStuffPair weaponMemory = meleeWeapons[i].toThingStuffPair();
                    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 <ThingStuffPair, int> dupeCounters = new Dictionary <ThingStuffPair, int>();
                var meleeWeaponMemoriesSorted = meleeWeaponMemories.ToList();
                meleeWeaponMemoriesSorted.SortStable((a, b) => { return((int)((b.Price - a.Price) * 1000)); });
                foreach (ThingStuffPair 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 && !parent.story.DisabledWorkTagsBackstoryAndTraits.OverlapsWithOnAnyWorkType(WorkTags.Violent))
            {
                DrawGizmoLabel(defaultLabel, gizmoRect);
            }
            else
            {
                DrawGizmoLabel(defaultLabel + " (godmode)", gizmoRect);
            }
            return(interactedWith != SidearmsListInteraction.None ? new GizmoResult(GizmoState.Interacted, Event.current) : new GizmoResult(GizmoState.Clear));
        }
Example #22
0
        private void iconClickAction(int buttonID)
        {
            if (interactedWeapon != null)
            {
                Thing toSwapTo;
                if (interactedRanged)
                {
                    if (buttonID == 0)
                    {
                        toSwapTo = interactedWeapon;

                        if (GoldfishModule.GetGoldfishForPawn(parent) != null && toSwapTo.def.defName.Equals(GoldfishModule.GetGoldfishForPawn(parent).primary))
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsPrimary, KnowledgeAmount.Total);
                        }

                        WeaponAssingment.weaponSwapSpecific(parent, toSwapTo, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
                        SwapControlsHandler handler = SwapControlsHandler.GetHandlerForPawn(parent);
                        if (handler.autoLockOnManualSwap)
                        {
                            handler.currentWeaponLocked = true;
                        }

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.dropSidearm(parent, interactedWeapon);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
                else
                {
                    if (buttonID == 0)
                    {
                        toSwapTo = interactedWeapon;

                        if (GoldfishModule.GetGoldfishForPawn(parent) != null && toSwapTo.def.defName.Equals(GoldfishModule.GetGoldfishForPawn(parent).primary))
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsPrimary, KnowledgeAmount.Total);
                        }

                        WeaponAssingment.weaponSwapSpecific(parent, toSwapTo, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.dropSidearm(parent, interactedWeapon);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsInInventory, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
            }
            else if (interactedWeaponMemory != null)
            {
                if (interactedRanged)
                {
                    if (buttonID == 0)
                    {
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.forgetSidearmMemory(parent, interactedWeaponMemory);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsMissing, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
                else
                {
                    if (buttonID == 0)
                    {
                    }
                    else if (buttonID == 1)
                    {
                        WeaponAssingment.forgetSidearmMemory(parent, interactedWeaponMemory);

                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SidearmsMissing, KnowledgeAmount.SpecificInteraction);
                        PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                    }
                }
            }
            else if (interactedUnarmed == true)
            {
                if (buttonID == 0)
                {
                    WeaponAssingment.weaponSwapSpecific(parent, null, true, MiscUtils.shouldDrop(DroppingModeEnum.UserForced), false);
                    PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                }
            }
        }
        public static Job TryGiveJobStatic(Pawn pawn, bool inCombat)
        {
            if (RestraintsUtility.InRestraints(pawn))
            {
                return(null);
            }

            {
                //SetNextTryTick(pawn, Find.TickManager.TicksGame + UnityEngine.Random.Range(PickupCheckIntervalMin, PickupCheckIntervalMax));


                Pawn_EquipmentTracker equipment = pawn.equipment;
                if (equipment == null)
                {
                    return(null);
                }

                GoldfishModule pawnMemory = GoldfishModule.GetGoldfishForPawn(pawn);
                if (pawnMemory == null)
                {
                    return(null);
                }

                WeaponAssingment.reequipPrimaryIfNeededAndAvailable(pawn, pawnMemory);

                foreach (string wepName in pawnMemory.weapons)
                {
                    ThingDef def = DefDatabase <ThingDef> .GetNamedSilentFail(wepName);

                    if (def == null)
                    {
                        continue;
                    }

                    if (!pawn.hasWeaponSomewhere(wepName))
                    {
                        float maxDist = 1000f;
                        if (pawn.Faction != Faction.OfPlayer || inCombat)
                        {
                            maxDist = 30f;
                        }
                        List <Thing> matchingWeapons = pawn.Map.listerThings.ThingsOfDef(def);

                        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) => SimpleSidearms.ReEquipBest ? t.GetStatValue(StatDefOf.MeleeWeapon_AverageDPS, false) : 0);

                        if (thing == null)
                        {
                            continue;
                        }

                        if (!inCombat)
                        {
                            return(new Job(SidearmsDefOf.EquipSecondary, thing));
                        }
                        else
                        {
                            return(new Job(SidearmsDefOf.EquipSecondaryCombat, thing, pawn.Position));
                        }
                    }
                }

                return(null);
            }
        }
Example #24
0
        private static bool DrawIconForWeaponMemory(GoldfishModule pawnMemory, ThingDef weapon, Rect contentRect, Vector2 iconOffset)
        {
            //Log.Message("drawing memory of " + weapon.defName);

            var     iconTex  = weapon.uiIcon;
            Graphic g        = weapon.graphicData.Graphic;
            Color   color    = getColor(weapon);
            Color   colorTwo = getColor(weapon);
            Graphic g2       = weapon.graphicData.Graphic.GetColoredVersion(g.Shader, color, colorTwo);

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

            //if (!contentRect.Contains(iconRect))
            //    return false;

            string label = weapon.label;

            Texture2D drawPocket;

            if (pawnMemory.IsCurrentPrimary(weapon.defName))
            {
                drawPocket = TextureResources.drawPocketMemoryPrimary;
            }
            else
            {
                drawPocket = TextureResources.drawPocketMemory;
            }

            TooltipHandler.TipRegion(iconRect, string.Format("DrawSidearm_gizmoTooltipMemory".Translate(), weapon.label));
            MouseoverSounds.DoRegion(iconRect, SoundDefOf.MouseoverCommand);
            if (Mouse.IsOver(iconRect))
            {
                GUI.color = iconMouseOverColor;
                GUI.DrawTexture(iconRect, drawPocket);
            }
            else
            {
                GUI.color = iconBaseColor;
                GUI.DrawTexture(iconRect, drawPocket);
            }

            Texture resolvedIcon;

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

            //Log.Message("done");

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }