重构怪物手册的一部分

This commit is contained in:
AncTe committed 2023-07-31 16:49:04 +08:00
1 parent dae43498ca
commit 112ce4c4ef
15 files changed
+214 -269

No files matched your search

+41 -8
View File
@@ -1,11 +1,17 @@
import {
DamageDir,
DamageEnemy,
ensureFloorDamage,
getNeedCalDir,
getSingleEnemy
} from './damage';
import { findDir, has } from '../utils';
export interface CurrentEnemy {
enemy: DamageEnemy;
onMapEnemy: DamageEnemy[];
}
export function getEnemy(
x: number,
y: number,
@@ -228,13 +234,39 @@ core.events._action_battle = function (data, x, y, prefix) {
}
};
core.enemys.getCurrentEnemys = function (floorId = core.status.floorId) {
floorId = floorId || core.status.floorId;
const enemys: CurrentEnemy[] = [];
const used: Record<string, DamageEnemy[]> = {};
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) => {
return (
(a.enemy.damage?.[0]?.damage ?? Infinity) -
(b.enemy.damage?.[0]?.damage ?? Infinity)
);
});
};
declare global {
interface Events {
/**
* 与怪物战斗前
* @param x 怪物横坐标
* @param y 怪物纵坐标
*/
beforeBattle(
enemy: DamageEnemy,
x: number,
@@ -242,9 +274,6 @@ declare global {
dir: DamageDir
): boolean;
/**
* 与怪物战斗后
*/
afterBattle(
enemy: DamageEnemy,
x: number,
@@ -252,4 +281,8 @@ declare global {
dir: DamageDir
): void;
}
interface Enemys {
getCurrentEnemys(floorId?: FloorIds): CurrentEnemy[];
}
}
+3 -2
View File
@@ -417,7 +417,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
* 计算怪物在不计光环下的属性,在inject光环之前,预平衡光环之后执行
*/
calAttribute() {
if (this.progress !== 1) return;
if (this.progress !== 1 && has(this.x) && has(this.floorId)) return;
this.progress = 2;
const special = this.info.special;
const info = this.info;
@@ -448,7 +448,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
* 获取怪物的真实属性信息,在inject光环后执行
*/
getRealInfo() {
if (this.progress < 3) {
if (this.progress < 3 && has(this.x) && has(this.floorId)) {
throw new Error(
`Unexpected early real info calculating. Progress: ${this.progress}`
);
@@ -804,6 +804,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
x?: number,
y?: number
): CriticalDamageDelta[] {
// todo: 可以优化,根据之前的计算可以直接确定下一个临界的范围
if (!isFinite(seckill)) return [];
const res: CriticalDamageDelta[] = [];
const def = hero.def!;
-2
View File
@@ -2,8 +2,6 @@ import { getEnemy } from '../enemy/battle';
import { DamageDir, getNeedCalDir } from '../enemy/damage';
import { formatDamage } from '../utils';
export {};
core.maps._initDetachedBlock = function (
info: BlockInfo,
x: number,
+48 -59
View File
@@ -1,39 +1,40 @@
import { CurrentEnemy } from '../game/enemy/battle';
import { has } from '../utils';
export interface ToShowEnemy extends CurrentEnemy {
critical: string;
criticalDam: string;
defDam: string;
/** [名称, 描述, 颜色] */
special: [string, string, string][];
damageColor: string;
showSpecial: [string, string, string][];
damage: string;
}
interface BookDetailInfo {
/** 怪物手册详细信息展示的怪物 */
enemy?: ToShowEnemy;
/** 怪物手册的怪物详细信息的初始位置 */
pos?: number;
}
export const detailInfo: BookDetailInfo = {};
/**
* 获取怪物的特殊技能描述
* @param enemy 怪物实例
*/
export function getSpecialHint(enemy: Enemy & DetailedEnemy) {
const all = core
.getSpecials()
.filter(v => enemy.special.includes(v[0]))
.sort((a, b) => a[0] - b[0]);
const des = all.map(v => {
const des = v[2];
if (des instanceof Function) {
return des(enemy);
}
return des;
});
const name = all.map(v => {
const name = v[1];
if (name instanceof Function) {
return name(enemy);
}
return name;
});
export function getSpecialHint(enemy: ToShowEnemy) {
return (
<div>
{all.map((v, i) => {
{enemy.showSpecial.map((v, i) => {
return (
<div class="special">
<span style={{ color: core.arrayToRGBA(v[3]) }}>
&nbsp;&nbsp;&nbsp;&nbsp;{name[i]}:
<span style={{ color: v[2] }}>
&nbsp;&nbsp;&nbsp;&nbsp;{v[0]}:
</span>
<span innerHTML={des[i]}></span>
<span innerHTML={v[1]}></span>
</div>
);
})}
@@ -46,12 +47,9 @@ export function getSpecialHint(enemy: Enemy & DetailedEnemy) {
* @param enemy 怪物实例
*/
export function getDefDamage(
enemy: DetailedEnemy,
enemy: ToShowEnemy,
addDef: number = 0,
addAtk: number = 0,
x?: number,
y?: number,
floorId?: FloorIds
addAtk: number = 0
) {
// todo: 删除 getDamageInfo
const ratio = core.status.thisMap.ratio;
@@ -63,29 +61,26 @@ export function getDefDamage(
const max = 100 - Math.floor(addDef / ratio);
for (let i = 0; i <= max; i++) {
const dam = core.getDamageInfo(
enemy.id,
const dam = enemy.enemy.calEnemyDamage(
{
def: core.getStatus('def') + ratio * i + addDef,
atk: core.getStatus('atk') + addAtk
atk: core.status.hero.atk + addAtk,
def: core.status.hero.def + addDef + i * ratio
},
x,
y,
floorId
'none'
);
if (res.length === 0) {
origin = dam?.damage;
origin = dam[0].damage;
if (has(origin)) {
res.push([addDef + i * ratio, origin]);
last = origin;
}
continue;
}
if (!has(dam)) continue;
if (dam.damage === res.at(-1)?.[1]) continue;
last = dam.damage;
res.push([ratio * i + addDef, dam.damage]);
if (!isFinite(dam[0].damage)) continue;
if (dam[0].damage === res.at(-1)?.[1]) continue;
last = dam[0].damage;
res.push([ratio * i + addDef, dam[0].damage]);
}
return res;
@@ -96,12 +91,9 @@ export function getDefDamage(
* @param enemy 怪物实例
*/
export function getCriticalDamage(
enemy: DetailedEnemy,
enemy: ToShowEnemy,
addAtk: number = 0,
addDef: number = 0,
x?: number,
y?: number,
floorId?: FloorIds
addDef: number = 0
): [number, number][] {
// todo: 删除 getDamageInfo
const ratio = core.status.thisMap.ratio;
@@ -113,29 +105,26 @@ export function getCriticalDamage(
const max = 100 - Math.floor(addAtk / ratio);
for (let i = 0; i <= max; i++) {
const dam = core.getDamageInfo(
enemy.id,
const dam = enemy.enemy.calEnemyDamage(
{
atk: core.getStatus('atk') + ratio * i + addAtk,
def: core.getStatus('def') + addDef
atk: core.status.hero.atk + addAtk + i * ratio,
def: core.status.hero.def + addDef
},
x,
y,
floorId
'none'
);
if (res.length === 0) {
origin = dam?.damage;
origin = dam[0].damage;
if (has(origin)) {
res.push([addAtk + i * ratio, origin]);
last = origin;
}
continue;
}
if (!has(dam)) continue;
if (dam.damage === res.at(-1)?.[1]) continue;
last = dam.damage;
res.push([ratio * i + addAtk, dam.damage]);
if (!isFinite(dam[0].damage)) continue;
if (dam[0].damage === res.at(-1)?.[1]) continue;
last = dam[0].damage;
res.push([ratio * i + addAtk, dam[0].damage]);
}
return res;