diff --git a/MrBigsock/Assets/Code/Character.cs b/MrBigsock/Assets/Code/Character.cs index 654604a12a3e6df918661b1408e90e2585c88c8f..f756423909c97f32fa3399166673f93690bde49f 100644 --- a/MrBigsock/Assets/Code/Character.cs +++ b/MrBigsock/Assets/Code/Character.cs @@ -253,6 +253,19 @@ namespace BigSock { print($"[Character.TryPickUpItem()] {item.Name} NOT picked up. ({Inventory.Items.Count}/{Inventory.Cap})"); return false; } + + /* + Try to drop an item. + */ + public bool TryDropItem(IItem item) { + if(Inventory.RemoveItem(item)) { + UpdateModifiers(); + print($"[Character.TryDropItem()] {item.Name} dropped. ({Inventory.Items.Count}/{Inventory.Cap})"); + return true; + } + print($"[Character.TryDropItem()] {item.Name} NOT dropped. ({Inventory.Items.Count}/{Inventory.Cap})"); + return false; + } } /* diff --git a/MrBigsock/Assets/Code/Core/ICharacterStats.cs b/MrBigsock/Assets/Code/Core/ICharacterStats.cs index afccfaf265773815843b27def98513049c26dcde..fdc3f74af35fd24e0c7cdec0e6bb0b2862382a19 100644 --- a/MrBigsock/Assets/Code/Core/ICharacterStats.cs +++ b/MrBigsock/Assets/Code/Core/ICharacterStats.cs @@ -72,6 +72,21 @@ namespace BigSock { AttackSpeed = a.AttackSpeed + b.AttackSpeed, }; } + + /* + Removes the values of one stat object from the other. + Effectively a - b. + */ + public static ICharacterStats Remove(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. diff --git a/MrBigsock/Assets/Code/Item/Inventory.cs b/MrBigsock/Assets/Code/Item/Inventory.cs index 2b8a75e1daaae76246547a8a8d34b6eb9fb6bb1a..7defaf7e13c0d82ff2848d815ac8b10a1ec18ceb 100644 --- a/MrBigsock/Assets/Code/Item/Inventory.cs +++ b/MrBigsock/Assets/Code/Item/Inventory.cs @@ -52,6 +52,8 @@ namespace BigSock.Item { if(item is PassiveItemBase passive) { Modifier = Modifier.Add(passive.Modifier); } + + // Add the listener for this item to the owner. else if(item is ConditionalItemBase conditional) { Owner.AddItemListener(conditional); } @@ -60,5 +62,25 @@ namespace BigSock.Item { return true; } + /* + Removes an item from the inventory and manages changes. + */ + public bool RemoveItem(IItem item) { + if(!Items.Remove(item)) return false; + + // Remove the passive effects from the modifier. + if(item is PassiveItemBase passive) { + Modifier = Modifier.Remove(passive.Modifier); + } + + // Remove the listener for this item from the owner. + else if(item is ConditionalItemBase conditional) { + Owner.RemoveItemListener(conditional); + } + //! Add ifs to handle the other 2 types of items. + + return true; + } + } } \ No newline at end of file