Player changes
This commit is contained in:
@@ -42,6 +42,8 @@ var damage_number_scene: PackedScene = null
|
||||
var projectiles: Dictionary = {} # id -> projectile node
|
||||
|
||||
var aim_angle: float = 0.0
|
||||
var last_attack_time: float = 0.0
|
||||
var attack_cooldown: float = 0.5 # Default attack cooldown in seconds
|
||||
|
||||
func _ready():
|
||||
# Add to group for HUD to access
|
||||
@@ -148,9 +150,7 @@ func _on_dungeon_entered():
|
||||
if camera:
|
||||
camera.position = world_pos
|
||||
|
||||
# Setup player texture
|
||||
if player_node and player_node.has_node("Sprite") and SpriteGenerator:
|
||||
player_node.get_node("Sprite").texture = SpriteGenerator.get_circle()
|
||||
# Player texture is now setup in player.gd using AnimatedSprite2D
|
||||
|
||||
# Request initial inventory
|
||||
if Network:
|
||||
@@ -286,24 +286,79 @@ func _handle_input():
|
||||
_use_hotbar_slot(i - 1)
|
||||
|
||||
func _perform_attack(attack_angle: float):
|
||||
# Check if player has a ranged weapon equipped
|
||||
# Check attack cooldown
|
||||
var current_time = Time.get_ticks_msec() / 1000.0
|
||||
var time_since_last_attack = current_time - last_attack_time
|
||||
|
||||
# Get attack speed from equipped weapon
|
||||
var equipped_weapon = GameState.equipment.get("weapon", null)
|
||||
var weapon_cooldown = attack_cooldown # Default cooldown
|
||||
|
||||
if equipped_weapon != null and not equipped_weapon.is_empty():
|
||||
# Get attack speed stat (attacks per second) if available
|
||||
var attack_speed = equipped_weapon.get("attackSpeed", 0.0)
|
||||
if attack_speed > 0:
|
||||
weapon_cooldown = 1.0 / attack_speed # Convert attacks/sec to seconds/attack
|
||||
else:
|
||||
# Default cooldowns based on weapon type
|
||||
var weapon_type = equipped_weapon.get("type", "")
|
||||
match weapon_type:
|
||||
"Weapon":
|
||||
var weapon_name = equipped_weapon.get("name", "").to_lower()
|
||||
if "dagger" in weapon_name or "fist" in weapon_name:
|
||||
weapon_cooldown = 0.3 # Fast weapons
|
||||
elif "sword" in weapon_name:
|
||||
weapon_cooldown = 0.5 # Medium weapons
|
||||
elif "axe" in weapon_name or "mace" in weapon_name:
|
||||
weapon_cooldown = 0.7 # Slow weapons
|
||||
elif "bow" in weapon_name or "crossbow" in weapon_name:
|
||||
weapon_cooldown = 0.8 # Ranged weapons
|
||||
else:
|
||||
weapon_cooldown = 0.5 # Default
|
||||
|
||||
# Check if enough time has passed since last attack
|
||||
if time_since_last_attack < weapon_cooldown:
|
||||
# Only print every 0.5 seconds to avoid spam
|
||||
if int(time_since_last_attack * 2) != int((time_since_last_attack - get_process_delta_time()) * 2):
|
||||
print("[DungeonManager] Attack on cooldown: %.2f / %.2f seconds" % [time_since_last_attack, weapon_cooldown])
|
||||
return
|
||||
|
||||
# Update last attack time
|
||||
last_attack_time = current_time
|
||||
|
||||
# Determine weapon type for animation
|
||||
var animation_type = "fist"
|
||||
|
||||
# Check if player has a ranged weapon equipped
|
||||
if equipped_weapon != null and not equipped_weapon.is_empty():
|
||||
# Server sends camelCase properties
|
||||
var requires_ammo = equipped_weapon.get("requiresAmmunition", false)
|
||||
var is_throwable = equipped_weapon.get("isThrowable", false)
|
||||
var projectile_speed = equipped_weapon.get("projectileSpeed", 0)
|
||||
var weapon_name = equipped_weapon.get("name", "").to_lower()
|
||||
|
||||
# Determine animation type from weapon
|
||||
if requires_ammo or "bow" in weapon_name or "crossbow" in weapon_name:
|
||||
animation_type = "bow"
|
||||
elif "staff" in weapon_name or "wand" in weapon_name:
|
||||
animation_type = "spell"
|
||||
elif weapon_name != "":
|
||||
animation_type = "sword"
|
||||
|
||||
print("[DungeonManager] Attack - Weapon: ", equipped_weapon.get("name", "Unknown"))
|
||||
print("[DungeonManager] RequiresAmmo: ", requires_ammo, ", IsThrowable: ", is_throwable, ", Speed: ", projectile_speed)
|
||||
|
||||
# If weapon fires projectiles (bow, crossbow, throwable), send projectile fire
|
||||
if (requires_ammo or is_throwable) and projectile_speed > 0:
|
||||
print("[DungeonManager] Firing projectile!")
|
||||
print("[DungeonManager] Firing projectile! Direction: (%.2f, %.2f)" % [cos(attack_angle), sin(attack_angle)])
|
||||
# Calculate direction vector from aim angle
|
||||
var direction_x = cos(attack_angle)
|
||||
var direction_y = sin(attack_angle)
|
||||
GameState.send_fire_projectile(direction_x, direction_y)
|
||||
if GameState and GameState.has_method("send_fire_projectile"):
|
||||
GameState.send_fire_projectile(direction_x, direction_y)
|
||||
print("[DungeonManager] Projectile fire command sent to server")
|
||||
else:
|
||||
print("[DungeonManager] ERROR: GameState.send_fire_projectile not available!")
|
||||
else:
|
||||
print("[DungeonManager] Using melee attack")
|
||||
# Melee weapon - use normal attack
|
||||
@@ -313,19 +368,28 @@ func _perform_attack(attack_angle: float):
|
||||
# No weapon or empty slot - use normal attack (fists)
|
||||
GameState.send_attack(attack_angle)
|
||||
|
||||
# Play attack animation on player (don't await to avoid blocking)
|
||||
if player_node and player_node.has_method("play_attack_animation"):
|
||||
player_node.play_attack_animation(animation_type)
|
||||
print("[DungeonManager] Triggered %s attack animation" % animation_type)
|
||||
|
||||
func _send_movement():
|
||||
# Don't move if UI is open
|
||||
var ui_open = (inventory_panel and inventory_panel.visible) or (chat_panel and chat_panel.visible)
|
||||
if ui_open:
|
||||
return
|
||||
|
||||
|
||||
var dx = Input.get_axis("move_left", "move_right")
|
||||
var dy = Input.get_axis("move_up", "move_down")
|
||||
|
||||
|
||||
var move_vec = Vector2(dx, dy)
|
||||
if move_vec.length() > 1:
|
||||
move_vec = move_vec.normalized()
|
||||
|
||||
|
||||
# Update player animation based on movement
|
||||
if player_node and player_node.has_method("set_movement"):
|
||||
player_node.set_movement(move_vec)
|
||||
|
||||
GameState.send_move(move_vec.x, move_vec.y, aim_angle)
|
||||
|
||||
func _update_camera(delta):
|
||||
|
||||
Reference in New Issue
Block a user