| Scripts/masslock_reimagined.js | this.name			= "masslock_reimagined";
this.author			= "Redspear";
this.copyright		= "2022 Redspear";
this.licence		= "CC BY-NC-SA 4.0"; 
this.description	= "Masslock delays (rather than always holds) torus drive";
this.version		= "1.2";
"use strict";
// establish toggles
this.startUpComplete  = this.playerBoughtNewShip = function()
{
	this._MLOR = 1; // orbital release
	//this._MLCR = 1; // combat release
}
// establish where masslock may be overridden
this.shipExitedPlanetaryVicinity = this.shipExitedWitchspace = function()
{
	this._MLOR = 1;
}
// establish where masslock may not be overridden
this.shipEnteredPlanetaryVicinity = function()
{
	this.$stopTimer();
	this._MLOR = 0;
	player.ship.massLockable = true;
	player.consoleMessage ("Gravity Well Influence Detected");
	
}
this.shipBeingAttacked = function()
{
	this.$stopTimer();
	//this._MLCR = 0;
	player.ship.massLockable = true;
	player.consoleMessage ("Torus Drive Recalibrating");
	this.$startTimer3();
	
}
// timer management
this.shipDied = function()
{	
	this.$stopTimer();
}	
this.$startTimer1 = function $startTimer1 () {
			this.$stopTimer(); // reset safety check
			this._myTimer = new Timer(this, this.$masslockReleaseTimer, 30, 0); // 30 seconds, no repeat
			}
			
this.$startTimer2 = function $startTimer2 () {
			this.$stopTimer(); // reset safety check
			this._myTimer = new Timer(this, this.$masslockRestoreTimer, 0.1, 0); // tenth of a second, no repeat unless scanner still not clear
			}
			
this.$startTimer3 = function $startTimer3 () {
			this.$stopTimer(); // reset safety check
			this._myTimer = new Timer(this, this.$masslockRecalibrationTimer, 30, 0); // 30 seconds, no repeat
			}			
this.$stopTimer = function $stopTimer ()
{
    if (this._myTimer && this._myTimer.isRunning) this._myTimer.stop();
}
// masslock management
this.alertConditionChanged = this.shipLaunchedFromStation = function()
{
	if (player.alertCondition === 2 && _MLOR === 1)
		{this.$startTimer1();
		}
		
	if (player.alertCondition === 2 && _MLOR === 0)
		{this.$stopTimer();
		}
		
	if (player.alertCondition === 1)
		{this.$startTimer2();
		//this._MLCR = 1;
		}	
}
this.$masslockReleaseTimer = function $masslockReleaseTimer ()
{
	player.ship.massLockable = false;
	player.consoleMessage ("Torus Drive Online");
}
this.$masslockRestoreTimer = function $masslockRestoreTimer ()
{
	var shpsNear = player.ship.checkScanner();
	
	if (shpsNear.length === 0) {
		player.ship.massLockable = true;
		player.consoleMessage ("Mass-Lock Sensitivity Restored");
	}
	else {
	this.$startTimer2();
	}
}
this.$masslockRecalibrationTimer = function $masslockRecalibrationTimer ()
{
	player.consoleMessage ("Torus Drive Recalibrated... rerouting...");
	//this._MLCR = 1;
	this.$startTimer1();
}
 |