void Awake()
        {
            instance = (ShootObject)target;
            LoadDB();

            InitLabel();
        }
Esempio n. 2
0
        //init certain parameter based on shoot object
        public void InitShootObject()
        {
            ShootObject so = shootObject.GetComponent <ShootObject>();

            requireAiming       = (so.type == _SOType.Homing || so.type == _SOType.Point);
            randCursorForRecoil = so.type == _SOType.Point;
        }
Esempio n. 3
0
        //fire the split shootobject
        void FireSplitSO(Quaternion shootRot)
        {
            GameObject soObj = ObjectPoolManager.Spawn(thisObj, thisT.position, shootRot);

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

            soInstance.DisableCollider(0.1f);

            soInstance.srcRange = splitRange;           //limite the range of split shootobject accordingly

            if (!splitRecursively)
            {
                soInstance.splitCount = 0;
            }
            else
            {
                soInstance.splitCount = (int)Mathf.Floor(splitCount / 2);
            }

            soInstance.Shoot(srcLayer, srcRange, thisT, attInstance);
        }
Esempio n. 4
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;
                }
            }
        }
Esempio n. 5
0
        //~ IEnumerator ShootRoutine(RaycastHit hit=default(RaycastHit)){
        IEnumerator ShootRoutine(ShootObject.AimInfo aimInfo=null)
        {
            if(uAnimation!=null) uAnimation.AttackRange();

            AttackStats aStats=ModifyAttackStatsToExistingEffect(weaponList[weaponID].CloneStats());
            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;
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        //launch the ability, at the position given
        public void Activate(Vector3 pos = default(Vector3), bool useCostNCD = true)
        {
            if (useCostNCD)
            {
                currentCD = GetCooldown();                                      //set the cooldown
                GameControl.GetPlayer().energy -= GetCost();                    //deduct player energy by the ability cost
            }

            AudioManager.PlaySound(launchSFX);

            //instantiate the launch object, if there's any
            if (launchObj != null)
            {
                GameObject obj = (GameObject)MonoBehaviour.Instantiate(launchObj, pos, Quaternion.identity);
                if (autoDestroyLaunchObj)
                {
                    MonoBehaviour.Destroy(obj, launchObjActiveDuration);
                }
            }

            //for aoe ability
            if (type == _AbilityType.AOE || type == _AbilityType.AOESelf)
            {
                //get all the collider in range
                Collider[] cols = Physics.OverlapSphere(pos, GetAOERadius());
                for (int i = 0; i < cols.Length; i++)
                {
                    Unit unitInstance = cols[i].gameObject.GetComponent <Unit>();

                    //only continue if the collider is a unit and is not player
                    if (unitInstance != null && unitInstance != GameControl.GetPlayer())
                    {
                        //create an AttackInstance and mark it as AOE attack
                        AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats());
                        aInstance.isAOE       = true;
                        aInstance.aoeDistance = Vector3.Distance(pos, cols[i].transform.position);
                        //apply the AttackInstance
                        unitInstance.ApplyAttack(aInstance);
                    }
                }

                //apply explosion force
                TDSPhysics.ApplyExplosionForce(pos, aStats);
            }

            //for ability that affects all hostile unit in game
            else if (type == _AbilityType.All)
            {
                //get all hostile unit for unit tracker
                List <Unit> unitList = new List <Unit>(UnitTracker.GetAllUnitList());
                //loop through all unit, create an AttackInstance and apply the attack
                for (int i = 0; i < unitList.Count; i++)
                {
                    AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats());
                    unitList[i].ApplyAttack(aInstance);
                }
            }

            //for ability that meant to be cast on player unit
            else if (type == _AbilityType.Self)
            {
                //apply the attack on player
                AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats());
                GameControl.GetPlayer().ApplyAttack(aInstance);
            }

            //for ability that fires a shoot object
            else if (type == _AbilityType.Shoot)
            {
                //get the position and rotation to fire the shoot object from
                Transform srcT     = GetShootObjectSrcTransform();
                Vector3   shootPos = srcT.TransformPoint(shootPosOffset);
                pos.y = shootPos.y;
                Quaternion shootRot = Quaternion.LookRotation(pos - shootPos);

                //create the AttackInstance
                AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats());

                //Instantiate the shoot-object and fires it
                GameObject  soObj      = (GameObject)MonoBehaviour.Instantiate(shootObject, shootPos, shootRot);
                ShootObject soInstance = soObj.GetComponent <ShootObject>();
                soInstance.Shoot(GameControl.GetPlayer().thisObj.layer, GetRange(), srcT, aInstance);
            }

            else if (type == _AbilityType.Movement)
            {
                if (moveType == _MoveType.Blink)
                {
                    GameControl.GetPlayer().thisT.position += GameControl.GetPlayer().thisT.TransformVector(Vector3.forward * range);
                }
                else if (moveType == _MoveType.Dash)
                {
                    //GameControl.GetPlayer().thisT.position+=GameControl.GetPlayer().thisT.TransformPoint(Vector3.z)*range;
                    GameControl.GetPlayer().Dash(range, duration);
                }
                else if (moveType == _MoveType.Teleport)
                {
                    Transform playerT = GameControl.GetPlayer().thisT;
                    Vector3   tgtPos  = new Vector3(pos.x, playerT.position.y, pos.z);

                    if (Vector3.Distance(playerT.position, tgtPos) > range)
                    {
                        tgtPos = playerT.position + (tgtPos - playerT.position).normalized * range;
                    }

                    playerT.position = tgtPos;
                }
            }
        }