예제 #1
0
        public ProjectileData GetData(GameData.Items.GunEquipment gunDef)
        {
            ProjectileData pdata;

            if (datas.TryGetValue(gunDef.Nickname, out pdata))
            {
                return(pdata);
            }
            pdata          = new ProjectileData();
            pdata.Munition = gunDef.Munition;
            pdata.Lifetime = gunDef.Munition.Def.Lifetime;
            pdata.Velocity = gunDef.Def.MuzzleVelocity;
            if (world.Renderer != null)
            {
                var res = world.Renderer.Game.GetService <GameDataManager>();
                if (gunDef.Munition.Def.MunitionHitEffect != null)
                {
                    pdata.HitEffect = res.GetEffect(gunDef.Munition.Def.MunitionHitEffect)
                                      .GetEffect(world.Renderer.ResourceManager);
                }
                if (gunDef.Munition.Def.ConstEffect != null)
                {
                    pdata.TravelEffect = res.GetEffect(gunDef.Munition.Def.ConstEffect)?
                                         .GetEffect(world.Renderer.ResourceManager);
                }
            }
            datas.Add(gunDef.Nickname, pdata);
            return(pdata);
        }
예제 #2
0
        public void Fire(Vector3 point)
        {
            if (Parent.Parent.TryGetComponent <ShipPhysicsComponent>(out var flight) &&
                (flight.EngineState == EngineStates.Cruise || flight.EngineState == EngineStates.CruiseCharging))
            {
                return;
            }
            if (CurrentCooldown > 0)
            {
                return;
            }
            if (projectiles == null)
            {
                hpfires     = Parent.GetHardpoints().Where((x) => x.Name.StartsWith("hpfire", StringComparison.CurrentCultureIgnoreCase)).ToArray();
                projectiles = Parent.GetWorld().Projectiles;
                toSpawn     = projectiles.GetData(Object);
            }
            var  tr = (Parent.Attachment.Transform * Parent.Parent.WorldTransform);
            uint hp = CrcTool.FLModelCrc(Parent.Attachment.Name);

            for (int i = 0; i < hpfires.Length; i++)
            {
                var pos     = Vector3.Transform(Vector3.Zero, hpfires[i].Transform * tr);
                var normal  = Vector3.TransformNormal(-Vector3.UnitZ, hpfires[i].Transform * tr);
                var heading = (point - pos).Normalized();

                var angle = GetAngle(normal, heading);
                if (angle <= MathHelper.DegreesToRadians(40)) //TODO: MUZZLE_CONE_ANGLE constant
                {
                    projectiles.SpawnProjectile(Parent.Parent, hp, toSpawn, pos, heading);
                    projectiles.QueueProjectile(Parent.Parent.NetID, Object, hp, pos, heading);
                }
            }
            CurrentCooldown = Object.Def.RefireDelay;
        }
예제 #3
0
        public ProjectileData GetData(GameData.Items.GunEquipment gunDef)
        {
            ProjectileData pdata;

            if (datas.TryGetValue(gunDef.Nickname, out pdata))
            {
                return(pdata);
            }
            pdata          = new ProjectileData();
            pdata.Munition = gunDef.Munition;
            pdata.Lifetime = gunDef.Munition.Def.Lifetime;
            pdata.Velocity = gunDef.Def.MuzzleVelocity;
            datas.Add(gunDef.Nickname, pdata);
            return(pdata);
        }
예제 #4
0
 public void SpawnProjectile(ProjectileData projectile, Vector3 position, Vector3 heading)
 {
     if (projectilePtr == 16383)
     {
         projectilePtr = 0;
     }
     Projectiles[projectilePtr] = new Projectile()
     {
         Data     = projectile,
         Time     = 0,
         Alive    = true,
         Position = position,
         Normal   = heading * projectile.Velocity
     };
     projectilePtr++;
 }
예제 #5
0
        public void SpawnProjectile(GameObject owner, uint hardpoint, ProjectileData projectile, Vector3 position, Vector3 heading)
        {
            if (projectilePtr == 16383)
            {
                projectilePtr = 0;
            }
            Projectiles[projectilePtr] = new Projectile()
            {
                Data     = projectile,
                Owner    = owner,
                Time     = 0,
                Alive    = true,
                Position = position,
                Start    = position,
                Normal   = heading * projectile.Velocity
            };
            SoundManager snd;

            if (world.Renderer != null && (snd = world.Renderer.Game.GetService <SoundManager>()) != null)
            {
                ulong soundID = ((ulong)owner.Unique << 32) | (ulong)hardpoint;
                if (!_instances.TryGetValue(soundID, out var inst))
                {
                    inst = snd.GetInstance(projectile.Munition.Def.OneShotSound, 0, -1, -1, position);
                    _instances[soundID] = inst;
                }

                if (inst != null)
                {
                    inst.Priority = -2;
                }
                inst?.Set3D();
                inst?.SetPosition(position);
                inst?.Stop();
                inst?.Play();
            }
            if (world.Renderer != null && projectile.TravelEffect != null)
            {
                Projectiles[projectilePtr].Effect = new ParticleEffectInstance(projectile.TravelEffect);
            }
            projectilePtr++;
        }
예제 #6
0
        public void Fire(Vector3 point)
        {
            if (CurrentCooldown > 0)
            {
                return;
            }
            if (projectiles == null)
            {
                hpfires     = Parent.GetHardpoints().Where((x) => x.Name.StartsWith("hpfire", StringComparison.CurrentCultureIgnoreCase)).ToArray();
                projectiles = Parent.GetWorld().Projectiles;
                toSpawn     = projectiles.GetData(Object);
            }
            var tr = (Parent.Attachment.Transform * Parent.Parent.GetTransform());

            for (int i = 0; i < hpfires.Length; i++)
            {
                var pos     = Vector3.Transform(Vector3.Zero, hpfires[i].Transform * tr);
                var heading = (pos - point).Normalized();
                projectiles.SpawnProjectile(toSpawn, pos, heading);
            }
            CurrentCooldown = Object.Def.RefireDelay;
        }