"use strict";

var EN_Anemone = function(){
	this.sprite = new Sprite(EN_Anemone.spriteSheet,"Anemone");
	this.sprite.game_object = this; // no longer a generic GO

	this._basicInit(EN_Anemone.params);

	//-----

	this.sprite.collision_flags |= (DEFINE_SPRITE_COLLISION_FLAGS.GROUND | DEFINE_SPRITE_COLLISION_FLAGS.AIR);

	this.state_frames = [
		100, // idle
		5, // opeining
		5, // open
		5 // closing
	];
	this.state=0;
	this.frame_timer=0;
};
EN_Anemone.spriteImg = SDS_Load_Image("art/sheets/sprite/anemone.png");
EN_Anemone.spriteSheet = new TileSheet(4, 4, 2, 1, EN_Anemone.spriteImg);
EN_Anemone.params = {
	name: "Anemone",
	box: [2,4,13,15], // left, top, right, bottom
	max_step: 0,
	hp: 2,
	infection: 1,
};

EN_Anemone.prototype = new GO_Enemy();

	EN_Anemone.prototype.ai = function(){
		if (this.infection>0 && this.state==2 && this.frame_timer==2){
			// spit
			//var spit = null;
			
			this._heap.spit = new GO_Bullet(0,-8);
			this._heap.spit.sprite.x = this.sprite.x+4;
			this._heap.spit.sprite.y = this.sprite.y+1;

			this.sprite.map_room.addSprite(this._heap.spit.sprite);
			this.manager.add(this._heap.spit);

			this._heap.spit = new GO_Bullet(-3,-7);
			this._heap.spit.sprite.x = this.sprite.x+4;
			this._heap.spit.sprite.y = this.sprite.y+1;

			this.sprite.map_room.addSprite(this._heap.spit.sprite);
			this.manager.add(this._heap.spit);

			this._heap.spit = new GO_Bullet(3,-7);
			this._heap.spit.sprite.x = this.sprite.x+4;
			this._heap.spit.sprite.y = this.sprite.y+1;

			this.sprite.map_room.addSprite(this._heap.spit.sprite);
			this.manager.add(this._heap.spit);

			this._heap.spit = new GO_Bullet(-6,-6);
			this._heap.spit.sprite.x = this.sprite.x+4;
			this._heap.spit.sprite.y = this.sprite.y+1;

			this.sprite.map_room.addSprite(this._heap.spit.sprite);
			this.manager.add(this._heap.spit);

			this._heap.spit = new GO_Bullet(6,-6);
			this._heap.spit.sprite.x = this.sprite.x+4;
			this._heap.spit.sprite.y = this.sprite.y+1;

			this.sprite.map_room.addSprite(this._heap.spit.sprite);
			this.manager.add(this._heap.spit);

			this._heap.spit = null;
			
		}

		this.toggleInteractionsStd();

		this.frame_timer++;
		if (this.frame_timer>=this.state_frames[this.state]){
			this.frame_timer=0;
			this.state = (this.state+1)%this.state_frames.length;
		}
		this.sprite.frame = (this.state==3) ? 1 : this.state;
		if (this.infection>0) this.sprite.frame+=4;
	};
	EN_Anemone.prototype.damage = function(source,points){
		if (points>0){
			this.hp-=points;
			return (this.hp<=0);
		}
		else{
			this.frame_timer=0;
			this.state = (this.state==2) ? 2 : 1;

			//var cough = new GO_Smoke();
			this._heap.cough = new GO_Smoke();
			this._heap.cough.sprite.x = this.sprite.x;
			this._heap.cough.sprite.y = this.sprite.y;
			this._heap.cough.launch_dir.x=0;
			this._heap.cough.launch_dir.y=-1;
			this._heap.cough.host_obj = this;

			this.sprite.map_room.addSprite(this._heap.cough.sprite);
			this.manager.add(this._heap.cough);

			this._heap.cough = null;

			this.infection--;
			return false;
		}
	};
	EN_Anemone.prototype._inflictVal = {hp:2, chi:1};
	EN_Anemone.prototype.inflict = function(){
		return this._inflictVal;
	};
	EN_Anemone.prototype.drop = function(){
		//var dropRand = Math.random();
		this._heap.dropRand = Math.random();
		if (this._heap.dropRand<0.25){
			return new GO_HeartDrop(GO_HeartDrop.SIZE.SMALL);
		}
		return null;
	};


	