Scripts/TeaMakerScript.js |
/*jslint white: true, undef: true, eqeqeq: true, bitwise: true, regexp: true, newcap: true, immed: true */
"use strict";
// Standard attributes
this.name = "TeaMakerScript.js";
this.author = "Smivs";
this.copyright = "(C) Smivs"
this.licence = "Creative Commons Attribution - Non-Commercial - Share Alike 4.0"
this.version = "1.2";
this.description = "Script to operate tea-maker and control refills.";
this.missionScreenOpportunity = function()
// update old TEA_MAKER version to new TEAPOT version for existing users
{
if (player.ship.docked && player.ship.equipmentStatus("EQ_TEA_MAKER") == "EQUIPMENT_DAMAGED")
{
return;
}
if (player.ship.docked && player.ship.equipmentStatus("EQ_TEA_MAKER") == "EQUIPMENT_OK")
{
mission.runScreen({title: "!!! Software Update !!!", messageKey: "teaPotUpdate"});
player.ship.removeEquipment("EQ_TEA_MAKER");
player.ship.awardEquipment("EQ_TEAPOT");
// clean up old status variable from previous versions...
{
if(missionVariables.teaRefill)
{
delete missionVariables.teaRefill;
}
}
// ...and set new variable
missionVariables.teaRefill_status = "OK";
// clean up old counter variable from previous versions...
{
if(missionVariables.teaRefillCounter)
{
delete missionVariables.teaRefillCounter;
}
}
// then set new counter variable
missionVariables.teaRefill_counter = 25;
}
}
this.playerBoughtEquipment = function(equipment)
// set variables upon purchase
{
if (equipment == "EQ_TEAPOT")
{
missionVariables.teaRefill_status = "OK";
{
// setup variable (counter) to control refill availability
if (!missionVariables.teaRefill_counter)
{
missionVariables.teaRefill_counter = 25;
}
}
}
// when buying refills reset variable and add 25 'T-pods' to tally
else if (equipment == "EQ_TEA_REFILL_1" || "EQ_TEA_REFILL_2" || "EQ_TEA_REFILL_3" || "EQ_TEA_REFILL_3")
{
missionVariables.teaRefill_status = "OK";
missionVariables.teaRefill_counter += 25;
}
}
this.allowAwardEquipment = function(equipment, ship, context)
// condition scripting for 'T-pods' to control availability
{
if (equipment == "EQ_TEA_REFILL_1" || "EQ_TEA_REFILL_2" || "EQ_TEA_REFILL_3" || "EQ_TEA_REFILL_3")
{
if (context == "purchase" && player.ship.equipmentStatus("EQ_TEAPOT") == "EQUIPMENT_OK" && missionVariables.teaRefill_status != "OK")
{
return true;
}
}
}
this.activated = function()
{
// make un-available if no T-pods left
if(missionVariables.teaRefill_status === "RUN_OUT")
{
player.consoleMessage("Tea Maker un-available - Please re-supply.",5);
return;
}
// run teamaker
if(missionVariables.teaRefill_status != "RUN_OUT")
{
this.boilWaterTimer = new Timer(this, this.$boilWater,1); // timer to boil water
this.brewTeaTimer = new Timer(this, this.$brewTea,8); // timer to brew tea after 8 seconds
this.teaReadyTimer = new Timer(this, this.$teaReady,15); // timer to confirm tea is ready
// we count off the 'T-Pods' as they are used
{
missionVariables.teaRefill_counter--;
}
// ...until we reach 5 left.
if (missionVariables.teaRefill_counter === 5)
{
// warn player that only 5 remain - more can now be bought
player.consoleMessage("After this cup you only have five 'T-pods' left. You can buy some when you next dock.",5);
missionVariables.teaRefill_status = "BUYABLE";
}
// ...then when we reach 1 left.
if (missionVariables.teaRefill_counter === 0)
{
// Then require more 'T-Pods', disable Tea Maker, add 'T-Pods' to F3 screen and reset counter.
player.consoleMessage("This is your last 'T-Pod' - you must buy some more.",5);
missionVariables.teaRefill_status = "RUN_OUT";
}
}
}
this.$boilWater = function()
{
this.boilSound = new SoundSource;
this.boilSound.sound = "boiling.ogg";
this.boilSound.loop = false;
this.boilSound.play();
player.consoleMessage("The water is boiling...",5);
}
this.$brewTea = function()
{
this.boilSound.stop();
this.brewSound = new SoundSource;
this.brewSound.sound = "brewing.ogg";
this.brewSound.loop = false;
this.brewSound.play();
player.consoleMessage("Your tea is now brewing...",5);
}
this.$teaReady = function()
{
this.brewSound.stop();
this.teaSound = new SoundSource;
this.teaSound.sound = "teaSound.ogg";
this.teaSound.loop = false;
this.teaSound.play();
player.consoleMessage("Your tea is now ready. Enjoy!",6);
this.$teaTimerStop ();
}
this.$teaTimerStop = function()
// stop timers
{
if(this.boilWaterTimer)
{
if (this.boilWaterTimer.isRunning)
{
this.boilWaterTimer.stop();
delete this.boilWaterTimer;
}
}
if(this.brewTeaTimer)
{
if (this.brewTeaTimer.isRunning)
{
this.brewTeaTimer.stop();
delete this.brewTeaTimer;
}
}
if(this.teaReadyTimer)
{
if (this.teaReadyTimer.isRunning)
{
this.teaReadyTimer.stop();
delete this.teaReadyTimer;
}
}
}
|