added inventory equipment system
This commit is contained in:
@@ -599,6 +599,18 @@ func _apply_appearance_to_sprites():
|
||||
func _on_character_changed(_char: CharacterStats):
|
||||
# Update appearance when character stats change (e.g., equipment)
|
||||
_apply_appearance_to_sprites()
|
||||
|
||||
# Sync equipment changes to other clients
|
||||
if multiplayer.has_multiplayer_peer() and is_multiplayer_authority() and can_send_rpcs and is_inside_tree():
|
||||
# Sync equipment to all clients
|
||||
var equipment_data = {}
|
||||
for slot_name in character_stats.equipment.keys():
|
||||
var item = character_stats.equipment[slot_name]
|
||||
if item:
|
||||
equipment_data[slot_name] = item.save() # Serialize item data
|
||||
else:
|
||||
equipment_data[slot_name] = null
|
||||
_sync_equipment.rpc(equipment_data)
|
||||
|
||||
func _get_player_color() -> Color:
|
||||
# Legacy function - now returns white (no color tint)
|
||||
@@ -782,18 +794,20 @@ func _physics_process(delta):
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
# Skip input if controls are disabled (e.g., when player reached exit)
|
||||
if controls_disabled:
|
||||
velocity = velocity.lerp(Vector2.ZERO, delta * 8.0) # Slow down movement
|
||||
return
|
||||
|
||||
# Handle knockback timer
|
||||
# Handle knockback timer (always handle knockback, even when controls are disabled)
|
||||
if is_knocked_back:
|
||||
knockback_time += delta
|
||||
if knockback_time >= knockback_duration:
|
||||
is_knocked_back = false
|
||||
knockback_time = 0.0
|
||||
|
||||
# Skip input if controls are disabled (e.g., when inventory is open)
|
||||
# But still allow knockback to continue (handled above)
|
||||
if controls_disabled:
|
||||
if not is_knocked_back:
|
||||
velocity = velocity.lerp(Vector2.ZERO, delta * 8.0) # Slow down movement
|
||||
return
|
||||
|
||||
# Check if being held by someone
|
||||
var being_held_by_someone = false
|
||||
for other_player in get_tree().get_nodes_in_group("player"):
|
||||
@@ -2556,6 +2570,29 @@ func _sync_stats_update(kills_count: int, coins_count: int):
|
||||
character_stats.coin = coins_count
|
||||
print(name, " stats synced from server: kills=", kills_count, " coins=", coins_count)
|
||||
|
||||
@rpc("any_peer", "reliable")
|
||||
func _sync_equipment(equipment_data: Dictionary):
|
||||
# Client receives equipment update from server
|
||||
# Update equipment to match other players
|
||||
# Only process if we're not the authority (remote player)
|
||||
if is_multiplayer_authority():
|
||||
return # Authority ignores this (it's the sender)
|
||||
|
||||
if not character_stats:
|
||||
return
|
||||
|
||||
# Update equipment from data
|
||||
for slot_name in equipment_data.keys():
|
||||
var item_data = equipment_data[slot_name]
|
||||
if item_data != null:
|
||||
character_stats.equipment[slot_name] = Item.new(item_data)
|
||||
else:
|
||||
character_stats.equipment[slot_name] = null
|
||||
|
||||
# Update appearance
|
||||
_apply_appearance_to_sprites()
|
||||
print(name, " equipment synced from server")
|
||||
|
||||
func heal(amount: float):
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user