public override OnPlayResult OnPlay(params object[] parameters) { List <HealthEntity> targets = parameters[0] as List <HealthEntity>; OnPlayResult onPlayResult = new OnPlayResult(); if (type == Type.Damage) { foreach (var t in targets) { Enemy.DamageInfo damageInfo = t.TakeDamage(amount); onPlayResult.unshieldedDamage = damageInfo.damageDealt; GameObject go = Instantiate(FindObjectOfType <BattleManager>().particlePrefab); if (t is Player) { go.transform.SetParent(((Player)t).particleEmitter); } else { go.transform.SetParent(t.transform); } go.GetComponent <ParticlesEffect>().Init(damageInfo.damageDealt); go.transform.localScale = Vector3.one; go.transform.localPosition = new Vector3(0, -20, 0); } } else if (type == Type.Heal) { foreach (var t in targets) { t.TakeHealing(amount); } } else if (type == Type.Block) { foreach (var t in targets) { t.ModifyArmor(amount); } } else { foreach (var t in targets) { ((Player)t).ModifyMana(amount); } } return(onPlayResult); }
public override Enemy.DamageInfo TakeDamage(int amount) { amount = Mathf.Clamp(amount, 0, amount); Enemy.DamageInfo damageInfo = new Enemy.DamageInfo(); int amountRemaining = amount; amountRemaining -= armor; ModifyArmor(-amount); amountRemaining = Mathf.Clamp(amountRemaining, 0, amountRemaining); if (amountRemaining > 0) { if (amountRemaining > health) { damageInfo.damageDealt = health; } else { damageInfo.damageDealt = amountRemaining; } health -= amountRemaining; health = Mathf.Clamp(health, 0, maxHealth); } if (health <= 0) { FindObjectOfType <BattleManager>().Defeat(); } RefreshUI(); return(damageInfo); }