#include "scripts/common.txt"
#include "scripts/bp_common.txt"
#include "scripts/misc/MenuShop.txt"

class ShopBuyAreaJump : ScriptObject {
    kActor @self;
	bool wasUsed = false;
	MenuShop menu = MenuShop("Sacred Eagle Feather", "Buy", "Cancel", 2000, MenuSelectCallBack(OnBuy));
	//------------------------------------------------------------------------------------------------------------------------
    ShopBuyAreaJump(kActor @actor) {
        @self = actor;
		self.Pitch() = Math::Deg2Rad(180);
    }
	//------------------------------------------------------------------------------------------------------------------------
	void OnBuy() {
		SetJumpPower(true);
		Game.PlaySound("sounds/shaders/generic_126_spell_cast_2.ksnd");
	}
	//------------------------------------------------------------------------------------------------------------------------
	void OnEnterArea() {
		if (HasJumpPower()) {
			Game.PrintLine("The power of the Sacred Eagle Feather is yours", 0, 90);
		} else {
			SetPlayerFlagNoMovement(true);
			menu.Open();
		}
	}
	//------------------------------------------------------------------------------------------------------------------------
	void OnExitArea() {
	}
	//------------------------------------------------------------------------------------------------------------------------
    void OnTick(void) {
		menu.Update();
		
		if (InRadius(self.Origin(), 50.0f) and Player.Actor().OnGround()) {
			if (!wasUsed) {
				wasUsed = true;
				OnEnterArea();
			}
		} else {
			if (wasUsed) {
				wasUsed = false;
				OnExitArea();
			}
		}
    }
	//------------------------------------------------------------------------------------------------------------------------
    void OnSpawn(void) {		
    }
	//------------------------------------------------------------------------------------------------------------------------
};
