teralove лет назад: 8
Родитель
Сommit
032e9f5e8d
2 измененных файлов с 160 добавлено и 53 удалено
  1. 21 1
      README.MD
  2. 139 52
      index.js

+ 21 - 1
README.MD

@@ -2,7 +2,7 @@
 tera-proxy module that skips lockons and instantly heals and cleanses party members.
 tera-proxy module that skips lockons and instantly heals and cleanses party members.
 
 
 ## Info
 ## Info
-- Heals will instantly auto-lockon and heal party members. Prioritizing the lowest HP.
+- Skills will instantly lockon and heal/cleanse party members. Heals prioritize the lowest HP.
 - Mystic's cleanse only works in parties of 5 members or less. Disabled in raids.
 - Mystic's cleanse only works in parties of 5 members or less. Disabled in raids.
 
 
 | Skills affected                 |
 | Skills affected                 |
@@ -16,14 +16,34 @@ tera-proxy module that skips lockons and instantly heals and cleanses party memb
 ### `autoheal`
 ### `autoheal`
 - Toggle on/off
 - Toggle on/off
 - Default is on
 - Default is on
+### `autoheal [on/off]`
+- Enable/disable auto-heals
+### `autoheal [HP]`
+- Set cutoff for healing. ('autoheal 50' = ignore members with >50% HP. Set to 100 to always heal)
+- Default cutoff is 97%
 ### `autocleanse`
 ### `autocleanse`
 - Toggle on/off
 - Toggle on/off
 - Default is on
 - Default is on
+### `autocleanse [on/off]`
+- Enable/disable auto-cleansing
 
 
+## Issues
+- Skills can ghost if proxy is also using Skill-Prediction (You see animation but nothing happens). [Click here for workaround.](https://i.imgur.com/bS4VkbX.png)
 
 
 ## Changelog
 ## Changelog
 <details>
 <details>
 
 
+    1.5
+    - New: autoheal and autocleanse commands toggle only their respectable behaviours. 
+    - New: autoheal command has argument to set HP cutoff.
+    - New: autoheal command has argument to toggle on/off explicitly ('autoheal on/off')
+    - New: autocleanse command has argument to toggle on/off explicitly ('autocleanse on/off')
+    - New: Vertical distance check.
+    - Fixed: Sometimes still locking onto dead players.
+    - Fixed: Locking onto players that left the party.
+    - Fixed: Mod would only start working on players when they had moved.
+    - Fixed: Mod would briefly stop working when a dead party member resses.
+    - Fixed: Mod would briefly stop working after toggling via command toggle.
     1.42
     1.42
     - Added S_USER_LOCATION_IN_ACTION hook. (Fixes issue with brawlers not getting lockons)
     - Added S_USER_LOCATION_IN_ACTION hook. (Fixes issue with brawlers not getting lockons)
     1.41
     1.41

+ 139 - 52
index.js

@@ -1,23 +1,12 @@
-// OP Required
-// - S_LOGIN
-// - S_PARTY_MEMBER_LIST
-// - S_LEAVE_PARTY
-// - C_PLAYER_LOCATION
-// - S_SPAWN_USER
-// - S_USER_LOCATION
-// - S_USER_LOCATION_IN_ACTION
-// - S_PARTY_MEMBER_CHANGE_HP
-// - C_START_SKILL
-// - S_CREST_INFO
-// - S_CREST_APPLY
 const Command = require('command');
 const Command = require('command');
 
 
 module.exports = function AutoHeal(dispatch) {
 module.exports = function AutoHeal(dispatch) {
+    const command = Command(dispatch);
     
     
     const Skills = {
     const Skills = {
         6: [ // Priest
         6: [ // Priest
             19, // Focus Heal
             19, // Focus Heal
-            37 // Immersion
+            37  // Immersion
         ],
         ],
         7: [ // Mystic
         7: [ // Mystic
             5, // Titanic Favor
             5, // Titanic Favor
@@ -25,39 +14,75 @@ module.exports = function AutoHeal(dispatch) {
         ]
         ]
     };
     };
     
     
-    const MaxDistance = 32; // in-game meters. can work up to 35m
-    const MaxHp = 0.97;     //(healing) ignore members that have more HP% than this
+    const MaxDistance = 35; // in-game meters. can work up to 35m
+    const MaxVertical = 28; // (Ignore targets at top of CS ladders, etc). Can also be 35m
     
     
-    let enabled = true,
+    let autoHeal = true,
         autoCleanse = true,
         autoCleanse = true,
+        hpCutoff = 97,   // (healing only) ignore members that have more HP% than this
+        enabled = false, // gets enabled if you log in as a healer
         playerId = 0,
         playerId = 0,
-        playerLocation,
+        gameId = 0,
+        playerLocation = {},
         partyMembers = [],
         partyMembers = [],
-        job,
-        glyphs;
+        job = -1,
+        glyphs = null;
         
         
-    const command = Command(dispatch);
-    
-    command.add('autoheal', ()=> {
-        enabled = !enabled;
-        command.message('(auto-heal) ' + (enabled ? 'enabled' : 'disabled'));
+    command.add('autoheal', (p1)=> {
+        if (p1 == null) {
+            autoHeal = !autoHeal;
+        } else if (p1.toLowerCase() === 'off') {
+            autoHeal = false;
+        } else if (p1.toLowerCase() === 'on') {
+            autoHeal = true;
+        } else if (!isNaN(p1)) {
+            autoHeal = true;
+            hpCutoff = (p1 < 0 ? 0 : p1 > 100 ? 100 : p1);
+        } else {
+            command.message('(auto-heal) ' + p1 +' is an invalid argument');
+            return;
+        }        
+        command.message('(auto-heal) Healing ' + (autoHeal ? 'enabled (' + hpCutoff + '%)' : 'disabled'));
     });
     });
     
     
-    command.add('autocleanse', ()=> {
-        autoCleanse = !autoCleanse;
-        command.message('(auto-heal) Cleansing ' + (enabled ? 'enabled' : 'disabled'));
+    command.add('autocleanse', (p1) => {
+        if (p1 == null) {
+            autoCleanse = !autoCleanse;
+        } else if (p1.toLowerCase() === 'off') {
+            autoCleanse = false;
+        } else if (p1.toLowerCase() === 'on') {
+            autoCleanse = true;
+        } else {
+            command.message('(auto-heal) ' + p1 +' is an invalid argument for cleanse command');
+            return;
+        }
+        command.message('(auto-heal) Cleansing ' + (autoCleanse ? 'enabled' : 'disabled'));
     });
     });
     
     
     dispatch.hook('S_LOGIN', 10, (event) => {
     dispatch.hook('S_LOGIN', 10, (event) => {
         playerId = event.playerId;
         playerId = event.playerId;
+        gameId = event.gameId;
         job = (event.templateId - 10101) % 100;
         job = (event.templateId - 10101) % 100;
-        (Skills[job]) ? enabled = true : enabled = false; 
+        enabled = (Skills[job]) ? true : false;
     })
     })
     
     
     dispatch.hook('S_PARTY_MEMBER_LIST', 6, (event) => {
     dispatch.hook('S_PARTY_MEMBER_LIST', 6, (event) => {
+        if (!enabled) return;
+        // refresh locations of existing party members.
+        for (let i = 0; i < event.members.length; i++) {
+            for (let j = 0; j < partyMembers.length; j++) {
+                if (partyMembers[j]) {
+                    if (event.members[i].gameId.equals(partyMembers[j].gameId)) {
+                        event.members[i].loc = partyMembers[j].loc;
+                        event.members[i].hpP = partyMembers[j].hpP;
+                    }
+                }
+            }
+        }
         partyMembers = event.members;
         partyMembers = event.members;
+        // remove self from targets
         for (let i = 0; i < partyMembers.length; i++) {
         for (let i = 0; i < partyMembers.length; i++) {
-            if (partyMembers[i].playerId == playerId) {
+            if (partyMembers[i].gameId.equals(gameId)) {
                 partyMembers.splice(i, 1);
                 partyMembers.splice(i, 1);
                 return;
                 return;
             }
             }
@@ -69,54 +94,112 @@ module.exports = function AutoHeal(dispatch) {
     })
     })
     
     
     dispatch.hook('C_PLAYER_LOCATION', 3, (event) => {
     dispatch.hook('C_PLAYER_LOCATION', 3, (event) => {
+        if (!enabled) return;
         playerLocation = event;
         playerLocation = event;
     })
     })
     
     
-    dispatch.hook('S_USER_LOCATION', 3, (event) => {
+    dispatch.hook('S_SPAWN_ME', 2, (event) => {
+        playerLocation.gameId = event.gameId;
+        playerLocation.loc = event.loc;
+        playerLocation.w = event.w;
+    })
+    
+    dispatch.hook('S_SPAWN_USER', 13, (event) => {
+        if (!enabled) return;
         if (partyMembers.length != 0) {
         if (partyMembers.length != 0) {
             for (let i = 0; i < partyMembers.length; i++) {
             for (let i = 0; i < partyMembers.length; i++) {
                 if (partyMembers[i].gameId.equals(event.gameId)) {
                 if (partyMembers[i].gameId.equals(event.gameId)) {
                     partyMembers[i].loc = event.loc;
                     partyMembers[i].loc = event.loc;
+                    partyMembers[i].hpP = (event.alive ? 100 : 0);
                     return;
                     return;
                 }
                 }
             }
             }
         }
         }
     })
     })
     
     
+    dispatch.hook('S_USER_LOCATION', 3, (event) => {
+        if (!enabled) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].gameId.equals(event.gameId)) {
+                partyMembers[i].loc = event.loc;
+                return;
+            }
+        }
+    })
+    
     dispatch.hook('S_USER_LOCATION_IN_ACTION', 2, (event) => {
     dispatch.hook('S_USER_LOCATION_IN_ACTION', 2, (event) => {
-        if (partyMembers.length != 0) {
-            for (let i = 0; i < partyMembers.length; i++) {
-                if (partyMembers[i].gameId.equals(event.gameId)) {
-                    partyMembers[i].loc = event.loc;
-                    return;
-                }
+        if (!enabled) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].gameId.equals(event.gameId)) {
+                partyMembers[i].loc = event.loc;
+                return;
             }
             }
         }
         }
     })
     })
     
     
-    dispatch.hook('S_SPAWN_USER', 13, (event) => {
-        if (partyMembers.length != 0) {
-            for (let i = 0; i < partyMembers.length; i++) {
-                if (partyMembers[i].gameId.equals(event.gameId)) {
-                    partyMembers[i].loc = event.loc;
-                    partyMembers[i].hpP = (event.alive ? 1 : 0);
-                    return;
-                }
+    dispatch.hook('S_INSTANT_DASH', 3, (event) => {
+        if (!enabled) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].gameId.equals(event.gameId)) {
+                partyMembers[i].loc = event.loc;
+                return;
             }
             }
         }
         }
     })
     })
     
     
     dispatch.hook('S_PARTY_MEMBER_CHANGE_HP', 3, (event) => {
     dispatch.hook('S_PARTY_MEMBER_CHANGE_HP', 3, (event) => {
+        if (!enabled) return;
         if (playerId == event.playerId) return;
         if (playerId == event.playerId) return;
-        
         for (let i = 0; i < partyMembers.length; i++) {
         for (let i = 0; i < partyMembers.length; i++) {
-            if (partyMembers[i].playerId == event.playerId) {
-                partyMembers[i].hpP = event.currentHp / event.maxHp;
+            if (partyMembers[i].playerId === event.playerId) {
+                partyMembers[i].hpP = (event.currentHp / event.maxHp) * 100;
+                return;
+            }
+        }
+    })
+    
+    dispatch.hook('S_PARTY_MEMBER_STAT_UPDATE', 3, (event) => {
+        if (!enabled) return;
+        if (playerId == event.playerId) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].playerId === event.playerId) {
+                partyMembers[i].hpP = (event.curHp / event.maxHp) * 100;
+                return;
+            }
+        }
+    })
+    
+    dispatch.hook('S_DEAD_LOCATION', 2, (event) => {
+        if (!enabled) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].gameId.equals(event.gameId)) {
+                partyMembers[i].loc = event.loc;
+                partyMembers[i].hpP = 0;
                 return;
                 return;
             }
             }
         }
         }
     })
     })
     
     
+    dispatch.hook('S_LEAVE_PARTY_MEMBER', 2, (event) => {
+        if (!enabled) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].playerId === event.playerId) {
+                partyMembers.splice(i, 1);
+                return;
+            }
+        }
+    });
+     
+    dispatch.hook('S_LOGOUT_PARTY_MEMBER', 1, (event) => {
+        if (!enabled) return;
+        for (let i = 0; i < partyMembers.length; i++) {
+            if (partyMembers[i].playerId === event.playerId) {
+                partyMembers[i].online = false;
+                return;
+            }
+        }
+    });
+    
     dispatch.hook('C_START_SKILL', 5, (event) => {
     dispatch.hook('C_START_SKILL', 5, (event) => {
         if (!enabled) return;
         if (!enabled) return;
         if (partyMembers.length == 0) return; // be in a party
         if (partyMembers.length == 0) return; // be in a party
@@ -124,12 +207,13 @@ module.exports = function AutoHeal(dispatch) {
             playerLocation.w = event.w;
             playerLocation.w = event.w;
             return; 
             return; 
         }
         }
-        
         let skill = Math.floor((event.skill - 0x4000000) / 10000);
         let skill = Math.floor((event.skill - 0x4000000) / 10000);
+        
         if(Skills[job] && Skills[job].includes(skill)) {
         if(Skills[job] && Skills[job].includes(skill)) {
+            if(skill != 9 && !autoHeal) return; //return; // skip heal if disabled
             if(skill == 9 && !autoCleanse) return; // skip cleanse if disabled
             if(skill == 9 && !autoCleanse) return; // skip cleanse if disabled
-            if(skill == 9 && partyMembers.length > 4) return;  // skip cleanse if in a raid
-
+            if(skill == 9 && partyMembers.length > 4) return; // skip cleanse if in a raid
+            
             let targetMembers = [];
             let targetMembers = [];
             let maxTargetCount = getMaxTargets(skill);
             let maxTargetCount = getMaxTargets(skill);
             if (skill != 9) sortHp();
             if (skill != 9) sortHp();
@@ -137,9 +221,10 @@ module.exports = function AutoHeal(dispatch) {
                 if (partyMembers[i].online &&
                 if (partyMembers[i].online &&
                     partyMembers[i].hpP != undefined &&
                     partyMembers[i].hpP != undefined &&
                     partyMembers[i].hpP > 0 &&
                     partyMembers[i].hpP > 0 &&
-                    ((skill == 9) ? true : partyMembers[i].hpP < MaxHp) && // (cleanse) ignore max hp
+                    ((skill == 9) ? true : partyMembers[i].hpP <= hpCutoff) && // (cleanse) ignore max hp
                     partyMembers[i].loc != undefined &&
                     partyMembers[i].loc != undefined &&
-                    (partyMembers[i].loc.dist3D(playerLocation.loc) / 25) <= MaxDistance)
+                    (partyMembers[i].loc.dist3D(playerLocation.loc) / 25) <= MaxDistance && 
+                    (Math.abs(partyMembers[i].loc.z - playerLocation.loc.z) / 25) <= MaxVertical)
                     {
                     {
                         targetMembers.push(partyMembers[i]);
                         targetMembers.push(partyMembers[i]);
                         if (targetMembers.length == maxTargetCount) break;
                         if (targetMembers.length == maxTargetCount) break;
@@ -162,10 +247,12 @@ module.exports = function AutoHeal(dispatch) {
     })
     })
     
     
     dispatch.hook('S_CREST_INFO', 2, (event) => {
     dispatch.hook('S_CREST_INFO', 2, (event) => {
+        if (!enabled) return;
         glyphs = event.crests;
         glyphs = event.crests;
     })
     })
     
     
     dispatch.hook('S_CREST_APPLY', 2, (event) => {
     dispatch.hook('S_CREST_APPLY', 2, (event) => {
+        if (!enabled) return;
         for (let i = 0; i < glyphs.length; i++) {
         for (let i = 0; i < glyphs.length; i++) {
             if (glyphs[i].id == event.id) {
             if (glyphs[i].id == event.id) {
                 glyphs[i].enable = event.enable;
                 glyphs[i].enable = event.enable;