TeraProxy 8 years ago
parent
commit
ffa202bd8c
6 changed files with 125 additions and 104 deletions
  1. 19 4
      README.md
  2. 6 3
      config.json
  3. 56 86
      index.js
  4. 9 6
      manifest.json
  5. 1 1
      module.json
  6. 34 4
      settings_migrator.js

+ 19 - 4
README.md

@@ -9,11 +9,17 @@ Should work on all regions as long as the opcodes are mapped. Thanks to EME's re
 If you enjoy my work and wish to support future development, feel free to drop me a small donation: [![Donate](https://www.paypalobjects.com/webstatic/en_US/i/buttons/PP_logo_h_100x26.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=A3KBZUCSEQ5RJ&lc=US&item_name=TeraProxy&curency_code=USD&no_note=1&no_shipping=1&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted)
 
 # Essentials
-A tera-proxy module that automatically uses the items "Elite Everful Nostrum" and "Complete Crystal Bind" whenever needed.  
+A tera-proxy module that automatically uses "Nostrum"/"Battle Solution" and "Complete Crystalbind" items whenever needed.  
 
 ## Usage
-If you don't have Elite/Club status, you can open up "config.json" and change "elite" from true to false in order to use Prime Battle Solution instead of Everful Nostrum.  
-You can change the used non-Elite/Club items by editing the item IDs for "ccb" and "nostrum" in "config.json".  
+There are several options you can change in the "config.json" file:  
+  
+* "elite" - If you don't have Elite/Club status, change this to "false" in order to use Prime Battle Solution instead of Everful Nostrum
+* "useNostrum" - Change this to "false" if you do not want the module to use any Nostrums
+* "useCCB" - Change this to "false" if you do not want the module to use any CCBs
+* "log" - If you need to find a specific item ID, change this to "true" and it will log the ID of any item you use in the proxy chat
+* "nostrum" - This is the ID of the Nostrum item the module will use. Only matters when "elite" is set to "false"
+* "ccb" - This is the ID of the Nostrum item the module will use
   
 While in game, open a proxy chat session by typing "/proxy" or "/8" in chat and hitting the space bar.  
 This serves as the script's command interface.  
@@ -26,11 +32,20 @@ Whatever you send to the proxy chat in game is intercepted client-side. The chat
 The script makes sure that you are not dead, mounted, in a battleground or in a negotiation before using an item.
 
 ## Credits
-Contains code from true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
+Based on true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
 
 ## Changelog
 <details>
 
+### 2.0.0
+* [*] Fixed Nostrum items being used after every loading screen
+* [*] Fixed missing abnormalities for some Crystalbind and Nostrum items
+* [~] Changed Nostrum reapplication time from 10-25 minutes to less than 5 minutes
+* [~] Code revamp
+* [+] Added CCB reapplication time at less than 10 minutes instead of waiting until the buff runs out
+* [+] Added "useNostrum" option (see Usage)
+* [+] Added "useCCB" option (see Usage)
+* [+] Added "log" option (see Usage)
 ### 1.3.10
 * [*] Support for patch versions < 75
 ### 1.3.9

+ 6 - 3
config.json

@@ -1,8 +1,11 @@
 {
-    "version": 1,
+    "version": 2,
     "data": {
         "elite": true,
-        "ccb": 70000,
-        "nostrum": 200999
+        "useNostrum": true,
+        "useCCB": true,
+        "log": false,
+        "nostrum": 200999,
+        "ccb": 70000
     }
 }

+ 56 - 86
index.js

@@ -1,71 +1,36 @@
-// Version 1.3.10
+// Version 2.0.0
 // Based on true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
+// Based on true-everful-nostrum by Caali https://github.com/caali-hackerman
 
 'use strict'
 
 const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604], // EU, NA, RU, TW, ?, ?, ?, TH
-	BUFF_INVINCIBILITY = [1134, 6007], // Invincibility abnormality (Goddess Blessing, Phoenix)
-	BUFF_NOSTRUM_TD = [4020, 4030], // Nostrum abnormality for Tanks and Damage Dealers (pleb, elite)
-	BUFF_NOSTRUM_H = [4021, 4031], // Nostrum abnormality for Healers (pleb, elite)
-	BUFF_CCB = [4610, 4612, 5020003], // Complete Crystalbind abnormality (12h, 1h, elite)
-	RANDOM_MIN_MAX = [600000, 1500000], // Random Nostrum reapplication time (10 - 25 minutes)
-	RANDOM_SHORT = [4000, 8000] // Random Nostrum reapplication time after loading (4 - 8 seconds)
+	BUFF_NOSTRUM = [4020, 4021, 4022, 4023, 4030, 4031, 4032, 4044], // Nostrum abnormalities
+	BUFF_CCB = [4610, 4611, 4612, 4613, 4615, 4616, 4950, 5000003, 5020003], // Complete Crystalbind abnormalities
+	BUFF_INVINCIBILITY = [1134, 6007] // Invincibility abnormalities on resurrection
 
 module.exports = function Essentials(mod) {
 
-	const ELITE = mod.settings.elite,
-		ITEM_PLEB_NOSTRUM = mod.settings.nostrum,
-		ITEM_CCB = mod.settings.ccb
-
 	mod.game.initialize("contract")
 
 	let slot = null,
-		timeoutNostrum = null,
-		timeoutCCB = null,
-		cooldown = 0,
-		nextUse = 0,
-		hasccb = false,
+		interval = null,
 		enabled = true,
-		iAmInvincible = false
+		abnormalities = {}
 
 	// ############# //
 	// ### Hooks ### //
 	// ############# //
 
-	mod.game.on('enter_game', () => {
-		hasccb = false
-
-		mod.hookOnce('C_PLAYER_LOCATION', 'raw', () => {
-			nextUse = Date.now() + randomNumber(RANDOM_SHORT)
-			setTimeout(ccb, randomNumber(RANDOM_SHORT)) // check if you have a CCB shortly after moving for the first time
-		})
-	})
-	mod.game.on('leave_game', () => {
-		if (timeoutNostrum) {
-			clearInterval(timeoutNostrum)
-			timeoutNostrum = null
-		}
-		if (timeoutCCB) {
-			clearInterval(timeoutCCB)
-			timeoutCCB = null
-		}
-	})
-
-	mod.game.on('leave_loading_screen', () => {
-		mod.hookOnce('C_PLAYER_LOCATION', 'raw', () => { nostrum() })
-	})
+	mod.game.on('enter_game', () => { start() })
+	mod.game.on('leave_game', () => { stop() })
 
-	mod.game.me.on('die', () => { 
-		nextUse = 0
-		nostrum()
-	})
-	mod.game.me.on('resurrect', () => { nostrum() })
+	mod.game.me.on('resurrect', () => { start() })
 
 	mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
 		for(let item of event.inventory)
 			if(ITEMS_NOSTRUM.includes(item.item)) {
 				slot = item.slot
-				if(item.cooldown) cooldown = Date.now() + item.cooldown
 				item.cooldown = 0 // Cooldowns from this packet don't seem to do anything except freeze your client briefly
 				return true
 			}
@@ -75,63 +40,59 @@ module.exports = function Essentials(mod) {
 	mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
 	mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
 
+	if(mod.settings.log) {
+		mod.hook('C_USE_ITEM', 3, event => {
+			mod.command.message('Used item ID: ' + event.id)
+		})
+	}
+
 	// ################# //
 	// ### Functions ### //
 	// ################# //
 
 	function abnormality(type, event) {
 		if(mod.game.me.is(event.target)) {
-			if(BUFF_NOSTRUM_TD.includes(event.id) || BUFF_NOSTRUM_H.includes(event.id)) {
-				if(type === 'S_ABNORMALITY_END') {
-					nextUse = 0
-					nostrum()
-				}
-			}
-			else if(BUFF_CCB.includes(event.id)) {
-				hasccb = type !== 'S_ABNORMALITY_END'
-				if(!hasccb) ccb()
-			}
-			else if(BUFF_INVINCIBILITY.includes(event.id)) {
-				iAmInvincible = type !== 'S_ABNORMALITY_END'
-				if(!iAmInvincible) {
-					nextUse = 0
-					nostrum()
-				}
-			}
+			if(type === 'S_ABNORMALITY_END')
+				delete abnormalities[event.id]
+			else abnormalities[event.id] = Date.now() + event.duration
 		}
 	}
 
-	function nostrum() {
-		clearTimeout(timeoutNostrum)
-		
-		if(mod.game.isIngame && mod.game.me.alive && !mod.game.isInLoadingScreen && !mod.game.me.mounted && !mod.game.contract.active && !mod.game.me.inBattleground && (slot || !ELITE) && !iAmInvincible)
-			timeoutNostrum = setTimeout(useNostrum, nextUse - Date.now())
+	function abnormalityDuration(id) {
+		if(!abnormalities[id]) return 0
+		return abnormalities[id] - Date.now()
 	}
 
-	function ccb() {
-		clearTimeout(timeoutCCB)
-		
-		if(!hasccb && mod.game.isIngame && mod.game.me.alive && !mod.game.isInLoadingScreen && !mod.game.me.mounted && !mod.game.contract.active && !mod.game.me.inBattleground) useItem(ITEM_CCB)
-		else if(!hasccb) timeoutCCB = setTimeout(ccb, 10000) // retry in 10 seconds if we were busy
+	function checkItems() {
+		for(let buff of BUFF_INVINCIBILITY) // Do not overwrite invincibility buff
+			if(abnormalityDuration(buff) > 0) return
+
+		useNostrum()
+		useCCB()
 	}
 
 	function useNostrum() {
-		let time = Date.now()
+		for(let buff of BUFF_NOSTRUM) // Use Nostrum only when less than 5 minutes remaining
+			if(abnormalityDuration(buff) > 300000 || !mod.settings.useNostrum) return
 
-		if(time >= cooldown) {
-			if(enabled) {
-				if(ELITE) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
-				else useItem(ITEM_PLEB_NOSTRUM)
-			}
-			nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
-			nostrum()
+		if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active || (mod.settings.elite && !slot)) return
+
+		if(enabled) {
+			if(slot) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
+			else useItem(mod.settings.nostrum)
 		}
-		else timeoutNostrum = setTimeout(useNostrum, cooldown - time)
 	}
-	
+
+	function useCCB() {
+		for(let buff of BUFF_CCB) // Use CCB only when less than 10 minutes remaining
+			if(abnormalityDuration(buff) > 600000 || !mod.settings.useCCB) return
+
+		if(!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active) return
+
+		if(enabled) useItem(mod.settings.ccb)
+	}
+
 	function useItem(item) {
-		if(!enabled) return
-		
 		mod.toServer('C_USE_ITEM', 3, {
 			gameId: mod.game.me.gameId,
 			id: item,
@@ -147,9 +108,18 @@ module.exports = function Essentials(mod) {
 			unk4: 1
 		})
 	}
+	
+	function start() {
+		stop()
+		interval = setInterval(checkItems, 1000)
+	}
 
-	function randomNumber([min, max]) {
-		return Math.floor(Math.random() * (max - min + 1) + min)
+	function stop() {
+		if (interval) {
+			clearInterval(interval)
+			interval = null
+		}
+		abnormalities = {}
 	}
 
 	// ################ //

+ 9 - 6
manifest.json

@@ -1,18 +1,21 @@
 {
 	"files": {
 		"LICENSE": "589ed823e9a84c56feb95ac58e7cf384626b9cbf4fda2a907bc36e103de1bad2",
-		"README.md": "65d6456545ad06ac132ddbc25d802a86a18d7ad3bb1a5619d19e715365845d09",
-		"index.js": "b98124e4f05e35662f0901657956ef8d968645dc487f35d51704b3971e65a0b7",
-		"module.json": "b44bf1fe879aa4c689f1989756c887ba5e20dafffe3b71f787656d5e3bcd2cbc",
-		"settings_migrator.js": "4a96d898023ad7a73f4fe027ef810cae042d3fe867a24a2a3b7413f1aa923d03"
+		"README.md": "694e0f8fc0bbf35f9386c69074839c74b4414d8fbfbcb14d1a7591894f34d5b6",
+		"config.json": {
+			"overwrite": false,
+			"hash": "a4b1339b7b5438cedc3f91a24e6b845c181c4990f7453f5d6b1822d32ee19f78"
+		},
+		"index.js": "2499119c3bc768e5cef9d72ef2a9c0788fae99dc92f4e14d723f2eb3118b3116",
+		"module.json": "395c3a7be155e332cbfeb2788946f42dc47b195659128bac685813025a192299",
+		"settings_migrator.js": "380eedc5a1e831f62363e4b089a897b0cf606c50b9c5032f9ce2bf5073136a37"
 	},
 	"defs": {
 		"C_PCBANGINVENTORY_USE_SLOT": 1,
-		"C_PLAYER_LOCATION": "raw",
 		"C_USE_ITEM": 3,
 		"S_ABNORMALITY_BEGIN": [2,3],
 		"S_ABNORMALITY_END": 1,
 		"S_ABNORMALITY_REFRESH": 1,
 		"S_PCBANGINVENTORY_DATALIST": 1
 	}
-}
+}

+ 1 - 1
module.json

@@ -2,7 +2,7 @@
     "disableAutoUpdate": false,
     "options": {
         "niceName": "Essentials",
-        "settingsVersion": 1,
+        "settingsVersion": 2,
         "settingsFile": "config.json",
         "settingsMigrator": "settings_migrator.js"
     },

+ 34 - 4
settings_migrator.js

@@ -1,9 +1,12 @@
 "use strict"
 
 const DefaultSettings = {
-    "elite": true,
-    "ccb": 70000,
-    "nostrum": 200999
+	"elite": true,
+	"useNostrum": true,
+	"useCCB": true,
+	"log": false,
+	"nostrum": 200999,
+	"ccb": 70000
 }
 
 module.exports = function MigrateSettings(from_ver, to_ver, settings) {
@@ -15,6 +18,33 @@ module.exports = function MigrateSettings(from_ver, to_ver, settings) {
         return DefaultSettings;
     } else {
         // Migrate from older version (using the new system) to latest one
-        throw new Error('So far there is only one settings version and this should never be reached!');
+        if (from_ver + 1 < to_ver) {
+            // Recursively upgrade in one-version steps
+            settings = MigrateSettings(from_ver, from_ver + 1, settings);
+            return MigrateSettings(from_ver + 1, to_ver, settings);
+        }
+        
+        // If we reach this point it's guaranteed that from_ver === to_ver - 1, so we can implement
+        // a switch for each version step that upgrades to the next version. This enables us to
+        // upgrade from any version to the latest version without additional effort!
+        switch(to_ver)
+        {
+			// keep old settings, add new ones
+			default:
+				let oldsettings = settings
+				
+				settings = Object.assign(DefaultSettings, settings);
+				
+				for(let option in oldsettings) {
+					if(settings[option]) {
+						settings[option] = oldsettings[option]
+					}
+				}
+
+				console.log('[Essentials] Your settings have been updated to version ' + to_ver + '. You can edit the new config file after the next relog.')
+				break;
+        }
+        
+        return settings;
     }
 }