コード例 #1
0
        private void Punch()
        {
            var weaponSound = WeaponSound.Create(GlobalTargets.Everyone, ReliabilityModes.Unreliable);

            weaponSound.Position = transform.position;
            weaponSound.Label    = weapon.Label;
            weaponSound.Player   = player.entity;
            weaponSound.Send();

            /*if (!Physics.SphereCast(player.playerCamera.transform.position, weapon.Radius,
             *  player.playerCamera.transform.forward, out var hit,
             *  weapon.MaxDistance)) return;*/

            var hits = Physics.SphereCastAll(player.playerCamera.transform.position, weapon.Radius,
                                             player.playerCamera.transform.forward, weapon.MaxDistance);

            foreach (var hit in hits)
            {
                var boltEntity = hit.transform.GetComponent <BoltEntity>();

                if (boltEntity == null || boltEntity.GetState <IPlayer>() == null || boltEntity.GetState <IPlayer>().Entity == player.entity)
                {
                    return;
                }

                var playerHit = PlayerHit.Create(GlobalTargets.OnlyServer);
                playerHit.Target        = boltEntity;
                playerHit.PlayerWhoShot = player.state.Username;
                playerHit.WeaponName    = weapon.Label;
                playerHit.Damage        = weapon.Damage;
                playerHit.Send();
            }
        }
コード例 #2
0
        private void Shoot(int spreadFactor)
        {
            var weaponFired = WeaponFired.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);

            weaponFired.WeaponId = weapon.Id;
            weaponFired.Entity   = weapon.Player;
            weaponFired.Send();

            var weaponSound = WeaponSound.Create(GlobalTargets.Everyone, ReliabilityModes.Unreliable);

            weaponSound.Position = transform.position;
            weaponSound.Label    = weapon.Label;
            weaponSound.Player   = player.entity;
            weaponSound.Send();

            var dir = Spread(spreadFactor);

            if (!Physics.Raycast(cameraTransform.transform.position, dir, out var hit, 100))
            {
                return;
            }

            if (hit.transform.CompareTag("Stalin"))
            {
                AudioSource soundSource = hit.transform.GetComponent <AudioSource>();
                if (!soundSource.isPlaying)
                {
                    soundSource.Play();
                }
            }

            var boltEntity = hit.transform.GetComponent <BoltEntity>();

            if (boltEntity != null && boltEntity.GetState <IPlayer>() != null)
            {
                var playerHit = PlayerHit.Create(GlobalTargets.OnlyServer);
                playerHit.Target        = boltEntity;
                playerHit.PlayerWhoShot = player.state.Username;
                playerHit.WeaponName    = weapon.Label;
                playerHit.Damage        = weapon.Damage;
                playerHit.Send();


                var applyHitIndicator = ApplyHitIndicator.Create(ReliabilityModes.Unreliable);
                applyHitIndicator.Message  = "Damage: " + weapon.Damage;
                applyHitIndicator.Position = hit.point;
                applyHitIndicator.Send();
            }
            else
            {
                var impactEffect = ImpactEffect.Create(ReliabilityModes.Unreliable);
                impactEffect.Position = hit.point;
                impactEffect.Send();
            }
        }