Skip to content

Commit

Permalink
Final touches
Browse files Browse the repository at this point in the history
  • Loading branch information
NancokPS2 committed Feb 25, 2024
1 parent 5f8310b commit d02facd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ func _ready():
user_authenticator.server_player_logged_in.connect(_on_server_player_logged_in)

# Connect to the disconnect signal, this is the trigger to emit the signal to remove the player from the server instance
_multiplayer_connection.multiplayer_api.peer_disconnected.connect(_on_server_peer_disconnected)
_multiplayer_connection.multiplayer_api.peer_disconnected.connect(
_on_server_peer_disconnected
)
else:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,46 +77,46 @@ func server_add_item(item: Item) -> bool:
return true

item.collision_layer = 0

#Inventory full
if items.size() >= size:
return false

#Try to stack
var existing_item: Item = null

#Look for an item that has available space.
for i_item in get_items_by_class(item.item_class):
if i_item.amount < i_item.amount_max:
existing_item = i_item
break

#If found, start the stacking.
if existing_item is Item:
var remaining_space: int = existing_item.amount_max - existing_item.amount
var amount_to_add: int = min(item.amount, remaining_space)
var surplus: int = max(0, item.amount - remaining_space)

#If there's space remaining, add some of this item's amount to the existing one.
#And remove it from the former.
#This is delegated to the server_set_item_amount() function which synchronizes amounts by itself.
if remaining_space > 0:
if remaining_space > 0:
server_set_item_amount(item.uuid, item.amount - amount_to_add)
server_set_item_amount(existing_item.uuid, existing_item.amount + amount_to_add)

#Any remaining amount is added as a separate item
if surplus > 0:
server_add_item(item)
_inventory_synchronizer_rpc.add_item(
_target_node.peer_id, item.name, item.item_class, item.amount
)

return true

#Adding the item from scratch
else:
items.append(item)

_inventory_synchronizer_rpc.add_item(
_target_node.peer_id, item.name, item.item_class, item.amount
)
Expand Down Expand Up @@ -158,13 +158,11 @@ func client_remove_item(item_uuid: String):
func server_set_item_amount(item_uuid: String, amount: int):
if not _target_node.multiplayer_connection.is_server():
return false

var item: Item = get_item(item_uuid)
if item != null:
item.amount = amount
_inventory_synchronizer_rpc.change_item_amount(_target_node.peer_id, item_uuid, amount)
else:
GodotLogger.error("This item does not exist!?")


func client_change_item_amount(item_uuid: String, amount: int):
Expand Down

0 comments on commit d02facd

Please sign in to comment.