From 3baee32c51ab5e881905e740e0266d91bf7712e1 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Thu, 3 Oct 2024 16:26:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B0=B8=E5=A4=9C/=E6=9E=81?= =?UTF-8?q?=E6=98=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/project/functions.js | 21 ++++++++++++++++++++- src/game/enemy/battle.ts | 11 +++-------- src/game/enemy/damage.ts | 11 +++++++---- src/game/index.ts | 3 ++- src/game/mechanism/misc.ts | 28 ++++++++++++++++++++++++++++ src/game/state/hero.ts | 15 +++++++-------- src/game/system.ts | 1 + 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/public/project/functions.js b/public/project/functions.js index 3ae9e0e..881bd15 100644 --- a/public/project/functions.js +++ b/public/project/functions.js @@ -269,7 +269,13 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = { version: core.firstData.version, guid: core.getGuid(), time: new Date().getTime(), - skills: Mota.Plugin.require('skillTree_g').saveSkillTree() + skills: Mota.Plugin.require('skillTree_g').saveSkillTree(), + night: [ + ...Mota.require( + 'module', + 'Mechanism' + ).NightSpecial.saveNight() + ] }; return data; @@ -318,6 +324,19 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a = { core.setFlag('__fromLoad__', true); Mota.Plugin.require('skillTree_g').loadSkillTree(data.skills); + const Night = Mota.require('module', 'Mechanism').NightSpecial; + + if (!data.night) { + // 兼容旧版 + Night.loadNight([]); + for (const [key, value] of Object.entries(data.hero.flags)) { + if (key.startsWith('night_')) { + const [, floorId] = key.split('_'); + Night.addNight(floorId, value); + delete data.hero.flags[key]; + } + } + } // 切换到对应的楼层 core.changeFloor(data.floorId, null, data.hero.loc, 0, function () { diff --git a/src/game/enemy/battle.ts b/src/game/enemy/battle.ts index 35133d8..511d362 100644 --- a/src/game/enemy/battle.ts +++ b/src/game/enemy/battle.ts @@ -1,6 +1,7 @@ import { DamageEnemy, ensureFloorDamage, getSingleEnemy } from './damage'; import { findDir, has } from '../../plugin/game/utils'; import { hook, loading } from '../game'; +import { NightSpecial } from '../mechanism/misc'; export interface CurrentEnemy { enemy: DamageEnemy; @@ -198,18 +199,12 @@ function init() { // 极昼永夜 if (special.has(22)) { - flags[`night_${floorId}`] ??= 0; - flags[`night_${floorId}`] -= enemy.info.night!; + NightSpecial.addNight(floorId, -enemy.info.night!); } if (special.has(23)) { - flags[`night_${floorId}`] ??= 0; - flags[`night_${floorId}`] += enemy.info.day; + NightSpecial.addNight(floorId, enemy.info.day!); } - // if (core.plugin.skillTree.getSkillLevel(11) > 0) { - // core.plugin.study.declineStudiedSkill(); - // } - // 如果是融化怪,需要特殊标记一下 if (special.has(25) && has(x) && has(y)) { flags[`melt_${floorId}`] ??= {}; diff --git a/src/game/enemy/damage.ts b/src/game/enemy/damage.ts index 00b939d..59234b1 100644 --- a/src/game/enemy/damage.ts +++ b/src/game/enemy/damage.ts @@ -3,6 +3,7 @@ import { Range } from '../util/range'; import { ensureArray, has, manhattan } from '@/plugin/game/utils'; import EventEmitter from 'eventemitter3'; import { hook } from '../game'; +import { NightSpecial } from '../mechanism/misc'; // todo: 光环划分优先级,从而可以实现光环的多级运算 @@ -335,12 +336,14 @@ export class DamageEnemy { } // 极昼永夜 - info.atk -= flags[`night_${floorId}`] ?? 0; - info.def -= flags[`night_${floorId}`] ?? 0; + const night = NightSpecial.getNight(floorId); + info.atk -= night; + info.def -= night; // 融化,融化不属于怪物光环,因此不能用provide和inject计算,需要在这里计算 - if (has(flags[`melt_${floorId}`]) && has(this.x) && has(this.y)) { - for (const [loc, per] of Object.entries(flags[`melt_${floorId}`])) { + const melt = flags[`melt_${floorId}`]; + if (has(melt) && has(this.x) && has(this.y)) { + for (const [loc, per] of Object.entries(melt)) { const [mx, my] = loc.split(',').map(v => parseInt(v)); if ( Math.abs(mx + dx - this.x) <= 1 && diff --git a/src/game/index.ts b/src/game/index.ts index 699d604..436ccf3 100644 --- a/src/game/index.ts +++ b/src/game/index.ts @@ -33,7 +33,8 @@ Mota.register('var', 'gameListener', gameListener); Mota.register('var', 'loading', loading); // ----- 模块注册 Mota.register('module', 'Mechanism', { - BluePalace: miscMechanism.BluePalace + BluePalace: miscMechanism.BluePalace, + NightSpecial: miscMechanism.NightSpecial }); Mota.register('module', 'State', { ItemState, diff --git a/src/game/mechanism/misc.ts b/src/game/mechanism/misc.ts index 94b58bb..318e18a 100644 --- a/src/game/mechanism/misc.ts +++ b/src/game/mechanism/misc.ts @@ -2,6 +2,34 @@ import { backDir, has } from '@/plugin/game/utils'; import { loading } from '../game'; import type { LayerDoorAnimate } from '@/core/render/preset/floor'; +/** + * 永夜/极昼 + */ +export namespace NightSpecial { + let nightMap = new Map(); + + export function getNight(floor: FloorIds) { + return nightMap.get(floor) ?? 0; + } + + export function addNight(floor: FloorIds, value: number) { + const num = nightMap.get(floor) ?? 0; + nightMap.set(floor, num + value); + } + + export function saveNight() { + return nightMap.entries(); + } + + export function loadNight(night: IterableIterator<[FloorIds, number]>) { + nightMap = new Map(night); + } + + export function getAll() { + return nightMap; + } +} + export namespace BluePalace { type DoorConvertInfo = [id: AllIds, x: number, y: number]; diff --git a/src/game/state/hero.ts b/src/game/state/hero.ts index 3cf27be..47c1475 100644 --- a/src/game/state/hero.ts +++ b/src/game/state/hero.ts @@ -2,6 +2,7 @@ import { logger } from '@/core/common/logger'; import { EventEmitter } from 'eventemitter3'; import { cloneDeep, isNil } from 'lodash-es'; import { ItemState } from './item'; +import { NightSpecial } from '../mechanism/misc'; /** * 获取勇士在某一点的属性 @@ -85,7 +86,7 @@ function getRealStatus( // 永夜、极昼 if (name === 'atk' || name === 'def') { - s += window.flags?.[`night_${floorId}`] ?? 0; + s += NightSpecial.getNight(floorId); } // 技能 @@ -93,8 +94,7 @@ function getRealStatus( const level = getSkillLevel(2); if (name === 'atk') { s *= 1 + 0.1 * level; - } - if (name === 'def') { + } else if (name === 'def') { s *= 1 - 0.1 * level; } } @@ -102,18 +102,17 @@ function getRealStatus( const level = getSkillLevel(10); if (name === 'atk') { s *= 1 - 0.1 * level; - } - if (name === 'def') { + } else if (name === 'def') { s *= 1 + 0.1 * level; } } // buff - if (typeof s === 'number') + if (typeof s === 'number') { s *= core.getBuff(name as keyof NumbericHeroStatus); + s = Math.floor(s); + } - // 取整 - if (typeof s === 'number') s = Math.floor(s); return s; } diff --git a/src/game/system.ts b/src/game/system.ts index 0e2f837..4bb8814 100644 --- a/src/game/system.ts +++ b/src/game/system.ts @@ -102,6 +102,7 @@ interface VariableInterface { interface ModuleInterface { Mechanism: { BluePalace: typeof misc.BluePalace; + NightSpecial: typeof misc.NightSpecial; }; Effect: { Portal: typeof portal;