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

INCLUDE_game

Arrow::Arrow(vf2d pos,vf2d targetPos,vf2d vel,float radius,int damage,bool upperLevel,bool friendly,Pixel col)
	:finalDistance(geom2d::line(pos,targetPos).length()),acc(PI/2*"Ranger.Auto Attack.ArrowSpd"_F),
	Bullet(pos,vel,radius,damage,
		"arrow.png",upperLevel,false,INFINITE,true,friendly,col){}

void Arrow::Update(float fElapsedTime){
	float speed=vel.mag();
	travelDistance+=speed*fElapsedTime;
	vel.y+=acc*fElapsedTime;
	if(!deactivated&&travelDistance>=finalDistance){
		deactivated=true;
		fadeOutTime=0.2f;
	}
}

bool Arrow::PlayerHit(Player*player)
{
	deactivated=true;
	fadeOutTime=0.2f;
	game->AddEffect(std::make_unique<Effect>(player->GetPos(),0,"splash_effect.png",upperLevel,player->GetSizeMult(),0.25));
	return false;
}

bool Arrow::MonsterHit(Monster& monster)
{
	deactivated=true;
	fadeOutTime=0.2f;
	game->AddEffect(std::make_unique<Effect>(monster.GetPos(),0,"splash_effect.png",upperLevel,monster.GetSizeMult(),0.25));
	return false;
}