
# -> Stamina work

# -> If player has met the sprinting requirement then add to speed
execute if score @s OverlyRealistic.Player.SprintTime matches 100000.. run \
    function overly_realistic:players/stamina/improve_running/player_run_max_time

# --> Wisdom operations

# -> If player is near a map item frame then add scribing XP
execute if entity @s[tag=OverlyRealistic.Player.IsNearMapItemFrame] run \
    function overly_realistic:players/wisdom/scribing/add_to_skill_xp_c_be_near_bookshelves

# -> If player has level 5 scribing and is holding a scribe book then increase nearby players' stats
execute if score @s OverlyRealistic.Player.WisdomStats.Scribing matches 5.. \
    if items entity @s weapon.* poisonous_potato[custom_data~{IsScribeBook:1b}] \
    as @a[distance=..15] run \
        function overly_realistic:players/misc/scribe_book/scribe_book_buff_nearby

# --> Intelligence operations

# -> Natural intelligence gain RNG
execute if predicate overly_realistic:player/misc/intelligence_gain_general_rng run \
    function overly_realistic:players/intelligence/add_1_intelligence

# -> Nearby bookshelf check
scoreboard players set #or.global OverlyRealistic.General.ArbitraryData 0
execute store result score #or.global OverlyRealistic.General.ArbitraryData run \
    fill ~-5 ~ ~-5 ~5 ~2 ~5 command_block{Command:"say OverRealistic:BookshelfNearPlayerCheck"} replace bookshelf
fill ~-5 ~ ~-5 ~5 ~2 ~5 bookshelf replace command_block{Command:"say OverRealistic:BookshelfNearPlayerCheck"}

# -> Bookshelf intelligence gain RNG
execute if score #or.global OverlyRealistic.General.ArbitraryData matches 1.. \
    if predicate overly_realistic:player/misc/intelligence_gain_general_rng run \
        function overly_realistic:players/intelligence/add_1_intelligence

# -> Bookshelf scribing gain RNG
execute if score #or.global OverlyRealistic.General.ArbitraryData matches 1.. run \
    function overly_realistic:players/wisdom/scribing/add_to_skill_xp_c_be_near_bookshelves

# -> Add temp tag
tag @s add OverlyRealistic.Player.TempPlayer

# -> Nearby player intelligence gain RNG
execute if entity @p[tag=!OverlyRealistic.Player.TempPlayer,distance=..6] \
    if predicate overly_realistic:player/misc/intelligence_gain_rare_rng run \
        function overly_realistic:players/intelligence/add_1_intelligence

# -> Scribe intelligence buff
execute if score @s OverlyRealistic.Player.WisdomStats.Scribing matches 2 \
    if predicate overly_realistic:player/misc/intelligence_gain_general_rng \
    as @a[distance=..25] run \
        function overly_realistic:players/intelligence/add_1_intelligence

# -> Scribe intelligence buff
execute if score @s OverlyRealistic.Player.WisdomStats.Scribing matches 3.. \
    if predicate overly_realistic:player/misc/scribe_level_3_int_buff_rng \
    as @a[distance=..25] run \
        function overly_realistic:players/intelligence/add_1_intelligence

# -> Nearby player intelligence gain RNG
execute if score @s OverlyRealistic.Player.Stats.MentalHealth matches ..5 \
    if predicate overly_realistic:player/misc/intelligence_reduction_low_sanity_rng run \
        function overly_realistic:players/intelligence/add_1_intelligence

# -> Remove temp tag
tag @s remove OverlyRealistic.Player.TempPlayer
