#include "BulletTypes.h"
#include "Effect.h"
#include "Crawler.h"
#include "DEFINES.h"
#include "utils.h"

INCLUDE_game
INCLUDE_MONSTER_LIST

FireBolt::FireBolt(vf2d pos,vf2d vel,float radius,int damage,bool upperLevel,bool friendly,Pixel col)
	:Bullet(pos,vel,radius,damage,AnimationState::ENERGY_BOLT,upperLevel,false,INFINITE,true,friendly,col){}

void FireBolt::Update(float fElapsedTime){
	lastParticleSpawn=std::max(0.f,lastParticleSpawn-fElapsedTime);
	if(lastParticleSpawn==0){
		lastParticleSpawn=0.03;
		game->AddEffect(std::make_unique<Effect>(pos,util::random(1),AnimationState::ENERGY_PARTICLE,upperLevel,util::random(2),0.3,vf2d{util::random(120)-60,-util::random(60)},Pixel{255,uint8_t(util::random(250)),0}));
	}
}

bool FireBolt::PlayerHit(Player*player)
{
	deactivated=true;
	fadeOutTime=0.2f;
	game->AddEffect(std::make_unique<Effect>(player->GetPos(),0,AnimationState::SPLASH_EFFECT,upperLevel,5,0.25,vf2d{},Pixel{240,120,60}));
	return false;
}

bool FireBolt::MonsterHit(Monster& monster)
{
	deactivated=true;
	fadeOutTime=0.2f;
	for(int i=0;i<72;i++){
		game->AddEffect(std::make_unique<Effect>(monster.GetPos(),util::random(0.5),AnimationState::DOT_PARTICLE,upperLevel,util::random(2),util::random(0.4),vf2d{util::random(300)-150,util::random(300)-150},Pixel{255,uint8_t(util::random(190)+60),60}));
	}
	game->SetupWorldShake(0.25);
	for(Monster&m:MONSTER_LIST){
		if(geom2d::line(monster.GetPos(),m.GetPos()).length()<=2.5*24){
			m.Hurt(3*damage);
		}
	}
	game->AddEffect(std::make_unique<Effect>(monster.GetPos(),0,AnimationState::SPLASH_EFFECT,upperLevel,5,0.25,vf2d{},Pixel{240,120,60}));
	return false;
}
