Config/script.js |
"use strict";
this.name = "MaintenanceTuneUp_Core";
this.author = "phkb";
this.copyright = "2019 phkb";
this.description = "Core operational script for Maintenance Tune Up";
this.licence = "CC BY-NC-SA 4.0";
this._storedServiceLevel = 0;
this._storedTechLevel = 0;
this._debug = false;
this._cost = 0;
//-------------------------------------------------------------------------------------------------------------
this.startUpComplete = function() {
if (!missionVariables.MaintenanceTuneUp_SL) missionVariables.MaintenanceTuneUp_SL = 0;
if (!missionVariables.MaintenanceTuneUp_TL) missionVariables.MaintenanceTuneUp_TL = 0;
this._storedServiceLevel = missionVariables.MaintenanceTuneUp_SL;
this._storedTechLevel = missionVariables.MaintenanceTuneUp_TL;
if (worldScripts.GalCopAdminServices) {
var ga = worldScripts.GalCopAdminServices;
ga._purchase_ignore_equip.push("EQ_MAINTENANCE_TUNEUP"); // don't sent a normal purchase email for this one
}
}
//-------------------------------------------------------------------------------------------------------------
this.shipDockedWithStation = function(station) {
if (this._debug) log(this.name, "Servicelevel when docking = " + player.ship.serviceLevel);
if (this._debug) log(this.name, "Station TL = " + (station.equivalentTechLevel + 1));
}
//-------------------------------------------------------------------------------------------------------------
this.guiScreenChanged = function(to, from) {
if (to === "GUI_SCREEN_EQUIP_SHIP") {
this._cost = player.ship.renovationCost;
}
}
//-------------------------------------------------------------------------------------------------------------
this.playerBoughtEquipment = function(equipment) {
if (equipment === "EQ_RENOVATION") {
if (this._debug) log(this.name, "Servicelevel after overhaul = " + player.ship.serviceLevel);
if (this._debug) log(this.name, "Station TL = " + (player.ship.dockedStation.equivalentTechLevel + 1));
// reset tune up observation variables
this._storedServiceLevel = 0;
this._storedTechLevel = 0;
}
if (equipment === "EQ_MAINTENANCE_TUNEUP") {
// normal service level range is 75-84
// calc for addition to service level is 5 + techLevel (of station or system, whichever applies)
// worst service level is 75, best tech level is 14, lowest tech level is 6
// in best scenario, for a normal renovation, the player would get back to a service level of 103 (84 + 19) but reduced to max 100.
// in worst scenario, the player would get back to a service level of 86 (75 + 11)
// so, if the player has servicelevel of 93, best would be +7, worst reno would be +1
// if player has a servicelevel of 85, best would be +15, worst would be +1
var diff = Math.floor((100 - player.ship.serviceLevel) * ((player.ship.dockedStation.equivalentTechLevel + 1) / 15));
if (diff < 1) diff = 1;
player.ship.serviceLevel += diff;
this._storedServiceLevel = player.ship.serviceLevel;
this._storedTechLevel = player.ship.dockedStation.equivalentTechLevel;
player.ship.removeEquipment("EQ_MAINTENANCE_TUNEUP");
if (worldScripts.GalCopAdminServices) {
var ga = worldScripts.GalCopAdminServices;
ga._maintCost = this._cost / 10;
ga.$setupRepNames();
ga.$sendMaintenanceEmail();
}
}
}
//-------------------------------------------------------------------------------------------------------------
this.playerWillSaveGame = function() {
missionVariables.MaintenanceTuneUp_SL = this._storedServiceLevel;
missionVariables.MaintenanceTuneUp_TL = this._storedTechLevel;
}
|
Scripts/maintenance_tuneup_conditions.js |
"use strict";
this.name = "MaintenanceTuneUp_Conditions";
this.author = "phkb";
this.copyright = "2019 phkb";
this.description = "Condition script for Maintenance Tune Up";
this.licence = "CC BY-NC-SA 4.0";
//-------------------------------------------------------------------------------------------------------------
this.allowAwardEquipment = function(equipment, ship, context) {
if (context === "scripted") return true;
if (equipment === "EQ_MAINTENANCE_TUNEUP") {
if (ship.canAwardEquipment("EQ_RENOVATION") == true) return false;
if (ship.serviceLevel >= 98) return false;
var mtu = worldScripts.MaintenanceTuneUp_Core;
var p = player.ship;
if (p.serviceLevel.toFixed(0) == mtu._storedServiceLevel.toFixed(0) && p.dockedStation.equivalentTechLevel <= mtu._storedTechLevel) {
return false;
}
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------------------
this.updateEquipmentPrice = function(equipment, price) {
var newprice = price;
var p = player.ship;
if (equipment === "EQ_MAINTENANCE_TUNEUP") {
newprice = p.renovationCost;
if (newprice < 10000) newprice = 10000; // set a minimum price
}
return newprice;
} |