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

Merge pull request #6 from anivay/master

Auto-Discard
Seagoose лет назад: 9
Родитель
Сommit
f92e4f36e5
3 измененных файлов с 69 добавлено и 7 удалено
  1. 5 2
      README.md
  2. 8 3
      config.json
  3. 56 2
      index.js

+ 5 - 2
README.md

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

+ 8 - 3
config.json

@@ -1,8 +1,13 @@
 {
 {
     "modes" : {
     "modes" : {
         "auto" : true,
         "auto" : true,
-        "easy" : false
+        "easy" : false,
+        "trash" : true
     },
     },
 
 
-    "blacklist" : [8000, 8001, 8002, 8005, 8018, 8025, 8023]
-}
+    "motes" : [8000, 8001, 8002, 8005, 8007, 8008, 8009, 8010, 8011, 8012, 8013, 8014, 8015, 8016, 8017, 8018, 8019, 8020, 8021, 8022, 8023, 8025],
+    "blacklist" : [169890, 169886, 169887, 169888, 169889, 169891, 160, 7214],
+    "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] 
+}

+ 56 - 2
index.js

@@ -3,13 +3,17 @@ const config = require('./config.json');
 module.exports = function Loot(dispatch) {
 module.exports = function Loot(dispatch) {
 
 
     let auto = config.modes.auto || false,
     let auto = config.modes.auto || false,
+        autotrash = config.modes.trash || false,
         enabled = config.modes.easy || true,
         enabled = config.modes.easy || true,
         lootInterval = auto ? setInterval(tryLootAll, 250) : null,
         lootInterval = auto ? setInterval(tryLootAll, 250) : null,
         location;
         location;
 
 
-    let blacklist = config.blacklist || [8000, 8001, 8002, 8005, 8018, 8025, 8023];
+    let blacklist = config.blacklist.concat(config.motes);
+    let trash = config.trash.concat(config.crystals.concat(config.strongboxes));
 
 
+    let cid = null;
     let loot = {};
     let loot = {};
+    let inventory = null;
 
 
     let commands = {
     let commands = {
         auto: {
         auto: {
@@ -37,9 +41,20 @@ module.exports = function Loot(dispatch) {
                 enabled = false;
                 enabled = false;
                 message('Easy looting is disabled.');
                 message('Easy looting is disabled.');
             }
             }
+        },
+        autotrash: {
+            alias: ['autotrash', 'trash'],
+            run: function() {
+                autotrash = !autotrash;
+
+                message('Autotrash toggled: ' + (autotrash ? 'on' : 'off'));
+                garbageCollect();
+            }
         }
         }
     }
     }
 
 
+    dispatch.hook('S_LOGIN', 1, event => { ({cid} = event) })
+
     dispatch.hook('C_CHAT', 1, (event) => {
     dispatch.hook('C_CHAT', 1, (event) => {
         if(!event.message.includes('!loot'))
         if(!event.message.includes('!loot'))
             return;
             return;
@@ -76,6 +91,45 @@ module.exports = function Loot(dispatch) {
         if(event.id.toString() in loot) delete loot[event.id.toString()];    
         if(event.id.toString() in loot) delete loot[event.id.toString()];    
     });
     });
 
 
+
+    dispatch.hook('S_SYSTEM_MESSAGE_LOOT_ITEM', 1, event => {
+        if(trash.includes(event.item)) {
+            garbageCollect();
+        }
+    });
+
+    dispatch.hook('S_SYSTEM_MESSAGE', 1, (event) => {
+        if(event.message === '@41') return false;  // Block "That isn't yours." system message.
+    });
+
+    function garbageCollect(){
+            dispatch.hook('S_INVEN', 5, event => {
+                if(autotrash) {
+                    if(event.first) inventory = []
+                    else if(!inventory) return
+
+                    for(let item of event.items) inventory.push(item)
+
+                    if(!event.more) {
+                        for(let item of inventory) {
+                            if(item.slot < 40) continue // First 40 slots are reserved for equipment, etc.
+                            else if(trash.includes(item.item)) deleteItem(item.slot, item.amount)
+                        }
+                        inventory = null
+                    }
+                }
+            })                
+    }
+
+
+    function deleteItem(slot, amount) {
+        dispatch.toServer('C_DEL_ITEM', 1, {
+            cid: cid,
+            slot: slot - 40,
+            amount
+        })
+    }
+
     function tryLootAll() {
     function tryLootAll() {
         for(let item in loot) {
         for(let item in loot) {
             if(location)
             if(location)
@@ -94,7 +148,7 @@ module.exports = function Loot(dispatch) {
             gm: 0,
             gm: 0,
             unk2: 0,
             unk2: 0,
             authorName: '',
             authorName: '',
-            message: ' (autoloot) ' + msg
+            message: ' (Autoloot) ' + msg
         });
         });
     }
     }