valkyr1e лет назад: 8
Родитель
Сommit
110e3a83f8
6 измененных файлов с 104 добавлено и 138 удалено
  1. 6 15
      README.md
  2. 0 18
      config.json
  3. 39 105
      index.js
  4. 15 0
      manifest.json
  5. 10 0
      module.json
  6. 34 0
      settings_migrator.js

+ 6 - 15
README.md

@@ -1,19 +1,10 @@
-# loot
+loot
+===
 A TERA utility to auto loot the items on the ground, as soon as they drop or with a command.
 
 ## Commands:
+- **loot**
+  - Toggles loot.
 
-* **!loot**
-    * **Arguments:** auto, on, off, trash
-
-* **!loot auto:** 
-    * Toggles auto loot on and off.
-
-* **!loot trash:** 
-    * Toggles auto trash on and off.
-
-* **!loot on:**
-    * Upon looting an item, attempts to loot everything in a 250 unit radius.
-
-* **!loot off:**
-    * Disables looting in range.
+- **loot auto:** 
+ - Toggles auto loot.

+ 0 - 18
config.json

@@ -1,18 +0,0 @@
-{
-	"lootInterval": 100,
-	"lootThrottleMax": 800,
-	"lootScanInterval": 400,
-	"lootRadius": 120,
-
-	"modes": {
-		"auto": true,
-		"easy": false,
-		"trash": false
-	},
-
-	"blacklist": [169890, 169886, 169887, 169888, 169889, 169891, 160, 7214],
-	"motes": [8000, 8001, 8002, 8005, 8007, 8008, 8009, 8010, 8011, 8012, 8013, 8014, 8015, 8016, 8017, 8018, 8019, 8020, 8021, 8022, 8023, 8025],
-	"trash": [160, 8007, 94201, 94202, 7214, 200997, 200998, 6452, 6453, 6454, 6522, 6523, 6524, 6525, 97392, 6468, 6463, 201018, 96100, 21311, 21312, 21313, 21314, 21315, 21316, 354, 650, 97013, 97012, 20904],
-	"crystals": [8108, 8122, 8136, 8150, 8164, 8249, 8321, 8375, 8587, 8441, 8501, 8513, 8525, 8537, 8573, 8109, 8123, 8137, 8151, 8165, 8250, 8322, 8376, 8388, 8422, 8502, 8514, 8526, 8538, 8574, 8110, 8124, 8138, 8152, 8166, 8251, 8323, 8377, 8389, 8443, 8503, 8515, 8527, 8539, 8575, 8111, 8125, 8139, 8153, 8167, 8252, 8324, 8378, 8390, 8444, 8504, 8516, 8528, 8540, 8576, 8112, 8126, 8140, 8154, 8168, 8253, 8325, 8379, 8391, 8445, 8505, 8517, 8529, 8541, 8577, 8241, 8427, 8101, 8129, 8900, 8901, 8906, 8908], 
-	"strongboxes": [155546, 169886, 169887, 169888, 169889, 169890, 169891] 
-}

+ 39 - 105
index.js

@@ -1,130 +1,64 @@
-const Command = require('command'),
-	config = require('./config.json'),
-	blacklist = config.blacklist.concat(config.motes, config.strongboxes),
-	trash = config.trash.concat(config.crystals, config.strongboxes)
+'use strict'
 
-module.exports = function Loot(dispatch) {
-	const command = Command(dispatch)
+module.exports = function Loot(mod) {
+	const motes = [...Array(26).keys()].map(i => i + 8000)
+	const blacklist = mod.settings.blacklist.concat(motes)
 
-	let auto = config.modes.auto || false,
-		autotrash = config.modes.trash || false,
-		enabled = config.modes.easy || true
+	let location = null
+	let lootTimeout = null
+	let items = new Map()
 
-	let gameId = -1n,
-		playerId = -1,
-		myLoc = null,
-		mounted = false,
-		inven = null,
-		loot = new Map(),
-		lootTimeout = null
-
-	let commands = {
-		auto: {
-			alias: ['auto', 'autoloot', 'toggle'],
-			run: function() {
-				auto = !auto
-				command.message(`Autoloot mode toggled: ${auto}`)
-				if(auto && !lootTimeout) tryLoot()
-				else {
-					clearTimeout(lootTimeout)
-					lootTimeout = null
-				}
-			}
+	mod.command.add('loot', {
+		$default() {
+			mod.settings.enabled = !mod.settings.enabled
+			mod.command.message(`${mod.settings.enabled ? 'en' : 'dis'}abled`)
 		},
-		enable: {
-			alias: ['enable', 'on'],
-			run: function() {
-				enabled = true
-				command.message('Easy looting is enabled.')
-			}
-		},
-		disable: {
-			alias: ['disable', 'off'],
-			run: function() {
-				enabled = false
-				command.message('Easy looting is disabled.')
-			}
-		},
-		autotrash: {
-			alias: ['autotrash', 'trash'],
-			run: function() {
-				autotrash = !autotrash
-
-				command.message('Autotrash toggled: ' + (autotrash ? 'on' : 'off'))
-			}
+		auto() {
+			mod.settings.auto = !mod.settings.auto
+			mod.command.message(`auto-loot ${mod.settings.enabled ? 'en' : 'dis'}abled`)
 		}
-	}
-
-	dispatch.hook('S_LOGIN', 10, event => { ({gameId, playerId} = event) })
-
-	command.add('loot', c => {
-		if(c)
-			for(let cmd in commands)
-				if(commands[cmd].alias.includes(c))
-					commands[cmd].run()
 	})
 
-	dispatch.hook('S_LOAD_TOPO', 3, event => {
-		myLoc = event.loc
-		mounted = false
-		loot.clear()
-	})
+	mod.game.me.on('change_zone', () => items.clear())
+
+	mod.hook('S_RETURN_TO_LOBBY', 1, () => items.clear())
 
-	dispatch.hook('C_PLAYER_LOCATION', 5, event => { myLoc = event.loc })
-	dispatch.hook('S_RETURN_TO_LOBBY', 'raw', () => { loot.clear() })
+	mod.hook('C_PLAYER_LOCATION', 5, event => location = event.loc)
 
-	dispatch.hook('S_MOUNT_VEHICLE', 2, event => { if(event.gameId === gameId) mounted = true })
-	dispatch.hook('S_UNMOUNT_VEHICLE', 2, event => { if(event.gameId === gameId) mounted = false })
+	mod.hook('S_SPAWN_DROPITEM', 6, event => {
+		if (blacklist.includes(event.item))
+			return
 
-	dispatch.hook('S_SPAWN_DROPITEM', 6, event => {
-		if(event.owners.some(owner => owner.playerId === playerId) && !blacklist.includes(event.item)) {
-			loot.set(event.gameId.toString(), Object.assign(event, {priority: 0}))
+		if (event.owners.some(owner => owner.playerId === mod.game.me.playerId)) {
+			items.set(event.gameId, Object.assign(event, {priority: 0}))
 
-			if(auto && !lootTimeout) tryLoot()
+			if (mod.settings.auto && !lootTimeout)
+				tryLoot()
 		}
 	})
 
-	dispatch.hook('C_TRY_LOOT_DROPITEM', 4, event => {
-		if(enabled && !lootTimeout) lootTimeout = setTimeout(tryLoot, config.lootInterval)
+	mod.hook('C_TRY_LOOT_DROPITEM', 4, () => {
+		if (mod.settings.enabled && !lootTimeout)
+			lootTimeout = setTimeout(tryLoot, mod.settings.interval)
 	})
 
-	dispatch.hook('S_DESPAWN_DROPITEM', 4, event => { loot.delete(event.gameId.toString()) })
-
-	dispatch.hook('S_INVEN', 12, event => {
-		inven = event.first ? event.items : inven.concat(event.items)
-
-		if(!event.more) {
-			if(autotrash)
-				for(let item of inven)
-					if(item.slot < 40) continue // First 40 slots are reserved for equipment, etc.
-					else if(trash.includes(item.id)) deleteItem(item.slot, item.amount)
-
-			inven = null
-		}
-	})
-
-	function deleteItem(slot, amount) {
-		dispatch.toServer('C_DEL_ITEM', 2, {
-			gameId,
-			slot: slot - 40,
-			amount
-		})
-	}
+	mod.hook('S_DESPAWN_DROPITEM', 4, event => items.delete(event.gameId))
 
 	function tryLoot() {
 		clearTimeout(lootTimeout)
 		lootTimeout = null
 
-		if(!loot.size) return
+		if (!items.size || mod.game.me.mounted)
+			return
 
-		if(!mounted)
-			for(let l of [...loot.values()].sort((a, b) => a.priority - b.priority))
-				if(myLoc.dist3D(l.loc) <= config.lootRadius) {
-					dispatch.toServer('C_TRY_LOOT_DROPITEM', 4, l)
-					lootTimeout = setTimeout(tryLoot, Math.min(config.lootInterval * ++l.priority, config.lootThrottleMax))
-					return
-				}
+		for(let item of [...items.values()].sort((a, b) => a.priority - b.priority))
+			if (location.dist3D(item.loc) <= mod.settings.radius) {
+				mod.toServer('C_TRY_LOOT_DROPITEM', 4, item)
+				lootTimeout = setTimeout(tryLoot, Math.min(mod.settings.interval * ++item.priority, mod.settings.throttleMax))
+				return
+			}
 
-		if(auto) setTimeout(tryLoot, config.lootScanInterval)
+		if (mod.settings.auto)
+			setTimeout(tryLoot, mod.settings.scanInterval)
 	}
 }

+ 15 - 0
manifest.json

@@ -0,0 +1,15 @@
+{
+	"files": {
+		"README.md": "6c2387544a95f5d6189dcc4d45ba3786333e7cfed98211475f01bae938294c8e",
+		"index.js": "320e3dc2880359611dd70080b09042ded5af9e27d18b2cdc89941777ed149de4",
+		"module.json": "3b7b75938bcb79d8c2ed6d44327c5ecbe4f8cc9e23ac805a3e820174ea91f64a",
+		"settings_migrator.js": "2741bf5f523135ef038636c3f3388d8e6422aa5a6f3b713ab5dc3f96ec6ec3c0"
+	},
+	"defs": {
+		"C_PLAYER_LOCATION": 5,
+		"C_TRY_LOOT_DROPITEM": 4,
+		"S_DESPAWN_DROPITEM": 4,
+		"S_RETURN_TO_LOBBY": 1,
+		"S_SPAWN_DROPITEM": 6
+	}
+}

+ 10 - 0
module.json

@@ -0,0 +1,10 @@
+{
+  "disableAutoUpdate": false,
+  "servers": ["https://raw.githubusercontent.com/valkyr1e-tera/loot/master/"],
+  "options": {
+    "niceName": "loot",
+    "settingsVersion": 1,
+    "settingsFile": "config.json",
+    "settingsMigrator": "settings_migrator.js"
+  }
+}

+ 34 - 0
settings_migrator.js

@@ -0,0 +1,34 @@
+"use strict"
+
+const DefaultSettings = {
+    "enabled": true,
+    "auto": false,
+	"interval": 100,
+	"throttleMax": 800,
+	"scanInterval": 400,
+    "radius": 250,
+    "blacklist": [98260, 98513, 98590]
+}
+
+module.exports = function MigrateSettings(from_ver, to_ver, settings) {
+    if (from_ver === undefined) {
+        // Migrate legacy config file
+        return DefaultSettings;
+    } else if (from_ver === null) {
+        // No config file exists, use default settings
+        return DefaultSettings;
+    } else {
+        if(from + 1 < to) {
+            settings = MigrateSettings(from_ver, from_ver + 1, settings);
+            return MigrateSettings(from_ver + 1, to_ver, settings);
+        }
+
+        switch (to) {
+            default:
+                settings = Object.assign(DefaultSettings, settings);
+                break;
+        }
+
+        return settings;
+    }
+}