diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/Trigger.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/Trigger.java')
| -rw-r--r-- | NET/worlds/scape/Trigger.java | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/NET/worlds/scape/Trigger.java b/NET/worlds/scape/Trigger.java new file mode 100644 index 0000000..a056535 --- /dev/null +++ b/NET/worlds/scape/Trigger.java @@ -0,0 +1,199 @@ +package NET.worlds.scape; + +import NET.worlds.console.Console; +import java.io.IOException; +import java.text.MessageFormat; + +public class Trigger extends SwitchableBehavior implements FrameHandler, Persister, MouseDownHandler, BumpHandler { + public static TriggeredSwitchableBehavior[] TriggeredSwitchableBehaviorList = new TriggeredSwitchableBehavior[1000]; + public static int TriggeredSwitchableBehaviorListCount = 0; + public String trigger = new String("none"); + public String targetTriggerTag = new String(""); + public String[][] targetTriggerTagArray = new String[20][10]; + public int targetTriggerTagCount = 0; + public int[] finishedTriggerTagSequenceNo = new int[50]; + public int[] finishedTriggerTagEventNo = new int[50]; + public int finishedTriggerTagCount = 0; + + private void addTargetTriggerTagArray(String[] sequentialTargetTriggerTagArray, String targetTriggerTag) { + int currentIndex = 1; + int currentSeparator = 0; + int nextSeparator = 0; + int lastSeparator = targetTriggerTag.lastIndexOf("+"); + if (lastSeparator == -1 && targetTriggerTag.length() == 0) { + int var8 = 0; + sequentialTargetTriggerTagArray[0] = String.valueOf((int)var8); + } else if (lastSeparator == -1) { + sequentialTargetTriggerTagArray[currentIndex] = targetTriggerTag; + sequentialTargetTriggerTagArray[0] = String.valueOf(currentIndex); + } else { + nextSeparator = targetTriggerTag.indexOf("+"); + sequentialTargetTriggerTagArray[currentIndex] = targetTriggerTag.substring(0, nextSeparator); + currentIndex++; + + while (nextSeparator != lastSeparator) { + currentSeparator = nextSeparator; + nextSeparator = targetTriggerTag.indexOf("+", nextSeparator + 1); + sequentialTargetTriggerTagArray[currentIndex] = targetTriggerTag.substring(currentSeparator + 1, nextSeparator); + currentIndex++; + } + + sequentialTargetTriggerTagArray[currentIndex] = targetTriggerTag.substring(nextSeparator + 1); + sequentialTargetTriggerTagArray[0] = String.valueOf(currentIndex); + } + } + + public void preprocessTargetTriggerTag(String targetTriggerTag) { + int currentIndex = 1; + int currentSeparator = 0; + int nextSeparator = 0; + int lastSeparator = targetTriggerTag.lastIndexOf(" "); + if (lastSeparator != -1 || targetTriggerTag.length() != 0) { + if (lastSeparator == -1) { + this.addTargetTriggerTagArray(this.targetTriggerTagArray[currentIndex], targetTriggerTag); + this.targetTriggerTagCount = currentIndex; + } else { + nextSeparator = targetTriggerTag.indexOf(" "); + this.addTargetTriggerTagArray(this.targetTriggerTagArray[currentIndex], targetTriggerTag.substring(0, nextSeparator)); + currentIndex++; + + while (nextSeparator != lastSeparator) { + currentSeparator = nextSeparator; + nextSeparator = targetTriggerTag.indexOf(" ", nextSeparator + 1); + this.addTargetTriggerTagArray(this.targetTriggerTagArray[currentIndex], targetTriggerTag.substring(currentSeparator + 1, nextSeparator)); + currentIndex++; + } + + this.addTargetTriggerTagArray(this.targetTriggerTagArray[currentIndex], targetTriggerTag.substring(nextSeparator + 1)); + this.targetTriggerTagCount = currentIndex; + } + } + } + + public void activateTrigger() { + for (int j = 1; j <= this.targetTriggerTagCount; j++) { + boolean match = false; + + for (int i = 0; !match && i < TriggeredSwitchableBehaviorListCount; i++) { + if (this.targetTriggerTagArray[j][1].equals(TriggeredSwitchableBehaviorList[i].externalTriggerTag) && TriggeredSwitchableBehaviorList[i] != null) { + TriggeredSwitchableBehaviorList[i].ExternalTrigger(this, j, 1); + } + } + } + } + + public void activateSequenceTrigger() { + for (int j = this.finishedTriggerTagCount; j > 0; j--) { + int sequence_no = this.finishedTriggerTagSequenceNo[j]; + int event_no = this.finishedTriggerTagEventNo[j]; + if (Integer.valueOf(this.targetTriggerTagArray[sequence_no][0]) > event_no) { + boolean match = false; + + for (int i = 0; !match && i < TriggeredSwitchableBehaviorListCount; i++) { + if (this.targetTriggerTagArray[sequence_no][event_no + 1].equals(TriggeredSwitchableBehaviorList[i].externalTriggerTag) + && TriggeredSwitchableBehaviorList[i] != null) { + TriggeredSwitchableBehaviorList[i].ExternalTrigger(this, sequence_no, event_no + 1); + } + } + } + } + + this.finishedTriggerTagCount = 0; + } + + public synchronized void registerFinishedTriggerTag(int sequence_no, int event_no) { + this.finishedTriggerTagCount++; + this.finishedTriggerTagSequenceNo[this.finishedTriggerTagCount] = sequence_no; + this.finishedTriggerTagEventNo[this.finishedTriggerTagCount] = event_no; + } + + @Override + public boolean handle(FrameEvent e) { + if (this.enabled && this.finishedTriggerTagCount > 0) { + this.activateSequenceTrigger(); + } + + return true; + } + + @Override + public boolean handle(MouseDownEvent e) { + if (this.enabled && this.trigger.equals("click")) { + this.activateTrigger(); + } + + return true; + } + + @Override + public boolean handle(BumpEventTemp e) { + if (this.enabled && this.trigger.equals("bump")) { + this.activateTrigger(); + } + + return true; + } + + @Override + public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { + Object ret = null; + switch (index - offset) { + case 0: + if (mode == 0) { + ret = StringPropertyEditor.make(new Property(this, index, "Trigger")); + } else if (mode == 1) { + ret = new String(this.trigger); + } else if (mode == 2) { + this.trigger = ((String)value).toString().trim(); + } + break; + case 1: + if (mode == 0) { + ret = StringPropertyEditor.make(new Property(this, index, "Target Trigger Tag")); + } else if (mode == 1) { + ret = new String(this.targetTriggerTag); + } else if (mode == 2) { + this.targetTriggerTag = ((String)value).toString().trim(); + this.preprocessTargetTriggerTag(this.targetTriggerTag); + } + break; + default: + ret = super.properties(index, offset + 2, mode, value); + } + + return ret; + } + + @Override + public String toString() { + return super.toString() + "[enabled " + this.enabled + ", trigger " + this.trigger + ", targetTriggerTag " + this.targetTriggerTag + "]"; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveString(this.trigger); + s.saveString(this.targetTriggerTag); + } + + @Override + public void restoreState(Restorer r) throws IOException { + this.trigger = r.restoreString(); + this.targetTriggerTag = r.restoreString(); + this.preprocessTargetTriggerTag(this.targetTriggerTag); + } + + @Override + public void postRestore(int version) { + String name = this.getName(); + String arg1 = name == null ? "<null>" : name; + SuperRoot owner = this.getOwner(); + String oname = ""; + if (owner != null) { + oname = owner.getName(); + } + + String arg2 = oname == null ? "<null>" : oname; + Object[] arguments = new Object[]{new String(arg1), new String(arg2)}; + Console.println(MessageFormat.format(Console.message("Trigger-obs"), arguments)); + } +} |