Skip to content
Snippets Groups Projects
Commit 775d81cf authored by Robin Halseth Sandvik's avatar Robin Halseth Sandvik
Browse files

Added mana & stamina + regeneration to Character.

parent 7a2f79e9
No related branches found
No related tags found
1 merge request!31Mana and stamina.
......@@ -48,7 +48,16 @@ namespace BigSock {
set => baseHP = value;
}
public float baseHP = 10;
/*
Mana of the character.
*/
public float Mana { get; set; }
/*
Stamina of the character.
*/
public float Stamina { get; set; }
/*
Maximum hit points of the character.
......@@ -133,10 +142,18 @@ namespace BigSock {
}
/*
Regenerates mana and stamina.
*/
protected virtual void Regenerate() {
Mana = Math.Min(Stats.MaxMana, Mana + Time.fixedDeltaTime * Stats.RegenMana);
Stamina = Math.Min(Stats.MaxStamina, Stamina + Time.fixedDeltaTime * Stats.RegenStamina);
}
/*
Updates the modifiers to the character's stats.
*/
public void UpdateModifiers(ICharacterStats modifiers = null) {
public virtual void UpdateModifiers(ICharacterStats modifiers = null) {
modifiers ??= Inventory.Modifier;
Stats = BaseStats.Modify(modifiers);
}
......
......@@ -18,6 +18,8 @@ namespace BigSock {
public HPBar hpBar;
public XpBar xpBar;
public XpBar manaBar;
public XpBar staminaBar;
public float collisionOffset = 0.05f;
......@@ -106,6 +108,8 @@ namespace BigSock {
}
private void Update() {
Regenerate();
if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButton(0)) {
// Manage attack cooldown.
if(NextTimeCanAttack <= DateTime.Now) {
......@@ -130,8 +134,24 @@ namespace BigSock {
}
}
/*
Updates the modifiers to the character's stats.
*/
public override void UpdateModifiers(ICharacterStats modifiers = null) {
super.UpdateModifiers(modifiers);
manaBar?.SetMaxXp(Stats.MaxMana);
staminaBar?.SetMaxXp(Stats.MaxStamina);
}
/*
Regenerates mana and stamina.
*/
protected override void Regenerate() {
base.Regenerate();
manaBar?.SetXp(Mana);
staminaBar?.SetXp(Stamina);
}
private bool TryMove_OLD(Vector2 direction) {
if(direction != Vector2.zero) {
......
......@@ -61,6 +61,8 @@ namespace BigSock {
}
protected virtual void Update() {
Regenerate();
if (target != null && !isInMelee){
/* //walk
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment