Пример #1
0
        IEnumerator ShootRoutine(ShootObject.AimInfo aimInfo = null)
        {
            if (uAnimation != null)
            {
                uAnimation.AttackRange();
            }

            AttackStats aStats = ModifyAttackStatsToLevel(weaponList[weaponID].GetRuntimeAttackStats());

            aStats = ModifyAttackStatsToExistingEffect(aStats);
            //aStats=ModifyAttackStatsToExistingEffect(weaponList[weaponID].GetRuntimeAttackStats());
            AttackInstance aInstance = new AttackInstance(this, aStats);

            int weapID = weaponID;              //to prevent weapon switch and state change while delay and firing multiple so

            int spread = weaponList[weapID].spread;

            if (spread > 1)
            {
                aInstance.aStats.damageMin /= spread;
                aInstance.aStats.damageMax /= spread;
            }

            float startAngle = spread > 1 ? -weaponList[weapID].spreadAngle / 2f : 0;
            float angleDelta = spread > 1 ? weaponList[weapID].spreadAngle / (spread - 1) : 0;

            List <Collider> soColliderList = new List <Collider>();             //colliders of all the so fired, used to tell each so to ignore each other

            for (int i = 0; i < weaponList[weapID].shootPointList.Count; i++)
            {
                Transform shootPoint = weaponList[weapID].shootPointList[i];

                float recoilSign = (Random.value < recoilSignTH ? -1 : 1);
                recoilSignTH = Mathf.Clamp(recoilSignTH + (recoilSign > 0 ? 0.25f : -0.25f), 0, 1);
                float      recoilValue  = recoilSign * Random.Range(0.1f, 1f) * GetRecoil();
                Quaternion baseShootRot = shootPoint.rotation * Quaternion.Euler(0, recoilValue, 0);

                for (int m = 0; m < Mathf.Max(1, spread); m++)
                {
                    Vector3 shootPos = shootPoint.position;
                    if (spread > 1)
                    {
                        shootPos = shootPoint.TransformPoint(new Vector3(0, 0, Random.Range(-1.5f, 1.5f)));
                    }
                    Quaternion shootRot = baseShootRot * Quaternion.Euler(0, startAngle + (m * angleDelta), 0);

                    //GameObject soObj=(GameObject)Instantiate(weaponList[weapID].shootObject, shootPos, shootRot);
                    GameObject  soObj      = ObjectPoolManager.Spawn(weaponList[weapID].shootObject, shootPos, shootRot);
                    ShootObject soInstance = soObj.GetComponent <ShootObject>();

                    soInstance.IgnoreCollider(GetCollider());
                    for (int n = 0; n < soColliderList.Count; n++)
                    {
                        soInstance.IgnoreCollider(soColliderList[n]);
                    }
                    if (soInstance.GetCollider() != null)
                    {
                        soColliderList.Add(soInstance.GetCollider());
                    }

                    soInstance.Shoot(thisObj.layer, GetRange(), shootPoint, aInstance.Clone(), aimInfo);
                    //soInstance.Shoot(thisObj.layer, GetRange(), shootPoint, aInstance.Clone(), hit);
                }

                TDS.CameraShake(weaponList[weapID].recoilCamShake);

                if (weaponList[weapID].shootPointDelay > 0)
                {
                    yield return(new WaitForSeconds(weaponList[weapID].shootPointDelay));
                }

                if (weapID >= weaponList.Count)
                {
                    break;
                }
            }
        }
Пример #2
0
        //fire main weapon
        public void FireWeapon()
        {
            if(destroyed) return;

            int fireState=CanFire();
            if(fireState==0){
                if(weaponList[weaponID].RequireAiming()){
                    Vector2 cursorPos=Input.mousePosition;

                    if(weaponList[weaponID].RandCursorForRecoil()){
                        float recoil=GameControl.GetPlayer().GetRecoil()*4;
                        cursorPos+=new Vector2(Random.value-0.5f, Random.value-0.5f)*recoil;
                    }

                    Ray ray = Camera.main.ScreenPointToRay(cursorPos);
                    RaycastHit hit;
                    //LayerMask mask=1<<TDS.GetLayerTerrain();
                    //Physics.Raycast(ray, out hit, Mathf.Infinity, mask);
                    Physics.Raycast(ray, out hit, Mathf.Infinity);

                    ShootObject.AimInfo aimInfo=new ShootObject.AimInfo(hit);

                    StartCoroutine(ShootRoutine(aimInfo));
                }
                else StartCoroutine(ShootRoutine());

                weaponList[weaponID].Fire();
            }
            else{
                string text="";
                if(fireState==1) text="attack disabled";
                if(fireState==2) text="weapon's on cooldown";
                if(fireState==3) text="weapon's out of ammo";
                if(fireState==4) text="weapon's reloading";
                TDS.FireFail(text);

                if(GetCurrentClip()==0 && GameControl.EnableAutoReload()) weaponList[weaponID].Reload();
            }
        }
Пример #3
0
        //fire main weapon
        public void FireWeapon()
        {
            if (destroyed || IsStunned())
            {
                return;
            }
            if (!thisObj.activeInHierarchy)
            {
                return;
            }

            int fireState = CanFire();

            if (fireState == 0)
            {
                if (weaponList[weaponID].RequireAiming())
                {
                    Vector2 cursorPos = Input.mousePosition;

                    if (weaponList[weaponID].RandCursorForRecoil())
                    {
                        float recoil = GameControl.GetPlayer().GetRecoil() * 4;
                        cursorPos += new Vector2(Random.value - 0.5f, Random.value - 0.5f) * recoil;
                    }

                    Ray        ray = Camera.main.ScreenPointToRay(cursorPos);
                    RaycastHit hit;
                    //LayerMask mask=1<<TDS.GetLayerTerrain();
                    //Physics.Raycast(ray, out hit, Mathf.Infinity, mask);
                    Physics.Raycast(ray, out hit, Mathf.Infinity);

                    ShootObject.AimInfo aimInfo = new ShootObject.AimInfo(hit);

                    StartCoroutine(ShootRoutine(aimInfo));
                }
                else
                {
                    StartCoroutine(ShootRoutine());
                }

                weaponList[weaponID].Fire();
            }
            else
            {
                string text = "";
                if (fireState == 1)
                {
                    text = "attack disabled";
                }
                if (fireState == 2)
                {
                    text = "weapon's on cooldown";
                }
                if (fireState == 3)
                {
                    text = "weapon's out of ammo";
                }
                if (fireState == 4)
                {
                    text = "weapon's reloading";
                }
                TDS.FireFail(text);

                if (GetCurrentClip() == 0 && GameControl.EnableAutoReload())
                {
                    weaponList[weaponID].Reload();
                }
            }
        }
Пример #4
0
        IEnumerator _ShootTarget(float targetDist)
        {
            if (targetDist > GetRange())
            {
                yield break;                    //if target is out of range, dont continue
            }
            currentCD = cooldown;               //set the cooldown

            if (uAnimation != null)
            {
                uAnimation.AttackRange();                               //play the attack animation
            }
            List <Collider> soColliderList = new List <Collider>();     //colliders of all the shoot-objs fired, used to tell each so to ignore each other

            //loop through the shoot-points, fire an shoot-object for each of them
            for (int i = 0; i < shootPointList.Count; i++)
            {
                //create a new attak instance for the attack
                AttackInstance attInstance = new AttackInstance(this, ModifyAttackStatsToExistingEffect(attackStats.Clone()));

                //record the target position, in case the target get destroyed before all shoot point has fired
                if (target != null)
                {
                    targetLastPos = target.thisT.position;
                }

                //create an aimInfo instance for the shootObject
                ShootObject.AimInfo aimInfo = target != null ? new ShootObject.AimInfo(target) : new ShootObject.AimInfo(targetLastPos);

                //get the shoot rotation
                Quaternion shootRot = shootPointList[i].rotation;
                if (alwaysShootTowardsTarget && target != null)
                {
                    shootRot = Quaternion.LookRotation(target.thisT.position - thisT.position);
                }

                //spawn the shootobject
                GameObject soObj = ObjectPoolManager.Spawn(shootObject, shootPointList[i].position, shootRot);

                ShootObject soInstance = soObj.GetComponent <ShootObject>();

                //inform the shootobject to ignore the certain collider
                soInstance.IgnoreCollider(GetCollider());
                for (int n = 0; n < soColliderList.Count; n++)
                {
                    soInstance.IgnoreCollider(soColliderList[n]);
                }
                if (soInstance.GetCollider() != null)
                {
                    soColliderList.Add(soInstance.GetCollider());
                }

                //fire the shootobject
                soInstance.Shoot(thisObj.layer, GetRange(), shootPointList[i], attInstance, aimInfo);

                //delay a bit before the next shoot point, if a delay has been specified
                if (shootPointDelay > 0)
                {
                    yield return(new WaitForSeconds(shootPointDelay));
                }
            }

            yield return(null);
        }