Implemented armor and diamond ability
This commit is contained in:
parent
c42406e615
commit
0c4592ac7c
6 changed files with 113 additions and 1 deletions
46
PuzzleGameProject/Assets/Scripts/Abilities/ArmorAbility.cs
Normal file
46
PuzzleGameProject/Assets/Scripts/Abilities/ArmorAbility.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Abilities
|
||||
{
|
||||
public class ArmorAbility : MonoBehaviour
|
||||
{
|
||||
public event Action MarkAbilityUsed;
|
||||
public event Action ArmorAbilityGained;
|
||||
|
||||
[SerializeField] private Player player;
|
||||
[SerializeField] private int maxUses;
|
||||
private int currentUses;
|
||||
|
||||
private bool _abilityAcive;
|
||||
private void OnEnable()
|
||||
{
|
||||
ChestRewardSelection.DiamondAndLifeSelected += HandleAbilityAcitvated;
|
||||
player.DamageTaken += HandleDamageDealt;
|
||||
}
|
||||
|
||||
private void HandleDamageDealt(int damage)
|
||||
{
|
||||
for (int i = 0; i < damage; i++)
|
||||
{
|
||||
if (_abilityAcive)
|
||||
{
|
||||
player.Heal(1);
|
||||
currentUses--;
|
||||
MarkAbilityUsed?.Invoke();
|
||||
if (currentUses < 1)
|
||||
{
|
||||
_abilityAcive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleAbilityAcitvated()
|
||||
{
|
||||
ArmorAbilityGained?.Invoke();
|
||||
_abilityAcive = true;
|
||||
currentUses = maxUses;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue