Example #1
0
        public static void Postfix(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result, StatRequest req)
        {
            // Tool def
            if (req.Thing == null && __instance.IsSurvivalTool(out SurvivalToolProperties tProps))
            {
                foreach (StatModifier modifier in tProps.baseWorkStatFactors)
                {
                    __result = __result.AddItem(new StatDrawEntry(ST_StatCategoryDefOf.SurvivalTool,
                                                                  modifier.stat.LabelCap,
                                                                  modifier.value.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor),
                                                                  reportText: modifier.stat.description,
                                                                  displayPriorityWithinCategory: 99999,
                                                                  //overrideReportTitle: SurvivalToolUtility.GetSurvivalToolOverrideReportText(this, modifier.stat),
                                                                  hyperlinks: null,
                                                                  forceUnfinalizedMode: false
                                                                  ));
                }
            }

            // Stuff
            if (__instance.IsStuff && __instance.GetModExtension <StuffPropsTool>() is StuffPropsTool sPropsTool)
            {
                foreach (StatModifier modifier in sPropsTool.toolStatFactors)
                {
                    __result = __result.AddItem(new StatDrawEntry(ST_StatCategoryDefOf.SurvivalToolMaterial,
                                                                  modifier.stat.LabelCap,
                                                                  modifier.value.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Factor),
                                                                  reportText: modifier.stat.description,
                                                                  displayPriorityWithinCategory: 99999));
                }
            }
        }
Example #2
0
 public static void GetGizmosPostfix(Pawn_EquipmentTracker __instance, ref IEnumerable <Gizmo> __result)
 {
     for (int o = 0; o < __instance.pawn.health.hediffSet.hediffs.Count; o++)
     {
         HediffComp_VerbGiverExtra _VerbGiverExtra;
         if ((_VerbGiverExtra = __instance.pawn.health.hediffSet.hediffs[o].TryGetComp <HediffComp_VerbGiverExtra>()) != null)
         {
             foreach (Command command in _VerbGiverExtra.GetVerbsCommands())
             {
                 if (o != 0)
                 {
                     if (o != 1)
                     {
                         if (o == 2)
                         {
                             command.hotKey = KeyBindingDefOf.Misc3;
                         }
                     }
                     else
                     {
                         command.hotKey = KeyBindingDefOf.Misc2;
                     }
                 }
                 else
                 {
                     command.hotKey = KeyBindingDefOf.Misc1;
                 }
                 __result.AddItem(command);
             }
         }
     }
 }
        //Thanks to XeoNovaDan
        public static void DisplayYieldInfo(PlantProperties __instance, ref IEnumerable <StatDrawEntry> __result)
        {
            ThingDef harvestedThingDef = Traverse.Create(__instance).Field("harvestedThingDef").GetValue <ThingDef>();
            float    harvestYield      = Traverse.Create(__instance).Field("harvestYield").GetValue <float>();

            if (harvestedThingDef == null)
            {
                return;
            }

            string harvestedThingDefLabel = harvestedThingDef.label;

            string extendedYieldInfo = string.Format("M4_HarvestYieldThingDetailInit".Translate(), harvestedThingDefLabel) + "\n\n";
            float  thingMarketValue  = harvestedThingDef.GetStatValueAbstract(StatDefOf.MarketValue, null);

            extendedYieldInfo += StatDefOf.MarketValue.label.CapitalizeFirst() + ": " + thingMarketValue.ToString();
            if (harvestedThingDef.IsNutritionGivingIngestible)
            {
                float         thingNutrition     = harvestedThingDef.GetStatValueAbstract(StatDefOf.Nutrition, null);
                FoodTypeFlags thingNutritionType = harvestedThingDef.ingestible.foodType;
                IDictionary <FoodTypeFlags, string> nutritionTypeToReportString = new Dictionary <FoodTypeFlags, string>()
                {
                    { FoodTypeFlags.VegetableOrFruit, "FoodTypeFlags_VegetableOrFruit" }, { FoodTypeFlags.Meat, "FoodTypeFlags_Meat" }, { FoodTypeFlags.Seed, "FoodTypeFlags_Seed" }
                };
                string nutritionTypeReportString = nutritionTypeToReportString.TryGetValue(thingNutritionType, out nutritionTypeReportString) ? nutritionTypeReportString : "StatsReport_OtherStats";
                extendedYieldInfo += "\n" + StatDefOf.Nutrition.label.CapitalizeFirst() + ": " + thingNutrition.ToString() +
                                     " (" + nutritionTypeReportString.Translate() + ")";
            }

            if (harvestYield > 0)
            {
                StatDrawEntry statDrawEntry = new StatDrawEntry(StatCategoryDefOf.Basics, "M4_HarvestYieldThing".Translate(), harvestedThingDef.label.CapitalizeFirst(), extendedYieldInfo, 0);
                __result = __result.AddItem(statDrawEntry);
            }
        }
 public static void Postfix(Thing __instance, ref IEnumerable <Gizmo> __result)
 {
     if (__instance.def.EverHaulable)
     {
         __result = __result.AddItem(new BufferStockpileGizmo());
     }
 }
 public static void Postfix(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result)
 {
     // Weapons get a readout for if they are usable with shields
     if (__instance.IsWeapon)
     {
         __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.Weapon, "VanillaFactionsExpanded.UsableWithShield".Translate(), __instance.UsableWithShields().ToStringYesNo(),
                                                       "VanillaFactionsExpanded.UsableWithShield_Desc".Translate(), 0));
     }
 }
Example #6
0
        public void RegisterAdminObserver(
            AdminObserverBase observer
            )
        {
            if (observer == null || _adminList.Contains(observer))
            {
                return;
            }

            _adminList = _adminList.AddItem(observer);
        }
Example #7
0
 /// <summary>
 /// Returns all current assemblies
 /// </summary>
 public static IEnumerable <Assembly> YieldGetFullAssemblies()
 {
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         if (cache_assemblies.IsNullOrEmpty() || !cache_assemblies.Contains(assembly))
         {
             cache_assemblies = cache_assemblies.AddItem(assembly);
         }
         yield return(assembly);
     }
 }
Example #8
0
        public static void Postfix(Thing __instance, ref IEnumerable <Thing> __result)
        {
            var ammoUser = (__instance as ThingWithComps)?.TryGetComp <CompAmmoUser>();

            if (ammoUser != null && (ammoUser.HasMagazine && ammoUser.CurMagCount > 0 && ammoUser.CurrentAmmo != null))
            {
                var ammoThing = ThingMaker.MakeThing(ammoUser.CurrentAmmo, null);
                ammoThing.stackCount = ammoUser.CurMagCount;
                __result             = __result.AddItem(ammoThing);
            }
        }
Example #9
0
 public static void Postfix(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result)
 {
     if (__instance.GetModExtension <AnimalStatExtension>() != null && !__instance.IsCorpse)
     {
         AnimalStatExtension extension = __instance.GetModExtension <AnimalStatExtension>();
         foreach (string stat in extension.statToAdd)
         {
             __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.BasicsPawn, stat.Translate(), extension.statValues[extension.statToAdd.IndexOf(stat)].Translate(), extension.statDescriptions[extension.statToAdd.IndexOf(stat)].Translate()
                                                           , 1));
         }
     }
 }
Example #10
0
 public static void GetGizmosPrefix(ref Pawn_EquipmentTracker __instance, ref IEnumerable <Gizmo> __result)
 {
     if (__instance.Primary != null)
     {
         foreach (ThingComp tc in __instance.Primary.AllComps)
         {
             foreach (Gizmo g in tc.CompGetGizmosExtra())
             {
                 __result.AddItem(g);
             }
         }
     }
 }
Example #11
0
        static void Postfix(Building __instance, ref IEnumerable <Gizmo> __result)
        {
            if (__instance is Building_NutrientPasteDispenser)
            {
                //Log.Message("Hello from Harmony Postfix Patch_Building_GetGizmos " + __result.Count());

                //Building_NutrientPasteDispenser myThis = (Building_NutrientPasteDispenser)__instance;
                //MethodInfo CanDispenseNow = myThis.GetType().GetMethod("CanDispenseNow", BindingFlags.Instance | BindingFlags.Public);
                //MethodInfo TryDispenseFood = myThis.GetType().GetMethod("TryDispenseFood", BindingFlags.Instance | BindingFlags.Public);

                //int[] numbers = { 1, 5, 25 };
                //foreach (int i in numbers)
                //{
                //    Gizmo newGizmo = new Command_Action
                //    {
                //        defaultLabel = "Dispense " + i,
                //        action = delegate
                //        {
                //            int k = i;
                //            for (int j = 0; j < k && (bool) CanDispenseNow.Invoke(myThis, null); j++)
                //            {
                //                TryDispenseFood.Invoke(myThis, null);
                //            }
                //        }
                //    };
                //    __result.Add(newGizmo);
                //}

                Building_NutrientPasteDispenser myThis = (Building_NutrientPasteDispenser)__instance;

                int[] numbers = { 1, 5, 25 };
                foreach (int i in numbers)
                {
                    Gizmo newGizmo = new Command_Action
                    {
                        defaultLabel = "Dispense " + i,
                        icon         = ContentFinder <Texture2D> .Get("UI/Designators/Open"),
                        action       = delegate
                        {
                            for (int j = 0; j < i && myThis.CanDispenseNow; j++)
                            {
                                Thing meal = myThis.TryDispenseFood();
                                GenPlace.TryPlaceThing(meal, myThis.InteractionCell, myThis.Map, ThingPlaceMode.Near);
                            }
                        }
                    };
                    __result = __result.AddItem(newGizmo);
                }
                //Log.Message("Goodbye from Harmony Postfix Patch_Building_GetGizmos " + __result.Count());
            }
        }
 // Token: 0x06000002 RID: 2 RVA: 0x00002090 File Offset: 0x00000290
 private static void MakeButcherProducts_PostFix(Thing __instance, ref IEnumerable <Thing> __result, Pawn butcher, float efficiency)
 {
     //    Log.Message(string.Format("{0}", __instance));
     if (__instance is Pawn pawn)
     {
         //    Log.Message(string.Format("{0} is Pawn pawn", __instance));
         if (XenomorphUtil.IsXenomorph(pawn))
         {
             //    Log.Message(string.Format("{0} Pawn pawn is Xenomorph", __instance));
             foreach (var item in pawn.health.hediffSet.GetNotMissingParts())
             {
                 if (item.def == XenomorphDefOf.RRY_Xeno_TailSpike)
                 {
                     ThingDefCountClass thingDefCountClass = new ThingDefCountClass
                     {
                         thingDef = XenomorphDefOf.RRY_Xenomorph_TailSpike,
                         count    = 1
                     };
                     Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                     thing.stackCount = thingDefCountClass.count;
                     __result         = __result.AddItem(thing);
                 }
                 if (item.def == XenomorphDefOf.RRY_Xeno_Shell)
                 {
                     ThingDefCountClass thingDefCountClass = new ThingDefCountClass
                     {
                         thingDef = XenomorphDefOf.RRY_Xenomorph_HeadShell,
                         count    = 1
                     };
                     Thing thing = ThingMaker.MakeThing(thingDefCountClass.thingDef, null);
                     thing.stackCount = thingDefCountClass.count;
                     __result         = __result.AddItem(thing);
                 }
             }
         }
     }
 }
 public static void Postfix(ThingDef __instance, ref IEnumerable <StatDrawEntry> __result)
 {
     if (__instance.race is RaceProperties raceProps && raceProps.Animal)
     {
         // Body clock
         BodyClock bodyClock         = BodyClock.Diurnal;
         var       extendedRaceProps = __instance.GetModExtension <ExtendedRaceProperties>();
         if (extendedRaceProps != null)
         {
             bodyClock = extendedRaceProps.bodyClock;
         }
         __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.BasicsPawn, "NocturnalAnimals.BodyClock".Translate(), $"NocturnalAnimals.BodyClock_{bodyClock}".Translate(),
                                                       "NocturnalAnimals.BodyClock_Description".Translate(), 1));
     }
 }
        //get valid body parts for a specific pawn
        public static IEnumerable <BodyPartRecord> getAvailableBodyParts(Pawn pawn)
        {
            //get all non-missing body parts:
            IEnumerable <BodyPartRecord> bodyParts = pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Outside, null, null);
            BodyPartRecord anus = pawn.def.race.body.AllParts.Find(bpr => string.Equals(bpr.def.defName, "Anus"));            //not found by above function since depth is "inside"

            if (anus != null)
            {
                bodyParts = bodyParts.AddItem(anus);
            }

            //filter for allowed body parts (e.g. no single fingers/toes):
            List <BodyPartDef> filterParts = SemenHelper.getAllowedBodyParts();

            IEnumerable <BodyPartRecord> filteredParts = bodyParts.Where(item1 => filterParts.Any(item2 => item2.Equals(item1.def)));

            return(filteredParts);
        }
Example #15
0
        public static void GetGizmos(Pawn __instance, ref IEnumerable <Gizmo> __result)
        {
            if (!__instance?.IsColonistPlayerControlled ?? true)
            {
                return;
            }

            if (__instance.ownership?.OwnedBed == null)
            {
                return;
            }

            WmbStatic.GizmoLabel ??= "WMB.Gizmo.Label".TranslateSimple();
            WmbStatic.GizmoDescription ??= "WMB.Gizmo.Description".TranslateSimple();

            __result = __result.AddItem(
                new Command_Action
            {
                defaultLabel  = Settings.ShowGizmoText ? WmbStatic.GizmoLabel : null,
                defaultDesc   = WmbStatic.GizmoDescription,
                icon          = WmbStatic.GizmoIcon,
                activateSound = WmbStatic.SoundDef,
                action        = delegate
                {
                    if (!CameraJumper.CanJump(__instance.ownership.OwnedBed))
                    {
                        return;
                    }

                    switch (Settings.GizmoAction)
                    {
                    case "Jump":
                        CameraJumper.TryJump(__instance.ownership.OwnedBed);
                        break;

                    case "Select":
                        CameraJumper.TryJumpAndSelect(__instance.ownership.OwnedBed);
                        break;
                    }
                }
            }
                );
        }
Example #16
0
 public static void Postfix(Zone_Stockpile __instance, ref IEnumerable <Gizmo> __result)
 {
     __result = __result.AddItem(new Command_StorageSettingsPresets(__instance));
 }
Example #17
0
            public static void Postfix(ThingDef __instance, StatRequest req, ref IEnumerable <StatDrawEntry> __result)
            {
                // Add mortar shell stats to the list of stat draw entries
                if (__instance.IsShell)
                {
                    var shellThing            = ThingMaker.MakeThing(__instance.projectileWhenLoaded);
                    var shellProps            = __instance.projectileWhenLoaded.projectile;
                    var shellDamage           = shellProps.GetDamageAmount(shellThing);
                    var shellArmorPenetration = shellProps.GetArmorPenetration(shellThing);
                    var shellStoppingPower    = shellProps.StoppingPower;
                    var shellDamageDef        = shellProps.damageDef.label.CapitalizeFirst();
                    var shellExplosionRadius  = shellProps.explosionRadius;

                    __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.TurretAmmo, "Damage".Translate(), shellDamage.ToString(), "Stat_Thing_Damage_Desc".Translate(),
                                                                  20));
                    __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.TurretAmmo, "TurretExtensions.ShellDamageType".Translate(), shellDamageDef,
                                                                  "TurretExtensions.ShellDamageType_Desc".Translate(), 19));
                    __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.TurretAmmo, "ArmorPenetration".Translate(), shellArmorPenetration.ToStringPercent(),
                                                                  "ArmorPenetrationExplanation".Translate(), 18));
                    __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.TurretAmmo, "StoppingPower".Translate(), shellStoppingPower.ToString(),
                                                                  "StoppingPowerExplanation".Translate(), 17));

                    if (shellExplosionRadius > 0)
                    {
                        __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.TurretAmmo, "TurretExtensions.ShellExplosionRadius".Translate(),
                                                                      shellExplosionRadius.ToString(), "TurretExtensions.ShellExplosionRadius_Desc".Translate(), 16));
                    }
                }

                // Minimum range
                if (__instance.Verbs.FirstOrDefault(v => v.isPrimary) is VerbProperties verb)
                {
                    var verbStatCategory = __instance.category != ThingCategory.Pawn ? RimWorld.StatCategoryDefOf.Weapon : RimWorld.StatCategoryDefOf.PawnCombat;
                    if (verb.LaunchesProjectile)
                    {
                        if (verb.minRange > default(float))
                        {
                            __result = __result.AddItem(new StatDrawEntry(verbStatCategory, "MinimumRange".Translate(), verb.minRange.ToString("F0"),
                                                                          "TurretExtensions.MinimumRange_Desc".Translate(), 5385));
                        }
                    }
                }

                // Add turret weapons stats to the list of SpecialDisplayStats
                var buildingProps = __instance.building;

                if (buildingProps == null || !buildingProps.IsTurret)
                {
                    return;
                }

                var gunStatList = new List <StatDrawEntry>();

                if (req.Def is ThingDef tDef)
                {
                    // Add upgradability
                    string upgradableString;
                    CompProperties_Upgradable upgradableCompProps;
                    if (req.HasThing && req.Thing.IsUpgradable(out var upgradableComp))
                    {
                        upgradableString    = (upgradableComp.upgraded ? "TurretExtensions.NoAlreadyUpgraded" : "TurretExtensions.YesClickForDetails").Translate();
                        upgradableCompProps = upgradableComp.Props;
                    }
                    else
                    {
                        upgradableString = (tDef.IsUpgradable(out upgradableCompProps) ? "TurretExtensions.YesClickForDetails" : "No").Translate();
                    }

                    var upgradeHyperlinks = new List <Dialog_InfoCard.Hyperlink>();
                    if (upgradableCompProps?.turretGunDef != null)
                    {
                        upgradeHyperlinks.Add(new Dialog_InfoCard.Hyperlink(upgradableCompProps.turretGunDef));
                    }

                    gunStatList.Add(new StatDrawEntry(RimWorld.StatCategoryDefOf.BasicsNonPawn, "TurretExtensions.Upgradable".Translate(), upgradableString,
                                                      TurretExtensionsUtility.UpgradeReadoutReportText(req), 999, hyperlinks: upgradeHyperlinks));

                    // Add firing arc
                    var firingArc = req.HasThing ? TurretExtensionsUtility.FiringArcFor(req.Thing) : TurretFrameworkExtension.Get(tDef).FiringArc;
                    gunStatList.Add(new StatDrawEntry(RimWorld.StatCategoryDefOf.Weapon, "TurretExtensions.FiringArc".Translate(), firingArc.ToStringDegrees(),
                                                      "TurretExtensions.FiringArc_Desc".Translate(), 5380));
                }

                // Replace cooldown
                __result = __result.Where(s => s.stat != StatDefOf.RangedWeapon_Cooldown);
                var cooldownStat = StatDefOf.RangedWeapon_Cooldown;

                gunStatList.Add(new StatDrawEntry(cooldownStat.category, cooldownStat, TurretCooldown(req, buildingProps), StatRequest.ForEmpty(),
                                                  cooldownStat.toStringNumberSense));

                // Replace warmup
                __result = __result.Where(s => s.LabelCap != "WarmupTime".Translate().CapitalizeFirst());
                gunStatList.Add(new StatDrawEntry(RimWorld.StatCategoryDefOf.Weapon, "WarmupTime".Translate(), $"{TurretWarmup(req, buildingProps).ToString("0.##")} s",
                                                  "Stat_Thing_Weapon_MeleeWarmupTime_Desc".Translate(), StatDisplayOrder.Thing_Weapon_MeleeWarmupTime));

                __result = __result.Concat(gunStatList);
            }
Example #18
0
 public override void LoadGeneratedCommands()
 {
     RegisterCommand(new Message(_prefixes.AddItem(Command)));
 }
 public static void Postfix(ThingDef parentDef, ref IEnumerable <StatDrawEntry> __result)
 {
     // Body clock
     __result = __result.AddItem(new StatDrawEntry(StatCategoryDefOf.BasicsPawn, "NocturnalAnimals.BodyClock".Translate(),
                                                   $"NocturnalAnimals.BodyClock_{ExtendedRaceProperties.Get(parentDef).bodyClock}".Translate(), "NocturnalAnimals.BodyClock_Description".Translate(), 2500));
 }
Example #20
0
 public override void LoadGeneratedCommands()
 {
     RegisterCommand(new Broadcast.Prefix(_prefixes.AddItem(Command)));
     RegisterCommand(new Hint.Prefix(_prefixes.AddItem(Command)));
 }
 public static IEnumerable <Gizmo> AddLockGizmo(IEnumerable <Gizmo> collection, Building_Door door)
 {
     return(collection.AddItem(new LockGizmo(door)));
 }
Example #22
0
        //public class JobDriver_Vomit : JobDriver
        public static bool MakeNewToils_VampVomit(JobDriver_Vomit __instance, ref IEnumerable <Toil> __result)
        {
            if (__instance.pawn.IsVampire())
            {
                Toil to = new Toil()
                {
                    initAction = delegate
                    {
                        AccessTools.Field(typeof(JobDriver_Vomit), "ticksLeft")
                        .SetValue(__instance, Rand.Range(300, 900));
                        int     num = 0;
                        IntVec3 c;
                        while (true)
                        {
                            c = __instance.pawn.Position + GenAdj.AdjacentCellsAndInside[Rand.Range(0, 9)];
                            num++;
                            if (num > 12)
                            {
                                break;
                            }

                            if (c.InBounds(__instance.pawn.Map) && c.Standable(__instance.pawn.Map))
                            {
                                goto IL_A1;
                            }
                        }

                        c = __instance.pawn.Position;
IL_A1:
                        __instance.pawn.CurJob.targetA = c;
                        __instance.pawn.rotationTracker.FaceCell(c);
                        __instance.pawn.pather.StopDead();
                    },
                    tickAction = delegate
                    {
                        int curTicks = Traverse.Create(__instance).Field("ticksLeft").GetValue <int>();
                        if (curTicks % 150 == 149)
                        {
                            FilthMaker.TryMakeFilth(__instance.pawn.CurJob.targetA.Cell, __instance.pawn.Map,
                                                    ThingDefOf.Filth_Blood, __instance.pawn.LabelIndefinite());
                            if (__instance.pawn.BloodNeed() is Need_Blood n && n.CurBloodPoints > 0)
                            {
                                n.AdjustBlood(-1);
                            }

                            //if (__instance.pawn.needs.food.CurLevelPercentage > 0.1f)
                            //{
                            //    __instance.pawn.needs.food.CurLevel -= __instance.pawn.needs.food.MaxLevel * 0.04f;
                            //}
                        }

                        AccessTools.Field(typeof(JobDriver_Vomit), "ticksLeft").SetValue(__instance, curTicks - 1);

                        if (curTicks - 1 <= 0)
                        {
                            __instance.ReadyForNextToil();
                            TaleRecorder.RecordTale(TaleDefOf.Vomited, new object[]
                            {
                                __instance.pawn
                            });
                        }
                    }
                };
                to.defaultCompleteMode = ToilCompleteMode.Never;
                to.WithEffect(DefDatabase <EffecterDef> .GetNamed("ROMV_BloodVomit"), TargetIndex.A);
                to.PlaySustainerOrSound(() => SoundDef.Named("Vomit"));
                __result = __result.AddItem(to);

                return(false);
            }

            return(true);
        }