Browse Source

mounted state for tracker, styling

SaltyMonkey 6 years ago
parent
commit
fc27926eb1
7 changed files with 48 additions and 25 deletions
  1. 1 1
      data/migrationData.js
  2. 6 0
      data/protoData.json
  3. 3 3
      lib/unitControl.js
  4. 3 1
      lib/unitFps.js
  5. 1 1
      lib/unitProto.js
  6. 10 10
      lib/unitState.js
  7. 24 9
      lib/unitTracker.js

+ 1 - 1
data/migrationData.js

@@ -13,7 +13,7 @@ const DefaultSettings = {
 module.exports = function MigrateSettings(from_ver, to_ver, settings) {
 	if (from_ver === undefined) {
 		// Migrate legacy config file
-		return {...DefaultSettings, ...settings};
+		return { ...DefaultSettings, ...settings };
 	} else if (from_ver === null) {
 		// No config file exists, use default settings
 		return DefaultSettings;

+ 6 - 0
data/protoData.json

@@ -133,5 +133,11 @@
 	},
 	"S_USER_LOCATION_IN_ACTION": {
 		"default": 2
+	},
+	"S_MOUNT_VEHICLE": {
+		"default": 2
+	},
+	"S_UNMOUNT_VEHICLE": {
+		"default": 2
 	}
 }

+ 3 - 3
lib/unitControl.js

@@ -22,7 +22,7 @@ class unitControl {
 
 		console.log("DEBUG: unitControl -> constructor");
 
-		if(deps.mod.settings.customCommandTag && deps.mod.settings.customCommandTag.length)
+		if (deps.mod.settings.customCommandTag && deps.mod.settings.customCommandTag.length)
 			prefixes.push(deps.mod.settings.customCommandTag);
 
 		const infoHandler = () => {
@@ -49,7 +49,7 @@ class unitControl {
 		};
 
 		const activeModeHandler = (str) => {
-			if(deps.data.preset[str]) {
+			if (deps.data.preset[str]) {
 				deps.data.prevMode = rfdc(deps.data.activeMode);
 				deps.data.activeMode = deps.data.preset[str];
 				deps.mod.command.message(`Mode was changed to ${str}.`);
@@ -75,7 +75,7 @@ class unitControl {
 			"debug": debugSettingsHandler
 		};
 
-		if(deps.mod.settings.enableCommands)
+		if (deps.mod.settings.enableCommands)
 			deps.mod.command.add(prefixes, commands);
 	}
 }

+ 3 - 1
lib/unitFps.js

@@ -363,7 +363,9 @@ class unitFps {
 		mod.hook(...proto.getData("S_CREATURE_ROTATE"), HOOK_SETTINGS.LAST, dropIfBlockedHandler);
 		mod.hook(...proto.getData("S_CREATURE_LIFE"), HOOK_SETTINGS.LAST, dropIfBlockedHandler);
 		mod.hook(...proto.getData("S_NPC_LOCATION"), HOOK_SETTINGS.LAST, dropIfBlockedHandler);
-
+		mod.hook(...proto.getData("S_MOUNT_VEHICLE"), HOOK_SETTINGS.LAST, dropIfBlockedHandler);
+		mod.hook(...proto.getData("S_UNMOUNT_VEHICLE"), HOOK_SETTINGS.LAST, dropIfBlockedHandler);
+		
 		//---------------------------------------
 		// Combined hooks with complicated logic
 		//---------------------------------------

+ 1 - 1
lib/unitProto.js

@@ -31,7 +31,7 @@ class unitProto {
 	 */
 	getData(defName) {
 		let version = proto[defName][this.__mod.majorPatchVersion];
-		return version ? [defName, version]	: [defName, proto[defName].default];
+		return version ? [defName, version] : [defName, proto[defName].default];
 	}
 
 }

+ 10 - 10
lib/unitState.js

@@ -33,13 +33,13 @@ class unitState extends EventEmitter {
 	 */
 	constructor(deps) {
 		super();
-		
+
 		console.log("DEBUG: unitState -> constructor");
 
 		this.__mod = deps.mod;
 		this.__proto = deps.proto;
 		this.__fps = deps.fps;
-		
+
 		Object.assign(this, {
 			//main properties for state management
 			"presets": {}, // all loaded per class presets
@@ -100,9 +100,9 @@ class unitState extends EventEmitter {
 
 		this.__mod.hook(...this.__proto.getData("S_LOAD_TOPO"), HOOK_SETTINGS.FIRST, (event) => {
 			if (!this.__mod.settings["applyTrigger"] || equal(this.prevMode, this.activeMode)) return;
-			
+
 			this.prevMode = rfdc(this.activeMode);
-		
+
 			if (this.__mod.game.me.inOpenWorld && this.preset.directives.triggerOW) {
 				this.activeMode = this.preset[this.preset.directives.triggerOW];
 			}
@@ -113,25 +113,25 @@ class unitState extends EventEmitter {
 				this.activeMode = this.preset[this.preset.directives.triggerCU];
 			}
 			else if (this.__mod.game.me.inDungeon && this.preset.directives.triggerDungeons) {
-				this.activeMode = this.preset[this.preset.directives.triggerDungeons[event.zone]] || 
-								this.preset[this.preset.directives.triggerDungeons["all"]];
+				this.activeMode = this.preset[this.preset.directives.triggerDungeons[event.zone]] ||
+					this.preset[this.preset.directives.triggerDungeons["all"]];
 			}
 		});
 
 		this.__mod.hook("S_FIELD_EVENT_ON_ENTER", RAW_HOOK_MODE.EVENT, HOOK_SETTINGS.FIRST, () => {
 			if (!this.__mod.settings["applyTrigger"] || equal(this.prevMode, this.activeMode)) return;
-			
+
 			this.prevMode = rfdc(this.activeMode);
-			
+
 			this.activeMode = this.preset[this.preset.directives.triggerGuardians];
 			this._eventTrigger();
 		});
 
 		this.__mod.hook("S_FIELD_EVENT_ON_LEAVE", RAW_HOOK_MODE.EVENT, HOOK_SETTINGS.FIRST, () => {
 			if (!this.__mod.settings["applyTrigger"] || equal(this.prevMode, this.activeMode)) return;
-			
+
 			this.activeMode = rfdc(this.prevMode);
-			
+
 			this._eventTrigger();
 		});
 	}

+ 24 - 9
lib/unitTracker.js

@@ -21,9 +21,9 @@ class unitTracker {
 	constructor(deps) {
 		const mod = deps.mod;
 		const proto = deps.proto;
-		
+
 		console.log("DEBUG: unitTracker -> constructor");
-		
+
 		// portals "shapeId": 652992,
 		// ninja log "shapeId": 303030
 		// sentinel "shapeId": 730500
@@ -83,8 +83,26 @@ class unitTracker {
 			}
 		};
 
+		const userMounted = (type, event) => {
+			if (this.users.has(event.gameId)) {
+				let data = undefined;
+				switch (type) {
+					case (ENTITY_HOOK_TYPE.DESPAWN):
+						data = this.users.get(event.gameId);
+						data.mount = 0;
+						this.users.set(event.gameId, data);
+						break;
+					case (ENTITY_HOOK_TYPE.SPAWN):
+						data = this.users.get(event.gameId);
+						data.mount = event.id;
+						this.users.set(event.gameId, data);
+						break;
+				}
+			}
+		};
+
 		const updateAngle = (data, w) => data.loc.w = w;
-		
+
 		const updateLoc = (data, loc) => data.loc = loc;
 
 		const updateAngleHandler = (event) => {
@@ -94,7 +112,7 @@ class unitTracker {
 			else if (this.summons.has(gameId)) this.summons.set(gameId, updateAngle(this.summons.get(gameId), event.w));
 		};
 
-		
+
 		const userLocationHandler = (event) => {
 			if (this.users.has(event.gameId)) {
 				this.users.set(event.gameId, updateLoc(this.users.get(event.gameId), event.loc));
@@ -136,11 +154,8 @@ class unitTracker {
 		mod.hook(...proto.getData("S_NPC_LOCATION"), HOOK_SETTINGS.FIRST, npcLocationHandler);
 		mod.hook(...proto.getData("S_USER_LOCATION"), HOOK_SETTINGS.FIRST, userLocationHandler);
 		mod.hook(...proto.getData("S_USER_LOCATION_IN_ACTION"), HOOK_SETTINGS.FIRST, userLocationHandler);
-
-		//mod.hook("S_ACTION_STAGE", HOOK_SETTINGS.FIRST, locFromAction);
-		//mod.hook("S_ACTION_END", HOOK_SETTINGS.FIRST, locFromAction);
-		//mod.hook(...def.getVersion("S_EACH_SKILL_RESULT"), HOOK_SETTINGS.FIRST, eachResultUpdate);
-
+		mod.hook(...proto.getData("S_MOUNT_VEHICLE"), HOOK_SETTINGS.FIRST, userMounted.bind(null, ENTITY_HOOK_TYPE.SPAWN));
+		mod.hook(...proto.getData("S_UNMOUNT_VEHICLE"), HOOK_SETTINGS.FIRST, userMounted.bind(null, ENTITY_HOOK_TYPE.SPAWN));
 
 		mod.hook(...proto.getData("S_SPAWN_NPC"), HOOK_SETTINGS.FIRST, npcHandler.bind(null, ENTITY_HOOK_TYPE.SPAWN));
 		mod.hook(...proto.getData("S_DESPAWN_NPC"), HOOK_SETTINGS.FIRST, npcHandler.bind(null, ENTITY_HOOK_TYPE.DESPAWN));