diff --git a/MrBigsock/Assets/Code/Item/Inventory.cs b/MrBigsock/Assets/Code/Item/Inventory.cs index 7defaf7e13c0d82ff2848d815ac8b10a1ec18ceb..8a5b3f2981a3f116b41d677a0ddbced07506e37e 100644 --- a/MrBigsock/Assets/Code/Item/Inventory.cs +++ b/MrBigsock/Assets/Code/Item/Inventory.cs @@ -25,7 +25,7 @@ namespace BigSock.Item { /* The max number of items the inventory can hold. */ - public int Cap { get; set; } = 3; + public int Cap { get; set; } = 10; /* diff --git a/MrBigsock/Assets/Code/Item/Items/ItemCoffee.cs b/MrBigsock/Assets/Code/Item/Items/ItemCoffee.cs new file mode 100644 index 0000000000000000000000000000000000000000..cd715f61b33ab59d24488fa157a43992c72ba835 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items/ItemCoffee.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + A passive item that increases user's max hp by 25%. + */ + public class ItemCoffee : PassiveItemBase { + public override ulong Id => 103; + public override string Name => "Caffeinated Coffee"; + public override string Description => "Increases attack speed by 25%"; + + public ItemCoffee() { + Modifier = new CharacterStats{ + AttackSpeed = 0.25f, + }; + } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Items/ItemCoffee.cs.meta b/MrBigsock/Assets/Code/Item/Items/ItemCoffee.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..feefdd6dfb1022198e1ee781e34a6ca417e2ec83 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items/ItemCoffee.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d8951e56770b7214ead328a100d9441e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Item/Items/ItemFourEyes.cs b/MrBigsock/Assets/Code/Item/Items/ItemFourEyes.cs index 03ae1178b541a80612118f05ff38cb5c1b01dc7e..f3401629412b59b8f921a1d530b9aa0c850d8226 100644 --- a/MrBigsock/Assets/Code/Item/Items/ItemFourEyes.cs +++ b/MrBigsock/Assets/Code/Item/Items/ItemFourEyes.cs @@ -13,11 +13,26 @@ namespace BigSock.Item { public class ItemFourEyes : OnHitItemBase { public override ulong Id => 201; public override string Name => "Four Eyes"; - public override string Description => "30% chance to deal double dammage."; + public override string Description => "30% chance to deal double dammage. Has a 2 second cooldown."; public static readonly double CHANCE = 0.3; + public static readonly TimeSpan COOLDOWN = new TimeSpan(0, 0, 0, 2, 0); + + /* + Stores the next time the character can recieve damage. + */ + public DateTime NextTimeCanTrigger { get; private set; } = DateTime.Now; + + public ItemFourEyes() { } public override void Handler(Character source, Character target, AttackStats attack) { + // Check if the cooldown has happened yet. + if(NextTimeCanTrigger > DateTime.Now) return; + + // Start new trigger time. + NextTimeCanTrigger = DateTime.Now + COOLDOWN; + + // Check if it triggers. var roll = RND.NextDouble(); if(roll >= CHANCE) { attack.Damage *= 2; diff --git a/MrBigsock/Assets/Code/Item/Items/ItemLunch.cs b/MrBigsock/Assets/Code/Item/Items/ItemLunch.cs new file mode 100644 index 0000000000000000000000000000000000000000..90dca6f31c20f077152a73f16f1f8446ce9f6572 --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items/ItemLunch.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.InputSystem; + + +namespace BigSock.Item { + + /* + A passive item that increases user's max hp by 20%. + */ + public class ItemLunch : PassiveItemBase { + public override ulong Id => 102; + public override string Name => "Lunch"; + public override string Description => "Increases hp by 20%"; + + public ItemLunch() { + Modifier = new CharacterStats{ + MaxHP = 0.2f, + }; + } + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Item/Items/ItemLunch.cs.meta b/MrBigsock/Assets/Code/Item/Items/ItemLunch.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..2f927b08a16fa9ff01854b6c088679bea56452be --- /dev/null +++ b/MrBigsock/Assets/Code/Item/Items/ItemLunch.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e4644e42ad4bf244093930558ebb86d0 +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 7fcca51046af8da6f0d22f6e53aca3f351b52a9e..5f1a6a4ace8e6c3b22c8e668b6a0e2c10464cf45 100644 --- a/MrBigsock/Assets/Code/PlayerController.cs +++ b/MrBigsock/Assets/Code/PlayerController.cs @@ -3,8 +3,11 @@ using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; + + using BigSock.UI; using BigSock.Item; +using BigSock.Service; namespace BigSock { @@ -46,7 +49,8 @@ namespace BigSock { hpBar.SetHealth(Convert.ToInt32(HP)); //!! DEBUG: Add item to player at start to test if it works. - TryPickUpItem(new ItemFourEyes()); + TryPickUpItem(ItemService.SINGLETON.Get(201)); + TryPickUpItem(ItemService.SINGLETON.Get(201)); } @@ -103,7 +107,8 @@ namespace BigSock { //!! Code for testing the new item stuff. if(Input.GetKeyDown(KeyCode.Space)) { - TryPickUpItem(new ItemRunningShoes()); + var item = ItemService.SINGLETON.GetRandom(); // new ItemRunningShoes(); + TryPickUpItem(item); } } diff --git a/MrBigsock/Assets/Code/Services.meta b/MrBigsock/Assets/Code/Services.meta new file mode 100644 index 0000000000000000000000000000000000000000..97987a2fa59b5145745519a11feef91565c7ca79 --- /dev/null +++ b/MrBigsock/Assets/Code/Services.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c3d1c0c020522874bb0830077e109d3f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/Services/ItemService.cs b/MrBigsock/Assets/Code/Services/ItemService.cs new file mode 100644 index 0000000000000000000000000000000000000000..c739901a0b11b6f58a92ea998f302303a2fdb83c --- /dev/null +++ b/MrBigsock/Assets/Code/Services/ItemService.cs @@ -0,0 +1,83 @@ +using System.Collections; +using System; +using System.Linq; +using System.Collections.Generic; +using System.Reflection; + +using UnityEngine; +using UnityEngine.InputSystem; + +using BigSock.Item; + + +namespace BigSock.Service { + + /* + Service for handling items. + */ + public partial class ItemService { + /* + The instance to use. + */ + public static readonly ItemService SINGLETON = new ItemService(); + + /* + Get an instance of the item of the given id. + */ + public IItem Get(ulong id) { + if(_items.TryGetValue(id, out var res)) return _new(res); + return null; + } + + /* + Get a random item from the item pool. + */ + public IItem GetRandom() { + var num = _rnd.Next(_itemList.Count); + return _new(_itemList[num]); + } + + } + + public partial class ItemService { + private Dictionary<ulong, IItem> _items = new Dictionary<ulong, IItem>(); + private List<IItem> _itemList = new List<IItem>(); + + private System.Random _rnd = new System.Random(); + + private ItemService() { + _loadItems(); + } + + /* + Load the items into the dictionary. + (Hard-coded for now, use reflection later) + Reflection code: https://stackoverflow.com/a/6944605 + */ + private void _loadItems() { + // Get the classs that inherit the item base class. + var types = Assembly + .GetAssembly(typeof(ItemBase)) + .GetTypes() + .Where(myType => myType.IsClass + && !myType.IsAbstract + && myType.IsSubclassOf(typeof(ItemBase))); + + // Create list of instances. + _itemList = types + .Select(t => (IItem) Activator.CreateInstance(t, new object[0])) + .ToList(); + + // Map to a dictionary by their ids. + _items = _itemList + .ToDictionary(t => t.Id); + } + + /* + Creates a new instance of the object. + */ + private IItem _new(IItem obj) + => (IItem) Activator.CreateInstance(obj.GetType(), new object[0]); + + } +} \ No newline at end of file diff --git a/MrBigsock/Assets/Code/Services/ItemService.cs.meta b/MrBigsock/Assets/Code/Services/ItemService.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..b6453e1b1e506c98178add60761277751667716e --- /dev/null +++ b/MrBigsock/Assets/Code/Services/ItemService.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fe48543826f888744847f1c3ee05f2c8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MrBigsock/Assets/Code/attack/AttackMovement.cs b/MrBigsock/Assets/Code/attack/AttackMovement.cs index 30c7f101c5b40cc29bdb5881373121ac299b35ed..5ed4cc03c3546ebd8334d702e8d2cbb57d10f985 100644 --- a/MrBigsock/Assets/Code/attack/AttackMovement.cs +++ b/MrBigsock/Assets/Code/attack/AttackMovement.cs @@ -53,7 +53,7 @@ namespace BigSock { void OnCollisionEnter2D(Collision2D collision) { - print($"[AttackMovement.OnCollisionEnter2D()] {collision.transform.position}"); + //print($"[AttackMovement.OnCollisionEnter2D()] {collision.transform.position}"); var target = collision.gameObject.GetComponent<Character>(); if(target != null) {