Skip to content
Snippets Groups Projects

Fixing knockback & movement.

Merged Robin Halseth Sandvik requested to merge master into main
21 files
+ 367
57
Compare changes
  • Side-by-side
  • Inline
Files
21
using System.Collections;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
namespace BigSock {
/*
Base class for abilities.
*/
public abstract class BaseAbility : IAbility {
/*
The cooldown of the ability in seconds.
*/
public TimeSpan Cooldown { get; set; } = new TimeSpan(0, 0, 0, 0, 250); // 1/4 seconds.
/*
The name of the ability.
*/
public string Name { get; set; }
/*
The description of the ability.
*/
public string Description { get; set; }
/*
The id of the ability.
*/
public ulong Id { get; set; }
/*
The next time the ability has cooled down.
*/
public DateTime NextTimeCanUse { get; set; } = DateTime.Now;
/*
Whether the ability is ready.
*/
public bool Ready => NextTimeCanUse <= DateTime.Now;
/*
Try to use the ability.
Handles cooldown and ability cost here.
Returns true if the ability was successfully used.
*/
public bool Use(Character actor, Vector2 target) {
// Check that the ability is cooled down.
if(Ready) {
//> Handle checking costs here.
// Activate the ability.
var res = Activate(actor, target);
// If it succeeded, update cooldown and pay ability cost.
if(res) {
NextTimeCanUse = DateTime.Now + Cooldown;
//> Handle paying the cost (HP, mana, stamina) here.
}
return res;
}
return false;
}
/*
Activates the ability.
Returns true if the ability was successfully activated.
- Even if nothing was hit, used to indicate that cooldowns should be updated.
This should be overridden in sub-classes for the actual abilities.
*/
protected abstract bool Activate(Character actor, Vector2 target);
}
/*
Notes:
- Subclasses should override Activate() to implement their actual functionality.
- Use() should not be overridden unless absolutely neccesary.
- Activate() can be used to hold special conditions, if it returns false, no cooldowns or costs will be enforced.
+ An ability that can only be activated if there is a valid target, Activate() can return false if no targets found.
- Planning to expand code later:
- Allow passing a target character instead of a position.
- Return a result object instead of just bool to allow for more fine grained controll, like resetting cooldown without mana cost.
- Adding cost management, use count limits (pr lvl or in total)
*/
}
\ No newline at end of file
Loading