Exemplo n.º 1
0
        private static void ShootProjectile(string prefab, GameObject shooter, Vector2 direction, BodyPartType damageZone,
                                            float rangeChange)
        {
            GameObject projectile = Spawn.ClientPrefab(prefab, shooter.transform.position, shooter.transform.parent).GameObject;

            if (projectile == null)
            {
                return;
            }
            Bullet bullet = projectile.GetComponent <Bullet>();

            if (bullet == null)
            {
                return;
            }

            if (rangeChange >= 0)
            {
                if (bullet.TryGetComponent <ProjectileRangeLimited>(out var rangeLimited))
                {
                    rangeLimited.SetDistance(rangeChange);
                }
            }

            bullet.Shoot(direction, shooter, null, damageZone);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Perform and display the shot locally (i.e. only on this instance of the game). Does not
        /// communicate anything to other players (unless this is the server, in which case the server
        /// will determine the effects of the bullet). Does not do any validation. This should only be invoked
        /// when displaying the results of a shot (i.e. after receiving a ShootMessage or after this client performs a shot)
        /// or when server is determining the outcome of the shot.
        /// </summary>
        /// <param name="shooter">gameobject of the shooter</param>
        /// <param name="finalDirection">direction the shot should travel (accuracy deviation should already be factored into this)</param>
        /// <param name="damageZone">targeted damage zone</param>
        /// <param name="isSuicideShot">if this is a suicide shot (aimed at shooter)</param>
        /// <param name="projectileName">the name of the projectile that should be spawned</param>
        /// <param name="quantity">the amount of projectiles to spawn when displaying the shot</param>
        public void DisplayShot(GameObject shooter, Vector2 finalDirection,
                                BodyPartType damageZone, bool isSuicideShot, string projectileName, int quantity)
        {
            if (!MatrixManager.IsInitialized)
            {
                return;
            }

            //if this is our gun (or server), last check to ensure we really can shoot
            if (isServer || PlayerManager.LocalPlayer == shooter)
            {
                if (CurrentMagazine.ClientAmmoRemains <= 0)
                {
                    if (isServer)
                    {
                        Logger.LogTrace("Server rejected shot - out of ammo", Category.Firearms);
                    }
                    return;
                }
                CurrentMagazine.ExpendAmmo();
            }
            //TODO: If this is not our gun, simply display the shot, don't run any other logic
            if (shooter == PlayerManager.LocalPlayer)
            {
                //this is our gun so we need to update our predictions
                FireCountDown += FireDelay;
                //add additional recoil after shooting for the next round
                AppendRecoil();

                Camera2DFollow.followControl.Recoil(-finalDirection, CameraRecoilConfig);
            }

            if (isSuicideShot)
            {
                GameObject projectile = Spawn.ClientPrefab(projectileName,
                                                           shooter.transform.position, parent: shooter.transform.parent).GameObject;
                Projectile projectileComponent = projectile.GetComponent <Projectile>();
                projectileComponent.Suicide(shooter, this, damageZone);
            }
            else
            {
                for (int n = 0; n < quantity; n++)
                {
                    GameObject projectile = Spawn.ClientPrefab(projectileName,
                                                               shooter.transform.position, parent: shooter.transform.parent).GameObject;
                    Projectile projectileComponent    = projectile.GetComponent <Projectile>();
                    Vector2    finalDirectionOverride = CalcDirection(finalDirection, n);
                    projectileComponent.Shoot(finalDirectionOverride, shooter, this, damageZone);
                }
            }
            if (isSuppressed && SuppressedSoundA != null)
            {
                SoundManager.PlayAtPosition(SuppressedSoundA, shooter.transform.position, shooter);
            }
            else
            {
                SoundManager.PlayAtPosition(FiringSoundA, shooter.transform.position, shooter);
            }
            shooter.GetComponent <PlayerSprites>().ShowMuzzleFlash();
        }
        private void OnBeamEnd(Vector2 position)
        {
            var newDecal = Spawn.ClientPrefab(decal.name,
                                              position).GameObject;
            var timeLimitedDecal = newDecal.GetComponent <TimeLimitedDecal>();

            timeLimitedDecal.SetUpDecal(animationTime);
        }
Exemplo n.º 4
0
        public bool OnHit(RaycastHit2D hit)
        {
            var newDecal = Spawn.ClientPrefab(decal.name,
                                              hit.point).GameObject;
            var timeLimitedDecal = newDecal.GetComponent <TimeLimitedDecal>();

            timeLimitedDecal.SetUpDecal(animationTime);
            return(false);
        }
Exemplo n.º 5
0
    /// <summary>
    /// Perform and display the shot locally (i.e. only on this instance of the game). Does not
    /// communicate anything to other players (unless this is the server, in which case the server
    /// will determine the effects of the bullet). Does not do any validation. This should only be invoked
    /// when displaying the results of a shot (i.e. after receiving a ShootMessage or after this client performs a shot)
    /// or when server is determining the outcome of the shot.
    /// </summary>
    /// <param name="shooter">gameobject of the shooter</param>
    /// <param name="finalDirection">direction the shot should travel (accuracy deviation should already be factored into this)</param>
    /// <param name="damageZone">targeted damage zone</param>
    /// <param name="isSuicideShot">if this is a suicide shot (aimed at shooter)</param>
    public void DisplayShot(GameObject shooter, Vector2 finalDirection,
                            BodyPartType damageZone, bool isSuicideShot)
    {
        //if this is our gun (or server), last check to ensure we really can shoot
        if ((isServer || PlayerManager.LocalPlayer == shooter) &&
            CurrentMagazine.ClientAmmoRemains <= 0)
        {
            if (isServer)
            {
                Logger.LogTrace("Server rejected shot - out of ammo", Category.Firearms);
            }

            return;
        }
        //TODO: If this is not our gun, simply display the shot, don't run any other logic
        if (shooter == PlayerManager.LocalPlayer)
        {
            //this is our gun so we need to update our predictions
            FireCountDown += 1.0 / FireRate;
            //add additional recoil after shooting for the next round
            AppendRecoil();

            //Default camera recoil params until each gun is configured separately
            if (CameraRecoilConfig == null || CameraRecoilConfig.Distance == 0f)
            {
                CameraRecoilConfig = new CameraRecoilConfig
                {
                    Distance         = 0.2f,
                    RecoilDuration   = 0.05f,
                    RecoveryDuration = 0.6f
                };
            }
            Camera2DFollow.followControl.Recoil(-finalDirection, CameraRecoilConfig);
        }

        //call ExpendAmmo outside of previous check, or it won't run serverside and state will desync.
        CurrentMagazine.ExpendAmmo();

        //display the effects of the shot

        //get the bullet prefab being shot
        GameObject bullet = Spawn.ClientPrefab(Resources.Load(Projectile.name) as GameObject,
                                               shooter.transform.position).GameObject;
        BulletBehaviour b = bullet.GetComponent <BulletBehaviour>();

        if (isSuicideShot)
        {
            b.Suicide(shooter, this, damageZone);
        }
        else
        {
            b.Shoot(finalDirection, shooter, this, damageZone);
        }
        SoundManager.PlayAtPosition(FiringSound, shooter.transform.position);
        shooter.GetComponent <PlayerSprites>().ShowMuzzleFlash();
    }
Exemplo n.º 6
0
    //FileTiles are client side effects only, no need for network sync (triggered by same event on all clients/server)
    public static void SpawnFireTileClient(float fuelAmt, Vector3 localPosition, Transform parent)
    {
        EnsureInit();
        //ClientSide pool spawn
        GameObject fireObj = Spawn.ClientPrefab(fireTile, Vector3.zero).GameObject;

        //Spawn tiles need to be placed in a local matrix:
        fireObj.transform.parent        = parent;
        fireObj.transform.localPosition = localPosition;
        FireTile fT = fireObj.GetComponent <FireTile>();

        fT.StartFire(fuelAmt);
    }
Exemplo n.º 7
0
        public bool OnHit(MatrixManager.CustomPhysicsHit hit)
        {
            if (decal == null)
            {
                Logger.LogError($"{this} on {gameObject} decal field not set in inspector!");
                return(false);
            }

            var newDecal = Spawn.ClientPrefab(decal.name,
                                              hit.HitWorld).GameObject;
            var timeLimitedDecal = newDecal.GetComponent <TimeLimitedDecal>();

            timeLimitedDecal.SetUpDecal(animationTime);
            return(false);
        }
Exemplo n.º 8
0
        public bool OnHit(RaycastHit2D hit)
        {
            if (decal == null)
            {
                Logger.LogError($"{this} on {gameObject} decal field not set in inspector!");
                return(false);
            }

            var newDecal = Spawn.ClientPrefab(decal.name,
                                              hit.point).GameObject;
            var timeLimitedDecal = newDecal.GetComponent <TimeLimitedDecal>();

            timeLimitedDecal.SetUpDecal(animationTime);
            return(false);
        }
Exemplo n.º 9
0
        private static void ShootProjectile(string prefab, GameObject shooter, Vector2 direction, BodyPartType damageZone)
        {
            GameObject projectile = Spawn.ClientPrefab(prefab, shooter.transform.position, shooter.transform.parent).GameObject;

            if (projectile == null)
            {
                return;
            }
            Bullet bullet = projectile.GetComponent <Bullet>();

            if (bullet == null)
            {
                return;
            }

            bullet.Shoot(direction, shooter, null, damageZone);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Perform and display the shot locally (i.e. only on this instance of the game). Does not
        /// communicate anything to other players (unless this is the server, in which case the server
        /// will determine the effects of the bullet). Does not do any validation. This should only be invoked
        /// when displaying the results of a shot (i.e. after receiving a ShootMessage or after this client performs a shot)
        /// or when server is determining the outcome of the shot.
        /// </summary>
        /// <param name="shooter">gameobject of the shooter</param>
        /// <param name="finalDirection">direction the shot should travel (accuracy deviation should already be factored into this)</param>
        /// <param name="damageZone">targeted damage zone</param>
        /// <param name="isSuicideShot">if this is a suicide shot (aimed at shooter)</param>
        public void DisplayShot(GameObject shooter, Vector2 finalDirection,
                                BodyPartType damageZone, bool isSuicideShot, string projectileName, int quantity)
        {
            if (!MatrixManager.IsInitialized)
            {
                return;
            }

            //if this is our gun (or server), last check to ensure we really can shoot
            if (isServer || PlayerManager.LocalPlayer == shooter)
            {
                if (CurrentMagazine.ClientAmmoRemains <= 0)
                {
                    if (isServer)
                    {
                        Logger.LogTrace("Server rejected shot - out of ammo", Category.Firearms);
                    }
                    return;
                }
                CurrentMagazine.ExpendAmmo();
            }
            //TODO: If this is not our gun, simply display the shot, don't run any other logic
            if (shooter == PlayerManager.LocalPlayer)
            {
                //this is our gun so we need to update our predictions
                FireCountDown += 1.0 / FireRate;
                //add additional recoil after shooting for the next round
                AppendRecoil();

                //Default camera recoil params until each gun is configured separately
                if (CameraRecoilConfig == null || CameraRecoilConfig.Distance == 0f)
                {
                    CameraRecoilConfig = new CameraRecoilConfig
                    {
                        Distance         = 0.2f,
                        RecoilDuration   = 0.05f,
                        RecoveryDuration = 0.6f
                    };
                }
                Camera2DFollow.followControl.Recoil(-finalDirection, CameraRecoilConfig);
            }

            if (isSuicideShot)
            {
                GameObject bullet = Spawn.ClientPrefab(projectileName,
                                                       shooter.transform.position, parent: shooter.transform.parent).GameObject;
                var b = bullet.GetComponent <Projectile>();
                b.Suicide(shooter, this, damageZone);
            }
            else
            {
                for (int n = 0; n < quantity; n++)
                {
                    GameObject Abullet = Spawn.ClientPrefab(projectileName,
                                                            shooter.transform.position, parent: shooter.transform.parent).GameObject;
                    var A = Abullet.GetComponent <Projectile>();
                    var finalDirectionOverride = CalcDirection(finalDirection, n);
                    A.Shoot(finalDirectionOverride, shooter, this, damageZone);
                }
            }
            SoundManager.PlayAtPosition(FiringSound, shooter.transform.position, shooter);
            shooter.GetComponent <PlayerSprites>().ShowMuzzleFlash();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Perform and display the shot locally (i.e. only on this instance of the game). Does not
        /// communicate anything to other players (unless this is the server, in which case the server
        /// will determine the effects of the bullet). Does not do any validation. This should only be invoked
        /// when displaying the results of a shot (i.e. after receiving a ShootMessage or after this client performs a shot)
        /// or when server is determining the outcome of the shot.
        /// </summary>
        /// <param name="shooter">gameobject of the shooter</param>
        /// <param name="finalDirection">direction the shot should travel (accuracy deviation should already be factored into this)</param>
        /// <param name="damageZone">targeted damage zone</param>
        /// <param name="isSuicideShot">if this is a suicide shot (aimed at shooter)</param>
        public void DisplayShot(GameObject shooter, Vector2 finalDirection,
                                BodyPartType damageZone, bool isSuicideShot)
        {
            if (!MatrixManager.IsInitialized)
            {
                return;
            }

            //if this is our gun (or server), last check to ensure we really can shoot
            if ((isServer || PlayerManager.LocalPlayer == shooter) &&
                CurrentMagazine.ClientAmmoRemains <= 0)
            {
                if (isServer)
                {
                    Logger.LogTrace("Server rejected shot - out of ammo", Category.Firearms);
                }

                return;
            }
            if (shooter == PlayerManager.LocalPlayer)
            {
                //this is our gun so we need to update our predictions
                FireCountDown += 1.0 / FireRate;
                //add additional recoil after shooting for the next round
                AppendRecoil();

                //Default camera recoil params until each gun is configured separately
                if (CameraRecoilConfig == null || CameraRecoilConfig.Distance == 0f)
                {
                    CameraRecoilConfig = new CameraRecoilConfig
                    {
                        Distance         = 0.2f,
                        RecoilDuration   = 0.05f,
                        RecoveryDuration = 0.6f
                    };
                }
                Camera2DFollow.followControl.Recoil(-finalDirection, CameraRecoilConfig);

                if (CurrentMagazine == null)
                {
                    Logger.LogWarning($"Why is {nameof(CurrentMagazine)} null for {this} on this client?");
                }
                else
                {
                    //call ExpendAmmo outside of previous check, or it won't run serverside and state will desync.
                    CurrentMagazine.ExpendAmmo();
                }
            }

            MagazineBehaviour magazine = ammoPrefab.GetComponent <MagazineBehaviour>();

            if (isSuicideShot)
            {
                GameObject bullet = Spawn.ClientPrefab(magazine.Projectile.name,
                                                       shooter.transform.position, parent: shooter.transform.parent).GameObject;
                var b = bullet.GetComponent <Projectile>();
                b.Suicide(shooter, this, damageZone);
            }
            else
            {
                for (int n = 0; n < magazine.ProjectilesFired; n++)
                {
                    GameObject Abullet = Spawn.ClientPrefab(magazine.Projectile.name,
                                                            shooter.transform.position, parent: shooter.transform.parent).GameObject;
                    var A = Abullet.GetComponent <Projectile>();
                    var finalDirectionOverride = CalcDirection(finalDirection, n);
                    A.Shoot(finalDirectionOverride, shooter, this, damageZone);
                }
            }
            SoundManager.PlayAtPosition(FiringSound, shooter.transform.position, shooter);
            shooter.GetComponent <PlayerSprites>().ShowMuzzleFlash();
        }