Browse Source

New feature.

• Added ability to blacklist entire pocket tab, via command `/!ab bl {+|-} pocket{1|2|3}`.
○ ReadMe.md:
• Added info about the new feature.
• Some wording fixes.
Risenio 5 years ago
parent
commit
ce5fd960b2
3 changed files with 58 additions and 33 deletions
  1. 8 4
      README.md
  2. 48 27
      index.js
  3. 2 2
      manifest.json

+ 8 - 4
README.md

@@ -17,11 +17,13 @@
         1. Followed by writing the id of item(s), if more than one, use space as separation between each, e.g.
           > `ab bl add 1 2 3 4 5`<br>`ab bl rem 1 2 3 4 5`
         2. Followed by linked items (ctrl+left click), any amount of items, if more than one, spacing doesn't matter here (you may add space or not).
-          > `ab bl add <item1> <item2> <item3>...`<br>`ab bl rem <item1> <item2> <item3>...`
-        3. If no arguments, it will enable (un)blacklisting;
-          > `ab bl add` ~ Toggles blacklisting.<br>`ab bl rem` ~ Toggles unblacklisting.
+          > `ab bl ad <item1> <item2> <item3>`<br>`ab bl rm <item1> <item2> <item3>`
+        3. If you omit arguments, it will enable (un)blacklisting;
+          > `ab bl +` ~ Toggles blacklisting.<br>`ab bl rmv` ~ Toggles unblacklisting.
           - Open bank, then try add that item to bank to (un)blacklist it.
             * Note: Item will not be banked while this enabled.
+        ○ ○ If you want to blacklist entire pocket tab, say you want to keep superior items there, don't want them to get banked at all, no matter if they exist in bank or blacklist or not, you can do that using: (case-insensitive)
+          > `ab bl + pocket1 PocKet2 pocket3`<br>`ab bl - pocKET1 pocket2 pocket3`
     * `ab bl <reset/default>`:
       - This command resets the blacklist to the [default blacklist](#Blacklist).
     * `ab bl <clear/empty>`:
@@ -32,7 +34,7 @@
   - `autobank <guild/g>` toggles banking to guild bank. **Default Off**. 
 
 ## Blacklist
-  If no blacklist.json file is found, it will be using the default blacklist.
+  If no `blacklist.json` file was found, it will be using the default blacklist.
   - Editing/modifying the blacklist using blacklisting commands will be saved into the `blacklist.json` file.
   - You can get the id of any item from [this site](https://teralore.com/en/).
   <details>
@@ -94,6 +96,8 @@
     - ? It have banked all the way until full page and continued in next page.
     - ? It have banked same item in 2 different pages.
       - A: Its impossible, script will never bank an item in different page, even if page is full. (Make sure you don't already have that item in different pages, aka see duplication log).
+    - ? It moved my items from pocket/inventory to other pockets or to inventory.
+      - A: Its client behaviour, works only for ¹stacked items. If a stacked item has more amount in slot than the other slot, and you banked it; the less amount one will be moved from the 'other slot' to get in place of the banked one. ¹Unstacked items are unaffected.
 
 ## Proof of concept
   <details>

+ 48 - 27
index.js

@@ -1,5 +1,7 @@
 'use strict'
 
+// ~~~ * Data * ~~~ \\
+
 const fs = require('fs'),
 	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]
@@ -12,20 +14,24 @@ ReadFile()
 if (fs.existsSync(fn)) fs.watch(fn, event => { if (event === 'change') ReadFile() })
 
 module.exports = function AutoBank(mod) {
+
+	// ~~~ * Constants * ~~~ \\
+
 	const NotCP = typeof mod.compileProto !== 'undefined'
-	const defs = { cPutWareItem: 3, sViewWareEx: mod.majorPatchVersion < 96 ? 2 : 3 }
+	const defs = { cPutWareItem: 3, sViewWareEx: 3 }
 
 	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.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')
 
-	// ** Variables ** \\
+	// ~~~ * Variables * ~~~ \\
 
-	let enabled = false,
+	let Enabled = false,
 		GuildBanking = false,
 		AddToBl = false,
 		RmvFromBl = false,
@@ -35,10 +41,10 @@ module.exports = function AutoBank(mod) {
 		QueuedDups = new Map(),
 		AllCurBankItems = new Map()
 
-	// ** Hook Functions ** \\
+	// ~~~ * Hook Functions * ~~~ \\
 
 	function sViewWareEx(event) {
-		if (!enabled) return
+		if (!Enabled) return
 		if (lastBankedPageOffset >= event.offset) return false
 		if (!GuildBanking && event.container === 3) return Msg('Banking to guild bank is <font color="#FE6F5E">disabled</font>.')
 		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.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 })
 			else mod.toServer('C_CANCEL_CONTRACT', 1, { type: 26, id: curBankContractId })
 		}, 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 }
 
-	// ** Hooks ** \\
+	// ~~~ * Hooks * ~~~ \\
 
 	mod.hook('S_VIEW_WARE_EX', defs.sViewWareEx, sViewWareEx)
 	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_SYSTEM_MESSAGE', 1, sSytemMessage)
 
-	// ** Helper Functions ** \\
+	// ~~~ * Helper Functions * ~~~ \\
 
 	function toUniqueDbidArr(a, b, c = {}) {
 		b = a.length
@@ -108,8 +114,15 @@ module.exports = function AutoBank(mod) {
 	function remvBlacklisted(a, b, c = []) {
 		b = a.length
 		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
 	}
 	function getLine(n, m = 1) {
@@ -122,13 +135,21 @@ module.exports = function AutoBank(mod) {
 		return `${a / 72 + 1}:${getLine(s)}:${s % 8 || 8}`
 	}
 	function convToCLA(id) {
-		return `<font color="#7289DA"><ChatLinkAction param="1#####${id}">&lt;Click Me&gt;</ChatLinkAction></font>`
+		return typeof id === 'string' ? id : `item <font color="#7289DA"><ChatLinkAction param="1#####${id}">&lt;Click Me&gt;</ChatLinkAction></font>`
 	}
 	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
 	}
+	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}`),
 		resetValues = () => {
@@ -142,13 +163,13 @@ module.exports = function AutoBank(mod) {
 						Msg(`- ${d.count}x${d.link} | (${d.details1}) & (${d.details2})`)
 				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()
 			AllCurBankItems.clear()
 			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 = () => {
 			AddToBl = !AddToBl
 			if (RmvFromBl && AddToBl) toggleRmvFromBl()
@@ -167,9 +188,9 @@ module.exports = function AutoBank(mod) {
 			for (const id of res)
 				if (blacklist.indexOf(id) === -1) {
 					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()
 		},
 		rmvFromBl = (...ids) => {
@@ -179,14 +200,14 @@ module.exports = function AutoBank(mod) {
 				const blItemIndex = blacklist.indexOf(id)
 				if (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()
 		}
 
-	// ** Command ** \\
+	// ~~~ * Command * ~~~ \\
 
 	mod.command.add(['autobank', 'ab'], (key, arg, ...args) => {
 		if (key) key = key.toLowerCase()
@@ -198,11 +219,11 @@ module.exports = function AutoBank(mod) {
 				break
 			case 'blacklist': case 'bl':
 				switch (arg) {
-					case 'add': case '+':
+					case 'add': case 'ad': case '+':
 						if (!args.length) toggleAddToBl()
 						else addToBl(...args)
 						break
-					case 'remove': case 'rem': case 'rm': case '-':
+					case 'remove': case 'rem': case 'rm': case 'rmv': case '-':
 						if (!args.length) toggleRmvFromBl()
 						else rmvFromBl(...args)
 						break
@@ -223,7 +244,7 @@ module.exports = function AutoBank(mod) {
 							Msg(`\t- ${convToCLA(blacklist[bll])}`)
 						break
 					default:
-						Msg('Invalid blacklist command, please refer to the readme.')
+						Msg('Invalid blacklist command, please refer to the README.')
 						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!')
 				break
 			default:
-				if (!enabled) {
-					enabled = true
+				if (!Enabled) {
+					Enabled = true
 					Msg('Auto Banking is <font color="#4DE19C">enabled</font>.')
 				}
 				else resetValues()

+ 2 - 2
manifest.json

@@ -1,7 +1,7 @@
 {
     "files": {
-        "README.md": "3e46f59df7ecec1b80dcc6c4943149cd7eae31e2f90e804f98dbdca1bd555574",
-        "index.js": "1b8371ed6586c1227aff1ba39694e9e101f30c5b0d76616cb1edad74a28f1e01",
+        "README.md": "74da43b0bcad63bd10b6f85d357de6f8e1a62ca5537255da67f2a8b4bcc67901",
+        "index.js": "f970e24fcecf5f9cd4d11a045f3182cb7edb65be42e85bb237447fc3c2349214",
         "module.json": "df54235a322877d003fa9a33d00cc19aaa8fb0808782399179e34d4e191fba8a",
         "package.json": "b9e2b74cb3dfef6d72d3829b2df3ca9d516c84e40daf22c8d141151c33769396"
     },