remove duplicate operation on trigger

This commit is contained in:
RaffaeleMorganti 2022-11-18 21:00:28 +01:00
parent 5d098bf32d
commit 2e12ab7f1f

View file

@ -430,22 +430,7 @@ public class Zork {
private boolean doTriggersContainersInRoom() { private boolean doTriggersContainersInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).container.keySet()) { for (String key : game.Rooms.get(currentRoom).container.keySet()) {
ZorkContainer tempContainer = game.Containers.get(key); skip = skip || doZorkTriggers(game.Containers.get(key));
for (int x = 0; x < tempContainer.trigger.size(); x++) {
ZorkTrigger tempTrigger = tempContainer.trigger.get(x);
if (tempTrigger.evaluate(this)) {
for (String print: tempTrigger.print) {
System.out.println(print);
}
for (String action: tempTrigger.action) {
executeAction(action);
}
skip = skip || tempTrigger.hasCommand;
if (tempTrigger.type.equals("single")) {
tempContainer.trigger.remove(x);
}
}
}
} }
return skip; return skip;
} }
@ -455,22 +440,7 @@ public class Zork {
for (String key : game.Rooms.get(currentRoom).container.keySet()) { for (String key : game.Rooms.get(currentRoom).container.keySet()) {
ZorkContainer tempContainer = game.Containers.get(key); ZorkContainer tempContainer = game.Containers.get(key);
for (String key2 : tempContainer.item.keySet()) { for (String key2 : tempContainer.item.keySet()) {
ZorkItem tempItem = game.Items.get(key2); skip = skip || doZorkTriggers(game.Items.get(key2));
for (int x = 0; x < tempItem.trigger.size(); x++) {
ZorkTrigger tempTrigger = tempItem.trigger.get(x);
if (tempTrigger.evaluate(this)) {
for (String print : tempTrigger.print) {
System.out.println(print);
}
for (String action : tempTrigger.action) {
executeAction(action);
}
skip = skip || tempTrigger.hasCommand;
if (tempTrigger.type.equals("single")) {
tempItem.trigger.remove(x);
}
}
}
} }
} }
return skip; return skip;
@ -479,22 +449,7 @@ public class Zork {
private boolean doTriggersItemsInRoom() { private boolean doTriggersItemsInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).item.keySet()) { for (String key : game.Rooms.get(currentRoom).item.keySet()) {
ZorkItem tempItem = game.Items.get(key); skip = skip || doZorkTriggers(game.Items.get(key));
for (int x = 0; x < tempItem.trigger.size(); x++) {
ZorkTrigger tempTrigger = tempItem.trigger.get(x);
if (tempTrigger.evaluate(this)) {
for (String print: tempTrigger.print) {
System.out.println(print);
}
for (String action: tempTrigger.action) {
executeAction(action);
}
skip = skip || tempTrigger.hasCommand;
if (tempTrigger.type.equals("single")) {
tempItem.trigger.remove(x);
}
}
}
} }
return skip; return skip;
} }
@ -502,22 +457,7 @@ public class Zork {
private boolean doTriggersItemsInInventory() { private boolean doTriggersItemsInInventory() {
boolean skip = false; boolean skip = false;
for (String key : game.Inventory.keySet()) { for (String key : game.Inventory.keySet()) {
ZorkItem tempItem = game.Items.get(key); skip = skip || doZorkTriggers(game.Items.get(key));
for (int x = 0; x < tempItem.trigger.size(); x++) {
ZorkTrigger tempTrigger = tempItem.trigger.get(x);
if (tempTrigger.evaluate(this)) {
for (String print: tempTrigger.print) {
System.out.println(print);
}
for (String action: tempTrigger.action) {
executeAction(action);
}
skip = skip || tempTrigger.hasCommand;
if (tempTrigger.type.equals("single")) {
tempItem.trigger.remove(x);
}
}
}
} }
return skip; return skip;
} }
@ -525,30 +465,20 @@ public class Zork {
private boolean doTriggersCreaturesInRoom() { private boolean doTriggersCreaturesInRoom() {
boolean skip = false; boolean skip = false;
for (String key : game.Rooms.get(currentRoom).creature.keySet()) { for (String key : game.Rooms.get(currentRoom).creature.keySet()) {
ZorkCreature tempCreature = game.Creatures.get(key); skip = skip || doZorkTriggers(game.Creatures.get(key));
for (int x = 0; x < tempCreature.trigger.size(); x++) {
ZorkTrigger tempTrigger = tempCreature.trigger.get(x);
if (tempTrigger.evaluate(this)) {
for (String print: tempTrigger.print) {
System.out.println(print);
}
for (String action: tempTrigger.action) {
executeAction(action);
}
skip = skip || tempTrigger.hasCommand;
if (tempTrigger.type.equals("single")) {
tempCreature.trigger.remove(x);
}
}
}
} }
return skip; return skip;
} }
private boolean doTriggersRoom() { private boolean doTriggersRoom() {
return doZorkTriggers(game.Rooms.get(currentRoom));
}
private boolean doZorkTriggers(ZorkObject zorkObject) {
boolean skip = false; boolean skip = false;
for (int x = 0; x < game.Rooms.get(currentRoom).trigger.size(); x++) { for (int x = 0; x < zorkObject.trigger.size(); x++) {
ZorkTrigger tempTrigger = game.Rooms.get(currentRoom).trigger.get(x); ZorkTrigger tempTrigger = zorkObject.trigger.get(x);
if (tempTrigger.evaluate(this)) { if (tempTrigger.evaluate(this)) {
for (String print: tempTrigger.print) { for (String print: tempTrigger.print) {
System.out.println(print); System.out.println(print);
@ -558,7 +488,7 @@ public class Zork {
} }
skip = skip || tempTrigger.hasCommand; skip = skip || tempTrigger.hasCommand;
if (tempTrigger.type.equals("single")) { if (tempTrigger.type.equals("single")) {
game.Rooms.get(currentRoom).trigger.remove(x); zorkObject.trigger.remove(x);
} }
} }
} }