#main
$scoreboard players set @s damage_amount $(damage)
$scoreboard players operation @s damage_amount *= @s $(stat)
scoreboard players operation @s damage_amount /= .100 number
scoreboard players operation @s base_damage = @s damage_amount
scoreboard players set @s final_damage 0

#local DMG bonus
scoreboard players set @s damage_storage 100
scoreboard players operation @s damage_storage += @s damage_bonus
$scoreboard players operation @s damage_storage += @s damage_bonus_$(type)
$scoreboard players operation @s damage_storage += $(local_bonus) number

scoreboard players operation @s base_damage *= @s damage_storage
scoreboard players operation @s base_damage /= .100 number

#final
scoreboard players operation @s final_damage = @s base_damage

#crit
tag @s remove crit_chance_triggered
execute store result score @s crit_chance_roll run random value 1..100
scoreboard players operation @s crit_chance_temp = @s crit_chance
scoreboard players operation @s crit_damage_temp = @s crit_damage

$scoreboard players operation @s crit_chance_temp += @s crit_chance_$(type)
$scoreboard players operation @s crit_damage_temp += @s crit_damage_$(type)

execute if score .focus_lense artifact matches 1.. if score @s crit_damage_temp matches 181.. run scoreboard players set @s crit_damage_temp 180

execute if score @s crit_chance_roll <= @s crit_chance_temp run tag @s add crit_chance_triggered
execute if score @s crit_chance_roll <= @s crit_chance_temp run scoreboard players operation @s final_damage *= @s crit_damage_temp
execute if score @s crit_chance_roll <= @s crit_chance_temp run scoreboard players operation @s final_damage /= .100 number
scoreboard players set @a crit_chance_roll 101

#end
execute store result storage minecraft:final_damage damage.damage int 1 run scoreboard players get @s final_damage

##variables based on the ID
$execute store result storage minecraft:$(type)_damage $(character).$(id).player_id int 1 run scoreboard players get @s player_id

$data modify storage minecraft:$(type)_damage $(character).$(id) merge value {"id":"$(id)"}
$data modify storage minecraft:$(type)_damage $(character).$(id) merge value {"indicator":$(indicator)}
$data modify storage minecraft:$(type)_damage $(character).$(id) merge value {"character":$(character)}
$data modify storage minecraft:$(type)_damage $(character).$(id) merge value {"type":$(type)}
$execute as @s[tag=!crit_chance_triggered] run data modify storage minecraft:$(type)_damage $(character).$(id) merge value {"crit":0}
$execute as @s[tag=crit_chance_triggered] run data modify storage minecraft:$(type)_damage $(character).$(id) merge value {"crit":1}

$execute store result storage minecraft:$(type)_damage $(character).$(id).damage int 1 run scoreboard players get @s final_damage