-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFighterRefresh.java
executable file
·73 lines (62 loc) · 2.09 KB
/
FighterRefresh.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
import com.swath.*;
//Command to surround a sector with fighters and limpets.
//Author Mind Dagger
public class FighterRefresh extends UserDefinedCommand {
private int count;
// private boolean start;
// private boolean stop;
//
public String getName() {
return "Fighter Refresh";
}
public boolean initCommand() throws Exception {
// Initialisation of the command is done in this method.
// All parameters should be created and registered here.
// If something goes wrong, throw a CommandException or return false.
// Check that we are at the correct prompt
if (!atPrompt(Swath.COMMAND_PROMPT)) {
throw new CommandException(this, "Not at correct prompt");
}
count = 0;
// start = false;
// stop = false;
return true;
}
public void startCommand() throws Exception {
setBufferText("");
sendString("g");
}
public void endCommand(boolean result) throws Exception {
//Minus 2 to handle 2 instances of r in deployed fighter scan titles.
setResult(new Integer(count-2));
}
public void onText(String buffer, String text) throws Exception {
// Incoming text is sent to this method when it arrives.
// The text parameter only contains the new text that arrived
// and the buffer contains all text received so far.
// The buffer can be cleared or updated using the setTextBuffer method.
// Tools.TextRange range;
// if((range = Tools.findText(buffer,"===========================================================","Command [")) != null){
// String figs = Tools.getText(buffer,range);
// int index = 0;
// while(figs.indexOf("\n", index) >= 0){
// count++;
// index = figs.indexOf("\n",index)+1;
// }
// }
//int index = 0;
String copy = buffer;
setBufferText(buffer.substring(copy.length()));
String[] s = copy.split("\n");
for(int i = 0; i < s.length; i++){
if(s[i].indexOf("r") >= 0){
count++;
}
}
}
public static int exec() throws Exception {
FighterRefresh cmd = new FighterRefresh();
cmd.initInstance();
return ((Integer)cmd.execInstance()).intValue();
}
}