Example #1
0
    public override void OnAction()
    {
        if (animator)
        {
            animator.speed = animationSpeedTemp;
        }

        if (Ammo > 0 || InfinityAmmo)
        {
            if (!InfinityAmmo)
            {
                Ammo -= 1;
            }

            if (BulletNum <= 0)
            {
                BulletNum = 1;
            }

            byte spread = (byte)(Spread * spreadmult);
            byte seed   = (byte)Random.Range(0, 255 * spreadmult);


            if (this.transform.localScale == Vector3.zero)
            {
                if (character.inventory.TDEquipment != null)
                {
                    MuzzlePoint = character.inventory.TDEquipment.EffectPoint;
                }
                if (MuzzlePoint == null)
                {
                    MuzzlePoint = this.transform;
                }
            }
            else
            {
                MuzzlePoint = this.transform;
            }


            if (IsVisible)
            {
                if (MuzzleFX)
                {
                    GameObject fx = (GameObject)GameObject.Instantiate(MuzzleFX, MuzzlePoint.position, MuzzlePoint.rotation);
                    fx.transform.parent = MuzzlePoint.transform;
                    GameObject.Destroy(fx, 2);
                }

                if (audioSource && SoundFire && IsVisible)
                {
                    if (audioSource.enabled && audioSource.isActiveAndEnabled)
                    {
                        audioSource.PlayOneShot(SoundFire);
                    }
                }

                for (int i = 0; i < BulletNum; i++)
                {
                    if (Pointer)
                    {
                        Vector3 direction = (Pointer.forward + (new Vector3(Random.Range(-spread, spread) * 0.001f, Random.Range(-spread, spread) * 0.001f, Random.Range(-spread, spread) * 0.001f) * spreadmult));
                        if (ProjectileFX && fpsController)
                        {
                            GameObject.Instantiate(ProjectileFX, Pointer.position + (direction * 5), Quaternion.LookRotation(direction));
                        }
                    }
                }
            }
            if (fpsController)
            {
                fpsController.Kick(KickPower);
            }

            if (character != null)
            {
                if (Pointer)
                {
                    if (panicfire < 0.5f)
                    {
                        if (BulletNum == 1)
                        {
                            spread = 0;
                        }
                    }

                    // we can call DoDamage with all parameters usage. But, it's sending too much parameter on networking
                    //character.DoDamage(Pointer.position, Pointer.forward, BulletNum, spread, (byte)Random.Range(0, 255), (byte)Damage, Distance, MaxPenetrate, character.NetID, character.Team);
                    // so we need to registeration all weapons in Item Manager so we just send only item Index.
                    character.DoDamageByItemIndex(Pointer.position, Pointer.forward, ItemIndex, seed);
                }
            }
            panicfire += 5;
        }
        base.OnAction();
    }
    public override void OnAction()
    {
        if (animator)
        {
            animator.speed = animationSpeedTemp;
        }

        if (Ammo > 0 || InfinityAmmo)
        {
            if (!InfinityAmmo)
            {
                Ammo -= 1;
            }

            if (BulletNum <= 0)
            {
                BulletNum = 1;
            }

            byte spread = (byte)(Spread * spreadmult);
            byte seed   = (byte)Random.Range(0, 255 * spreadmult);

            if (!MuzzlePoint)
            {
                MuzzlePoint = this.transform;
            }

            if (IsVisible)
            {
                if (MuzzleFX)
                {
                    GameObject fx = (GameObject)GameObject.Instantiate(MuzzleFX, MuzzlePoint.position, MuzzlePoint.rotation);
                    fx.transform.parent = this.transform;
                    GameObject.Destroy(fx, 2);
                }

                if (audioSource && SoundFire && IsVisible)
                {
                    if (audioSource.enabled)
                    {
                        audioSource.PlayOneShot(SoundFire);
                    }
                }

                for (int i = 0; i < BulletNum; i++)
                {
                    if (Pointer)
                    {
                        Vector3 direction = (Pointer.forward + (new Vector3(Random.Range(-spread, spread) * 0.001f, Random.Range(-spread, spread) * 0.001f, Random.Range(-spread, spread) * 0.001f) * spreadmult));
                        if (ProjectileFX && fpsController)
                        {
                            GameObject.Instantiate(ProjectileFX, Pointer.position + (direction * 5), Quaternion.LookRotation(direction));
                        }
                    }
                }
            }
            if (fpsController)
            {
                fpsController.Kick(KickPower);
            }

            if (character != null)
            {
                if (Pointer)
                {
                    if (panicfire < 0.5f)
                    {
                        if (BulletNum == 1)
                        {
                            spread = 0;
                        }
                    }

                    //我们可以使用所有参数调用DoDamage。但是,它在网络上发送了太多参数
                    //character.DoDamage(Pointer.position, Pointer.forward, BulletNum, spread, (byte)Random.Range(0, 255), (byte)Damage, Distance, MaxPenetrate, character.NetID, character.Team);
                    //所以我们需要在物品管理器中注册所有武器,所以我们只发送物品索引。
                    character.DoDamageByItemIndex(Pointer.position, Pointer.forward, ItemIndex, seed);
                }
            }
            panicfire += 5;
        }
        base.OnAction();
    }
Example #3
0
    public override void OnAction()
    {
//		Debug.Log(this+" OnAction");

        if (animator)
        {
            animator.speed = animationSpeedTemp;
        }
        if (Ammo > 0 || InfinityAmmo)
        {
            if (!InfinityAmmo)
            {
                Ammo -= 1;
            }

            if (BulletNum <= 0)
            {
                BulletNum = 1;
            }

            Vector3[] dirs = new Vector3[BulletNum];

            //muzzle
            if (!MuzzlePoint)
            {
                MuzzlePoint = this.transform;
            }
            //effects sound
            PlayFireSound();

            GameObject muzzleObj = GameObject.Instantiate(MuzzleFX, MuzzlePoint);
            Destroy(muzzleObj, 3);

            for (int i = 0; i < dirs.Length; i++)
            {
                if (dirs.Length <= 1)
                {
                    panicfire = 1;
                }
//				Debug.Log(fpsController.FPSCamera);
                if (fpsController)
                {
                    dirs [i] = (fpsController.tpsCamera.MainCamera.transform.forward + (new Vector3(Random.Range(-Spread + (int)panicfire, Spread + (int)panicfire) * 0.001f, Random.Range(-Spread + (int)panicfire, Spread + (int)panicfire) * 0.001f, Random.Range(-Spread + (int)panicfire, Spread + (int)panicfire) * 0.001f) * spreadmult));
                }
                if (ProjectileFX && fpsController)
                {
                    GameObject.Instantiate(ProjectileFX, fpsController.tpsCamera.MainCamera.transform.position + (dirs [i] * 5), Quaternion.LookRotation(dirs [i]));
                }
                dirs [i] *= Force;
            }

            if (fpsController)
            {
                fpsController.Kick(KickPower);
            }

            if (character != null)
            {
                character.DoDamage(fpsController.tpsCamera.MainCamera.transform.position, dirs, Damage, Distance, MaxPenetrate, character.ID, character.Team);
            }

            panicfire += PanicFireMult;
        }

        base.OnAction();
    }