Reformat and clean up npc scripts
This commit is contained in:
@@ -23,7 +23,7 @@
|
||||
* @npc: Vending Machine
|
||||
* @map: 193000000 - Premium Road - Kerning City Internet Cafe
|
||||
* @func: Cafe PQ Rewarder
|
||||
*/
|
||||
*/
|
||||
|
||||
var status;
|
||||
|
||||
@@ -58,100 +58,116 @@ var curItemSel;
|
||||
var advance = true;
|
||||
|
||||
function start() {
|
||||
status = -1;
|
||||
action(1, 0, 0);
|
||||
status = -1;
|
||||
action(1, 0, 0);
|
||||
}
|
||||
|
||||
function action(mode, type, selection) {
|
||||
if (mode == -1) {
|
||||
cm.dispose();
|
||||
} else {
|
||||
if (mode == 0 && type > 0) {
|
||||
cm.dispose();
|
||||
return;
|
||||
}
|
||||
if (mode == 1 && advance)
|
||||
status++;
|
||||
else
|
||||
status--;
|
||||
|
||||
advance = true;
|
||||
|
||||
if(status == 0) {
|
||||
hasCoin = cm.haveItem(coinId);
|
||||
cm.sendNext("This is the vending machine of the Internet Cafe. Place your erasers or #t" + coinId + "# earned throughout the quests to redeem a prize. You can place #bany amount of erasers#k, however take note that placing #rdifferent erasers#k and #rbigger shots of any of them#k will improve the reward possibilities!");
|
||||
} else if(status == 1) {
|
||||
var sendStr;
|
||||
currentTier = getRewardTier();
|
||||
|
||||
if(currentTier >= 0) sendStr = "With the items you have currently placed, you can retrieve a #r" + levels[currentTier] + "#k prize. Place erasers:";
|
||||
else sendStr = "You have placed no erasers yet. Place erasers:";
|
||||
|
||||
var listStr = "";
|
||||
for(var i = 0; i < tickets.length; i++) {
|
||||
listStr += "#b#L" + i + "##t" + (4001009 + i) + "##k";
|
||||
if(tickets[i] > 0) listStr += " - " + tickets[i] + " erasers";
|
||||
listStr += "#l\r\n";
|
||||
}
|
||||
if(hasCoin) {
|
||||
listStr += "#b#L" + tickets.length + "##t" + coinId + "##k";
|
||||
if(coins > 0) listStr += " - " + coins + " feathers";
|
||||
listStr += "#l\r\n";
|
||||
}
|
||||
|
||||
cm.sendSimple(sendStr + "\r\n\r\n" + listStr + "#r#L" + getRewardIndex(hasCoin) + "#Retrieve a prize!#l#k\r\n");
|
||||
|
||||
} else if(status == 2) {
|
||||
if(selection == getRewardIndex(hasCoin)) {
|
||||
if(currentTier < 0) {
|
||||
cm.sendPrev("You have set no erasers. Insert at least one to claim a prize.");
|
||||
advance = false;
|
||||
} else {
|
||||
givePrize();
|
||||
cm.dispose();
|
||||
}
|
||||
} else {
|
||||
var tickSel;
|
||||
if(selection < tickets.length) tickSel = 4001009 + selection;
|
||||
else tickSel = coinId;
|
||||
|
||||
curItemQty = cm.getItemQuantity(tickSel);
|
||||
curItemSel = selection;
|
||||
|
||||
if(curItemQty > 0) {
|
||||
cm.sendGetText("How many of #b#t" + tickSel + "##k do you want to insert on the machine? (#r" + curItemQty + "#k available)#k");
|
||||
} else {
|
||||
cm.sendPrev("You have got #rnone#k of #b#t" + tickSel + "##k to insert on the machine. Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
}
|
||||
}
|
||||
} else if(status == 3) {
|
||||
var text = cm.getText();
|
||||
|
||||
try {
|
||||
var placedQty = parseInt(text);
|
||||
if(isNaN(placedQty) || placedQty < 0) throw true;
|
||||
|
||||
if(placedQty > curItemQty) {
|
||||
cm.sendPrev("You cannot insert the given amount of erasers (#r" + curItemQty + "#k available). Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
} else {
|
||||
if(curItemSel < tickets.length) tickets[curItemSel] = placedQty;
|
||||
else coins = placedQty;
|
||||
|
||||
cm.sendPrev("Operation succeeded. Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
}
|
||||
} catch(err) {
|
||||
cm.sendPrev("You must enter a positive number of erasers to insert. Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
}
|
||||
|
||||
status = 2;
|
||||
} else {
|
||||
cm.dispose();
|
||||
}
|
||||
if (mode == -1) {
|
||||
cm.dispose();
|
||||
} else {
|
||||
if (mode == 0 && type > 0) {
|
||||
cm.dispose();
|
||||
return;
|
||||
}
|
||||
if (mode == 1 && advance) {
|
||||
status++;
|
||||
} else {
|
||||
status--;
|
||||
}
|
||||
|
||||
advance = true;
|
||||
|
||||
if (status == 0) {
|
||||
hasCoin = cm.haveItem(coinId);
|
||||
cm.sendNext("This is the vending machine of the Internet Cafe. Place your erasers or #t" + coinId + "# earned throughout the quests to redeem a prize. You can place #bany amount of erasers#k, however take note that placing #rdifferent erasers#k and #rbigger shots of any of them#k will improve the reward possibilities!");
|
||||
} else if (status == 1) {
|
||||
var sendStr;
|
||||
currentTier = getRewardTier();
|
||||
|
||||
if (currentTier >= 0) {
|
||||
sendStr = "With the items you have currently placed, you can retrieve a #r" + levels[currentTier] + "#k prize. Place erasers:";
|
||||
} else {
|
||||
sendStr = "You have placed no erasers yet. Place erasers:";
|
||||
}
|
||||
|
||||
var listStr = "";
|
||||
for (var i = 0; i < tickets.length; i++) {
|
||||
listStr += "#b#L" + i + "##t" + (4001009 + i) + "##k";
|
||||
if (tickets[i] > 0) {
|
||||
listStr += " - " + tickets[i] + " erasers";
|
||||
}
|
||||
listStr += "#l\r\n";
|
||||
}
|
||||
if (hasCoin) {
|
||||
listStr += "#b#L" + tickets.length + "##t" + coinId + "##k";
|
||||
if (coins > 0) {
|
||||
listStr += " - " + coins + " feathers";
|
||||
}
|
||||
listStr += "#l\r\n";
|
||||
}
|
||||
|
||||
cm.sendSimple(sendStr + "\r\n\r\n" + listStr + "#r#L" + getRewardIndex(hasCoin) + "#Retrieve a prize!#l#k\r\n");
|
||||
|
||||
} else if (status == 2) {
|
||||
if (selection == getRewardIndex(hasCoin)) {
|
||||
if (currentTier < 0) {
|
||||
cm.sendPrev("You have set no erasers. Insert at least one to claim a prize.");
|
||||
advance = false;
|
||||
} else {
|
||||
givePrize();
|
||||
cm.dispose();
|
||||
}
|
||||
} else {
|
||||
var tickSel;
|
||||
if (selection < tickets.length) {
|
||||
tickSel = 4001009 + selection;
|
||||
} else {
|
||||
tickSel = coinId;
|
||||
}
|
||||
|
||||
curItemQty = cm.getItemQuantity(tickSel);
|
||||
curItemSel = selection;
|
||||
|
||||
if (curItemQty > 0) {
|
||||
cm.sendGetText("How many of #b#t" + tickSel + "##k do you want to insert on the machine? (#r" + curItemQty + "#k available)#k");
|
||||
} else {
|
||||
cm.sendPrev("You have got #rnone#k of #b#t" + tickSel + "##k to insert on the machine. Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
}
|
||||
}
|
||||
} else if (status == 3) {
|
||||
var text = cm.getText();
|
||||
|
||||
try {
|
||||
var placedQty = parseInt(text);
|
||||
if (isNaN(placedQty) || placedQty < 0) {
|
||||
throw true;
|
||||
}
|
||||
|
||||
if (placedQty > curItemQty) {
|
||||
cm.sendPrev("You cannot insert the given amount of erasers (#r" + curItemQty + "#k available). Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
} else {
|
||||
if (curItemSel < tickets.length) {
|
||||
tickets[curItemSel] = placedQty;
|
||||
} else {
|
||||
coins = placedQty;
|
||||
}
|
||||
|
||||
cm.sendPrev("Operation succeeded. Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
}
|
||||
} catch (err) {
|
||||
cm.sendPrev("You must enter a positive number of erasers to insert. Click '#rBack#k' to return to the main interface.");
|
||||
advance = false;
|
||||
}
|
||||
|
||||
status = 2;
|
||||
} else {
|
||||
cm.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getRewardIndex(hasCoin) {
|
||||
@@ -160,77 +176,87 @@ function getRewardIndex(hasCoin) {
|
||||
|
||||
function getRewardTier() {
|
||||
var points = getPoints();
|
||||
|
||||
if(points <= 6) {
|
||||
if(points <= 0) return -1;
|
||||
else return 0;
|
||||
|
||||
if (points <= 6) {
|
||||
if (points <= 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(points >= 46) return 5;
|
||||
|
||||
if (points >= 46) {
|
||||
return 5;
|
||||
}
|
||||
|
||||
return Math.floor((points - 6) / 8);
|
||||
}
|
||||
|
||||
function getPoints() {
|
||||
var points = 0;
|
||||
|
||||
for(var i = 0; i < tickets.length; i++) {
|
||||
if(tickets[i] <= 0) continue;
|
||||
|
||||
|
||||
for (var i = 0; i < tickets.length; i++) {
|
||||
if (tickets[i] <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
points += (6 + ((tickets[i] - 1) * getTicketMultiplier(i))); //6 from uniques + rest from each ticket difficulty
|
||||
}
|
||||
points += Math.ceil(0.46 * coins); // 100 coins for a LV6 tier item.
|
||||
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
function getTicketMultiplier(ticket) {
|
||||
if(ticket == 1 || ticket == 3) return 3;
|
||||
else return 1;
|
||||
if (ticket == 1 || ticket == 3) {
|
||||
return 3;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
function givePrize() {
|
||||
var lvTarget, lvQty;
|
||||
|
||||
if(currentTier == 0) {
|
||||
lvTarget = itemSet_lv1;
|
||||
lvQty = itemQty_lv1;
|
||||
} else if(currentTier == 1) {
|
||||
lvTarget = itemSet_lv2;
|
||||
lvQty = itemQty_lv2;
|
||||
} else if(currentTier == 2) {
|
||||
lvTarget = itemSet_lv3;
|
||||
lvQty = itemQty_lv3;
|
||||
} else if(currentTier == 3) {
|
||||
lvTarget = itemSet_lv4;
|
||||
lvQty = itemQty_lv4;
|
||||
} else if(currentTier == 4) {
|
||||
lvTarget = itemSet_lv5;
|
||||
lvQty = itemQty_lv5;
|
||||
} else {
|
||||
lvTarget = itemSet_lv6;
|
||||
lvQty = itemQty_lv6;
|
||||
}
|
||||
|
||||
if(!hasRewardSlot(lvTarget, lvQty)) {
|
||||
cm.sendOk("Check for an available space on your inventory before retrieving a prize.");
|
||||
} else {
|
||||
var rnd = Math.floor(Math.random() * lvTarget.length);
|
||||
|
||||
for(var i = 0; i < tickets.length; i++) {
|
||||
cm.gainItem(4001009 + i, -1 * tickets[i]);
|
||||
}
|
||||
cm.gainItem(coinId, -1 * coins);
|
||||
|
||||
cm.gainItem(lvTarget[rnd], lvQty[rnd]);
|
||||
var lvTarget, lvQty;
|
||||
|
||||
if (currentTier == 0) {
|
||||
lvTarget = itemSet_lv1;
|
||||
lvQty = itemQty_lv1;
|
||||
} else if (currentTier == 1) {
|
||||
lvTarget = itemSet_lv2;
|
||||
lvQty = itemQty_lv2;
|
||||
} else if (currentTier == 2) {
|
||||
lvTarget = itemSet_lv3;
|
||||
lvQty = itemQty_lv3;
|
||||
} else if (currentTier == 3) {
|
||||
lvTarget = itemSet_lv4;
|
||||
lvQty = itemQty_lv4;
|
||||
} else if (currentTier == 4) {
|
||||
lvTarget = itemSet_lv5;
|
||||
lvQty = itemQty_lv5;
|
||||
} else {
|
||||
lvTarget = itemSet_lv6;
|
||||
lvQty = itemQty_lv6;
|
||||
}
|
||||
|
||||
if (!hasRewardSlot(lvTarget, lvQty)) {
|
||||
cm.sendOk("Check for an available space on your inventory before retrieving a prize.");
|
||||
} else {
|
||||
var rnd = Math.floor(Math.random() * lvTarget.length);
|
||||
|
||||
for (var i = 0; i < tickets.length; i++) {
|
||||
cm.gainItem(4001009 + i, -1 * tickets[i]);
|
||||
}
|
||||
cm.gainItem(coinId, -1 * coins);
|
||||
|
||||
cm.gainItem(lvTarget[rnd], lvQty[rnd]);
|
||||
}
|
||||
}
|
||||
|
||||
function hasRewardSlot(lvTarget, lvQty) {
|
||||
for(var i = 0; i < lvTarget.length; i++) {
|
||||
if(!cm.canHold(lvTarget[i], lvQty[i])) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < lvTarget.length; i++) {
|
||||
if (!cm.canHold(lvTarget[i], lvQty[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user