#include "scripts/common.txt"

const array<int> BPRaptorMeleeAnims = {anim_aiMelee2, anim_aiMelee3, anim_aiMelee6, anim_aiMelee7, anim_aiMelee8};
const array<int> BPRaptorRangeAnims = {anim_aiRangeAttack1};
										
		//anim_aiMelee2
		//anim_aiMelee3
		//anim_aiMelee6 - leap attack
		//anim_aiMelee7
		//anim_aiMelee8
		//anim_aiRangeAttack1 - fires plasma shot
//============================================================================================================================
class TurokBPRaptor : TurokBPEnemy
{
	float meleeRange = 143.36f;
	float minAttackDelay = 0.0f; //in seconds
	float maxAttackDelay = 0.0f; //in seconds
	
	float curAttackTime = 0.0f;
	bool isAttacking = false;
	//------------------------------------------------------------------------------------------------------------------------
    TurokBPRaptor(kActor @actor) {
        super(actor);
    }
	//------------------------------------------------------------------------------------------------------------------------
	void OnTickStart() {
		TurokBPEnemy::OnTickStart();
		curAttackTime = Math::RandRange(minAttackDelay, maxAttackDelay);
		animSpeed = 2.0f;
		//self.ModelVariation() = 1; //for gun raptors
	}
	//------------------------------------------------------------------------------------------------------------------------
    void OnTick() {
		TurokBPEnemy::OnTick();
		if (Debug::IsActorsDisabled()) {
			return;
		}
		
		isAttacking = IsAttacking();
		if (IsDead()) {
			return;
		}
		
		AIStandard();
	}
	//------------------------------------------------------------------------------------------------------------------------
	void AIStandard(bool useRange = false) {
		if (!HasTarget()) {
			return;
		}
		kVec3 targetPos = self.GetTarget().Origin();
		
		if (!isAttacking) {
			curAttackTime = Math::Maxf(curAttackTime - GAME_DELTA_TIME, 0.0f);
		}
		
		if (CanAttack()) {
			float targetDist = Math::Sqrt(self.DistanceToPoint(targetPos));
			if (targetDist <= meleeRange) {
				curAttackTime = Math::RandRange(minAttackDelay, maxAttackDelay);
				PlayRandomAnimation(BPRaptorMeleeAnims);
			} else if (useRange) {
				curAttackTime = Math::RandRange(minAttackDelay, maxAttackDelay);
				PlayRandomAnimation(BPRaptorRangeAnims);
			}
		}
	}
	//------------------------------------------------------------------------------------------------------------------------
	bool CanAttack() {
		return (!isAttacking and curAttackTime <= 0);
	}
	//------------------------------------------------------------------------------------------------------------------------
	bool IsAttacking() {
		int animID = self.AnimState().PlayingID();
		if (BPRaptorMeleeAnims.find(animID) >= 0) {
			return true;
		}
		if (BPRaptorRangeAnims.find(animID) >= 0) {
			return true;
		}
		return false;
	}
	//------------------------------------------------------------------------------------------------------------------------
    void FireRaptorMissile(kActor @instigator, const float w, const float x, const float y, const float z) {
        if (!HasTarget()) {
            return;
        }
        self.SpawnFx("fx/generic_178.kfx", kVec3(x, y, z));
    }
	//------------------------------------------------------------------------------------------------------------------------
    void DeathSound(kActor @instigator, const float w, const float x, const float y, const float z) {
        self.PlaySound("sounds/shaders/raptor_death.ksnd");
    }
	//------------------------------------------------------------------------------------------------------------------------
    void InjurySound(kActor @instigator, const float w, const float x, const float y, const float z) {
        self.PlaySound("sounds/shaders/raptor_injury.ksnd");
    }
	//------------------------------------------------------------------------------------------------------------------------
    void ViolentSound(kActor @instigator, const float w, const float x, const float y, const float z) {
        self.PlaySound("sounds/shaders/raptor_violent_death.ksnd");
    }
	//------------------------------------------------------------------------------------------------------------------------
}
//============================================================================================================================
class TurokBPDimetrodon : TurokBPEnemy
{
	//------------------------------------------------------------------------------------------------------------------------
    TurokBPDimetrodon(kActor @actor) {
        super(actor);
    }
	//------------------------------------------------------------------------------------------------------------------------
    void DeathSound(kActor @instigator, const float w, const float x, const float y, const float z) {
        self.PlaySound("sounds/shaders/dimetrodon_death.ksnd");
    }
	//------------------------------------------------------------------------------------------------------------------------
    void ViolentSound(kActor @instigator, const float w, const float x, const float y, const float z) {
        self.PlaySound("sounds/shaders/dimetrodon_violent_death.ksnd");
    }
	//------------------------------------------------------------------------------------------------------------------------
}
//============================================================================================================================
