protected IEnumerator Hit(BoardCreator board, UnitStats target, Tile source) { if (data.Damage > 0) { target.TakeDamage(unit.GetComponent <UnitStats>().GetAttack(board, data)); } if (data.Heal > 0) { target.Heal(data.Heal); } if (!target.IsDead()) { if (data.hasKnockback && target.GetComponent <Unit>().KnockbackAble()) { Point direction = source.pos - target.GetComponent <Unit>().tile.pos; yield return(StartCoroutine(target.ApplyKnockback(board, direction))); } if (data.status != StatusEffects.NONE) { target.AddStatus(data.status); } } }
public static void Attack(RaycastHit2D other) { if (currentUnit.tag == "Player") { UnitStats player = currentUnit.GetComponent <UnitStats>(); EnemyUnitStats enemy = other.collider.GetComponent <EnemyUnitStats>(); if (player.unitAttack <= enemy.unitDefense) { currentDamage = 1; } else { currentDamage = player.unitAttack - enemy.unitDefense; } enemy.GetComponent <EnemyHealth>().TakeDamage(currentDamage); } else if (currentUnit.tag == "Enemy") { EnemyUnitStats enemy = currentUnit.GetComponent <EnemyUnitStats>(); UnitStats player = other.collider.GetComponent <UnitStats>(); if (enemy.unitAttack <= player.unitDefense) { currentDamage = 1; } else { currentDamage = enemy.unitAttack - player.unitDefense; } player.GetComponent <PlayerHealth>().TakeDamage(currentDamage); } }
public void hit(GameObject target) { if (target != null) { //if we are attacking how are we attacking? UnitStats ownerStats = this.owner.GetComponent <UnitStats>(); UnitStats targetStats = target.GetComponent <UnitStats>(); if (ownerStats.mana >= this.manaCost) //got enough Mana to cast? { //calculate the attack value of the attacking unit with a crit chance on top float attackMultiplier = (Random.value * (this.maxAttackMultiplier - this.minAttackMultiplier)) + this.minAttackMultiplier; float damage = (this.magicAttack) ? attackMultiplier * ownerStats.magic : attackMultiplier * ownerStats.attack; float defenseMultiplier = (Random.value * (this.maxDefenseMultiplier - this.minDefenseMultiplier)) + this.minDefenseMultiplier; //calculate the damage delt to the target by taking your attack value away from the defence value damage = Mathf.Max(0, damage - (defenseMultiplier * targetStats.defense)); this.owner.GetComponent <Animator>().Play(this.attackAnimation); //play the attacking animation targetStats.GetComponent <UnitStatFunctions>().receiveDamage(damage); //tell the target that they have been attacked and to react ownerStats.mana -= this.manaCost; //reduce this units mana value as we used magic } else { //then punch them if not //calculate the attack value of the attacking unit with a crit chance on top float attackMultiplier = (Random.value * (this.maxAttackMultiplier - this.minAttackMultiplier)) + this.minAttackMultiplier; float damage = attackMultiplier * ownerStats.attack; //calculate the damage delt to the target by taking your attack value away from the defence value float defenseMultiplier = (Random.value * (this.maxDefenseMultiplier - this.minDefenseMultiplier)) + this.minDefenseMultiplier; damage = Mathf.Max(0, damage - (defenseMultiplier * targetStats.defense)); this.owner.GetComponent <Animator>().Play(this.attackAnimation); //play the attacking animation targetStats.GetComponent <UnitStatFunctions>().receiveDamage(damage); //tell the target that they have been attacked and to react } } }
IEnumerator AttackWithCooldown(UnitStats targetStats) { while (isAttacking) { Debug.Log("ATTACKING"); if (targetStats == null) { StopAttack(); Debug.Log("Target possible dead"); break; } else { Debug.Log("GOINH to take damage"); CmdTakeDamage(targetStats.GetComponent <NetworkIdentity> (), myStats.damage.GetValue()); } yield return(new WaitForSeconds(attackSpeed)); } yield return(null); }