script_enemy_main {
  #include_function ".\lib\enemy.dnh"
  #include_function ".\lib\fairy_animation.dnh"
  @Initialize {
    InitializeEnemy;
    InitializeFairyAnimation(imgBigFairy);
    SetLife(3000);
    Attack;
  }
  
  @MainLoop {
    if(Spawned){
      SetCollisionA(GetX, GetY, 32);
      SetCollisionB(GetX, GetY, 24);
    }
    yield;
  }
  
  @DrawLoop {
    if(Spawned){
      DrawFairy;
    }
  }
  
  @Finalize {
    FinalizeEnemy;
  }
  
  task Attack {
    while(!Spawned){ yield; }
    MainPattern;
    AimedPattern;
    
    task MainPattern {
      let counter = 0;
      let angle = rand(0, 360);
      loop {
        PlaySE(sfxShot1);
        let dist = sin(counter*12)*32;
        ascent(i in 0..3){
          WrapObjShot_Initialize(GetX+cos(angle+i*120)*dist, GetY+sin(angle+i*120)*dist, 1.3, angle+i*120, 63, 10, 480);
          WrapObjShot_Initialize(GetX+cos(angle+i*120)*dist, GetY+sin(angle+i*120)*dist, 1.3, angle+72+i*120, 63, 10, 480);
          WrapObjShot_Initialize(GetX+cos(angle+i*120)*dist, GetY+sin(angle+i*120)*dist, 1.3, angle-72+i*120, 63, 10, 480);
        }
        angle+=11;
        counter++;
        Wait(10);
      }
    }
    
    task AimedPattern {
      loop {
        Wait(120);
        PlaySE(sfxShot2);
        ascent(i in 0..5){
          ascent(j in 4..8){
            ascent(k in -1..2){
              WrapObjShot_Initialize(GetX, GetY, j*0.5, GetAngleToPlayer+i*72+k*2, 207, 10, 180);
            }
          }
        }
      }
    }
  }
}