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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a78399457cb0c74b9140b3ea8b42870
|
||||
|
|
@ -6,7 +6,8 @@ using UnityEngine.Serialization;
|
|||
public class Player : MonoBehaviour
|
||||
{
|
||||
public event Action<int> DiamondCountUpdated;
|
||||
public event Action<int> HealthUpdated;
|
||||
public event Action<int> HealthUpdated;
|
||||
public event Action<int> DamageTaken;
|
||||
|
||||
[SerializeField] private int maxHealth;
|
||||
[SerializeField] private int diamonds;
|
||||
|
|
@ -44,6 +45,7 @@ public class Player : MonoBehaviour
|
|||
_healthIndex += damage;
|
||||
UpdateGUI();
|
||||
}
|
||||
DamageTaken?.Invoke(damage);
|
||||
}
|
||||
|
||||
public void Heal(int healAmount)
|
||||
|
|
|
|||
|
|
@ -184,6 +184,12 @@ namespace UI
|
|||
_blackDieAbilityUsesUsed--;
|
||||
}
|
||||
|
||||
public void MarkArmorAbilityUsed()
|
||||
{
|
||||
_armorUses[_armorUsesUsed].value = true;
|
||||
_armorUsesUsed++;
|
||||
}
|
||||
|
||||
public void MarkStartingBlackDieAbilityUsed()
|
||||
{
|
||||
_startingBlackDieAbilityUses[_startingBlackDieAbilityUsesUsed].value = true;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace UI
|
|||
[SerializeField] private BlackDieAbility blackDieAbility;
|
||||
[SerializeField] private ChestRewardSelection chestRewardSelection;
|
||||
[SerializeField] private TorchAbility torchAbility;
|
||||
[SerializeField] private ArmorAbility armorAbility;
|
||||
[SerializeField] private Player player;
|
||||
|
||||
public static UIManager Instance { get; private set; }
|
||||
|
|
@ -73,6 +74,9 @@ namespace UI
|
|||
|
||||
player.DiamondCountUpdated += hudController.SetDiamondCount;
|
||||
player.HealthUpdated += hudController.SetHealth;
|
||||
|
||||
armorAbility.ArmorAbilityGained += hudController.SetArmorAbilityEnabled;
|
||||
armorAbility.MarkAbilityUsed += hudController.MarkArmorAbilityUsed;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue