-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelivery.js
57 lines (55 loc) · 3 KB
/
delivery.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function MedicalDeliveryRequestEvent (origin, destination) {
let distance = Math.max(Math.abs(destination.xCoord - origin.xCoord), Math.abs(destination.yCoord - origin.yCoord));
this.diseaseName = destination.system.universe.systems.random().name + " parasite";
this.turns = Math.floor(distance/2) + randomNumber(10,40);
this.reward = Math.floor(distance/5 + 1)*5;
this.origin = origin;
this.destination = destination;
this.message = `${this.origin.name} is suffering from a category 4 pandemic of the ${this.diseaseName}! Local authorities have requested your assistance in retrieving vaccines from ${destination.name}. If the vaccines are brought within ${this.turns} days, then you will be compensated ${this.reward} BitCredits.`;
this.time_until = 0;
}
MedicalDeliveryRequestEvent.prototype = {
action: function (universe, callbackFunction) {
this.startTurn = universe.turn;
this.destination.events.push(new MedicalDeliveryPickupEvent(this));
getAcknowledgement(this.message, callbackFunction);
}
}
function MedicalDeliveryPickupEvent (request) {
this.request = request;
this.message = `The xenoparasitology research lab on ${this.request.destination.name} provides you with a large supply of ${this.request.diseaseName} vaccines.`;
this.time_until = 0;
}
MedicalDeliveryPickupEvent.prototype = {
action: function (universe, callbackFunction) {
let turnsRemaining = this.request.startTurn + this.request.turns - universe.turn;
if (turnsRemaining > 0) {
this.message += ` ${turnsRemaining} days remain to deliver the vaccines to ${this.request.origin.name}.`
this.request.origin.events.push(new MedicalDeliveryDeliverEvent(this.request));
getAcknowledgement(this.message, callbackFunction);
}
else {
this.message = `You inquire with the xenoparasitology research lab on ${this.request.destination.name} about the ${this.request.diseaseName} vaccines, but the chief medical officer tells you that it's too late for a delivery now.`;
getAcknowledgement(this.message, callbackFunction);
}
}
}
function MedicalDeliveryDeliverEvent (request) {
this.request = request;
this.message = "";
this.time_until = 0;
}
MedicalDeliveryDeliverEvent.prototype = {
action: function (universe, callbackFunction) {
let turnsRemaining = this.request.startTurn + this.request.turns - universe.turn;
if (turnsRemaining >= 0) {
this.message = `The authorities on ${this.request.origin.name} thank you profusely for delivering the ${this.request.diseaseName} vaccines. ${this.request.reward} BitCredits have been added to your account.`;
let ps = getPlayerShip(getPlayerSystem(universe).ships);
ps.credits += this.request.reward;
}
else {
this.message = `The authorities on ${this.request.origin.name} thank you for delivering the ${this.request.diseaseName} vaccines. \"Unfortunately we cannot compensate you for the delivery because it was ${-turnsRemaining} days late.\"`;
}
getAcknowledgement(this.message, callbackFunction);
}
}