Beispiel #1
0
        //for apply damage directly, not in used
        public void ApplyDamage(float damage)
        {
            if (immunityCounter > 0)
            {
                return;
            }

            //show the overlay (for UI)
            Vector3 offsetPos = new Vector3(0, Random.value + 0.5f, 0);

            new TextOverlay(thisT.position + offsetPos, damage.ToString("f0"));

            //if the unit is player, fire event to inform UI
            if (thisObj.layer == TDS.GetLayerPlayer())
            {
                TDS.PlayerDamaged(damage);
            }

            //register the stagger
            hpRegenStaggerCounter = hpRegenStagger;

            hitPoint -= damage;                 //damage the hitpoint
            if (hitPoint <= 0)
            {
                Destroyed();
            }

            if (hitPoint > 0 && uAnimation != null)
            {
                uAnimation.Hit();
            }
        }
Beispiel #2
0
        public void Init()
        {
            if (init)
            {
                return;
            }
            init = true;

            thisT         = transform;
            thisObj       = gameObject;
            thisObj.layer = TDS.GetLayerShootObject();

            if (type == _SOType.Simple || type == _SOType.Homing)
            {
                //hitRadius=thisObj.GetComponent<SphereCollider>().radius;
                //destroyTime=100f/speed;
                InitProjectile();
            }
            else if (type == _SOType.Beam)
            {
                speed = 9999;
            }

            if (shootEffect != null)
            {
                ObjectPoolManager.New(shootEffect, 1);
            }
            if (hitEffect != null)
            {
                ObjectPoolManager.New(hitEffect, 1);
            }
        }
Beispiel #3
0
        public void _LaunchAbility(int index = -1)
        {
            if (instance == null)
            {
                return;
            }

            //make sure we have a valid selected ability
            index = index < 0 ? selectedID : index;
            if (index < 0 || index >= abilityList.Count)
            {
                return;
            }

            //check if the selected ability is ready
            string status = abilityList[index].IsReady();

            //if the abilty is not ready, fire event explaining why (for UI)
            if (status != "")
            {
                TDS.AbilityActivationFailFail(status);
                return;
            }

            //call function to launch ability
            LaunchAbility(abilityList[index]);
        }
Beispiel #4
0
        //when any collider trigger the collider of this collectible
        void OnTriggerEnter(Collider col)
        {
            //only carry on if the trigger object is player
            if (col.gameObject.layer != TDS.GetLayerPlayer())
            {
                return;
            }

            //check the effect type and apply them accordingly
            if (type == _CollectType.Self)              //apply effect to player unit
            {
                ApplyEffectSelf(col.gameObject.GetComponent <UnitPlayer>());
            }
            else if (type == _CollectType.AOEHostile)           //apply effect to all surrounding hostile
            {
                ApplyEffectAOE(col);
            }
            else if (type == _CollectType.AllHostile)                   //apply effect to all hostile
            {
                ApplyEffectAll();
            }
            else if (type == _CollectType.Ability)
            {
                AbilityManager.TriggerAbility(abilityID);
            }

            GameControl.ColletibleCollected(this);

            //play the sound and show spawn the trigger effect object at current position
            AudioManager.PlaySound(triggerSFX);
            TriggeredEffect(transform.position + new Vector3(0, 0.1f, 0));

            //Destroy(gameObject);
            ObjectPoolManager.Unspawn(gameObject);
        }
Beispiel #5
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();
        }
Beispiel #6
0
        public void _PlayerDestroyed()
        {
            TDS.PlayerDestroyed();

            if (respawning)
            {
                return;
            }

            //player unit is destroyed, check playerLife and respawn player if need be

            playerLife -= 1;

            if (playerLife <= 0)                //playerLife's used up, game over
            {
                GameOver(false);
                return;
            }

            respawning = true;                  //set respawning flag to true to prevent duplicate spawn

            //create a duplicate of current player unit so the selected weapon and ability is retained
            GameObject obj = (GameObject)Instantiate(player.gameObject, player.thisT.position, player.thisT.rotation);

            player          = obj.GetComponent <UnitPlayer>();
            player.hitPoint = player.GetFullHitPoint();
            player.Start();
            player.ClearAllEffect();

            //set the new player unit to false to give it a little delay before showing it again
            obj.SetActive(false);

            //call the coroutine which will do the delay and reactivate the new unit
            StartCoroutine(ActivateRepawnPlayer());
        }
Beispiel #7
0
        void Awake()
        {
            gameObject.GetComponent <Collider>().isTrigger = true;
            gameObject.layer = TDS.GetLayerCollectible();

            if (type == _CollectType.Self)
            {
                //initiate the weapon list to contain all weapon if the condition is checked
                if (gainWeapon && randomWeapon && enableAllWeapon)
                {
                    weaponList = new List <Weapon>(WeaponDB.Load());
                }

                //make sure none of the element in weaponList is null
                for (int i = 0; i < weaponList.Count; i++)
                {
                    if (weaponList[i] == null)
                    {
                        weaponList.RemoveAt(i); i -= 1;
                    }
                }
            }

            //effect=EffectDB.CloneItem(effectID);
            effectIdx = EffectDB.GetEffectIndex(effectID);

            if (triggerEffectObj != null)
            {
                ObjectPoolManager.New(triggerEffectObj, 1);
            }
        }
Beispiel #8
0
        //spawn the an unit instance of given the prefab
        private UnitAI SpawnUnit(GameObject prefab, Vector3 spawnPos, Quaternion rot, string name = "")
        {
            //instantiate the unit, assign the layer and name
            //~ GameObject unitObj=(GameObject)Instantiate(prefab, spawnPos, rot);
            GameObject unitObj = ObjectPoolManager.Spawn(prefab, spawnPos, rot);

            unitObj.layer = TDS.GetLayerAIUnit();
            unitObj.name  = name;

            //get the UnitAI instance and assign target
            UnitAI unitInstance = unitObj.GetComponent <UnitAI>();

            unitInstance.target = GameControl.GetPlayer();
            //if(anchorToPoint) unitInstance.SetAnchorPoint(transform, anchorRadius);	//not in use atm

            //override the unit default hitpoint if overrideHitPoint is enabled
            if (overrideHitPoint)
            {
                unitInstance.OverrideHitPoint(spawnHP, overrideHPMode);
            }

            AddUnit(unitInstance);              //track unit

            return(unitInstance);
        }
Beispiel #9
0
        //function call when the unit instance gain/lost hitpoint from external source
        public virtual float GainHitPoint(float value)
        {
            float limit = GetFullHitPoint() - hitPoint;

            hitPoint += Mathf.Min(value, limit);

            //if the unit lost hitpoint instead of gaining it
            if (value < 0)
            {
                hpRegenStaggerCounter = hpRegenStagger;

                //if this is the player, call the damage event (inform UI)
                if (thisObj.layer == TDS.GetLayerPlayer())
                {
                    TDS.PlayerDamaged(value);
                }
            }

            //if hitpoint reach 0, destroy the unit
            if (hitPoint <= 0)
            {
                Destroyed();
            }

            return(limit);
        }
Beispiel #10
0
        //public static void LevelUp(){ instance._LevelUp(); }
        public void _LevelUp()
        {
            PlayerPerk perk = player.GetPlayerPerk();

            if (perk != null)
            {
                for (int i = 0; i < stats.perkUnlockingAtLevelList.Count; i++)
                {
                    if (level + 1 == stats.perkUnlockingAtLevelList[i].level)
                    {
                        for (int n = 0; n < stats.perkUnlockingAtLevelList[i].perkIDList.Count; n++)
                        {
                            perk.PurchasePerk(stats.perkUnlockingAtLevelList[i].perkIDList[n], false);
                        }

                        break;
                    }
                }
            }

            level += 1;

            if (level > 1)
            {
                player.GainHitPoint(stats.hitPointGain);
                player.GainEnergy(stats.energyGain);

                player.GainPerkCurrency(stats.perkCurrencyGain);

                TDS.PlayerLevelUp(player);
                TDS.OnGameMessage("level Up!");
            }

            GainExp();                  //call the function to make sure if we under level
        }
Beispiel #11
0
 private void CurrencyChanged()
 {
     TDS.OnPerkCurrency(perkCurrency);
     if (player.SaveUponChange())
     {
         Save();
     }
 }
Beispiel #12
0
 public override bool ApplyEffect(Effect effect)
 {
     if (!base.ApplyEffect(effect))
     {
         return(false);
     }
     TDS.GainEffect(effect);             //for UIBuffIcons
     return(true);
 }
Beispiel #13
0
        //turret facing
        public void AimTurretMouse(Vector3 mousePos)
        {
            if (destroyed || IsStunned())
            {
                return;
            }

            if (!enableTurretRotate || turretObj == null)
            {
                return;
            }

            if (turretAimMode == _TurretAimMode.ScreenSpace)
            {
                //get camera direction and mouse direction with repect to the player position on screen
                Vector3 camV = Quaternion.Euler(0, camT.eulerAngles.y, 0) * Vector3.forward;
                Vector3 dir  = (mousePos - Camera.main.WorldToScreenPoint(thisT.position)).normalized;
                dir = new Vector3(dir.x, 0, dir.y);

                float angleOffset = camT.eulerAngles.y;                   //get the camera y-axis angle
                float sign        = dir.x > 0 ? 1 : -1;                   //get the angle direction

                Vector3 dirM = Quaternion.Euler(0, angleOffset, 0) * dir; //rotate the dir for the camera angle, dir has to be vector3 in order to work

                Quaternion wantedRot = Quaternion.Euler(0, sign * Vector3.Angle(camV, dirM) + angleOffset, 0);
                if (!smoothTurretRotation)
                {
                    turretObj.rotation = wantedRot;
                }
                else
                {
                    turretObj.rotation = Quaternion.Slerp(turretObj.rotation, wantedRot, Time.deltaTime * 15);
                }
            }
            else if (turretAimMode == _TurretAimMode.Raycast)
            {
                LayerMask  mask = 1 << TDS.GetLayerTerrain();
                Ray        ray  = Camera.main.ScreenPointToRay(mousePos);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, mask))
                {
                    Vector3 point = new Vector3(hit.point.x, thisT.position.y, hit.point.z);

                    Quaternion wantedRot = Quaternion.LookRotation(point - thisT.position);
                    if (!smoothTurretRotation)
                    {
                        turretObj.rotation = wantedRot;
                    }
                    else
                    {
                        turretObj.rotation = Quaternion.Slerp(turretObj.rotation, wantedRot, Time.deltaTime * 15);
                    }
                }
            }
        }
Beispiel #14
0
        // Use this for initialization
        public override void Awake()
        {
            base.Awake();

            thisObj.layer = TDS.GetLayerPlayer();

            isPlayer = true;

            SetDestroyCallback(this.PlayerDestroyCallback);

            if (enableAllWeapons)
            {
                weaponList = new List <Weapon>(Weapon_DB.Load());
            }

            if (weaponMountPoint == null)
            {
                weaponMountPoint = thisT;
            }

            if (enableTurretRotate)
            {
                if (turretObj != null)
                {
                    turretObjParent = turretObj.parent;
                }
                else
                {
                    turretObj = thisT;
                    //faceTravelDirection=false;
                }
            }

            hitPointBase = hitPointFull;
            energyBase   = energyFull;

            InitSpawnImmunity();

            progress = thisObj.GetComponent <PlayerProgression>();
            if (progress != null)
            {
                progress.SetPlayer(this);
            }

            perk = thisObj.GetComponent <PlayerPerk>();
            if (perk != null)
            {
                perk.SetPlayer(this);
            }

            Load();
        }
Beispiel #15
0
        //when the unit enter some trigger
        void OnTriggerEnter(Collider col)
        {
            if (col.gameObject.layer != TDS.GetLayerPlayer())
            {
                return;
            }

            OnPlayerContact();
            if (destroyUponPlayerContact)
            {
                ClearUnit();                                            //if destroyUponPlayerContact is enabled, clear the unit
            }
        }
Beispiel #16
0
        //when the unit collide with something, for collision with player
        void OnCollisionEnter(Collision collision)
        {
            if (collision.gameObject.layer != TDS.GetLayerPlayer())
            {
                return;
            }

            OnPlayerContact();
            if (destroyUponPlayerContact)
            {
                ClearUnit();                                            //if destroyUponPlayerContact is enabled, clear the unit
            }
        }
Beispiel #17
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);
        }
Beispiel #18
0
        IEnumerator ActivateRepawnPlayer()
        {
            //delay for 1 second
            yield return(new WaitForSeconds(1));

            //after the delay, set the new player unit to the respawn point and activate it
            player.thisT.position = respawnPoint;
            player.thisObj.SetActive(true);

            respawning = false;                 //clear the respawning flag

            TDS.PlayerRespawned();
        }
Beispiel #19
0
        void Init()
        {
            if (init)
            {
                return;
            }
            init = true;

            //AbilityManager.SetupAbility(abilityList);

            if (!weaponInitiated)
            {
                weaponInitiated = true;
                for (int i = 0; i < weaponList.Count; i++)
                {
                    GameObject obj = MountWeapon((GameObject)Instantiate(weaponList[i].gameObject));
                    weaponList[i] = obj.GetComponent <Weapon>();
                    weaponList[i].Reset();
                    if (i > 0)
                    {
                        obj.SetActive(false);
                    }

                    if (perk != null)
                    {
                        weaponList[i].SetPlayerPerk(perk);
                    }
                }

                if (weaponList.Count == 0)
                {
                    GameObject obj = MountWeapon(null, "defaultObject");
                    weaponList.Add(obj.AddComponent <Weapon>());
                    weaponList[0].aStats.damageMax = 2;
                    weaponList[0].Reset();

                    obj = MountWeapon(GameObject.CreatePrimitive(PrimitiveType.Sphere), "defaultShootObject");
                    obj.AddComponent <ShootObject>();
                    obj.SetActive(false);
                    obj.transform.localScale = new Vector3(.2f, .2f, .2f);

                    GameObject soObj = (GameObject)Instantiate(Resources.Load("Prefab_TDSTK/DefaultShootObject", typeof(GameObject)));
                    soObj.SetActive(false);

                    weaponList[0].shootObject = soObj;
                    weaponList[0].InitShootObject();
                }
            }

            TDS.SwitchWeapon(weaponList[weaponID]);
        }
Beispiel #20
0
        //select a particular ability
        public static void Select(int newID)
        {
            if (newID == instance.selectedID)
            {
                return;
            }
            if (newID < 0 || newID >= instance.abilityList.Count)
            {
                return;
            }

            instance.selectedID = newID;
            TDS.SwitchAbility(GetSelectedAbility());                    //launch the ability switch event to inform the UI
        }
Beispiel #21
0
        //function call to scan for all active unit in game
        //not in used atm
        public static void ScanForUnit()
        {
            allUnitList = new List <Unit>();
            Unit[] list = GameObject.FindObjectsOfType(typeof(UnitAI)) as Unit[];

            for (int i = 0; i < list.Length; i++)
            {
                if (list[i].thisObj.layer == TDS.GetLayerPlayer())
                {
                    continue;
                }
                allUnitList.Add(list[i]);
            }
        }
Beispiel #22
0
        public void SwitchWeapon(int newID)
        {
            weaponList[weaponID].gameObject.SetActive(false);
            weaponList[newID].gameObject.SetActive(true);

            if (weaponList[newID].currentClip == 0 && GameControl.EnableAutoReload())
            {
                weaponList[newID].Reload();
            }

            TDS.SwitchWeapon(weaponList[newID]);

            weaponID = newID;
        }
Beispiel #23
0
        public IEnumerator _GameOver(bool won)
        {
            if (gameOver)
            {
                yield break;                            //stop the coroutine if it has already been called
            }
            gameOver = true;

            Debug.Log("game over - " + (won ? "win" : "lost"));

            //delay 1.5 second before issuing a global gameover event
            yield return(new WaitForSeconds(1.5f));

            gameState = _GameState.GameOver;
            TDS.GameOver(won);
        }
Beispiel #24
0
 void UpdateSphereCastMask(bool ignoreFriendly, bool ignoreSO, bool ignoreCollectible)
 {
     mask = ~(1 << TDS.GetLayerTrigger());
     if (ignoreFriendly)
     {
         mask &= ~(1 << srcLayer);
     }
     if (ignoreSO)
     {
         mask &= ~(1 << TDS.GetLayerShootObject());
     }
     if (ignoreCollectible)
     {
         mask &= ~(1 << TDS.GetLayerCollectible());
     }
 }
Beispiel #25
0
        public void RemoveWeapon()              //used to remove temporary weapon only
        {
            if (weaponList.Count <= 1)
            {
                return;
            }

            if (weaponList[weaponID] != null)
            {
                Destroy(weaponList[weaponID].gameObject);
            }

            weaponList.RemoveAt(weaponID);
            weaponID = tempWeapReturnID;

            weaponList[weaponID].gameObject.SetActive(true);
            TDS.SwitchWeapon(weaponList[weaponID]);
        }
Beispiel #26
0
        //for explosion
        public static void ApplyExplosionForce(Vector3 impactPoint, AttackStats aStats, bool ignorePlayer = false)
        {
            float explosionForce  = aStats.explosionForce * 10;
            float explosionRadius = explosionForce > 0 ? aStats.explosionRadius : 0;

            if (explosionRadius > 0)
            {
                LayerMask  mask = ignorePlayer ? ~(1 << TDS.GetLayerPlayer()) : ~0;
                Collider[] cols = Physics.OverlapSphere(impactPoint, explosionRadius, mask);
                for (int i = 0; i < cols.Length; i++)
                {
                    Rigidbody rd = cols[i].gameObject.GetComponent <Rigidbody>();
                    if (rd != null)
                    {
                        rd.AddExplosionForce(explosionForce, impactPoint, explosionRadius, 0, ForceMode.Impulse);
                    }
                }
            }
        }
Beispiel #27
0
        public override void Awake()
        {
            base.Awake();

            //initiation
            thisObj.layer = TDS.GetLayerAIUnit();
            hostileUnit   = true;

            //setup the cooldown
            if (!randFirstAttackDelay)
            {
                currentCD = firstAttackDelay;
            }
            else
            {
                currentCD = Random.Range(0, firstAttackDelay);
            }

            //make sure the setting for range attack is correct
            if (enableRangeAttack)
            {
                if (shootPointList.Count == 0)
                {
                    shootPointList.Add(thisT);                                          //make sure there a valid shoot point
                }
                if (shootObject == null)
                {
                    Debug.LogWarning("shoot object unassigned for range attack unit, attack disabled", thisT);
                    enableRangeAttack = false;
                }
            }

            //if using navmeshagent
            agent = thisObj.GetComponent <NavMeshAgent>();
            if (agent != null)
            {
                agent.stoppingDistance = brakeRange;
                agent.speed            = moveSpeed;
            }

            evadeCD = evadeCooldown;
            stopCD  = stopCooldown;
        }
Beispiel #28
0
        public void _AddAbility(int abID, int replaceID = -1)
        {
            Ability newAbility = Ability_DB.CloneItem(abID);

            if (newAbility == null)
            {
                return;
            }

            int slotID = -1;

            if (replaceID >= 0)
            {
                for (int i = 0; i < abilityList.Count; i++)
                {
                    if (abilityList[i].ID == replaceID)
                    {
                        slotID = i;     break;
                    }
                }
            }

            if (slotID < 0)
            {
                slotID = abilityList.Count;
                abilityList.Add(null);
            }

            abilityList[slotID] = newAbility;
            abilityList[slotID].Init();

            if (replaceID < 0 || slotID < 0)
            {
                TDS.NewAbility(abilityList[slotID]);
            }
            else
            {
                TDS.NewAbility(newAbility, slotID);
            }

            Select(slotID);
        }
Beispiel #29
0
        private int tempWeapReturnID = 0;       //a cache to store the default weaponID when using temporary weapon
        public void AddWeapon(Weapon prefab, bool replaceWeapon = false, bool temporary = false, float temporaryTimer = 30)
        {
            GameObject obj = MountWeapon((GameObject)Instantiate(prefab.gameObject));

            //replace weapon and temporary are mutually exclusive
            if (replaceWeapon)
            {
                Destroy(weaponList[weaponID].gameObject);
                weaponList[weaponID] = obj.GetComponent <Weapon>();

                TDS.NewWeapon(weaponList[weaponID], weaponID);
            }
            else if (temporary)
            {
                tempWeapReturnID = weaponID;
                weaponList[weaponID].gameObject.SetActive(false);

                if (weaponList[weaponID].temporary)
                {
                    RemoveWeapon();
                }

                weaponID = weaponList.Count;
                weaponList.Add(obj.GetComponent <Weapon>());

                weaponList[weaponList.Count - 1].temporary = true;
                if (temporaryTimer > 0)
                {
                    StartCoroutine(TemporaryWeaponTimer(weaponList[weaponList.Count - 1], temporaryTimer));
                }
            }
            else
            {
                weaponID = weaponList.Count;
                weaponList.Add(obj.GetComponent <Weapon>());
                TDS.NewWeapon(weaponList[weaponID]);
            }

            weaponList[weaponID].Reset();

            TDS.SwitchWeapon(weaponList[weaponID]);
        }
Beispiel #30
0
        //aim split, the split shootobject will try to aim at unit in range
        void SplitAim(Collider col)
        {
            //first all all target in range
            LayerMask mask = 1 << TDS.GetLayerAIUnit();

            Collider[] cols = Physics.OverlapSphere(thisT.position, splitRange, mask);

            if (cols.Length == 0)
            {
                Debug.Log("no target in range");
                return;
            }

            //make sure we dont aim at the collider we hit in th first place again
            List <Collider> colList = cols.ToList();

            for (int i = 0; i < colList.Count; i++)
            {
                if (colList[i] == col)
                {
                    colList.RemoveAt(i); i -= 1;
                }
            }

            //randomly reduce the possible target so we dont exceed the split count
            List <Transform> targetList = new List <Transform>();

            for (int i = 0; i < Mathf.Min(colList.Count, splitCount); i++)
            {
                int rand = Random.Range(0, colList.Count);
                targetList.Add(colList[i].transform);
                colList.RemoveAt(rand);
            }

            //not aim at each target and fire another shootobject at them
            for (int i = 0; i < targetList.Count; i++)
            {
                Quaternion shootRot = Quaternion.LookRotation(targetList[i].position - thisT.position);
                FireSplitSO(shootRot);
            }
        }