Browse Source

Optimize duplication checks.

Mie 6 years ago
parent
commit
fcb09f795d
3 changed files with 31 additions and 24 deletions
  1. 8 1
      README.md
  2. 21 21
      index.js
  3. 2 2
      manifest.json

+ 8 - 1
README.md

@@ -86,7 +86,14 @@
       - If you're using Pinkie's proxy, you will have to get it, via [this LINK](https://github.com/tera-mods-forks/tera-game-state) & place it in your mods folder (`[proxy dir]/mods`).
 
 ## Additional information
-  It will also send a warning if the same exact item is available in more than one page (i.e. Dublicate) in your storage space. (the warning will include a blue clickable links, you can click it to show the item).
+  It will also send a warning if the same exact item is available in more than one page (i.e. Duplicate) in your storage space. (the warning will include a blue clickable links, you can click it to show the item).
+
+  * FAQ
+    ? It have banked an item for me, and now I can't withdraw it with "That item isn't in your bank" error.
+    A: This is unrelated to script, simply you have same item, but 2 different time remaining, so make sure you don't withdraw with quantity or by right clicking on wrong stacks.
+    ? 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 duplicate log).
 
 ## Proof of concept
   <details>

+ 21 - 21
index.js

@@ -31,9 +31,8 @@ module.exports = function AutoBank(mod) {
 		RmvFromBl = false,
 		curBankContractId = -1,
 		lastBankedPageOffset = -1,
-		QueuedMsgs = [],
-		AllCurrentBankItems = [],
-		AllCurrentBankItemsIds = []
+		QueuedDups = new Map(),
+		AllCurBankItems = new Map()
 
 	// ** Hook Functions ** \\
 
@@ -46,18 +45,13 @@ module.exports = function AutoBank(mod) {
 			lastBankedPageOffset = event.offset
 			for (const bankItem of event.items) {
 				{
-					const bankItemDub = { offset: event.offset, id: bankItem.id, slot: bankItem.slot },
-						dubIndex = AllCurrentBankItemsIds.indexOf(bankItemDub.id)
-					if (dubIndex !== -1) {
-						const dubItem = AllCurrentBankItems[dubIndex],
-							dub1Slot = dubItem.slot - dubItem.offset + 1,
-							dub2Slot = bankItemDub.slot - bankItemDub.offset + 1
-
-						if (dubItem.offset !== event.offset) QueuedMsgs.push(`${convToCLA(dubItem.id)} | First (${dubItem.offset / 72 + 1}:${getLine(dub1Slot)}:${dub1Slot !== 8 ? dub1Slot % 8 : 8}) ^ Second (${bankItemDub.offset / 72 + 1}:${getLine(dub2Slot)}:${dub2Slot !== 8 ? dub2Slot % 8 : 8})`)
-					} else {
-						AllCurrentBankItems.push(bankItemDub)
-						AllCurrentBankItemsIds.push(bankItemDub.id)
-					}
+					if (AllCurBankItems.has(bankItem.id)) {
+						const dupItem = AllCurBankItems.get(bankItem.id)
+						if (dupItem.offset !== event.offset)
+							QueuedDups.has(dupItem.id) ?
+								QueuedDups.get(dupItem.id).count++ :
+								QueuedDups.set(dupItem.id, { count: 1, link: convToCLA(dupItem.id), details1: getDetails(dupItem.offset, dupItem.slot), details2: getDetails(event.offset, bankItem.slot) })
+					} else AllCurBankItems.set(bankItem.id, { offset: event.offset, id: bankItem.id, slot: bankItem.slot })
 				}
 				const found = mod.game.inventory.findAllInBagOrPockets(bankItem.id)
 				if (found && found.length)
@@ -122,8 +116,12 @@ module.exports = function AutoBank(mod) {
 			m++
 		return m
 	}
+	function getDetails(a, b, s = 0) {
+		s = b - a + 1
+		return `${a / 72 + 1}:${getLine(s)}:${s % 8 || 8}`
+	}
 	function convToCLA(id) {
-		return `<font color="#7289DA"><ChatLinkAction param="1#####${id}">&lt;ID=${id}&gt;</ChatLinkAction></font>`
+		return `<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)
@@ -135,15 +133,17 @@ module.exports = function AutoBank(mod) {
 		resetValues = () => {
 			if (AddToBl) toggleAddToBl()
 			if (RmvFromBl) toggleRmvFromBl()
-			if (QueuedMsgs.length) {
+			if (QueuedDups.size) {
 				Msg(`[Warning] <font color="#FE6F5E">Duplicate</font> items were found in your bank (page:line:slot).`)
-				for (const msg of QueuedMsgs) Msg(`\t- ${msg}`)
+				if (QueuedDups.size < 50)
+					for (const d of QueuedDups.values())
+						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
-			QueuedMsgs.length = 0
-			AllCurrentBankItems.length = 0
-			AllCurrentBankItemsIds.length = 0
+			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) }),

+ 2 - 2
manifest.json

@@ -1,7 +1,7 @@
 {
     "files": {
-        "README.md": "99b801199a44f9c52f6fb019f94833bdac9d3fb3b2f4a324668eecc52cb817b3",
-        "index.js": "4632d1b48745ac855d49e477b3b09f53ba9b668de631af841fde42cb442e5564",
+        "README.md": "69f58c69d551b87399a7586c9f8ffdb5ebba27843ccde90eefaee3394134e4cb",
+        "index.js": "b587aefc52287c4132719651a8c171dd58958b7b1df1a5aceb1b9b7b7e5149c5",
         "module.json": "df54235a322877d003fa9a33d00cc19aaa8fb0808782399179e34d4e191fba8a",
         "package.json": "b9e2b74cb3dfef6d72d3829b2df3ca9d516c84e40daf22c8d141151c33769396"
     },