teralove лет назад: 8
Родитель
Сommit
0e18af0a64
2 измененных файлов с 81 добавлено и 75 удалено
  1. 18 17
      README.MD
  2. 63 58
      index.js

+ 18 - 17
README.MD

@@ -1,8 +1,5 @@
 # auto-heal
-tera-proxy module that skips lockons and automatically heals and cleanses party members.
-
-## Dependency
-- `Command` module
+tera-proxy module that skips lockons and instantly heals and cleanses party members.
 
 ## Usage
 ### `autoheal`
@@ -13,23 +10,27 @@ tera-proxy module that skips lockons and automatically heals and cleanses party
 - Default is on
 
 ## Info
-| Skills affected                 |
-| ------------------------------- |
-| Priest - Focus Heal             |
-| Mystic - Titanic Favor          |
-| Mystic - Arun's Cleansing Touch |
-- Heal will auto-lockon and immediately heal up to 4 party members with the lowest HP.
-- Mystic's cleanse works only in parties of 5 members or less. Disabled in raids!
-- Skills work up to 35m. You can remove the distance glyph and spend the points elsewhere.
+- Skills affected
+-- Priest
+--- Focus Heal
+--- Immersion Heal
+-- Mystic
+--- Titanic Favor
+--- Arun's Cleansing Touch
+- Heals will instantly auto-lockon and heal party members. Prioritizing the lowest HP.
+- Mystic's cleanse only works in parties of 5 members or less. Disabled in raids.
 
 ## Changelog
 <details>
 
-    2.01
-    - Renamed module from auto-lockon to auto-heal
-    2.00
-    - Rewrote module
-    - Fixed bug: Casting skills would rotate the player towards north.
+    1.40
+    - Faster response
+    - Added Priest's Immersion skill.
+    - Glyphs affect number of lockon targets.
+    - Fixed bug: Casting skills would ignore player rotation
+    - Reduced max distance to 30m
+    1.30
+    - Code update and aesthetics
     - Fixed bug: Locking and casting onto dead targets
     - Added Command dependency
     - Added autocleanse command

+ 63 - 58
index.js

@@ -1,6 +1,5 @@
 // OP Required
 // - S_LOGIN
-// - S_SPAWN_ME
 // - S_PARTY_MEMBER_LIST
 // - S_LEAVE_PARTY
 // - C_PLAYER_LOCATION
@@ -8,13 +7,16 @@
 // - S_USER_LOCATION
 // - S_PARTY_MEMBER_CHANGE_HP
 // - C_START_SKILL
+// - S_CREST_INFO
+// - S_CREST_APPLY
 const Command = require('command');
 
 module.exports = function AutoHeal(dispatch) {
     
     const Skills = {
         6: [ // Priest
-            19 // Focus Heal
+            19, // Focus Heal
+            37 // Immersion
         ],
         7: [ // Mystic
             5, // Titanic Favor
@@ -22,15 +24,16 @@ module.exports = function AutoHeal(dispatch) {
         ]
     };
     
-    const MaxDistance = 900;  //~35 meters
-    const MaxHp = 0.97;       //(healing) ignore members that have more HP% than this
+    const MaxDistance = 30; // in-game meters. can work up to 35m but can look suspicious
+    const MaxHp = 0.97;     //(healing) ignore members that have more HP% than this
     
     let enabled = true,
         autoCleanse = true,
         playerId = 0,
-        playerLocation = null,
+        playerLocation,
         partyMembers = [],
-        job;
+        job,
+        glyphs;
         
     const command = Command(dispatch);
     
@@ -47,11 +50,7 @@ module.exports = function AutoHeal(dispatch) {
     dispatch.hook('S_LOGIN', 9, (event) => {
         playerId = event.playerId;
         job = (event.templateId - 10101) % 100;
-        (job == 6 || job == 7) ? enabled = true : enabled = false; 
-    })
-        
-    dispatch.hook('S_SPAWN_ME', 2, (event) => {
-        playerLocation = event.loc;
+        (Skills[job]) ? enabled = true : enabled = false; 
     })
     
     dispatch.hook('S_PARTY_MEMBER_LIST', 6, (event) => {
@@ -69,7 +68,7 @@ module.exports = function AutoHeal(dispatch) {
     })
     
     dispatch.hook('C_PLAYER_LOCATION', 3, (event) => {
-        playerLocation = event.loc;
+        playerLocation = event;
     })
     
     dispatch.hook('S_USER_LOCATION', 3, (event) => {
@@ -109,16 +108,30 @@ module.exports = function AutoHeal(dispatch) {
     dispatch.hook('C_START_SKILL', 4, (event) => {
         if (!enabled) return;
         if (partyMembers.length == 0) return; // be in a party
-        if ((event.skill - 0x4000000) / 10 & 1 != 0) return; // is casting (opposed to locking on)
-            
+        if ((event.skill - 0x4000000) / 10 & 1 != 0) { // is casting (opposed to locking on)
+            playerLocation.w = event.w;
+            return; 
+        }
+        
         let skill = Math.floor((event.skill - 0x4000000) / 10000);
         if(Skills[job] && Skills[job].includes(skill)) {
-            
+            if(skill == 9 && !autoCleanse) return; // skip cleanse if disabled
+            if(skill == 9 && partyMembers.length > 4) return;  // skip cleanse if in a raid
+
             let targetMembers = [];
-            if (job == 7 && skill == 9 && autoCleanse) {
-                targetMembers = getMembersToCleanse();
-            } else {
-                targetMembers = getMembersToHeal();
+            let maxTargetCount = getMaxTargets(skill);
+            if (skill != 9) sortHp();
+            for (let i = 0; i < partyMembers.length; i++) {
+                if (partyMembers[i].online &&
+                    partyMembers[i].hpP != undefined &&
+                    partyMembers[i].hpP > 0 &&
+                    ((skill == 9) ? true : partyMembers[i].hpP < MaxHp) && // (cleanse) ignore max hp
+                    partyMembers[i].loc != undefined &&
+                    (partyMembers[i].loc.dist3D(playerLocation.loc) / 25) <= MaxDistance)
+                    {
+                        targetMembers.push(partyMembers[i]);
+                        if (targetMembers.length == maxTargetCount) break;
+                    }
             }
             
             if (targetMembers.length > 0) {
@@ -126,36 +139,46 @@ module.exports = function AutoHeal(dispatch) {
                     setTimeout(() => {
                         dispatch.toServer('C_CAN_LOCKON_TARGET', 1, {target: targetMembers[i].gameId, skill: event.skill});
                     }, 5);
-                    setTimeout(() => {
-                        dispatch.toClient('S_CAN_LOCKON_TARGET', 1, {target: targetMembers[i].gameId, skill: event.skill, ok: true})
-                    }, 60);
                 }
                 
                 setTimeout(() => {
-                    dispatch.toServer('C_START_SKILL', 4, Object.assign({}, event, {skill: (event.skill + 10)}));
-                }, 120);
+                    dispatch.toServer('C_START_SKILL', 4, Object.assign({}, event, {w: playerLocation.w, skill: (event.skill + 10)}));
+                }, 10);
             }
         }
+        
     })
     
-    function getMembersToCleanse() {
-        let result = [];
-        
-        if (partyMembers.length > 4) { 
-            // in a raid
-        } else { 
-            // not in a raid
-            for (let i = 0; i < partyMembers.length; i++) {
-                if (partyMembers[i].online &&
-                    partyMembers[i].hpP != undefined &&
-                    partyMembers[i].hpP > 0 &&
-                    partyMembers[i].loc != undefined &&
-                    partyMembers[i].loc.dist3D(playerLocation) < MaxDistance) {
-                        result.push(partyMembers[i]);
-                    }
+    dispatch.hook('S_CREST_INFO', 2, (event) => {
+        glyphs = event.crests;
+    })
+    
+    dispatch.hook('S_CREST_APPLY', 2, (event) => {
+        for (let i = 0; i < glyphs.length; i++) {
+            if (glyphs[i].id == event.id) {
+                glyphs[i].enable = event.enable;
+                return;
             }
         }
-        return result;
+    })
+    
+    function getMaxTargets (skill) {
+        switch(skill) {
+            case 19: return isGlyphEnabled(28003) ? 4 : 2;
+            case 37: return 1;
+            case 5: return isGlyphEnabled(27000) ? 4 : 2;
+            case 9: return (isGlyphEnabled(27063) || isGlyphEnabled(27003)) ? 5 : 3;
+        }
+        return 1;
+    }
+    
+    function isGlyphEnabled(glyphId) {
+        for(let i = 0; i < glyphs.length; i++) {
+            if (glyphs[i].id == glyphId && glyphs[i].enable) {
+                return true;
+            }
+        }
+        return false;
     }
     
     function sortHp() {
@@ -164,22 +187,4 @@ module.exports = function AutoHeal(dispatch) {
         });
     }
     
-    function getMembersToHeal() {
-        let result = [];
-        
-        sortHp();
-        for (let i = 0; i < partyMembers.length; i++) {
-            if (partyMembers[i].online &&
-                partyMembers[i].hpP != undefined &&
-                partyMembers[i].hpP > 0 && 
-                partyMembers[i].hpP < MaxHp && 
-                partyMembers[i].loc != undefined &&
-                partyMembers[i].loc.dist3D(playerLocation) < MaxDistance) {
-                    result.push(partyMembers[i]);
-                    if (result.length == 4) break;
-                }
-        }
-        return result;
-    }
-    
 }