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

//area to buy extra lives
class ShopBuyAreaLives : ScriptObject {
    kActor @self;
	bool wasUsed = false;
	MenuShop menu = MenuShop("Extra Life", "Buy", "Cancel", 25, MenuSelectCallBack(OnBuy));
	//------------------------------------------------------------------------------------------------------------------------
    ShopBuyAreaLives(kActor @actor) {
        @self = actor;
		self.Pitch() = Math::Deg2Rad(180);
    }
	//------------------------------------------------------------------------------------------------------------------------
	void OnBuy() {
		kVec3 p = Player.Actor().Origin();
		kActor @extraLife = ActorFactory.Spawn("LifeForce_100", p.x, p.y, p.z, 0, Player.Actor().SectorIndex()); //Spawn Extra Life Pickup
		extraLife.Scale() = kVec3(0.35f, 0.35f, 0.35f);
		int liveBought;
		GameVariables.GetInt("BP.LivesBought", liveBought);
		liveBought++;
		GameVariables.SetValue("BP.LivesBought", "" + liveBought);
	}
	//------------------------------------------------------------------------------------------------------------------------
	void OnEnterArea() {
		SetPlayerFlagNoMovement(true);
		
		
	
		int liveBought;
		GameVariables.GetInt("BP.LivesBought", liveBought);
		if (liveBought <= 1)
			menu.SetCost(25);
		else if (liveBought <= 3)
			menu.SetCost(50);
		else if (liveBought <= 5)
			menu.SetCost(100);
		else if (liveBought <= 7)
			menu.SetCost(250);
		else
			menu.SetCost(500);
		
		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) {		
    }
	//------------------------------------------------------------------------------------------------------------------------
};
