UNPKG

md5-fight-plus

Version:

107 lines (106 loc) 4.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerHooks = registerHooks; const utils_1 = require("../../player/utils"); const utils_2 = require("../../utils"); const index_1 = __importDefault(require("../../skills/index")); const registerFrostbiteHook_1 = require("./registerFrostbiteHook"); const registerFiring_1 = require("./registerFiring"); const registerPosion_1 = require("./registerPosion"); function registerHooks(battleField) { initFightStart(battleField); (0, registerFrostbiteHook_1.initBuffFrostbite)(battleField); (0, registerFiring_1.initBuffFiring)(battleField); (0, registerPosion_1.initBuffPoison)(battleField); initAdjustRuntime(battleField); } function initFightStart(battleField) { battleField.hooks.fightStart.tap("init runtimeProperty", (battleField) => { //初始化runtime const { player1, player2 } = (0, utils_2.getPlayers)(battleField); calRunTime(player1); calRunTime(player2); (0, utils_1.initActionTimes)(player1, player2); return battleField; }); battleField.hooks.fightStart.tap("fill skills", (battleField) => { // 填充技能组,这是由于玩家一开始设置的战斗技能组形如 ['k1','k2','k3'],这里要根据id(k1)填充技能类 const { player1, player2 } = (0, utils_2.getPlayers)(battleField); fillSkill(player1); fillSkill(player2); return battleField; }); } function calRunTime(player) { player.runtimeProperty.hp = player.baseProperty.CON * 15; player.runtimeProperty.attack = player.baseProperty.STR; player.runtimeProperty.mana = Math.round(player.baseProperty.MANA * 1.5); player.runtimeProperty.speed = player.baseProperty.SPD; } function fillSkill(player) { const skills = player.skills; skills.forEach((skillName) => { const skill = index_1.default[skillName] || index_1.default["normalAttack"]; player.runtimeContext.skills.push(skill); }); } function initAdjustRuntime(battleField) { const { player1, player2 } = (0, utils_2.getPlayers)(battleField); [player1, player2].forEach((player) => { player.hooks.onAdjustHp.tap("adjust Hp", (value) => { player.runtimeProperty.hp += value; return value; }); player.hooks.onAdjustMana.tap("adjust Mana", (value) => { const val = player.hooks.onAdjustManaBefore.call(value); player.runtimeProperty.mana += val; return value; }); player.hooks.onAdjustAttack.tap("adjust Attack", (value) => { let nextValue = player.runtimeProperty.attack + value; if (nextValue < 0) nextValue = 0; player.runtimeProperty.attack = nextValue; return nextValue; }); player.hooks.onAdjustFrostbite.tap("adjust Frostbite", (value) => { let nextValue = player.runtimeProperty.frostbite + value; if (nextValue < 0) nextValue = 0; player.runtimeProperty.frostbite = nextValue; return nextValue; }); player.hooks.onAdjustFiring.tap("adjust Firing", (value) => { let nextValue = player.runtimeProperty.firing + value; if (nextValue < 0) nextValue = 0; player.runtimeProperty.firing = nextValue; return nextValue; }); player.hooks.onAdjustPoison.tap("adjust Poison", (value) => { let nextValue = player.runtimeProperty.poison + value; if (nextValue < 0) nextValue = 0; player.runtimeProperty.poison = nextValue; return nextValue; }); player.hooks.onAdjustArmor.tap("adjust Armor", (value) => { let nextValue = player.runtimeProperty.armor + value; if (nextValue < 0) { player.runtimeProperty.armor = 0; return nextValue; } player.runtimeProperty.armor = nextValue; return nextValue; }); player.hooks.onAdjustSpeed.tap("adjust Speed", (value) => { player.runtimeProperty.speed += value; if (player.runtimeProperty.speed <= 0) player.runtimeProperty.speed = 1; return value; }); }); }