Exemplo n.º 1
0
    void SpawnEnemy(string _enemyName, int _spawnIndex)
    {
        // Spawn and fill components
        GameObject _enemy = objPool.GetObjectForType(_enemyName, true);

        if (_enemy != null)
        {
            // Give it its starting position
            _enemy.transform.position = spawnPositions[_spawnIndex];

            // reset its Stats in case it just got brought back from the Pool
            Enemy_AttackHandler _attkHandler = _enemy.GetComponentInChildren <Enemy_AttackHandler>();
            _attkHandler.stats.Init();

            // also reset their Health Bar
            _attkHandler.statusIndicator.SetHealth(_attkHandler.stats.curHP, _attkHandler.stats.maxHP);
            Debug.Log("WAVESPAWNER: spawning unit with curHP: " + _attkHandler.stats.curHP + " and maxHP: " + _attkHandler.stats.maxHP);

            // and give it the Object Pool
            _attkHandler.objPool = objPool;

            // store its position for its neighbors
            neighborEnemyPosition = _enemy.transform.position;

            // pathfinding variables
            Enemy_MoveHandler _moveHandler = _enemy.GetComponent <Enemy_MoveHandler>();
            _moveHandler.resourceGrid  = resourceGrid;
            _moveHandler.spwnPtIndex   = _spawnIndex;
            _moveHandler.spwnPtHandler = spwnPtHandler;

            // reset the current move speed in case this unit was affected by a DeBuffer
            _moveHandler.mStats.curMoveSpeed = _moveHandler.mStats.startMoveSpeed;

            // feed it the move handler from the enemy spawned before this one so it has a buddy
            if (lastEnemy != null)
            {
                // make sure they belong to the same wave
                if (lastEnemy.gameObject.name == _enemyName)
                {
                    _moveHandler.myBuddy = lastEnemy;
                }
                else
                {
                    // not the same name so this must be the first spawn of a new wave
                    lastEnemy = null;
                }
            }

            lastEnemy = _moveHandler;

            // Add this newly Spawned enemy to the list of spawned enemies
            spawnedEnemies.Add(_moveHandler);
        }
    }
Exemplo n.º 2
0
    public bool AttackTile(int x, int y, Enemy_MoveHandler enemyMove)
    {
        if (resourceGrid.tiles [x, y] != null)
        {
            // if no tile has been attacked OR this unit is attacking ANOTHER TILE, then we fill the tile and store it for calcs
            if (tileUnderAttack == null || tileUnderAttack != resourceGrid.tiles [x, y])
            {
                tileUnderAttack = resourceGrid.tiles [x, y];
                tileDefence     = tileUnderAttack.def;
                tileShield      = tileUnderAttack.shield;
                tileHP          = tileUnderAttack.hp;
            }
            Debug.Log("TileHP: " + tileUnderAttack.hp);

            if (tileHP > 0)
            {
                float calc = (tileDefence - stats.curAttack) - tileShield;
//
                if (calc > 0)
                {
                    // Apply full damage
                    resourceGrid.DamageTile(x, y, stats.curDamage);
                }
                else
                {
                    // Apply just 1 damage
                    resourceGrid.DamageTile(x, y, 1f);
                }
                canAttackTile = true;
                return(true);
            }
            else
            {
                canAttackTile         = false;
                enemyMove.isAttacking = false;
//				enemyMove.GetPath (); // start on path again!
                tileUnderAttack = null;
                return(false);
            }
        }
        else
        {
            canAttackTile         = false;
            enemyMove.isAttacking = false;
            return(false);
//			enemyMove.GetPath (); // start on path again!
        }
    }
Exemplo n.º 3
0
 void ResetEnemy(Unit_Base target)
 {
     if (type == debuffType.DEFENCE)
     {
         target.stats.curDefence = target.stats.startDefence;
     }
     else if (type == debuffType.ATTACK)
     {
         target.stats.curAttack = target.stats.startAttack;
     }
     else
     {
         Enemy_MoveHandler moveH = target.gameObject.GetComponent <Enemy_MoveHandler>();
         moveH.mStats.curMoveSpeed = moveH.mStats.startMoveSpeed;
     }
 }
Exemplo n.º 4
0
 void DebuffUnit(Unit_Base target)
 {
     if (type == debuffType.DEFENCE)
     {
         target.stats.curDefence = target.stats.curDefence - debuffAmmt;
         target.TakeDebuff(debuffAmmt, "Defence");
     }
     else if (type == debuffType.ATTACK)
     {
         target.stats.curAttack = target.stats.curAttack - debuffAmmt;
         target.TakeDebuff(debuffAmmt, "Attack");
     }
     else
     {
         // get the move handler from the unit's gameobject
         Enemy_MoveHandler moveH = target.gameObject.GetComponent <Enemy_MoveHandler>();
         moveH.mStats.curMoveSpeed = moveH.mStats.curMoveSpeed - slowDownDebuffAmmnt;
         target.TakeDebuff(slowDownDebuffAmmnt, "Speed");
     }
 }
Exemplo n.º 5
0
    public bool AttackTile(int x, int y, Enemy_MoveHandler enemyMove)
    {
        if (resourceGrid.tiles [x, y] != null) {
            // if no tile has been attacked OR this unit is attacking ANOTHER TILE, then we fill the tile and store it for calcs
            if (tileUnderAttack == null || tileUnderAttack != resourceGrid.tiles [x, y]) {
                tileUnderAttack = resourceGrid.tiles [x, y];
                tileDefence = tileUnderAttack.def;
                tileShield = tileUnderAttack.shield;
                tileHP = tileUnderAttack.hp;
            }
        Debug.Log ("TileHP: " + tileUnderAttack.hp);

            if (tileHP > 0) {
                float calc = (tileDefence - stats.curAttack) - tileShield;
        //
                if (calc > 0) {
                    // Apply full damage
                    resourceGrid.DamageTile (x, y, stats.curDamage);

                } else {

                    // Apply just 1 damage
                    resourceGrid.DamageTile (x, y, 1f);

                }
        //				canAttackTile = true;
                return true;

            } else {
        //				canAttackTile = false;
                enemyMove.state = Enemy_MoveHandler.State.MOVING;
                tileUnderAttack = null;
                return false;
            }
        } else {
        //			canAttackTile = false;
            enemyMove.state = Enemy_MoveHandler.State.MOVING;
            return false;
        }
    }
Exemplo n.º 6
0
    void SpawnEnemy(string _enemyName, int _spawnIndex)
    {
        // Spawn and fill components
        GameObject _enemy = objPool.GetObjectForType (_enemyName, true);

        if (_enemy != null) {

            // Give it its starting position
            _enemy.transform.position = spawnPositions[_spawnIndex];

            // Get the Attack Handler
            Enemy_AttackHandler _attkHandler = _enemy.GetComponentInChildren<Enemy_AttackHandler>();

            // Get the Move Handler
            Enemy_MoveHandler _moveHandler = _enemy.GetComponent<Enemy_MoveHandler>();

            // Pathfinding variables
            _moveHandler.resourceGrid = resourceGrid;
            _moveHandler.spwnPtIndex = _spawnIndex;
            _moveHandler.spwnPtHandler = spwnPtHandler;

            // Give it the Object Pool
            _attkHandler.objPool = objPool;

            // Give it the Camera Shake for Special Attack
            _attkHandler._camShake = camShake;

            // Don't Activate GameObject until all components are set
            _enemy.SetActive(false);

            // Feed it the move handler from the enemy spawned before this one so it has a buddy
            if (lastEnemy != null){
                // make sure they belong to the same wave
                if (lastEnemy.gameObject.name == _enemyName){
                    _moveHandler.myBuddy = lastEnemy;
                }else{
                    // not the same name so this must be the first spawn of a new wave
                    lastEnemy = null;
                }

            }

            // Store this unit as Last Enemy spawned
            lastEnemy = _moveHandler;

            // Add this newly Spawned enemy to the list of spawned enemies
            spawnedEnemies.Add(_moveHandler);

            // Store its position for its neighbors
            neighborEnemyPosition = _enemy.transform.position;

            // IN CASE THIS UNIT WAS ALREADY SPAWNED FROM POOL:
            if (_moveHandler.unitInitialized){

                // Reset their Health Bar
                _attkHandler.statusIndicator.SetHealth(_attkHandler.stats.curHP, _attkHandler.stats.maxHP);

        //				 Reset its starting path position to this new spawn point
                _moveHandler.posX = (int)_enemy.transform.position.x;
                _moveHandler.posY = (int)_enemy.transform.position.y;

                // Reset the current move speed in case this unit was affected by a Speed DeBuffer
                _moveHandler.mStats.curMoveSpeed = _moveHandler.mStats.startMoveSpeed;

                if (_enemy.GetComponentInChildren<Text>() != null){
                    Text dmgTxt = _enemy.GetComponentInChildren<Text>();
                    objPool.PoolObject(dmgTxt.gameObject);
                }
            }

            // Object Ready to be Activated
            _enemy.SetActive(true);

            if (_enemy.GetComponentInChildren<Text>() != null){
                Text dmgTxt = _enemy.GetComponentInChildren<Text>();
                objPool.PoolObject(dmgTxt.gameObject);
            }

            // Initialize its Stats
            _attkHandler.stats.Init();

            // Initialize their path to Start moving to their destination
            _moveHandler.InitPath();

        //			Debug.Log ("WAVE: Spawned " + _enemyName + " with " + _attkHandler.stats.curHP +
        //			           "HP. At position: (x)" + _enemy.transform.position.x + " (y)" + _enemy.transform.position.y);
        }
    }
 void Awake()
 {
     move_handler = GetComponentInParent<Enemy_MoveHandler> ();
 }