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

Added code to drop items and handle the effects of doing that.

parent 9d2440b8
No related branches found
No related tags found
1 merge request!22Implemented initial version of conditional items.
...@@ -253,6 +253,19 @@ namespace BigSock { ...@@ -253,6 +253,19 @@ namespace BigSock {
print($"[Character.TryPickUpItem()] {item.Name} NOT picked up. ({Inventory.Items.Count}/{Inventory.Cap})"); print($"[Character.TryPickUpItem()] {item.Name} NOT picked up. ({Inventory.Items.Count}/{Inventory.Cap})");
return false; 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;
}
} }
/* /*
......
...@@ -72,6 +72,21 @@ namespace BigSock { ...@@ -72,6 +72,21 @@ namespace BigSock {
AttackSpeed = a.AttackSpeed + b.AttackSpeed, 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. Multiplies the values of 2 character stats together.
......
...@@ -52,6 +52,8 @@ namespace BigSock.Item { ...@@ -52,6 +52,8 @@ namespace BigSock.Item {
if(item is PassiveItemBase passive) { if(item is PassiveItemBase passive) {
Modifier = Modifier.Add(passive.Modifier); Modifier = Modifier.Add(passive.Modifier);
} }
// Add the listener for this item to the owner.
else if(item is ConditionalItemBase conditional) { else if(item is ConditionalItemBase conditional) {
Owner.AddItemListener(conditional); Owner.AddItemListener(conditional);
} }
...@@ -60,5 +62,25 @@ namespace BigSock.Item { ...@@ -60,5 +62,25 @@ namespace BigSock.Item {
return true; 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
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