private static bool TryDrawFiringCone(Verb instance)
 {
     if (instance.Caster is Building_Turret turret && TurretExtensionsUtility.FiringArcFor(turret) < 360)
     {
         TurretExtensionsUtility.TryDrawFiringCone(turret, instance.verbProps.range);
         return true;
     }
     return false;
 }
            private static bool TryDrawFiringCone(Verb instance)
            {
                if (!(instance.Caster is Building_Turret turret) || !(TurretExtensionsUtility.FiringArcFor(turret) < 360))
                {
                    return(false);
                }

                TurretExtensionsUtility.TryDrawFiringCone(turret, instance.verbProps.range);
                return(true);
            }
Exemple #3
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);
            }