# -*- coding: utf-8 -*-
from Bosses import *
from Enemies import *
from generator import *

for e in [(tutorial, "Tutorial"), (b_floor_1, "Floor 1"), (b_floor_2, "Floor 2"), (b_floor_3, "Floor 3"), (b_floor_4, "Floor 4")]:
    gen = Generator(e[0], "bosses", e[1])
    gen.make()

for e in [(e_floor_1, "Floor 1"), (e_floor_2, "Floor 2"), (e_floor_3, "Floor 3"), (e_floor_4, "Floor 4"), (e_others, "Others"), (builders, "Community Builders")]:
    gen = Generator(e[0], "enemies", e[1])
    gen.make()


# ====== Enemies ========
spawn_enemies = open('../enemies_py/functions/0_spawn_sort.mcfunction',"w")
stone_marker = open('../enemies_py/functions/1_stone_marker.mcfunction', 'w')
spawn_cooldown = open('../enemies_py/functions/2_spawn_cooldown_sort.mcfunction', 'w')
for mob in enemies:
    if mob.overwrite_summon == None:
        spawn_enemies.write(f'execute if entity @s[tag={mob.name_}] run function enemies_py:{mob.name_}\n')
    else:
        spawn_enemies.write(f'execute if entity @s[tag={mob.name_}] run {mob.overwrite_summon}\n')
    if mob.custom_attack:
        spawn_cooldown.write(f'execute if entity @s[tag={mob.name_}] run function enemies:{mob.name_}/attacks/spawn_cooldown\n')
    stone_marker.write(f"""give @s stone{{type:"{mob.name_}",display:{{Name:'{{"text":"{mob.name_}"}}'}}}} 64\n""")
spawn_enemies.write('\nkill @s')
spawn_enemies.close()
stone_marker.close()
spawn_cooldown.close()

# ====== Bosses ========
spawn_bosses = open('../bosses_py/functions/0_spawn_sort.mcfunction', "w")
bossbar_name = open('../bosses_py/functions/1_bossbar_name.mcfunction', 'w')
spawn_cooldown = open('../bosses_py/functions/2_spawn_cooldown_sort.mcfunction', 'w')
for mob in bosses:
    spawn_bosses.write(f'execute if entity @s[tag={mob.name_}] run function bosses_py:{mob.name_}\n')
    bossbar_name.write(f'execute if entity @s[tag={mob.name_}] run bossbar set boss name {{"translate":"{mob.name.plain()}","color":"red"}}\n')
    if mob.custom_attack:
        spawn_cooldown.write(f'execute if entity @s[tag={mob.name_}] run function bosses:{mob.name_}/attacks/spawn_cooldown\n')
spawn_bosses.close()
bossbar_name.close()
spawn_cooldown.close()

total = len(bosses) + len(enemies)
print('\n\t· Bosses: {}, Enemies: {}, Community Builders: {} Total:{}\n'.format(len(bosses), len(enemies)-len(builders), len(builders), total))

input("Pres any key.")

"""
Entity(
    mob = "<str>",
    name = JTxt("<JTxt>", color = "red"),
    hp = 1.3,
    baby = False,
    follow_range = 1.2,
    movement_speed = 1.5,
    attack_damage = 4.2,
    knockback_resistance = 0.3,
    right_hand = 'id:"flint",Count:1,tag:{CustomModelData:3001}',
    left_hand = '<nbt>',
    feet = 'id:"leather_leggings",Count:1',
    legs = '<nbt>',
    chest = '<nbt>',
    head = '<nbt>',
    tags =  ["enemy","boss"],
    silent = False,
    eClock = False,
    invisible = False,
    death_trigger = False,
    custom_sound = False,
    custom_attack = False,
    objmc = Objmc('7000', 80)
    )
"""
