private bool Operable(Hediff target, RecipeDef recipe)
        {
            int hediffLevelOffset = recipe.hediffLevelOffset;

            if (hediffLevelOffset == 0)
            {
                return(false);
            }
            Hediff_ImplantWithLevel hediff_ImplantWithLevel = target as Hediff_ImplantWithLevel;

            if (hediff_ImplantWithLevel == null)
            {
                return(false);
            }
            int level = hediff_ImplantWithLevel.level;

            if (hediff_ImplantWithLevel.def == recipe.changesHediffLevel)
            {
                if (hediffLevelOffset <= 0)
                {
                    return(level > 0);
                }
                return((float)level < hediff_ImplantWithLevel.def.maxSeverity);
            }
            return(false);
        }
        public override bool CanBeUsedBy(Pawn p, out string failReason)
        {
            if ((!p.IsFreeColonist || p.HasExtraHomeFaction()) && !Props.allowNonColonists)
            {
                failReason = "InstallImplantNotAllowedForNonColonists".Translate();
                return(false);
            }
            if (p.RaceProps.body.GetPartsWithDef(Props.bodyPart).FirstOrFallback() == null)
            {
                failReason = "InstallImplantNoBodyPart".Translate() + ": " + Props.bodyPart.LabelShort;
                return(false);
            }
            Hediff existingImplant = GetExistingImplant(p);

            if (existingImplant != null)
            {
                if (!Props.canUpgrade)
                {
                    failReason = "InstallImplantAlreadyInstalled".Translate();
                    return(false);
                }
                Hediff_ImplantWithLevel hediff_ImplantWithLevel = (Hediff_ImplantWithLevel)existingImplant;
                if ((float)hediff_ImplantWithLevel.level >= hediff_ImplantWithLevel.def.maxSeverity)
                {
                    failReason = "InstallImplantAlreadyMaxLevel".Translate();
                    return(false);
                }
            }
            failReason = null;
            return(true);
        }
Example #3
0
        public static TaggedString CheckForViolations(Pawn pawn, HediffDef hediff, int levelOffset)
        {
            if (levelOffset < 0)
            {
                return("");
            }
            if (pawn.Faction != Faction.OfPlayer || !hediff.HasComp(typeof(HediffComp_RoyalImplant)))
            {
                return("");
            }
            Hediff_ImplantWithLevel hediff_ImplantWithLevel = (Hediff_ImplantWithLevel)pawn.health.hediffSet.hediffs.FirstOrDefault((Hediff h) => h.def == hediff);
            int num = (levelOffset != 0 && hediff_ImplantWithLevel != null) ? (hediff_ImplantWithLevel.level + levelOffset) : 0;

            foreach (Faction item in Find.FactionManager.AllFactionsListForReading)
            {
                if (pawn.Faction != null && !item.def.hidden && !item.HostileTo(Faction.OfPlayer) && ThingRequiringRoyalPermissionUtility.IsViolatingRulesOf(hediff, pawn, item, num))
                {
                    RoyalTitleDef minTitleForImplant = item.GetMinTitleForImplant(hediff, num);
                    HediffCompProperties_RoyalImplant hediffCompProperties_RoyalImplant = hediff.CompProps <HediffCompProperties_RoyalImplant>();
                    string       arg          = hediff.label + ((num == 0) ? "" : (" (" + num + "x)"));
                    TaggedString taggedString = hediffCompProperties_RoyalImplant.violationTriggerDescriptionKey.Translate(pawn.Named("PAWN"));
                    TaggedString t            = "RoyalImplantIllegalUseWarning".Translate(pawn.Named("PAWN"), arg.Named("IMPLANT"), item.Named("FACTION"), minTitleForImplant.GetLabelCapFor(pawn).Named("TITLE"), taggedString.Named("VIOLATIONTRIGGER"));
                    if (levelOffset != 0)
                    {
                        return(t + ("\n\n" + "RoyalImplantUpgradeConfirmation".Translate()));
                    }
                    return(t + ("\n\n" + "RoyalImplantInstallConfirmation".Translate()));
                }
            }
            return("");
        }
Example #4
0
        protected override string FloatMenuOptionLabel(Pawn pawn)
        {
            CompUseEffect_InstallImplant compUseEffect_InstallImplant = parent.TryGetComp <CompUseEffect_InstallImplant>();

            if (compUseEffect_InstallImplant != null)
            {
                Hediff_ImplantWithLevel hediff_ImplantWithLevel = compUseEffect_InstallImplant.GetExistingImplant(pawn) as Hediff_ImplantWithLevel;
                if (hediff_ImplantWithLevel != null && compUseEffect_InstallImplant.Props.canUpgrade && (float)hediff_ImplantWithLevel.level < hediff_ImplantWithLevel.def.maxSeverity)
                {
                    return("UpgradeImplant".Translate(hediff_ImplantWithLevel.def.label, hediff_ImplantWithLevel.level + 1));
                }
            }
            return(base.FloatMenuOptionLabel(pawn));
        }
        public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill)
        {
            if (billDoer != null)
            {
                TaleRecorder.RecordTale(TaleDefOf.DidSurgery, billDoer, pawn);
            }
            Hediff_ImplantWithLevel hediff_ImplantWithLevel = (Hediff_ImplantWithLevel)pawn.health.hediffSet.hediffs.FirstOrDefault((Hediff h) => Operable(h, recipe) && h.Part == part);

            if (hediff_ImplantWithLevel != null)
            {
                if (IsViolationOnPawn(pawn, part, Faction.OfPlayer))
                {
                    ReportViolation(pawn, billDoer, pawn.FactionOrExtraMiniOrHomeFaction, -70, "GoodwillChangedReason_DowngradedImplant".Translate(hediff_ImplantWithLevel.Label));
                }
                hediff_ImplantWithLevel.ChangeLevel(recipe.hediffLevelOffset);
            }
        }
Example #6
0
        public override void TryStartUseJob(Pawn pawn, LocalTargetInfo extraTarget)
        {
            CompUseEffect_InstallImplant useEffectImplant        = parent.TryGetComp <CompUseEffect_InstallImplant>();
            Hediff_ImplantWithLevel      hediff_ImplantWithLevel = useEffectImplant.GetExistingImplant(pawn) as Hediff_ImplantWithLevel;
            TaggedString text = CompRoyalImplant.CheckForViolations(pawn, useEffectImplant.Props.hediffDef, (hediff_ImplantWithLevel != null && useEffectImplant.Props.canUpgrade) ? 1 : 0);

            if (!text.NullOrEmpty())
            {
                Find.WindowStack.Add(new Dialog_MessageBox(text, "Yes".Translate(), delegate
                {
                    UseJobInternal(pawn, extraTarget, useEffectImplant.Props.hediffDef);
                }, "No".Translate()));
            }
            else
            {
                UseJobInternal(pawn, extraTarget, useEffectImplant.Props.hediffDef);
            }
        }
Example #7
0
        private bool Operable(Hediff target, RecipeDef recipe)
        {
            Hediff_ImplantWithLevel hediff_ImplantWithLevel = target as Hediff_ImplantWithLevel;

            if (hediff_ImplantWithLevel == null)
            {
                return(false);
            }
            int level = hediff_ImplantWithLevel.level;

            if (hediff_ImplantWithLevel.def != recipe.changesHediffLevel)
            {
                return(false);
            }
            else
            {
                return(level > 0);
            }
            //return (float)level < hediff_ImplantWithLevel.def.maxSeverity;
        }