From e3d6fe5705dd25f5b09d7f1a43455d038fd7b505 Mon Sep 17 00:00:00 2001 From: Ny Bruker <robinhs@stud.ntnu.no> Date: Tue, 27 Sep 2022 11:29:00 +0200 Subject: [PATCH] Intial skeleton of the ability system. --- MrBigsock/Assets/Code/Core/Abilities.meta | 8 ++ .../Assets/Code/Core/Abilities/Base.meta | 8 ++ .../Code/Core/Abilities/Base/BaseAbility.cs | 95 +++++++++++++++++++ .../Core/Abilities/Base/BaseAbility.cs.meta | 11 +++ .../Code/Core/Abilities/Base/BaseAttack.cs | 22 +++++ .../Core/Abilities/Base/BaseAttack.cs.meta | 11 +++ .../Code/Core/Abilities/Base/IAbility.cs | 62 ++++++++++++ .../Code/Core/Abilities/Base/IAbility.cs.meta | 11 +++ .../Code/Core/Abilities/Base/IAttack.cs | 23 +++++ .../Code/Core/Abilities/Base/IAttack.cs.meta | 11 +++ .../Code/Core/Abilities/BasicProjectile1.cs | 44 +++++++++ .../Core/Abilities/BasicProjectile1.cs.meta | 11 +++ 12 files changed, 317 insertions(+) create mode 100644 MrBigsock/Assets/Code/Core/Abilities.meta create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base.meta create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs.meta create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs.meta create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs.meta create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs create mode 100644 MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs.meta create mode 100644 MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs create mode 100644 MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs.meta diff --git a/MrBigsock/Assets/Code/Core/Abilities.meta b/MrBigsock/Assets/Code/Core/Abilities.meta new file mode 100644 index 00000000..ca28cb71 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 27a976b8ec0044e4ca0a1b2e9e3180e1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base.meta b/MrBigsock/Assets/Code/Core/Abilities/Base.meta new file mode 100644 index 00000000..b34f3d2f --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ea9851c0a856efc41bea28abd815c6d0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs new file mode 100644 index 00000000..aeb2f813 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs @@ -0,0 +1,95 @@ +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 diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs.meta b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs.meta new file mode 100644 index 00000000..c077a0b5 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAbility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 46edbd7e16fb5e740996dfed00e42fe0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs new file mode 100644 index 00000000..99de1553 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs @@ -0,0 +1,22 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Base class for attacks. + */ + public abstract class BaseAttack : BaseAbility, IAttack { + + /* + The attack stats of the ability. + */ + public IAttackStats AttackStats { get; set; } + + } + +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs.meta b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs.meta new file mode 100644 index 00000000..dac0115c --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/BaseAttack.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 26f8841e1cc588e4ab0747ee086e1656 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs new file mode 100644 index 00000000..80fa7096 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs @@ -0,0 +1,62 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Interface that represents an ability. + */ + public interface IAbility { + /* + The cooldown of the ability. + */ + TimeSpan Cooldown { get; } + + /* + The name of the ability. + */ + string Name { get; } + + /* + The description of the ability. + */ + string Description { get; } + + /* + The id of the ability. + */ + ulong Id { get; } + + /* + The next time the ability has cooled down. + */ + DateTime NextTimeCanUse { get; } + + /* + Whether the ability is ready. + */ + bool Ready { get; } + + + /* + ----------------------------- + Add in something for costs. + - Uses + - Mana + - Stamina + - HP + ----------------------------- + */ + + + + /* + Try to use the ability. + */ + bool Use(Character actor, Vector2 target); + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs.meta b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs.meta new file mode 100644 index 00000000..61a3b2ea --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAbility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ce6bc2fefa543f14d8f247ae75d52b63 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs b/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs new file mode 100644 index 00000000..6fdcdfb0 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs @@ -0,0 +1,23 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Interface that represents an attack. + */ + public interface IAttack : IAbility { + /* + The attack stats of the ability. + */ + IAttackStats AttackStats { get; } + + + + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs.meta b/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs.meta new file mode 100644 index 00000000..2973e2c7 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/Base/IAttack.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 40ec26590615cce489719a031d08410b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs new file mode 100644 index 00000000..b92dea6d --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs @@ -0,0 +1,44 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Basic projectile attack for the player.. + */ + public class BasicProjectile1 : BaseAttack { + //protected static readonly GameObject PROJECTILE_BASE = new AttackMovement(); + + /* + The attack stats of the ability. + */ + public IAttackStats AttackStats { get; set; } + + + + public BasicProjectile1() { + Name = "Basic Player Projectile Attack"; + Id = 101; + Description = "A basic projectile shooting attack the player has."; + } + + + + /* + 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 override bool Activate(Character actor, Vector2 target) { + //MonoBehaviour.Instantiate(PROJECTILE_BASE, (Vector3) actor.transform.position, PROJECTILE_BASE.transform.rotation); + return true; + } + + } + +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs.meta b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs.meta new file mode 100644 index 00000000..11917128 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/Abilities/BasicProjectile1.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6dc6766c5fc7b88439f8e7051dce071f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- GitLab