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

Intial skeleton of the ability system.

parent d54c558f
No related branches found
No related tags found
1 merge request!15Fixing knockback & movement.
Showing
with 317 additions and 0 deletions
fileFormatVersion: 2
guid: 27a976b8ec0044e4ca0a1b2e9e3180e1
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ea9851c0a856efc41bea28abd815c6d0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
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
fileFormatVersion: 2
guid: 46edbd7e16fb5e740996dfed00e42fe0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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
fileFormatVersion: 2
guid: 26f8841e1cc588e4ab0747ee086e1656
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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
fileFormatVersion: 2
guid: ce6bc2fefa543f14d8f247ae75d52b63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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
fileFormatVersion: 2
guid: 40ec26590615cce489719a031d08410b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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
fileFormatVersion: 2
guid: 6dc6766c5fc7b88439f8e7051dce071f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
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