From e9b9e4b0697dfdca8556fdced79338eae8e3b0f1 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Wed, 6 Nov 2024 12:41:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8E=B7=E5=8F=96buff=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/libs/control.js | 11 +++-------- public/project/functions.js | 15 +++++++++++++++ src/core/index.ts | 7 ------- src/game/state/hero.ts | 25 +++++++++++++++++-------- src/types/status.d.ts | 2 ++ 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/public/libs/control.js b/public/libs/control.js index 596d39c..fcd664c 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -2896,22 +2896,17 @@ control.prototype.getStatusLabel = function (name) { ////// 设置某个属性的增幅值 ////// control.prototype.setBuff = function (name, value) { - // 仅保留三位有效buff值 - value = parseFloat(value.toFixed(3)); - this.setFlag('__' + name + '_buff__', value); + core.status.hero.buff[name] = value; }; ////// 加减某个属性的增幅值 ////// control.prototype.addBuff = function (name, value) { - var buff = this.getBuff(name) + value; - // 仅保留三位有效buff值 - buff = parseFloat(buff.toFixed(3)); - this.setFlag('__' + name + '_buff__', buff); + core.status.hero.buff[name] += value; }; ////// 获得某个属性的增幅值 ////// control.prototype.getBuff = function (name) { - return core.getFlag('__' + name + '_buff__', 1); + return core.status.hero.buff[name] ?? 1; }; ////// 设置勇士的位置 ////// diff --git a/public/project/functions.js b/public/project/functions.js index f345a57..d610a0a 100644 --- a/public/project/functions.js +++ b/public/project/functions.js @@ -62,6 +62,21 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = { if (h.magicDef === void 0 || h.magicDef === null) { h.magicDef = 0; } + if (!core.status.hero.buff) { + const buff = {}; + core.status.hero.buff = buff; + const toDelete = []; + for (const [key, value] of Object.entries(flags)) { + if (/__\w+_buff__/.test(key)) { + const name = key.slice(2, -7); + buff[name] = value; + toDelete.push(key); + } + } + toDelete.forEach(v => { + delete flags[v]; + }); + } }, win: function (reason, norank, noexit) { // 游戏获胜事件 diff --git a/src/core/index.ts b/src/core/index.ts index 5f65e0e..5d7f596 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,5 +1,3 @@ -import { WeatherController } from './../module/weather/weather'; -import '@/module/weather/snow'; import { BgmController, bgm } from './audio/bgm'; import { SoundController, SoundEffect, sound } from './audio/sound'; import { Focus, GameUi, UiController } from './main/custom/ui'; @@ -176,8 +174,3 @@ Mota.register('module', 'Animation', Animation); main.renderLoaded = true; Mota.require('var', 'hook').emit('renderLoaded'); - -const weather = new WeatherController(); -Mota.require('var', 'hook').once('reset', () => { - weather.activate('snow'); -}); diff --git a/src/game/state/hero.ts b/src/game/state/hero.ts index 918fb32..e6c4939 100644 --- a/src/game/state/hero.ts +++ b/src/game/state/hero.ts @@ -71,19 +71,30 @@ function getRealStatus( if (name === 'all') { const res: any = {}; - Object.keys(core.status.hero).forEach(v => { - res[v] = getRealStatus(status, v as keyof HeroStatus, floorId); - }); + for (const [key, value] of Object.entries(core.status.hero)) { + if (typeof value === 'number') { + res[key] = getRealStatus( + status, + key as keyof HeroStatus, + floorId + ); + } else { + res[key] = value; + } + } + return res; } - let s = (status?.[name] ?? core.status.hero[name]) as number; + let s = (status[name] ?? core.status.hero[name]) as number; if (s === null || s === void 0) { throw new ReferenceError( `Wrong hero status property name is delivered: ${name}` ); } + if (typeof s !== 'number') return s; + // 永夜、极昼 if (name === 'atk' || name === 'def') { s += NightSpecial.getNight(floorId); @@ -108,10 +119,8 @@ function getRealStatus( } // buff - if (typeof s === 'number') { - s *= flags[`__${name}_buff__`] ?? 1; - s = Math.floor(s); - } + s *= core.status.hero.buff[name] ?? 1; + s = Math.floor(s); return s; } diff --git a/src/types/status.d.ts b/src/types/status.d.ts index 15bd9fd..74f6015 100644 --- a/src/types/status.d.ts +++ b/src/types/status.d.ts @@ -965,4 +965,6 @@ interface HeroStatus { x?: number; y?: number; floorId?: FloorIds; + + buff: Partial>; }