#stop regen for 5s when hit (20t=1s)
execute unless score @s[scores={health_absorption=..0},tag=!evade] damage_resistance matches 100.. run scoreboard players set @s out_of_combat 100

$data modify storage player_data 1.enemy_hit_id set value $(id_number)

execute unless score @s iframes matches 1.. run function main:mechanics/damage/player/on_hit_effects with storage player_data 1

# execute as @s[tag=assassin] at @s run function main:characters/assassin/passive
execute as @s[tag=evade] run return run tag @s remove evade

execute if entity @s[scores={iframes=1..}] run return fail
scoreboard players operation @s iframes = @s iframes_max

#get base damage
$scoreboard players set @s base_enemy_damage $(damage)

#get the amount of damage absorbed by damage_resistance
scoreboard players operation @s[scores={shield=1..}] damage_resistance *= @s base_enemy_damage
scoreboard players operation @s[scores={shield=1..}] damage_resistance /= .100 number
scoreboard players operation @s[scores={shield=1..}] base_enemy_damage -= @s damage_resistance

#global dmg multiplier
execute if entity @a[tag=game_started] run scoreboard players operation @s base_enemy_damage *= .damage_multiplier arena
execute if entity @a[tag=game_started] run scoreboard players operation @s base_enemy_damage /= .100 number

#deal damage to the player
scoreboard players operation @s final_enemy_damage = @a base_enemy_damage

#sfx and vfx
execute if score @s base_enemy_damage matches ..99 run function main:mechanics/effects/screenshake/start {duration:5,strength:50}
execute if score @s base_enemy_damage matches 100.. run function main:mechanics/effects/screenshake/start {duration:5,strength:200}
execute if score @s final_enemy_damage matches 1..100 run playsound entity.player.hurt master @a ~ ~ ~ 10 1
execute if score @s final_enemy_damage matches 101.. run playsound entity.player.hurt master @a ~ ~ ~ 10 0.8

#negative damage
execute if score @s final_enemy_damage matches ..0 run scoreboard players set @s final_enemy_damage 0
execute if score @s damage_resistance matches 100.. run scoreboard players set @s final_enemy_damage 0

#deal damage to absorption
scoreboard players operation @s final_enemy_damage_temp = @a final_enemy_damage
execute as @s[scores={health_absorption=1..}] if score @s health_absorption <= @s final_enemy_damage_temp run function main:mechanics/damage/player/absorption/less
execute as @s[scores={health_absorption=1..}] if score @s health_absorption > @s final_enemy_damage run function main:mechanics/damage/player/absorption/more

#deal damage to shield
scoreboard players operation @s final_enemy_damage_temp = @a final_enemy_damage
execute as @s[scores={shield=1..}] if score @s shield <= @s final_enemy_damage_temp run function main:mechanics/damage/player/shield/less
execute as @s[scores={shield=1..}] if score @s shield > @s final_enemy_damage run function main:mechanics/damage/player/shield/more

#deal damage to health
execute as @s[scores={health=1..,shield=..0,health_absorption=..0}] run scoreboard players operation @s health -= @s final_enemy_damage

#reset the final damage
scoreboard players set @s final_enemy_damage 0
scoreboard players set @s number 10

#reset the damage_resistance
scoreboard players operation @s damage_resistance_stat = .store damage_resistance