Example #1
0
        public static bool canCarrySidearmInstance(ThingWithComps sidearmThing, Pawn pawn, out string errString)
        {
            //nicked from EquipmentUtility.CanEquip
            CompBladelinkWeapon compBladelinkWeapon = sidearmThing.TryGetComp <CompBladelinkWeapon>();

            if (compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn != null && compBladelinkWeapon.bondedPawn != pawn)
            {
                errString = "BladelinkBondedToSomeoneElse".Translate();
                return(false);
            }
            if (EquipmentUtility.IsBiocoded(sidearmThing) && pawn != sidearmThing.TryGetComp <CompBiocodableWeapon>().CodedPawn)
            {
                errString = "BiocodedCodedForSomeoneElse".Translate();
                return(false);
            }
            if (compBladelinkWeapon != null && compBladelinkWeapon.bondedPawn == null)
            {
                errString = "SidearmPickupFail_NotYetBladelinkBonded".Translate();
                return(false);
            }

            ThingDefStuffDefPair sidearm = sidearmThing.toThingDefStuffDefPair();

            return(canCarrySidearmType(sidearm, pawn, out errString));
        }
        public static bool canCarrySidearmInstance(ThingWithComps sidearmThing, Pawn pawn, out string errString)
        {
            //nicked from EquipmentUtility.CanEquip
            CompBladelinkWeapon compBladelinkWeapon = sidearmThing.TryGetComp <CompBladelinkWeapon>();

            if (compBladelinkWeapon != null && compBladelinkWeapon.Biocodable && compBladelinkWeapon.CodedPawn != null && compBladelinkWeapon.CodedPawn != pawn)
            {
                errString = "BladelinkBondedToSomeoneElse".Translate();
                return(false);
            }
            if (CompBiocodable.IsBiocoded(sidearmThing) && !CompBiocodable.IsBiocodedFor(sidearmThing, pawn))
            {
                errString = "BiocodedCodedForSomeoneElse".Translate();
                return(false);
            }
            if (EquipmentUtility.AlreadyBondedToWeapon(sidearmThing, pawn))
            {
                errString = "BladelinkAlreadyBondedMessage".Translate(pawn.Named("PAWN"), pawn.equipment.bondedWeapon.Named("BONDEDWEAPON"));
                return(false);
            }
            if (compBladelinkWeapon != null && !compBladelinkWeapon.Biocoded && !compBladelinkWeapon.TraitsListForReading.Any(t => t.neverBond == true))
            {
                errString = "SidearmPickupFail_NotYetBladelinkBonded".Translate();
                return(false);
            }
            if (EquipmentUtility.RolePreventsFromUsing(pawn, sidearmThing, out string roleReason))
            {
                errString = roleReason;
                return(false);
            }

            ThingDefStuffDefPair sidearm = sidearmThing.toThingDefStuffDefPair();

            return(canCarrySidearmType(sidearm, pawn, out errString));
        }
Example #3
0
        public static void TryDropEquipment_Postfix(Pawn_EquipmentTracker __instance, bool __result, ThingWithComps resultingEq)
        {
            if (__result == true && resultingEq != null)
            {
                Pawn pawn = __instance.pawn;
                if (!pawn.IsValidSidearmsCarrier())
                {
                    return;
                }

                if (!(Pawn_HealthTracker_MakeDowned.beingDowned || dropEquipmentSourcedBySimpleSidearms))
                {
                    CompSidearmMemory pawnMemory = CompSidearmMemory.GetMemoryCompForPawn(pawn);
                    if (pawnMemory != null)
                    {
                        pawnMemory.ForgetSidearmMemory(resultingEq.toThingDefStuffDefPair());
                    }
                }
            }
        }
Example #4
0
        public void DrawIconForWeapon(Pawn pawn, CompSidearmMemory pawnMemory, ThingWithComps weapon, bool isDuplicate, Rect contentRect, Vector2 iconOffset)
        {
            if (weapon is null || weapon.def is null || weapon.def.uiIcon is null)
            {
                return;
            }

            ThingDefStuffDefPair weaponType = weapon.toThingDefStuffDefPair();

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

            string hoverText;

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

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

            Texture2D drawPocket;

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

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

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

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

            Graphic outerGraphic = weaponType.thing.graphic;

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

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

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

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

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


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

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

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

                GUI.color = Color.white;
            }

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

            if (Widgets.ButtonInvisible(iconRect, true))
            {
                interactedWith               = SidearmsListInteraction.Weapon;
                interactionWeapon            = weapon;
                interactionWeaponIsDuplicate = isDuplicate;
            }
        }
Example #5
0
        public static void AddHumanlikeOrders(Vector3 clickPos, Pawn pawn, List <FloatMenuOption> opts)
        {
            try
            {
                if (SimpleSidearms.CEOverride)
                {
                    return;
                }

                IntVec3 c = IntVec3.FromVector3(clickPos);
                if (pawn.equipment != null)
                {
                    ThingWithComps equipment = null;
                    List <Thing>   thingList = c.GetThingList(pawn.Map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        if (thingList[i].TryGetComp <CompEquippable>() != null)
                        {
                            equipment = (ThingWithComps)thingList[i];
                            break;
                        }
                    }
                    if (equipment != null)
                    {
                        string          labelShort = equipment.LabelShort;
                        string          errStr;
                        FloatMenuOption item3;

                        /*if ((!equipment.toThingStuffPair().isToolNotWeapon()) && ((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0))
                         * {
                         * }*/
                        if (!pawn.CanReach(equipment, PathEndMode.ClosestTouch, Danger.Deadly, false, TraverseMode.ByPawn))
                        {
                        }
                        else if (!pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
                        {
                        }
                        else if (!equipment.def.IsWeapon)
                        {
                        }
                        else if (equipment.IsBurning())
                        {
                        }
                        else if (pawn.IsQuestLodger())
                        {
                        }
                        else if (!StatCalculator.canCarrySidearmInstance(equipment, pawn, out errStr))
                        {
                            "CannotEquip".Translate();
                            item3 = new FloatMenuOption("CannotEquip".Translate(labelShort) + " (" + errStr + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null);
                            opts.Add(item3);
                        }
                        else
                        {
                            string text2 = "Equip".Translate(labelShort);
                            if (((pawn.CombinedDisabledWorkTags & WorkTags.Violent) != 0) || equipment.toThingDefStuffDefPair().isToolNotWeapon())
                            {
                                text2 += "AsTool".Translate();
                            }
                            else
                            {
                                text2 += "AsSidearm".Translate();
                            }


                            if (equipment.def.IsRangedWeapon && pawn.story != null && pawn.story.traits.HasTrait(TraitDefOf.Brawler))
                            {
                                text2 = text2 + " " + "EquipWarningBrawler".Translate();
                            }

                            item3 = FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(text2, delegate
                            {
                                equipment.SetForbidden(false, true);
                                pawn.jobs.TryTakeOrderedJob(JobMaker.MakeJob(SidearmsDefOf.EquipSecondary, equipment), JobTag.Misc);
                                MoteMaker.MakeStaticMote(equipment.DrawPos, equipment.Map, ThingDefOf.Mote_FeedbackEquip, 1f);

                                PlayerKnowledgeDatabase.KnowledgeDemonstrated(SidearmsDefOf.Concept_SimpleSidearmsBasic, KnowledgeAmount.SmallInteraction);
                            }, MenuOptionPriority.High, null, null, 0f, null, null), pawn, equipment, "ReservedBy");
                            opts.Add(item3);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception during SimpleSidearms floatmenumaker intercept. Cancelling intercept. Exception: " + e.ToString());
            }
        }