|
@@ -7,6 +7,7 @@ module.exports = function boxOpener(dispatch) {
|
|
|
enabled = false,
|
|
enabled = false,
|
|
|
boxEvent = null,
|
|
boxEvent = null,
|
|
|
gacha_detected = false,
|
|
gacha_detected = false,
|
|
|
|
|
+ gacha_contract = 0,
|
|
|
isLooting = false,
|
|
isLooting = false,
|
|
|
location = null,
|
|
location = null,
|
|
|
timer = null,
|
|
timer = null,
|
|
@@ -53,6 +54,7 @@ module.exports = function boxOpener(dispatch) {
|
|
|
|
|
|
|
|
function load() {
|
|
function load() {
|
|
|
hook("C_USE_ITEM", 3, event => {
|
|
hook("C_USE_ITEM", 3, event => {
|
|
|
|
|
+ if (gacha_detected) return false;
|
|
|
if (!scanning) return;
|
|
if (!scanning) return;
|
|
|
|
|
|
|
|
if (scanning) {
|
|
if (scanning) {
|
|
@@ -64,15 +66,13 @@ module.exports = function boxOpener(dispatch) {
|
|
|
const d = new Date();
|
|
const d = new Date();
|
|
|
statStarted = d.getTime();
|
|
statStarted = d.getTime();
|
|
|
enabled = true;
|
|
enabled = true;
|
|
|
- timer = setTimeout(openBox, delay);
|
|
|
|
|
- return true; // for consistency of sent data
|
|
|
|
|
|
|
+ timer = dispatch.setTimeout(openBox, delay);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- hook("S_SYSTEM_MESSAGE_LOOT_ITEM", 1, event => {
|
|
|
|
|
|
|
+ hook("S_SYSTEM_MESSAGE_LOOT_ITEM", "raw", () => {
|
|
|
if (!gacha_detected && !isLooting && boxEvent) {
|
|
if (!gacha_detected && !isLooting && boxEvent) {
|
|
|
isLooting = true;
|
|
isLooting = true;
|
|
|
- statOpened++;
|
|
|
|
|
if (!useDelay) {
|
|
if (!useDelay) {
|
|
|
dispatch.clearTimeout(timer);
|
|
dispatch.clearTimeout(timer);
|
|
|
openBox();
|
|
openBox();
|
|
@@ -80,41 +80,81 @@ module.exports = function boxOpener(dispatch) {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- hook("S_GACHA_END", 1, () => {
|
|
|
|
|
- if (boxEvent) {
|
|
|
|
|
- statOpened++;
|
|
|
|
|
- if (!useDelay) {
|
|
|
|
|
- clearTimeout(timer);
|
|
|
|
|
- openBox();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ hook("S_GACHA_END", "raw", () => {
|
|
|
|
|
+ if (boxEvent && gacha_detected) {
|
|
|
|
|
+ dispatch.clearTimeout(timer);
|
|
|
|
|
+ if (useDelay) timer = dispatch.setTimeout(openBox, delay);
|
|
|
|
|
+ else process.nextTick(openBox);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
hook("S_SYSTEM_MESSAGE", 1, event => {
|
|
hook("S_SYSTEM_MESSAGE", 1, event => {
|
|
|
- const msg = dispatch.parseSystemMessage(event.message);
|
|
|
|
|
- if (msg.id === "SMT_ITEM_MIX_NEED_METERIAL" || msg.id === "SMT_CANT_CONVERT_NOW") {
|
|
|
|
|
|
|
+ const msg = dispatch.parseSystemMessage(event.message).id;
|
|
|
|
|
+ if (["SMT_ITEM_MIX_NEED_METERIAL", "SMT_CANT_CONVERT_NOW", "SMT_GACHA_NO_MORE_ITEM_SHORT", "SMT_NOTI_LEFT_LIMITED_GACHA_ITEM", "SMT_GACHA_CANCEL", "SMT_COMMON_NO_MORE_ITEM_TO_USE"].includes(msg)) {
|
|
|
command.message("Box can not be opened anymore, stopping");
|
|
command.message("Box can not be opened anymore, stopping");
|
|
|
stop();
|
|
stop();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- hook("S_GACHA_START", 1, event => {
|
|
|
|
|
- gacha_detected = true;
|
|
|
|
|
- dispatch.send("C_GACHA_TRY", 1, {
|
|
|
|
|
- "id": event.id
|
|
|
|
|
|
|
+ if (dispatch.majorPatchVersion >= 93) {
|
|
|
|
|
+ hook("S_REQUEST_CONTRACT", dispatch.majorPatchVersion > 107 ? 2 : 1, event => {
|
|
|
|
|
+ if (event.type !== 53) return;
|
|
|
|
|
+ dispatch.hookOnce("S_GACHA_START", "raw", () => {
|
|
|
|
|
+ gacha_detected = true;
|
|
|
|
|
+ gacha_contract = event.id;
|
|
|
|
|
+ openBox();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
|
|
+ return false;
|
|
|
});
|
|
});
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ hook("S_CANCEL_CONTRACT", 1, event => {
|
|
|
|
|
+ if (!gacha_detected || event.type !== 53) return;
|
|
|
|
|
+ gacha_contract = 0;
|
|
|
|
|
+ stop();
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ hook("S_GACHA_START", 1, event => {
|
|
|
|
|
+ gacha_detected = true;
|
|
|
|
|
+ dispatch.send("C_GACHA_TRY", 1, {
|
|
|
|
|
+ "id": event.id
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function openBox() {
|
|
function openBox() {
|
|
|
if (dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0) {
|
|
if (dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0) {
|
|
|
- boxEvent.loc = location.loc;
|
|
|
|
|
- boxEvent.w = location.w;
|
|
|
|
|
- dispatch.send("C_USE_ITEM", 3, boxEvent);
|
|
|
|
|
- if (useDelay) {
|
|
|
|
|
- statUsed++; // counter for used items other than boxes
|
|
|
|
|
|
|
+ if (dispatch.majorPatchVersion >= 93) {
|
|
|
|
|
+ if (gacha_detected) {
|
|
|
|
|
+ if (dispatch.majorPatchVersion >= 99) {
|
|
|
|
|
+ dispatch.toServer("C_GACHA_TRY", 2, {
|
|
|
|
|
+ id: gacha_contract,
|
|
|
|
|
+ amount: 1
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dispatch.toServer("C_GACHA_TRY", 1, {
|
|
|
|
|
+ id: gacha_contract
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ boxEvent.loc = location.loc;
|
|
|
|
|
+ boxEvent.w = location.w;
|
|
|
|
|
+ dispatch.toServer("C_USE_ITEM", 3, boxEvent);
|
|
|
|
|
+ if (useDelay) {
|
|
|
|
|
+ statUsed++; // counter for used items other than boxes
|
|
|
|
|
+ }
|
|
|
|
|
+ timer = dispatch.setTimeout(openBox, delay);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ boxEvent.loc = location.loc;
|
|
|
|
|
+ boxEvent.w = location.w;
|
|
|
|
|
+ dispatch.send("C_USE_ITEM", 3, boxEvent);
|
|
|
|
|
+ if (useDelay) {
|
|
|
|
|
+ statUsed++; // counter for used items other than boxes
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- timer = setTimeout(openBox, delay);
|
|
|
|
|
|
|
+ statOpened++;
|
|
|
} else {
|
|
} else {
|
|
|
command.message("You ran out of boxes, stopping");
|
|
command.message("You ran out of boxes, stopping");
|
|
|
stop();
|
|
stop();
|
|
@@ -134,13 +174,14 @@ module.exports = function boxOpener(dispatch) {
|
|
|
scanning = false;
|
|
scanning = false;
|
|
|
command.message("Scanning for a box is aborted");
|
|
command.message("Scanning for a box is aborted");
|
|
|
} else {
|
|
} else {
|
|
|
- clearTimeout(timer);
|
|
|
|
|
|
|
+ if (gacha_detected && gacha_contract) dispatch.toServer("C_GACHA_CANCEL", 1, { id: gacha_contract });
|
|
|
|
|
+ if (useDelay && statOpened === 0) statOpened = statUsed;
|
|
|
|
|
+ if (!gacha_detected) statOpened += 1; // Add the box we used at start if not gacha.
|
|
|
|
|
+ dispatch.clearTimeout(timer);
|
|
|
enabled = false;
|
|
enabled = false;
|
|
|
gacha_detected = false;
|
|
gacha_detected = false;
|
|
|
|
|
+ gacha_contract = 0;
|
|
|
boxEvent = null;
|
|
boxEvent = null;
|
|
|
- if (useDelay && statOpened == 0) {
|
|
|
|
|
- statOpened = statUsed;
|
|
|
|
|
- }
|
|
|
|
|
let d = new Date();
|
|
let d = new Date();
|
|
|
const t = d.getTime();
|
|
const t = d.getTime();
|
|
|
const timeElapsedMSec = t - statStarted;
|
|
const timeElapsedMSec = t - statStarted;
|