UNPKG

md5-fight-plus

Version:

178 lines (177 loc) 5.62 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPlayerHook = exports.loadPlayer = exports.createPlayer = void 0; const blueimp_md5_1 = __importDefault(require("blueimp-md5")); const SyncBailHook_1 = require("../hooks/SyncBailHook"); function calculateProperty(name) { const encryptedMd5Hex = (0, blueimp_md5_1.default)(name); // Generates Player's ID. const propertyNumber = []; for (let i = 0; i < 16; i += 1) { const piece = encryptedMd5Hex.slice(i * 2, (i + 1) * 2); const convertedNumber = parseInt(piece, 16) / 2.55; propertyNumber.push(Math.floor(convertedNumber)); } return propertyNumber; } function getBaseProperty(dataSources) { const baseProperty = { STR: 0, SPD: 0, MANA: 0, CON: 0, }; let total = 0; for (const key in baseProperty) { const val = dataSources.shift(); const valAdjusted = val; baseProperty[key] += val; //调整基础值 total += valAdjusted; } adjustPropertyBefore(baseProperty, total); return baseProperty; } function adjustPropertyBefore(baseProperty, total) { //调整生命值 let max = -1; let maxKey = ""; for (const key in baseProperty) { if (max < baseProperty[key]) { max = baseProperty[key]; maxKey = key; } } // if (maxKey !== 'CON') { // baseProperty[maxKey] = baseProperty['CON'] // baseProperty['CON'] = max; // } //x基数 for (const key in baseProperty) { baseProperty[key] = (baseProperty[key] * 40) / total; } if (baseProperty["SPD"] < 3) baseProperty["SPD"] = 3; baseProperty["MANA"] = baseProperty["MANA"] + 3; baseProperty[maxKey] = baseProperty[maxKey] - 3; // //调整攻击力 // if (baseProperty['STR'] > 7) { // const diff = baseProperty['STR'] * 0.4 // baseProperty['STR'] -= diff; // baseProperty['CON'] += diff * 0.9 // baseProperty['MANA'] += diff * 0.1 // } // if (baseProperty['STR'] < 0.5) { // baseProperty['STR'] += 1 // } //规整化数字 for (const key in baseProperty) { baseProperty[key] = Math.round(baseProperty[key]); } } const createPlayer = function (name) { const md5Numbers = calculateProperty(name); //属性设定 const baseProperty = getBaseProperty(md5Numbers); //等级设定 const level = 1; //技能组 const skills = ["a", "a", "a", "a", "a"]; //hooks列表 const hooks = (0, exports.createPlayerHook)(); const runtimeProperty = { hp: undefined, attack: undefined, speed: undefined, mana: undefined, stunned: false, firing: 0, frostbite: 0, poison: 0, armor: 0, }; const runtimeContext = { actionTimes: 0, //行动计数 roundCount: 0, skills: [], }; const playerParameter = { name, baseProperty, level, skills, hooks, runtimeProperty, runtimeContext, battleField: undefined, }; hooks.initProperty.call(playerParameter); const currentPlayer = playerParameter; return currentPlayer; }; exports.createPlayer = createPlayer; const loadPlayer = function (config) { const md5Numbers = calculateProperty(config.name); //属性设定 const baseProperty = config.baseProperty; //等级设定 const level = config.level; //技能组 const skills = config.skills; //hooks列表 const hooks = (0, exports.createPlayerHook)(); const runtimeProperty = { hp: undefined, attack: undefined, speed: undefined, mana: undefined, stunned: false, firing: 0, frostbite: 0, poison: 0, armor: 0, }; const runtimeContext = { actionTimes: 0, //行动计数 roundCount: 0, skills: [], }; const playerParameter = { name: config.name, baseProperty, level, skills, hooks, runtimeProperty, runtimeContext, battleField: undefined, }; hooks.initProperty.call(playerParameter); const currentPlayer = playerParameter; return currentPlayer; }; exports.loadPlayer = loadPlayer; const createPlayerHook = () => { const hooks = { initProperty: new SyncBailHook_1.SyncBailHook(), prepare: new SyncBailHook_1.SyncBailHook(), beforeAttack: new SyncBailHook_1.SyncBailHook(), beforeUnderAttack: new SyncBailHook_1.SyncBailHook(), onAttack: new SyncBailHook_1.SyncBailHook(), onUnderAttack: new SyncBailHook_1.SyncBailHook(), afterAttack: new SyncBailHook_1.SyncBailHook(), afterUnderAttack: new SyncBailHook_1.SyncBailHook(), onAdjustHp: new SyncBailHook_1.SyncBailHook(), onAdjustManaBefore: new SyncBailHook_1.SyncBailHook(), onAdjustMana: new SyncBailHook_1.SyncBailHook(), onAdjustFrostbite: new SyncBailHook_1.SyncBailHook(), onAdjustFiring: new SyncBailHook_1.SyncBailHook(), onAdjustPoison: new SyncBailHook_1.SyncBailHook(), onAdjustArmor: new SyncBailHook_1.SyncBailHook(), onAdjustSpeed: new SyncBailHook_1.SyncBailHook(), onAdjustAttack: new SyncBailHook_1.SyncBailHook(), }; return hooks; }; exports.createPlayerHook = createPlayerHook;