public virtual bool CanSign(Alliance alliance, AllianceAgreementDef allianceAgreementDef, Pawn speaker, out string reason)
        {
            reason = string.Empty;

            if (alliance.AgreementActive(allianceAgreementDef))
            {
                reason = "Alliance_CanSignAgreement_AlreadyActive".Translate();
                return(false);
            }

            if (!allianceAgreementDef.TargetGoals.Contains(alliance.AllianceGoalDef))
            {
                reason = "Alliance_CanSignAgreement_NoTargetGoal".Translate();
                return(false);
            }

            if (allianceAgreementDef.UseAgreementsSlot && alliance.AllianceAgreements.Count == alliance.AgreementsSlots)
            {
                reason = "Alliance_CanSignAgreement_NoSlots".Translate(alliance.AgreementsSlots);
                return(false);
            }

            var conditions = allianceAgreementDef.Conditions;

            if (conditions != null)
            {
                foreach (var condition in conditions)
                {
                    if (!condition.Avaliable(alliance))
                    {
                        reason = condition.Reason;
                        return(false);
                    }
                }
            }

            if (alliance.Factions.Count < allianceAgreementDef.MinMembersRequired)
            {
                reason = "Alliance_CanSignAgreement_MinMembersRequired".Translate(allianceAgreementDef.MinMembersRequired);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private void DrawAgreements(Rect rect)
        {
            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.MiddleCenter;
            Widgets.Label(new Rect(rect.x, rect.y, rect.width, 28), "AllianceManager_ActiveAgreements".Translate());
            Text.Anchor = TextAnchor.UpperLeft;
            Text.Font   = GameFont.Small;

            float x                  = 0;
            float width              = rect.width - 20;
            Rect  agreementListRect  = new Rect(rect.x, rect.y + 33, width, 160);
            Rect  scrollVertRectFact = new Rect(0, 0, DefDatabase <AllianceAgreementDef> .DefCount * 140, 135);
            Rect  agreementRect      = new Rect(0, 0, 130, 145);

            Widgets.BeginScrollView(agreementListRect, ref agreementsSlider, scrollVertRectFact, true);
            foreach (var agreement in from def in DefDatabase <AllianceAgreementDef> .AllDefsListForReading orderby def.AgreementCategory, alliance.AgreementActive(def) select def)
            {
                DrawAgreement(agreementRect, ref x, agreement);
            }
            Widgets.EndScrollView();
            GUIUtils.DrawLineHorizontal(rect.x, rect.y + 195, rect.width, MenuSectionBGBorderColor);
        }