コード例 #1
0
ファイル: Weapon.cs プロジェクト: mybluecorners/unitystation
    public void ServerShoot(GameObject shotBy, Vector2 direction, string bulletName,
                            BodyPartType damageZone, bool isSuicideShot)
    {
        PlayerMove shooter = shotBy.GetComponent <PlayerMove>();

        if (!shooter.allowInput || shooter.isGhost)
        {
            return;
        }

        Shoot(shotBy, direction, bulletName, damageZone, isSuicideShot);

        //This is used to determine where bullet shot should head towards on client
        Ray2D ray = new Ray2D(shotBy.transform.position, direction);

        ShootMessage.SendToAll(gameObject, ray.GetPoint(30f), bulletName, damageZone, shotBy);

        if (SpawnsCaseing)
        {
            if (casingPrefab == null)
            {
                casingPrefab = Resources.Load("BulletCasing") as GameObject;
            }
            ItemFactory.SpawnItem(casingPrefab, shotBy.transform.position, shotBy.transform.parent);
        }
    }
コード例 #2
0
    private void DequeueAndProcessServerShot()
    {
        if (queuedShots.Count > 0)
        {
            QueuedShot nextShot = queuedShots.Dequeue();

            // check if we can still shoot
            PlayerMove   shooter       = nextShot.shooter.GetComponent <PlayerMove>();
            PlayerScript shooterScript = nextShot.shooter.GetComponent <PlayerScript>();
            if (!shooter.allowInput || shooterScript.IsGhost)
            {
                Logger.Log("A player tried to shoot when not allowed or when they were a ghost.", Category.Exploits);
                Logger.LogWarning("A shot was attempted when shooter is a ghost or is not allowed to shoot.", Category.Firearms);
                return;
            }


            if (CurrentMagazine == null || CurrentMagazine.ServerAmmoRemains <= 0 || Projectile == null)
            {
                Logger.LogTrace("Player tried to shoot when there was no ammo.", Category.Exploits);
                Logger.LogWarning("A shot was attempted when there is no ammo.", Category.Firearms);
                return;
            }

            if (FireCountDown > 0)
            {
                Logger.LogTrace("Player tried to shoot too fast.", Category.Exploits);
                Logger.LogWarning("Shot was attempted to be dequeued when the fire count down is not yet at 0.", Category.Exploits);
                return;
            }

            //perform the actual server side shooting, creating the bullet that does actual damage
            DisplayShot(nextShot.shooter, nextShot.finalDirection, nextShot.damageZone, nextShot.isSuicide);

            //trigger a hotspot caused by gun firing
            registerTile.Matrix.ReactionManager.ExposeHotspotWorldPosition(nextShot.shooter.TileWorldPosition(), 3200, 0.005f);

            //tell all the clients to display the shot
            ShootMessage.SendToAll(nextShot.finalDirection, nextShot.damageZone, nextShot.shooter, this.gameObject, nextShot.isSuicide);

            //kickback
            shooterScript.pushPull.Pushable.NewtonianMove((-nextShot.finalDirection).NormalizeToInt());

            if (SpawnsCaseing)
            {
                if (casingPrefab == null)
                {
                    casingPrefab = Resources.Load("BulletCasing") as GameObject;
                }

                Spawn.ServerPrefab(casingPrefab, nextShot.shooter.transform.position, nextShot.shooter.transform.parent);
            }
        }
    }
コード例 #3
0
    /// <summary>
    /// Tell all clients + server to perform a shot with the specified parameters.
    /// </summary>
    /// <param name="direction">Direction of shot from shooter</param>
    /// <param name="damageZone">body part being targeted</param>
    /// <param name="shooter">gameobject of player making the shot</param>
    /// <param name="isSuicide">if the shooter is shooting themselves</param>
    /// <returns></returns>
    public static ShootMessage SendToAll(Vector2 direction, BodyPartType damageZone, GameObject shooter, GameObject weapon, bool isSuicide)
    {
        var msg = new ShootMessage {
            Weapon        = weapon ? weapon.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
            Direction     = direction,
            DamageZone    = damageZone,
            Shooter       = shooter ? shooter.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
            IsSuicideShot = isSuicide
        };

        msg.SendToAll();
        return(msg);
    }
コード例 #4
0
    //public static ShootMessage Send(GameObject weapon, Vector2 endPos, string bulletName,
    //									BodyPartType damageZone, GameObject shotBy)
    //{
    //	var msg = new ShootMessage {

    //	};
    //	msg.SendTo(recipient);
    //	return msg;
    //}

    /// <param name="transformedObject">object to hide</param>
    /// <param name="state"></param>
    /// <param name="forced">
    ///     Used for client simulation, use false if already updated by prediction
    ///     (to avoid updating it twice)
    /// </param>
    public static ShootMessage SendToAll(GameObject weapon, Vector2 endPos, string bulletName,
                                         BodyPartType damageZone, GameObject shotBy)
    {
        var msg = new ShootMessage {
            Weapon     = weapon ? weapon.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
            EndPos     = endPos,
            BulletName = bulletName,
            DamageZone = damageZone,
            ShotBy     = shotBy ? shotBy.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid
        };

        msg.SendToAll();
        return(msg);
    }
コード例 #5
0
ファイル: Weapon.cs プロジェクト: JacobSweeten/unitystation
    private void DequeueAndProcessServerShot()
    {
        if (queuedShots.Count > 0)
        {
            QueuedShot nextShot = queuedShots.Dequeue();

            // check if we can still shoot
            PlayerMove   shooter       = nextShot.shooter.GetComponent <PlayerMove>();
            PlayerScript shooterScript = nextShot.shooter.GetComponent <PlayerScript>();
            if (!shooter.allowInput || shooterScript.IsGhost)
            {
                Logger.Log("A player tried to shoot when not allowed or when they were a ghost.", Category.Exploits);
                Logger.LogWarning("A shot was attempted when shooter is a ghost or is not allowed to shoot.", Category.Firearms);
                return;
            }


            if (CurrentMagazine == null || CurrentMagazine.ammoRemains <= 0 || Projectile == null)
            {
                Logger.LogTrace("Player tried to shoot when there was no ammo.", Category.Exploits);
                Logger.LogWarning("A shot was attempted when there is no ammo.", Category.Firearms);
                return;
            }

            if (FireCountDown > 0)
            {
                Logger.LogTrace("Player tried to shoot too fast.", Category.Exploits);
                Logger.LogWarning("Shot was attempted to be dequeued when the fire count down is not yet at 0.", Category.Exploits);
                return;
            }

            //perform the actual server side shooting, creating the bullet that does actual damage
            DisplayShot(nextShot.shooter, nextShot.finalDirection, nextShot.damageZone, nextShot.isSuicide);

            //tell all the clients to display the shot
            ShootMessage.SendToAll(nextShot.finalDirection, nextShot.damageZone, nextShot.shooter, this.gameObject, nextShot.isSuicide);

            if (SpawnsCaseing)
            {
                if (casingPrefab == null)
                {
                    casingPrefab = Resources.Load("BulletCasing") as GameObject;
                }

                PoolManager.PoolNetworkInstantiate(casingPrefab, nextShot.shooter.transform.position, nextShot.shooter.transform.parent);
            }
        }
    }