#include "scripts/animations.txt"
#include "scripts/bp_common.txt"

//Health is monkey id
class TurokBPMonkey : ScriptObject {
    kActor @self;
    bool started = false;
	kVec3 direction;
	kVec3 movePos;
	//------------------------------------------------------------------------------------------------------------------------
    TurokBPMonkey(kActor @actor) {
        @self = actor;
		//self.AnimState().Blend(anim_aiStanding, 4.0f, 8.0f, ANF_LOOP);
		//scaling bug if fxevent are run at init
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnTick(void) {
		if (!started) {
			started = true;
			self.RunFxEvent("Monkey_Glow");
		}
		
		if (Debug::IsActorsDisabled()) {
			return;
		}
		
		if (self.AnimState().PlayingID() != anim_activate) {
			if (InRadius(self.Origin(), 500.0f) and self.CanSee(Player.Actor().CastToActor())) {
				self.AnimState().Blend(anim_activate, 6.0f, 6.0f, ANF_LOOP); //3.0f, 6.0f, ANF_ROOTMOTION
				direction = Math::AngleToDirectionXY(self.Yaw());
				movePos = Math::vecZero;
			}
		} else {
			if (self.AnimState().TrackTime() <= 0.36f) {
				if (self.AnimState().TrackTime() >= 0.17f) {
					movePos = direction * (380.0f * ((self.AnimState().TrackTime() - 0.17f) / 0.19f));
				}
				if (InRadius(self.Origin() + movePos, 60.0f)) {
					SetMonkeyFound(self.Health(), true);
					Game.PlaySound("sounds/shaders/health_pickup_1.ksnd");
					Game.PrintLine("caught on this level", 0, 240);
					Game.PrintLine("" + GetMonkeysFoundOnLevel() + " out of " + GetMaxMonkeysOnLevel() + " monkeys", 1, 240);
					self.Remove();
				}
			}
			if (self.AnimState().CycleCompleted()) {
				self.Remove();
			}
		}
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnSpawn(void) {
    }
	//------------------------------------------------------------------------------------------------------------------------
};
