From c61e789ddf2d93585a87a674a798f5b5cf04586e Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 2 Feb 2024 20:21:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/common/eventEmitter.ts | 2 - src/core/main/custom/hotkey.ts | 2 - src/core/main/init/settings.tsx | 55 +++-- src/core/main/setting.ts | 3 +- src/game/enemy/battle.ts | 352 +++++++++++++++++--------------- src/game/index.ts | 4 - src/plugin/fx/frag.ts | 7 +- src/plugin/ui/fixed.ts | 2 +- src/types/function.d.ts | 6 +- src/ui/fixed.vue | 2 +- src/ui/settings.vue | 26 ++- 11 files changed, 253 insertions(+), 208 deletions(-) diff --git a/src/core/common/eventEmitter.ts b/src/core/common/eventEmitter.ts index 72b2f06..24baa18 100644 --- a/src/core/common/eventEmitter.ts +++ b/src/core/common/eventEmitter.ts @@ -24,8 +24,6 @@ type EmitFn any> = ( ...params: Parameters ) => any; -console.log(1); - export class EventEmitter { protected events: { [P in keyof T]?: Listener[]; diff --git a/src/core/main/custom/hotkey.ts b/src/core/main/custom/hotkey.ts index 7f45678..6aa0cae 100644 --- a/src/core/main/custom/hotkey.ts +++ b/src/core/main/custom/hotkey.ts @@ -40,8 +40,6 @@ export interface HotkeyJSON { assist: number; } -console.log(2); - export class Hotkey extends EventEmitter { static list: Hotkey[]; diff --git a/src/core/main/init/settings.tsx b/src/core/main/init/settings.tsx index 0619386..820b54d 100644 --- a/src/core/main/init/settings.tsx +++ b/src/core/main/init/settings.tsx @@ -48,7 +48,7 @@ function BooleanSetting(props: SettingComponentProps) { size="large" onClick={changeValue} > - {item.value ? '开启' : '关闭'}设置 + {item.value ? '关闭' : '开启'}设置 ); @@ -56,24 +56,51 @@ function BooleanSetting(props: SettingComponentProps) { function NumberSetting(props: SettingComponentProps) { const { setting, displayer, item } = props; - const changeValue = () => { - setting.setValue(displayer.selectStack.join('.'), !item.value); + const changeValue = (value: number) => { + if (typeof value !== 'number') return; + setting.setValue(displayer.selectStack.join('.'), value); displayer.update(); }; return (
- 修改设置: - +
+ 修改设置: + changeValue(value as number)} + > +
+
+ + +
); } diff --git a/src/core/main/setting.ts b/src/core/main/setting.ts index 30f21dd..3fa3ba5 100644 --- a/src/core/main/setting.ts +++ b/src/core/main/setting.ts @@ -124,6 +124,7 @@ export class MotaSetting extends EventEmitter { } const old = setting.value as boolean | number; setting.value = value; + this.emit('valueChange', key, value, old); } @@ -472,7 +473,7 @@ mainSetting '小地图楼传缩放', 300, COM.Number, - [50, 50, 1000] + [50, 1000, 50] ) ); diff --git a/src/game/enemy/battle.ts b/src/game/enemy/battle.ts index 84a6020..eb4ff16 100644 --- a/src/game/enemy/battle.ts +++ b/src/game/enemy/battle.ts @@ -23,174 +23,182 @@ export function getEnemy( return enemy; } -export function canBattle( - x: number, - y: number, - floorId: FloorIds = core.status.floorId -) { - const enemy = getEnemy(x, y, floorId); - const { damage } = enemy.calDamage(); - return damage < core.status.hero.hp; -} - -export function battle( - x: number, - y: number, - force: boolean = false, - callback?: () => void -) { - core.saveAndStopAutomaticRoute(); - const enemy = getEnemy(x, y); - // 非强制战斗 - if (!canBattle(x, y) && !force && !core.status.event.id) { - core.stopSound(); - core.playSound('操作失败'); - core.drawTip('你打不过此怪物!', enemy.id); - return core.clearContinueAutomaticRoute(callback); - } - // 自动存档 - if (!core.status.event.id) core.autosave(true); - // 战前事件 - // 战后事件 - afterBattle(enemy, x, y); - callback?.(); -} - -export function afterBattle(enemy: DamageEnemy, x?: number, y?: number) { - const floorId = core.status.floorId; - const special = enemy.info.special; - - // 播放战斗动画 - let animate: AnimationIds = 'hand'; - // 检查当前装备是否存在攻击动画 - const equipId = core.getEquip(0); - if (equipId && (core.material.items[equipId].equip || {}).animate) - animate = core.material.items[equipId].equip.animate; - - // 检查该动画是否存在SE,如果不存在则使用默认音效 - if (!core.material.animates[animate]?.se) core.playSound('attack.mp3'); - - // 战斗伤害 - const info = enemy.calDamage(core.status.hero); - const damage = info.damage; - // 判定是否致死 - if (damage >= core.status.hero.hp) { - core.status.hero.hp = 0; - core.updateStatusBar(false, true); - core.events.lose('战斗失败'); - return; - } - - // 扣减体力值并记录统计数据 - core.status.hero.hp -= damage; - core.status.hero.statistics.battleDamage += damage; - core.status.hero.statistics.battle++; - - // 智慧之源 - if (special.includes(14) && flags.hard === 2) { - core.addFlag( - 'inte_' + floorId, - Math.ceil((core.status.hero.mdef / 10) * 0.3) * 10 - ); - core.status.hero.mdef -= - Math.ceil((core.status.hero.mdef / 10) * 0.3) * 10; - } - - // 极昼永夜 - if (special.includes(22)) { - flags[`night_${floorId}`] ??= 0; - flags[`night_${floorId}`] -= enemy.enemy.night!; - } - if (special.includes(23)) { - flags[`night_${floorId}`] ??= 0; - flags[`night_${floorId}`] += enemy.enemy.day; - } - - // if (core.plugin.skillTree.getSkillLevel(11) > 0) { - // core.plugin.study.declineStudiedSkill(); - // } - - // 如果是融化怪,需要特殊标记一下 - if (special.includes(25) && has(x) && has(y)) { - flags[`melt_${floorId}`] ??= {}; - flags[`melt_${floorId}`][`${x},${y}`] = enemy.enemy.melt; - } - - // 获得金币 - const money = enemy.enemy.money; - core.status.hero.money += money; - core.status.hero.statistics.money += money; - - // 获得经验 - const exp = enemy.enemy.exp; - core.status.hero.exp += exp; - core.status.hero.statistics.exp += exp; - - const hint = - '打败 ' + enemy.enemy.name + ',金币+' + money + ',经验+' + exp; - core.drawTip(hint, enemy.id); - - if (core.getFlag('bladeOn') && core.getFlag('blade')) { - core.setFlag('blade', false); - } - if (core.getFlag('shieldOn') && core.getFlag('shield')) { - core.setFlag('shield', false); - } - - // 事件的处理 - const todo: MotaEvent = []; - - // 战后事件 - if (has(core.status.floorId)) { - const loc = `${x},${y}` as LocString; - todo.push(...(core.floors[core.status.floorId].afterBattle[loc] ?? [])); - } - todo.push(...(enemy.enemy.afterBattle ?? [])); - - // 如果事件不为空,将其插入 - if (todo.length > 0) core.insertAction(todo, x, y); - - if (has(x) && has(y)) { - core.drawAnimate(animate, x, y); - core.removeBlock(x, y); - } else core.drawHeroAnimate(animate); - - // 如果已有事件正在处理中 - if (core.status.event.id == null) core.continueAutomaticRoute(); - else core.clearContinueAutomaticRoute(); -} - -export function getCurrentEnemys(floorId = core.status.floorId) { - floorId = floorId || core.status.floorId; - const enemys: CurrentEnemy[] = []; - const used: Record = {}; - ensureFloorDamage(floorId); - const floor = core.status.maps[floorId]; - floor.enemy.list.forEach(v => { - if (!(v.id in used)) { - const e = new DamageEnemy(v.enemy); - e.calAttribute(); - e.getRealInfo(); - e.calDamage(); - const curr: CurrentEnemy = { - enemy: e, - onMapEnemy: [v] - }; - enemys.push(curr); - used[v.id] = curr.onMapEnemy; - } else { - used[v.id].push(v); - } - }); - - return enemys.sort((a, b) => { - const ad = a.enemy.calDamage().damage; - const bd = b.enemy.calDamage().damage; - return ad - bd; - }); -} - function init() { + core.enemys.canBattle = function canBattle( + x: number, + y: number, + floorId: FloorIds = core.status.floorId + ) { + const enemy = getEnemy(x, y, floorId); + const { damage } = enemy.calDamage(); + return damage < core.status.hero.hp; + }; + + core.events.battle = function battle( + x: number, + y: number, + force: boolean = false, + callback?: () => void + ) { + core.saveAndStopAutomaticRoute(); + const enemy = getEnemy(x, y); + // 非强制战斗 + if (!core.canBattle(x, y) && !force && !core.status.event.id) { + core.stopSound(); + core.playSound('操作失败'); + core.drawTip('你打不过此怪物!', enemy.id); + return core.clearContinueAutomaticRoute(callback); + } + // 自动存档 + if (!core.status.event.id) core.autosave(true); + // 战前事件 + // 战后事件 + core.afterBattle(enemy, x, y); + callback?.(); + }; + + core.events.afterBattle = function afterBattle( + enemy: DamageEnemy, + x?: number, + y?: number + ) { + const floorId = core.status.floorId; + const special = enemy.info.special; + + // 播放战斗动画 + let animate: AnimationIds = 'hand'; + // 检查当前装备是否存在攻击动画 + const equipId = core.getEquip(0); + if (equipId && (core.material.items[equipId].equip || {}).animate) + animate = core.material.items[equipId].equip.animate; + + // 检查该动画是否存在SE,如果不存在则使用默认音效 + if (!core.material.animates[animate]?.se) core.playSound('attack.mp3'); + + // 战斗伤害 + const info = enemy.calDamage(core.status.hero); + const damage = info.damage; + // 判定是否致死 + if (damage >= core.status.hero.hp) { + core.status.hero.hp = 0; + core.updateStatusBar(false, true); + core.events.lose('战斗失败'); + return; + } + + // 扣减体力值并记录统计数据 + core.status.hero.hp -= damage; + core.status.hero.statistics.battleDamage += damage; + core.status.hero.statistics.battle++; + + // 智慧之源 + if (special.includes(14) && flags.hard === 2) { + core.addFlag( + 'inte_' + floorId, + Math.ceil((core.status.hero.mdef / 10) * 0.3) * 10 + ); + core.status.hero.mdef -= + Math.ceil((core.status.hero.mdef / 10) * 0.3) * 10; + } + + // 极昼永夜 + if (special.includes(22)) { + flags[`night_${floorId}`] ??= 0; + flags[`night_${floorId}`] -= enemy.enemy.night!; + } + if (special.includes(23)) { + flags[`night_${floorId}`] ??= 0; + flags[`night_${floorId}`] += enemy.enemy.day; + } + + // if (core.plugin.skillTree.getSkillLevel(11) > 0) { + // core.plugin.study.declineStudiedSkill(); + // } + + // 如果是融化怪,需要特殊标记一下 + if (special.includes(25) && has(x) && has(y)) { + flags[`melt_${floorId}`] ??= {}; + flags[`melt_${floorId}`][`${x},${y}`] = enemy.enemy.melt; + } + + // 获得金币 + const money = enemy.enemy.money; + core.status.hero.money += money; + core.status.hero.statistics.money += money; + + // 获得经验 + const exp = enemy.enemy.exp; + core.status.hero.exp += exp; + core.status.hero.statistics.exp += exp; + + const hint = + '打败 ' + enemy.enemy.name + ',金币+' + money + ',经验+' + exp; + core.drawTip(hint, enemy.id); + + if (core.getFlag('bladeOn') && core.getFlag('blade')) { + core.setFlag('blade', false); + } + if (core.getFlag('shieldOn') && core.getFlag('shield')) { + core.setFlag('shield', false); + } + + // 事件的处理 + const todo: MotaEvent = []; + + // 战后事件 + if (has(core.status.floorId)) { + const loc = `${x},${y}` as LocString; + todo.push( + ...(core.floors[core.status.floorId].afterBattle[loc] ?? []) + ); + } + todo.push(...(enemy.enemy.afterBattle ?? [])); + + // 如果事件不为空,将其插入 + if (todo.length > 0) core.insertAction(todo, x, y); + + if (has(x) && has(y)) { + core.drawAnimate(animate, x, y); + core.removeBlock(x, y); + } else core.drawHeroAnimate(animate); + + // 如果已有事件正在处理中 + if (core.status.event.id == null) core.continueAutomaticRoute(); + else core.clearContinueAutomaticRoute(); + }; + + core.enemys.getCurrentEnemys = function getCurrentEnemys( + floorId = core.status.floorId + ) { + floorId = floorId || core.status.floorId; + const enemys: CurrentEnemy[] = []; + const used: Record = {}; + ensureFloorDamage(floorId); + const floor = core.status.maps[floorId]; + floor.enemy.list.forEach(v => { + if (!(v.id in used)) { + const e = new DamageEnemy(v.enemy); + e.calAttribute(); + e.getRealInfo(); + e.calDamage(); + const curr: CurrentEnemy = { + enemy: e, + onMapEnemy: [v] + }; + enemys.push(curr); + used[v.id] = curr.onMapEnemy; + } else { + used[v.id].push(v); + } + }); + + return enemys.sort((a, b) => { + const ad = a.enemy.calDamage().damage; + const bd = b.enemy.calDamage().damage; + return ad - bd; + }); + }; + core.events._sys_battle = function (data: Block, callback?: () => void) { // 检查战前事件 const floor = core.floors[core.status.floorId]; @@ -215,7 +223,7 @@ function init() { core.insertAction(beforeBattle, data.x, data.y, callback); } } else { - battle(data.x, data.y, false, callback); + core.battle(data.x, data.y, false, callback); } }; @@ -234,8 +242,14 @@ function init() { y, prefix ) as LocArr; - battle(ex, ey, true, core.doAction); + core.battle(ex, ey, true, core.doAction); } }; } loading.once('coreInit', init); + +declare global { + interface Enemys { + getCurrentEnemys(floorId: FloorIds): CurrentEnemy[]; + } +} diff --git a/src/game/index.ts b/src/game/index.ts index 23ce7f0..43b9958 100644 --- a/src/game/index.ts +++ b/src/game/index.ts @@ -14,11 +14,7 @@ Mota.register('class', 'EventEmitter', EventEmitter); Mota.register('class', 'IndexedEventEmitter', IndexedEventEmitter); Mota.register('class', 'Range', Range); // ----- 函数注册 -Mota.register('fn', 'battle', battle.battle); Mota.register('fn', 'getEnemy', battle.getEnemy); -Mota.register('fn', 'afterBattle', battle.afterBattle); -Mota.register('fn', 'canBattle', battle.canBattle); -Mota.register('fn', 'getCurrentEnemys', battle.getCurrentEnemys); // ----- 变量注册 Mota.register('var', 'enemySpecials', specials); Mota.register('var', 'hook', hook); diff --git a/src/plugin/fx/frag.ts b/src/plugin/fx/frag.ts index 77cf0c5..c92e7d8 100644 --- a/src/plugin/fx/frag.ts +++ b/src/plugin/fx/frag.ts @@ -25,11 +25,12 @@ const MAX_ROTATE = 0.5; const FRAG_TIMING = linear(); export function init() { - const fn = Mota.requireAll('fn'); - Mota.rewrite(fn, 'afterBattle', 'add', (_, enemy, x, y) => { + Mota.rewrite(core.events, 'afterBattle', 'add', (_, enemy, x, y) => { // 打怪特效 const setting = Mota.require('var', 'mainSetting'); - if (setting.getValue('screen.frag') && has(x) && has(y)) { + console.log(setting.getValue('fx.frag')); + + if (setting.getValue('fx.frag') && has(x) && has(y)) { const frame = core.status.globalAnimateStatus % 2; const canvas = document.createElement('canvas'); canvas.width = 32; diff --git a/src/plugin/ui/fixed.ts b/src/plugin/ui/fixed.ts index 07d39a1..f919c87 100644 --- a/src/plugin/ui/fixed.ts +++ b/src/plugin/ui/fixed.ts @@ -29,7 +29,7 @@ export function getDetailedEnemy( return typeof func === 'string' ? func : func(enemy); }; const special: [string, string, string][] = enemy.enemy.special.map(vv => { - const s = Mota.Plugin.require('special_g').special[vv]; + const s = Mota.require('var', 'enemySpecials')[vv]; return [ fromFunc(s.name, enemy.enemy), fromFunc(s.desc, enemy.enemy), diff --git a/src/types/function.d.ts b/src/types/function.d.ts index e6f0015..43548fa 100644 --- a/src/types/function.d.ts +++ b/src/types/function.d.ts @@ -110,11 +110,7 @@ interface EventData { * @param x 怪物横坐标 * @param y 怪物纵坐标 */ - afterBattle( - enemyId: AllIdsOf<'enemys' | 'enemy48'>, - x?: number, - y?: number - ): void; + afterBattle(enemyId: any, x?: number, y?: number): void; /** * 开门后 diff --git a/src/ui/fixed.vue b/src/ui/fixed.vue index 875f88c..6cf7aeb 100644 --- a/src/ui/fixed.vue +++ b/src/ui/fixed.vue @@ -83,7 +83,7 @@ const special = (() => { }; const show = s.slice(0, 2).map(v => { - const s = Mota.Plugin.require('special_g').specials[v]; + const s = Mota.require('var', 'enemySpecials')[v]; return [fromFunc(s.name, enemy.enemy), s.color]; }); if (s.length > 2) show.push(['...', 'white']); diff --git a/src/ui/settings.vue b/src/ui/settings.vue index e9b3150..47939fb 100644 --- a/src/ui/settings.vue +++ b/src/ui/settings.vue @@ -58,6 +58,7 @@ :item="selectedItem" :displayer="displayer" :setting="setting" + :update="update" > @@ -67,7 +68,7 @@