Exemplo n.º 1
0
        private void GenerateStartingWeaponPresets()
        {
            WeaponPreset _weaponPreset1 = this.MakeNewWeaponPreset();

            _weaponPreset1.label = "WOC.WeaponPresetNone".Translate();
            _weaponPreset1.filter.SetDisallowAll(null, null);
        }
 public Dialog_ManageWeapons(WeaponPreset selectedWeaponPreset)
 {
     this.forcePause              = true;
     this.doCloseX                = true;
     this.doCloseButton           = true;
     this.closeOnClickedOutside   = true;
     this.absorbInputAroundWindow = true;
     if (Dialog_ManageWeapons.WeaponPresetGlobalFilter == null)
     {
         Dialog_ManageWeapons.WeaponPresetGlobalFilter = new ThingFilter();
         Dialog_ManageWeapons.WeaponPresetGlobalFilter.SetAllow(ThingCategoryDefOf.Weapons, true, null, null);
     }
     this.SelectedWeaponPreset = selectedWeaponPreset;
 }
Exemplo n.º 3
0
        public WeaponPreset MakeNewWeaponPreset()
        {
            int num;

            if (this.WeaponPresets.Any <WeaponPreset>())
            {
                num = this.WeaponPresets.Max((WeaponPreset o) => o.uniqueId) + 1;
            }
            else
            {
                num = 1;
            }
            int          uniqueId      = num;
            WeaponPreset _weaponPreset = new WeaponPreset(uniqueId, "WOC.NewWeaponPreset".Translate() + " " + uniqueId.ToString());

            _weaponPreset.filter.SetAllow(ThingCategoryDefOf.Weapons, false);
            this.WeaponPresets.Add(_weaponPreset);
            return(_weaponPreset);
        }
Exemplo n.º 4
0
 public AcceptanceReport TryDelete(WeaponPreset weaponPreset)
 {
     foreach (Pawn pawn in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive)
     {
         if (pawn.TryGetComp <Pawn_WeaponPresetTracker>()?.CurrentWeaponPreset == weaponPreset)
         {
             return(new AcceptanceReport("WOC.WeaponPresetInUse".Translate(pawn)));
         }
     }
     foreach (Pawn pawn2 in PawnsFinder.AllMapsWorldAndTemporary_AliveOrDead)
     {
         if (pawn2.TryGetComp <Pawn_WeaponPresetTracker>() is Pawn_WeaponPresetTracker Tracker && Tracker.CurrentWeaponPreset == weaponPreset)
         {
             Tracker.CurrentWeaponPreset = null;
         }
     }
     this.WeaponPresets.Remove(weaponPreset);
     return(AcceptanceReport.WasAccepted);
 }
        private IEnumerable <Widgets.DropdownMenuElement <WeaponPreset> > Button_GenerateMenu(Pawn pawn)
        {
            Pawn_WeaponPresetTracker pawn_WeaponPresetTracker = pawn.TryGetComp <Pawn_WeaponPresetTracker>();

            using (List <WeaponPreset> .Enumerator enumerator = Current.Game.GetComponent <WeaponPresetDatabase>().AllWeaponPresets.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    WeaponPreset weaponPreset = enumerator.Current;
                    yield return(new Widgets.DropdownMenuElement <WeaponPreset>
                    {
                        option = new FloatMenuOption(weaponPreset.label, delegate()
                        {
                            pawn_WeaponPresetTracker.CurrentWeaponPreset = weaponPreset;
                        }, MenuOptionPriority.Default, null, null, 0f, null, null),
                        payload = weaponPreset
                    });
                }
            }
            yield break;
        }
        public override void DoWindowContents(Rect inRect)
        {
            float num  = 0f;
            Rect  rect = new Rect(0f, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect, "WOC.SelectWeaponPreset".Translate(), true, false, true))
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                foreach (WeaponPreset localOut3 in Current.Game.GetComponent <WeaponPresetDatabase>().AllWeaponPresets)
                {
                    WeaponPreset localOut = localOut3;
                    list.Add(new FloatMenuOption(localOut.label, delegate()
                    {
                        this.SelectedWeaponPreset = localOut;
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list));
            }
            num += 10f;
            Rect rect2 = new Rect(num, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect2, "WOC.NewWeaponPreset".Translate(), true, false, true))
            {
                this.SelectedWeaponPreset = Current.Game.GetComponent <WeaponPresetDatabase>().MakeNewWeaponPreset();
            }
            num += 10f;
            Rect rect3 = new Rect(num, 0f, 150f, 35f);

            num += 150f;
            if (Widgets.ButtonText(rect3, "WOC.DeleteWeaponPreset".Translate(), true, false, true))
            {
                List <FloatMenuOption> list2 = new List <FloatMenuOption>();
                foreach (WeaponPreset localOut2 in Current.Game.GetComponent <WeaponPresetDatabase>().AllWeaponPresets)
                {
                    WeaponPreset localOut = localOut2;
                    list2.Add(new FloatMenuOption(localOut.label, delegate()
                    {
                        AcceptanceReport acceptanceReport = Current.Game.GetComponent <WeaponPresetDatabase>().TryDelete(localOut);
                        if (!acceptanceReport.Accepted)
                        {
                            Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.RejectInput, false);
                        }
                        else if (localOut == this.SelectedWeaponPreset)
                        {
                            this.SelectedWeaponPreset = null;
                        }
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
                Find.WindowStack.Add(new FloatMenu(list2));
            }
            Rect rect4 = new Rect(0f, 40f, inRect.width, inRect.height - 40f - this.CloseButSize.y).ContractedBy(10f);

            if (this.SelectedWeaponPreset == null)
            {
                GUI.color   = Color.grey;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(rect4, "WOC.NoWeaponPresetSelected".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
                GUI.color   = Color.white;
                return;
            }
            GUI.BeginGroup(rect4);
            Rect rect5 = new Rect(0f, 0f, 200f, 30f);

            Dialog_ManageWeapons.DoNameInputRect(rect5, ref this.SelectedWeaponPreset.label);
            Rect        rect6        = new Rect(0f, 40f, 300f, rect4.height - 45f - 10f);
            Rect        rect7        = rect6;
            ref Vector2 ptr          = ref this.scrollPosition;
        protected override Job TryGiveJob(Pawn pawn)
        {
            Pawn_WeaponPresetTracker pawn_WeaponPresetTracker = pawn.TryGetComp <Pawn_WeaponPresetTracker>();

            if (pawn_WeaponPresetTracker == null)
            {
                return(null);
            }
            if (pawn.Faction != Faction.OfPlayer)
            {
                return(null);
            }
            if (!DebugViewSettings.debugApparelOptimize)
            {
                if (Find.TickManager.TicksGame < pawn_WeaponPresetTracker.nextWeaponPresetOptimizeTick)
                {
                    return(null);
                }
            }

            WeaponPreset   CurweaponPreset  = pawn_WeaponPresetTracker.CurrentWeaponPreset;
            ThingFilter    _equipmentFilter = CurweaponPreset.filter;
            ThingWithComps thingWithComps   = pawn.equipment?.Primary;

            bool HasWeaponEquipped = true;  //true = Has got  a weapon equipped
            bool HasNonePreset     = false; //false = Not using "NONE" PRESET
            bool WeaponNotAllowed  = false; //false = The weapon is not allowed by the preset

            if (thingWithComps is null)
            {
                HasWeaponEquipped = false;
            }
            if (CurweaponPreset.filter.AllowedDefCount == 0)
            {
                HasNonePreset = true;
            }
            if (thingWithComps != null && !_equipmentFilter.Allows(thingWithComps.def))
            {
                WeaponNotAllowed = true;
            }

            Log.Message(pawn + " HasWeaponEquipped = " + HasWeaponEquipped.ToString(), true);
            Log.Message(pawn + " HasNonePreset = " + HasNonePreset.ToString(), true);
            Log.Message(pawn + " WeaponNotAllowed = " + WeaponNotAllowed.ToString(), true);


            Log.Message(pawn + " Has this equipped " + thingWithComps, true);



            if ((!HasWeaponEquipped && !HasNonePreset) || (!HasNonePreset && WeaponNotAllowed))

            {
                Log.Warning(pawn + " Will Optimize weapons", true);
                Thing        newWeapon = null;
                List <Thing> list      = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.Weapon);

                if (list.Count == 0)
                {
                    this.SetNextOptimizeTick(pawn);
                    return(null);
                }

                // Top 3 Guns chosen by the pawn first
                bool found = false;
                for (int j = 0; j < 3; j++) //it's 3 right now
                {
                    if (!(CurweaponPreset.SearchPriorityDefnames[j].NullOrEmpty()))
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            Thing searchedWeapon = list[i];

                            if (CurweaponPreset.SearchPriorityDefnames[j] == searchedWeapon.def.defName && searchedWeapon.IsInAnyStorage() && !searchedWeapon.IsForbidden(pawn) && !searchedWeapon.IsBurning() && pawn.CanReserveAndReach(searchedWeapon, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1, -1, null, false))
                            {
                                newWeapon = searchedWeapon;
                                found     = true;
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        break;
                    }
                }
                Log.Warning(pawn + " found weapon = " + found.ToString(), true);
                //else just keep browsing the other filter stuff
                if (!found)
                {
                    Log.Message(pawn + " Looking in the rest of the non priorityized weapons ", true);

                    for (int j = 0; j < list.Count; j++)
                    {
                        Thing searchedWeapon = list[j];

                        if (_equipmentFilter.Allows(searchedWeapon.def) && searchedWeapon.IsInAnyStorage() && !searchedWeapon.IsForbidden(pawn) && !searchedWeapon.IsBurning() && pawn.CanReserveAndReach(searchedWeapon, PathEndMode.OnCell, pawn.NormalMaxDanger(), 1, -1, null, false))
                        {
                            newWeapon = searchedWeapon;
                            found     = true;
                            break;
                        }
                    }
                }

                if (newWeapon == null)
                {
                    this.SetNextOptimizeTick(pawn);
                    return(null);
                }


                return(new Job(JobDefOf.Equip, newWeapon));
            }


            else
            {
                Log.Warning("Not doing anything, no need to optimize", true);
                this.SetNextOptimizeTick(pawn);
                return(null);
            }
        }