private static bool IsValidTarget(Building_TurretGun __instance, Thing t)
        {
            Building_Turret building_Turret = __instance;
            Pawn            pawn            = t as Pawn;

            if (pawn != null)
            {
                if (__instance.AttackVerb.ProjectileFliesOverhead())
                {
                    RoofDef roofDef = building_Turret.Map.roofGrid.RoofAt(t.Position);
                    if (roofDef != null && roofDef.isThickRoof)
                    {
                        return(false);
                    }
                }

                if (mannableComp == null)
                {
                    return(!GenAI.MachinesLike(building_Turret.Faction, pawn));
                }

                if (pawn.RaceProps.Animal && pawn.Faction == Faction.OfPlayer)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        public static string ShotCalculationTipString(Thing target)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Find.Selector.SingleSelectedThing != null)
            {
                Verb verb = null;
                Pawn pawn = Find.Selector.SingleSelectedThing as Pawn;
                if (pawn != null && pawn != target && pawn.equipment != null && pawn.equipment.Primary != null && pawn.equipment.PrimaryEq.PrimaryVerb is Verb_LaunchProjectile)
                {
                    verb = pawn.equipment.PrimaryEq.PrimaryVerb;
                }
                Building_TurretGun building_TurretGun = Find.Selector.SingleSelectedThing as Building_TurretGun;
                if (building_TurretGun != null && building_TurretGun != target)
                {
                    verb = building_TurretGun.AttackVerb;
                }
                if (verb != null)
                {
                    stringBuilder.Append("ShotBy".Translate(new object[]
                    {
                        Find.Selector.SingleSelectedThing.LabelShort
                    }) + ": ");
                    if (verb.CanHitTarget(target))
                    {
                        stringBuilder.Append(ShotReport.HitReportFor(verb.caster, verb, target).GetTextReadout());
                    }
                    else
                    {
                        stringBuilder.Append("CannotHit".Translate());
                    }
                }
            }
            return(stringBuilder.ToString());
        }
            public static void Postfix(Building_TurretGun __instance, ref bool __result)
            {
                // If the turret isn't mannable, is player-controlled and is set to be able to force target, do so
                if (__instance.Faction != Faction.OfPlayer)
                {
                    return;
                }

                var extensionValues = TurretFrameworkExtension.Get(__instance.def);
                var upgradableComp  = __instance.TryGetComp <CompUpgradable>();

                // Upgradable comp doesn't exist/isn't upgraded and can force attack, or exists and upgraded and can force attack
                if (upgradableComp == null || upgradableComp.Props.canForceAttack != null && (upgradableComp.upgraded || !extensionValues.canForceAttack) &&
                    (!upgradableComp.upgraded || !upgradableComp.Props.canForceAttack.Value))
                {
                    return;
                }

                if (!__instance.def.HasComp(typeof(CompMannable)))
                {
                    __result = true;
                }
                else
                {
                    Log.Warning($"Turret (defName={__instance.def.defName}) has canForceAttack set to true and CompMannable; canForceAttack is redundant in this case.");
                }
            }
Exemple #4
0
 public static void Postfix(Building_TurretGun __instance, ref float __result)
 {
     if (__instance.IsUpgraded(out CompUpgradable upgradableComp))
     {
         __result *= upgradableComp.Props.turretBurstCooldownTimeFactor;
     }
 }
Exemple #5
0
            public static void Postfix(Building_TurretGun __instance, TurretTop ___top)
            {
                // Determine which way the turret initially faces when spawned
                var turretFrameworkExtension = TurretFrameworkExtension.Get(__instance.def);

                switch (turretFrameworkExtension.gunFaceDirectionOnSpawn)
                {
                case TurretGunFaceDirection.North:
                    NonPublicProperties.TurretTop_set_CurRotation(___top, Rot4.North.AsAngle);
                    break;

                case TurretGunFaceDirection.East:
                    NonPublicProperties.TurretTop_set_CurRotation(___top, Rot4.East.AsAngle);
                    break;

                case TurretGunFaceDirection.South:
                    NonPublicProperties.TurretTop_set_CurRotation(___top, Rot4.South.AsAngle);
                    break;

                case TurretGunFaceDirection.West:
                    NonPublicProperties.TurretTop_set_CurRotation(___top, Rot4.West.AsAngle);
                    break;

                default:
                    NonPublicProperties.TurretTop_set_CurRotation(___top, __instance.Rotation.AsAngle);
                    break;
                }
            }
        static void Prefix(Pawn pawn, Building_TurretGun gun)
        {
#if DEBUG
            Log.Warning("Find Ammo");
#endif
            if (pawn.IsColonist && pawn.Map == gun.Map)
            {
                StorageSettings allowedShellsSettings = gun.gun.TryGetComp <CompChangeableProjectile>().allowedShellsSettings;
                foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(gun.Map))
                {
#if DEBUG
                    Log.Warning("    Storeage: " + storage.Label);
#endif
                    List <Thing> l;
                    if (storage.TryRemove(allowedShellsSettings.filter, out l))
                    {
                        foreach (Thing t in l)
                        {
#if DEBUG
                            Log.Warning("        Ammo fouynd: " + t.Label);
#endif
                            List <Thing> dropped = new List <Thing>();
                            BuildingUtil.DropThing(t, t.stackCount, storage, storage.Map, dropped);
                        }
                    }
                }
            }
        }
        public static Mote ThrowCasingTurret(Thing caster, Map map, int weaponDamage, ThingDef moteDef)
        {
            if (!caster.Position.ShouldSpawnMotesAt(map) || map.moteCounter.Saturated)
            {
                return(null);
            }
            Building_TurretGun turret    = caster as Building_TurretGun;
            TurretTop          turrettop = Traverse.Create(turret).Field("top").GetValue <TurretTop>();

            float            angle      = Traverse.Create(turrettop).Field("curRotationInt").GetValue <float>();
            MoteThrownCasing moteThrown = (MoteThrownCasing)ThingMaker.MakeThing(moteDef, null);

            if (BulletCasingMoteSettings.uncapCasingSize)
            {
                moteThrown.Scale = GenMath.LerpDouble(5f, 50f, 0.2f, 0.5f, weaponDamage);
            }
            else
            {
                moteThrown.Scale = GenMath.LerpDoubleClamped(5f, 75f, 0.2f, 0.5f, weaponDamage);
            }
            moteThrown.exactPosition  = caster.TrueCenter();
            moteThrown.rotationRate   = Rand.Range(-360f, 360f);
            moteThrown.speed          = Rand.Range(BulletCasingMoteSettings.velocityFactor.min, BulletCasingMoteSettings.velocityFactor.max);
            moteThrown.rotation       = angle;
            moteThrown.velocityRandom = new Vector3(Rand.Range(-4f, 4f), 0f, Rand.Range(-4f, 4f));
            GenSpawn.Spawn(moteThrown, caster.Position, map, WipeMode.Vanish);
            return(moteThrown);
        }
Exemple #8
0
        private static void GenerateAvoidGridInternal(ByteGrid grid, Faction faction, Map map, AvoidGridMode mode)
        {
            List <TrapMemory> list = faction.TacticalMemory.TrapMemories();

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].map == map)
                {
                    AvoidGridMaker.PrintAvoidGridAroundTrapLoc(list[i], grid);
                }
            }
            if (mode == AvoidGridMode.Smart)
            {
                List <Building> allBuildingsColonist = map.listerBuildings.allBuildingsColonist;
                for (int j = 0; j < allBuildingsColonist.Count; j++)
                {
                    if (allBuildingsColonist[j].def.building.ai_combatDangerous)
                    {
                        Building_TurretGun building_TurretGun = allBuildingsColonist[j] as Building_TurretGun;
                        if (building_TurretGun != null)
                        {
                            AvoidGridMaker.PrintAvoidGridAroundTurret(building_TurretGun, grid);
                        }
                    }
                }
            }
            AvoidGridMaker.ExpandAvoidGridIntoEdifices(grid, map);
        }
            public static void Postfix(Building_TurretGun __instance)
            {
                var artilleryComp = __instance.TryGetComp <CompLongRangeArtillery>();

                if (artilleryComp != null && artilleryComp.targetedTile != TargetInfo.Invalid)
                {
                    var edgeCell = artilleryComp.FacingEdgeCell;

                    // Warmup pie
                    if (artilleryComp.CanLaunch)
                    {
                        if (artilleryComp.warmupTicksLeft > 0)
                        {
                            GenDraw.DrawAimPie(__instance, edgeCell, (int)(artilleryComp.warmupTicksLeft * 0.5f), __instance.def.size.x * 0.5f);
                        }
                    }

                    // Targeting lines
                    var a = __instance.TrueCenter();
                    var b = edgeCell.CenterVector3;
                    a.y = AltitudeLayer.MetaOverlays.AltitudeFor();
                    b.y = a.y;
                    GenDraw.DrawLineBetween(a, b, Building_TurretGun.ForcedTargetLineMat);
                }
            }
 public static void Postfix(Building_TurretGun __instance)
 {
     if (__instance.GetComp <CompLongRangeArtillery>() is CompLongRangeArtillery artilleryComp)
     {
         artilleryComp.ResetForcedTarget();
     }
 }
 public static void TurretPostLoadInit(Building_TurretGun turret)
 {
     if (turret.gun == null)
     {
         turret.MakeGun();
     }
 }
        public static bool ShotCalculationTipStringPrefix(ref string __result, Thing target)
        {
            StringBuilder stringBuilder = new StringBuilder();

            if (Find.Selector.SingleSelectedThing != null)
            {
                Thing singleSelectedThing = Find.Selector.SingleSelectedThing;
                Verb  verb = null;
                Pawn  pawn = singleSelectedThing as Pawn;
                if (pawn != null && pawn != target && pawn.equipment != null && pawn.equipment.Primary != null)
                {
                    Comp_VerbSaveable compsav = pawn.equipment.Primary.GetComp <Comp_VerbSaveable>();
                    if (compsav != null && compsav.tempVerb != null && compsav.tempVerb is Verb_LaunchProjectile)
                    {
                        verb = compsav.tempVerb;
                    }
                    else
                    {
                        verb = pawn.equipment.PrimaryEq.PrimaryVerb;
                    }
                }
                Building_TurretGun building_TurretGun = singleSelectedThing as Building_TurretGun;
                if (building_TurretGun != null && building_TurretGun != target)
                {
                    verb = building_TurretGun.AttackVerb;
                }
                if (verb != null)
                {
                    stringBuilder.Append("ShotBy".Translate(Find.Selector.SingleSelectedThing.LabelShort, Find.Selector.SingleSelectedThing) + ": ");
                    if (verb.CanHitTarget(target))
                    {
                        stringBuilder.Append(ShotReport.HitReportFor(verb.caster, verb, target).GetTextReadout());
                    }
                    else
                    {
                        stringBuilder.AppendLine("CannotHit".Translate());
                    }
                    Pawn pawn2 = target as Pawn;
                    if (pawn2 != null && pawn2.Faction == null && !pawn2.InAggroMentalState)
                    {
                        float manhunterOnDamageChance;
                        if (verb.IsMeleeAttack)
                        {
                            manhunterOnDamageChance = PawnUtility.GetManhunterOnDamageChance(pawn2, 0f, singleSelectedThing);
                        }
                        else
                        {
                            manhunterOnDamageChance = PawnUtility.GetManhunterOnDamageChance(pawn2, singleSelectedThing);
                        }
                        if (manhunterOnDamageChance > 0f)
                        {
                            stringBuilder.AppendLine();
                            stringBuilder.AppendLine(string.Format("{0}: {1}", "ManhunterPerHit".Translate(), manhunterOnDamageChance.ToStringPercent()));
                        }
                    }
                }
            }
            __result = stringBuilder.ToString();
            return(false);
        }
        public RangedWeaponStats(Building_TurretGun turret)
        {
            weapon    = turret.gun;
            shootVerb = GetShootVerb(weapon.def);

            // Get the damage from the loaded projectile if the weapon is loadable or the default projectile otherwise
            var projectile = weapon.TryGetComp <CompChangeableProjectile>()?.Projectile?.projectile
                             ?? shootVerb?.defaultProjectile?.projectile;

            // Default to zero damage if we can't find a projectile.
            // Not an error as unloaded mortars don't have projectiles
            shotDamage = projectile?.GetDamageAmount(weapon) ?? 0;

            // Note that turrets completely ignore the warmup and cooldown stat of the weapon
            warmup = turret.def.building.turretBurstWarmupTime;

            // Logic duplicated from Building_TurretGun.BurstCooldownTime()
            if (turret.def.building.turretBurstCooldownTime >= 0f)
            {
                cooldown = turret.def.building.turretBurstCooldownTime;
            }
            else
            {
                cooldown = turret.AttackVerb.verbProps.defaultCooldownTime;
            }
        }
Exemple #14
0
 public static void Postfix(Building_TurretGun __instance, Thing t, ref bool __result)
 {
     // Cone of fire check
     if (__result && !t.Position.WithinFiringArcOf(__instance))
     {
         __result = false;
     }
 }
        public static IAttackTargetSearcher TargSearcher(Building_TurretGun __instance)
        {
            if (mannableComp(__instance) != null && mannableComp(__instance).MannedNow)
            {
                return(mannableComp(__instance).ManningPawn);
            }

            return(__instance);
        }
Exemple #16
0
        public static bool Prefix(Building_TurretGun __instance, ref bool __result, Thing t)
        {
            bool result;

            if (__instance?.Faction == PurpleIvyData.AlienFaction && t is Pawn pawn && pawn.health.hediffSet.GetFirstHediffOfDef(PurpleIvyDefOf.PI_MaskingSprayHigh) != null)
            {
                __result = false;
                result   = false;
            }
        // Token: 0x06000007 RID: 7 RVA: 0x00002089 File Offset: 0x00000289
        public static void Postfix(Building_TurretGun __instance, ref bool __result)
        {
            if (__result)
            {
                return;
            }

            __result = __instance.def.defName == "Ra2_Bunker";
        }
        /// <summary>
        /// Calculates a stats breakdown of the given turret.
        /// Logs an error and returns null if the thing is null.
        /// </summary>
        /// <returns>The stats of the passed-in turret.</returns>
        /// <param name="turret">The turret to get stats for.</param>
        protected static RangedWeaponStats GetTurretStats(Building_TurretGun turret)
        {
            if (turret == null)
            {
                Log.Error($"[RangedDPS] Tried to get the ranged weapon stats of a null turret");
                return(null);
            }

            return(new RangedWeaponStats(turret));
        }
        public static bool AcceptsShell(Building_TurretGun artillery, ThingDef shellDef)
        {
            var changeableProjComp = artillery.gun.TryGetComp <CompChangeableProjectile>();

            if (changeableProjComp == null)
            {
                return(false);
            }
            return(changeableProjComp.allowedShellsSettings.AllowedToAccept(shellDef));
        }
Exemple #20
0
 static void Postfix(Building_TurretGun __instance, ref bool __result)
 {
     if (Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(__instance.Map).rogueAI is Building_RogueAI rogueAI)
     {
         if (rogueAI.controlledTurrets.Contains(__instance))
         {
             __result = true;
         }
     }
 }
Exemple #21
0
 static void Postfix(Building_TurretGun __instance)
 {
     if (Base.Instance.GetExtendedDataStorage().GetExtendedDataFor(__instance.Map).rogueAI is Building_RogueAI controller)
     {
         if (controller.controlledTurrets.Contains(__instance))
         {
             GenDraw.DrawLineBetween(__instance.Position.ToVector3Shifted(), controller.Position.ToVector3Shifted(), SimpleColor.Green);
         }
     }
 }
Exemple #22
0
 public static bool Prefix(Building_TurretGun __instance, LocalTargetInfo targ)
 {
     // Cone of fire check
     if (targ.IsValid && !targ.Cell.WithinFiringArcOf(__instance))
     {
         Messages.Message("TurretExtensions.MessageTargetOutsideFiringArc".Translate(), MessageTypeDefOf.RejectInput, false);
         return(false);
     }
     return(true);
 }
            public static bool Prefix(Building_TurretGun __instance)
            {
                // Don't try and automatically target if targeting a world tile
                var artilleryComp = __instance.GetComp <CompLongRangeArtillery>();

                if (artilleryComp != null && artilleryComp.targetedTile.IsValid)
                {
                    return(false);
                }
                return(true);
            }
Exemple #24
0
        public override string GetStatDrawEntryLabel(StatDef stat, float value, ToStringNumberSense numberSense, StatRequest optionalReq, bool finalized = true)
        {
            Building_TurretGun turret      = GetTurret(optionalReq);
            RangedWeaponStats  weaponStats = GetTurretStats(optionalReq);

            int optimalRange = (int)weaponStats.FindOptimalRange(turret);

            return(string.Format("{0} ({1})",
                                 value.ToStringByStyle(stat.toStringStyle, numberSense),
                                 string.Format("StatsReport_RangedDPSOptimalRange".Translate(), optimalRange)));
        }
Exemple #25
0
        public override string GetExplanationUnfinalized(StatRequest req, ToStringNumberSense numberSense)
        {
            if (!ShouldShowFor(req))
            {
                return("");
            }

            Building_TurretGun turret      = GetTurret(req);
            RangedWeaponStats  weaponStats = GetTurretStats(req);

            return(DPSRangeBreakdown(weaponStats, turret));
        }
Exemple #26
0
        public override void Initialize(Verse.CompProperties props)
        {
            base.Initialize(props);
            Building_TurretGun turret = parent as Building_TurretGun;

            if (turret != null && turret.gun == null)
            {
                gun        = (Thing)ThingMaker.MakeThing(parent.def.building.turretGunDef);
                turret.gun = gun;
                turret.GunCompEq.verbTracker.InitVerbs();
            }
        }
        // prefix
        // - wants instance, result and count
        // - wants to change count
        // - returns a boolean that controls if original is executed (true) or not (false)
        public static Boolean CanSetForcedTargetPrefix(ref bool __result, ref Building_TurretGun __instance)
        {
            //Allow for all Turrets belonging to the Player
            if (__instance.Faction == Faction.OfPlayer)
            {
                //Set result to true so targeting can be used and return fasle to stop origional check.
                __result = true;
                return(false);
            }

            //Retuen true so the origional method is executed.
            return(true);
        }
Exemple #28
0
 static void Postfix(Building_TurretGun __instance, TurretTop ___top)
 {
     if (__instance.GetComp <CompMountable>() is CompMountable comp && comp.Active)
     {
         //TODO: look into performance of this. Try to avoid Traverse.
         float curRotation = Traverse.Create(___top).Property("CurRotation").GetValue <float>();
         if (__instance.Rotation != comp.mountedTo.Rotation)
         {
             Traverse.Create(___top).Property("CurRotation").SetValue(comp.mountedTo.Rotation.AsAngle);
             __instance.Rotation = comp.mountedTo.Rotation;
         }
     }
 }
        public static void Listener(Building_TurretGun __instance, ref bool __result)
        {
            var crt = __instance.TryGetComp <CompRemotelyControlledTurret>();

            if (crt?.controller == null)
            {
                return;
            }

            var mannable = (CompMannable)mannableComp.GetValue(__instance);

            __result = __result || mannable == null;
        }
Exemple #30
0
        private static void PrintAvoidGridAroundTurret(Building_TurretGun tur, ByteGrid avoidGrid)
        {
            int num = GenRadial.NumCellsInRadius((float)(tur.GunCompEq.PrimaryVerb.verbProps.range + 4.0));

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = tur.Position + GenRadial.RadialPattern[i];
                if (intVec.InBounds(tur.Map) && intVec.Walkable(tur.Map) && GenSight.LineOfSight(intVec, tur.Position, tur.Map, true, null, 0, 0))
                {
                    AvoidGridMaker.IncrementAvoidGrid(avoidGrid, intVec, 12);
                }
            }
        }