Block maybe
This commit is contained in:
@@ -34,8 +34,16 @@ func take_damage(amount: float, attacker_id: int = -1):
|
||||
if is_dead:
|
||||
return
|
||||
|
||||
# Apply blocking reduction if applicable (duck typing - check if method exists)
|
||||
var final_damage = amount
|
||||
if has_method("get_block_reduction"):
|
||||
var block_reduction = call("get_block_reduction")
|
||||
if block_reduction > 0.0:
|
||||
final_damage = amount * (1.0 - block_reduction)
|
||||
print("Blocked! Damage reduced from ", amount, " to ", final_damage, " (", block_reduction * 100, "% reduction)")
|
||||
|
||||
var old_health = current_health
|
||||
current_health = max(0, current_health - amount)
|
||||
current_health = max(0, current_health - final_damage)
|
||||
|
||||
# Broadcast health change to all clients
|
||||
rpc("sync_health", current_health)
|
||||
|
||||
@@ -103,3 +103,10 @@ func get_range() -> float:
|
||||
|
||||
func get_cooldown() -> float:
|
||||
return weapon_data.attack_cooldown if weapon_data else 0.0
|
||||
|
||||
## Blocking functionality
|
||||
func can_block() -> bool:
|
||||
return weapon_data.can_block if weapon_data else false
|
||||
|
||||
func get_block_reduction() -> float:
|
||||
return weapon_data.block_reduction if weapon_data else 0.0
|
||||
|
||||
+40
-1
@@ -36,6 +36,7 @@ var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
var equipped_weapon: BaseWeapon = null # Main hand weapon
|
||||
var equipped_offhand: BaseWeapon = null # Off-hand weapon
|
||||
var _nearby_weapons: Array[WorldWeapon] = []
|
||||
var is_blocking: bool = false
|
||||
|
||||
# Attack system
|
||||
@export var attack_damage: float = 10.0
|
||||
@@ -165,8 +166,14 @@ func _process(delta):
|
||||
if Input.is_action_just_pressed("dash") and _dash_cooldown_timer <= 0 and not is_dead and is_on_floor():
|
||||
_perform_dash()
|
||||
|
||||
# Handle block input
|
||||
if Input.is_action_pressed("block") and not is_dead:
|
||||
_try_block()
|
||||
else:
|
||||
is_blocking = false
|
||||
|
||||
# Handle attack input
|
||||
if Input.is_action_just_pressed("attack") and not is_dead and not _is_dashing:
|
||||
if Input.is_action_just_pressed("attack") and not is_dead and not _is_dashing and not is_blocking:
|
||||
_perform_attack()
|
||||
|
||||
# Handle weapon pickup/drop
|
||||
@@ -270,6 +277,38 @@ func set_mesh_texture(mesh_instance: MeshInstance3D, texture: CompressedTexture2
|
||||
new_material.albedo_texture = texture
|
||||
mesh_instance.set_surface_override_material(0, new_material)
|
||||
|
||||
## Block system
|
||||
func _try_block():
|
||||
# Check if we have a weapon that can block
|
||||
var can_block_weapon = false
|
||||
|
||||
if equipped_weapon and equipped_weapon.can_block():
|
||||
can_block_weapon = true
|
||||
elif equipped_offhand and equipped_offhand.can_block():
|
||||
can_block_weapon = true
|
||||
|
||||
is_blocking = can_block_weapon
|
||||
|
||||
# Could add blocking animation here
|
||||
# if is_blocking and _body:
|
||||
# _body.play_block_animation()
|
||||
|
||||
## Get block reduction amount (0.0 to 1.0)
|
||||
func get_block_reduction() -> float:
|
||||
if not is_blocking:
|
||||
return 0.0
|
||||
|
||||
var reduction = 0.0
|
||||
|
||||
# Use the highest block reduction from equipped weapons
|
||||
if equipped_weapon and equipped_weapon.can_block():
|
||||
reduction = max(reduction, equipped_weapon.get_block_reduction())
|
||||
|
||||
if equipped_offhand and equipped_offhand.can_block():
|
||||
reduction = max(reduction, equipped_offhand.get_block_reduction())
|
||||
|
||||
return reduction
|
||||
|
||||
## Attack system
|
||||
func _perform_attack():
|
||||
if not is_multiplayer_authority() or is_dead:
|
||||
|
||||
@@ -17,6 +17,10 @@ enum Hand { MAIN_HAND, OFF_HAND, TWO_HAND }
|
||||
@export var attack_cooldown: float = 0.5
|
||||
@export var attack_animation: String = "Attack1" # Animation to play when attacking
|
||||
|
||||
@export_category("Defense Stats")
|
||||
@export var can_block: bool = false
|
||||
@export_range(0.0, 1.0) var block_reduction: float = 0.5 # Percentage of damage blocked (0.5 = 50%)
|
||||
|
||||
@export_category("Visual")
|
||||
@export var mesh_scene: PackedScene # The 3D mesh for this weapon
|
||||
@export var icon: Texture2D # Optional icon for UI
|
||||
|
||||
Reference in New Issue
Block a user