コード例 #1
0
        private static string ReadHediffGiver(HediffGiver hediffGiver)
        {
            if (hediffGiver is HediffGiver_Random hg_r)
            {
                return("Stat_MTB_Hediff".Translate(hg_r.hediff.Named("HEDIFF")) + ": " + ToStringDaysToPeriod(hg_r.mtbDays));
            }
            else if (hediffGiver is HediffGiver_RandomDrugEffect hg_rde)
            {
                return("Stat_MTB_Hediff".Translate(hg_rde.hediff.Named("HEDIFF")) + ": " + ToStringDaysToPeriod(hg_rde.baseMtbDays));
            }

            return("Stat_CanCause_Hediff".Translate(hediffGiver.hediff.Named("HEDIFF")));
        }
コード例 #2
0
        static bool Prefix(HediffGiver __instance, ref bool __result, Pawn pawn)
        {
            // if the instance is of gendered type, check pawn gender before applying.
            Debug("HediffGiver.TryApply(" + __instance.hediff.defName + ", " + pawn.NameStringShort + " [" +
                  pawn.gender + "])");
            HediffGiver_Birthday_Gender gendered = __instance as HediffGiver_Birthday_Gender;

            if (gendered != null && gendered.gender != pawn.gender)
            {
                __result = false; // return false from TryApply
                return(false);    // stop further execution
            }

            Debug("OK", 1);
            return(true); // allow further execution of vanilla HediffGiver.TryApply()
        }
コード例 #3
0
        protected void InitializeHediffGiverInjuries(OptionsHealth options, HediffGiver giver)
        {
            if (giver == null)
            {
                Logger.Warning("Could not add injury/health condition because a HediffGiver was null");
                return;
            }
            if (giver.hediff == null)
            {
                Logger.Warning("Could not add injury/health condition because the hediff for " + giver.GetType().FullName + " was null");
                return;
            }
            InjuryOption option = new InjuryOption();

            option.HediffDef = giver.hediff;
            option.Label     = giver.hediff.LabelCap;
            option.Giver     = giver;
            if (giver.partsToAffect == null)
            {
                option.WholeBody = true;
            }
            if (giver.canAffectAnyLivePart)
            {
                option.WholeBody = false;
            }
            if (giver.partsToAffect != null && !giver.canAffectAnyLivePart)
            {
                List <BodyPartDef> validParts = new List <BodyPartDef>();
                foreach (var def in giver.partsToAffect)
                {
                    List <UniqueBodyPart> parts = options.FindBodyPartsForDef(def);
                    if (parts != null)
                    {
                        validParts.Add(def);
                    }
                }
                if (validParts.Count == 0)
                {
                    return;
                }
                else
                {
                    option.ValidParts = validParts;
                }
            }
            options.AddInjury(option);
        }
コード例 #4
0
        static bool Prefix(HediffGiver __instance, ref bool __result, Pawn pawn)
        {
            // if the instance is of gendered type, check pawn gender before applying.
            // NOTE: This debug call can give nullref errors in certain cases (what cases?). Disabled for now.
            // Debug( "HediffGiver.TryApply(" + __instance.hediff.defName + ", " + pawn.Name.ToStringShort + " [" +
            //         pawn.gender + "])" );
            HediffGiver_Birthday_Gender gendered = __instance as HediffGiver_Birthday_Gender;

            if (gendered != null && gendered.gender != pawn.gender)
            {
                __result = false; // return false from TryApply
                return(false);    // stop further execution
            }

            Debug("OK", 1);
            return(true); // allow further execution of vanilla HediffGiver.TryApply()
        }
コード例 #5
0
        public override void Execute(int amount, string boughtBy)
        {
            //HediffDef heDiffDef = DefDatabase<HediffDef>.GetNamed(thingDef.defName);
            HediffGiver heDiffGiver = PawnKindDefOf.Colonist.RaceProps.hediffGiverSets.SelectMany((HediffGiverSetDef set) => set.hediffGivers).Where((HediffGiver
                                                                                                                                                      hediffGiver) => hediffGiver.hediff.Equals(this.thingDef)).First();

            String notificationMessage;

            // I hope no viewer uses RC with the name "Poll"
            if (boughtBy == "Poll")
            {
                notificationMessage = $"<color=#9147ff>By popular opinion</color>, your channel has triggered {defLabel} on random colonists";
            }
            else
            {
                notificationMessage = $"<color=#9147ff>{boughtBy}</color> purchased {defLabel} for a random colonist";
            }

            var colonists = Find.ColonistBar.GetColonistsInOrder().Where(colonist => !colonist.Dead);

            var randomColonists = colonists.InRandomOrder().Take(amount);

            foreach (Pawn colonist in randomColonists)
            {
                heDiffGiver.TryApply(colonist);
            }

            string additionalMessage = "";

            if (amount == 1)
            {
                additionalMessage = $"{randomColonists.First().Name.ToStringFull} has been given {heDiffGiver.hediff.label}";
            }
            else
            {
                IEnumerable <String> colonistNames = randomColonists.Select((Pawn colonist) => colonist.Name.ToStringFull);
                additionalMessage = $"{String.Join(", ", colonistNames)} have been given {heDiffGiver.hediff.label}";
            }

            AlertManager.BadEventNotification($"{notificationMessage}\n\n{additionalMessage}");
        }
コード例 #6
0
        protected void InitializeHediffGiverInjuries(OptionsHealth options, HediffGiver giver)
        {
            InjuryOption option = new InjuryOption();

            option.HediffDef = giver.hediff;
            option.Label     = giver.hediff.LabelCap;
            option.Giver     = giver;
            if (giver.partsToAffect == null)
            {
                option.WholeBody = true;
            }
            if (giver.canAffectAnyLivePart)
            {
                option.WholeBody = false;
            }
            if (giver.partsToAffect != null && !giver.canAffectAnyLivePart)
            {
                List <BodyPartDef> validParts = new List <BodyPartDef>();
                foreach (var def in giver.partsToAffect)
                {
                    List <UniqueBodyPart> parts = options.FindBodyPartsForDef(def);
                    if (parts != null)
                    {
                        validParts.Add(def);
                    }
                }
                if (validParts.Count == 0)
                {
                    return;
                }
                else
                {
                    option.ValidParts = validParts;
                }
            }
            options.AddInjury(option);
        }
コード例 #7
0
 private static IAction CreateActionFromDef(HediffGiver hediffGiver)
 {
     return(new HeDiffAction(hediffGiver.hediff));
 }