"use strict";
this.name = "blackmonk_fuel";

this.startUp = function () {
	this.$fillSound = new SoundSource;
	this.$fillSound.sound = "blackmonk_fill.ogg";
	if (missionVariables.blackmonk_fuel) {
		this.$condensedFuel = missionVariables.blackmonk_fuel;
	} else this.$condensedFuel = 0;
}

this.playerWillSaveGame = function () {
	missionVariables.blackmonk_fuel = this.$condensedFuel;
}

this.playerBoughtEquipment = function (equipment) {
	if (equipment === "EQ_HOLY_FUEL") {
		player.ship.removeEquipment(equipment);
		player.ship.fuel = 7;
		this.$condensedFuel = 10.5;//1.5*7 = 10.5
	}
	else if (equipment === "EQ_FUEL") this.$condensedFuel = 0;
}

this.shipWillLaunchFromStation = function () {
	if (this.$condensedFuel > 7) {
		this.$fuelMonitor = new Timer(this, this._fuelMonitor, 0, 1);
	}
}

this.shipWillDockWithStation = function () {
	if (this.$fuelMonitor) {
		this.$fuelMonitor.stop();
		delete this.$fuelMonitor;
	}
}

this._fuelMonitor = function () {
	if (player.ship.fuel < 7 && this.$condensedFuel > player.ship.fuel && !this.$fuelAnimation) {
		this.$fuelAnimation = addFrameCallback(this._fuelAnimation.bind(this));
	}
}

this._fuelAnimation = function () {
	if (player.ship.fuel < 7 && this.$condensedFuel > player.ship.fuel) {
		player.ship.fuel += 0.1;
		this.$condensedFuel -= 0.1;
		if (!this.$fillSound.isPlaying) this.$fillSound.play();
	}
	else {
		removeFrameCallback(this.$fuelAnimation);
		delete this.$fuelAnimation;
		//all gone?
		if (player.ship.fuel < 7) {
			this.$condensedFuel = 0;
			this.$fuelMonitor.stop();
			delete this.$fuelMonitor;
		}
	}
}

