public void InflictDamage(Unit target, Unit caster, float damage) { //Applies status effects if (target.statusEffects.Count > 0) { StatusEffect statusEffect; statusEffect = target.statusEffects.Find(x => x.type == StatusEffectType.ReduceDamage); if (statusEffect != null) { ReduceDamage reduceDamage = (ReduceDamage)statusEffect; damage -= damage * reduceDamage.magnitude; } } if (caster != null) { if (caster.statusEffects.Count > 0) { StatusEffect statusEffect = caster.statusEffects.Find(x => x.type == StatusEffectType.IncreaseAttackSingleUse); if (statusEffect != null) { IncreaseAttack increaseAttack = (IncreaseAttack)statusEffect; damage = (float)damage * (1f + increaseAttack.magnitude); caster.statusEffects.Remove(statusEffect); } } } target.CurrentHealth -= (int)damage; var pos = target.gameObject.transform.position; var o = Instantiate(damageText, pos + new Vector3(0.25f, target.gameObject.GetComponent <SpriteRenderer>().bounds.size.y / 2, 0), Quaternion.identity); var dText = o.GetComponent <DamageText>(); dText.SetText((int)damage); if (turn == Turn.Player) { dText.destroyed.AddListener(CheckUnitStatuses); } else { dText.destroyed.AddListener(CheckUnitStatuses); } }
public void IncreaseDefense(Unit target, float percent, int rounds) { ReduceDamage statusEffect = (ReduceDamage)target.statusEffects.Find(x => x.type == StatusEffectType.ReduceDamage); if (statusEffect != null) { statusEffect.rounds = rounds; statusEffect.magnitude = percent; } else { statusEffect = new ReduceDamage(); statusEffect.rounds = rounds; statusEffect.magnitude = percent; target.statusEffects.Add(statusEffect); } GameObject textObj = Instantiate(playerBattleEndText, target.transform.position + new Vector3(0, 2f, 0), Quaternion.identity); textObj.GetComponent <BattleEndText>().SetText("+ Defense"); textObj.GetComponent <BattleEndText>().SetColor(Color.green); nextTurnExecuting = true; Invoke("NextTurn", 1.5f); }
internal static float OnReduceDamage(object sender, ReduceDamageEventArgs arg) { var ret = ReduceDamage?.Invoke(sender, arg); return(ret.GetValueOrDefault(arg.Damage)); }