Scripts/SUWitchdriveConditions.js |
"use strict";
this.name = "Single-Use Witchdrive Conditions Script";
this.author = "ocz";
this.copyright = "2015 ocz";
this.licence = "CC BY-NC-SA 4.0";
var versionLowerThan183 = function(_version) {
if ((_version[0] < 1) || (_version[0] == 1 && _version[1] < 83)) {
return true;
}
return false;
}
this.allowAwardEquipment = function(eqKey, ship, context) {
if (context === "purchase" && eqKey === "EQ_SUWITCHDRIVE") {
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVE") === "EQUIPMENT_DAMAGED" && !versionLowerThan183(oolite.version)) {return true;}
return false;
}
if (context === "purchase" && eqKey === "EQ_SUWITCHDRIVE_REP") { // An Oolite pre v1.83 fix to offer a repair option, even when no additional 2t free cargo space, which is needed before v1.83, is available.
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVE") === "EQUIPMENT_DAMAGED" && versionLowerThan183(oolite.version)) {
return true;
}
return false;
}
if (context === "purchase" && eqKey === "EQ_SUWITCHDRIVEBUY" && !(Ship.shipDataForKey(player.ship.dataKey)["hyperspace_motor"] === "no") ) {
return false;
}
return true; // In any other case, it's fine. (All other stuff is available, too.)
} |
Scripts/SUWitchdriveScripts.js |
"use strict";
this.name = "Single-Use Witchdrive Script";
this.author = "ocz";
this.copyright = "2015 ocz";
this.licence = "CC BY-NC-SA 4.0";
this.playerBoughtEquipment = function(equipment) {
if (equipment == "EQ_SUWITCHDRIVEBUY") {
player.ship.removeEquipment("EQ_SUWITCHDRIVEBUY");
player.ship.awardEquipment("EQ_SUWITCHDRIVE");
player.ship.hyperspaceSpinTime = 15; //This line gives both the ship the ability to make Witchjumps and sets the countdown length to 15s.
return;
}
if (equipment == "EQ_SUWITCHDRIVE_REP") {
player.ship.removeEquipment("EQ_SUWITCHDRIVE_REP");
player.ship.setEquipmentStatus("EQ_SUWITCHDRIVE", "EQUIPMENT_OK");
player.ship.hyperspaceSpinTime = 15;
return;
}
if (equipment == "EQ_SUWITCHDRIVE_REMOVE") {
player.ship.removeEquipment("EQ_SUWITCHDRIVE_REMOVE");
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVE") === "EQUIPMENT_DAMAGED") {
player.credits += 200; // If damaged, refund only half the price.
}
else player.credits += 400; // Refund the price.
player.ship.hyperspaceSpinTime = -1; // Take away the Witchdrive for good. SU-Witchdrive shouldn't be available for ships with standard Witchdrive anyway.
player.ship.removeEquipment("EQ_SUWITCHDRIVE");
return;
}
if (equipment == "EQ_SUWITCHDRIVEANDSPARECOILS_REMOVE") {
player.ship.removeEquipment("EQ_SUWITCHDRIVEANDSPARECOILS_REMOVE");
player.ship.removeEquipment("EQ_SUWITCHDRIVESPARECOILS");
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVE") === "EQUIPMENT_DAMAGED") {
player.credits += 400;
}
else player.credits += 600;
player.ship.hyperspaceSpinTime = -1;
player.ship.removeEquipment("EQ_SUWITCHDRIVE");
return;
}
if (equipment == "EQ_SUWITCHDRIVESPARECOILS_REMOVE") {
player.ship.removeEquipment("EQ_SUWITCHDRIVESPARECOILS_REMOVE");
player.ship.removeEquipment("EQ_SUWITCHDRIVESPARECOILS");
player.credits += 200;
}
}
this.shipWillEnterWitchspace = function(cause, destination) {
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVE") === "EQUIPMENT_OK" && cause === "standard jump") {
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVESPARECOILS") === "EQUIPMENT_OK") {
player.ship.removeEquipment("EQ_SUWITCHDRIVESPARECOILS"); //The spare coils get ejected after use.
}
else player.ship.setEquipmentStatus("EQ_SUWITCHDRIVE", "EQUIPMENT_DAMAGED");
}
}
this.equipmentDamaged = function(equipment) {
if (equipment === "EQ_SUWITCHDRIVE") {
player.ship.hyperspaceSpinTime = -1; //If the Single-Use Witchdrive gets damaged in a fight or by using it without spare coils, the ship loses its witchjump ability.
player.ship.cancelHyperspaceCountdown(); //Just in case the player was about to jump out of a fight for example.
}
else if (equipment === "EQ_SUWITCHDRIVESPARECOILS") {
player.ship.removeEquipment("EQ_SUWITCHDRIVESPARECOILS"); //If the spare coils get somehow damaged they get ejected.
}
}
this.equipmentRepaired = function(equipment) {
if (equipment === "EQ_SUWITCHDRIVE") {
player.ship.hyperspaceSpinTime = 15; //If the Single-Use Witchdrive gets repaired, the ship regains its witchjump ability.
}
}
this.startUpComplete = function() {
if (player.ship.equipmentStatus("EQ_SUWITCHDRIVE") === "EQUIPMENT_OK") {
player.ship.hyperspaceSpinTime = 15;
}
}
|