//function created to condence similar funtionallity of player and enemy creatures //source unit is the one doing the move, the target is recieving it IEnumerator RunMove(BattleUnit sourceUnit, BattleUnit targetUnit, Move move) { //checks to see if the cresture is effected by a modifier that would stop runmove bool canRunMove = sourceUnit.Creature.OnBeforeMove(); if (!canRunMove) { //yield break is called to stop the coroutine if a the move is unable to run yield return(ShowStatusChanges(sourceUnit.Creature)); //to remove hp from damage if required from a volitle status yield return(sourceUnit.Hud.UpdateHP()); yield break; } yield return(ShowStatusChanges(sourceUnit.Creature)); //none of this logic will be performed if can run move is false move.Pp--; yield return(dialogueBox.TypeDialog($"{sourceUnit.Creature.Base.Name} used {move.Base.Name}")); if (CheckIfMoveHits(move, sourceUnit.Creature, targetUnit.Creature)) { sourceUnit.BattleAttackAnimation(); yield return(new WaitForSeconds(1f)); targetUnit.BattleHitAmination(); //check to see if the move was a status move if (move.Base.Category == MoveCategory.Status) { yield return(RunMoveEffects(move.Base.Effects, sourceUnit.Creature, targetUnit.Creature, move.Base.Target)); } else { var damageDetails = targetUnit.Creature.TakeDamage(move, sourceUnit.Creature); yield return(targetUnit.Hud.UpdateHP()); yield return(ShowDamageDetails(damageDetails)); } if (move.Base.SecondaryEffects != null && move.Base.SecondaryEffects.Count > 0 && targetUnit.Creature.HP > 0) { foreach (var secondary in move.Base.SecondaryEffects) { var rnd = UnityEngine.Random.Range(1, 101); if (rnd <= secondary.Chance) { yield return(RunMoveEffects(secondary, sourceUnit.Creature, targetUnit.Creature, secondary.Target)); } } } //this coroutine plays if the creature loses all hp if (targetUnit.Creature.HP <= 0) { yield return(HandleCreatureFainted(targetUnit)); } } //if the move misses else { yield return(dialogueBox.TypeDialog($"{sourceUnit.Creature.Base.Name}'s attack missed")); } }