public void Notify_PermitUsed(RoyalTitlePermitDef permitDef)
 {
     if (!permitLastUsedTick.ContainsKey(permitDef))
     {
         permitLastUsedTick.Add(permitDef, GenTicks.TicksGame);
     }
 }
 public int GetPermitLastUsedTick(RoyalTitlePermitDef permitDef)
 {
     if (!permitLastUsedTick.ContainsKey(permitDef))
     {
         return(-1);
     }
     return(permitLastUsedTick[permitDef]);
 }
        public bool PermitOnCooldown(RoyalTitlePermitDef permitDef)
        {
            int num = GetPermitLastUsedTick(permitDef);

            if (num != -1)
            {
                return(GenTicks.TicksGame < num + permitDef.CooldownTicks);
            }
            return(false);
        }
示例#4
0
 private static bool CanDrawPermit(RoyalTitlePermitDef permit)
 {
     if (permit.permitPointCost > 0)
     {
         if (permit.faction != null)
         {
             return(permit.faction == selectedFaction.def);
         }
         return(true);
     }
     return(false);
 }
        public bool HasPermit(RoyalTitlePermitDef permit, Faction faction)
        {
            RoyalTitleDef currentTitle = GetCurrentTitle(faction);

            if (currentTitle != null)
            {
                if (currentTitle.permits != null)
                {
                    return(currentTitle.permits.Contains(permit));
                }
                return(false);
            }
            return(false);
        }
示例#6
0
        private static bool PermitUnlocked(RoyalTitlePermitDef permit, Pawn pawn)
        {
            if (pawn.royalty.HasPermit(permit, selectedFaction))
            {
                return(true);
            }
            List <FactionPermit> allFactionPermits = pawn.royalty.AllFactionPermits;

            for (int i = 0; i < allFactionPermits.Count; i++)
            {
                if (allFactionPermits[i].Permit.prerequisite == permit && allFactionPermits[i].Faction == selectedFaction)
                {
                    return(true);
                }
            }
            return(false);
        }
示例#7
0
        private static void DrawLines()
        {
            Vector2 start = default(Vector2);
            Vector2 end   = default(Vector2);
            List <RoyalTitlePermitDef> allDefsListForReading = DefDatabase <RoyalTitlePermitDef> .AllDefsListForReading;

            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < allDefsListForReading.Count; j++)
                {
                    RoyalTitlePermitDef royalTitlePermitDef = allDefsListForReading[j];
                    if (!CanDrawPermit(royalTitlePermitDef))
                    {
                        continue;
                    }
                    Vector2 vector = DrawPosition(royalTitlePermitDef);
                    start.x = vector.x;
                    start.y = vector.y + 25f;
                    RoyalTitlePermitDef prerequisite = royalTitlePermitDef.prerequisite;
                    if (prerequisite != null)
                    {
                        Vector2 vector2 = DrawPosition(prerequisite);
                        end.x = vector2.x + 200f;
                        end.y = vector2.y + 25f;
                        if ((i == 1 && selectedPermit == royalTitlePermitDef) || selectedPermit == prerequisite)
                        {
                            Widgets.DrawLine(start, end, TexUI.HighlightLineResearchColor, 4f);
                        }
                        else if (i == 0)
                        {
                            Widgets.DrawLine(start, end, TexUI.DefaultLineResearchColor, 2f);
                        }
                    }
                }
            }
        }
示例#8
0
        public static void DrawRecordsCard(Rect rect, Pawn pawn)
        {
            if (!ModLister.RoyaltyInstalled)
            {
                Log.ErrorOnce("Permits are a Royalty-specific game system. If you want to use this code please check ModLister.RoyaltyInstalled before calling it. See rules on the Ludeon forum for more info.", 43244);
                return;
            }
            rect.yMax -= 4f;
            if (ShowSwitchFactionButton)
            {
                Rect rect2 = new Rect(rect.x, rect.y, 32f, 32f);
                if (Widgets.ButtonImage(rect2, SwitchFactionIcon))
                {
                    List <FloatMenuOption> list = new List <FloatMenuOption>();
                    foreach (Faction item in Find.FactionManager.AllFactionsVisibleInViewOrder)
                    {
                        if (!item.IsPlayer && !item.def.permanentEnemy)
                        {
                            Faction localFaction = item;
                            list.Add(new FloatMenuOption(localFaction.Name, delegate
                            {
                                selectedFaction = localFaction;
                                selectedPermit  = null;
                            }, localFaction.def.FactionIcon, localFaction.Color));
                        }
                    }
                    Find.WindowStack.Add(new FloatMenu(list));
                }
                TooltipHandler.TipRegion(rect2, "SwitchFaction_Desc".Translate());
            }
            if (selectedFaction.def.HasRoyalTitles)
            {
                string label = "ReturnAllPermits".Translate();
                Rect   rect3 = new Rect(rect.xMax - 180f, rect.y - 4f, 180f, 51f);
                int    num   = TotalReturnPermitsCost(pawn);
                if (Widgets.ButtonText(rect3, label))
                {
                    if (!pawn.royalty.PermitsFromFaction(selectedFaction).Any())
                    {
                        Messages.Message("NoPermitsToReturn".Translate(pawn.Named("PAWN")), new LookTargets(pawn), MessageTypeDefOf.RejectInput, historical: false);
                    }
                    else if (pawn.royalty.GetFavor(selectedFaction) < num)
                    {
                        Messages.Message("NotEnoughFavor".Translate(num.Named("FAVORCOST"), selectedFaction.def.royalFavorLabel.Named("FAVOR"), pawn.Named("PAWN"), pawn.royalty.GetFavor(selectedFaction).Named("CURFAVOR")), MessageTypeDefOf.RejectInput);
                    }
                    else
                    {
                        string str = "ReturnAllPermits_Confirm".Translate(8.Named("BASEFAVORCOST"), num.Named("FAVORCOST"), selectedFaction.def.royalFavorLabel.Named("FAVOR"), selectedFaction.Named("FACTION"));
                        Find.WindowStack.Add(Dialog_MessageBox.CreateConfirmation(str, delegate
                        {
                            pawn.royalty.RefundPermits(8, selectedFaction);
                        }, destructive: true));
                    }
                }
                TooltipHandler.TipRegion(rect3, "ReturnAllPermits_Desc".Translate(8.Named("BASEFAVORCOST"), num.Named("FAVORCOST"), selectedFaction.def.royalFavorLabel.Named("FAVOR")));
            }
            RoyalTitleDef currentTitle = pawn.royalty.GetCurrentTitle(selectedFaction);
            Rect          rect4        = new Rect(rect.xMax - 360f - 4f, rect.y - 4f, 360f, 55f);
            string        text         = (string)("CurrentTitle".Translate() + ": " + ((currentTitle != null) ? currentTitle.GetLabelFor(pawn).CapitalizeFirst() : ((string)"None".Translate())) + "\n" + "UnusedPermits".Translate() + ": ") + pawn.royalty.GetPermitPoints(selectedFaction);

            if (!selectedFaction.def.royalFavorLabel.NullOrEmpty())
            {
                text = text + "\n" + selectedFaction.def.royalFavorLabel.CapitalizeFirst() + ": " + pawn.royalty.GetFavor(selectedFaction);
            }
            Widgets.Label(rect4, text);
            rect.yMin += 55f;
            Rect rect5 = new Rect(rect);

            rect5.width *= 0.33f;
            DoLeftRect(rect5, pawn);
            Rect rect6 = new Rect(rect);

            rect6.xMin = rect5.xMax + 10f;
            DoRightRect(rect6, pawn);
        }
示例#9
0
        private static Vector2 DrawPosition(RoyalTitlePermitDef permit)
        {
            Vector2 a = new Vector2(permit.uiPosition.x * 200f, permit.uiPosition.y * 50f);

            return(a + a * PermitOptionSpacing);
        }
示例#10
0
 private static bool PermitAvailable(RoyalTitlePermitDef permit, Pawn pawn)
 {
     return(permit.AvailableForPawn(pawn, selectedFaction));
 }
示例#11
0
        private static void DoRightRect(Rect rect, Pawn pawn)
        {
            Widgets.DrawMenuSection(rect);
            if (selectedFaction == null)
            {
                return;
            }
            List <RoyalTitlePermitDef> allDefsListForReading = DefDatabase <RoyalTitlePermitDef> .AllDefsListForReading;
            Rect outRect = rect.ContractedBy(10f);
            Rect rect2   = default(Rect);

            for (int i = 0; i < allDefsListForReading.Count; i++)
            {
                RoyalTitlePermitDef permit = allDefsListForReading[i];
                if (CanDrawPermit(permit))
                {
                    rect2.width  = Mathf.Max(rect2.width, DrawPosition(permit).x + 200f + 26f);
                    rect2.height = Mathf.Max(rect2.height, DrawPosition(permit).y + 50f + 26f);
                }
            }
            Widgets.BeginScrollView(outRect, ref rightScrollPosition, rect2);
            GUI.BeginGroup(rect2.ContractedBy(10f));
            DrawLines();
            for (int j = 0; j < allDefsListForReading.Count; j++)
            {
                RoyalTitlePermitDef royalTitlePermitDef = allDefsListForReading[j];
                if (CanDrawPermit(royalTitlePermitDef))
                {
                    Vector2 vector  = DrawPosition(royalTitlePermitDef);
                    Rect    rect3   = new Rect(vector.x, vector.y, 200f, 50f);
                    Color   color   = Widgets.NormalOptionColor;
                    Color   bgColor = (PermitUnlocked(royalTitlePermitDef, pawn) ? TexUI.FinishedResearchColor : TexUI.AvailResearchColor);
                    Color   borderColor;
                    if (selectedPermit == royalTitlePermitDef)
                    {
                        borderColor = TexUI.HighlightBorderResearchColor;
                        bgColor    += TexUI.HighlightBgResearchColor;
                    }
                    else
                    {
                        borderColor = TexUI.DefaultBorderResearchColor;
                    }
                    if (!royalTitlePermitDef.AvailableForPawn(pawn, selectedFaction) && !PermitUnlocked(royalTitlePermitDef, pawn))
                    {
                        color = Color.red;
                    }
                    if (Widgets.CustomButtonText(ref rect3, string.Empty, bgColor, color, borderColor))
                    {
                        SoundDefOf.Click.PlayOneShotOnCamera();
                        selectedPermit = royalTitlePermitDef;
                    }
                    TextAnchor anchor = Text.Anchor;
                    Color      color2 = GUI.color;
                    GUI.color   = color;
                    Text.Anchor = TextAnchor.MiddleCenter;
                    Widgets.Label(rect3, royalTitlePermitDef.LabelCap);
                    GUI.color   = color2;
                    Text.Anchor = anchor;
                }
            }
            GUI.EndGroup();
            Widgets.EndScrollView();
        }
 public FactionPermit(Faction faction, RoyalTitleDef title, RoyalTitlePermitDef permit)
 {
     this.title   = title;
     this.faction = faction;
     this.permit  = permit;
 }