
# -> Apply polar bear buffs
attribute @s armor modifier add overly_realistic:animal_polar_bear_buff 20.0 add_value
attribute @s knockback_resistance modifier add overly_realistic:animal_polar_bear_buff 0.15 add_value


# --> Do animal tag operations

# -> Apply modifiers
execute if score #or.setting.nerfed_aggro_animals OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    attribute @s max_health modifier add overly_realistic:animal_default_max_health -0.25 add_multiplied_total

# -> Apply modifiers for 'nerfed aggro animals'
execute if score #or.setting.nerfed_aggro_animals OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    attribute @s max_health modifier add overly_realistic:animal_default_max_health -0.15 add_multiplied_total

# -> Maximize health
effect give @s regeneration 2 255 true
effect give @s instant_health 1 255 true
data modify entity @s Health set value 999

# -> If aggro animals are disabled then return
execute if score #or.setting.should_aggro_animals_spawn OverlyRealistic.Settings.ArbitrarySetting matches 0 run \
    return run \
        function overly_realistic:animals/operations/add_marker_to_passive_animal

# -> Tag entity
tag @s add OverlyRealistic.CommonAnimalAggressive

# -> Apply modifiers
execute unless score #or.setting.nerfed_aggro_animals OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    attribute @s max_health modifier add overly_realistic:animal_aggressive_max_health 8 add_value
execute unless score #or.setting.nerfed_aggro_animals OverlyRealistic.Settings.ArbitrarySetting matches 1 run \
    attribute @s knockback_resistance modifier add overly_realistic:animal_aggressive_knockback_resistance 0.05 add_value
attribute @s movement_speed modifier add overly_realistic:animal_aggressive_movement_speed 0.01 add_value

# -> Create targeter entity
summon piglin_brute ~ ~ ~ {Silent:1b,Invulnerable:1b,CustomNameVisible:0b,DeathLootTable:"minecraft:empty",Team:"overly_realistic.targeters",PersistenceRequired:1b,IsImmuneToZombification:1b,Tags:["OverlyRealistic.TempEntity","OverlyRealistic.TargeterEntity","OverlyRealistic.Animal.AnimalHolderEntity"],CustomName:"Wild Animal",active_effects:[{id:"minecraft:invisibility",amplifier:0,duration:-1,show_particles:0b}],attributes:[{id:"minecraft:scale",base:0.0625}]}

# -> Targeter rider
ride @n[type=piglin_brute,tag=OverlyRealistic.TempEntity,dx=0,dy=0,dz=0] mount @s

# -> Apply polar bear buffs
execute on vehicle run \
    attribute @s attack_damage modifier add overly_realistic:animal_polar_bear_buff 4.0 add_value

# -> Gene set attack damage
execute if score @s OverlyRealistic.Animal.GeneSet matches 0..3 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier 4.0 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 4..5 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier 3.0 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 6..7 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier 2.0 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 8..9 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier 1.0 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 10..12 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier 0.85 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 13..14 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier 0.25 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 15..16 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier -0.65 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 17 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier -1.1 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 18 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier -3.25 add_value
execute if score @s OverlyRealistic.Animal.GeneSet matches 19 \
    on vehicle run \
        attribute @s attack_damage modifier add overly_realistic:random_spawn_modifier -5.0 add_value

# -> Untag entity
execute on vehicle run \
    tag @s remove OverlyRealistic.TempEntity

# -> Reduce animal damage
execute unless score #or.setting.nerfed_aggro_animals OverlyRealistic.Settings.ArbitrarySetting matches 1 \
    unless entity @s[type=chicken] \
    on passengers \
    if entity @s[type=piglin_brute] run \
        attribute @s attack_damage modifier add overly_realistic:nerfed_aggro_animal_attack_damage -0.38 add_multiplied_total

# -> If 'nerfed aggro animals' is on then nerf attack damage
execute if score #or.setting.nerfed_aggro_animals OverlyRealistic.Settings.ArbitrarySetting matches 1 \
    on passengers \
    if entity @s[type=piglin_brute] run \
        attribute @s attack_damage modifier add overly_realistic:nerfed_aggro_animal_attack_damage -0.68 add_multiplied_total

# -> Get entity scale
execute store result score #or.equation_part_1 OverlyRealistic.General.ArbitraryData run \
    attribute @s scale get 100

# -> Tribal fear RNG
execute if predicate overly_realistic:animal/animal_fear_smart_rng_big_animal run \
    tag @s add OverlyRealistic.Animal.TribalFearAggroAnimal

# --> Smart fear RNG

# -> Small scaled animal
execute if score #or.equation_part_1 OverlyRealistic.General.ArbitraryData matches ..98 run \
    return run \
        execute if predicate overly_realistic:animal/animal_fear_smart_rng_small_animal run \
            tag @s add OverlyRealistic.Animal.SmartFearAggroAnimal

# -> Normal & big scaled animal
execute if predicate overly_realistic:animal/animal_fear_smart_rng_big_animal run \
    tag @s add OverlyRealistic.Animal.SmartFearAggroAnimal
