Browse Source

update for require fix

TeraProxy 8 years ago
parent
commit
c28fd24936
6 changed files with 143 additions and 117 deletions
  1. 73 77
      README.md
  2. 8 0
      config.json
  3. 26 30
      index.js
  4. 6 7
      manifest.json
  5. 10 3
      module.json
  6. 20 0
      settings_migrator.js

+ 73 - 77
README.md

@@ -1,78 +1,74 @@
-##### :heavy_exclamation_mark: Status :heavy_exclamation_mark:
-Should work on all regions as long as the opcodes are mapped but I personally only test modules on NA with Caali's tera-proxy: https://discord.gg/maqBmJV  
-
-##### :heavy_exclamation_mark: Installation for Caali's tera-proxy :heavy_exclamation_mark:
-1) Download Essentials: https://github.com/TeraProxy/Essentials/archive/master.zip
-2) Extract the contents of the zip file into "\tera-proxy\bin\node_modules\"
-3) Done! (the module will auto-update when a new version is released)
-
-##### :heavy_exclamation_mark: Installation for PinkiePie's tera-proxy :heavy_exclamation_mark:
-1) Update your tera-data: https://github.com/meishuu/tera-data
-2) Download Essentials: https://github.com/TeraProxy/Essentials/archive/master.zip
-3) Download tera-game-state: https://github.com/hackerman-caali/tera-game-state/archive/master.zip
-4) Extract the contents of both zip files into "\tera-proxy\bin\node_modules\"
-5) Done!
-6) Check back here once in a while for updates
-
-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.  
-
-## Usage
-If you don't have Elite/Club status, you can open up "config_1-3-6.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_1-3-6.json".  
-  
-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.  
-The following commands are supported:  
-  
-* essentials - enable/disable Essentials
-
-## Safety
-Whatever you send to the proxy chat in game is intercepted client-side. The chat is NOT sent to the server.  
-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
-
-## Changelog
-<details>
-
-### 1.3.6
-* [+] Added option for using different CCB items to config file
-* [+] Added option for using different non-elite nostrums to config file ("ELITE" has to be set to false to use these)
-* [+] Added Phoenix mount revival invincibility check
-* [*] Code optimizations
-### 1.3.5
-* [*] Fixed trying to use CCB when you are under the influence of the 1h CCB
-### 1.3.4
-* [+] Added option to use Prime Battle Solution instead of Everful Nostrum
-* [*] More code cleanup
-### 1.3.3
-* [+] Now supports all regions
-* [+] Rewrote code to use Caali's "tera-game-state" module in order to reduce overhead
-* [+] Now supports auto-updating via Caali's tera-proxy
-### 1.3.2
-* [*] Updated hook versions for compatibility with the latest tera-proxy
-### 1.3.1
-* [*] Fixed an issue of Nostrum not being reapplied when ressurecting quickly with Grace/Vow
-### 1.3.0
-* [+] The random timer for Nostrum now waits for loading to be finished before it starts instead of being hardcoded
-* [+] Will now wait until your Goddess Blessing buff ended before it uses Nostrum so you stay immune to damage
-### 1.2.3
-* [*] Using newer version of S_ABNORMALITY_BEGIN hook
-### 1.2.2
-* [*] Fixed trying to use CCB when players already have the new Elite CCB running
-### 1.2.1
-* [*] Full conversion to Pinkie Pie's command module
-### 1.2.0
-* [+] Added support for Pinkie Pie's command module which is now a requirement
-* [+] Added randomized timers
-* [-] Removed hiding messages and buff timer functions
-### 1.1.0
-* [+] Added !essentials command to toggle between "on" and "off" in non-whisper chats
-### 1.0.0
-* [~] Initial Release
-
+##### :heavy_exclamation_mark: Status :heavy_exclamation_mark:
+Should work on all regions as long as the opcodes are mapped but I personally only test modules on NA with Caali's tera-proxy: https://discord.gg/maqBmJV  
+
+##### :heavy_exclamation_mark: Installation for Caali's tera-proxy :heavy_exclamation_mark:
+1) Download Essentials: https://github.com/TeraProxy/Essentials/archive/master.zip
+2) Extract the contents of the zip file into "\tera-proxy\bin\node_modules\"
+3) Done! (the module will auto-update when a new version is released)
+  
+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.  
+
+## 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".  
+  
+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.  
+The following commands are supported:  
+  
+* essentials - enable/disable Essentials
+
+## Safety
+Whatever you send to the proxy chat in game is intercepted client-side. The chat is NOT sent to the server.  
+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
+
+## Changelog
+<details>
+
+### 1.3.7
+* [*] Fixed non-elite Nostrum not properly applying (thx aurelius88)
+* [~] Code changes due to Caali's recent tera-proxy updates
+* [-] Removed support for Pinkie Pie's tera-proxy
+### 1.3.6
+* [+] Added option for using different CCB items to config file
+* [+] Added option for using different non-elite nostrums to config file ("ELITE" has to be set to false to use these)
+* [+] Added Phoenix mount revival invincibility check
+* [*] Code optimizations
+### 1.3.5
+* [*] Fixed trying to use CCB when you are under the influence of the 1h CCB
+### 1.3.4
+* [+] Added option to use Prime Battle Solution instead of Everful Nostrum
+* [*] More code cleanup
+### 1.3.3
+* [+] Now supports all regions
+* [+] Rewrote code to use Caali's "tera-game-state" module in order to reduce overhead
+* [+] Now supports auto-updating via Caali's tera-proxy
+### 1.3.2
+* [*] Updated hook versions for compatibility with the latest tera-proxy
+### 1.3.1
+* [*] Fixed an issue of Nostrum not being reapplied when ressurecting quickly with Grace/Vow
+### 1.3.0
+* [+] The random timer for Nostrum now waits for loading to be finished before it starts instead of being hardcoded
+* [+] Will now wait until your Goddess Blessing buff ended before it uses Nostrum so you stay immune to damage
+### 1.2.3
+* [*] Using newer version of S_ABNORMALITY_BEGIN hook
+### 1.2.2
+* [*] Fixed trying to use CCB when players already have the new Elite CCB running
+### 1.2.1
+* [*] Full conversion to Pinkie Pie's command module
+### 1.2.0
+* [+] Added support for Pinkie Pie's command module which is now a requirement
+* [+] Added randomized timers
+* [-] Removed hiding messages and buff timer functions
+### 1.1.0
+* [+] Added !essentials command to toggle between "on" and "off" in non-whisper chats
+### 1.0.0
+* [~] Initial Release
+
 </details>

+ 8 - 0
config.json

@@ -0,0 +1,8 @@
+{
+    "version": 1,
+    "data": {
+        "elite": true,
+        "ccb": 70000,
+        "nostrum": 200999
+    }
+}

+ 26 - 30
index.js

@@ -1,16 +1,9 @@
-// Version 1.3.6
+// Version 1.3.7
 // Based on true-everful-nostrum by Pinkie Pie https://github.com/pinkipi
 
 'use strict'
 
-const Command = require('command'),
-	GameState = require('tera-game-state'),
-	Config = require('./config_1-3-6')
-
 const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604], // EU, NA, RU, TW, ?, ?, ?, TH
-	ELITE = Config.elite,
-	ITEM_PLEB_NOSTRUM = Config.nostrum,
-	ITEM_CCB = Config.ccb,
 	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)
@@ -18,10 +11,13 @@ const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 8
 	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)
 
-module.exports = function Essentials(dispatch) {
-	const command = Command(dispatch),
-		game = GameState(dispatch)
-	game.initialize("contract")
+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,
@@ -36,26 +32,26 @@ module.exports = function Essentials(dispatch) {
 	// ### Hooks ### //
 	// ############# //
 
-	game.on('enter_game', () => {
+	mod.game.on('enter_game', () => {
 		hasccb = false
 
-		dispatch.hookOnce('C_PLAYER_LOCATION', 'raw', () => {
+		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
 		})
 	})
 
-	game.on('leave_loading_screen', () => {
-		dispatch.hookOnce('C_PLAYER_LOCATION', 'raw', () => { nostrum() })
+	mod.game.on('leave_loading_screen', () => {
+		mod.hookOnce('C_PLAYER_LOCATION', 'raw', () => { nostrum() })
 	})
 
-	game.me.on('die', () => { 
+	mod.game.me.on('die', () => { 
 		nextUse = 0
 		nostrum()
 	})
-	game.me.on('resurrect', () => { nostrum() })
+	mod.game.me.on('resurrect', () => { nostrum() })
 
-	dispatch.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
+	mod.hook('S_PCBANGINVENTORY_DATALIST', 1, event => {
 		for(let item of event.inventory)
 			if(ITEMS_NOSTRUM.includes(item.item)) {
 				slot = item.slot
@@ -65,16 +61,16 @@ module.exports = function Essentials(dispatch) {
 			}
 	})
 
-	dispatch.hook('S_ABNORMALITY_BEGIN', 2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
-	dispatch.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
-	dispatch.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
+	mod.hook('S_ABNORMALITY_BEGIN', 2, abnormality.bind(null, 'S_ABNORMALITY_BEGIN'))
+	mod.hook('S_ABNORMALITY_REFRESH', 1, abnormality.bind(null, 'S_ABNORMALITY_REFRESH'))
+	mod.hook('S_ABNORMALITY_END', 1, abnormality.bind(null, 'S_ABNORMALITY_END'))
 
 	// ################# //
 	// ### Functions ### //
 	// ################# //
 
 	function abnormality(type, event) {
-		if(game.me.is(event.target)) {
+		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
@@ -98,14 +94,14 @@ module.exports = function Essentials(dispatch) {
 	function nostrum() {
 		clearTimeout(timeoutNostrum)
 		
-		if(game.isIngame && game.me.alive && !game.isInLoadingScreen && !game.me.mounted && !game.contract.active && !game.me.inBattleground && slot && !iAmInvincible)
+		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 ccb() {
 		clearTimeout(timeoutCCB)
 		
-		if(!hasccb && game.isIngame && game.me.alive && !game.isInLoadingScreen && !game.me.mounted && !game.contract.active && !game.me.inBattleground) useItem(ITEM_CCB)
+		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
 	}
 
@@ -114,7 +110,7 @@ module.exports = function Essentials(dispatch) {
 
 		if(time >= cooldown) {
 			if(enabled) {
-				if(ELITE) dispatch.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
+				if(ELITE) mod.toServer('C_PCBANGINVENTORY_USE_SLOT', 1, {slot})
 				else useItem(ITEM_PLEB_NOSTRUM)
 			}
 			nextUse = Date.now() + randomNumber(RANDOM_MIN_MAX)
@@ -126,8 +122,8 @@ module.exports = function Essentials(dispatch) {
 	function useItem(item) {
 		if(!enabled) return
 		
-		dispatch.toServer('C_USE_ITEM', 3, {
-			gameId: game.me.gameId,
+		mod.toServer('C_USE_ITEM', 3, {
+			gameId: mod.game.me.gameId,
 			id: item,
 			dbid: 0,
 			target: 0,
@@ -150,9 +146,9 @@ module.exports = function Essentials(dispatch) {
 	// ### Commands ### //
 	// ################ //
 
-	command.add('essentials', () => {
+	mod.command.add('essentials', () => {
 		enabled = !enabled
-		command.message('[Essentials] ' + (enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
+		mod.command.message((enabled ? '<font color="#56B4E9">enabled</font>' : '<font color="#E69F00">disabled</font>'))
 		console.log('[Essentials] ' + (enabled ? 'enabled' : 'disabled'))
 	})
 }

+ 6 - 7
manifest.json

@@ -1,17 +1,16 @@
 {
 	"force_clean": true,
 	"files": {
-		"config_1-3-6.json": {
-			"overwrite": false,
-			"hash": "add4c2e726e87d83b70a4bb057a82d7680f9839d26c3dd7da9acba953e070f9b"
-		},
-		"index.js": "c6e6bb6b35fa3958c83a9c78a1566df4dc84c7503a7dd58a3fe310b27a6ce016",
 		"LICENSE": "589ed823e9a84c56feb95ac58e7cf384626b9cbf4fda2a907bc36e103de1bad2",
-		"module.json": "4475b48560557f54b45de6542301c25a0f6fbb50d2d4489906ded2ddd8ac7f5f",
-		"README.md": "4959689fcbb984dc078436bb244448ae7c9b6606af2c97f17cb3a2dd60e909ac"
+		"README.md": "dee0e93c688f4b4642043a61fb12e55b5c5684616b8405dd2f03867a1985b8cc",
+		"config.json": "f2f129d4bbb4b84f0a85ac5e23720f703e972ffb6a1219112b5dd87f7e9db5ac",
+		"index.js": "9f49f83b3068ed423d1d4f9521578edf7757102fe592e484feb8cd32c73bcf1b",
+		"module.json": "b44bf1fe879aa4c689f1989756c887ba5e20dafffe3b71f787656d5e3bcd2cbc",
+		"settings_migrator.js": "4a96d898023ad7a73f4fe027ef810cae042d3fe867a24a2a3b7413f1aa923d03"
 	},
 	"defs": {
 		"C_PCBANGINVENTORY_USE_SLOT": 1,
+		"C_PLAYER_LOCATION": "raw",
 		"C_USE_ITEM": 3,
 		"S_ABNORMALITY_BEGIN": 2,
 		"S_ABNORMALITY_END": 1,

+ 10 - 3
module.json

@@ -1,4 +1,11 @@
-{
-    "servers": ["https://raw.githubusercontent.com/TeraProxy/Essentials/master/"],
-    "supportUrl": "https://github.com/TeraProxy/Essentials/issues"
+{
+    "disableAutoUpdate": false,
+    "options": {
+        "niceName": "Essentials",
+        "settingsVersion": 1,
+        "settingsFile": "config.json",
+        "settingsMigrator": "settings_migrator.js"
+    },
+    "servers": ["https://raw.githubusercontent.com/TeraProxy/Essentials/master/"],
+    "supportUrl": "https://github.com/TeraProxy/Essentials/issues"
 }

+ 20 - 0
settings_migrator.js

@@ -0,0 +1,20 @@
+"use strict"
+
+const DefaultSettings = {
+    "elite": true,
+    "ccb": 70000,
+    "nostrum": 200999
+}
+
+module.exports = function MigrateSettings(from_ver, to_ver, settings) {
+    if (from_ver === undefined) {
+        // Migrate legacy config file
+        return Object.assign(Object.assign({}, DefaultSettings), settings);
+    } else if (from_ver === null) {
+        // No config file exists, use default 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!');
+    }
+}