|
@@ -1,5 +1,7 @@
|
|
|
'use strict'
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
+// ~~~ * Data * ~~~ \\
|
|
|
|
|
+
|
|
|
const fs = require('fs'),
|
|
const fs = require('fs'),
|
|
|
fn = __dirname + '/blacklist.json',
|
|
fn = __dirname + '/blacklist.json',
|
|
|
defaultBl = [112, 114, 116, 194, 130, 444, 6552, 6553, 6562, 6563, 9310, 9311, 60260, 70000, 80081, 80095, 81209, 150532, 150533, 150534, 150535, 150542, 151643, 155324, 160322, 167001, 177131, 177132, 177133, 200529, 200922, 200999, 201957, 201958, 202015, 206049, 206050, 206051]
|
|
defaultBl = [112, 114, 116, 194, 130, 444, 6552, 6553, 6562, 6563, 9310, 9311, 60260, 70000, 80081, 80095, 81209, 150532, 150533, 150534, 150535, 150542, 151643, 155324, 160322, 167001, 177131, 177132, 177133, 200529, 200922, 200999, 201957, 201958, 202015, 206049, 206050, 206051]
|
|
@@ -12,20 +14,24 @@ ReadFile()
|
|
|
if (fs.existsSync(fn)) fs.watch(fn, event => { if (event === 'change') ReadFile() })
|
|
if (fs.existsSync(fn)) fs.watch(fn, event => { if (event === 'change') ReadFile() })
|
|
|
|
|
|
|
|
module.exports = function AutoBank(mod) {
|
|
module.exports = function AutoBank(mod) {
|
|
|
|
|
+
|
|
|
|
|
+ // ~~~ * Constants * ~~~ \\
|
|
|
|
|
+
|
|
|
const NotCP = typeof mod.compileProto !== 'undefined'
|
|
const NotCP = typeof mod.compileProto !== 'undefined'
|
|
|
- const defs = { cPutWareItem: 3, sViewWareEx: mod.majorPatchVersion < 96 ? 2 : 3 }
|
|
|
|
|
|
|
+ const defs = { cPutWareItem: 3, sViewWareEx: 3 }
|
|
|
|
|
|
|
|
if (NotCP) {
|
|
if (NotCP) {
|
|
|
defs.cPutWareItem = mod.compileProto('uint64 gameId\nint32 container\nint32 offset\nint64 money\nint32 fromPocket\nint32 fromSlot\nint32 id\nuint64 dbid\nint32 amount\nint32 toSlot')
|
|
defs.cPutWareItem = mod.compileProto('uint64 gameId\nint32 container\nint32 offset\nint64 money\nint32 fromPocket\nint32 fromSlot\nint32 id\nuint64 dbid\nint32 amount\nint32 toSlot')
|
|
|
defs.sViewWareEx = mod.compileProto('array items\n- array<int32> crystals\n- int32 id\n- uint64 dbid\n- uint64 ownerId\n- int32 container\n- int32 pocket\n- uint32 slot\n- int32 amountTotal\n- int32 amount\n- int32 enchant\n- int32 durability\n- bool soulbound\n- uint32 unk\n- bool masterwork\n- int32 enigma\n- int32 enchantAdvantage\n- int32 enchantBonus\n- int32 enchantBonusMaxPlus\n- bool awakened\n- int32 liberationStatus\n- int64 availableUntil ^96\nuint64 gameId\nint32 container\nint32 action\nint32 offset\nint32 maxUsedSlot\nint32 numUsedSlots\nint64 money\nint16 numUnlockedSlots')
|
|
defs.sViewWareEx = mod.compileProto('array items\n- array<int32> crystals\n- int32 id\n- uint64 dbid\n- uint64 ownerId\n- int32 container\n- int32 pocket\n- uint32 slot\n- int32 amountTotal\n- int32 amount\n- int32 enchant\n- int32 durability\n- bool soulbound\n- uint32 unk\n- bool masterwork\n- int32 enigma\n- int32 enchantAdvantage\n- int32 enchantBonus\n- int32 enchantBonusMaxPlus\n- bool awakened\n- int32 liberationStatus\n- int64 availableUntil ^96\nuint64 gameId\nint32 container\nint32 action\nint32 offset\nint32 maxUsedSlot\nint32 numUsedSlots\nint64 money\nint16 numUnlockedSlots')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ** Initialize dependency ** \\
|
|
|
|
|
|
|
+ // ~~~ * Initialize dependency * ~~~ \\
|
|
|
|
|
+
|
|
|
mod.game.initialize('inventory')
|
|
mod.game.initialize('inventory')
|
|
|
|
|
|
|
|
- // ** Variables ** \\
|
|
|
|
|
|
|
+ // ~~~ * Variables * ~~~ \\
|
|
|
|
|
|
|
|
- let enabled = false,
|
|
|
|
|
|
|
+ let Enabled = false,
|
|
|
GuildBanking = false,
|
|
GuildBanking = false,
|
|
|
AddToBl = false,
|
|
AddToBl = false,
|
|
|
RmvFromBl = false,
|
|
RmvFromBl = false,
|
|
@@ -35,10 +41,10 @@ module.exports = function AutoBank(mod) {
|
|
|
QueuedDups = new Map(),
|
|
QueuedDups = new Map(),
|
|
|
AllCurBankItems = new Map()
|
|
AllCurBankItems = new Map()
|
|
|
|
|
|
|
|
- // ** Hook Functions ** \\
|
|
|
|
|
|
|
+ // ~~~ * Hook Functions * ~~~ \\
|
|
|
|
|
|
|
|
function sViewWareEx(event) {
|
|
function sViewWareEx(event) {
|
|
|
- if (!enabled) return
|
|
|
|
|
|
|
+ if (!Enabled) return
|
|
|
if (lastBankedPageOffset >= event.offset) return false
|
|
if (lastBankedPageOffset >= event.offset) return false
|
|
|
if (!GuildBanking && event.container === 3) return Msg('Banking to guild bank is <font color="#FE6F5E">disabled</font>.')
|
|
if (!GuildBanking && event.container === 3) return Msg('Banking to guild bank is <font color="#FE6F5E">disabled</font>.')
|
|
|
let toBankItems = []
|
|
let toBankItems = []
|
|
@@ -64,7 +70,7 @@ module.exports = function AutoBank(mod) {
|
|
|
mod.toServer('C_PUT_WARE_ITEM', defs.cPutWareItem, { gameId: mod.game.me.gameId, container: event.container, offset: event.offset, fromPocket: toBank.pocket, fromSlot: toBank.slot, id: toBank.id, dbid: toBank.dbid, amount: toBank.amount, toSlot: event.offset })
|
|
mod.toServer('C_PUT_WARE_ITEM', defs.cPutWareItem, { gameId: mod.game.me.gameId, container: event.container, offset: event.offset, fromPocket: toBank.pocket, fromSlot: toBank.slot, id: toBank.id, dbid: toBank.dbid, amount: toBank.amount, toSlot: event.offset })
|
|
|
}
|
|
}
|
|
|
mod.setTimeout(() => {
|
|
mod.setTimeout(() => {
|
|
|
- if (!enabled) return
|
|
|
|
|
|
|
+ if (!Enabled) return
|
|
|
if (event.offset + 72 < event.numUnlockedSlots) mod.toServer('C_VIEW_WARE', 2, { gameId: mod.game.me.gameId, type: event.container, offset: event.offset + 72 })
|
|
if (event.offset + 72 < event.numUnlockedSlots) mod.toServer('C_VIEW_WARE', 2, { gameId: mod.game.me.gameId, type: event.container, offset: event.offset + 72 })
|
|
|
else mod.toServer('C_CANCEL_CONTRACT', 1, { type: 26, id: curBankContractId })
|
|
else mod.toServer('C_CANCEL_CONTRACT', 1, { type: 26, id: curBankContractId })
|
|
|
}, toBankItems.length * 47 + 150)
|
|
}, toBankItems.length * 47 + 150)
|
|
@@ -88,7 +94,7 @@ module.exports = function AutoBank(mod) {
|
|
|
}
|
|
}
|
|
|
//function sSytemMessage(event) { if (enabled && mod.parseSystemMessage(event.message).id === 'SMT_WAREHOUSE_FULL') return false }
|
|
//function sSytemMessage(event) { if (enabled && mod.parseSystemMessage(event.message).id === 'SMT_WAREHOUSE_FULL') return false }
|
|
|
|
|
|
|
|
- // ** Hooks ** \\
|
|
|
|
|
|
|
+ // ~~~ * Hooks * ~~~ \\
|
|
|
|
|
|
|
|
mod.hook('S_VIEW_WARE_EX', defs.sViewWareEx, sViewWareEx)
|
|
mod.hook('S_VIEW_WARE_EX', defs.sViewWareEx, sViewWareEx)
|
|
|
mod.hook('C_PUT_WARE_ITEM', defs.cPutWareItem, cPutWareItem)
|
|
mod.hook('C_PUT_WARE_ITEM', defs.cPutWareItem, cPutWareItem)
|
|
@@ -96,7 +102,7 @@ module.exports = function AutoBank(mod) {
|
|
|
mod.hook('S_CANCEL_CONTRACT', 1, sCancelContract)
|
|
mod.hook('S_CANCEL_CONTRACT', 1, sCancelContract)
|
|
|
//mod.hook('S_SYSTEM_MESSAGE', 1, sSytemMessage)
|
|
//mod.hook('S_SYSTEM_MESSAGE', 1, sSytemMessage)
|
|
|
|
|
|
|
|
- // ** Helper Functions ** \\
|
|
|
|
|
|
|
+ // ~~~ * Helper Functions * ~~~ \\
|
|
|
|
|
|
|
|
function toUniqueDbidArr(a, b, c = {}) {
|
|
function toUniqueDbidArr(a, b, c = {}) {
|
|
|
b = a.length
|
|
b = a.length
|
|
@@ -108,8 +114,15 @@ module.exports = function AutoBank(mod) {
|
|
|
function remvBlacklisted(a, b, c = []) {
|
|
function remvBlacklisted(a, b, c = []) {
|
|
|
b = a.length
|
|
b = a.length
|
|
|
if (!b) return c
|
|
if (!b) return c
|
|
|
- while (b--)
|
|
|
|
|
- if (blacklist.indexOf(a[b].id) === -1) c.push(a[b])
|
|
|
|
|
|
|
+ while (b--) {
|
|
|
|
|
+ const el = a[b]
|
|
|
|
|
+ if (el.pocket !== 0) {
|
|
|
|
|
+ if (blacklist.indexOf('pocket1') !== -1 && el.pocket === 1) continue
|
|
|
|
|
+ if (blacklist.indexOf('pocket2') !== -1 && el.pocket === 2) continue
|
|
|
|
|
+ if (blacklist.indexOf('pocket3') !== -1 && el.pocket === 3) continue
|
|
|
|
|
+ }
|
|
|
|
|
+ if (blacklist.indexOf(el.id) === -1) c.push(el)
|
|
|
|
|
+ }
|
|
|
return c
|
|
return c
|
|
|
}
|
|
}
|
|
|
function getLine(n, m = 1) {
|
|
function getLine(n, m = 1) {
|
|
@@ -122,13 +135,21 @@ module.exports = function AutoBank(mod) {
|
|
|
return `${a / 72 + 1}:${getLine(s)}:${s % 8 || 8}`
|
|
return `${a / 72 + 1}:${getLine(s)}:${s % 8 || 8}`
|
|
|
}
|
|
}
|
|
|
function convToCLA(id) {
|
|
function convToCLA(id) {
|
|
|
- return `<font color="#7289DA"><ChatLinkAction param="1#####${id}"><Click Me></ChatLinkAction></font>`
|
|
|
|
|
|
|
+ return typeof id === 'string' ? id : `item <font color="#7289DA"><ChatLinkAction param="1#####${id}"><Click Me></ChatLinkAction></font>`
|
|
|
}
|
|
}
|
|
|
function validIdOrCLA(str, res = []) {
|
|
function validIdOrCLA(str, res = []) {
|
|
|
- const [...match] = str.matchAll(/<ChatLinkAction.+?1#####([0-9]+).*?<\/ChatLinkAction>|(^[0-9]+|\s[0-9]+|[0-9]+\s)/gm)
|
|
|
|
|
- for (const m of match) res.push(Number.parseInt(m[1] || m[2]))
|
|
|
|
|
|
|
+ //Match if <ChatLinkAction> OR <start or space>Id<space or end> OR <start or space>pocket<1 or 2 or 3><space or end>.
|
|
|
|
|
+ const [...match] = str.matchAll(/<ChatLinkAction.+?1#####([0-9]+).*?<\/ChatLinkAction>|(\b(?:(?<=\s)|^)[0-9]+(?:(?=\s)|$)\b)|(\b(?:(?<=\s)|^)pocket[1-3](?:(?=\s)|$)\b)/gi)
|
|
|
|
|
+ for (const m of match) res.push(Number.parseInt(m[1] || m[2]) || m[3]?.toLowerCase())
|
|
|
return res
|
|
return res
|
|
|
}
|
|
}
|
|
|
|
|
+ function sortStrNum(arr) {
|
|
|
|
|
+ arr.sort((a, b) => typeof a === 'string' ? -1 : a - b)
|
|
|
|
|
+ arr.sort((a, b) => typeof a === 'string' && typeof b === 'string' ? a.slice(-1) - b.slice(-1) : 0)
|
|
|
|
|
+ return arr
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ~~~ * Command Functions * ~~~ \\
|
|
|
|
|
|
|
|
const Msg = msg => mod.command.message(`${NotCP ? '[Auto-Bank]' : ''} ${msg}`),
|
|
const Msg = msg => mod.command.message(`${NotCP ? '[Auto-Bank]' : ''} ${msg}`),
|
|
|
resetValues = () => {
|
|
resetValues = () => {
|
|
@@ -142,13 +163,13 @@ module.exports = function AutoBank(mod) {
|
|
|
Msg(`- ${d.count}x${d.link} | (${d.details1}) & (${d.details2})`)
|
|
Msg(`- ${d.count}x${d.link} | (${d.details1}) & (${d.details2})`)
|
|
|
else Msg(`Over 50 items; won't be listed to prevent spam.`)
|
|
else Msg(`Over 50 items; won't be listed to prevent spam.`)
|
|
|
}
|
|
}
|
|
|
- if (enabled) Msg('Auto Banking is <font color="#FE6F5E">disabled</font>.')
|
|
|
|
|
- enabled = false
|
|
|
|
|
|
|
+ if (Enabled) Msg('Auto Banking is <font color="#FE6F5E">disabled</font>.')
|
|
|
|
|
+ Enabled = false
|
|
|
QueuedDups.clear()
|
|
QueuedDups.clear()
|
|
|
AllCurBankItems.clear()
|
|
AllCurBankItems.clear()
|
|
|
lastBankedPageOffset = -1
|
|
lastBankedPageOffset = -1
|
|
|
},
|
|
},
|
|
|
- saveBlacklistFile = () => fs.writeFileSync(fn, JSON.stringify(blacklist.sort((a, b) => a - b)), err => { ReadFile(); if (err) console.log(err) }),
|
|
|
|
|
|
|
+ saveBlacklistFile = () => fs.writeFileSync(fn, JSON.stringify(sortStrNum(blacklist)), err => { ReadFile(); if (err) console.log(err) }),
|
|
|
toggleAddToBl = () => {
|
|
toggleAddToBl = () => {
|
|
|
AddToBl = !AddToBl
|
|
AddToBl = !AddToBl
|
|
|
if (RmvFromBl && AddToBl) toggleRmvFromBl()
|
|
if (RmvFromBl && AddToBl) toggleRmvFromBl()
|
|
@@ -167,9 +188,9 @@ module.exports = function AutoBank(mod) {
|
|
|
for (const id of res)
|
|
for (const id of res)
|
|
|
if (blacklist.indexOf(id) === -1) {
|
|
if (blacklist.indexOf(id) === -1) {
|
|
|
blacklist.push(id)
|
|
blacklist.push(id)
|
|
|
- Msg(`The item ${convToCLA(id)} was <font color="#4DE19C">Added</font> to blacklist.`)
|
|
|
|
|
|
|
+ Msg(`The ${convToCLA(id)} was <font color="#4DE19C">Added</font> to blacklist.`)
|
|
|
}
|
|
}
|
|
|
- else Msg(`The item ${convToCLA(id)} is <font color="#AB58F4">Already</font> blacklisted.`)
|
|
|
|
|
|
|
+ else Msg(`The ${convToCLA(id)} is <font color="#AB58F4">Already</font> blacklisted.`)
|
|
|
saveBlacklistFile()
|
|
saveBlacklistFile()
|
|
|
},
|
|
},
|
|
|
rmvFromBl = (...ids) => {
|
|
rmvFromBl = (...ids) => {
|
|
@@ -179,14 +200,14 @@ module.exports = function AutoBank(mod) {
|
|
|
const blItemIndex = blacklist.indexOf(id)
|
|
const blItemIndex = blacklist.indexOf(id)
|
|
|
if (blItemIndex !== -1) {
|
|
if (blItemIndex !== -1) {
|
|
|
blacklist.splice(blItemIndex, 1)
|
|
blacklist.splice(blItemIndex, 1)
|
|
|
- Msg(`The item ${convToCLA(id)} was <font color="#FE6F5E">Removed</font> from blacklist.`)
|
|
|
|
|
|
|
+ Msg(`The ${convToCLA(id)} was <font color="#FE6F5E">Removed</font> from blacklist.`)
|
|
|
}
|
|
}
|
|
|
- else Msg(`The item ${convToCLA(id)} is <font color="#AB58F4">Not</font> blacklisted.`)
|
|
|
|
|
|
|
+ else Msg(`The ${convToCLA(id)} is <font color="#AB58F4">Not</font> blacklisted.`)
|
|
|
}
|
|
}
|
|
|
saveBlacklistFile()
|
|
saveBlacklistFile()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ** Command ** \\
|
|
|
|
|
|
|
+ // ~~~ * Command * ~~~ \\
|
|
|
|
|
|
|
|
mod.command.add(['autobank', 'ab'], (key, arg, ...args) => {
|
|
mod.command.add(['autobank', 'ab'], (key, arg, ...args) => {
|
|
|
if (key) key = key.toLowerCase()
|
|
if (key) key = key.toLowerCase()
|
|
@@ -198,11 +219,11 @@ module.exports = function AutoBank(mod) {
|
|
|
break
|
|
break
|
|
|
case 'blacklist': case 'bl':
|
|
case 'blacklist': case 'bl':
|
|
|
switch (arg) {
|
|
switch (arg) {
|
|
|
- case 'add': case '+':
|
|
|
|
|
|
|
+ case 'add': case 'ad': case '+':
|
|
|
if (!args.length) toggleAddToBl()
|
|
if (!args.length) toggleAddToBl()
|
|
|
else addToBl(...args)
|
|
else addToBl(...args)
|
|
|
break
|
|
break
|
|
|
- case 'remove': case 'rem': case 'rm': case '-':
|
|
|
|
|
|
|
+ case 'remove': case 'rem': case 'rm': case 'rmv': case '-':
|
|
|
if (!args.length) toggleRmvFromBl()
|
|
if (!args.length) toggleRmvFromBl()
|
|
|
else rmvFromBl(...args)
|
|
else rmvFromBl(...args)
|
|
|
break
|
|
break
|
|
@@ -223,7 +244,7 @@ module.exports = function AutoBank(mod) {
|
|
|
Msg(`\t- ${convToCLA(blacklist[bll])}`)
|
|
Msg(`\t- ${convToCLA(blacklist[bll])}`)
|
|
|
break
|
|
break
|
|
|
default:
|
|
default:
|
|
|
- Msg('Invalid blacklist command, please refer to the readme.')
|
|
|
|
|
|
|
+ Msg('Invalid blacklist command, please refer to the README.')
|
|
|
break
|
|
break
|
|
|
}
|
|
}
|
|
|
break
|
|
break
|
|
@@ -231,8 +252,8 @@ module.exports = function AutoBank(mod) {
|
|
|
Msg('<font color="#FE6F5E">Deprecated command</font>, please use `<font color="#AB58F4">ab bl rem \<items?...\></font>` instead!')
|
|
Msg('<font color="#FE6F5E">Deprecated command</font>, please use `<font color="#AB58F4">ab bl rem \<items?...\></font>` instead!')
|
|
|
break
|
|
break
|
|
|
default:
|
|
default:
|
|
|
- if (!enabled) {
|
|
|
|
|
- enabled = true
|
|
|
|
|
|
|
+ if (!Enabled) {
|
|
|
|
|
+ Enabled = true
|
|
|
Msg('Auto Banking is <font color="#4DE19C">enabled</font>.')
|
|
Msg('Auto Banking is <font color="#4DE19C">enabled</font>.')
|
|
|
}
|
|
}
|
|
|
else resetValues()
|
|
else resetValues()
|