Просмотр исходного кода

Vec3 revamp

* Now throttles interval for items that it has attempted to loot already.
* No longer tries to loot while mounted.
* No longer bugs out and tries to delete the wrong items if you enable autotrash at a bad time.
Pinkie Pie лет назад: 8
Родитель
Сommit
57834b729e
2 измененных файлов с 39 добавлено и 47 удалено
  1. 2 1
      config.json
  2. 37 46
      index.js

+ 2 - 1
config.json

@@ -1,5 +1,6 @@
 {
 	"lootInterval": 100,
+	"lootThrottleMax": 800,
 	"lootScanInterval": 400,
 	"lootRadius": 120,
 
@@ -13,5 +14,5 @@
 	"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": [169886, 169887, 169888, 169889, 169890, 169891] 
+	"strongboxes": [155546, 169886, 169887, 169888, 169889, 169890, 169891] 
 }

+ 37 - 46
index.js

@@ -10,11 +10,12 @@ module.exports = function Loot(dispatch) {
 		autotrash = config.modes.trash || false,
 		enabled = config.modes.easy || true
 
-	let cid = null,
+	let gameId = null,
 		playerId = -1,
-		location = null,
-		inventory = null,
-		loot = {},
+		myLoc = null,
+		mounted = false,
+		inven = null,
+		loot = new Map(),
 		lootTimeout = null
 
 	let commands = {
@@ -50,12 +51,11 @@ module.exports = function Loot(dispatch) {
 				autotrash = !autotrash
 
 				command.message('Autotrash toggled: ' + (autotrash ? 'on' : 'off'))
-				garbageCollect()
 			}
 		}
 	}
 
-	dispatch.hook('S_LOGIN', 1, event => { ({cid, playerId} = event) })
+	dispatch.hook('S_LOGIN', 9, event => { ({gameId, playerId} = event) })
 
 	command.add('loot', c => {
 		if(c)
@@ -64,51 +64,48 @@ module.exports = function Loot(dispatch) {
 					commands[cmd].run()
 	})
 
-	dispatch.hook('S_LOAD_TOPO', 1, event => {
-		location = event
-		loot = {}
+	dispatch.hook('S_LOAD_TOPO', 3, event => {
+		myLoc = event.loc
+		mounted = false
+		loot.clear()
 	})
 
-	dispatch.hook('C_PLAYER_LOCATION', 2, event => { location = event })
-	dispatch.hook('S_RETURN_TO_LOBBY', 'raw', () => { loot = {} })
+	dispatch.hook('C_PLAYER_LOCATION', 3, event => { myLoc = event.loc })
+	dispatch.hook('S_RETURN_TO_LOBBY', 'raw', () => { loot.clear() })
 
-	dispatch.hook('S_SPAWN_DROPITEM', 1, event => {
-		if(event.owners.some(owner => owner.id === playerId) && !blacklist.includes(event.item)) {
-			loot[event.id.toString()] = Object.assign(event, {priority: 0})
+	dispatch.hook('S_MOUNT_VEHICLE', 2, event => { if(event.gameId.equals(gameId)) mounted = true })
+	dispatch.hook('S_UNMOUNT_VEHICLE', 2, event => { if(event.gameId.equals(gameId)) mounted = false })
+
+	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(auto && !lootTimeout) tryLoot()
 		}
 	})
 
-	dispatch.hook('C_TRY_LOOT_DROPITEM', 1, event => {
+	dispatch.hook('C_TRY_LOOT_DROPITEM', 4, event => {
 		if(enabled && !lootTimeout) lootTimeout = setTimeout(tryLoot, config.lootInterval)
 	})
 
-	dispatch.hook('S_DESPAWN_DROPITEM', 1, event => {
-		delete loot[event.id.toString()]
-	})
-
-	/*dispatch.hook('S_SYSTEM_MESSAGE_LOOT_ITEM', 1, event => {
-		if(event.message === '@41') return false // Block "That isn't yours." system message.
-	})*/
+	dispatch.hook('S_DESPAWN_DROPITEM', 4, event => { loot.delete(event.gameId.toString()) })
 
-	dispatch.hook('S_INVEN', 10, event => {
-		if(autotrash) {
-			inventory = inventory ? inventory.concat(event.items) : event.items
+	dispatch.hook('S_INVEN', 12, event => {
+		inven = event.first ? event.items : inven.concat(event.items)
 
-			if(!event.more) {
-				for(let item of inventory)
+		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.dbid)) deleteItem(item.slot, item.amount)
+					else if(trash.includes(item.id)) deleteItem(item.slot, item.amount)
 
-				inventory = null
-			}
+			inven = null
 		}
 	})
 
 	function deleteItem(slot, amount) {
-		dispatch.toServer('C_DEL_ITEM', 1, {
-			cid: cid,
+		dispatch.toServer('C_DEL_ITEM', 2, {
+			gameId,
 			slot: slot - 40,
 			amount
 		})
@@ -118,22 +115,16 @@ module.exports = function Loot(dispatch) {
 		clearTimeout(lootTimeout)
 		lootTimeout = null
 
-		let lootItems = Object.values(loot).sort((a, b) => a.priority - b.priority)
+		if(!loot.size) return
 
-		if(!lootItems.length) return
-
-		for(let item of lootItems)
-			if(dist3D(location, item) < config.lootRadius) {
-				dispatch.toServer('C_TRY_LOOT_DROPITEM', 1, { id: item.id })
-				item.priority++
-				lootTimeout = setTimeout(tryLoot, config.lootInterval)
-				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
+				}
 
 		if(auto) setTimeout(tryLoot, config.lootScanInterval)
 	}
-}
-
-function dist3D(loc1, loc2) {
-	return Math.sqrt(Math.pow(loc2.x - loc1.x, 2) + Math.pow(loc2.y - loc1.y, 2) + Math.pow(loc2.z - loc1.z, 2))
 }