Stack rework
This commit is contained in:
parent
5da9e11f36
commit
ea9c41054b
7 changed files with 60 additions and 39 deletions
|
@ -71,19 +71,25 @@ func can_be_merged(item : Item) -> bool:
|
|||
return item == held_item
|
||||
|
||||
## Add provided stack's amount to this amount. Returns null if stack is empty or items arent matching
|
||||
func merge_stack(stack: Stack) -> Stack:
|
||||
if stack == null or stack.held_item == null or stack.amount == 0:
|
||||
return stack
|
||||
func merge_stack(stack: Stack) -> bool:
|
||||
if stack == null or stack.is_valid() == false:
|
||||
return false
|
||||
|
||||
if filter and filter.is_equal(stack.held_item) == false:
|
||||
return false
|
||||
|
||||
if held_item == null:
|
||||
if filter != null and filter.is_equal(stack.held_item) == false:
|
||||
return stack
|
||||
held_item = stack.held_item
|
||||
amount = stack.amount
|
||||
return null
|
||||
if stack.held_item != held_item:
|
||||
return null
|
||||
var return_stack_amount = max(0,stack.amount-amount)
|
||||
amount += stack.amount - return_stack_amount
|
||||
if return_stack_amount == 0:
|
||||
return null
|
||||
return Stack.new(held_item,return_stack_amount)
|
||||
stack.invalidate()
|
||||
return true
|
||||
|
||||
var delta_amount = stack.amount - (held_item.stack_size - amount)
|
||||
amount += stack.amount
|
||||
|
||||
if delta_amount <= 0:
|
||||
stack.invalidate()
|
||||
return true
|
||||
|
||||
stack.amount = delta_amount
|
||||
return true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue