Browse Source

Initial commit.

Risenio 6 years ago
commit
c544b1ac96
5 changed files with 301 additions and 0 deletions
  1. 76 0
      README.md
  2. 186 0
      index.js
  3. 16 0
      manifest.json
  4. 13 0
      module.json
  5. 10 0
      package.json

+ 76 - 0
README.md

@@ -0,0 +1,76 @@
+# Auto-Bank
+  A tera-proxy module that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/guild bank/etc.'s tab.
+
+# Usage
+  1. Use command `autobank`/`ab` to toggle banking.
+  2. Open bank or click on bank tab to begin.
+  3. That's it. It will automatically check all pages in the bank you've open, and once it ends, it will close the bank for you.
+
+## Commands
+  All commands starts with `autobank` or `ab` as alternative.
+
+  - `autobank` or `ab` to start.
+  ---
+  - `autobank <blacklist/bl>` toggles adding to blacklist.
+    * Open bank, and then try add that item to bank to blacklist. 
+      * Note: Item will not be banked while adding to blacklist.
+  ---
+  - `ab <rmvblacklist/rmbl>` toggles removing from blacklist.
+    * Open bank, and then try add that item to bank to remove it from blacklist.
+      * Note: Item will not be banked while removing from blacklist.
+  ---
+  - `autobank <guild/g>` toggles banking to guild bank. **Default Off**. 
+
+## Blacklist
+  If no blacklist.json file was found, it will be using default blacklist.
+    - Editing/modifying the blacklist using blacklisting commands will saved into `blacklist.json` file.
+  <details>
+    <summary><b>Default blacklist</b></summary>
+  
+  - ID: 112     - [Rejuvenation Potion](https://teralore.com/en/item/112)
+  - ID: 114     - [Valkyon Health Potion](https://teralore.com/en/item/114)
+  - ID: 116     - [Health Potion](https://teralore.com/en/item/116)
+  - ID: 194     - [Scroll of Rapid Resurrection](https://teralore.com/en/item/194)
+  - ID: 130     - [Divine Infusion](https://teralore.com/en/item/130)
+  - ID: 444     - [[Legacy] Bravery Potion](https://teralore.com/en/item/444)
+  - ID: 6552    - [Prime Recovery Potable](https://teralore.com/en/item/6552)
+  - ID: 6553    - [Superior Recovery Potable](https://teralore.com/en/item/6553)
+  - ID: 6562    - [Prime Replenishment Potable](https://teralore.com/en/item/6562)
+  - ID: 6563    - [Superior Replenishment Potable](https://teralore.com/en/item/6563)
+  - ID: 9310    - [Veteran's HP Potion](https://teralore.com/en/item/9310)
+  - ID: 9311    - [Veteran's MP Potion](https://teralore.com/en/item/9311)
+  - ID: 60260   - [Goddess's Blessing](https://teralore.com/en/item/60260)
+  - ID: 70000   - [Complete Crystalbind](https://teralore.com/en/item/70000)
+  - ID: 80081   - [Lein's Dark Root Beer](https://teralore.com/en/item/80081)
+  - ID: 80095   - [Federation Supply: Rejuvenation Potion](https://teralore.com/en/item/80095)
+  - ID: 81209   - [Friendly Feast](https://teralore.com/en/item/81209)
+  - ID: 150532  - [Strong Bravery Potion](https://teralore.com/en/item/150532)
+  - ID: 150533  - [Strong Bravery Potion](https://teralore.com/en/item/150533)
+  - ID: 150534  - [Strong Canephora Potion](https://teralore.com/en/item/150534)
+  - ID: 150535  - [Strong Canephora Potion](https://teralore.com/en/item/150535)
+  - ID: 150542  - [Bravery Potion](https://teralore.com/en/item/150542)
+  - ID: 151643  - [Elleon's Mark of Valor](https://teralore.com/en/item/151643)
+  - ID: 155324  - [Goddess's Blessing](https://teralore.com/en/item/155324)
+  - ID: 160322  - [Goddess's Blessing](https://teralore.com/en/item/160322)
+  - ID: 167001  - [Canephora Potion](https://teralore.com/en/item/167001)
+  - ID: 177131  - [Pet Treat](https://teralore.com/en/item/177131)
+  - ID: 177132  - [Pet Food](https://teralore.com/en/item/177132)
+  - ID: 177133  - [Pet Snack](https://teralore.com/en/item/177133)
+  - ID: 200529  - [Goddess's Blessing](https://teralore.com/en/item/200529)
+  - ID: 200922  - [Superior Noctenium Elixir](https://teralore.com/en/item/200922)
+  - ID: 200999  - [Prime Battle Solution](https://teralore.com/en/item/200999)
+  - ID: 201957  - [Eren's Key](https://teralore.com/en/item/201957)
+  - ID: 201958  - [Eren's Key](https://teralore.com/en/item/201958)
+  - ID: 202015  - [Bravery Potion](https://teralore.com/en/item/202015)
+  - ID: 206049  - [Puppy Figurine](https://teralore.com/en/item/206049)
+  - ID: 206050  - [Piglet Figurine](https://teralore.com/en/item/206050)
+  - ID: 206051  - [Popori Figurine](https://teralore.com/en/item/206051)
+  </details>
+
+## Capability.
+  * Should work on any proxy. (Currently awaiting update def for Pinkie's).
+  * 1 dependency;
+    - tera-game-state
+      - If you're using Caali's proxy(toolbox), you don't have to do anything, as this comes along-with by default.
+      - 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`).
+

+ 186 - 0
index.js

@@ -0,0 +1,186 @@
+'use strict'
+
+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]
+
+let blacklist = []
+
+function ReadFile() { try { blacklist = require(fn) } catch (err) { blacklist = defaultBl } }
+ReadFile()
+
+if (fs.existsSync(fn)) fs.watch(fn, event => { if (event === 'change') ReadFile() })
+
+module.exports = function AutoBank(mod) {
+
+	const NotCP = typeof mod.compileProto !== 'undefined'
+	if (NotCP) return //Lets see if pinkie will update defs anytime soon.
+
+	// ** Initialize dependency ** \\	
+	mod.game.initialize('inventory')
+
+	// ** Variables ** \\	
+
+	let enabled = false,
+		GuildBanking = false,
+		AddToBl = false,
+		RmvFromBl = false,
+		curBankContractId = -1,
+		lastBankedPageOffset = -1,
+		QueuedMsgs = [],
+		AllCurrentBankItems = [],
+		AllCurrentBankItemsIds = []
+
+	// ** Hook Functions ** \\
+
+	function sViewWareEx(event) {
+		if (!enabled) return
+		if (lastBankedPageOffset >= event.offset) return false
+		if (!GuildBanking && event.container === 3) return Msg('Banking to guild bank is disabled.')
+		let toBankItems = []
+		if (event.items.length > 0 && mod.game.inventory.items.length > 0) {
+			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})`)
+					}
+					AllCurrentBankItems.push(bankItemDub)
+					AllCurrentBankItemsIds.push(bankItemDub.id)
+				}
+				const found = mod.game.inventory.findAllInBagOrPockets(bankItem.id)
+				if (found && found.length)
+					toBankItems.push(...found)
+			}
+			toBankItems = toUniqueDbidArr(toBankItems)
+			toBankItems = remvBlacklisted(toBankItems)
+			for (const toBank of toBankItems)
+				mod.toServer('C_PUT_WARE_ITEM', 3, { 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 (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)
+	}
+	function cPutWareItem({ id }) {
+		if (AddToBl) {
+			if (blacklist.indexOf(id) === -1) {
+				blacklist.push(id)
+				Msg(`The item '${convToCLA(id)}' was <font color="#4DE19C">Added</font> to blacklist.`)
+			}
+			else Msg(`The item '${convToCLA(id)}' is Already blacklisted.`)
+			return false
+		}
+		if (RmvFromBl) {
+			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.`)
+			}
+			else Msg(`The item '${convToCLA(id)}' is Not blacklisted.`)
+			return false
+		}
+	}
+	function sRequestContract(event) { if (event.type === 26) curBankContractId = event.id }
+	function sCancelContract(event) {
+		if (event.type === 26) {
+			curBankContractId = -1
+			resetValues()
+		}
+	}
+	//function sSytemMessage(event) { if (enabled && mod.parseSystemMessage(event.message).id === 'SMT_WAREHOUSE_FULL') return false }
+
+	// ** Hooks ** \\
+
+	mod.hook('S_VIEW_WARE_EX', 2, sViewWareEx)
+	mod.hook('C_PUT_WARE_ITEM', 3, cPutWareItem)
+	mod.hook('S_REQUEST_CONTRACT', 1, sRequestContract)
+	mod.hook('S_CANCEL_CONTRACT', 1, sCancelContract)
+	//mod.hook('S_SYSTEM_MESSAGE', 1, sSytemMessage)
+
+	// ** Helper Functions ** \\
+
+	function toUniqueDbidArr(a, b, c = {}) {
+		b = a.length
+		if (!b) return []
+		while (b--)
+			c[a[b].dbid] = a[b]
+		return Object.values(c)
+	}
+	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])
+		return c
+	}
+	function getLine(n, m = 1) {
+		while (8 * m < n)
+			m++
+		return m
+	}
+	function convToCLA(id) {
+		return `<font color="#7289DA"><ChatLinkAction param="1#####${id}">&lt;ID=${id}&gt;</ChatLinkAction></font>`
+	}
+
+	const Msg = msg => mod.command.message(`${NotCP ? '[Auto-Bank]' : ''} ${msg}`),
+		resetValues = () => {
+			if (AddToBl) toggleAddToBl()
+			if (RmvFromBl) toggleRmvFromBl()
+			if (QueuedMsgs.length) {
+				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 (enabled) Msg('Auto Banking is <font color="#FE6F5E">disabled</font>.')
+			enabled = false
+			QueuedMsgs.length = 0
+			AllCurrentBankItems.length = 0
+			AllCurrentBankItemsIds.length = 0
+			lastBankedPageOffset = -1
+		},
+		saveBlacklistFile = () => fs.writeFileSync(fn, JSON.stringify(blacklist.sort((a, b) => a - b)), err => { ReadFile(); if (err) console.log(err) }),
+		toggleAddToBl = () => {
+			AddToBl = !AddToBl
+			if (RmvFromBl && AddToBl) toggleRmvFromBl()
+			Msg(`Adding to Blacklist <font color="#${AddToBl ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
+			if (!AddToBl) saveBlacklistFile()
+		},
+		toggleRmvFromBl = () => {
+			RmvFromBl = !RmvFromBl
+			if (RmvFromBl && AddToBl) toggleAddToBl()
+			Msg(`Removing from Blacklist <font color="#${RmvFromBl ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
+			if (!RmvFromBl) saveBlacklistFile()
+		}
+
+	// ** Command ** \\
+
+	mod.command.add(['autobank', 'ab'], (key) => {
+		if (key) key = key.toLowerCase()
+		switch (key) {
+			case 'guild': case 'g':
+				GuildBanking = !GuildBanking
+				Msg(`Banking to Guild Bank is <font color="#${GuildBanking ? `4DE19C">En` : `FE6F5E">Dis`}abled</font>.`)
+				break
+			case 'blacklist': case 'bl':
+				toggleAddToBl()
+				break
+			case 'rmblacklist': case 'rmvblacklist': case 'rmbl': case 'rmvbl':
+				toggleRmvFromBl()
+				break
+			default:
+				if (!enabled) {
+					enabled = true
+					Msg('Auto Banking is <font color="#4DE19C">enabled</font>.')
+				}
+				else resetValues()
+				break
+		}
+	})
+}

+ 16 - 0
manifest.json

@@ -0,0 +1,16 @@
+{
+    "files": {
+        "README.md": "1f67fad7c8c9fa7286b82ffaf92fedde04b114fc78de91c3ff0c9c5fd0a12108",
+        "index.js": "840c50cfda007f1ad33a1d7302fb363b2715cdd40118d7491151ecb8092b2fb3",
+        "module.json": "df54235a322877d003fa9a33d00cc19aaa8fb0808782399179e34d4e191fba8a",
+        "package.json": "e8886ae26005161df8365d0a94b2e76e29ecc04a5d7b7b804b647d21c0ae0300"
+    },
+    "defs": {
+        "C_CANCEL_CONTRACT": 1,
+        "C_PUT_WARE_ITEM": 3,
+        "C_VIEW_WARE": 2,
+        "S_CANCEL_CONTRACT": 1,
+        "S_REQUEST_CONTRACT": 1,
+        "S_VIEW_WARE_EX": 2
+    }
+}

+ 13 - 0
module.json

@@ -0,0 +1,13 @@
+{
+    "disableAutoUpdate": false,
+    "name": "Auto-Bank",
+    "author": "Risenio",
+    "homepage": "https://github.com/Risenio/Auto-Bank/blob/master/README.md",
+    "description": "A script that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/etc's tab.",
+    "version": "*",
+    "options": {
+        "niceName": "AutoBank",
+        "guiName": "Auto Bank"
+    },
+    "servers": ["https://raw.githubusercontent.com/Risenio/Auto-Bank/master/"]
+}

+ 10 - 0
package.json

@@ -0,0 +1,10 @@
+{
+	"main": "index.js",
+	"name": "auto-bank",
+	"author": "Risenio",
+	"description": "A script that auto merges inventory items to bank if same item exists in bank/special storage/wardrobe/etc's tab.",
+	"version": "*",
+	"homepage": "https://github.com/Risenio/Auto-Bank/blob/master/README.md",
+	"keywords": ["tera", "tera-proxy", "tera-online", "fps-utils", "automatic"],
+	"repository": { "type":	"git", "url": "git+https://github.com/Risenio/Auto-Bank.git" }
+}