Просмотр исходного кода

some reformat and naming fixes

SaltyMonkey лет назад: 6
Родитель
Сommit
1e71c8d230
8 измененных файлов с 81 добавлено и 75 удалено
  1. 1 1
      README.md
  2. 3 3
      data/migrationData.js
  3. 4 3
      lib/unitControl.js
  4. 21 16
      lib/unitFps.js
  5. 2 2
      lib/unitState.js
  6. 44 44
      lib/unitTracker.js
  7. 5 5
      settings/presets/common.json
  8. 1 1
      settings/settings.json

+ 1 - 1
README.md

@@ -1,4 +1,4 @@
-[![Toolbox](https://img.shields.io/badge/Tera--Toolbox-%40latest-blueviolet)](https://github.com/tera-toolbox) ![](https://api.dependabot.com/badges/status?host=github&repo=SaltyMonkey/fps-manager) ![](https://github.com/SaltyMonkey/fps-manager/workflows/CI/badge.svg)
+[![Toolbox](https://img.shields.io/badge/Tera--Toolbox-%40latest-blueviolet)](https://github.com/tera-toolbox) ![](https://api.dependabot.com/badges/status?host=github&repo=SaltyMonkey/fps-manager) ![](https://github.com/SaltyMonkey/fps-manager/workflows/CI/badge.svg) ![](https://img.shields.io/github/license/SaltyMonkey/fps-manager)
 
 # !!!!!!!!!!!IT IS NOT FINISHED YET!!!!!!!!!!!
 

+ 3 - 3
data/migrationData.js

@@ -5,9 +5,9 @@ const DefaultSettings = {
 	"customCommandTag": "",
 	"interactiveMode": true,
 	"debugMode": false,
-	"applyTriggers": true,
-	"classBasedPresets": true,
-	"trackPresetsChanges": true
+	"classBasedPresets": false,
+	"applyTriggers": false,
+	"trackPresetsChanges": false
 };
 
 module.exports = function MigrateSettings(from_ver, to_ver, settings) {

+ 4 - 3
lib/unitControl.js

@@ -31,6 +31,7 @@ class unitControl {
 
 		const helpHandler = () => {
 			deps.mod.command.message("FPS Manager help.");
+			
 		};
 
 		const autoSettingHandler = () => {
@@ -45,18 +46,18 @@ class unitControl {
 
 		const debugSettingsHandler = () => {
 			deps.mod.settings.debugMode = !deps.mod.settings.debugMode;
-			deps.mod.command.message(`Debug ${deps.mod.settings.debugMode ? "a" : "dea"}ctivated.`);
+			deps.mod.command.message(`Debug mode was ${deps.mod.settings.debugMode ? "a" : "dea"}ctivated.`);
 		};
 
 		const activeModeHandler = (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}.`);
+				deps.mod.command.message(`Mode was changed to "${str}".`);
 				deps.data._eventTrigger();
 			}
 			else {
-				deps.mod.command.message(`Mode ${str} was not found.`);
+				deps.mod.command.message(`Mode "${str}" was not found.`);
 			}
 		};
 

+ 21 - 16
lib/unitFps.js

@@ -25,7 +25,7 @@ class unitFps {
 		const tracker = deps.tracker;
 		const proto = deps.proto;
 
-		let throttledDAta = {};
+		let throttlePacketsData = {};
 
 		const blockedPlayers = new Set();
 		const blockedNpcs = new Set();
@@ -106,6 +106,11 @@ class unitFps {
 						return true;
 					}
 				}
+				else if (data.activeMode.blockPlayersOptions.name) {
+					if (utils.arraysHasIntersect(event.name, data.activeMode.blockPlayersOptions.class)) {
+						return true;
+					}
+				}
 			}
 			return false;
 		};
@@ -163,7 +168,7 @@ class unitFps {
 					blockedNpcs.delete(event.gameId);
 					break;
 				case (ENTITY_HOOK_TYPE.SPAWN):
-					if(tracker.summons.has(event.gameId) && isSummonsBlockable(event)) {
+					if(tracker.spawnedSummons.has(event.gameId) && isSummonsBlockable(event)) {
 						blockedSummons.add(event.gameId);
 						return false;
 					}
@@ -192,20 +197,20 @@ class unitFps {
 		const projectileHandler = (event) => {
 			if (isEntityBlocked(event.gameId)) return false;
 			if (data.activeMode.blockProjectiles && data.activeMode.blockProjectilesOptions) {
-				if (data.activeMode.blockProjectilesOptions.players && tracker.users.has(event.gameId)) return false;
+				if (data.activeMode.blockProjectilesOptions.players && tracker.spawnedPlayers.has(event.gameId)) return false;
 			}
 		};
 
 		const blockAdditionalSkillEffectsHandler = (event) => {
 			if (isEntityBlocked(event.gameId)) return false;
 			if (data.activeMode.blockAdditionalSkillEffects && data.activeMode.blockAdditionalSkillEffectsOptions) {
-				if (data.activeMode.blockAdditionalSkillEffectsOptions.players && tracker.users.has(event.gameId)) return false;
+				if (data.activeMode.blockAdditionalSkillEffectsOptions.players && tracker.spawnedPlayers.has(event.gameId)) return false;
 				if (data.activeMode.blockAdditionalSkillEffectsOptions.own && isMe(event.gameId)) return false;
 			}
 		};
 
 		const smtHandler = (event) => (
-			(data.activeMode.blockAnnoyingScreenMessages && data.smtsSet.has(mod.parseSystemMessage(event.message).id))
+			(data.activeMode.blockAnnoyingScreenMessages && data.smtData.has(mod.parseSystemMessage(event.message).id))
 				? false
 				: undefined
 		);
@@ -220,8 +225,8 @@ class unitFps {
 
 		const throttlePacketsHandler = (name, code, data) => {
 			// eslint-disable-next-line no-magic-numbers
-			let needBlock = (data.activeMode.throttleSomePackets && throttledDAta[name] && (Buffer.compare(throttledDAta[name], data) === 0));
-			throttledDAta[name] = data;
+			let needBlock = (data.activeMode.throttleSomePackets && throttlePacketsData[name] && (Buffer.compare(throttlePacketsData[name], data) === 0));
+			throttlePacketsData[name] = data;
 			return needBlock ? true : undefined;
 		};
 
@@ -272,7 +277,7 @@ class unitFps {
 				return res;
 			}
 			else if (
-				data.activeMode.blockAreaHits && (tracker.users.has(event.owner) || tracker.users.has(event.source))
+				data.activeMode.blockAreaHits && (tracker.spawnedPlayers.has(event.owner) || tracker.spawnedPlayers.has(event.source))
 				&& !isMe(event.target) && !isMe(event.source) && !isMe(event.owner)
 			) {
 				event.skill.id = 0;
@@ -306,7 +311,7 @@ class unitFps {
 			if (isEntityBlocked(event.gameId) || data.activeMode.blockCustomAppearanceChanges) return false;
 		};
 
-		const achievementHandler = () => ((data.activeMode.blockAchievementSpamInCombat && meInCombat()) ? false : undefined);
+		const achievementHandler = () => ((data.activeMode.blockAchievementsInCombat && meInCombat()) ? false : undefined);
 
 		const cleanup = () => {
 			console.log("DEBUG: unitFps -> cleanup");
@@ -401,18 +406,18 @@ class unitFps {
 			if (data.prevMode.blockCollections !== data.activeMode.blockCollections) {
 				switch (data.activeMode.blockCollections) {
 					case (true):
-						for (const value of tracker.collections.values()) {
+						for (const value of tracker.spawnedCollections.values()) {
 							mod.send(...proto.getData("S_DESPAWN_COLLECTION"), value);
 						}
 						break;
 					case (false):
-						for (const value of tracker.collections.values()) {
+						for (const value of tracker.spawnedCollections.values()) {
 							mod.send(...proto.getData("S_SPAWN_COLLECTION"), value);
 						}
 						break;
 				}
 			}
-			for (const [key, value] of tracker.drop.entries()) {
+			for (const [key, value] of tracker.spawnedDrop.entries()) {
 				let needBlock = isDropBlockable(value);
 				if (needBlock && !blockedDrop.has(key)) {
 					mod.send(...proto.getData("S_DESPAWN_DROPITEM"), value);
@@ -424,7 +429,7 @@ class unitFps {
 				}
 			}
 
-			for (const [key, value] of tracker.users.entries()) {
+			for (const [key, value] of tracker.spawnedPlayers.entries()) {
 				let needBlock = isUserBlockable(value);
 				if (needBlock && !blockedPlayers.has(key)) {
 					mod.send(...proto.getData("S_DESPAWN_USER"), value);
@@ -436,7 +441,7 @@ class unitFps {
 				}
 			}
 
-			for (const [key, value] of tracker.servants.entries()) {
+			for (const [key, value] of tracker.spawnedServants.entries()) {
 				let needBlock = isServantBlockable(value);
 				if (needBlock && !blockedServants.has(key)) {
 					mod.send(...proto.getData("S_REQUEST_DESPAWN_SERVANT"), value);
@@ -448,7 +453,7 @@ class unitFps {
 				}
 			}
 
-			for (const [key, value] of tracker.summons.entries()) {
+			for (const [key, value] of tracker.spawnedSummons.entries()) {
 				let needBlock = isSummonsBlockable(value);
 				if (needBlock && !blockedSummons.has(key)) {
 					mod.send(...proto.getData("S_DESPAWN_NPC"), value);
@@ -460,7 +465,7 @@ class unitFps {
 				}
 			}
 
-			for (const [key, value] of tracker.npcs.entries()) {
+			for (const [key, value] of tracker.spawnedNPCS.entries()) {
 				let needBlock = isSummonsBlockable(value);
 				if (needBlock && !blockedNpcs.has(key)) {
 					mod.send(...proto.getData("S_DESPAWN_NPC"), value);

+ 2 - 2
lib/unitState.js

@@ -54,7 +54,7 @@ class unitState extends EventEmitter {
 			"huntingRewardsBuffs": new Set(),
 			"shapeChangersBuffs": new Set(),
 			"onScreenEffectsBuffs": new Set(),
-			"smtsSet": new Set()
+			"smtData": new Set()
 		});
 
 		deps.mod.game.data.abnormalities.forEach(abnormality => {
@@ -86,7 +86,7 @@ class unitState extends EventEmitter {
 
 		this.lockedPacketsData = staticData.blockedProto;
 		this.throttlePacketsData = staticData.throttledProto;
-		this.smtsSet = new Set(...staticData.blockedSmt);
+		this.smtData = new Set(...staticData.blockedSmt);
 
 		this.__mod.hook("S_LOGIN", RAW_HOOK_MODE.EVENT, HOOK_SETTINGS.FIRST, () => {
 			this.preset = this.__mod.settings["classBasedPresets"]

+ 44 - 44
lib/unitTracker.js

@@ -29,73 +29,73 @@ class unitTracker {
 		// sentinel "shapeId": 730500
 
 		Object.assign(this, {
-			"collections": new Map(),
-			"drop": new Map(),
-			"servants": new Map(),
-			"users": new Map(),
-			"npcs": new Map(),
-			"summons": new Map()
+			"spawnedCollections": new Map(),
+			"spawnedDrop": new Map(),
+			"spawnedServants": new Map(),
+			"spawnedPlayers": new Map(),
+			"spawnedNPCS": new Map(),
+			"spawnedSummons": new Map()
 		});
 
 		const dropHandler = (type, event) => {
 			switch (type) {
-				case (ENTITY_HOOK_TYPE.DESPAWN): this.drop.delete(event.gameId); break;
-				case (ENTITY_HOOK_TYPE.SPAWN): this.drop.set(event.gameId, event); break;
+				case (ENTITY_HOOK_TYPE.DESPAWN): this.spawnedDrop.delete(event.gameId); break;
+				case (ENTITY_HOOK_TYPE.SPAWN): this.spawnedDrop.set(event.gameId, event); break;
 			}
 		};
 
 		const collectionHandler = (type, event) => {
 			switch (type) {
-				case (ENTITY_HOOK_TYPE.DESPAWN): this.collections.delete(event.gameId); break;
-				case (ENTITY_HOOK_TYPE.SPAWN): this.collections.set(event.gameId, event); break;
+				case (ENTITY_HOOK_TYPE.DESPAWN): this.spawnedCollections.delete(event.gameId); break;
+				case (ENTITY_HOOK_TYPE.SPAWN): this.spawnedCollections.set(event.gameId, event); break;
 			}
 		};
 
 		const servantsHandler = (type, event) => {
 			switch (type) {
-				case (ENTITY_HOOK_TYPE.DESPAWN): this.servants.delete(event.gameId); break;
-				case (ENTITY_HOOK_TYPE.SPAWN): this.servants.set(event.gameId, event); break;
+				case (ENTITY_HOOK_TYPE.DESPAWN): this.spawnedServants.delete(event.gameId); break;
+				case (ENTITY_HOOK_TYPE.SPAWN): this.spawnedServants.set(event.gameId, event); break;
 			}
 		};
 
 		const userHandler = (type, event) => {
 			switch (type) {
-				case (ENTITY_HOOK_TYPE.DESPAWN): this.users.delete(event.gameId); break;
-				case (ENTITY_HOOK_TYPE.SPAWN): this.users.set(event.gameId, event); break;
+				case (ENTITY_HOOK_TYPE.DESPAWN): this.spawnedPlayers.delete(event.gameId); break;
+				case (ENTITY_HOOK_TYPE.SPAWN): this.spawnedPlayers.set(event.gameId, event); break;
 			}
 		};
 
 		const npcHandler = (type, event) => {
 			switch (type) {
 				case (ENTITY_HOOK_TYPE.DESPAWN):
-					this.npcs.delete(event.gameId);
-					this.summons.delete(event.gameId);
+					this.spawnedNPCS.delete(event.gameId);
+					this.spawnedSummons.delete(event.gameId);
 					break;
 				case (ENTITY_HOOK_TYPE.SPAWN):
 					// eslint-disable-next-line no-magic-numbers
-					if (event.huntingZoneId === SPECIAL_ZONES.HELPERS && this.users.has(event.owner)) {
-						this.summons.set(event.gameId, event);
+					if (event.huntingZoneId === SPECIAL_ZONES.HELPERS && this.spawnedPlayers.has(event.owner)) {
+						this.spawnedSummons.set(event.gameId, event);
 					}
 					else {
-						this.npcs.set(event.gameId, event);
+						this.spawnedNPCS.set(event.gameId, event);
 					}
 					break;
 			}
 		};
 
 		const userMounted = (type, event) => {
-			if (this.users.has(event.gameId)) {
+			if (this.spawnedPlayers.has(event.gameId)) {
 				let data = undefined;
 				switch (type) {
 					case (ENTITY_HOOK_TYPE.DESPAWN):
-						data = this.users.get(event.gameId);
+						data = this.spawnedPlayers.get(event.gameId);
 						data.mount = 0;
-						this.users.set(event.gameId, data);
+						this.spawnedPlayers.set(event.gameId, data);
 						break;
 					case (ENTITY_HOOK_TYPE.SPAWN):
-						data = this.users.get(event.gameId);
+						data = this.spawnedPlayers.get(event.gameId);
 						data.mount = event.id;
-						this.users.set(event.gameId, data);
+						this.spawnedPlayers.set(event.gameId, data);
 						break;
 				}
 			}
@@ -107,46 +107,46 @@ class unitTracker {
 
 		const updateAngleHandler = (event) => {
 			let gameId = event.gameId;
-			if (this.users.has(gameId)) this.users.set(gameId, updateAngle(this.users.get(gameId), event.w));
-			else if (this.npcs.has(gameId)) this.npcs.set(gameId, updateAngle(this.npcs.get(gameId), event.w));
-			else if (this.summons.has(gameId)) this.summons.set(gameId, updateAngle(this.summons.get(gameId), event.w));
+			if (this.spawnedPlayers.has(gameId)) this.spawnedPlayers.set(gameId, updateAngle(this.spawnedPlayers.get(gameId), event.w));
+			else if (this.spawnedNPCS.has(gameId)) this.spawnedNPCS.set(gameId, updateAngle(this.spawnedNPCS.get(gameId), event.w));
+			else if (this.spawnedSummons.has(gameId)) this.spawnedSummons.set(gameId, updateAngle(this.spawnedSummons.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));
+			if (this.spawnedPlayers.has(event.gameId)) {
+				this.spawnedPlayers.set(event.gameId, updateLoc(this.spawnedPlayers.get(event.gameId), event.loc));
 			}
 		};
 
 		const npcLocationHandler = (event) => {
-			if (this.npcs.has(event.gameId)) {
-				this.npcs.set(event.gameId, updateLoc(this.npcs.get(event.gameId), event.loc));
+			if (this.spawnedNPCS.has(event.gameId)) {
+				this.spawnedNPCS.set(event.gameId, updateLoc(this.spawnedNPCS.get(event.gameId), event.loc));
 			}
-			else if (this.summons.has(event.gameId)) {
-				this.summons.set(event.gameId, updateLoc(this.summons.get(event.gameId), event.loc));
+			else if (this.spawnedSummons.has(event.gameId)) {
+				this.spawnedSummons.set(event.gameId, updateLoc(this.spawnedSummons.get(event.gameId), event.loc));
 			}
-			else if (this.servants.has(event.gameId)) {
-				this.servants.set(event.gameId, updateLoc(this.servants.get(event.gameId), event.loc));
+			else if (this.spawnedServants.has(event.gameId)) {
+				this.spawnedServants.set(event.gameId, updateLoc(this.spawnedServants.get(event.gameId), event.loc));
 			}
 		};
 
 		const creatureLifeHandler = (event) => {
-			if (this.users.has(event.gameId)) {
-				let data = this.users.get(event.gameId);
+			if (this.spawnedPlayers.has(event.gameId)) {
+				let data = this.spawnedPlayers.get(event.gameId);
 				data.alive = event.alive;
-				this.users.set(event.gameId, data);
+				this.spawnedPlayers.set(event.gameId, data);
 			}
 		};
 
 		const cleanup = () => {
 			console.log("DEBUG: unitTracker -> cleanup");
-			this.npcs.clear();
-			this.summons.clear();
-			this.users.clear();
-			this.servants.clear();
-			this.collections.clear();
-			this.drop.clear();
+			this.spawnedNPCS.clear();
+			this.spawnedSummons.clear();
+			this.spawnedPlayers.clear();
+			this.spawnedServants.clear();
+			this.spawnedCollections.clear();
+			this.spawnedDrop.clear();
 		};
 
 		mod.hook(...proto.getData("S_CREATURE_ROTATE"), HOOK_SETTINGS.FIRST, updateAngleHandler);

+ 5 - 5
settings/presets/common.json

@@ -3,8 +3,7 @@
 		"default": "default",
 		"triggerGuardians": "default",
 		"triggerDungeons": {
-			"all": "default",
-			"vanigayId": "vanigay"
+			"all": "default"
 		},
 		"triggerCU": "default",
 		"triggerBG": "default",
@@ -16,7 +15,7 @@
 		"blockUselessPackets": false,
 		"blockAnnoyingScreenMessages": false,
 		"blockNpcsDeathAnimations": false,
-		"blockAchievementSpamInCombat": false,
+		"blockAchievementsInCombat": false,
 		"blockInventoryInCombat": false,
 		"blockHuntingRewardsBuffs": false,
 		"blockShapeChangeBuffs": false,
@@ -33,12 +32,12 @@
 		"blockOwnSummons": false,
 		"blockAreaSummons": false,
 		"blockCollections": false,
-		"blockProjectiles": false,
 		"blockAdditionalSkillEffects": false,
 		"blockAdditionalSkillEffectsOptions": {
 			"own": false,
 			"players": false
 		},
+		"blockProjectiles": false,
 		"blockProjectilesOptions": {
 			"players": true
 		},
@@ -55,7 +54,8 @@
 		"blockPlayers": false,
 		"blockPlayersOptions": {
 			"all": false,
-			"class": []
+			"class": [],
+			"name": []
 		}
 	}
 }

+ 1 - 1
settings/settings.json

@@ -3,7 +3,7 @@
 	"customCommandTag": "",
 	"interactiveMode": true,
 	"debugMode": false,
-	"applyTriggers": true,
 	"classBasedPresets": true,
+	"applyTriggers": true,
 	"trackPresetsChanges": true
 }