Copy to Clipboard Test

Bubble (Counter Drain) Code

const int COUNTER_THIEF_USE_PRECENT_FROM_MAXIMUM = 0;//>0 - drain precent of counter capacity, instead of precent of current amount. 

ffc script Counter_Thief{
	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 sizex = Ghost_GetAttribute(ghost, 0, 1);//Enemy Size X
		int sizey = Ghost_GetAttribute(ghost, 1, 1);//EnemySize Y;
		int counter = Ghost_GetAttribute(ghost, 2, 1);//counter to drain
		int drain = Ghost_GetAttribute(ghost, 3, 0);//Drain amount. >0 - absolute value, <0 - precent, depending on COUNTER_THIEF_USE_PRECENT_FROM_MAXIMUM
		int delay = Ghost_GetAttribute(ghost, 4, 60);//Cooldown between thefts
		int preventitem = Ghost_GetAttribute(ghost, 5, 0);//Item that prevents counter drain.
		int noknockback = Ghost_GetAttribute(ghost, 6, 0);//>0 - no knockback.

		
		
		ghost->Extend=3;
		Ghost_SetSize(this, ghost, sizex, sizey);
		if (sizex>2 || sizey>2)Ghost_SetHitOffsets(ghost, 8, 8, 8, 8);
		
		Ghost_SetFlag(GHF_NORMAL);
		if (noknockback>0)Ghost_UnsetFlag(GHF_KNOCKBACK);
		
		int OrigTile = ghost->OriginalTile;
		int State = 0;
		int statecounter = 0;
		int haltcounter = -1;
		int cooldown = delay;
		
		while(true){
			haltcounter = Ghost_ConstantWalk4(haltcounter, SPD, RR, HF, HNG);
			if (cooldown>0) cooldown--;			
			if (cooldown<=0&&LinkCollision(ghost)&&!Link->Item[preventitem]&&(Link->Action==LA_GOTHURTLAND || Link->Action==LA_GOTHURTWATER)){
				int c = Abs(drain);
				if (drain<-100) c=100;
				if (drain<0){
					if (COUNTER_THIEF_USE_PRECENT_FROM_MAXIMUM>0) c = Abs(drain)*Game->MCounter[counter]/100;
					else c = Abs(drain)*Game->Counter[counter]/100;
				}
				//Trace(c);
				Game->DCounter[counter]-=c;
				cooldown=delay;
			}
			//debugValue(1,cooldown);
			Ghost_Waitframe(this, ghost);
		}
	}
}