コード例 #1
0
 protected override void ArrivedAtTargetLocation()
 {
     if (isServer && myMoM != null)
     {
         if (IsTargetingEnemy())
         {
             if (canAttack && Vector3.Distance(Location, targetEnemy.Location) < 1f)
             {
                 Attack(targetEnemy);
             }
             else
             {
                 MoveTo(targetEnemy.Location);
             }
         }
         else
         {
             targetEnemy = TargetNearest();
             if (targetEnemy != null)
             {
                 MoveTo(targetEnemy.Location);
             }
             else
             {
                 MoveRandomly(myMoM.FightAnchor, orbit);
             }
         }
     }
 }
コード例 #2
0
    // KAMIKAZE ONLY:
    /// <summary>
    /// When hit with Player Unit or Building is detected,
    /// this unit does full Special Damage. If it was a building/tile it
    /// does damage through the Grid. If it was a Unit then it attacks through 
    /// Unit Base stats, spawns a dead sprite and pools itself
    /// </summary>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    public void KamikazeAttack(int x, int y, Unit_Base unit = null)
    {
        if (unit == null) {
            // Hit the tile with special damage
            resourceGrid.DamageTile (x, y, stats.curSPdamage);
            // then pool myself
            objPool.PoolObject (this.gameObject);
        } else {
            // Hit the Player unit with special damage
            SpecialAttackOtherUnit(unit);
        }

        // Spawn an explosion at my position
        GameObject explosion = objPool.GetObjectForType ("Explosion Particles", true);

        if (explosion != null) {
            // Explosion must match my layer
            string targetLayer = GetComponent<SpriteRenderer>().sortingLayerName;

            // assign it to Particle Renderer
            explosion.GetComponent<ParticleSystemRenderer>().sortingLayerName = targetLayer;

            explosion.transform.position = transform.position;
        }
    }
コード例 #3
0
ファイル: Unit_Base.cs プロジェクト: cesarrac/TheyRise
    public void AttackOtherUnit(Unit_Base unit)
    {
        Debug.Log ("UNIT: target unit hp at " + unit.stats.curHP);
        Debug.Log ("UNIT: My damage is " + stats.curDamage + " and my HP is " + stats.curHP);
        if (unit.stats.curHP >= 1f) {

            float def = (unit.stats.curDefence + unit.stats.curShield);

            if (stats.curAttack > def){
                Debug.Log("UNIT: Attacking " + unit.name + " DEF: " + def + " ATTK: " + stats.curAttack);

                // Apply full damage
                TakeDamage(unit, stats.curDamage);

            }else{
                // hit for difference between def and attack
                float calc = def - stats.curAttack;
                float damageCalc = stats.curDamage - calc;

                // always do MINIMUM 1 pt of damage
                float clampedDamage = Mathf.Clamp(damageCalc, 1f, stats.curDamage);

                Debug.Log("UNIT: Can't beat " + unit.name + "'s Defence, so I hit for " + clampedDamage);

                TakeDamage (unit, clampedDamage);

            }
        } else {
            // target is dead by now
            Debug.Log("UNIT: Target Dead!");
            Die (unit.gameObject);

        }
    }
コード例 #4
0
    /// <summary>
    /// When hit with Player Unit or Building is detected,
    /// this unit does full Special Damage. If it was a building/tile it
    /// does damage through the Grid. If it was a Unit then it attacks through
    /// Unit Base stats, spawns a dead sprite and pools itself
    /// </summary>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    public void KamikazeAttack(int x, int y, Unit_Base unit = null)
    {
        if (unit == null)
        {
            // Hit the tile with special damage
            resourceGrid.DamageTile(x, y, stats.curSPdamage);
            // then pool myself
            objPool.PoolObject(this.gameObject);
        }
        else
        {
            // Hit the Player unit with special damage
            SpecialAttackOtherUnit(unit);
        }



        // Spawn an explosion at my position
        GameObject explosion = objPool.GetObjectForType("Explosion Particles", true);

        if (explosion != null)
        {
            // Explosion must match my layer
            string targetLayer = GetComponent <SpriteRenderer>().sortingLayerName;

            // assign it to Particle Renderer
            explosion.GetComponent <ParticleSystemRenderer>().sortingLayerName = targetLayer;

            explosion.transform.position = transform.position;
        }
    }
コード例 #5
0
    Unit_Base TargetNearest()
    {
        Collider[] cols = Physics.OverlapSphere(transform.position, sightRange, mask, QueryTriggerInteraction.Ignore);
        float      nearestDist, newDist;
        Collider   temp   = new Collider();
        Unit_Base  target = null;

        if (cols.Length > 0)
        {
            nearestDist = (cols[0].transform.position - transform.position).sqrMagnitude;           //Vector3.Distance(Location,enemies[0].Location);
            foreach (Collider o in cols)
            {
                if (o.CompareTag("Drone"))
                {
                    newDist = (o.transform.position - transform.position).sqrMagnitude;                  //Vector3.Distance(Location,unit.Location);
                    if (newDist <= nearestDist)
                    {
                        nearestDist = newDist;
                        temp        = o;
                    }
                }
            }
            if (temp != null)
            {
                target = temp.GetComponent <Unit_Base>();
            }
        }
        return(target);
    }
コード例 #6
0
    //public void createUnits_ByRowColumn (int column, int row)
    //{
    //	unitsTable = new Unit_Base[column, row];

    //	/*create units table, from bottom left, to top right, column after column.*/
    //	for (int c = 0; c < column; c++) {
    //		for (int r = 0; r < row; r++) {
    //			GameObject tempObj = Instantiate (unitPrefab, new Vector3 (c, r, 0), Quaternion.identity) as GameObject;
    //			tempObj.transform.SetParent (unitsHolder, false);

    //			tempUnit = tempObj.GetComponent<Unit_Base> ();
    //               tempUnit.InitNormalUnit (c, r, allTypes);

    //			unitsTable [c, r] = tempUnit;
    //		}
    //	}
    //}

    public void createUnits__FromLayout(GameObject[,] boardLayout)
    {
        int column = boardLayout.GetLength(0);
        int row    = boardLayout.GetLength(1);

        unitsTable = new Unit_Base[column, row];
        GameObject tempObj;

        /*create units table, from bottom left, to top right, column after column.*/
        for (int c = 0; c < column; c++)
        {
            for (int r = 0; r < row; r++)
            {
                if (boardLayout[c, r] == null)
                {
                    tempObj = Instantiate(unitPrefab, new Vector3(c, r, 0), Quaternion.identity) as GameObject;
                    //tempObj.transform.SetParent(unitsHolder, false);

                    tempUnit = tempObj.GetComponent <Unit_Base>();
                    //tempUnit.InitNormalUnit(c, r, allTypes);//++++++++++++++++++++++++

                    //unitsTable[c, r] = tempUnit;
                }
                else
                {
                    tempObj = Instantiate(boardLayout[c, r], new Vector3(c, r, 0), Quaternion.identity) as GameObject;
                }
                tempObj.transform.SetParent(unitsHolder, false);
                unitsTable[c, r] = tempUnit;
            }
        }
    }
コード例 #7
0
    public void ChangeOwner(Unit_Base newOwnerUnit)
    {
        CardManager newOwner = null;

        if (newOwnerUnit != null)
        {
            newOwner = newOwnerUnit.Owner;
        }
        if (newOwner != OwnerManager)
        {
            CardManager oldOwner = OwnerManager;
            OwnerManager = newOwner;

            if (oldOwner != null)
            {
                oldOwner.LostCell(this);
            }

            if (newOwnerUnit != null)
            {
                newOwnerUnit.OccupyCell(this);
            }

            if (OwnerChangeEvent != null)
            {
                OwnerChangeEvent(oldOwner);
            }
        }
    }
コード例 #8
0
    private void OnGameStateChange()
    {
        switch (InGameManager.CurrentGameState)
        {
        case GameStateType.Move:
            if (canMove && Health > Cell.MinUnitAmount && PathCells.Count > 0 && PathCells[PathCells.Count - 1] != Cell && canMove)
            {
                Unit_Base unit = Owner.CreateNewUnit(Cell, Cell.MinUnitAmount);
                Cell.UnitArrived(unit);
                ChangeHealth(-Cell.MinUnitAmount);
                StartCoroutine(MoveProcess());
            }
            else
            {
                Cell.UnitArrived(this);
            }
            break;

        case GameStateType.AfterBattle:
            StartCoroutine(MoveToCenter());
            break;

        case GameStateType.Decision:
            TempHealth = 0;
            canMove    = true;
            break;
        }
    }
コード例 #9
0
    public override void Effect(CardManager user, HexCell cell)
    {
        user.ActionPoint += ActionPoint;
        Unit_Base unit = cell.GetUnitOnCell();

        unit.AddTempHealth(TempHealth);
        unit.ChangeHealth(Health);
    }
コード例 #10
0
    private void Awake()
    {
        agent = GetComponent <NavMeshAgent>();
        selec = GetComponentInChildren <Selectable>();

        building = FindObjectOfType <Building>();
        unit     = GetComponent <Unit_Base>();
    }
コード例 #11
0
    Unit_Base TargetNearest()
    {
        float     nearestEnemyDist, newDist;
        Unit_Base enemy = null;

        enemies.Clear();
        Collider[] cols = Physics.OverlapSphere(tran.position, sightRange, mask);

        if (cols.Length > 0)
        {
            for (int e = 0; e < cols.Length; e++)
            {
                if (cols[e].CompareTag("Sarlac"))
                {
                    enemy = cols[e].GetComponent <SarlacController>();
                    if (enemy != null)
                    {
                        return(enemy);
                    }
                }
                if (cols[e].CompareTag("MoM"))
                {
                    Unit_Base ot = cols[e].GetComponent <MoMController>();
                    if (ot != null && !ot.teamID.Equals(teamID) && !enemies.Contains(ot))
                    {
                        enemies.Add(ot);
                    }
                }
                if (cols[e].CompareTag("Drone"))
                {
                    Unit_Base ot = cols[e].GetComponent <Unit_Base>();
                    if (ot != null && !ot.teamID.Equals(teamID) && !enemies.Contains(ot))
                    {
                        enemies.Add(ot);
                    }
                }
            }
        }

        //enemiesCopy = enemies.FindAll(e=> e.isActive && e.teamID!=teamID && (e.Location-Location).sqrMagnitude<sqrDist);
        if (enemies.Count > 0)
        {
            nearestEnemyDist = (enemies[0].Location - Location).sqrMagnitude;           //Vector3.Distance(Location,enemies[0].Location);
            for (int f = 0; f < enemies.Count; f++)
            {
                if (enemies[f].isActive)
                {
                    newDist = (enemies[f].Location - Location).sqrMagnitude;                  //Vector3.Distance(Location,unit.Location);
                    if (newDist <= nearestEnemyDist)
                    {
                        nearestEnemyDist = newDist;
                        enemy            = enemies[f];
                    }
                }
            }
        }
        return(enemy);
    }
コード例 #12
0
 protected override void TargetLost(int id)
 {
     if (targetEnemy != null && id == targetEnemy.unitID)
     {
         enemies.Clear();
         targetEnemy = null;
         ArrivedAtTargetLocation();
     }
 }
コード例 #13
0
 void Attack(Unit_Base target)
 {
     spark.Play();
     target.Health = -attackStrength;
     canAttack     = false;
     if (this.isActive)
     {
         StartCoroutine(AttackCooldown());
     }
 }
コード例 #14
0
 protected override void OnEnable()
 {
     spark       = GetComponentInChildren <ParticleSystem>();
     enemies     = new List <Unit_Base>();
     targetEnemy = null;
     mask        = 1 << LayerMask.NameToLayer("Units");
     canAttack   = true;
     base.OnEnable();
     UnityEventManager.StartListeningInt("PlaceFightFlag", UpdateFlagLocation);
 }
コード例 #15
0
    void OnTriggerEnter2D(Collider2D coll)
    {
        if (coll.gameObject.CompareTag("Citizen"))
        {
            target = coll.gameObject.GetComponent<Unit_Base>();

            StartCoroutine("Damage");

        }
    }
コード例 #16
0
ファイル: Unit_Base.cs プロジェクト: PeakPei/TheWall_Unity2D
 // ONLY USED BY KAMIKAZE UNITS ATTACKING PLAYER UNITS
 public void SpecialAttackOtherUnit(Unit_Base unit)
 {
     if (unit.stats.curHP >= 1)
     {
         TakeDamage(unit, stats.curSPdamage);
     }
     else
     {
         Die(unit.gameObject);
     }
 }
コード例 #17
0
    public Unit_Base CreateNewUnit(HexCell cell, int health)
    {
        GameObject g    = Instantiate(GetUnitPrefab());
        Unit_Base  unit = g.GetComponent <Unit_Base>();

        unit.UnitCreated(cell, this, health);
        Units.Add(unit);
        unit.transform.position = cell.transform.position;

        return(unit);
    }
コード例 #18
0
 void Attack(Unit_Base target)
 {
     spark.Play();
     target.TakeDamage(attackStrength);
     TakeDamage(selfAttack);
     canAttack = false;
     if (this.isActive)
     {
         StartCoroutine(AttackCooldown());
     }
 }
コード例 #19
0
 protected override void UpdateFlagLocation(int mom)
 {
     if (isServer)
     {
         if (myMoM.unitID == mom && Vector3.Distance(Location, myMoM.FightAnchor) > orbit)
         {
             targetEnemy = null;
             MoveTo(myMoM.FightAnchor);
         }
     }
 }
コード例 #20
0
 public void UnitArrived(Unit_Base unit)
 {
     if (Camps.Contains(unit.Owner.camp))
     {
         unit.Merged(CampUnits[Camps.IndexOf(unit.Owner.camp)]);
     }
     else
     {
         Camps.Add(unit.Owner.camp);
         CampUnits.Add(unit);
     }
 }
コード例 #21
0
    public override void OnCollisionEnter(Collision bang)
    {
        if (bang.collider.tag == "Drone")
        {
            DroneController ot = bang.gameObject.GetComponent <DroneController>();
            if (ot != null && ot.CanBeTargetted)
            {
                if (IsTargetingFood() || CanTargetFood())
                {
                    targetEnemy = null;
                    //carriedEnemy = ot;
                    if (numCarried < maxCarry)
                    {
                        ot.Attach(this.tran, tran.TransformPoint(nose));
                    }
                    else
                    {
                        Attack(ot);
                    }

                    eaten++;
                    numCarried++;
                    if (numCarried > 3)
                    {
                        ReturnToHome();
                    }
                }
            }
        }

        if (bang.collider.tag == "Pit")
        {
            if (IsCarryingFood())
            {
                for (int i = 0; i < numCarried; i++)
                {
                    if (enemiesCarried[i] != null)
                    {
                        Destroy(enemiesCarried[i]);
                    }
                }
                numCarried      = 0;
                this.bReturning = false;
            }
            if (eaten >= maxEaten || bDay)
            {
                //PitController pc = bang.gameObject.GetComponent<PitController>();
                this.bReturning = false;
                //GameController.Instance.StartTimer();
                this.Death();
            }
        }
    }
コード例 #22
0
 /// <summary>
 /// Handles the damage to unit by using
 /// method from Unit_Base class.
 /// </summary>
 void HandleDamageToUnit()
 {
     if (targetUnit != null)
     {
         Unit_Base unitToHit = targetUnit.GetComponent <Unit_Base> ();
         AttackOtherUnit(unitToHit);
         canShoot = true;
     }
     else
     {
         canShoot = false;
     }
 }
コード例 #23
0
 public override void OnCollisionEnter(Collision bang)
 {
     if (!isServer)
     {
         return;
     }
     if (bang.collider.CompareTag("Drone") || bang.collider.CompareTag("Sarlac") || bang.collider.CompareTag("MoM"))
     {
         Unit_Base ot = bang.gameObject.GetComponent <Unit_Base>();
         if (ot != null && !ot.teamID.Equals(teamID) && canAttack)
         {
             Attack(ot);
         }
     }
 }
コード例 #24
0
    /// <summary>
    /// Handles the damage to unit by using
    /// method from Unit_Base class.
    /// </summary>
    void HandleDamageToUnit()
    {
//		Debug.Log ("Damaging the player!");
        if (playerUnit != null)
        {
            Unit_Base unitToHit = playerUnit.GetComponent <Unit_Base> ();
            AttackOtherUnit(unitToHit);
            canAttack    = true;
            startCounter = true;
        }
        else
        {
            canAttack = false;
        }
    }
コード例 #25
0
    //general mov
    public bool RequestPosUpdate(Unit_Base mover, Vector2Int move)
    {
        Vector2Int end = mover.indexPos + move;

        if (end.x > gameBoard.GetLength(0) - 1 || end.y > gameBoard.GetLength(1) - 1 || end.x < 0 || end.y < 0)
        {
            return(false);
        }
        if (gameBoard[end.x, end.y] == null)
        {
            //We're good
            MoveObj(mover, end);
            return(true);
        }
        return(false);
    }
コード例 #26
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;
     }
 }
コード例 #27
0
    public static Unit_Base[,] MakeBoard(Data_Board boardData)
    {
        Transform holder = new GameObject("Board").GetComponent <Transform>();

        Unit_Base[,] boardGameplay = new Unit_Base[boardData.boardSize.x, boardData.boardSize.y];
        BoardTile[,] boardVisual;

        switch (boardData.boardType)
        {
        case BoardType.Circle: boardVisual = Board_Circle.MakeBoard(boardData.boardSize, boardData.secondaryFloat); break;

        default: boardVisual = Board_Default.MakeBoard(boardData.boardSize); break;
        }

        float   xS       = -(boardVisual.GetLength(1) / 2f);
        float   yS       = -(boardVisual.GetLength(0) / 2f);
        Vector2 startPos = new Vector2(yS * tileSize, xS * tileSize);

        for (int x = 0; x < boardVisual.GetLength(0); x++)
        {
            for (int y = 0; y < boardVisual.GetLength(1); y++)
            {
                Vector2        location = new Vector2(startPos.x + (tileSize * x), startPos.y + (tileSize * y));
                SpriteRenderer temp     = GameObject.Instantiate(Data.instance.tileObj, location, Quaternion.Euler(new Vector3(0, 0, boardVisual[x, y].rotation)), holder).GetComponent <SpriteRenderer>();
                temp.color = (x + y) % 2 == 0 ? Data.instance.artData.tileBlack : Data.instance.artData.tileWhite;
                if (temp.GetComponentInChildren <TextMeshPro>() != null)
                {
                    temp.GetComponentInChildren <TextMeshPro>().text = x + "," + y;
                }
                switch (boardVisual[x, y].areaType)
                {
                case BoardArea.Corner: temp.sprite = Data.instance.artData.corner;  break;

                case BoardArea.Edge: temp.sprite = Data.instance.artData.edge; break;

                case BoardArea.Middle: temp.sprite = Data.instance.artData.middle; break;

                case BoardArea.Empty: temp.color = Data.instance.artData.tileBlock; boardGameplay[x, y] = temp.gameObject.AddComponent <Unit_Block>(); break;
                }
            }
        }



        return(boardGameplay);
    }
コード例 #28
0
    /// <summary>
    /// Handles the damage to unit by using
    /// method from Unit_Base class.
    /// </summary>
    void HandleDamageToUnit()
    {
//		Debug.Log ("Damaging enemy!");
        if (enemyUnit != null)
        {
            Unit_Base unitToHit = enemyUnit.GetComponent <Unit_Base> ();
            AttackOtherUnit(unitToHit);
            canAttack       = true;
            continueCounter = true;
        }
        else
        {
            canAttack       = false;
            enemyUnit       = null;
            continueCounter = true;
        }
    }
コード例 #29
0
    void MoveObj(Unit_Base mover, Vector2Int end)
    {
        //Update grid

        //Check where we're going
        if (gameBoard[end.x, end.y] == null)
        {
            gameBoard[end.x, end.y] = mover;
        }//else if (gameBoard[end.x, end.y].type != Unit_Base.UnitType.Reflector) { Debug.LogError("ERROR ERROR @ " + end + " location not null but movement occuring"); }

        //check where we are
        if (gameBoard[mover.indexPos.x, mover.indexPos.y] == mover)
        {
            gameBoard[mover.indexPos.x, mover.indexPos.y] = null;
        }
        //Update Unit
        mover.Move(BoardToWorld(end, mover.myTrans.position.z), end);
    }
コード例 #30
0
ファイル: Unit_Base.cs プロジェクト: PeakPei/TheWall_Unity2D
    public void AttackOtherUnit(Unit_Base unit)
    {
        if (unit.stats.curHP >= 1f)
        {
            float def = (unit.stats.curDefence + unit.stats.curShield);

            if (stats.curAttack > def)
            {
//				Debug.Log("Attacking " + unit.name + " DEF: " + def + " ATTK: " + stats.curAttack);

                // Apply full damage
                TakeDamage(unit, stats.curDamage);

//				unit.hp = unit.hp - damage;
//
//				if (unit.hp <=0){
//					Die(unit.gameObject);
//				}
            }
            else
            {
                // hit for difference between def and attack
                float calc       = def - stats.curAttack;
                float damageCalc = stats.curDamage - calc;


                // always do MINIMUM 1 pt of damage
                float clampedDamage = Mathf.Clamp(damageCalc, 1f, stats.curDamage);

//				Debug.Log("Can't beat " + unit.name + "'s Defence, so I hit for " + clampedDamage);

                TakeDamage(unit, clampedDamage);
//				unit.hp = unit.hp - Mathf.Clamp(damageCalc, 1f, damage);
//				if (unit.hp <=0){
//					Die(unit.gameObject);
//				}
            }
        }
        else
        {
            // target is dead by now
            Die(unit.gameObject);
        }
    }
コード例 #31
0
ファイル: Unit_Base.cs プロジェクト: PeakPei/TheWall_Unity2D
    void TakeDamage(Unit_Base unit, float damage)
    {
        unit.stats.curHP = unit.stats.curHP - damage;
        if (unit.stats.curHP < 1f)
        {
            Debug.Log("UNIT BASE: Killing target!");
            Die(unit.gameObject);
        }
        else
        {
            if (unit.statusIndicator != null)
            {
                unit.statusIndicator.SetHealth(unit.stats.curHP, unit.stats.maxHP, damage);
            }
        }

        // pop up the damage
//		unit.dmgPopUp.PopUpDamage (damage);
    }
コード例 #32
0
    public void GameStart()
    {
        InGameManager.instance.GameStateChangeEvent += OnGameStateChange;
        GameObject coreObj = Instantiate(GetCorePrefab());

        PlayerCore = coreObj.GetComponent <Core>();
        HexCell startCell = HexGrid.instance.cells[StartCell];

        PlayerCore.transform.position = startCell.transform.position;
        PlayerCore.InitCore(startCell, this);
        Unit_Base unit = CreateNewUnit(startCell, 1);

        startCell.ChangeOwner(unit);

        for (int i = 0; i < StartDeck.Length; i++)
        {
            AddNewCard(StartDeck[i]);
        }
    }
コード例 #33
0
    public bool TakeDamage(int amount, Unit_Base source)
    {
        if (TempHealth >= amount)
        {
            TempHealth -= amount;
            return(false);
        }
        else
        {
            amount -= TempHealth;

            ChangeHealth(-amount);
            if (Health <= 0)
            {
                Death(source);
                return(true);
            }
            return(false);
        }
    }
コード例 #34
0
ファイル: Tower_DeBuffer.cs プロジェクト: cesarrac/TheyRise
    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");
        }
    }
コード例 #35
0
    IEnumerator Damage()
    {
        isDamaging = true;
        float timeElapsed = 0;

        while (true)
        {

            DoDamage();

            yield return new WaitForSeconds(1f);

            timeElapsed += 1;

            if (timeElapsed >= damageTime || target != null)
            {
                isDamaging = false;
                target = null;
                yield break;
            }

        }
    }
コード例 #36
0
    /// <summary>
    /// Handles the damage to unit by using
    /// method from Unit_Base class.
    /// </summary>
    void HandleDamageToUnit(Unit_Base target)
    {
        if (AttackUnit(target))
        {

            // Tell the enemy this Tower is attacking it if it doesn't already have an attacker
            if (target.gameObject.GetComponent<Enemy_AttackHandler>().attackingTower == null)
                target.gameObject.GetComponent<Enemy_AttackHandler>().attackingTower = gameObject;

            // Lose a bullet
            ammoCount--;

        }
        else
        {
            targetUnit = null;

            // Target is null, go back to Seeking IF NOT in Manual Control or Starved
            if (_state != State.MANUAL_SHOOTING && _state != State.STARVED)
            {

                // if we have Enemies in range we need to acquire target (just stops rotation so Trigger can rotate)
                _state = State.SEEKING;

            }
            else if (_state == State.MANUAL_SHOOTING)
            {
                // We are Manually Shooting, so send back to Manual Control
                _state = State.MANUAL_CONTROL;
            }
        }
    }
コード例 #37
0
ファイル: Unit_Base.cs プロジェクト: cesarrac/TheyRise
 // ONLY USED BY KAMIKAZE UNITS ATTACKING PLAYER UNITS
 public void SpecialAttackOtherUnit(Unit_Base unit)
 {
     if (unit.stats.curHP >= 1f) {
         TakeDamage (unit, stats.curSPdamage);
     } else {
         Die (unit.gameObject);
     }
 }
コード例 #38
0
ファイル: Tower_DeBuffer.cs プロジェクト: cesarrac/TheyRise
    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;

        }
    }
コード例 #39
0
    void EnergizeTowerUnit(Unit_Base tower)
    {
        Debug.Log("TOWER is ENERGIZING!");
        // Attack boost
        tower.stats.curAttack = boost * tower.stats.curAttack;

        // Rate boost
        tower.stats.curRateOfAttk = boost * tower.stats.curRateOfAttk;

        // Damage boost
        tower.stats.curDamage = boost * tower.stats.curDamage;

        // Reload Speed boost (subtracts because Reload speed is how long it takes to reload in seconds)
        tower.stats.curReloadSpeed = tower.stats.curReloadSpeed - boost;

        Debug.Log("Attack " + tower.stats.curAttack + " Damage " + tower.stats.curDamage);

        Debug.Log("Past Attack " + tower.stats.startAttack + " Past Damage " + tower.stats.startDamage);

        tower.CountDownToDeEnergize(DeEnergizeTowerUnit, BoostDuration);
    }
コード例 #40
0
ファイル: Unit_Base.cs プロジェクト: cesarrac/TheyRise-game
    // ********************** WARNING! This is the old Attack Unit method that really does not work as well!! ******************************
    //   public void AttackOtherUnit(Unit_Base unit){
    //    Debug.Log ("UNIT: target unit hp at " + unit.stats.curHP);
    //    Debug.Log ("UNIT: My damage is " + stats.curDamage + " and my HP is " + stats.curHP);
    //    if (unit.stats.curHP > 0) {
    //        float def = (unit.stats.curDefence + unit.stats.curShield);
    //        if (stats.curAttack > def){
    //            Debug.Log("UNIT: Attacking " + unit.name + " DEF: " + def + " ATTK: " + stats.curAttack);
    //            // Apply full damage
    //            TakeDamage(unit, stats.curDamage);
    //        }else{
    //            // hit for difference between def and attack
    //            float calc = stats.curAttack - def;
    //            float damageCalc = stats.curDamage - calc;
    //            // always do MINIMUM 1 pt of damage
    //            float clampedDamage = Mathf.Clamp(damageCalc, 1f, stats.curDamage);
    //            Debug.Log("UNIT: Can't beat " + unit.name + "'s Defence, so I hit for " + clampedDamage);
    //            TakeDamage (unit, clampedDamage);
    //        }
    //    } else {
    //        // target is dead by now
    //        Debug.Log("UNIT: Target Dead!");
    //        Die (unit.gameObject);
    //    }
    //}
    // *************************************************************************
    // *********** THIS IS THE NEW ONE! ***************************
    public bool AttackUnit(Unit_Base target)
    {
        if (target.stats.curHP > 0)
        {

            float def = (target.stats.curDefence + target.stats.curShield);

            if (stats.curAttack > def)
            {
                //Debug.Log("UNIT: Attacking " + target.name + " DEF: " + def + " ATTK: " + stats.curAttack);

                // Apply full damage
                TakeDamage(target, stats.curDamage);

            }
            else
            {
                // hit for difference between def and attack
                float calc = stats.curAttack - def;
                float damageCalc = stats.curDamage - calc;

                // always do MINIMUM 1 pt of damage
                float clampedDamage = Mathf.Clamp(damageCalc, 1f, stats.curDamage);

               // Debug.Log("UNIT: Can't beat " + target.name + "'s Defence, so I hit for " + clampedDamage);

                TakeDamage(target, clampedDamage);

            }

            return true;
        }
        else
        {
            // target is dead by now
            Debug.Log("UNIT: Target Dead!");
            //Die(unit.gameObject);

            return false;

        }
    }
コード例 #41
0
ファイル: Unit_Base.cs プロジェクト: cesarrac/TheyRise-game
 // ONLY USED BY KAMIKAZE UNITS ATTACKING PLAYER UNITS
 public void SpecialAttackOtherUnit(Unit_Base unit)
 {
     if (unit.stats.curHP >= 1f) {
         TakeDamage (unit, stats.curSPdamage);
         // Play do damage sound
         if (audio_source)
             audio_source.PlayOneShot(doDamageSound, 1);
     } else {
         Die (unit.gameObject);
     }
 }
コード例 #42
0
ファイル: Unit_Base.cs プロジェクト: cesarrac/TheyRise-game
    void TakeDamage(Unit_Base unit, float damage)
    {
        unit.stats.curHP -= damage;

        // Indicate damage using Unit / Building's canvas
        if (unit.gameObject.activeSelf) {

            if (unit.gameObject.tag == "Building") {

                // indicate damage on building
                if (unit.buildingStatusIndicator != null)
                    unit.buildingStatusIndicator.SetHealth (unit.stats.curHP, unit.stats.maxHP, damage);

            } else {
                // indicate damage on unit
                if (unit.statusIndicator != null)
                    unit.statusIndicator.SetHealth (unit.stats.curHP, unit.stats.maxHP, damage);
            }

        }
    }