コード例 #1
0
        protected virtual void FireTurret(VehicleTurret turret)
        {
            float   horizontalOffset = turret.turretDef.projectileShifting.NotNullAndAny() ? turret.turretDef.projectileShifting[turret.CurrentTurretFiring] : 0;
            Vector3 launchPos        = TurretLocation(turret) + new Vector3(horizontalOffset, 1f, turret.turretDef.projectileOffset);

            Vector3 targetPos = Target(turret);
            float   range     = Vector3.Distance(TurretLocation(turret), targetPos);
            IntVec3 target    = targetPos.ToIntVec3() + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(turret.CurrentFireMode.spreadRadius * (range / turret.turretDef.maxRange)))];

            if (turret.CurrentTurretFiring >= turret.turretDef.projectileShifting.Count)
            {
                turret.CurrentTurretFiring = 0;
            }

            ThingDef projectile;

            if (turret.turretDef.ammunition != null && !turret.turretDef.genericAmmo)
            {
                projectile = turret.loadedAmmo?.projectileWhenLoaded;
            }
            else
            {
                projectile = turret.turretDef.projectile;
            }
            try
            {
                float speedTicksPerTile = projectile.projectile.SpeedTilesPerTick;
                if (turret.turretDef.projectileSpeed > 0)
                {
                    speedTicksPerTile = turret.turretDef.projectileSpeed;
                }
                ProjectileSkyfaller projectile2 = ProjectileSkyfallerMaker.WrapProjectile(ProjectileSkyfallerDefOf.ProjectileSkyfaller,
                                                                                          projectile, this, launchPos, target.ToVector3Shifted(), speedTicksPerTile); //REDO - RANDOMIZE TARGETED CELLS
                GenSpawn.Spawn(projectile2, target.ClampInsideMap(Map), Map);
                if (turret.turretDef.ammunition != null)
                {
                    turret.ConsumeShellChambered();
                }
                if (turret.turretDef.cannonSound != null)
                {
                    turret.turretDef.cannonSound.PlayOneShot(new TargetInfo(Position, Map, false));
                }
                turret.PostTurretFire();
            }
            catch (Exception ex)
            {
                Log.Error($"Exception when firing Cannon: {turret.turretDef.LabelCap} on Pawn: {vehicle.LabelCap}. Exception: {ex.Message}");
            }
        }
コード例 #2
0
 /// <summary>
 /// Generate projectile launched from <paramref name="origin"/> to <paramref name="destination"/>
 /// </summary>
 /// <param name="def"></param>
 /// <param name="vehicle"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 public static ProjectileSkyfaller WrapProjectile(ThingDef skyfallerDef, ThingDef projectileDef, Thing caster, Vector3 origin, Vector3 destination, float speedTilesPerTick, bool reverseDraw = false)
 {
     try
     {
         ProjectileSkyfaller skyfaller = (ProjectileSkyfaller)ThingMaker.MakeThing(skyfallerDef);
         skyfaller.caster            = caster;
         skyfaller.origin            = origin;
         skyfaller.destination       = destination;
         skyfaller.projectileDef     = projectileDef;
         skyfaller.speedTilesPerTick = speedTilesPerTick;
         skyfaller.reverseDraw       = reverseDraw;
         return(skyfaller);
     }
     catch (Exception ex)
     {
         Log.Error($"Unable to generate StrafeProjectile with projectile <type>{projectileDef.thingClass}</type>. Exception=\"{ex.Message}\"");
     }
     return(null);
 }