diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index eeba1738d63a48b44c5ccfe4d070714d8788b811..3a04ccfd00919e28e66af357d3fb610280ac3888 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -99,18 +99,20 @@ namespace BigSock { } /* - Adds damage to the player if they don't have IFrames. + Try to move in a given direction. */ - public bool TakeDamage(float amount) { - return TakeDamage(new AttackStats{ - Damage = amount, - }); + protected virtual bool TryMove(Vector2 direction) { + if(direction != Vector2.zero) { + rb.AddForce(direction * (float) MovementSpeed * Time.fixedDeltaTime, ForceMode2D.Impulse); + return true; + } + return false; } /* Adds damage to the player if they don't have IFrames. */ - public bool TakeDamage(IAttackStats attack) { + public virtual bool TakeDamage(IAttackStats attack) { // Check if player has IFrames if(NextTimeCanTakeDamage > DateTime.Now) return false; @@ -155,9 +157,9 @@ namespace BigSock { /* Method for what to do when the character dies. */ - protected void OnDeath() { + protected virtual void OnDeath() { print($"[Character.TryKill()] start. | {HP}, {Alive}"); - Destroy(this); + Destroy(gameObject); } } diff --git a/MrBigsock/Assets/Code/Core/Abilities.meta b/MrBigsock/Assets/Code/Core/Abilities.meta new file mode 100644 index 0000000000000000000000000000000000000000..ca28cb71dc5ce57b6f6a7638aec8219317f26ecd --- /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 0000000000000000000000000000000000000000..b34f3d2fa3bb152418ecc737db0bbb082c621f08 --- /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 0000000000000000000000000000000000000000..aeb2f81303eb2b14696519bb3c445a6e9baf42aa --- /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 0000000000000000000000000000000000000000..c077a0b5a8e16c8a8ac7a2a2404891a581405983 --- /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 0000000000000000000000000000000000000000..99de155333fa836e121ffba90869c49a53a354b1 --- /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 0000000000000000000000000000000000000000..dac0115c3542ab1836100e4be1ef9d35e069c5a5 --- /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 0000000000000000000000000000000000000000..80fa70963e840b5f6aef56553106009215b67628 --- /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 0000000000000000000000000000000000000000..61a3b2ea8a94981875b052e84ef783f8e014b052 --- /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 0000000000000000000000000000000000000000..6fdcdfb0277b7e0fda9d3d1024e93248556bd3a5 --- /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 0000000000000000000000000000000000000000..2973e2c72983d21821acc284020d1c966537e84d --- /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 0000000000000000000000000000000000000000..b92dea6dbbca44f2f838dd7ec45ad064ef545bc1 --- /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 0000000000000000000000000000000000000000..11917128acf55833b6fb01faea73be264cdfed32 --- /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: diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index f8fad1276b270ec54bd0d89ae09341697ed734d4..0711143f7fb5eb7509ca9b5ae0815edff431225b 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -104,7 +104,10 @@ namespace BigSock { } } - private bool TryMove(Vector2 direction) { + + + + private bool TryMove_OLD(Vector2 direction) { if(direction != Vector2.zero) { // Check for potential collisions int count = rb.Cast( @@ -123,7 +126,8 @@ namespace BigSock { // Can't move if there's no direction to move in return false; } - + + // } void OnMove(InputValue movementValue) { diff --git a/MrBigsock/Assets/Code/Slime/SlimeController.cs b/MrBigsock/Assets/Code/Slime/SlimeController.cs index a7d612764b42147510de8700dc9ccd8b0895a0af..f8b89ba4552430b3ecc6f0f16489c05efa57c4e4 100644 --- a/MrBigsock/Assets/Code/Slime/SlimeController.cs +++ b/MrBigsock/Assets/Code/Slime/SlimeController.cs @@ -118,7 +118,8 @@ namespace BigSock { var temp = (pos - rb.transform.position); temp.z = 0; var direction = temp.normalized; - rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + //rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + TryMove(direction); // Update the state. State = SlimeState.Leaping; @@ -139,36 +140,18 @@ namespace BigSock { } - private bool TryMove(Vector2 direction) { - + + /* + Try to move in a given direction. + */ + protected override bool TryMove(Vector2 direction) { if(direction != Vector2.zero) { - - // Check for potential collisions - int count = rb.Cast( - direction, // X and Y values between -1 and 1 that represent the direction from the body to look for collisions - movementFilter, // The settings that determine where a collision can occur on such as layers to collide with - castCollisions, // List of collisions to store the found collisions into after the Cast is finished - (float) MovementSpeed * Time.fixedDeltaTime + collisionOffset); // The amount to cast equal to the movement plus an offset - //Debug.Log($"cast {string.Join(", ", castCollisions.Select(x => $"{x.collider.isTrigger}"))}"); - //Debug.Log($"rb.position : {rb.position}"); - //Debug.Log($"target.position : {target.position}"); - //Debug.Log($"direction : {direction}"); - if(count == 0){ - rb.MovePosition(rb.position + direction * (float) MovementSpeed * Time.fixedDeltaTime); - //print($"rb.position {rb.position}"); - //print($"direction {direction}"); - RotateAnimation(direction); - - return true; - } else { - return false; - } - } else { - // Can't move if there's no direction to move in - return false; + rb.AddForce((float) LeapForce * direction, ForceMode2D.Impulse); + return true; } - + return false; } + } diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index f8cc663fb3e7ef4f8d49bf1d9cf361e12d9baf4d..4768aed3df61a8e6f88499b42378da4fd421d130 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -19,7 +19,7 @@ namespace BigSock { public float baseDamage = 1; public float KnockbackForce => knockbackForce; - public float knockbackForce = 50; + public float knockbackForce = 1; // Start is called before the first frame update @@ -50,7 +50,7 @@ namespace BigSock { void OnCollisionEnter2D(Collision2D collision) { print($"[AttackMovement.OnCollisionEnter2D()] {collision.transform.position}"); - var target = collision.gameObject.GetComponent<EnemyController>(); + var target = collision.gameObject.GetComponent<Character>(); if(target != null) { diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs index ed68aac6a524df55e0e0f8a0fa9e9d495eeb5490..fb98ebe58dffa93a1d9e4ca4322caf8c6c82af23 100644 --- a/MrBigsock/Assets/Code/orc/EnemyController.cs +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -38,7 +38,7 @@ namespace BigSock { followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; - attackCollider = transform.Find("AttackCollider").GetComponent<EmptyCollider>(); + attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; @@ -78,7 +78,9 @@ namespace BigSock { } } - private bool TryMove(Vector2 direction) { + + + private bool TryMove_OLD(Vector2 direction) { if(direction != Vector2.zero) { diff --git a/MrBigsock/Assets/Prefabs/BigSock.prefab b/MrBigsock/Assets/Prefabs/BigSock.prefab index 4377491706318209a491ee3f5fc607363ec1dae6..52165aac41096bbcd02f9a7d695e494321b089f5 100644 --- a/MrBigsock/Assets/Prefabs/BigSock.prefab +++ b/MrBigsock/Assets/Prefabs/BigSock.prefab @@ -132,11 +132,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 4 - baseMovementSpeed: 3 + baseMovementSpeed: 10 baseDamage: 1 - KnockbackForce: 150 + knockbackForce: 150 baseHP: 10 baseMaxHP: 10 + hpBar: {fileID: 0} collisionOffset: 0.05 movementFilter: useTriggers: 0 @@ -165,8 +166,8 @@ Rigidbody2D: m_Simulated: 1 m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 - m_Mass: 1 - m_LinearDrag: 1 + m_Mass: 0.5 + m_LinearDrag: 2 m_AngularDrag: 0.05 m_GravityScale: 0 m_Material: {fileID: 0} diff --git a/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab b/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab index 55991571520c7f059ed2cfc2f492e769ac1e6334..0326212c7cb41ab30e3dcf5569d19b697c41df07 100644 --- a/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab +++ b/MrBigsock/Assets/Prefabs/Enemy_Slime.prefab @@ -101,9 +101,9 @@ Rigidbody2D: m_BodyType: 0 m_Simulated: 1 m_UseFullKinematicContacts: 1 - m_UseAutoMass: 1 - m_Mass: 0.6243647 - m_LinearDrag: 2.5 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 2 m_AngularDrag: 0 m_GravityScale: 0 m_Material: {fileID: 0} @@ -172,7 +172,7 @@ MonoBehaviour: baseAttackSpeed: 1 baseMovementSpeed: 2 baseDamage: 1 - knockbackForce: 150 + knockbackForce: 2 baseHP: 10 baseMaxHP: 10 collisionOffset: 0.05 diff --git a/MrBigsock/Assets/Prefabs/attack.prefab b/MrBigsock/Assets/Prefabs/attack.prefab index 22ddb3611f09dea88044c02f546a8a856e5a7087..0e34dd60f0bd76b077a05a901efb23f750857270 100644 --- a/MrBigsock/Assets/Prefabs/attack.prefab +++ b/MrBigsock/Assets/Prefabs/attack.prefab @@ -161,3 +161,4 @@ MonoBehaviour: m_EditorClassIdentifier: speed: 10 baseDamage: 1 + knockbackForce: 2 diff --git a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab index 9df14e8df38d288bfa3b48089d173fe7f8ef47d7..f54b01037d71fad82c05ecf8fbc94675e6e271c3 100644 --- a/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab +++ b/MrBigsock/Assets/Prefabs/enemy_orc_warrior.prefab @@ -101,9 +101,9 @@ Rigidbody2D: m_BodyType: 0 m_Simulated: 1 m_UseFullKinematicContacts: 1 - m_UseAutoMass: 1 - m_Mass: 0.6243647 - m_LinearDrag: 2.5 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 2 m_AngularDrag: 0 m_GravityScale: 0 m_Material: {fileID: 0} @@ -144,9 +144,9 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: baseAttackSpeed: 1 - baseMovementSpeed: 2 + baseMovementSpeed: 4 baseDamage: 1 - KnockbackForce: 150 + knockbackForce: 3 baseHP: 10 baseMaxHP: 10 collisionOffset: 0.05 @@ -248,7 +248,7 @@ MonoBehaviour: m_GameObject: {fileID: 7539630614846898202} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b1aeda8fe8f5c1f4fa7a8f47e2864211, type: 3} + m_Script: {fileID: 11500000, guid: 02e1a714e20472c46a1f156e232741cd, type: 3} m_Name: m_EditorClassIdentifier: --- !u!1 &8620845285361089561 @@ -309,6 +309,6 @@ MonoBehaviour: m_GameObject: {fileID: 8620845285361089561} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b1aeda8fe8f5c1f4fa7a8f47e2864211, type: 3} + m_Script: {fileID: 11500000, guid: 02e1a714e20472c46a1f156e232741cd, type: 3} m_Name: m_EditorClassIdentifier: