Ejemplo n.º 1
0
        public static void RedressPawn(Pawn pawn, PawnGenerationRequest request)
        {
            try
            {
                if (pawn.becameWorldPawnTickAbs != -1 && pawn.health != null)
                {
                    float         x    = (GenTicks.TicksAbs - pawn.becameWorldPawnTickAbs).TicksToDays();
                    List <Hediff> list = SimplePool <List <Hediff> > .Get();

                    list.Clear();
                    foreach (Hediff hediff in pawn.health.hediffSet.hediffs)
                    {
                        if (Rand.Chance(hediff.def.removeOnRedressChanceByDaysCurve.Evaluate(x)))
                        {
                            list.Add(hediff);
                        }
                    }
                    foreach (Hediff item in list)
                    {
                        pawn.health.RemoveHediff(item);
                    }
                    list.Clear();
                    SimplePool <List <Hediff> > .Return(list);
                }
                pawn.ChangeKind(request.KindDef);
                if (pawn.royalty != null)
                {
                    pawn.royalty.allowRoomRequirements    = pawn.kindDef.allowRoyalRoomRequirements;
                    pawn.royalty.allowApparelRequirements = pawn.kindDef.allowRoyalApparelRequirements;
                }
                if (pawn.Faction != request.Faction)
                {
                    pawn.SetFaction(request.Faction);
                }
                GenerateGearFor(pawn, request);
                if (pawn.guest != null)
                {
                    pawn.guest.SetGuestStatus(null);
                }
                if (pawn.needs != null)
                {
                    pawn.needs.SetInitialLevels();
                }
            }
            finally
            {
            }
        }
Ejemplo n.º 2
0
        public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish)
        {
            base.DeSpawn(mode);
            this.cellsToAffect.Clear();
            SimplePool <List <IntVec3> > .Return(this.cellsToAffect);

            this.cellsToAffect = null;
            this.damagedThings.Clear();
            SimplePool <List <Thing> > .Return(this.damagedThings);

            this.damagedThings = null;
            this.addedCellsAffectedOnlyByDamage.Clear();
            SimplePool <HashSet <IntVec3> > .Return(this.addedCellsAffectedOnlyByDamage);

            this.addedCellsAffectedOnlyByDamage = null;
        }
Ejemplo n.º 3
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            if (!respawningAfterLoad)
            {
                this.cellsToAffect = SimplePool <List <IntVec3> > .Get();

                this.cellsToAffect.Clear();
                this.damagedThings = SimplePool <List <Thing> > .Get();

                this.damagedThings.Clear();
                this.addedCellsAffectedOnlyByDamage = SimplePool <HashSet <IntVec3> > .Get();

                this.addedCellsAffectedOnlyByDamage.Clear();
            }
        }
Ejemplo n.º 4
0
        public static int RemoveAll <TKey, TValue>(this Dictionary <TKey, TValue> dictionary, Predicate <KeyValuePair <TKey, TValue> > predicate)
        {
            List <TKey> list = null;
            int         result;

            try
            {
                foreach (KeyValuePair <TKey, TValue> current in dictionary)
                {
                    if (predicate(current))
                    {
                        if (list == null)
                        {
                            list = SimplePool <List <TKey> > .Get();
                        }
                        list.Add(current.Key);
                    }
                }
                if (list != null)
                {
                    int i     = 0;
                    int count = list.Count;
                    while (i < count)
                    {
                        dictionary.Remove(list[i]);
                        i++;
                    }
                    result = list.Count;
                }
                else
                {
                    result = 0;
                }
            }
            finally
            {
                if (list != null)
                {
                    list.Clear();
                    SimplePool <List <TKey> > .Return(list);
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
        public static int RemoveAll <TKey, TValue>(this Dictionary <TKey, TValue> dictionary, Predicate <KeyValuePair <TKey, TValue> > predicate)
        {
            List <TKey> list = null;

            try
            {
                foreach (KeyValuePair <TKey, TValue> item in dictionary)
                {
                    if (predicate(item))
                    {
                        if (list == null)
                        {
                            list = SimplePool <List <TKey> > .Get();
                        }
                        list.Add(item.Key);
                    }
                }
                if (list != null)
                {
                    int i     = 0;
                    int count = list.Count;
                    for (; i < count; i++)
                    {
                        dictionary.Remove(list[i]);
                    }
                    return(list.Count);
                }
                return(0);
            }
            finally
            {
                if (list != null)
                {
                    list.Clear();
                    SimplePool <List <TKey> > .Return(list);
                }
            }
        }
Ejemplo n.º 6
0
        public static void DrawGizmoGrid(IEnumerable <Gizmo> gizmos, float startX, out Gizmo mouseoverGizmo)
        {
            tmpAllGizmos.Clear();
            tmpAllGizmos.AddRange(gizmos);
            tmpAllGizmos.SortStable(SortByOrder);
            gizmoGroups.Clear();
            for (int i = 0; i < tmpAllGizmos.Count; i++)
            {
                Gizmo gizmo = tmpAllGizmos[i];
                bool  flag  = false;
                for (int j = 0; j < gizmoGroups.Count; j++)
                {
                    if (gizmoGroups[j][0].GroupsWith(gizmo))
                    {
                        flag = true;
                        gizmoGroups[j].Add(gizmo);
                        gizmoGroups[j][0].MergeWith(gizmo);
                        break;
                    }
                }
                if (!flag)
                {
                    List <Gizmo> list = SimplePool <List <Gizmo> > .Get();

                    list.Add(gizmo);
                    gizmoGroups.Add(list);
                }
            }
            firstGizmos.Clear();
            for (int k = 0; k < gizmoGroups.Count; k++)
            {
                List <Gizmo> list2  = gizmoGroups[k];
                Gizmo        gizmo2 = null;
                for (int l = 0; l < list2.Count; l++)
                {
                    if (!list2[l].disabled)
                    {
                        gizmo2 = list2[l];
                        break;
                    }
                }
                if (gizmo2 == null)
                {
                    gizmo2 = list2.FirstOrDefault();
                }
                else
                {
                    Command_Toggle command_Toggle = gizmo2 as Command_Toggle;
                    if (command_Toggle != null)
                    {
                        if (!command_Toggle.activateIfAmbiguous && !command_Toggle.isActive())
                        {
                            for (int m = 0; m < list2.Count; m++)
                            {
                                Command_Toggle command_Toggle2 = list2[m] as Command_Toggle;
                                if (command_Toggle2 != null && !command_Toggle2.disabled && command_Toggle2.isActive())
                                {
                                    gizmo2 = list2[m];
                                    break;
                                }
                            }
                        }
                        if (command_Toggle.activateIfAmbiguous && command_Toggle.isActive())
                        {
                            for (int n = 0; n < list2.Count; n++)
                            {
                                Command_Toggle command_Toggle3 = list2[n] as Command_Toggle;
                                if (command_Toggle3 != null && !command_Toggle3.disabled && !command_Toggle3.isActive())
                                {
                                    gizmo2 = list2[n];
                                    break;
                                }
                            }
                        }
                    }
                }
                if (gizmo2 != null)
                {
                    firstGizmos.Add(gizmo2);
                }
            }
            drawnHotKeys.Clear();
            float num      = UI.screenWidth - 147;
            float maxWidth = num - startX;

            Text.Font = GameFont.Tiny;
            Vector2 topLeft = new Vector2(startX, (float)(UI.screenHeight - 35) - GizmoSpacing.y - 75f);

            mouseoverGizmo = null;
            Gizmo gizmo3 = null;
            Event ev     = null;
            Gizmo gizmo4 = null;

            for (int num2 = 0; num2 < firstGizmos.Count; num2++)
            {
                Gizmo gizmo5 = firstGizmos[num2];
                if (gizmo5.Visible)
                {
                    if (topLeft.x + gizmo5.GetWidth(maxWidth) > num)
                    {
                        topLeft.x  = startX;
                        topLeft.y -= 75f + GizmoSpacing.x;
                    }
                    heightDrawnFrame = Time.frameCount;
                    heightDrawn      = (float)UI.screenHeight - topLeft.y;
                    GizmoResult gizmoResult = gizmo5.GizmoOnGUI(topLeft, maxWidth);
                    if (gizmoResult.State == GizmoState.Interacted || (gizmoResult.State == GizmoState.OpenedFloatMenu && gizmo5.RightClickFloatMenuOptions.FirstOrDefault() == null))
                    {
                        ev     = gizmoResult.InteractEvent;
                        gizmo3 = gizmo5;
                    }
                    else if (gizmoResult.State == GizmoState.OpenedFloatMenu)
                    {
                        gizmo4 = gizmo5;
                    }
                    if ((int)gizmoResult.State >= 1)
                    {
                        mouseoverGizmo = gizmo5;
                    }
                    GenUI.AbsorbClicksInRect(new Rect(topLeft.x, topLeft.y, gizmo5.GetWidth(maxWidth), 75f + GizmoSpacing.y).ContractedBy(-12f));
                    topLeft.x += gizmo5.GetWidth(maxWidth) + GizmoSpacing.x;
                }
            }
            if (gizmo3 != null)
            {
                List <Gizmo> list3 = FindMatchingGroup(gizmo3);
                for (int num3 = 0; num3 < list3.Count; num3++)
                {
                    Gizmo gizmo6 = list3[num3];
                    if (gizmo6 != gizmo3 && !gizmo6.disabled && gizmo3.InheritInteractionsFrom(gizmo6))
                    {
                        gizmo6.ProcessInput(ev);
                    }
                }
                gizmo3.ProcessInput(ev);
                Event.current.Use();
            }
            else if (gizmo4 != null)
            {
                List <FloatMenuOption> list4 = new List <FloatMenuOption>();
                foreach (FloatMenuOption rightClickFloatMenuOption in gizmo4.RightClickFloatMenuOptions)
                {
                    list4.Add(rightClickFloatMenuOption);
                }
                List <Gizmo> list5 = FindMatchingGroup(gizmo4);
                Action       prevAction;
                Action       localOptionAction;
                for (int num4 = 0; num4 < list5.Count; num4++)
                {
                    Gizmo gizmo7 = list5[num4];
                    if (gizmo7 != gizmo4 && !gizmo7.disabled && gizmo4.InheritFloatMenuInteractionsFrom(gizmo7))
                    {
                        foreach (FloatMenuOption rightClickFloatMenuOption2 in gizmo7.RightClickFloatMenuOptions)
                        {
                            FloatMenuOption floatMenuOption = null;
                            for (int num5 = 0; num5 < list4.Count; num5++)
                            {
                                if (list4[num5].Label == rightClickFloatMenuOption2.Label)
                                {
                                    floatMenuOption = list4[num5];
                                    break;
                                }
                            }
                            if (floatMenuOption == null)
                            {
                                list4.Add(rightClickFloatMenuOption2);
                            }
                            else if (!rightClickFloatMenuOption2.Disabled)
                            {
                                if (!floatMenuOption.Disabled)
                                {
                                    prevAction             = floatMenuOption.action;
                                    localOptionAction      = rightClickFloatMenuOption2.action;
                                    floatMenuOption.action = delegate
                                    {
                                        prevAction();
                                        localOptionAction();
                                    };
                                }
                                else if (floatMenuOption.Disabled)
                                {
                                    list4[list4.IndexOf(floatMenuOption)] = rightClickFloatMenuOption2;
                                }
                            }
                        }
                    }
                }
                Event.current.Use();
                if (list4.Any())
                {
                    Find.WindowStack.Add(new FloatMenu(list4));
                }
            }
            for (int num6 = 0; num6 < gizmoGroups.Count; num6++)
            {
                gizmoGroups[num6].Clear();
                SimplePool <List <Gizmo> > .Return(gizmoGroups[num6]);
            }
            gizmoGroups.Clear();
            firstGizmos.Clear();
            tmpAllGizmos.Clear();
            List <Gizmo> FindMatchingGroup(Gizmo toMatch)
            {
                for (int num7 = 0; num7 < gizmoGroups.Count; num7++)
                {
                    if (gizmoGroups[num7].Contains(toMatch))
                    {
                        return(gizmoGroups[num7]);
                    }
                }
                return(null);
            }
        }
        public static void DrawGizmoGrid(IEnumerable <Gizmo> gizmos, float startX, out Gizmo mouseoverGizmo)
        {
            if (Event.current.type == EventType.Layout)
            {
                mouseoverGizmo = null;
                return;
            }
            tmpAllGizmos.Clear();
            tmpAllGizmos.AddRange(gizmos);
            tmpAllGizmos.SortStable(SortByOrder);
            gizmoGroups.Clear();
            for (int i = 0; i < tmpAllGizmos.Count; i++)
            {
                Gizmo gizmo = tmpAllGizmos[i];
                bool  flag  = false;
                for (int j = 0; j < gizmoGroups.Count; j++)
                {
                    if (gizmoGroups[j][0].GroupsWith(gizmo))
                    {
                        flag = true;
                        gizmoGroups[j].Add(gizmo);
                        gizmoGroups[j][0].MergeWith(gizmo);
                        break;
                    }
                }
                if (!flag)
                {
                    List <Gizmo> list = SimplePool <List <Gizmo> > .Get();

                    list.Add(gizmo);
                    gizmoGroups.Add(list);
                }
            }
            firstGizmos.Clear();
            shrinkableCommands.Clear();
            float   num      = UI.screenWidth - 147;
            Vector2 vector   = new Vector2(startX, (float)(UI.screenHeight - 35) - GizmoSpacing.y - 75f);
            float   maxWidth = num - startX;
            int     num2     = 0;

            for (int k = 0; k < gizmoGroups.Count; k++)
            {
                List <Gizmo> list2  = gizmoGroups[k];
                Gizmo        gizmo2 = null;
                for (int l = 0; l < list2.Count; l++)
                {
                    if (!list2[l].disabled)
                    {
                        gizmo2 = list2[l];
                        break;
                    }
                }
                if (gizmo2 == null)
                {
                    gizmo2 = list2.FirstOrDefault();
                }
                else
                {
                    Command_Toggle command_Toggle = gizmo2 as Command_Toggle;
                    if (command_Toggle != null)
                    {
                        if (!command_Toggle.activateIfAmbiguous && !command_Toggle.isActive())
                        {
                            for (int m = 0; m < list2.Count; m++)
                            {
                                Command_Toggle command_Toggle2 = list2[m] as Command_Toggle;
                                if (command_Toggle2 != null && !command_Toggle2.disabled && command_Toggle2.isActive())
                                {
                                    gizmo2 = list2[m];
                                    break;
                                }
                            }
                        }
                        if (command_Toggle.activateIfAmbiguous && command_Toggle.isActive())
                        {
                            for (int n = 0; n < list2.Count; n++)
                            {
                                Command_Toggle command_Toggle3 = list2[n] as Command_Toggle;
                                if (command_Toggle3 != null && !command_Toggle3.disabled && !command_Toggle3.isActive())
                                {
                                    gizmo2 = list2[n];
                                    break;
                                }
                            }
                        }
                    }
                }
                if (gizmo2 != null)
                {
                    Command command;
                    if ((command = gizmo2 as Command) != null && command.shrinkable && command.Visible)
                    {
                        shrinkableCommands.Add(command);
                    }
                    if (vector.x + gizmo2.GetWidth(maxWidth) > num)
                    {
                        vector.x  = startX;
                        vector.y -= 75f + GizmoSpacing.x;
                        num2++;
                    }
                    vector.x += gizmo2.GetWidth(maxWidth) + GizmoSpacing.x;
                    firstGizmos.Add(gizmo2);
                }
            }
            if (num2 > 1 && shrinkableCommands.Count > 1)
            {
                for (int num3 = 0; num3 < shrinkableCommands.Count; num3++)
                {
                    firstGizmos.Remove(shrinkableCommands[num3]);
                }
            }
            else
            {
                shrinkableCommands.Clear();
            }
            drawnHotKeys.Clear();
            Text.Font = GameFont.Tiny;
            Vector2 vector2 = new Vector2(startX, (float)(UI.screenHeight - 35) - GizmoSpacing.y - 75f);

            mouseoverGizmo = null;
            Gizmo interactedGiz   = null;
            Event interactedEvent = null;
            Gizmo floatMenuGiz    = null;

            for (int num4 = 0; num4 < firstGizmos.Count; num4++)
            {
                Gizmo gizmo3 = firstGizmos[num4];
                if (gizmo3.Visible)
                {
                    if (vector2.x + gizmo3.GetWidth(maxWidth) > num)
                    {
                        vector2.x  = startX;
                        vector2.y -= 75f + GizmoSpacing.x;
                    }
                    heightDrawnFrame = Time.frameCount;
                    heightDrawn      = (float)UI.screenHeight - vector2.y;
                    GizmoResult result2 = gizmo3.GizmoOnGUI(vector2, maxWidth);
                    ProcessGizmoState(gizmo3, result2, ref mouseoverGizmo);
                    GenUI.AbsorbClicksInRect(new Rect(vector2.x, vector2.y, gizmo3.GetWidth(maxWidth), 75f + GizmoSpacing.y).ContractedBy(-12f));
                    vector2.x += gizmo3.GetWidth(maxWidth) + GizmoSpacing.x;
                }
            }
            float x    = vector2.x;
            int   num5 = 0;

            for (int num6 = 0; num6 < shrinkableCommands.Count; num6++)
            {
                Command command2      = shrinkableCommands[num6];
                float   getShrunkSize = command2.GetShrunkSize;
                if (vector2.x + getShrunkSize > num)
                {
                    num5++;
                    if (num5 > 1)
                    {
                        x = startX;
                    }
                    vector2.x  = x;
                    vector2.y -= getShrunkSize + 3f;
                }
                Vector2 topLeft = vector2;
                topLeft.y       += getShrunkSize + 3f;
                heightDrawnFrame = Time.frameCount;
                heightDrawn      = Mathf.Min(heightDrawn, (float)UI.screenHeight - topLeft.y);
                GizmoResult result3 = command2.GizmoOnGUIShrunk(topLeft, getShrunkSize);
                ProcessGizmoState(command2, result3, ref mouseoverGizmo);
                GenUI.AbsorbClicksInRect(new Rect(topLeft.x, topLeft.y, getShrunkSize, getShrunkSize + 3f).ExpandedBy(3f));
                vector2.x += getShrunkSize + 3f;
            }
            if (interactedGiz != null)
            {
                List <Gizmo> list3 = FindMatchingGroup(interactedGiz);
                for (int num7 = 0; num7 < list3.Count; num7++)
                {
                    Gizmo gizmo4 = list3[num7];
                    if (gizmo4 != interactedGiz && !gizmo4.disabled && interactedGiz.InheritInteractionsFrom(gizmo4))
                    {
                        gizmo4.ProcessInput(interactedEvent);
                    }
                }
                interactedGiz.ProcessInput(interactedEvent);
                Event.current.Use();
            }
            else if (floatMenuGiz != null)
            {
                List <FloatMenuOption> list4 = new List <FloatMenuOption>();
                foreach (FloatMenuOption rightClickFloatMenuOption in floatMenuGiz.RightClickFloatMenuOptions)
                {
                    list4.Add(rightClickFloatMenuOption);
                }
                List <Gizmo> list5 = FindMatchingGroup(floatMenuGiz);
                for (int num8 = 0; num8 < list5.Count; num8++)
                {
                    Gizmo gizmo5 = list5[num8];
                    if (gizmo5 == floatMenuGiz || gizmo5.disabled || !floatMenuGiz.InheritFloatMenuInteractionsFrom(gizmo5))
                    {
                        continue;
                    }
                    foreach (FloatMenuOption rightClickFloatMenuOption2 in gizmo5.RightClickFloatMenuOptions)
                    {
                        FloatMenuOption floatMenuOption = null;
                        for (int num9 = 0; num9 < list4.Count; num9++)
                        {
                            if (list4[num9].Label == rightClickFloatMenuOption2.Label)
                            {
                                floatMenuOption = list4[num9];
                                break;
                            }
                        }
                        if (floatMenuOption == null)
                        {
                            list4.Add(rightClickFloatMenuOption2);
                        }
                        else
                        {
                            if (rightClickFloatMenuOption2.Disabled)
                            {
                                continue;
                            }
                            if (!floatMenuOption.Disabled)
                            {
                                Action prevAction        = floatMenuOption.action;
                                Action localOptionAction = rightClickFloatMenuOption2.action;
                                floatMenuOption.action = delegate
                                {
                                    prevAction();
                                    localOptionAction();
                                };
                            }
                            else if (floatMenuOption.Disabled)
                            {
                                list4[list4.IndexOf(floatMenuOption)] = rightClickFloatMenuOption2;
                            }
                        }
                    }
                }
                Event.current.Use();
                if (list4.Any())
                {
                    Find.WindowStack.Add(new FloatMenu(list4));
                }
            }
            for (int num10 = 0; num10 < gizmoGroups.Count; num10++)
            {
                gizmoGroups[num10].Clear();
                SimplePool <List <Gizmo> > .Return(gizmoGroups[num10]);
            }
            gizmoGroups.Clear();
            firstGizmos.Clear();
            tmpAllGizmos.Clear();