//King Ghini
//Moves 8-way. As he takes damage, the enemy increases in size and spawns orbiters around himself. Thise orbiters moves like lemniscattos and fire eweapons at Link.
//When his HP gets critically low (<20% max HP), King Ghini increases his movement speed. Explodes SuperBomb sized on death.
//Animation - 1 frame, 8-dir.
ffc script King_Ghini{
void run(int enemyID){
npc ghost = Ghost_InitAutoGhost(this, enemyID);
int HF = ghost->Homing;
int HR = ghost->Haltrate;
int RR = ghost->Rate;
int HNG = ghost->Hunger;
int SPD = ghost->Step;
int WPND = ghost->WeaponDamage;
int rangex = Ghost_GetAttribute(ghost, 0, 60);//Maximum range at X coordinate for orbiters.
int rangey = Ghost_GetAttribute(ghost, 1, 30);//Maximum range at Y coordinate for orbiters.
int speedx = Ghost_GetAttribute(ghost, 2, 1);//Angular speed for X coordinate for orbiters.
int speedy = Ghost_GetAttribute(ghost, 3, 2);//Angular speed for Y coordinate for orbiters.
int enID = Ghost_GetAttribute(ghost, 4, enemyID+1);//ID of enemy to spawn arund boss
int berserkspeedmodifier = Ghost_GetAttribute(ghost, 5, 20);//Berserk Speed modifier.
int WPNS = Ghost_GetAttribute(ghost, 6, -1);//Eweapon sprite
int shotdelay = Ghost_GetAttribute(ghost, 7, 150);//delay between firing eweapons, in frames.
// int weakspotcmb = Ghost_GetAttribute(ghost, 8, 0);//Combo used to render weak spot - central 1*1 tile spot at the center of enemy.
ghost->Extend=3;
// Ghost_SetSize(this, ghost, sizex, sizex);
// if (sizex>2)Ghost_SetHitOffsets(ghost, 8, 8, 8, 8);
Ghost_SetFlag(GHF_NORMAL);
Ghost_SetFlag(GHF_NO_FALL);
Ghost_UnsetFlag(GHF_KNOCKBACK);
Ghost_SetFlag(GHF_8WAY);
int origtile = ghost->OriginalTile;
ghost->OriginalTile = GH_BLANK_TILE;
int haltcounter = -1;
int shootcounter=shotdelay;
int anim = 0;
npc en1[5];
int Ghost_MaxHP=Ghost_HP;
eweapon e;
int anglex[5] = {0,0,0,0,0};
int angley[5] = {0,0,0,0,0};
int numen = 0;
int ghostcounter = 0;
int defs[18];
Ghost_StoreDefenses(ghost,defs);
// Ghost_SetAllDefenses(ghost, NPCDT_BLOCK);
while(true){
haltcounter = Ghost_VariableWalk8(haltcounter, SPD, RR, HF, HNG, HR);
if (WPND>0)shootcounter--;
for (int i=0;i < 5;i++){
if (en1[i]->isValid()){
anglex[i]+=speedx;
angley[i]+=speedy;
if (anglex[i]>=360) anglex[i]-=360;
if (angley[i]>=360) angley[i]-=360;
if (anglex[i]<0)anglex[i]+=360;
if (angley[i]<0)angley[i]+=360;
SetEnemyProperty(en1[i], ENPROP_X, CenterX(ghost) + rangex*Cos(anglex[i]));
SetEnemyProperty(en1[i], ENPROP_Y, CenterY(ghost) + rangey*Sin(angley[i]));
if (shootcounter<=0)e = FireAimedEWeapon(ghost->Weapon, en1[i]->X, en1[i]->Y, 0, 100, WPND, WPNS, -1, 0);
}
}
if (shootcounter==0)shootcounter =shotdelay;
ghostcounter = 5 - Ceiling((Ghost_HP/Ghost_MaxHP)*5);
if (ghostcounter>numen){
numen++;
en1[numen-1]=CreateNPCAt(enID,Ghost_X,Ghost_Y);
anglex[numen-1]=Rand(360);
angley[numen-1]=Rand(360);
if (numen==4)SPD = ghost->Step + berserkspeedmodifier;
anim=8;
while(anim>0){
anim--;
Screen->DrawTile (2, Ghost_X, Ghost_Y, origtile+Ghost_Dir, 1, 1, Ghost_CSet, 16+numen*16-anim , 16+numen*16-anim,0, 0,0, 0, true, OP_OPAQUE);
if (!Ghost_Waitframe(this, ghost, false, false)){
for (int i=0;i < 5;i++){
if (en1[i]->isValid()) en1[i]->HP=0;
}
lweapon l = CreateLWeaponAt(LW_SBOMBBLAST,Ghost_X,Ghost_Y);
Quit();
}
}
if (numen<4)Ghost_SetSize(this, ghost, numen+1, numen+1);
}
// Screen->Rectangle(4, Ghost_X+ghost->HitXOffset, Ghost_Y+ghost->HitYOffset, Ghost_X+ghost->HitXOffset+ghost->HitWidth, Ghost_Y+ghost->HitYOffset+ghost->HitHeight, 0x81, -1, 0, 0, 0, false, OP_OPAQUE);
Screen->DrawTile (2, Ghost_X, Ghost_Y, origtile+Ghost_Dir, 1, 1, Ghost_CSet, 16+numen*16 , 16+numen*16, 0, 0,0, 0, true, OP_OPAQUE);
// if (numen>1)Screen->FastCombo(2, Ghost_X, Ghost_Y,weakspotcmb, Ghost_CSet,OP_OPAQUE);
if (!Ghost_Waitframe(this, ghost, false, false)){
for (int i=0;i < 5;i++){
if (en1[i]->isValid()) en1[i]->HP=0;
}
e = CreateEWeaponAt(EW_SBOMBBLAST,CenterX(ghost),CenterY(ghost));
Quit();
}
}
}
}