Reformat and clean up npc scripts

This commit is contained in:
P0nk
2021-09-09 23:35:02 +02:00
parent 0c1545f81d
commit d893309b4f
665 changed files with 19932 additions and 19046 deletions

View File

@@ -7,30 +7,30 @@
*/
function clearStage(stage, eim) {
eim.setProperty("stage" + stage + "clear", "true");
eim.showClearEffect(true);
eim.setProperty("stage" + stage + "clear", "true");
eim.showClearEffect(true);
eim.giveEventPlayersStageReward(stage);
eim.giveEventPlayersStageReward(stage);
}
function start() {
if (cm.getPlayer().getMap().getReactorByName("watergate").getState() > 0){
if (cm.getPlayer().getMap().getReactorByName("watergate").getState() > 0) {
cm.sendOk("Excellent work. You may proceed to the next stage.");
cm.dispose();
return;
}
var eim = cm.getPlayer().getEventInstance();
if (eim == null) {
cm.warp(990001100);
cm.warp(990001100);
} else {
if (cm.isEventLeader()) {
if (cm.isEventLeader()) {
var currentCombo = eim.getProperty("stage3combo");
if (currentCombo == null || currentCombo.equals("reset")) {
var newCombo = makeCombo();
eim.setProperty("stage3combo",newCombo);
eim.setProperty("stage3combo", newCombo);
//cm.playerMessage("Debug: " + newCombo);
eim.setProperty("stage3attempt","1");
eim.setProperty("stage3attempt", "1");
cm.sendOk("This fountain guards the secret passage to the throne room. Offer items in the area to the vassals to proceed. The vassals shall tell you whether your offerings are accepted, and if not, which vassals are displeased. You have seven attempts. Good luck.");
} else {
var attempt = parseInt(eim.getProperty("stage3attempt"));
@@ -41,33 +41,36 @@ function start() {
cm.getPlayer().getMap().getReactorByName("watergate").forceHitReactor(1);
clearStage(3, eim);
cm.getGuild().gainGP(25);
removeGroundItems();
cm.sendOk("Excellent work. You may proceed to the next stage.");
} else {
if (attempt < 7) {
var comboItems = [0, 0, 0, 0];
var guessItems = [0, 0, 0, 0];
var correct = 0, incorrect, unknown = 0;
for(var i = 0; i < 4; i++) {
for (var i = 0; i < 4; i++) {
var guessIdx = Math.floor(guess / Math.pow(10, i)) % 10;
var comboIdx = Math.floor(combo / Math.pow(10, i)) % 10;
if(guessIdx == comboIdx) correct++;
else {
if (guessIdx == comboIdx) {
correct++;
} else {
(guessItems[guessIdx])++;
(comboItems[comboIdx])++;
}
}
for(var i = 0; i < 4; i++) {
for (var i = 0; i < 4; i++) {
var diff = guessItems[i] - comboItems[i];
if(diff > 0) unknown += diff;
if (diff > 0) {
unknown += diff;
}
}
incorrect = 4 - correct - unknown;
var string = "";
//cm.playerMessage("Results - Correct: " + results[0] + " | Incorrect: " + results[1] + " | Unknown: " + results[2]);
if (correct != 0) {
@@ -113,10 +116,10 @@ function start() {
spawnMob(9300037, 400, 150, cm.getPlayer().getMap());
cm.sendOk(string);
eim.setProperty("stage3attempt",attempt + 1);
eim.setProperty("stage3attempt", attempt + 1);
} else {
//reset the combo and mass spawn monsters
eim.setProperty("stage3combo","reset");
eim.setProperty("stage3combo", "reset");
cm.sendOk("You have failed the test. Please compose yourselves and try again later.");
for (var i = 0; i < 6; i++) {
@@ -125,7 +128,7 @@ function start() {
spawnMob(9300037, randX(), 150, cm.getPlayer().getMap());
}
}
eim.showWrongEffect();
}
} else {
@@ -136,7 +139,7 @@ function start() {
cm.sendOk("Please have your leader speak to me.");
}
}
cm.dispose();
}
@@ -144,43 +147,45 @@ function action(mode, type, selection) {}
function makeCombo() {
var combo = 0;
for (var i = 0; i < 4; i++) {
combo += (Math.floor(Math.random() * 4) * Math.pow(10, i));
combo += (Math.floor(Math.random() * 4) * Math.pow(10, i));
}
return combo;
}
function getRawItems() {
var mapItems = cm.getPlayer().getMap().getItems();
var rawItems = new Array();
var rawItems = [];
var iter = mapItems.iterator();
while (iter.hasNext()) {
var item = iter.next();
var id = item.getItem().getItemId();
if (id < 4001027 || id > 4001030) {
continue;
} else {
rawItems.push(item);
}
var item = iter.next();
var id = item.getItem().getItemId();
if (id < 4001027 || id > 4001030) {
} else {
rawItems.push(item);
}
}
return rawItems;
}
//check the items on ground and convert into an applicable string; null if items aren't proper
function getGroundItems() {
var itemInArea = new Array(-1, -1, -1, -1);
var itemInArea = [-1, -1, -1, -1];
var rawItems = getRawItems();
if (rawItems.length != 4) return null;
for(var j = 0; j < rawItems.length; j++) {
if (rawItems.length != 4) {
return null;
}
for (var j = 0; j < rawItems.length; j++) {
var item = rawItems[j];
var id = item.getItem().getItemId();
//check item location
for (var i = 0; i < 4; i++) {
if (cm.getPlayer().getMap().getArea(i).contains(item.getPosition())) {
@@ -189,18 +194,19 @@ function getGroundItems() {
}
}
}
//guaranteed four items that are part of the stage 3 item set by this point, check to see if each area has an item
if (itemInArea[0] == -1 || itemInArea[1] == -1 || itemInArea[2] == -1 || itemInArea[3] == -1)
return null;
if (itemInArea[0] == -1 || itemInArea[1] == -1 || itemInArea[2] == -1 || itemInArea[3] == -1) {
return null;
}
return ((itemInArea[0] * 1000) + (itemInArea[1] * 100) + (itemInArea[2] * 10) + itemInArea[3]);
}
function removeGroundItems() {
var map = cm.getMap();
var rawItems = getRawItems();
for(var j = 0; j < rawItems.length; j++) {
for (var j = 0; j < rawItems.length; j++) {
map.makeDisappearItemFromMap(rawItems[j]);
}
}
@@ -213,6 +219,6 @@ function randX() {
function spawnMob(id, x, y, map) {
const LifeFactory = Java.type('server.life.LifeFactory');
const Point = Java.type('java.awt.Point');
var mob = LifeFactory.getMonster(id);
map.spawnMonsterOnGroundBelow(mob, new Point(x, y));
var mob = LifeFactory.getMonster(id);
map.spawnMonsterOnGroundBelow(mob, new Point(x, y));
}