From fbe81fedd28cf7eb46ebf736fb5ba0ed8b7f32c1 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sun, 30 Jul 2023 17:04:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E4=B8=AD=E7=9A=84=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E6=88=98=E6=96=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierignore | 3 +- public/editor.html | 924 ++++++++++++++------------ public/libs/control.js | 4 +- public/libs/enemys.js | 2 +- public/libs/events.js | 35 +- src/plugin/game/{ => enemy}/battle.ts | 27 +- src/plugin/game/{ => enemy}/damage.ts | 21 +- src/plugin/game/index.js | 4 +- src/plugin/game/itemDetail.ts | 2 +- src/types/event.d.ts | 4 + 10 files changed, 549 insertions(+), 477 deletions(-) rename src/plugin/game/{ => enemy}/battle.ts (90%) rename src/plugin/game/{ => enemy}/damage.ts (98%) diff --git a/.prettierignore b/.prettierignore index 57af69b..ba4d211 100644 --- a/.prettierignore +++ b/.prettierignore @@ -6,4 +6,5 @@ public/project/items.js public/project/floors/*.js public/project/maps.js public/_server/**/*.js -script/**/*.js \ No newline at end of file +script/**/*.js +public/editor.html \ No newline at end of file diff --git a/public/editor.html b/public/editor.html index 22f3209..6aebc60 100644 --- a/public/editor.html +++ b/public/editor.html @@ -1,5 +1,6 @@ + @@ -8,124 +9,121 @@ + - -
-
-
-
-
-
- -
-
- - - - - - - - 保留楼层属性 -
-
- - - - -
- - -
-
-
-

追加素材

-
-

- - - - - -   自动注册 -

-

从V2.7.1开始,你可以直接将素材图片拖到对应的素材区,将自动追加并注册。同时,4x4的道具素材已支持快速追加一次16个。

-

- 色相: - -

-
- - - - -
-
1
-
2
-
3
-
4
+ +
+
+
+
+
+
+ +
+
+ + + + + + + + 保留楼层属性 +
+
+ + + + +
+ +
-
-
-

地图选点       -

-
-

0,0

-
- - - - - - - - -
条目注释
+
+

追加素材

+
+

+ + + + + +   自动注册 +

+

从V2.7.1开始,你可以直接将素材图片拖到对应的素材区,将自动追加并注册。同时,4x4的道具素材已支持快速追加一次16个。

+

+ 色相: + +

+
+ + + + +
+
1
+
2
+
3
+
4
+
+
-
-
-

图块属性         -

-
-
+
+

地图选点       +

+
+

0,0

- + @@ -134,350 +132,414 @@
条目 注释
-
- - - - +
+
+
+

图块属性         +

+
+
+
+ + + + + + + + +
条目注释
+
+
+ + + + +
+
+
+ + + +
+ + + +
+
+ + + +
-
- - - -
- - - -
-
- - - - +
+
+

楼层属性         +

+
+
+ + + + + + + + +
条目注释
+
+
+ + +
+
+ 修改地图大小:宽,高, + 偏移x y + +
-
-
-

楼层属性         -

-
-
- - - - - - - - -
条目注释
-
-
- - -
-
- 修改地图大小:宽,高, - 偏移x y - +
+

全塔属性       +

+
+
+ + + + + + + + +
条目注释
+
-
-
-

全塔属性       -

-
-
- - - - - - - - -
条目注释
-
-
-
-
-
-

事件编辑器    - +

事件编辑器    + - - - - -
- - + + + + +
+ + +
+ + + + 开启中文名替换 + + 展开值块逻辑运算 + +

+
+
+
+
+
- - - - 开启中文名替换 - - 展开值块逻辑运算 - +
+
+ +
+
+ + + + + + + 语法检查 + + 字体大小 + +
+ +
+
+

脚本编辑    

-
-
-
+
+
+ + + + + + + + +
条目注释
+
+
+
+
+

公共事件         +

+
+
+ + + + + + + + +
条目注释
+
+
+
+
+

插件编写         +

+
+
+ + + + + + + + +
条目注释
+
+
+
+
+
+
+
+ + + +
+
+
+ + 通行度 + +
+ + 线 + 矩形 + tile平铺 + 填充 + + +
+ + 背景层 + 事件层 + 前景层 + +
+
+ + + + + +
+ + + + + + +
+
+
+

(Ctrl+滚轮放缩,右键置顶)

+
+ +
+
+ +
- -
-
- - - - - - - 语法检查 - - 字体大小 - -
- -
-
-

脚本编辑     -

-
-
- - - - - - - - -
条目注释
+ + + + + + -
-

公共事件         -

-
-
- - - - - - - - -
条目注释
-
-
-
-
-

插件编写         -

-
-
- - - - - - - - -
条目注释
-
-
-
-
-
-
-
- - - -
-
-
- - 通行度 - -
- - 线 - 矩形 - tile平铺 - 填充 - - -
- - 背景层 - 事件层 - 前景层 - -
-
- - - - - -
- - - - - - -
-
-
-

(Ctrl+滚轮放缩,右键置顶)

-
- -
-
- - -
- - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + + \ No newline at end of file diff --git a/public/libs/control.js b/public/libs/control.js index 9f71bfb..67edf7b 100644 --- a/public/libs/control.js +++ b/public/libs/control.js @@ -1468,11 +1468,11 @@ control.prototype.updateDamage = function (floorId, ctx) { }; control.prototype._updateDamage_damage = function (floorId, onMap) { - // Deprecated. See src/plugin/game/damage.ts EnemyCollection.render. + // Deprecated. See src/plugin/game/enemy/damage.ts EnemyCollection.render. }; control.prototype._updateDamage_extraDamage = function (floorId, onMap) { - // Deprecated. See src/plugin/game/damage.ts EnemyCollection.render. + // Deprecated. See src/plugin/game/enemy/damage.ts EnemyCollection.render. }; ////// 重绘地图显伤 ////// diff --git a/public/libs/enemys.js b/public/libs/enemys.js index c20e3a8..b68a2a4 100644 --- a/public/libs/enemys.js +++ b/public/libs/enemys.js @@ -203,7 +203,7 @@ enemys.prototype.getEnemyValue = function (enemy, name, x, y, floorId) { ////// 能否获胜 ////// enemys.prototype.canBattle = function (enemy, x, y, floorId) { - // Deprecated. See src/plugin/game/battle.ts + // Deprecated. See src/plugin/game/enemy/battle.ts }; enemys.prototype.getDamageString = function (enemy, x, y, floorId, hero) { diff --git a/public/libs/events.js b/public/libs/events.js index ad50f18..412be57 100644 --- a/public/libs/events.js +++ b/public/libs/events.js @@ -430,49 +430,22 @@ events.prototype._trigger_ignoreChangeFloor = function (block) { }; events.prototype._sys_battle = function (data, callback) { - // todo: 重写这个函数的一部分 - - // 检查战前事件 - var beforeBattle = []; - core.push( - beforeBattle, - core.floors[core.status.floorId].beforeBattle[data.x + ',' + data.y] - ); - core.push( - beforeBattle, - (core.material.enemys[data.event.id] || {}).beforeBattle - ); - if (beforeBattle.length > 0) { - core.push(beforeBattle, [{ type: 'battle', x: data.x, y: data.y }]); - core.clearContinueAutomaticRoute(); - - // 自动存档 - var inAction = core.status.event.id == 'action'; - if (inAction) { - core.insertAction(beforeBattle, data.x, data.y); - core.doAction(); - } else { - core.autosave(true); - core.insertAction(beforeBattle, data.x, data.y, callback); - } - } else { - this.battle(data.event.id, data.x, data.y, false, callback); - } + // Deprecated. See /src/plugin/game/enemy/battle.ts }; ////// 战斗 ////// events.prototype.battle = function (id, x, y, force, callback) { - // Deprecated. See src/plugin/game/battle.ts + // Deprecated. See src/plugin/game/enemy/battle.ts }; ////// 战斗前触发的事件 ////// events.prototype.beforeBattle = function (enemyId, x, y) { - // Deprecated. See src/plugin/game/battle.ts + // Deprecated. See src/plugin/game/enemy/battle.ts }; ////// 战斗结束后触发的事件 ////// events.prototype.afterBattle = function (enemyId, x, y) { - // Deprecated. See src/plugin/game/battle.ts + // Deprecated. See src/plugin/game/enemy/battle.ts }; events.prototype._sys_openDoor = function (data, callback) { diff --git a/src/plugin/game/battle.ts b/src/plugin/game/enemy/battle.ts similarity index 90% rename from src/plugin/game/battle.ts rename to src/plugin/game/enemy/battle.ts index f1d49d0..5e2a912 100644 --- a/src/plugin/game/battle.ts +++ b/src/plugin/game/enemy/battle.ts @@ -1,5 +1,10 @@ -import { DamageDir, DamageEnemy, getNeedCalDir } from './damage'; -import { findDir, has } from './utils'; +import { + DamageDir, + DamageEnemy, + getNeedCalDir, + getSingleEnemy +} from './damage'; +import { findDir, has } from '../utils'; export function getEnemy( x: number, @@ -205,6 +210,24 @@ core.events._sys_battle = function (data: Block, callback?: () => void) { } }; +core.events._action_battle = function (data, x, y, prefix) { + if (data.id) { + const enemy = getSingleEnemy(data.id as EnemyIds); + // todo: 与不在地图上的怪物战斗 + } else { + if (data.floorId != core.status.floorId) { + core.doAction(); + return; + } + const [ex, ey] = this.__action_getLoc(data.loc, x, y, prefix) as LocArr; + const dir = findDir(core.status.hero.loc, { + x: ex, + y: ey + }) as DamageDir; + this.battle(ex, ey, dir, true, core.doAction); + } +}; + declare global { interface Events { /** diff --git a/src/plugin/game/damage.ts b/src/plugin/game/enemy/damage.ts similarity index 98% rename from src/plugin/game/damage.ts rename to src/plugin/game/enemy/damage.ts index 2f057a0..514efb9 100644 --- a/src/plugin/game/damage.ts +++ b/src/plugin/game/enemy/damage.ts @@ -1,6 +1,6 @@ -import { equal } from './utils'; -import { getHeroStatusOf, getHeroStatusOn } from './hero'; -import { Range, RangeCollection } from './range'; +import { equal } from '../utils'; +import { getHeroStatusOf, getHeroStatusOn } from '../hero'; +import { Range, RangeCollection } from '../range'; import { backDir, checkV2, @@ -9,7 +9,7 @@ import { has, manhattan, ofDir -} from './utils'; +} from '../utils'; interface HaloType { square: { @@ -968,11 +968,11 @@ const skills: [unlock: string, condition: string][] = [ export function getNeedCalDir( x?: number, y?: number, - floorId: FloorIds = core.status.floorId, + floorId?: FloorIds, hero: Partial = core.status.hero ): (Dir | 'none')[] { // 第一章或序章,或者没有指定怪物位置,或者没开自动定位,用不到这个函数 - if (flags.chapter < 2 || !has(x) || !has(y)) { + if (flags.chapter < 2 || !has(x) || !has(y) || !floorId) { return ['none']; } @@ -1105,6 +1105,15 @@ export function ensureFloorDamage(floorId: FloorIds) { floor.enemy ??= new EnemyCollection(floorId); } +export function getSingleEnemy(id: EnemyIds) { + const e = core.material.enemys[id]; + const enemy = new DamageEnemy(e); + enemy.calAttribute(); + enemy.getRealInfo(); + enemy.calDamage(core.status.hero, false)[0]; + return enemy; +} + declare global { interface PluginDeclaration { damage: { diff --git a/src/plugin/game/index.js b/src/plugin/game/index.js index 66daccf..3f8340f 100644 --- a/src/plugin/game/index.js +++ b/src/plugin/game/index.js @@ -17,8 +17,8 @@ import * as study from './study'; import * as towerBoss from './towerBoss'; import * as utils from './utils'; import * as chase from './chase'; -import * as damage from './damage'; -import * as battle from './battle'; +import * as damage from './enemy/damage'; +import * as battle from './enemy/battle'; export { halo, diff --git a/src/plugin/game/itemDetail.ts b/src/plugin/game/itemDetail.ts index b0feccf..f4e448b 100644 --- a/src/plugin/game/itemDetail.ts +++ b/src/plugin/game/itemDetail.ts @@ -1,4 +1,4 @@ -import { ensureFloorDamage } from './damage'; +import { ensureFloorDamage } from './enemy/damage'; core.control.updateDamage = function (floorId = core.status.floorId, ctx) { if (!floorId || core.status.gameOver || main.mode !== 'play') return; diff --git a/src/types/event.d.ts b/src/types/event.d.ts index 3f34d22..1b6b42b 100644 --- a/src/types/event.d.ts +++ b/src/types/event.d.ts @@ -760,6 +760,10 @@ interface Events extends EventData { tryUseItem(itemId: ItemIdOf<'tools' | 'constants'>): void; _sys_battle(data: Block, callback?: () => void): void; + + _action_battle(data: any, x?: number, y?: number, prefix?: any): void; + + __action_getLoc(data: any, x?: number, y?: number, prefix?: any): any; } declare const events: new () => Events;