Example #1
0
        void Awake()
        {
            instance = this;

            //QualitySettings.vSyncCount=1;
            //Application.targetFrameRate=60;

            //get the unit in game
            player = (UnitPlayer)FindObjectOfType(typeof(UnitPlayer));

            //setup the collision rules
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerShootObject(), !shootObject);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerCollectible(), !collectible);

            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTerrain(), true);
            Physics.IgnoreLayerCollision(TDS.GetLayerShootObject(), TDS.GetLayerTrigger(), true);

            //clear all the spawner and tracker sicne it's a new game
            UnitTracker.Clear();
            UnitSpawnerTracker.Clear();

            //this is not required, each individual unit and spawner will register itself to the tracker
            //UnitTracker.ScanForUnit();
            //UnitSpawnerTracker.ScanForSpawner();
        }
Example #2
0
        //apply effect to all active hostile unit
        void ApplyEffectAll()
        {
            //get all active hostile unit from UnitTracker
            List <Unit> unitList = UnitTracker.GetAllUnitList();

            for (int i = 0; i < unitList.Count; i++)
            {
                //clone the attack stats so that the original value wont get modified when making further calculation
                AttackInstance aInstance = new AttackInstance();
                aInstance.aStats = aStats.Clone();
                unitList[i].ApplyAttack(aInstance);
            }
        }
Example #3
0
        public virtual void Start()
        {
            //assign a unique ID to the unit instance
            instanceID = GameControl.GetUnitInstanceID();

            //add to UnitTracker if this is a hostile unit
            if (hostileUnit)
            {
                UnitTracker.AddUnit(this);
            }

            TDS.NewUnit(this);
        }
Example #4
0
        public IEnumerator _ClearUnit(bool showDestroyEffect = true, float delay = 0)
        {
            destroyed = true;

            //if the unit is spawned from a spawner for a parcicular wave, inform the spawner that a unit in the wave is cleared
            if (spawner != null && waveID >= 0)
            {
                spawner.UnitCleared(waveID);
            }

            //remove the unit from UnitTracker and inform GameControl (to check for objective)
            if (hostileUnit)
            {
                UnitTracker.RemoveUnit(this);
                GameControl.UnitDestroyed(this);
            }

            //clear all the effects on the unit
            for (int i = 0; i < effectList.Count; i++)
            {
                effectList[i].expired = true;
            }

            //call all the destroy callback, if there's any
            for (int i = 0; i < destroyCallbackList.Count; i++)
            {
                destroyCallbackList[i]();
            }

            //spawn the destroy effect
            if (showDestroyEffect)
            {
                DestroyedEffect(thisT.position + new Vector3(0, 0.1f, 0));
            }

            if (delay > 0)
            {
                yield return(new WaitForSeconds(delay));
            }

            //if(destroyParent) Destroy(thisT.parent.gameObject);

            Destroy(thisObj);

            yield return(null);
        }
Example #5
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;
                }
            }
        }
Example #6
0
        //function call to check all the objective has been completed
        public void CheckObjectiveComplete()
        {
            bool cleared = true;

            //objective status set to true by default, it will be set to false if any of the objective condition is not full-filled
            //cleared flag will then be use when calling GameControl.GameOver, indicate if player win/lose the level

            //if require to wait for timer but time is not up yet, dont proceed
            if (waitForTimer && !GameControl.TimesUp())
            {
                return;
            }

            //if scoring criteria not full filled, set cleared to false
            if (enableScoring && !scored)
            {
                cleared = false;
            }


            if (colPrefabList.Count > 0)
            {
                for (int i = 0; i < colPrefabList.Count; i++)
                {
                    if (colPrefabCountList[i] > colPrefabCollectedCountList[i])
                    {
                        cleared = false;
                        break;
                    }
                }
            }

            //if(clearAllCol){	//if clear all collectible is required and not all collectible is collected, set clear to false
            //	if(GetAllCollectibleCount>0) cleared=false;
            //}
            if (collectibleList.Count > 0)
            {
                cleared = false;                                                //if not all require collectible required has been collectible
            }
            //if either of the prefab kill count is not adequate, set cleared to false
            if (prefabList.Count > 0)
            {
                for (int i = 0; i < prefabList.Count; i++)
                {
                    if (prefabCountList[i] > prefabKillCountList[i])
                    {
                        cleared = false;
                        break;
                    }
                }
            }

            if (clearAllHostile)                //if clear all hostile is required and not all unit is destroyed, set clear to false
            {
                if (UnitTracker.GetUnitCount() > 0)
                {
                    cleared = false;
                }
            }
            else                //if not all the target unit has been destroyed, set clear to false
            {
                if (unitList.Count > 0)
                {
                    cleared = false;
                }
            }

            if (clearAllSpawner)                //if clear all spawner is required and not all spawner is cleared/destroyed, set clear to false
            {
                if (UnitSpawnerTracker.GetSpawnerCount() > 0)
                {
                    cleared = false;
                }
            }
            else                //if not all the spawner has been cleared/destroyed, set clear to false
            {
                if (spawnerList.Count > 0)
                {
                    cleared = false;
                }
            }

            //if time is up, consider game is complete and call GameOver
            if (GameControl.TimesUp())
            {
                isComplete = true;
                GameControl.GameOver(cleared);
            }
            //else if we dont need to wait for timer and the objective is cleared, call GameOver
            else if (!waitForTimer)
            {
                if (cleared)
                {
                    isComplete = true;
                    GameControl.GameOver(cleared);
                }
            }
        }