Exemple #1
0
 public static void DoApparelScoreRawStatsHandlers(Pawn pawn, Apparel apparel, StatDef statDef, ref float num)
 {
     if (PawnCalcForApparel.ApparelScoreRawStatsHandlers != null)
     {
         PawnCalcForApparel.ApparelScoreRawStatsHandlers(pawn, apparel, statDef, ref num);
     }
 }
Exemple #2
0
        public static void DoOptimizeApparel(List <PawnCalcForApparel> newCalcList, List <Apparel> allApparels)
        {
#if LOG && ALLAPPARELS
            MapComponent_AutoEquip.logMessage.AppendLine("All Apparels");
            foreach (Apparel a in allApparels)
            {
                MapComponent_AutoEquip.logMessage.AppendLine("   " + a.LabelCap);
            }
            MapComponent_AutoEquip.logMessage.AppendLine();
#endif

            foreach (PawnCalcForApparel pawnCalc in newCalcList)
            {
                pawnCalc.InitializeAllApparelScores(allApparels);
                pawnCalc.InitializeCalculedApparelScoresFromFixedApparel();
            }

            while (true)
            {
                bool changed = false;
                foreach (PawnCalcForApparel pawnCalc in newCalcList)
                {
                    pawnCalc.OptimeFromList(ref changed);

#if LOG && PARTIAL_OPTIMIZE
                    MapComponent_AutoEquip.logMessage.AppendLine("Optimization For Pawn: " + pawnCalc.LabelCap);
                    foreach (Apparel ap in pawnCalc.CalculedApparel)
                    {
                        MapComponent_AutoEquip.logMessage.AppendLine("    * Apparel: " + ap.LabelCap);
                    }
                    MapComponent_AutoEquip.logMessage.AppendLine();
#endif
                }

                if (!PawnCalcForApparel.CheckForConflicts(newCalcList))
                {
                    break;
                }
            }

            foreach (PawnCalcForApparel pawnCalc in newCalcList)
            {
                pawnCalc.PassToSaveable();
            }

#if LOG
            Type         T = typeof(GUIUtility);
            PropertyInfo systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic);
            systemCopyBufferProperty.SetValue(null, MapComponent_AutoEquip.logMessage.ToString(), null);

            Log.Message(MapComponent_AutoEquip.logMessage.ToString());
            MapComponent_AutoEquip.logMessage = null;
#endif
        }
Exemple #3
0
        private static bool CheckForConflicts(IEnumerable <PawnCalcForApparel> pawns)
        {
            bool any = false;

            foreach (PawnCalcForApparel pawnCalc in pawns)
            {
                foreach (Apparel apprel in pawnCalc.CalculedApparel)
                {
                    float?apparalGainPercentual = null;

                    foreach (PawnCalcForApparel otherPawnCalc in pawns)
                    {
                        if (otherPawnCalc == pawnCalc)
                        {
                            continue;
                        }

                        foreach (Apparel otherApprel in otherPawnCalc.CalculedApparel)
                        {
                            if (otherApprel == apprel)
                            {
                                any = true;
                                PawnCalcForApparel.DoConflict(apprel, pawnCalc, otherPawnCalc, ref apparalGainPercentual);
                                break;
                            }
                        }

                        if ((!pawnCalc.optimized) ||
                            (!otherPawnCalc.optimized))
                        {
                            break;
                        }
                    }

                    if (!pawnCalc.optimized)
                    {
                        break;
                    }
                }
            }

#if LOG && CONFLICT
            MapComponent_AutoEquip.logMessage.AppendLine();
#endif

            return(any);
        }
Exemple #4
0
        public float GetStatValue(Apparel apparel, Saveable_StatDef stat)
        {
            float baseStat    = apparel.GetStatValue(stat.statDef, true);
            float currentStat = baseStat;

            currentStat += apparel.def.equippedStatOffsets.GetStatOffsetFromList(stat.statDef);

            PawnCalcForApparel.DoApparelScoreRawStatsHandlers(pawn, apparel, stat.statDef, ref currentStat);

            if (baseStat == 0)
            {
                return(currentStat);
            }
            else
            {
                return(currentStat / baseStat);
            }
        }
Exemple #5
0
        private static void DoConflict(Apparel apprel, PawnCalcForApparel x, PawnCalcForApparel y, ref float?xPercentual)
        {
            if (!xPercentual.HasValue)
            {
                if (x.totalStats == null)
                {
                    x.totalStats = x.CalculateTotalStats(null);
                }
                float xNoStats = x.CalculateTotalStats(apprel);
                xPercentual = x.totalStats / xNoStats;
                if (x.saveablePawn.pawn.apparel.WornApparel.Contains(apprel))
                {
                    xPercentual *= 1.1f;
                }
            }

            if (y.totalStats == null)
            {
                y.totalStats = y.CalculateTotalStats(null);
            }

            float yNoStats    = y.CalculateTotalStats(apprel);
            float yPercentual = y.totalStats.Value / yNoStats;

            if (y.saveablePawn.pawn.apparel.WornApparel.Contains(apprel))
            {
                yPercentual *= 1.1f;
            }

            if (xPercentual.Value > yPercentual)
            {
#if LOG && CONFLICT
                MapComponent_AutoEquip.logMessage.AppendLine("Conflict: " + apprel.LabelCap + "   Winner: " + x.pawn.LabelCap + " Looser: " + y.pawn.LabelCap);
#endif
                y.LooseConflict(apprel);
            }
            else
            {
#if LOG && CONFLICT
                MapComponent_AutoEquip.logMessage.AppendLine("Conflict: " + apprel.LabelCap + "   Winner: " + y.pawn.LabelCap + " Looser: " + x.pawn.LabelCap);
#endif
                x.LooseConflict(apprel);
            }
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            if (Find.TickManager.TicksGame < this.nextOptimization)
            {
                return;
            }

#if LOG
            MapComponent_AutoEquip.logMessage = new StringBuilder();
            MapComponent_AutoEquip.logMessage.AppendLine("Start Scaning Best Apparel");
            MapComponent_AutoEquip.logMessage.AppendLine();
#endif
            List <Saveable_Pawn>      newSaveableList = new List <Saveable_Pawn>();
            List <PawnCalcForApparel> newCalcList     = new List <PawnCalcForApparel>();

            List <Apparel> allApparels = new List <Apparel>(Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType <Apparel>());
            foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
            {
                this.InjectTab(pawn.def);
                Saveable_Pawn      newPawnSaveable = this.GetCache(pawn);
                PawnCalcForApparel newPawnCalc     = new PawnCalcForApparel(newPawnSaveable);

                newSaveableList.Add(newPawnSaveable);
                newCalcList.Add(newPawnCalc);

                newPawnCalc.InitializeFixedApparelsAndGetAvaliableApparels(allApparels);
            }

            this.pawnCache = newSaveableList;
            PawnCalcForApparel.DoOptimizeApparel(newCalcList, allApparels);

#if LOG
            this.nextOptimization = Find.TickManager.TicksGame + 500;
#else
            this.nextOptimization = Find.TickManager.TicksGame + 5000;
#endif
        }
Exemple #7
0
        private float CalculateTotalStats(Apparel ignore)
        {
            float num = 1.0f;

            foreach (Saveable_StatDef stat in this.stats)
            {
                float nint = stat.statDef.defaultBaseValue;

                foreach (Apparel a in this.calculedApparelItems)
                {
                    if (a == ignore)
                    {
                        continue;
                    }
                    nint += a.def.equippedStatOffsets.GetStatOffsetFromList(stat.statDef);
                }

                foreach (Apparel a in this.calculedApparelItems)
                {
                    if (a == ignore)
                    {
                        continue;
                    }

                    PawnCalcForApparel.DoApparelScoreRawStatsHandlers(this.pawn, a, stat.statDef, ref nint);
                }

                num += nint * stat.strength;
            }

            if (num == 0)
            {
                Log.Warning("No Stat to optimize apparel");
            }

            return(num);
        }
        public override void DoWindowContents(Rect windowRect)
        {
            PawnCalcForApparel conf = new PawnCalcForApparel(this.pawn);

            Rect groupRect = windowRect.ContractedBy(10f);

            groupRect.height -= 100;
            GUI.BeginGroup(groupRect);

            float baseValue       = 100f;
            float multiplierWidth = 100f;
            float finalValue      = 120f;
            float labelWidth      = groupRect.width - baseValue - multiplierWidth - finalValue - 8f - 8f;

            Rect itemRect = new Rect(groupRect.xMin + 4f, groupRect.yMin, groupRect.width - 8f, Text.LineHeight * 1.2f);

            this.DrawLine(ref itemRect,
                          "Status", labelWidth,
                          "Base", baseValue,
                          "Strengh", multiplierWidth,
                          "Final", finalValue);

            groupRect.yMin += itemRect.height;
            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMin, groupRect.width);
            groupRect.yMin   += 4f;
            groupRect.height -= 4f;
            groupRect.height -= Text.LineHeight * 1.2f * 3f + 5f;

            Saveable_StatDef[] stats = conf.Stats.ToArray();
            Rect viewRect            = new Rect(groupRect.xMin, groupRect.yMin, groupRect.width - 16f, stats.Length * Text.LineHeight * 1.2f + 16f);

            if (viewRect.height < groupRect.height)
            {
                groupRect.height = viewRect.height;
            }

            Rect listRect = viewRect.ContractedBy(4f);

            Widgets.BeginScrollView(groupRect, ref scrollPosition, viewRect);

            float sumValue = 0;

            foreach (Saveable_StatDef stat in stats)
            {
                itemRect = new Rect(listRect.xMin, listRect.yMin, listRect.width, Text.LineHeight * 1.2f);
                if (Mouse.IsOver(itemRect))
                {
                    GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                    GUI.DrawTexture(itemRect, TexUI.HighlightTex);
                    GUI.color = Color.white;
                }

                float value = conf.GetStatValue(apparel, stat);
                sumValue += value;

                this.DrawLine(ref itemRect,
                              stat.statDef.label, labelWidth,
                              value.ToString("N3"), baseValue,
                              stat.strength.ToString("N2"), multiplierWidth,
                              (value * stat.strength).ToString("N5"), finalValue);

                listRect.yMin = itemRect.yMax;
            }

            Widgets.EndScrollView();

            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMax, groupRect.width);

            itemRect = new Rect(listRect.xMin, groupRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                          "AverageStat".Translate(), labelWidth,
                          (sumValue / stats.Length).ToString("N3"), baseValue,
                          "", multiplierWidth,
                          conf.CalculateApparelScoreRawStats(apparel).ToString("N5"), finalValue);

            itemRect.yMax += 5;

            itemRect = new Rect(listRect.xMin, itemRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                          "AutoEquipHitPoints".Translate(), labelWidth,
                          conf.CalculateApparelScoreRawHitPointAjust(apparel).ToString("N3"), baseValue,
                          "", multiplierWidth,
                          "", finalValue);

            itemRect = new Rect(listRect.xMin, itemRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                          "AutoEquipTemperature".Translate(), labelWidth,
                          conf.CalculateApparelScoreRawInsulationColdAjust(apparel).ToString("N3"), baseValue,
                          "", multiplierWidth,
                          "", finalValue);

            itemRect = new Rect(listRect.xMin, itemRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                          "AutoEquipTotal".Translate(), labelWidth,
                          conf.CalculateApparelModifierRaw(apparel).ToString("N3"), baseValue,
                          "", multiplierWidth,
                          conf.CalculateApparelScoreRaw(apparel).ToString("N5"), finalValue);

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
        }
        private static void DoConflict(Apparel apprel, PawnCalcForApparel x, PawnCalcForApparel y, ref float? xPercentual)
        {
            if (!xPercentual.HasValue)
            {
                if (x.totalStats == null)
                    x.totalStats = x.CalculateTotalStats(null);
                float xNoStats = x.CalculateTotalStats(apprel);
                xPercentual = x.totalStats / xNoStats;
                if (x.saveablePawn.pawn.apparel.WornApparel.Contains(apprel))
                    xPercentual *= 1.1f;
            }

            if (y.totalStats == null)
                y.totalStats = y.CalculateTotalStats(null);

            float yNoStats = y.CalculateTotalStats(apprel);
            float yPercentual = y.totalStats.Value / yNoStats;

            if (y.saveablePawn.pawn.apparel.WornApparel.Contains(apprel))
                yPercentual *= 1.1f;

            if (xPercentual.Value > yPercentual)
            {
            #if LOG && CONFLICT
                MapComponent_AutoEquip.logMessage.AppendLine("Conflict: " + apprel.LabelCap + "   Winner: " + x.pawn.LabelCap + " Looser: " + y.pawn.LabelCap);
            #endif
                y.LooseConflict(apprel);
            }
            else
            {
            #if LOG && CONFLICT
                MapComponent_AutoEquip.logMessage.AppendLine("Conflict: " + apprel.LabelCap + "   Winner: " + y.pawn.LabelCap + " Looser: " + x.pawn.LabelCap);
            #endif
                x.LooseConflict(apprel);
            }
        }
Exemple #10
0
        public override void DoWindowContents(Rect windowRect)
        {
            MapComponent_AutoEquip mapComponent  = MapComponent_AutoEquip.Get;
            PawnCalcForApparel     pawnAutoEquip = new PawnCalcForApparel(mapComponent.GetCache(this.pawn));
            List <Apparel>         allApparels   = new List <Apparel>(Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType <Apparel>());

            foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
            {
                foreach (Apparel pawnApparel in pawn.apparel.WornApparel)
                {
                    if (pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(pawnApparel))
                    {
                        allApparels.Add(pawnApparel);
                    }
                }
            }

            allApparels = allApparels.Where(i => !ApparelUtility.CanWearTogether(this.apparel.def, i.def)).ToList();

            Rect groupRect = windowRect.ContractedBy(10f);

            groupRect.height -= 100;
            GUI.BeginGroup(groupRect);

            float apparelScoreWidth   = 100f;
            float apparelGainWidth    = 100f;
            float apparelLabelWidth   = (groupRect.width - apparelScoreWidth - apparelGainWidth) / 3 - 8f - 8f;
            float apparelEquipedWidth = apparelLabelWidth;
            float apparelOwnerWidth   = apparelLabelWidth;

            Rect itemRect = new Rect(groupRect.xMin + 4f, groupRect.yMin, groupRect.width - 8f, 28f);

            this.DrawLine(ref itemRect,
                          null, "Apparel", apparelLabelWidth,
                          null, "Equiped", apparelEquipedWidth,
                          null, "Target", apparelOwnerWidth,
                          "Score", apparelScoreWidth,
                          "Gain", apparelGainWidth);

            groupRect.yMin += itemRect.height;
            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMin, groupRect.width);
            groupRect.yMin   += 4f;
            groupRect.height -= 4f;
            groupRect.height -= Text.LineHeight * 1.2f * 3f;

            Rect viewRect = new Rect(groupRect.xMin, groupRect.yMin, groupRect.width - 16f, allApparels.Count() * 28f + 16f);

            if (viewRect.height < groupRect.height)
            {
                groupRect.height = viewRect.height;
            }

            Rect listRect = viewRect.ContractedBy(4f);

            Widgets.BeginScrollView(groupRect, ref scrollPosition, viewRect);

            allApparels = allApparels.OrderByDescending(i => { float g; if (pawnAutoEquip.CalculateApparelScoreGain(i, out g))
                                                               {
                                                                   return(g);
                                                               }
                                                               return(-1000f); }).ToList();

            foreach (Apparel currentAppel in allApparels)
            {
                itemRect = new Rect(listRect.xMin, listRect.yMin, listRect.width, 28f);
                if (Mouse.IsOver(itemRect))
                {
                    GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                    GUI.DrawTexture(itemRect, TexUI.HighlightTex);
                    GUI.color = Color.white;
                }

                Pawn equiped = null;
                Pawn target  = null;

                foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
                {
                    foreach (Apparel a in pawn.apparel.WornApparel)
                    {
                        if (a == currentAppel)
                        {
                            equiped = pawn;
                            break;
                        }
                    }

                    foreach (Apparel a in mapComponent.GetCache(pawn).targetApparel)
                    {
                        if (a == currentAppel)
                        {
                            target = pawn;
                            break;
                        }
                    }

                    if ((equiped != null) &&
                        (target != null))
                    {
                        break;
                    }
                }

                float gain;
                if (pawnAutoEquip.CalculateApparelScoreGain(currentAppel, out gain))
                {
                    this.DrawLine(ref itemRect,
                                  currentAppel, currentAppel.LabelCap, apparelLabelWidth,
                                  equiped, equiped == null ? null : equiped.LabelCap, apparelEquipedWidth,
                                  target, target == null ? null : target.LabelCap, apparelOwnerWidth,
                                  pawnAutoEquip.CalculateApparelScoreRaw(currentAppel).ToString("N5"), apparelScoreWidth,
                                  gain.ToString("N5"), apparelGainWidth);
                }
                else
                {
                    this.DrawLine(ref itemRect,
                                  currentAppel, currentAppel.LabelCap, apparelLabelWidth,
                                  equiped, equiped == null ? null : equiped.LabelCap, apparelEquipedWidth,
                                  target, target == null ? null : target.LabelCap, apparelOwnerWidth,
                                  pawnAutoEquip.CalculateApparelScoreRaw(currentAppel).ToString("N5"), apparelScoreWidth,
                                  "No Allow", apparelGainWidth);
                }

                listRect.yMin = itemRect.yMax;
            }

            Widgets.EndScrollView();

            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMax, groupRect.width);

            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
        }
        protected override void FillTab()
        {
            Saveable_Pawn pawnSave;
            PawnCalcForApparel pawnCalc;
            if (this.SelPawnForGear.IsColonist)
            {
                pawnSave = MapComponent_AutoEquip.Get.GetCache(this.SelPawnForGear);
                pawnCalc = new PawnCalcForApparel(pawnSave);
            }
            else
            {
                pawnSave = null;
                pawnCalc = null;
            }

            Text.Font = GameFont.Small;
            Rect rect = new Rect(0f, 20f, this.size.x, this.size.y - 20f);
            Rect rect2 = rect.ContractedBy(10f);
            Rect position = new Rect(rect2.x, rect2.y, rect2.width, rect2.height);
            GUI.BeginGroup(position);
            Text.Font = GameFont.Small;
            GUI.color = Color.white;
            Rect outRect = new Rect(0f, 0f, position.width, position.height);

            if (pawnSave != null)
            {
                Rect rect3 = new Rect(outRect.xMin + 4f, outRect.yMin, 100f, 30f);
                if (Widgets.TextButton(rect3, pawnSave.pawn.outfits.CurrentOutfit.label, true, false))
                {
                    List<FloatMenuOption> list = new List<FloatMenuOption>();
                    foreach (Outfit current in Find.Map.outfitDatabase.AllOutfits)
                    {
                        Outfit localOut = current;
                        list.Add(new FloatMenuOption(localOut.label, delegate
                        {
                            pawnSave.pawn.outfits.CurrentOutfit = localOut;
                        }, MenuOptionPriority.Medium, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list, false));
                }
                rect3 = new Rect(rect3.xMax + 4f, outRect.yMin, 100f, 30f);
                if (Widgets.TextButton(rect3, "AutoEquipStatus".Translate(), true, false))
                {
                    if (pawnSave.stats == null)
                        pawnSave.stats = new List<Saveable_StatDef>();
                    Find.WindowStack.Add(new Dialog_ManagePawnOutfit(pawnSave.stats));
                }

                outRect.yMin += rect3.height + 4f;
            }

            Rect viewRect = new Rect(0f, 0f, position.width - 16f, this.scrollViewHeight);
            Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect);
            float num = 0f;
            if (this.SelPawnForGear.equipment != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Equipment".Translate());
                foreach (ThingWithComps current in this.SelPawnForGear.equipment.AllEquipment)
                    this.DrawThingRow(ref num, viewRect.width, current, true, ITab_Pawn_AutoEquip.ThingLabelColor, pawnSave, pawnCalc);
            }
            if (this.SelPawnForGear.apparel != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Apparel".Translate());
                foreach (Apparel current2 in from ap in this.SelPawnForGear.apparel.WornApparel
                                             orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                                             select ap)
                    this.DrawThingRow(ref num, viewRect.width, current2, true, ITab_Pawn_AutoEquip.ThingLabelColor, pawnSave, pawnCalc);
            }
            if (pawnSave != null)
            {
                if ((pawnSave.toWearApparel != null) &&
                    (pawnSave.toWearApparel.Any()))
                {
                    Widgets.ListSeparator(ref num, viewRect.width, "ToWear".Translate());
                    foreach (Apparel current2 in from ap in pawnSave.toWearApparel
                                                 orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                                                 select ap)
                        this.DrawThingRow(ref num, viewRect.width, current2, false, ITab_Pawn_AutoEquip.ThingToEquipLabelColor, pawnSave, pawnCalc);
                }

                if ((pawnSave.toDropApparel != null) &&
                    (pawnSave.toDropApparel.Any()))
                {
                    Widgets.ListSeparator(ref num, viewRect.width, "ToDrop".Translate());
                    foreach (Apparel current2 in from ap in pawnSave.toDropApparel
                                                 orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                                                 select ap)
                        this.DrawThingRow(ref num, viewRect.width, current2, this.SelPawnForGear.apparel.WornApparel.Contains(current2), ITab_Pawn_AutoEquip.ThingToDropLabelColor, pawnSave, pawnCalc);
                }
            }
            if (this.SelPawnForGear.inventory != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Inventory".Translate());
                foreach (Thing current3 in this.SelPawnForGear.inventory.container)
                    this.DrawThingRow(ref num, viewRect.width, current3, true, ITab_Pawn_AutoEquip.ThingLabelColor, pawnSave, pawnCalc);
            }

            if (Event.current.type == EventType.Layout)
                this.scrollViewHeight = num + 30f;
            Widgets.EndScrollView();
            GUI.EndGroup();
            GUI.color = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
        private void DrawThingRow(ref float y, float width, Thing thing, bool equiped, Color thingColor, Saveable_Pawn pawnSave, PawnCalcForApparel pawnCalc)
        {
            Rect rect = new Rect(0f, y, width, 28f);
            if (Mouse.IsOver(rect))
            {
                GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }
            if (Widgets.InvisibleButton(rect) && Event.current.button == 1)
            {
                List<FloatMenuOption> list = new List<FloatMenuOption>();
                list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }, MenuOptionPriority.Medium, null, null));
                if (this.CanEdit && equiped)
                {
                    Action action = null;
                    ThingWithComps eq = thing as ThingWithComps;
                    Apparel ap = thing as Apparel;
                    if (ap != null)
                    {
                        Apparel unused;
                        action = delegate
                        {
                            this.SelPawnForGear.apparel.TryDrop(ap, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (eq != null && this.SelPawnForGear.equipment.AllEquipment.Contains(eq))
                    {
                        ThingWithComps unused;
                        action = delegate
                        {
                            this.SelPawnForGear.equipment.TryDropEquipment(eq, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (!thing.def.destroyOnDrop)
                    {
                        Thing unused;
                        action = delegate
                        {
                            this.SelPawnForGear.inventory.container.TryDrop(thing, this.SelPawnForGear.Position, ThingPlaceMode.Near, out unused);
                        };
                    }
                    list.Add(new FloatMenuOption("DropThing".Translate(), action, MenuOptionPriority.Medium, null, null));
                }

                if ((pawnSave != null) &&
                    (thing is Apparel))
                {
                    if (!equiped)
                        list.Add(new FloatMenuOption("Locate", delegate
                        {
                            Pawn apparelEquipedThing = null;

                            foreach (Pawn p in Find.ListerPawns.FreeColonists)
                            {
                                foreach (Apparel a in p.apparel.WornApparel)
                                    if (a == thing)
                                    {
                                        apparelEquipedThing = p;
                                        break;
                                    }
                                if (apparelEquipedThing != null)
                                    break;
                            }

                            if (apparelEquipedThing != null)
                            {
                                Find.CameraMap.JumpTo(apparelEquipedThing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (apparelEquipedThing.SpawnedInWorld)
                                    Find.Selector.Select(apparelEquipedThing, true, true);
                            }
                            else
                            {
                                Find.CameraMap.JumpTo(thing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (thing.SpawnedInWorld)
                                    Find.Selector.Select(thing, true, true);
                            }
                        }, MenuOptionPriority.Medium, null, null));
                    list.Add(new FloatMenuOption("AutoEquip Details", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelDetail(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));

                    list.Add(new FloatMenuOption("AutoEquip Comparer", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelComparer(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));
                }

                FloatMenu window = new FloatMenu(list, thing.LabelCap, false, false);
                Find.WindowStack.Add(window);
            }
            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color = thingColor;
            Rect rect2 = new Rect(36f, y, width - 36f, 28f);
            string text = thing.LabelCap;
            if (thing is Apparel)
            {
                if ((pawnSave != null) &&
                    (pawnSave.targetApparel != null))
                    text = pawnCalc.CalculateApparelScoreRaw((Apparel)thing).ToString("N5") + "   " + text;

                if (this.SelPawnForGear.outfits != null && this.SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing))
                    text = text + ", " + "ApparelForcedLower".Translate();
            }
            Widgets.Label(rect2, text);
            y += 28f;
        }
Exemple #13
0
        protected override void FillTab()
        {
            Saveable_Pawn      pawnSave;
            PawnCalcForApparel pawnCalc;

            if (this.SelPawnForGear.IsColonist)
            {
                pawnSave = MapComponent_AutoEquip.Get.GetCache(this.SelPawnForGear);
                pawnCalc = new PawnCalcForApparel(pawnSave);
            }
            else
            {
                pawnSave = null;
                pawnCalc = null;
            }

            Text.Font = GameFont.Small;
            Rect rect     = new Rect(0f, 20f, this.size.x, this.size.y - 20f);
            Rect rect2    = rect.ContractedBy(10f);
            Rect position = new Rect(rect2.x, rect2.y, rect2.width, rect2.height);

            GUI.BeginGroup(position);
            Text.Font = GameFont.Small;
            GUI.color = Color.white;
            Rect outRect = new Rect(0f, 0f, position.width, position.height);

            if (pawnSave != null)
            {
                Rect rect3 = new Rect(outRect.xMin + 4f, outRect.yMin, 100f, 30f);
                if (Widgets.TextButton(rect3, pawnSave.pawn.outfits.CurrentOutfit.label, true, false))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (Outfit current in Find.Map.outfitDatabase.AllOutfits)
                    {
                        Outfit localOut = current;
                        list.Add(new FloatMenuOption(localOut.label, delegate
                        {
                            pawnSave.pawn.outfits.CurrentOutfit = localOut;
                        }, MenuOptionPriority.Medium, null, null));
                    }
                    Find.WindowStack.Add(new FloatMenu(list, false));
                }
                rect3 = new Rect(rect3.xMax + 4f, outRect.yMin, 100f, 30f);
                if (Widgets.TextButton(rect3, "AutoEquipStatus".Translate(), true, false))
                {
                    if (pawnSave.stats == null)
                    {
                        pawnSave.stats = new List <Saveable_StatDef>();
                    }
                    Find.WindowStack.Add(new Dialog_ManagePawnOutfit(pawnSave.stats));
                }

                outRect.yMin += rect3.height + 4f;
            }

            Rect viewRect = new Rect(0f, 0f, position.width - 16f, this.scrollViewHeight);

            Widgets.BeginScrollView(outRect, ref this.scrollPosition, viewRect);
            float num = 0f;

            if (this.SelPawnForGear.equipment != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Equipment".Translate());
                foreach (ThingWithComps current in this.SelPawnForGear.equipment.AllEquipment)
                {
                    this.DrawThingRow(ref num, viewRect.width, current, true, ITab_Pawn_AutoEquip.ThingLabelColor, pawnSave, pawnCalc);
                }
            }
            if (this.SelPawnForGear.apparel != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Apparel".Translate());
                foreach (Apparel current2 in from ap in this.SelPawnForGear.apparel.WornApparel
                         orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                         select ap)
                {
                    this.DrawThingRow(ref num, viewRect.width, current2, true, ITab_Pawn_AutoEquip.ThingLabelColor, pawnSave, pawnCalc);
                }
            }
            if (pawnSave != null)
            {
                if ((pawnSave.toWearApparel != null) &&
                    (pawnSave.toWearApparel.Any()))
                {
                    Widgets.ListSeparator(ref num, viewRect.width, "ToWear".Translate());
                    foreach (Apparel current2 in from ap in pawnSave.toWearApparel
                             orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                             select ap)
                    {
                        this.DrawThingRow(ref num, viewRect.width, current2, false, ITab_Pawn_AutoEquip.ThingToEquipLabelColor, pawnSave, pawnCalc);
                    }
                }

                if ((pawnSave.toDropApparel != null) &&
                    (pawnSave.toDropApparel.Any()))
                {
                    Widgets.ListSeparator(ref num, viewRect.width, "ToDrop".Translate());
                    foreach (Apparel current2 in from ap in pawnSave.toDropApparel
                             orderby ap.def.apparel.bodyPartGroups[0].listOrder descending
                             select ap)
                    {
                        this.DrawThingRow(ref num, viewRect.width, current2, this.SelPawnForGear.apparel.WornApparel.Contains(current2), ITab_Pawn_AutoEquip.ThingToDropLabelColor, pawnSave, pawnCalc);
                    }
                }
            }
            if (this.SelPawnForGear.inventory != null)
            {
                Widgets.ListSeparator(ref num, viewRect.width, "Inventory".Translate());
                foreach (Thing current3 in this.SelPawnForGear.inventory.container)
                {
                    this.DrawThingRow(ref num, viewRect.width, current3, true, ITab_Pawn_AutoEquip.ThingLabelColor, pawnSave, pawnCalc);
                }
            }

            if (Event.current.type == EventType.Layout)
            {
                this.scrollViewHeight = num + 30f;
            }
            Widgets.EndScrollView();
            GUI.EndGroup();
            GUI.color   = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
        }
Exemple #14
0
        private void DrawThingRow(ref float y, float width, Thing thing, bool equiped, Color thingColor, Saveable_Pawn pawnSave, PawnCalcForApparel pawnCalc)
        {
            Rect rect = new Rect(0f, y, width, 28f);

            if (Mouse.IsOver(rect))
            {
                GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                GUI.DrawTexture(rect, TexUI.HighlightTex);
            }
            if (Widgets.InvisibleButton(rect) && Event.current.button == 1)
            {
                List <FloatMenuOption> list = new List <FloatMenuOption>();
                list.Add(new FloatMenuOption("ThingInfo".Translate(), delegate
                {
                    Find.WindowStack.Add(new Dialog_InfoCard(thing));
                }, MenuOptionPriority.Medium, null, null));
                if (this.CanEdit && equiped)
                {
                    Action         action = null;
                    ThingWithComps eq     = thing as ThingWithComps;
                    Apparel        ap     = thing as Apparel;
                    if (ap != null)
                    {
                        Apparel unused;
                        action = delegate
                        {
                            this.SelPawnForGear.apparel.TryDrop(ap, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (eq != null && this.SelPawnForGear.equipment.AllEquipment.Contains(eq))
                    {
                        ThingWithComps unused;
                        action = delegate
                        {
                            this.SelPawnForGear.equipment.TryDropEquipment(eq, out unused, this.SelPawnForGear.Position, true);
                        };
                    }
                    else if (!thing.def.destroyOnDrop)
                    {
                        Thing unused;
                        action = delegate
                        {
                            this.SelPawnForGear.inventory.container.TryDrop(thing, this.SelPawnForGear.Position, ThingPlaceMode.Near, out unused);
                        };
                    }
                    list.Add(new FloatMenuOption("DropThing".Translate(), action, MenuOptionPriority.Medium, null, null));
                }

                if ((pawnSave != null) &&
                    (thing is Apparel))
                {
                    if (!equiped)
                    {
                        list.Add(new FloatMenuOption("Locate", delegate
                        {
                            Pawn apparelEquipedThing = null;

                            foreach (Pawn p in Find.ListerPawns.FreeColonists)
                            {
                                foreach (Apparel a in p.apparel.WornApparel)
                                {
                                    if (a == thing)
                                    {
                                        apparelEquipedThing = p;
                                        break;
                                    }
                                }
                                if (apparelEquipedThing != null)
                                {
                                    break;
                                }
                            }

                            if (apparelEquipedThing != null)
                            {
                                Find.CameraMap.JumpTo(apparelEquipedThing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (apparelEquipedThing.SpawnedInWorld)
                                {
                                    Find.Selector.Select(apparelEquipedThing, true, true);
                                }
                            }
                            else
                            {
                                Find.CameraMap.JumpTo(thing.PositionHeld);
                                Find.Selector.ClearSelection();
                                if (thing.SpawnedInWorld)
                                {
                                    Find.Selector.Select(thing, true, true);
                                }
                            }
                        }, MenuOptionPriority.Medium, null, null));
                    }
                    list.Add(new FloatMenuOption("AutoEquip Details", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelDetail(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));

                    list.Add(new FloatMenuOption("AutoEquip Comparer", delegate
                    {
                        Find.WindowStack.Add(new Dialog_PawnApparelComparer(pawnSave.pawn, (Apparel)thing));
                    }, MenuOptionPriority.Medium, null, null));
                }

                FloatMenu window = new FloatMenu(list, thing.LabelCap, false, false);
                Find.WindowStack.Add(window);
            }
            if (thing.def.DrawMatSingle != null && thing.def.DrawMatSingle.mainTexture != null)
            {
                Widgets.ThingIcon(new Rect(4f, y, 28f, 28f), thing);
            }
            Text.Anchor = TextAnchor.MiddleLeft;
            GUI.color   = thingColor;
            Rect   rect2 = new Rect(36f, y, width - 36f, 28f);
            string text  = thing.LabelCap;

            if (thing is Apparel)
            {
                if ((pawnSave != null) &&
                    (pawnSave.targetApparel != null))
                {
                    text = pawnCalc.CalculateApparelScoreRaw((Apparel)thing).ToString("N5") + "   " + text;
                }

                if (this.SelPawnForGear.outfits != null && this.SelPawnForGear.outfits.forcedHandler.IsForced((Apparel)thing))
                {
                    text = text + ", " + "ApparelForcedLower".Translate();
                }
            }
            Widgets.Label(rect2, text);
            y += 28f;
        }
        public override void DoWindowContents(Rect windowRect)
        {
            PawnCalcForApparel conf = new PawnCalcForApparel(this.pawn);

            Rect groupRect = windowRect.ContractedBy(10f);
            groupRect.height -= 100;
            GUI.BeginGroup(groupRect);

            float baseValue = 100f;
            float multiplierWidth = 100f;
            float finalValue = 120f;
            float labelWidth = groupRect.width - baseValue - multiplierWidth - finalValue - 8f - 8f;

            Rect itemRect = new Rect(groupRect.xMin + 4f, groupRect.yMin, groupRect.width - 8f, Text.LineHeight * 1.2f);

            this.DrawLine(ref itemRect,
                "Status", labelWidth,
                "Base", baseValue,
                "Strengh", multiplierWidth,
                "Final", finalValue);

            groupRect.yMin += itemRect.height;
            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMin, groupRect.width);
            groupRect.yMin += 4f;
            groupRect.height -= 4f;
            groupRect.height -= Text.LineHeight * 1.2f * 3f + 5f;

            Saveable_StatDef[] stats = conf.Stats.ToArray();
            Rect viewRect = new Rect(groupRect.xMin, groupRect.yMin, groupRect.width - 16f, stats.Length * Text.LineHeight * 1.2f + 16f);
            if (viewRect.height < groupRect.height)
                groupRect.height = viewRect.height;

            Rect listRect = viewRect.ContractedBy(4f);

            Widgets.BeginScrollView(groupRect, ref scrollPosition, viewRect);

            float sumValue = 0;
            foreach (Saveable_StatDef stat in stats)
            {
                itemRect = new Rect(listRect.xMin, listRect.yMin, listRect.width, Text.LineHeight * 1.2f);
                if (Mouse.IsOver(itemRect))
                {
                    GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                    GUI.DrawTexture(itemRect, TexUI.HighlightTex);
                    GUI.color = Color.white;
                }

                float value = conf.GetStatValue(apparel, stat);
                sumValue += value;

                this.DrawLine(ref itemRect,
                    stat.statDef.label, labelWidth,
                    value.ToString("N3"), baseValue,
                    stat.strength.ToString("N2"), multiplierWidth,
                    (value * stat.strength).ToString("N5"), finalValue);

                listRect.yMin = itemRect.yMax;
            }

            Widgets.EndScrollView();

            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMax, groupRect.width);

            itemRect = new Rect(listRect.xMin, groupRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                "AverageStat".Translate(), labelWidth,
                (sumValue / stats.Length).ToString("N3"), baseValue,
                "", multiplierWidth,
                conf.CalculateApparelScoreRawStats(apparel).ToString("N5"), finalValue);

            itemRect.yMax += 5;

            itemRect = new Rect(listRect.xMin, itemRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                "AutoEquipHitPoints".Translate(), labelWidth,
                conf.CalculateApparelScoreRawHitPointAjust(apparel).ToString("N3"), baseValue,
                "", multiplierWidth,
                "", finalValue);

            itemRect = new Rect(listRect.xMin, itemRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                "AutoEquipTemperature".Translate(), labelWidth,
                conf.CalculateApparelScoreRawInsulationColdAjust(apparel).ToString("N3"), baseValue,
                "", multiplierWidth,
                "", finalValue);

            itemRect = new Rect(listRect.xMin, itemRect.yMax, listRect.width, Text.LineHeight * 1.2f);
            this.DrawLine(ref itemRect,
                "AutoEquipTotal".Translate(), labelWidth,
                conf.CalculateApparelModifierRaw(apparel).ToString("N3"), baseValue,
                "", multiplierWidth,
                conf.CalculateApparelScoreRaw(apparel).ToString("N5"), finalValue);

            GUI.color = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
        }
        public override void DoWindowContents(Rect windowRect)
        {
            MapComponent_AutoEquip mapComponent = MapComponent_AutoEquip.Get;
            PawnCalcForApparel pawnAutoEquip = new PawnCalcForApparel(mapComponent.GetCache(this.pawn));
            List<Apparel> allApparels = new List<Apparel>(Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType<Apparel>());
            foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
            {
                foreach (Apparel pawnApparel in pawn.apparel.WornApparel)
                    if (pawn.outfits.forcedHandler.AllowedToAutomaticallyDrop(pawnApparel))
                        allApparels.Add(pawnApparel);
            }

            allApparels = allApparels.Where(i => !ApparelUtility.CanWearTogether(this.apparel.def, i.def)).ToList();

            Rect groupRect = windowRect.ContractedBy(10f);
            groupRect.height -= 100;
            GUI.BeginGroup(groupRect);

            float apparelScoreWidth = 100f;
            float apparelGainWidth = 100f;
            float apparelLabelWidth = (groupRect.width - apparelScoreWidth - apparelGainWidth) / 3 - 8f - 8f;
            float apparelEquipedWidth = apparelLabelWidth;
            float apparelOwnerWidth = apparelLabelWidth;

            Rect itemRect = new Rect(groupRect.xMin + 4f, groupRect.yMin, groupRect.width - 8f, 28f);

            this.DrawLine(ref itemRect,
                null, "Apparel", apparelLabelWidth,
                null, "Equiped", apparelEquipedWidth,
                null, "Target", apparelOwnerWidth,
                "Score", apparelScoreWidth,
                "Gain", apparelGainWidth);

            groupRect.yMin += itemRect.height;
            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMin, groupRect.width);
            groupRect.yMin += 4f;
            groupRect.height -= 4f;
            groupRect.height -= Text.LineHeight * 1.2f * 3f;

            Rect viewRect = new Rect(groupRect.xMin, groupRect.yMin, groupRect.width - 16f, allApparels.Count() * 28f + 16f);
            if (viewRect.height < groupRect.height)
                groupRect.height = viewRect.height;

            Rect listRect = viewRect.ContractedBy(4f);

            Widgets.BeginScrollView(groupRect, ref scrollPosition, viewRect);

            allApparels = allApparels.OrderByDescending(i => { float g; if (pawnAutoEquip.CalculateApparelScoreGain(i, out g)) return g; return -1000f; }).ToList();

            foreach (Apparel currentAppel in allApparels)
            {
                itemRect = new Rect(listRect.xMin, listRect.yMin, listRect.width, 28f);
                if (Mouse.IsOver(itemRect))
                {
                    GUI.color = ITab_Pawn_AutoEquip.HighlightColor;
                    GUI.DrawTexture(itemRect, TexUI.HighlightTex);
                    GUI.color = Color.white;
                }

                Pawn equiped = null;
                Pawn target = null;

                foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
                {
                    foreach (Apparel a in pawn.apparel.WornApparel)
                        if (a == currentAppel)
                        {
                            equiped = pawn;
                            break;
                        }

                    foreach (Apparel a in mapComponent.GetCache(pawn).targetApparel)
                        if (a == currentAppel)
                        {
                            target = pawn;
                            break;
                        }

                    if ((equiped != null) &&
                        (target != null))
                        break;
                }

                float gain;
                if (pawnAutoEquip.CalculateApparelScoreGain(currentAppel, out gain))
                    this.DrawLine(ref itemRect,
                        currentAppel, currentAppel.LabelCap, apparelLabelWidth,
                        equiped, equiped == null ? null : equiped.LabelCap, apparelEquipedWidth,
                        target, target == null ? null : target.LabelCap, apparelOwnerWidth,
                        pawnAutoEquip.CalculateApparelScoreRaw(currentAppel).ToString("N5"), apparelScoreWidth,
                        gain.ToString("N5"), apparelGainWidth);
                else
                    this.DrawLine(ref itemRect,
                        currentAppel, currentAppel.LabelCap, apparelLabelWidth,
                        equiped, equiped == null ? null : equiped.LabelCap, apparelEquipedWidth,
                        target, target == null ? null : target.LabelCap, apparelOwnerWidth,
                        pawnAutoEquip.CalculateApparelScoreRaw(currentAppel).ToString("N5"), apparelScoreWidth,
                        "No Allow", apparelGainWidth);

                listRect.yMin = itemRect.yMax;
            }

            Widgets.EndScrollView();

            Widgets.DrawLineHorizontal(groupRect.xMin, groupRect.yMax, groupRect.width);

            GUI.color = Color.white;
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.EndGroup();
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            if (Find.TickManager.TicksGame < this.nextOptimization)
                return;

            #if LOG
            MapComponent_AutoEquip.logMessage = new StringBuilder();
            MapComponent_AutoEquip.logMessage.AppendLine("Start Scaning Best Apparel");
            MapComponent_AutoEquip.logMessage.AppendLine();
            #endif
            List<Saveable_Pawn> newSaveableList = new List<Saveable_Pawn>();
            List<PawnCalcForApparel> newCalcList = new List<PawnCalcForApparel>();

            List<Apparel> allApparels = new List<Apparel>(Find.ListerThings.ThingsInGroup(ThingRequestGroup.Apparel).OfType<Apparel>());
            foreach (Pawn pawn in Find.ListerPawns.FreeColonists)
            {
                this.InjectTab(pawn.def);
                Saveable_Pawn newPawnSaveable = this.GetCache(pawn);
                PawnCalcForApparel newPawnCalc = new PawnCalcForApparel(newPawnSaveable);

                newSaveableList.Add(newPawnSaveable);
                newCalcList.Add(newPawnCalc);

                newPawnCalc.InitializeFixedApparelsAndGetAvaliableApparels(allApparels);
            }

            this.pawnCache = newSaveableList;
            PawnCalcForApparel.DoOptimizeApparel(newCalcList, allApparels);

            #if LOG
            this.nextOptimization = Find.TickManager.TicksGame + 500;
            #else
            this.nextOptimization = Find.TickManager.TicksGame + 5000;
            #endif
        }