diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 3a04ccfd00919e28e66af357d3fb610280ac3888..de0bdcacdd805bfe9071fd611a69d3ee7735e957 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; +using BigSock.Item; namespace BigSock { // Common class for all characters. @@ -11,7 +12,7 @@ namespace BigSock { /* Attack speed of the character. */ - public float AttackSpeed => baseAttackSpeed; + public float AttackSpeed => Stats.AttackSpeed; public float baseAttackSpeed = 1; /* @@ -22,20 +23,20 @@ namespace BigSock { /* Movement speed of the character. */ - public float MovementSpeed => baseMovementSpeed; + public float MovementSpeed => Stats.MoveSpeed; public float baseMovementSpeed = 1; /* Damage of the character. */ - public float Damage => baseDamage; + public float Damage => Stats.Damage; public float baseDamage = 1; /* Knockback force */ - public float KnockbackForce => knockbackForce; + public float KnockbackForce => Stats.Knockback; public float knockbackForce = 150; @@ -52,7 +53,7 @@ namespace BigSock { /* Maximum hit points of the character. */ - public float MaxHP => baseMaxHP; + public float MaxHP => Stats.MaxHP; public float baseMaxHP = 10; @@ -81,8 +82,58 @@ namespace BigSock { protected Rigidbody2D rb; - void Start() { - rb = GetComponent<Rigidbody2D>(); + /* + The inventory of the character. + */ + public Inventory Inventory { get; protected set; } = new Inventory(); + + /* + The base stats of the character. + */ + public ICharacterStats BaseStats { get; protected set; } = new CharacterStats(); + + /* + The final stats of the character after applying modifiers. + */ + public ICharacterStats Stats { get; protected set; } = new CharacterStats(); + + + + protected virtual void Start() { + rb = GetComponent<Rigidbody2D>(); + + // Set the base stats. + BaseStats = new CharacterStats { + MaxHP = baseMaxHP, + Damage = baseDamage, + MoveSpeed = baseMovementSpeed, + Knockback = knockbackForce, + Range = 1, + AttackSpeed = baseAttackSpeed, + }; + UpdateModifiers(); + + } + + /* + Updates the modifiers to the character's stats. + */ + public void UpdateModifiers(ICharacterStats modifiers = null) { + modifiers ??= Inventory.Modifier; + Stats = BaseStats.Modify(modifiers); + } + + /* + Try to pick up an item. + */ + public bool TryPickUpItem(IItem item) { + if(Inventory.AddItem(item)) { + UpdateModifiers(); + print($"[Character.TryPickUpItem()] {item.Name} picked up. ({Inventory.Items.Count}/{Inventory.Cap})"); + return true; + } + print($"[Character.TryPickUpItem()] {item.Name} NOT picked up. ({Inventory.Items.Count}/{Inventory.Cap})"); + return false; } /* diff --git a/MrBigsock/Assets/Code/Core/CharacterStats.cs b/MrBigsock/Assets/Code/Core/CharacterStats.cs new file mode 100644 index 0000000000000000000000000000000000000000..e6e13cbabf07dda3571d6496fab421846b98eb1c --- /dev/null +++ b/MrBigsock/Assets/Code/Core/CharacterStats.cs @@ -0,0 +1,45 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + class represents the stats of a character. + */ + public class CharacterStats : ICharacterStats { + /* + The hp of the character. + */ + public float MaxHP { get; set; } + + /* + The damage of the character. + */ + public float Damage { get; set; } + + /* + The movement speed of the character. + */ + public float MoveSpeed { get; set; } + + /* + The knockback of the character. + */ + public float Knockback { get; set; } + + /* + The range of the character. + */ + public float Range { get; set; } + + /* + The attack speed of the character. + */ + public float AttackSpeed { get; set; } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/CharacterStats.cs.meta b/MrBigsock/Assets/Code/Core/CharacterStats.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..aa194f501fac12f79b35d5817f71673e224c9bff --- /dev/null +++ b/MrBigsock/Assets/Code/Core/CharacterStats.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 697f21373556c9549b064efc46c9730b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Core/ICharacterStats.cs b/MrBigsock/Assets/Code/Core/ICharacterStats.cs new file mode 100644 index 0000000000000000000000000000000000000000..afccfaf265773815843b27def98513049c26dcde --- /dev/null +++ b/MrBigsock/Assets/Code/Core/ICharacterStats.cs @@ -0,0 +1,100 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Interface represents the stats of a character. + */ + public interface ICharacterStats { + /* + The hp of the character. + */ + float MaxHP { get; } + + /* + The damage of the character. + */ + float Damage { get; } + + /* + The movement speed of the character. + */ + float MoveSpeed { get; } + + /* + The knockback of the character. + */ + float Knockback { get; } + + /* + The range of the character. + */ + float Range { get; } + + /* + The attack speed of the character. + */ + float AttackSpeed { get; } + + } + + /* + Holds extension methods for character stat objects. + */ + public static class CharacterStatsExtension { + /* + Identity object for character stats. + */ + public static readonly ICharacterStats IDENTITY = new CharacterStats{ + MaxHP = 1, + Damage = 1, + MoveSpeed = 1, + Knockback = 1, + Range = 1, + AttackSpeed = 1, + }; + + /* + Adds the values of 2 character stats together. + */ + public static ICharacterStats Add(this ICharacterStats a, ICharacterStats b) { + return new CharacterStats{ + MaxHP = a.MaxHP + b.MaxHP, + Damage = a.Damage + b.Damage, + MoveSpeed = a.MoveSpeed + b.MoveSpeed, + Knockback = a.Knockback + b.Knockback, + Range = a.Range + b.Range, + AttackSpeed = a.AttackSpeed + b.AttackSpeed, + }; + } + + /* + Multiplies the values of 2 character stats together. + */ + public static ICharacterStats Multiply(this ICharacterStats a, ICharacterStats b) { + return new CharacterStats{ + MaxHP = a.MaxHP * b.MaxHP, + Damage = a.Damage * b.Damage, + MoveSpeed = a.MoveSpeed * b.MoveSpeed, + Knockback = a.Knockback * b.Knockback, + Range = a.Range * b.Range, + AttackSpeed = a.AttackSpeed * b.AttackSpeed, + }; + } + + + /* + Modifies the first stat object by the second one. + Ex.: if the second is 20% hp, the result will be the first one, but with 20% more hp. + */ + public static ICharacterStats Modify(this ICharacterStats a, ICharacterStats b) { + return a.Multiply(b.Add(IDENTITY)); + } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Core/ICharacterStats.cs.meta b/MrBigsock/Assets/Code/Core/ICharacterStats.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..48fb62635f548d34ef2b2d9eef3cad9ce2ee6225 --- /dev/null +++ b/MrBigsock/Assets/Code/Core/ICharacterStats.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d67cdc4f8a1fd31439d31116ad4821b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item.meta b/MrBigsock/Assets/Code/Item.meta new file mode 100644 index 0000000000000000000000000000000000000000..fa111966b15fa7cc106df13fefe50dbd37dddfb7 --- /dev/null +++ b/MrBigsock/Assets/Code/Item.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 023fe0779d2abeb44ad4470ad4e5642a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Base.meta b/MrBigsock/Assets/Code/Item/Base.meta new file mode 100644 index 0000000000000000000000000000000000000000..0b806ae62abd931bdeb3f79f166131d0948bd6d4 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fdc1d36c8d53fe54898d8cccff53b536 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Base/ConditionalItemBase.cs b/MrBigsock/Assets/Code/Item/Base/ConditionalItemBase.cs new file mode 100644 index 0000000000000000000000000000000000000000..9561289398ced21d1238d3b72eed0f9c4bdae616 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/ConditionalItemBase.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + A class that represents an item that an effect when a condition is meet. + */ + public abstract class ConditionalItemBase : ItemBase { + /* + The type of trigger this item uses. + */ + public TriggerType Trigger { get; set; } + + /* + The handler to activate when the condition is triggered. + */ + public Action<ICharEventParams> Handler { get; set; } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Base/ConditionalItemBase.cs.meta b/MrBigsock/Assets/Code/Item/Base/ConditionalItemBase.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..ec5d95648b7e2b2f55f9eeb61c722713513845a8 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/ConditionalItemBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 15064819886e52a4a85b803e26467c05 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Base/IItem.cs b/MrBigsock/Assets/Code/Item/Base/IItem.cs new file mode 100644 index 0000000000000000000000000000000000000000..720fa112b799cb7f7f8373b9b32617315939e313 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/IItem.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + An interface representing a generic item. + */ + public interface IItem { + /* + The name of the item. + */ + string Name { get; } + + /* + The description of the item. + */ + string Description { get; } + + /* + The id of the item. + */ + ulong Id { get; } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Base/IItem.cs.meta b/MrBigsock/Assets/Code/Item/Base/IItem.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..7c3c5385da20ccce838959983475ea760de2d696 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/IItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0a4fa79a9560deb45976fa4bebd5d1ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Base/ItemBase.cs b/MrBigsock/Assets/Code/Item/Base/ItemBase.cs new file mode 100644 index 0000000000000000000000000000000000000000..bd74fdd3b23a7dd5f0ef149b226700c37db581ab --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/ItemBase.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + A class that represents the root of all items. + */ + public abstract class ItemBase : IItem { + /* + The name of the item. + */ + public string Name { get; protected set; } + + /* + The description of the item. + */ + public string Description { get; protected set; } + + /* + The id of the item. + */ + public ulong Id { get; protected set; } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Base/ItemBase.cs.meta b/MrBigsock/Assets/Code/Item/Base/ItemBase.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..fa7b453195eae4547f3c337f3db982ae379d264e --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/ItemBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e99afc192b85f3d43a7159cbbd68a39c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Base/PassiveItemBase.cs b/MrBigsock/Assets/Code/Item/Base/PassiveItemBase.cs new file mode 100644 index 0000000000000000000000000000000000000000..1b09c3b45c9e33bb67790386d61559486ca16d0e --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/PassiveItemBase.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + A class that represents an item that provides passive stat boosts. + */ + public abstract class PassiveItemBase : ItemBase { + /* + The modifier of the item. + */ + public ICharacterStats Modifier { get; set; } + + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Base/PassiveItemBase.cs.meta b/MrBigsock/Assets/Code/Item/Base/PassiveItemBase.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d264b9a2f2dfb6752f394787448ba76f09828638 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/PassiveItemBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 779b8b8f25258cf4983c1ac9d442cb8c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Base/TriggerType.cs b/MrBigsock/Assets/Code/Item/Base/TriggerType.cs new file mode 100644 index 0000000000000000000000000000000000000000..5ea86686ea3a336febb9af898ac444e10196e4c8 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/TriggerType.cs @@ -0,0 +1,20 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + The type of trigger that activates the item's effect. + */ + public enum TriggerType { + None, + OnKill, + OnAttack, + OnHit, + OnDamage, + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Base/TriggerType.cs.meta b/MrBigsock/Assets/Code/Item/Base/TriggerType.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..de080a71d83b00ed33ee9f7a465d794301ca6be0 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Base/TriggerType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 39ba995ac8dbf00498eb995c98f71402 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/EventParams.meta b/MrBigsock/Assets/Code/Item/EventParams.meta new file mode 100644 index 0000000000000000000000000000000000000000..ed6be0cab34c3379653b0fff94562c4f859679aa --- /dev/null +++ b/MrBigsock/Assets/Code/Item/EventParams.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b2c87c112ffd1a4dbacf0405214b30b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/EventParams/CharEventParams.cs b/MrBigsock/Assets/Code/Item/EventParams/CharEventParams.cs new file mode 100644 index 0000000000000000000000000000000000000000..fa52874e947279b9a67f649f19856c68a79ecf53 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/EventParams/CharEventParams.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Class that represents the parameters of a generic character event. + */ + public class CharEventParams : ICharEventParams { + /* + The character that own's the event. + */ + public Character Source { get; set; } + + /* + The character that triggered the event. (If any) + ex.: OnKill -> the killed enemy. OnDamage -> Enemy that dealt the damage. + */ + public Character Target { get; set; } + + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/EventParams/CharEventParams.cs.meta b/MrBigsock/Assets/Code/Item/EventParams/CharEventParams.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..d594b12ab5bbbb768b16315448091d7d834a9106 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/EventParams/CharEventParams.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 69465ff2019a5bb428771fa1c74e4f41 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/EventParams/ICharEventParms.cs b/MrBigsock/Assets/Code/Item/EventParams/ICharEventParms.cs new file mode 100644 index 0000000000000000000000000000000000000000..8204f89ee6af36be47ef6fd8c0c851be92a4e4a7 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/EventParams/ICharEventParms.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock { + + /* + Interface that represents the parameters of a generic character event. + */ + public interface ICharEventParams { + /* + The character that own's the event. + */ + Character Source { get; } + + /* + The character that triggered the event. (If any) + ex.: OnKill -> the killed enemy. OnDamage -> Enemy that dealt the damage. + */ + Character Target { get; } + + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/EventParams/ICharEventParms.cs.meta b/MrBigsock/Assets/Code/Item/EventParams/ICharEventParms.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..1161d2b5f7ac2f2593134a08c62c6209280e364e --- /dev/null +++ b/MrBigsock/Assets/Code/Item/EventParams/ICharEventParms.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f392d99fa5161e04791a522b7becc933 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Inventory.cs b/MrBigsock/Assets/Code/Item/Inventory.cs new file mode 100644 index 0000000000000000000000000000000000000000..26c4656832fcf521ae5c2ccb164171312edf8f28 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Inventory.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + An inventory of a character. + */ + public class Inventory { + /* + The items in the inventory. + */ + public List<IItem> Items { get; protected set; } = new List<IItem>(); + + /* + The modifier from all the passives. + */ + public ICharacterStats Modifier { get; protected set; } = new CharacterStats(); + + + /* + The max number of items the inventory can hold. + */ + public int Cap { get; set; } = 3; + + + /* + Adds an item to the inventory and manages changes. + */ + public bool AddItem(IItem item) { + if(Items.Count >= Cap) return false; + + Items.Add(item); + + // Add the passive effects to the modifier. + if(item is PassiveItemBase passive) { + Modifier = Modifier.Add(passive.Modifier); + } + //! Add ifs to handle the other 2 types of items. + + return true; + } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Inventory.cs.meta b/MrBigsock/Assets/Code/Item/Inventory.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..f35fc65d8c981db6397e9cf58dcbfce6192b66ca --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Inventory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 91c4ea7605d846e4a8ea5208d2217072 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Items.meta b/MrBigsock/Assets/Code/Item/Items.meta new file mode 100644 index 0000000000000000000000000000000000000000..0970a19ed437c91a865ed0fc2b94c0e2d91cbd3d --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: dbcc22c9f61379c4e9676afbe7eb8feb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Items/RunningShoes.cs b/MrBigsock/Assets/Code/Item/Items/RunningShoes.cs new file mode 100644 index 0000000000000000000000000000000000000000..618fdef69119bb7a3d8b3287512a4671f78d51b1 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items/RunningShoes.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + A passive item that increases user's running speed by 50%. + */ + public class RunningShoes : PassiveItemBase { + public RunningShoes() { + Id = 101; + Name = "Running Shoes"; + Description = "Increases movement speed by 50%"; + Modifier = new CharacterStats{ + MoveSpeed = 0.5f, + }; + } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Items/RunningShoes.cs.meta b/MrBigsock/Assets/Code/Item/Items/RunningShoes.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..791c93b1d01a17f77cac06836a39c1c2ff9c6cd1 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items/RunningShoes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12406fa4fcf374142ad545946396cbde +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Root.meta b/MrBigsock/Assets/Code/Item/Root.meta new file mode 100644 index 0000000000000000000000000000000000000000..ebb119032c2e6e46d02d06a64330f22c93ccccc2 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Root.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fad9ca94bd85fe14da5644defaaf3820 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/PlayerController.cs b/MrBigsock/Assets/Code/PlayerController.cs index 0711143f7fb5eb7509ca9b5ae0815edff431225b..dea96a53c392c6ca7d24236fa97ad348aa716053 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using BigSock.UI; +using BigSock.Item; namespace BigSock { @@ -36,13 +37,13 @@ namespace BigSock { // Start is called before the first frame update - void Start() + protected override void Start() { - rb = GetComponent<Rigidbody2D>(); - animator = GetComponent<Animator>(); - spriteRenderer = GetComponent<SpriteRenderer>(); - hpBar.SetMaxHealth(Convert.ToInt32(MaxHP)); - hpBar.SetHealth(Convert.ToInt32(HP)); + base.Start(); + animator = GetComponent<Animator>(); + spriteRenderer = GetComponent<SpriteRenderer>(); + hpBar.SetMaxHealth(Convert.ToInt32(MaxHP)); + hpBar.SetHealth(Convert.ToInt32(HP)); } @@ -102,6 +103,11 @@ namespace BigSock { } + + //!! Code for testing the new item stuff. + if(Input.GetKeyDown(KeyCode.Space)) { + TryPickUpItem(new RunningShoes()); + } } diff --git a/MrBigsock/Assets/Code/Slime/SlimeController.cs b/MrBigsock/Assets/Code/Slime/SlimeController.cs index f8b89ba4552430b3ecc6f0f16489c05efa57c4e4..743445cbf21abd97c6aced09311cc6fe9a8dcd90 100644 --- a/MrBigsock/Assets/Code/Slime/SlimeController.cs +++ b/MrBigsock/Assets/Code/Slime/SlimeController.cs @@ -7,21 +7,21 @@ using System; namespace BigSock { - public partial class SlimeController : Character { - public float collisionOffset = 0.05f; - public ContactFilter2D movementFilter; - List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); + public partial class SlimeController : EnemyController { + //public float collisionOffset = 0.05f; + //public ContactFilter2D movementFilter; + //List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); - private Transform target; - Animator m_Animator; - private float distance; + //private Transform target; + //Animator m_Animator; + //private float distance; - private float canAttack; + //private float canAttack; - private EmptyCollider followCollider; - private EmptyCollider attackCollider; + //private EmptyCollider followCollider; + //private EmptyCollider attackCollider; - private bool isInMelee = false; + //private bool isInMelee = false; //Rigidbody2D rb; @@ -63,40 +63,24 @@ namespace BigSock { public double LeapForce => MovementSpeed * 4; - void Start() { - rb = GetComponent<Rigidbody2D>(); - - m_Animator = gameObject.GetComponent<Animator>(); - - followCollider = transform.Find("followCollider").GetComponent<EmptyCollider>(); - followCollider.OnColliderEnter2D_Action += Move_OnColliderEnter2D; - followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; - followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; - - attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); - attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; - attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; - attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; - } - + //void Start() { + // rb = GetComponent<Rigidbody2D>(); + // m_Animator = gameObject.GetComponent<Animator>(); + // followCollider = transform.Find("followCollider").GetComponent<EmptyCollider>(); + // followCollider.OnColliderEnter2D_Action += Move_OnColliderEnter2D; + // followCollider.OnColliderStay2D_Action += Move_OnColliderStay2D; + // followCollider.OnColliderExit2D_Action += Move_OnColliderExit2D; + // attackCollider = transform.Find("MeleeCollider").GetComponent<EmptyCollider>(); + // attackCollider.OnColliderEnter2D_Action += Attack_OnColliderEnter2D; + // attackCollider.OnColliderStay2D_Action += Attack_OnColliderStay2D; + // attackCollider.OnColliderExit2D_Action += Attack_OnColliderExit2D; + //} - - private void RotateAnimation(Vector2 direction) - { - if (direction.x > 0.01f){ - gameObject.GetComponent<SpriteRenderer>().flipX = false; - } - else if (direction.x < -0.01f){ - gameObject.GetComponent<SpriteRenderer>().flipX = true; - } - - } - - private void Update() { + protected override void Update() { if(State == SlimeState.Idle) { // If it has a target and has idled long enough. if(target != null && DateTime.Now >= NextTimeStateCanChange) { @@ -160,37 +144,36 @@ namespace BigSock { */ public partial class SlimeController { - private void Attack_OnColliderEnter2D(Collider2D other) { - if (other.gameObject.tag == "Player") - isInMelee = true; - } - - - private void Attack_OnColliderStay2D(Collider2D other) { - var player = other.gameObject.GetComponent<PlayerController>(); - if (player != null) { - // Create attack object. - var attack = new AttackStats{ - Damage = Damage, - Knockback = KnockbackForce, - Range = 0, - AttackSpeed = AttackSpeed, - Source = transform.position, - }; - - // Get the player to take the damage. - if(player.TakeDamage(attack)) { - //knockback ? - //animer nå ? - - } - } - } - - private void Attack_OnColliderExit2D(Collider2D other){ - if (other.gameObject.tag == "Player") - isInMelee = false; - } + //private void Attack_OnColliderEnter2D(Collider2D other) { + // if (other.gameObject.tag == "Player") + // isInMelee = true; + //} + + + //private void Attack_OnColliderStay2D(Collider2D other) { + // var player = other.gameObject.GetComponent<PlayerController>(); + // if (player != null) { + // // Create attack object. + // var attack = new AttackStats{ + // Damage = Damage, + // Knockback = KnockbackForce, + // Range = 0, + // AttackSpeed = AttackSpeed, + // Source = transform.position, + // }; + // // Get the player to take the damage. + // if(player.TakeDamage(attack)) { + // //knockback ? + // //animer nå ? + // + // } + // } + //} + + //private void Attack_OnColliderExit2D(Collider2D other){ + // if (other.gameObject.tag == "Player") + // isInMelee = false; + //} } @@ -199,18 +182,15 @@ namespace BigSock { */ public partial class SlimeController { - private void Move_OnColliderEnter2D(Collider2D other) { + protected override void Move_OnColliderEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("walk"); target = other.transform; } } - private void Move_OnColliderStay2D(Collider2D other) { - if (other.gameObject.tag == "Player") { } - } - private void Move_OnColliderExit2D(Collider2D other) { + protected override void Move_OnColliderExit2D(Collider2D other) { if (other.gameObject.tag == "Player") { //m_Animator.SetTrigger("idle"); target = null; diff --git a/MrBigsock/Assets/Code/orc/EnemyController.cs b/MrBigsock/Assets/Code/orc/EnemyController.cs index fb98ebe58dffa93a1d9e4ca4322caf8c6c82af23..5e286172793b1282a79e2395d207afc5c7f592cc 100644 --- a/MrBigsock/Assets/Code/orc/EnemyController.cs +++ b/MrBigsock/Assets/Code/orc/EnemyController.cs @@ -10,26 +10,26 @@ namespace BigSock { public partial class EnemyController : Character { public float collisionOffset = 0.05f; public ContactFilter2D movementFilter; - List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); + protected List<RaycastHit2D> castCollisions = new List<RaycastHit2D>(); - private Transform target; - Animator m_Animator; - private float distance; + protected Transform target; + protected Animator m_Animator; + protected float distance; - private float canAttack; + protected float canAttack; - private EmptyCollider followCollider; - private EmptyCollider attackCollider; + protected EmptyCollider followCollider; + protected EmptyCollider attackCollider; - private bool isInMelee = false; + protected bool isInMelee = false; //Rigidbody2D rb; // private Collider2D_Proxy secondCollider; - void Start(){ - rb = GetComponent<Rigidbody2D>(); + protected override void Start() { + base.Start(); m_Animator = gameObject.GetComponent<Animator>(); @@ -50,7 +50,7 @@ namespace BigSock { - private void RotateAnimation(Vector2 direction) { + protected virtual void RotateAnimation(Vector2 direction) { if (direction.x > 0.01f){ gameObject.GetComponent<SpriteRenderer>().flipX = false; } @@ -59,7 +59,7 @@ namespace BigSock { } } - private void Update(){ + protected virtual void Update() { if (target != null && !isInMelee){ /* //walk @@ -78,38 +78,7 @@ namespace BigSock { } } - - - private bool TryMove_OLD(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; - } - - } } @@ -118,14 +87,13 @@ namespace BigSock { */ public partial class EnemyController { - private void Attack_OnColliderEnter2D(Collider2D other){ - if (other.gameObject.tag == "Player") - isInMelee = true; + protected virtual void Attack_OnColliderEnter2D(Collider2D other) { + if (other.gameObject.tag == "Player") isInMelee = true; } - private void Attack_OnColliderStay2D(Collider2D other) { + protected virtual void Attack_OnColliderStay2D(Collider2D other) { var player = other.gameObject.GetComponent<PlayerController>(); if(player != null) { // Create attack object. @@ -146,9 +114,9 @@ namespace BigSock { } } } - private void Attack_OnColliderExit2D(Collider2D other){ - if (other.gameObject.tag == "Player") - isInMelee = false; + protected virtual void Attack_OnColliderExit2D(Collider2D other) { + if (other.gameObject.tag == "Player") + isInMelee = false; } } @@ -158,32 +126,26 @@ namespace BigSock { */ public partial class EnemyController { - private void Move_OnColliderEnter2D(Collider2D other) - { - Debug.Log("enter"); - if (other.gameObject.tag == "Player"){ - Debug.Log("enter if"); - - m_Animator.SetTrigger("walk"); - target = other.transform; - } + protected virtual void Move_OnColliderEnter2D(Collider2D other) { + //Debug.Log("enter"); + if (other.gameObject.tag == "Player"){ + //Debug.Log("enter if"); + + m_Animator.SetTrigger("walk"); + target = other.transform; + } } - private void Move_OnColliderStay2D(Collider2D other) - { - - if (other.gameObject.tag == "Player"){ - - } + protected virtual void Move_OnColliderStay2D(Collider2D other) { + } - private void Move_OnColliderExit2D(Collider2D other) - { - if (other.gameObject.tag == "Player"){ - m_Animator.SetTrigger("idle"); - target = other.transform; - target = null; - } + protected virtual void Move_OnColliderExit2D(Collider2D other) { + if (other.gameObject.tag == "Player"){ + m_Animator.SetTrigger("idle"); + target = other.transform; + target = null; + } } }