#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Incense Lamp \"Impurity-Hating Sparkler\""]

#include"./Cutin.txt"
#include"./../../Functions/Effects/Effects.txt"
#include"./LoadGraphics.txt"
#include"./LoadSounds.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;
#include"./MiyakoDrawBoss.txt"


@Initialize{	
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	SetAutoDeleteObject(true);
	LoadShotData;
	animateBossM;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 8, 0);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);

	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY,5,3);
	TEtama;wait(90);
	SE(se_spell);
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("Incense Lamp \"Impurity-Hating Sparkler\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("Incense Lamp \"Impurity-Hating Sparkler\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin, "Extra");}
	TSpellBG;SetCommonData("BG",1);
	wait(120);damage=1;
	EnepRhythm(5);
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
		wait(2.5);Apricot;}}

task Apricot{
	let count = 0;
	let scale = 3;
	let obj = ObjShot_Create(OBJ_SHOT);
	ObjShot_Regist(obj);
	ObjMove_SetPosition(obj,rand(0,384),0);
	ObjMove_SetSpeed(obj,4);
	ObjMove_SetAngle(obj,rand(80,100));
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(obj,scale,scale,0);
	ObjShot_SetGraphic(obj,359);
	ObjShot_SetDelay(obj,30);	
	while(!Obj_IsDeleted(obj) && ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
		if(GetObjectDistance(obj,GetPlayerObjectID())<=80){
			ObjShot_SetGraphic(obj,332);
			ObjMove_SetSpeed(obj,1);
				if(count<30){
					ObjRender_SetScaleXYZ(obj,scale,scale,0);
					scale-=2/30;}
				if(count>=60){count=60;}
			count++;}
			yield;}}

task EnepRhythm(zeit){
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){
	SE(se_tan2);wait(zeit-rand(-3,3));}}