#include_function "lib\Ikareimu\System\Polarity.dnh"
#include_function "lib\Ikareimu\System\Power.dnh"
#include_function "lib\Ikareimu\System\Chaining.dnh"
#include_function "lib\Ikareimu\System\PlayerShot.dnh"
#include_function "lib\Ikareimu\System\PlayerLaser.dnh"
#include_function "lib\Ikareimu\System\Shield.dnh"
#include_function "lib\Ikareimu\System\System.dnh"

#include_function "lib\Ikareimu\Common\ShotReplace.dnh"

/******************************************
* Player Script Functions                 *
******************************************/
// Run this in @Initialize
sub IkareimuPlayer_Initialize {  
  PolarityManager_Initialize;
  PowerManager_Initialize;
  ChainingManager_Initialize;
  ShieldManager_Initialize;
  PlayerLaserManager_Initialize;
  System_Initialize;
  
  LoadPlayerShotData("lib/Ikareimu/Common/ShotDefinition.dnh");
  SetRebirthFrame(0);
  SetInitialBombCount(0);
}

// Run this is @MainLoop
sub IkareimuPlayer_Run {  
  PolarityManager_Run; 
  PowerManager_Run;
  ChainingManager_Run;
  PlayerLaserManager_Run;
  ShieldManager_Run;
  SetCommonData("SetCollisionA", []);
  
  System_Run;
}

// Run this in @Finalize
sub IkareimuPlayer_Finalize {
  ShieldManager_Finalize;
}



// Use this to create player shots. It will automatically detect
// which polarity the player currently is and shot the approriate
// type of bullet.
task IkareimuPlayer_CreateShot(x, y, speed, angle, redgraphic, bluegraphic) {
  let obj = Obj_Create(OBJ_SHOT);
  let ShotPolarity = GetPolarity;
  Obj_SetPosition(obj, x, y);
  Obj_SetSpeed(obj, speed);
  Obj_SetAngle(obj, angle);
  if(ShotPolarity == RED){
    ObjShot_SetGraphic(obj, redgraphic);
  }
  else if(ShotPolarity == BLUE){
    ObjShot_SetGraphic(obj, bluegraphic);
  }
  while(!Obj_BeDeleted(obj)){
    PlayerShot_detectCollision(obj, ShotPolarity);
	yield;
  }
}

function IkareimuPlayer_SetPolaritySwitchTrigger(trigger){
  if(trigger != "c" && trigger != "ctrl" && trigger != "shotslow"){
    RaiseError("You did not set a valid trigger for switching polarities", "Ikareimu Player Error");
  }
  ShieldTriggerKey = trigger
}