예제 #1
0
        public static float CalculateArmorByPartsCE(Pawn pawn, StatDef stat, ref string text, string unit)
        {
            ValidateArg.NotNull(pawn, nameof(pawn));

            text = string.Empty;
            float          num         = 0f;
            List <Apparel> wornApparel = pawn.apparel?.WornApparel;

            if (wornApparel == null)
            {
                return(num);
            }

            for (int i = 0; i < wornApparel.Count; i++)
            {
                num += wornApparel[i].GetStatValue(stat, true) * wornApparel[i].def.apparel.HumanBodyCoverage;
            }

            if (num > 0.005f)
            {
                List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts;
                for (int i = 0; i < bpList.Count; i++)
                {
                    float          armorValue = 0f;
                    BodyPartRecord part       = bpList[i];
                    if (part.depth == BodyPartDepth.Outside && (part.coverage >= 0.1 || (part.def == BodyPartDefOf.Eye || part.def == BodyPartDefOf.Neck)))
                    {
                        text += part.LabelCap + ": ";
                        for (int j = wornApparel.Count - 1; j >= 0; j--)
                        {
                            Apparel apparel = wornApparel[j];
                            if (apparel.def.apparel.CoversBodyPart(part))
                            {
                                armorValue += apparel.GetStatValue(stat, true);
                            }
                        }
                        text += formatArmorValue(armorValue, unit) + "\n";
                    }
                }
            }

            return(num);
        }
예제 #2
0
        /// <summary>
        /// Make float menu options for creating empty loadout or loadout derived from equipped items.
        /// </summary>
        /// <param name="selPawn"> Selected pawn. </param>
        /// <returns> A list of options. </returns>
        public static List <FloatMenuOption> MakeActionableLoadoutOption(this Pawn selPawn)
        {
            ValidateArg.NotNull(selPawn, nameof(selPawn));

            return(new List <FloatMenuOption>()
            {
                new FloatMenuOption(
                    UIText.MakeEmptyLoadout.Translate(selPawn.NameShortColored)
                    , () =>
                {
                    AwesomeInventoryLoadout emptyLoadout = AwesomeInventoryLoadout.MakeEmptyLoadout(selPawn);
                    LoadoutManager.AddLoadout(emptyLoadout);
                    selPawn.SetLoadout(emptyLoadout);
                    Find.WindowStack.Add(
                        AwesomeInventoryServiceProvider.MakeInstanceOf <Dialog_ManageLoadouts>(emptyLoadout, selPawn, true));

                    if (BetterPawnControlUtility.IsActive)
                    {
                        BetterPawnControlUtility.SaveState(new List <Pawn> {
                            selPawn
                        });
                    }
                }),
                new FloatMenuOption(
                    UIText.MakeNewLoadout.Translate(selPawn.NameShortColored)
                    , () =>
                {
                    AwesomeInventoryLoadout loadout = new AwesomeInventoryLoadout(selPawn);
                    LoadoutManager.AddLoadout(loadout);
                    selPawn.SetLoadout(loadout);
                    Find.WindowStack.Add(
                        AwesomeInventoryServiceProvider.MakeInstanceOf <Dialog_ManageLoadouts>(loadout, selPawn, true));

                    if (BetterPawnControlUtility.IsActive)
                    {
                        BetterPawnControlUtility.SaveState(new List <Pawn> {
                            selPawn
                        });
                    }
                }),
            });
        }
예제 #3
0
        /// <summary>
        /// Check if argument is null or empty.
        /// </summary>
        /// <param name="arg"> Argument to check. </param>
        /// <param name="argName"> Name of <paramref name="arg"/>. </param>
        public static void NotNullOrEmpty(object arg, string argName)
        {
            ValidateArg.NotNull(arg, argName);

            switch (arg)
            {
            case string str:
                if (string.IsNullOrEmpty(str))
                {
                    throw new ArgumentEmtpyException(argName);
                }
                break;

            case IEnumerable items:
                if (items.GetEnumerator().MoveNext())
                {
                    throw new ArgumentEmtpyException(argName);
                }
                break;
            }
        }
        /*
         * public static IEnumerable<FloatMenuOption> EquipAndAddToLoadout(Pawn pawn, Thing thing)
         * {
         *  if (pawn.UseLoadout(out CompAwesomeInventoryLoadout comp))
         *  {
         *      if (comp.Loadout != null)
         *      {
         *      }
         *  }
         * }
         */

        /*
         * private static IEnumerable<FloatMenuOption> OptionForSpawnThing(Pawn pawn, Thing thing, CompAwesomeInventoryLoadout comp)
         * {
         *  List<FloatMenuOption> options = new List<FloatMenuOption>();
         *  if (thing.def.IsWeapon)
         *  {
         *      var option = FloatMenuUtility.DecoratePrioritizedTask(
         *          new FloatMenuOption(
         *              "Equip, keep the replaced and add to loadout"
         *              , () =>
         *              {
         *                  EquipWeaponDialog(pawn, thing);
         *              }
         *              , MenuOptionPriority.High)
         *          , pawn
         *          , thing);
         *      options.Add(option);
         *  }
         *  else if (thing.def.IsApparel)
         *  {
         *      var option = FloatMenuUtility.DecoratePrioritizedTask(
         *          new FloatMenuOption(
         *              "Wear, keep the replaced and add to loadout"
         *              , () =>
         *              {
         *                  WearApparel(pawn, thing, false);
         *                  AddToLoadoutDialog(pawn, comp, thing, false);
         *              }
         *              , MenuOptionPriority.High)
         *          , pawn
         *          , thing);
         *      options.Add(option);
         *  }
         *  else
         *  {
         *      var option = FloatMenuUtility.DecoratePrioritizedTask(
         *          new FloatMenuOption(
         *              "Pick up and add to loadout"
         *              , () =>
         *              {
         *                  AddToLoadoutDialog(pawn, comp, thing, true);
         *              }
         *              , MenuOptionPriority.High)
         *          , pawn
         *          , thing);
         *      options.Add(option);
         *  }
         * }
         */

        /// <summary>
        /// Create loadout options(add to loadout or remove from loadout) for <paramref name="thing"/> that <paramref name="pawn"/> carries.
        /// </summary>
        /// <param name="pawn"> Pawn who carries <paramref name="thing"/>. </param>
        /// <param name="thing"> Thing that is carried by <paramref name="pawn"/>. </param>
        /// <param name="comp"> Comp on <paramref name="pawn"/>. </param>
        /// <returns> Returns different options based on the condition that whether <paramref name="thing"/> is in <paramref name="pawn"/>'s loadout. </returns>
        public static FloatMenuOption OptionForThingOnPawn(Pawn pawn, Thing thing, CompAwesomeInventoryLoadout comp)
        {
            ValidateArg.NotNull(comp, nameof(comp));

            CompAwesomeInventoryLoadout.ThingGroupSelectorPool pool = comp.FindPotentialThingGroupSelectors(thing, comp.Loadout);
            if (pool.OrderedSelectorTuples.Any())
            {
                return(MakeDecoratedOption(
                           UIText.RemoveFromLoadout.Translate(comp.Loadout.label)
                           , () => comp.Loadout.Remove(pool.OrderedSelectorTuples.First().Item2)
                           , pawn
                           , thing));
            }
            else
            {
                return(MakeDecoratedOption(
                           UIText.AddToLoadout.Translate(comp.Loadout.label)
                           , () => AddToLoadoutDialog(pawn, comp, thing)
                           , pawn
                           , thing));
            }
        }
        /// <summary>
        /// Stop jobs that are either of <see cref="AwesomeInventory_JobDefOf.AwesomeInventory_Dress"/> or <see cref="AwesomeInventory_JobDefOf.AwesomeInventory_Undress"/>.
        /// </summary>
        /// <param name="pawn"> Pawn who has jobs. </param>
        public static void StopDressingJobs(Pawn pawn)
        {
            ValidateArg.NotNull(pawn, nameof(pawn));

            if (IsDressingJob(pawn.CurJobDef))
            {
                pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, false);
            }

            List <QueuedJob> queuedJobs = new List <QueuedJob>(pawn.jobs?.jobQueue ?? Enumerable.Empty <QueuedJob>());

            foreach (QueuedJob queuedJob in queuedJobs)
            {
                if (IsDressingJob(queuedJob.job.def))
                {
                    pawn.jobs.EndCurrentOrQueuedJob(queuedJob.job, JobCondition.InterruptForced);
                }
            }

            bool IsDressingJob(JobDef jobDef)
            {
                return(jobDef == AwesomeInventory_JobDefOf.AwesomeInventory_Undress || jobDef == AwesomeInventory_JobDefOf.AwesomeInventory_Dress);
            }
        }
        public static void AddPlugIn(Plugin plugin)
        {
            ValidateArg.NotNull(plugin, nameof(plugin));

            _pluginService[plugin.ID] = plugin;
        }
예제 #7
0
        /// <summary>
        /// Check if <paramref name="pawn"/> is a colonist.
        /// </summary>
        /// <param name="pawn"> Pawn to check. </param>
        /// <returns> Returns true if <paramref name="pawn"/> is a colonist. </returns>
        /// <remarks> It controls if the RPG-Style gear tab is visible to players. </remarks>
        public virtual bool IsColonist(Pawn pawn)
        {
            ValidateArg.NotNull(pawn, nameof(pawn));

            return(pawn.Faction != null && pawn.Faction.IsPlayer);
        }
예제 #8
0
        /****************************************************************************
         *  List order used by AwesomeInventory to display items.
         *
         *  UpperHead = 200, FullHead = 199, Eyes = 198, Teeth = 197, Mouth = 196,
         *  Neck = 180,
         *  Torso = 100, Arms = 90, LeftArm = 89, RightArm = 88,
         *  Shoulders = 85, LeftShoulder = 84, RightShoulder = 83,
         *  Hands = 80, LeftHand = 79, RightHand = 78,
         *  Waist = 50,
         *  Legs = 10,
         *  Feet = 9
         *
         *****************************************************************************/

        /// <summary>
        /// Check if inventory should be shown for <paramref name="p"/>.
        /// </summary>
        /// <param name="p"> Pawn to check. </param>
        /// <returns> Returns true if inventory should be displayed. </returns>
        public static bool ShouldShowInventory(Pawn p)
        {
            ValidateArg.NotNull(p, nameof(p));

            return(p.RaceProps.Humanlike || p.inventory.innerContainer.Any);
        }