-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeployGenesisTorpedo.java
executable file
·141 lines (128 loc) · 4.36 KB
/
DeployGenesisTorpedo.java
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import com.swath.*;
/**
Makes a planet and returns whether it is the type that is being tried for.
Author MD
*/
public class DeployGenesisTorpedo extends UserDefinedCommand {
private String name;
private PlanetClass[] c;
private int owner;
private boolean isDone;
private String nameIfNotRight;
private boolean busting;
public String getName() {
// Return the name of the command
return "Deploy Genesis Torpedo";
}
public boolean initCommand() throws Exception {
if(!atPrompt(Swath.COMMAND_PROMPT)){
throw new Exception("Must be at Command Prompt.");
}
return true;
}
public void startCommand() throws Exception {
sendString("uy ");
}
public void endCommand(boolean finished) throws Exception {
setResult(new Boolean(isDone));
}
public void onText(String buffer, String text) throws Exception {
Tools.TextRange range;
if ((range = ((Tools.findText(buffer, "What do you want to name this planet? (",")")))) != null) {
String input = Tools.getText(buffer,range);
input = input.substring(input.indexOf("("),input.lastIndexOf(")"));
isDone = false;
int i = 0;
while(!isDone && i < c.length){
if(input.indexOf(c[i].name()) >= 0){
sendString(name+RETURN_KEY);
isDone = true;
}
i++;
}
if(!isDone){
sendString(nameIfNotRight+RETURN_KEY);
}
if(owner == Swath.PERSONAL){
if(Swath.you.corporation() != null){
sendString("p");
}
}
else{
if(Swath.you.corporation() != null){
sendString("c");
}
}
setBufferText("");
if(!isDone){
sendString("l");
}
}
else if ((range = ((Tools.findText(buffer, "WARNING! It is potentially hazardous to place more than","Do you wish to abort?")))) != null) {
setBufferText("");
sendString("n ");
}
else if ((range = ((Tools.findText(buffer, "<Atmospheric maneuvering system engaged>","Land on which planet <Q to abort>")))) != null) {
String input = Tools.getText(buffer,range);
int loc;
if((loc = input.indexOf(nameIfNotRight)) < 0){
throw new CommandException(this,"Invalid Planet");
}
else{
input = input.substring(loc-8,loc).trim();
input = input.substring(input.indexOf("<")+1,input.indexOf(">")).trim();
}
sendString(input+RETURN_KEY+" zdy ");
isDone = false;
setBufferText("");
}
}
public void onEvent(EventIfc event) throws Exception {
// // Here you can receive and process incoming events
// printTrace("onEvent('" + event.getClassName() + "')");
}
public static boolean exec(String name, PlanetClass[] c, int owner, String nameIfNotRight) throws Exception {
// This is the static method that will make it possible to use
// this command in a user defined script just like using any of
// the given SWATH commands.
// Several different exec methods could be defined if needed.
DeployGenesisTorpedo cmd = new DeployGenesisTorpedo();
cmd.initInstance();
cmd.c = c;
cmd.name = name;
cmd.owner = owner;
cmd.nameIfNotRight = nameIfNotRight;
cmd.busting = false;
return ((Boolean)(cmd.execInstance())).booleanValue();
}
public static boolean exec(boolean busting, String name) throws Exception {
// This is the static method that will make it possible to use
// this command in a user defined script just like using any of
// the given SWATH commands.
// Several different exec methods could be defined if needed.
DeployGenesisTorpedo cmd = new DeployGenesisTorpedo();
cmd.initInstance();
cmd.c = new PlanetClass[0];
cmd.name = name;
cmd.owner = Swath.PERSONAL;
cmd.nameIfNotRight = name;
cmd.busting = busting;
return ((Boolean)(cmd.execInstance())).booleanValue();
}
public static boolean exec(String name, PlanetClass c, int owner, String nameIfNotRight) throws Exception {
// This is the static method that will make it possible to use
// this command in a user defined script just like using any of
// the given SWATH commands.
// Several different exec methods could be defined if needed.
DeployGenesisTorpedo cmd = new DeployGenesisTorpedo();
cmd.initInstance();
PlanetClass[] temp = new PlanetClass[1];
temp[0] = c;
cmd.c = temp;
cmd.name = name;
cmd.owner = owner;
cmd.nameIfNotRight = nameIfNotRight;
cmd.busting = false;
return ((Boolean)(cmd.execInstance())).booleanValue();
}
}