Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        public void TriggerPlayerHitEvent()
        {
            PlayerHit playerHitEvent = PlayerHit.Create();

            playerHitEvent.VictimEntity = SWExtensions.KartExtensions.GetKartWithID(SWMatchmaking.GetMyBoltId()).GetComponent <BoltEntity>();
            playerHitEvent.Send();
        }
Ejemplo n.º 3
0
        public override void OnEvent(CreateSplash createSplash)
        {
            var splash = Instantiate(splashEffect, createSplash.Position, Quaternion.identity);

            Destroy(splash, 2f);

            var hits = Physics.SphereCastAll(createSplash.Position, createSplash.Radius, Vector3.one);

            foreach (var hit in hits)
            {
                var player = hit.transform.GetComponent <Player>();
                if (player == null)
                {
                    continue;
                }

                if (player.entity.HasControl)
                {
                    var playerHit = PlayerHit.Create(GlobalTargets.OnlyServer, ReliabilityModes.ReliableOrdered);
                    playerHit.Damage        = createSplash.Damage;
                    playerHit.Target        = player.entity;
                    playerHit.WeaponName    = "Sponge";
                    playerHit.PlayerWhoShot = createSplash.PlayerWhoShot.GetState <IPlayer>().Username;
                    playerHit.Send();

                    break;
                }
            }
        }
Ejemplo n.º 4
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();
            }
        }
Ejemplo n.º 5
0
        private void SendPlayerHitEvent(Ownership itemOwnership)
        {
            PlayerHit playerHitEvent = PlayerHit.Create();

            playerHitEvent.KillerID     = itemOwnership.OwnerID;
            playerHitEvent.KillerName   = itemOwnership.OwnerNickname;
            playerHitEvent.KillerTeam   = (int)itemOwnership.Team;
            playerHitEvent.Item         = itemOwnership.Label;
            playerHitEvent.VictimEntity = entity;
            playerHitEvent.VictimID     = state.OwnerID;
            playerHitEvent.VictimName   = GetComponentInParent <Multiplayer.PlayerInfo>().Nickname;
            playerHitEvent.VictimTeam   = state.Team;
            playerHitEvent.Send();
        }
Ejemplo n.º 6
0
        private void SendPlayerHitAndRemove(Collider other)
        {
            IKartState victimKartState;
            BoltEntity victimEntity = other.GetComponentInParent <BoltEntity>();

            if (victimEntity.TryFindState <IKartState>(out victimKartState))
            {
                PlayerHit playerHitEvent = PlayerHit.Create();
                playerHitEvent.KillerID     = _ownership.OwnerID;
                playerHitEvent.KillerName   = _ownership.OwnerNickname;
                playerHitEvent.KillerTeam   = (int)_ownership.Team;
                playerHitEvent.Item         = _ownership.Label;
                playerHitEvent.VictimEntity = victimEntity;
                playerHitEvent.VictimID     = victimKartState.OwnerID;
                playerHitEvent.VictimName   = victimEntity.GetComponent <PlayerInfo>().Nickname;
                playerHitEvent.VictimTeam   = (int)victimKartState.Team;
                playerHitEvent.Send();
            }
            else
            {
                Debug.LogError("Could not find the victim's attached state.");
            }
            TryRemoveFromLists(other);
        }