Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ server:
USE_MAKER_PERMISSIVE_ATKUP: false #Allows players to use attack-based strengthening gems on non-weapon items.
USE_MAKER_FEE_HEURISTICS: true #Apply compiled values for stimulants and reagents into the Maker fee calculations (max error revolves around 50k mesos). Set false to use basic constant values instead (results are never higher than requested by the client-side).

#Custom Configuration
USE_ENABLE_CUSTOM_NPC_SCRIPT: false #Enables usage of custom HeavenMS NPC scripts (Agent E, Coco, etc). Will not disable Abdula (it's actually useful for the gameplay) or quests.
USE_STARTER_MERGE: false #Allows any players to use the Equipment Merge custom mechanic (as opposed to the high-level, Maker lv3 requisites).

#Commands Configuration
BLOCK_GENERATE_CASH_ITEM: false #Prevents creation of cash items with the item/drop command.
USE_WHOLE_SERVER_RANKING: false #Enables a ranking pool made from every character registered on the server for the "ranks" command, instead of separated by worlds.
Expand Down
202 changes: 3 additions & 199 deletions scripts/npc/2042000.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,13 @@ var cpqMaxLvl = 50;
var cpqMinAmt = 2;
var cpqMaxAmt = 6;

// Ronan's custom ore refiner NPC
var refineRocks = true; // enables moon rock, star rock
var refineCrystals = true; // enables common crystals
var refineSpecials = true; // enables lithium, special crystals
var feeMultiplier = 7.0;

function start() {
status = -1;

const YamlConfig = Java.type('config.YamlConfig');
if (!YamlConfig.config.server.USE_CPQ) {
if (YamlConfig.config.server.USE_ENABLE_CUSTOM_NPC_SCRIPT) {
status = 0;
action(1, 0, 4);
} else {
cm.sendOk("The Monster Carnival is currently unavailable.");
cm.dispose();
}

cm.sendOk("The Monster Carnival is currently unavailable.");
cm.dispose();
return;
}

Expand Down Expand Up @@ -239,9 +227,6 @@ function action(mode, type, selection) {
} else {
if (status == 0) {
var talk = "What would you like to do? If you have never participate in the Monster Carnival, you will need to know a few things before participating! \r\n#b#L0# Go to the Monster Carnival 1.#l \r\n#L3# Go to the Monster Carnival 2.#l \r\n#L1# Learn about the Monster Carnival.#l\r\n#L2# Trade #t4001129#.#l";
if (YamlConfig.config.server.USE_ENABLE_CUSTOM_NPC_SCRIPT) {
talk += "\r\n#L4# ... Can I just refine my ores?#l";
}
cm.sendSimple(talk);
} else if (status == 1) {
if (selection == 0) {
Expand Down Expand Up @@ -269,24 +254,6 @@ function action(mode, type, selection) {
cm.warp(980030000, 0);
cm.dispose();

} else if (selection == 4) {
var selStr = "Very well, instead I offer a steadfast #bore refining#k service for you, taxing #r" + ((feeMultiplier * 100) | 0) + "%#k over the usual fee to synthetize them. What will you do?#b";

var options = ["Refine mineral ores", "Refine jewel ores"];
if (refineCrystals) {
options.push("Refine crystal ores");
}
if (refineRocks) {
options.push("Refine plates/jewels");
}

for (var i = 0; i < options.length; i++) {
selStr += "\r\n#L" + i + "# " + options[i] + "#l";
}

cm.sendSimple(selStr);

status = 76;
}
} else if (status == 2) {
select = selection;
Expand Down Expand Up @@ -445,170 +412,7 @@ function action(mode, type, selection) {
} else if (status == 66) {
cm.sendNext("Lastly, while in the Monster Carnival, #byou can not use items / recovery potions that you carry around with you. #kMeanwhile, the monsters let these items fall for good. when, and when you #bget them, the item will immediately activate#k. That's why it's important to know when to get these items.");
cm.dispose();
} else if (status == 77) {
var allDone;

if (selection == 0) {
allDone = refineItems(0); // minerals
} else if (selection == 1) {
allDone = refineItems(1); // jewels
} else if (selection == 2 && refineCrystals) {
allDone = refineItems(2); // crystals
} else if (selection == 2 && !refineCrystals || selection == 3) {
allDone = refineRockItems(); // moon/star rock
}

if (allDone) {
cm.sendOk("Done. Thanks for showing up~.");
} else {
cm.sendOk("Done. Be aware some of the items #rcould not be synthetized#k because either you have a lack of space on your ETC inventory or there's not enough mesos to cover the fee.");
}
cm.dispose();
}
}
}
}

function getRefineFee(fee) {
return ((feeMultiplier * fee) | 0);
}

function isRefineTarget(refineType, refineItemid) {
if (refineType == 0) { //mineral refine
return refineItemid >= 4010000 && refineItemid <= 4010007 && !(refineItemid == 4010007 && !refineSpecials);
} else if (refineType == 1) { //jewel refine
return refineItemid >= 4020000 && refineItemid <= 4020008 && !(refineItemid == 4020008 && !refineSpecials);
} else if (refineType == 2) { //crystal refine
return refineItemid >= 4004000 && refineItemid <= 4004004 && !(refineItemid == 4004004 && !refineSpecials);
}

return false;
}

function getRockRefineTarget(refineItemid) {
if (refineItemid >= 4011000 && refineItemid <= 4011006) {
return 0;
} else if (refineItemid >= 4021000 && refineItemid <= 4021008) {
return 1;
}

return -1;
}

function refineItems(refineType) {
var allDone = true;

var refineFees = [[300, 300, 300, 500, 500, 500, 800, 270], [500, 500, 500, 500, 500, 500, 500, 1000, 3000], [5000, 5000, 5000, 5000, 1000000]];
var itemCount = {};

const InventoryType = Java.type('client.inventory.InventoryType');
var iter = cm.getPlayer().getInventory(InventoryType.ETC).iterator();
while (iter.hasNext()) {
var it = iter.next();
var itemid = it.getItemId();

if (isRefineTarget(refineType, itemid)) {
var ic = itemCount[itemid];

if (ic != undefined) {
itemCount[itemid] += it.getQuantity();
} else {
itemCount[itemid] = it.getQuantity();
}
}
}

for (var key in itemCount) {
var itemqty = itemCount[key];
var itemid = parseInt(key);

var refineQty = ((itemqty / 10) | 0);
if (refineQty <= 0) {
continue;
}

while (true) {
itemqty = refineQty * 10;

var fee = getRefineFee(refineFees[refineType][(itemid % 100) | 0] * refineQty);
if (cm.canHold(itemid + 1000, refineQty, itemid, itemqty) && cm.getMeso() >= fee) {
cm.gainMeso(-fee);
cm.gainItem(itemid, -itemqty);
cm.gainItem(itemid + (itemid != 4010007 ? 1000 : 1001), refineQty);

break;
} else if (refineQty <= 1) {
allDone = false;
break;
} else {
refineQty--;
}
}
}

return allDone;
}

function refineRockItems() {
var allDone = true;
var minItems = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]];
var minRocks = [2147483647, 2147483647];

var rockItems = [4011007, 4021009];
var rockFees = [10000, 15000];

const InventoryType = Java.type('client.inventory.InventoryType');
var iter = cm.getPlayer().getInventory(InventoryType.ETC).iterator();
while (iter.hasNext()) {
var it = iter.next();
var itemid = it.getItemId();
var rockRefine = getRockRefineTarget(itemid);
if (rockRefine >= 0) {
var rockItem = ((itemid % 100) | 0);
var itemqty = it.getQuantity();

minItems[rockRefine][rockItem] += itemqty;
}
}

for (var i = 0; i < minRocks.length; i++) {
for (var j = 0; j < minItems[i].length; j++) {
if (minRocks[i] > minItems[i][j]) {
minRocks[i] = minItems[i][j];
}
}
if (minRocks[i] <= 0 || minRocks[i] == 2147483647) {
continue;
}

var refineQty = minRocks[i];
while (true) {
var fee = getRefineFee(rockFees[i] * refineQty);
if (cm.canHold(rockItems[i], refineQty) && cm.getMeso() >= fee) {
cm.gainMeso(-fee);

var j;
if (i == 0) {
for (j = 4011000; j < 4011007; j++) {
cm.gainItem(j, -refineQty);
}
cm.gainItem(j, refineQty);
} else {
for (j = 4021000; j < 4021009; j++) {
cm.gainItem(j, -refineQty);
}
cm.gainItem(j, refineQty);
}

break;
} else if (refineQty <= 1) {
allDone = false;
break;
} else {
refineQty--;
}
}
}

return allDone;
}
}
Loading