| Scripts/wc_equipment_conditions.js |
"use strict";
this.allowAwardEquipment = function(equipment, ship, context) {
// Remove Auto-SOS conditions
if (equipment == "EQ_WITCH_CHARGER_REM")
if (player.ship.equipmentStatus ("EQ_WITCH_CHARGER") === "EQUIPMENT_OK")
return true; else return false;
return true;
}
|
| Scripts/wc_script.js |
"use strict";
this.name = "Witch-Charger";
this.author = "Reval";
this.license = "CC-BY-NC-SA 4.0";
this.version = "1.1";
this.description = "This emergency capacitor conducts potential energy from the Witchdrive to shore up shield resistance and prevent equipment damage when hull integrity is critical. If the ship remains under fire, the unit's last-ditch replenishing action will finally drain all fuel.";
// OPTION: Log Witch-Charger quantity stats for each viable 'hit'
this.$log = false;
// OPTION: adjust fuel cost multiplier (default: 0.01)
this.$wcFuelCostMultiplier = 0.01;
// OPTION: adjust shield re-charge factor (default: 1.2)
this.$wcShieldRechargeFactor = 1.2;
// OPTION: adjust energy recharge factor (default: 10.0)
this.$wcEnergyRechargeFactor = 10.0;
/*
Version 1.1
In addition to shoring up shields, Charger feeds sufficient energy to prevent core equipment damage.
Version 1.0
Added anunciator for cumulative Witchdrive fuel drain.
Added adjustable W.C. factors / multipliers as options.
Added witch-drive capacitor 'drain and flow' sound.
Added use-requirement that player must be 'clean'.
Added check for presence of equipment.
Added check for clean legal record before purchase.
Added saving-cutoff for a shield if at full capacity.
Global flag for status of Witch Charge capacitor (viable or drained)
*/
this.shipTakingDamage = function(amount, whom, type) {
// Shields absorbed it, no drain needed
if (amount <= 0) return;
// Proceed only if player's legal status is unsullied
if (player.legalStatus!=="Clean") return;
// Actuate if unit is installed and not already depleted
if (!this.$hasWitchCharger || this.$witchChargerEmpty) return;
var ship = player.ship;
// Tuned: 0.02 fuel per 1 hull damage
var fuelCost = amount * this.$wcFuelCostMultiplier;
if (ship.fuel >= fuelCost) {
// THE CONDUIT OPENS
ship.fuel -= fuelCost;
// THE CAPACITOR DISCHARGES INTO SHIELDS
var restoreAmount = amount * this.$wcShieldRechargeFactor;
// Only restore shields that are below maximum
if (ship.forwardShield < ship.maxForwardShield) {
ship.forwardShield = Math.min(ship.forwardShield + restoreAmount, ship.maxForwardShield);
}
if (ship.aftShield < ship.maxAftShield) {
ship.aftShield = Math.min(ship.aftShield + restoreAmount, ship.maxAftShield);
}
// Restore a fraction of ENERGY (try 10 units per activation)
ship.energy = Math.min(ship.energy + this.$wcEnergyRechargeFactor, ship.maxEnergy);
// track Witch Charge reserve state
this.$witchChargerEmpty = (ship.fuel <= 0.0);
// track total cumulative capacitor drain
this.$wcTFCD += fuelCost;
// drain annunciator
player.consoleMessage("Witch Charge capacitor drain: "+this.$wcTFCD.toFixed(3), 2);
// sound to reflect capacitor's witch-fuel flow and drain
this.$witchChargerSound.playSound("breakpattern.ogg");
// log quantities
this._wcChargeStatus(amount, fuelCost, restoreAmount, this.$wcTFCD);
} else {
// CAPACITOR EMPTY
this.$witchChargerEmpty = true;
player.commsMessage("WITCH CHARGER: RESERVE DEPLETED.");
}
};
this._wcChargeStatus = function(damage, cost, restore, drain) {
var ps = player.ship;
if (this.$log) {
this._log("Witch Charger - damage: "+damage);
this._log("Witch Charger - fuel: "+ps.fuel);
this._log("Witch Charger - fuel cost: "+cost);
this._log("Witch Charger - total drain: "+drain);
this._log("Witch Charger - restored: "+restore);
this._log("Witch Charger - energy: "+ps.energy);
this._log("Witch Charger - f-shield: "+ps.forwardShield);
this._log("Witch Charger - a-shield: "+ps.aftShield);
this._log(" "); // section break
}
}
// Witch-Charger feeds sufficient energy to prevent core equipment damage
this.equipmentDamaged = function(equipmentKey) {
// A: Repair ONLY the specific item that was just hit (Efficient)
player.ship.setEquipmentStatus(equipmentKey, "EQUIPMENT_OK");
// B: Loop through ALL equipment and repair anything damaged (Comprehensive)
// Use only to catch items that might have been damaged in the same hit but didn't trigger the event separately
/*
var allEq = player.ship.allEquipment;
for (var i = 0; i < allEq.length; i++) {
var eqKey = allEq[i];
// Check status; if not OK, repair it
if (player.ship.equipmentStatus(eqKey) !== "EQUIPMENT_OK") {
player.ship.setEquipmentStatus(eqKey, "EQUIPMENT_OK");
}
}
*/
};
this.shipWillLaunchFromStation = function() {
var ps = player.ship;
this.$hasWitchCharger = (ps.equipmentStatus ("EQ_WITCH_CHARGER") === "EQUIPMENT_OK");
// re-set key W.C. quantities and flags
this.$witchChargerEmpty = false;
this.$wsTFCD = 0.0;
}
this.playerBoughtEquipment = function(equipment, paid) {
var pc = player.consoleMessage;
if (equipment == "EQ_WITCH_CHARGER") {
pc("Witch Charge capacitor installed. Monitoring.",9);
} else
// Service cancellation removal and refund
if (equipment == "EQ_WITCH_CHARGER_REM") {
player.ship.removeEquipment("EQ_WITCH_CHARGER");
player.ship.removeEquipment("EQ_WITCH_CHARGER_REM");
pc("Witch Charger removed. No refund.",9);
}
}
// Reset status if player explicitly sells the item via other means
this.playerSoldEquipment = function(equipment) {
if (equipment.equipmentKey == "EQ_WITCH_CHARGER") {
this.hasWitchCharger = false;
}
};
// echo to Oolite log for this script only
this._log = function(msg) {
log(this.name+".debug", msg);
}
this.startUp = function() {
// flag to track if the unit is active/installed
this.$hasWitchCharger = false;
// flag to track W.C. capacitor state
this.$witchChargerEmpty = false;
// Create the SoundSource once
this.$witchChargerSound = new SoundSource();
// cumulative capacitor drain
this.$wcTFCD = 0.0;
};
|