feat: Add core player input, movement, and special ability management systems with new UI components.
This commit is contained in:
@@ -118,6 +118,12 @@ func initialize(p_player: Node3D, p_gridmap: Node):
|
||||
enhanced_gridmap = p_gridmap
|
||||
rng = RandomNumberGenerator.new()
|
||||
rng.randomize()
|
||||
|
||||
# Ensure Powerup Tiles (11-14) are NOT in the non-walkable list
|
||||
if enhanced_gridmap and "non_walkable_items" in enhanced_gridmap:
|
||||
for id in HOLO_TILES:
|
||||
if id in enhanced_gridmap.non_walkable_items:
|
||||
enhanced_gridmap.non_walkable_items.erase(id)
|
||||
|
||||
# =============================================================================
|
||||
# Helper: Item ID to Effect Enum
|
||||
@@ -137,45 +143,58 @@ func add_powerup_from_item(item_id: int):
|
||||
var effect = get_effect_from_item(item_id)
|
||||
if effect == -1: return
|
||||
|
||||
# Unlock or Level Up
|
||||
if not inventory.get(effect, false):
|
||||
# New Unlock
|
||||
inventory[effect] = true
|
||||
powerup_levels[effect] = 1
|
||||
emit_signal("inventory_updated", inventory)
|
||||
emit_signal("powerup_unlocked", effect, 1)
|
||||
print("Player %s unlocked powerup %s (Lvl 1)" % [player.name, SpecialEffect.keys()[effect]])
|
||||
else:
|
||||
# Level Up
|
||||
var current_lvl = powerup_levels.get(effect, 1)
|
||||
if current_lvl < 8:
|
||||
powerup_levels[effect] = current_lvl + 1
|
||||
emit_signal("powerup_unlocked", effect, powerup_levels[effect])
|
||||
print("Player %s leveled up %s to Lvl %d" % [player.name, SpecialEffect.keys()[effect], powerup_levels[effect]])
|
||||
# 1-PowerUp Rule: If this is a DIFFERENT power-up, clear the old one
|
||||
var is_different = not inventory.get(effect, false)
|
||||
var already_has_any = false
|
||||
for e in inventory:
|
||||
if inventory[e]:
|
||||
already_has_any = true
|
||||
break
|
||||
|
||||
if is_different and already_has_any:
|
||||
print("Player %s replacing existing powerup with %s" % [player.name, SpecialEffect.keys()[effect]])
|
||||
for e in inventory:
|
||||
inventory[e] = false
|
||||
powerup_levels[e] = 1 # Reset levels of discarded powerups
|
||||
|
||||
# Instant Level 8 on pickup (User Request)
|
||||
inventory[effect] = true
|
||||
powerup_levels[effect] = 8
|
||||
emit_signal("inventory_updated", inventory)
|
||||
emit_signal("powerup_unlocked", effect, 8)
|
||||
print("[SpecialTiles] SUCCESS: Player %s picked up %s. Force Level 8 applied." % [player.name, SpecialEffect.keys()[effect]])
|
||||
|
||||
if player.is_multiplayer_authority() and multiplayer.has_multiplayer_peer() and multiplayer.multiplayer_peer.get_connection_status() == MultiplayerPeer.CONNECTION_CONNECTED:
|
||||
rpc("sync_inventory_add", effect, powerup_levels[effect])
|
||||
rpc("sync_inventory_add", effect, 8)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func sync_inventory_add(effect: int, level: int):
|
||||
# Clear others on sync too to maintain 1-powerup rule
|
||||
for e in inventory:
|
||||
inventory[e] = false
|
||||
powerup_levels[e] = 1 # Reset levels of discarded powerups
|
||||
|
||||
inventory[effect] = true
|
||||
powerup_levels[effect] = level
|
||||
emit_signal("inventory_updated", inventory)
|
||||
emit_signal("powerup_unlocked", effect, level)
|
||||
|
||||
func remove_powerup(effect: int):
|
||||
# We DO NOT remove item from inventory on use anymore (for reusable leveling system)?
|
||||
# Wait, user request: "cooldown is decarese and max is level 8"
|
||||
# Does "activate it" consume the item?
|
||||
# User says "it will cooldown agian for 15 seconds".
|
||||
# Implies PERMANENT UNLOCK once picked up, reusable with cooldown.
|
||||
# So we NEVER set inventory[effect] = false unless reset.
|
||||
pass
|
||||
# User Request: "If the power up already use it will remain empty"
|
||||
if inventory.get(effect, false):
|
||||
inventory[effect] = false
|
||||
powerup_levels[effect] = 1
|
||||
emit_signal("inventory_updated", inventory)
|
||||
print("[SpecialTiles] Player %s consumed powerup %s" % [player.name, SpecialEffect.keys()[effect]])
|
||||
|
||||
if player.is_multiplayer_authority() and multiplayer.has_multiplayer_peer() and multiplayer.multiplayer_peer.get_connection_status() == MultiplayerPeer.CONNECTION_CONNECTED:
|
||||
rpc("sync_inventory_remove", effect)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func sync_inventory_remove(effect: int):
|
||||
# Deprecated for new system, but kept for compatibility if needed
|
||||
pass
|
||||
inventory[effect] = false
|
||||
powerup_levels[effect] = 1
|
||||
emit_signal("inventory_updated", inventory)
|
||||
|
||||
# =============================================================================
|
||||
# Activate Effect (Explicit Target)
|
||||
@@ -228,8 +247,10 @@ func activate_effect(effect: int, target_player: Node3D = null):
|
||||
# Play generic cast animation or sound?
|
||||
if player.is_multiplayer_authority() and multiplayer.has_multiplayer_peer() and multiplayer.multiplayer_peer.get_connection_status() == MultiplayerPeer.CONNECTION_CONNECTED:
|
||||
player.rpc("trigger_screen_shake", "light")
|
||||
# Sync cooldown to others not strictly needed unless UI shows it?
|
||||
# Probably local UI only.
|
||||
|
||||
# Consumable: Remove after use (User Request)
|
||||
print("[SpecialTiles] Consuming %s after successful activation." % SpecialEffect.keys()[effect])
|
||||
remove_powerup(effect)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@@ -256,10 +277,9 @@ func _execute_area_freeze(target_pos: Vector2i = Vector2i.ZERO):
|
||||
var current_lvl = powerup_levels.get(SpecialEffect.AREA_FREEZE, 1)
|
||||
|
||||
if center_pos == Vector2i.ZERO:
|
||||
# Calculate distance ahead based on Level
|
||||
# Gap of 2 floors = 3 tiles ahead
|
||||
# Gap of 4 floors = 5 tiles ahead
|
||||
var distance = 3 if current_lvl < 5 else 5
|
||||
# Updated: Always 3 tiles ahead as per user request
|
||||
var distance = 3
|
||||
print("[SpecialTiles] Area Freeze logic executing with distance: %d" % distance)
|
||||
|
||||
var movement = player.movement_manager
|
||||
if movement and movement.current_move_direction != Vector2i.ZERO:
|
||||
@@ -441,7 +461,7 @@ func spawn_powerups_around(center: Vector2i, force_powerups: bool = true, only_c
|
||||
# PROTECTED FLOOR CHECK: Don't spawn on existing walls or void
|
||||
var f0 = enhanced_gridmap.get_cell_item(Vector3i(pos.x, 0, pos.y))
|
||||
var f1 = enhanced_gridmap.get_cell_item(Vector3i(pos.x, 1, pos.y))
|
||||
if f0 in [4, -1] or f1 in [4, 13, 16]:
|
||||
if f0 in [4, -1] or f1 in [4, 16]:
|
||||
continue
|
||||
|
||||
var item_id: int
|
||||
|
||||
Reference in New Issue
Block a user