📄 script.java
字号:
package mobileRPG.client;
import mobileRPG.client.scriptaction.*;
public class Script {
private int indexAction;
private ScriptAction[] scriptaction;
public String[] line;
public Entity entity;
private boolean active;
public Script(Entity e, int lineCount) {
entity = e;
line = new String[lineCount];
}
public boolean isActive() {
return active;
}
public void activateScript() {
// If this script is already running return
if (isActive()) {return;}
// Start at the top of the action stack
active = true;
indexAction = 0;
scriptaction = new ScriptAction[line.length];
}
public void printScript() {
for (int n = 0; n < line.length; n++) {
System.out.println(line[n]);
}
}
public void onTime() {
// If this is not active, don't start it
if (!isActive()) {return;}
while (doScriptAction()) {
indexAction++;
if (indexAction >= scriptaction.length) {
active = false;
break;
}
}
}
// Returns true if the next script action should be started
private boolean doScriptAction() {
// If the script action hasn't been inited yet, do that
if (scriptaction[indexAction] == null) {
scriptaction[indexAction] = initScriptAction(line[indexAction].trim());
// This action failed to init, go to the next one
if (scriptaction[indexAction] == null) {
return true;
}
}
// Do the action
scriptaction[indexAction].active = true;
scriptaction[indexAction].onTime();
// If the action is complete, move to the next one
if (scriptaction[indexAction].isComplete()) {
scriptaction[indexAction].active = false;
return true;
}
return false;
}
private ScriptAction initScriptAction(String l) {
if (l.equals("kick")) {
return new Kick(this);
}
if (l.length() > 4 && l.substring(0, 4).equals("wait")) {
String time = l.substring(5);
int timeCountMax = Integer.parseInt(time);
return new Wait(this, timeCountMax);
}
if (l.length() > 4 && l.substring(0, 4).equals("move")) {
String direction = l.substring(5);
return new Move(this, direction);
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -