获得需要攻击的方向

This commit is contained in:
unanmed 2023-05-11 21:47:57 +08:00
parent 19b2256efb
commit e4c18c0766
3 changed files with 67 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import { getHeroStatusOf, getHeroStatusOn } from './hero';
import { Range, RangeCollection } from './range';
import { ensureArray, has } from './utils';
import { backDir, ensureArray, has, ofDir } from './utils';
interface HaloType {
square: {
@ -101,7 +101,11 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
floorId?: FloorIds;
enemy: Enemy<T>;
/** 怪物属性 */
/**
*
* () ->
* -> provide inject -> ->
*/
info!: EnemyInfo;
/** 是否需要计算属性 */
needCalculate: boolean = true;
@ -143,7 +147,6 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
* inject光环之前
* @param hero
* @param getReal
* @returns
*/
calAttribute(
hero: Partial<HeroStatus> = core.status.hero,
@ -293,13 +296,59 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
}
}
/**
* buff加成core.status.hero取
*/
const realStatus: (keyof HeroStatus)[] = ['atk', 'def'];
/**
*
* @param x
* @param y
* @param floorId
*/
export function getNeedCalDir(x: number, y: number, floorId: FloorIds) {}
export function getNeedCalDir(
x: number,
y: number,
floorId: FloorIds,
hero: Partial<HeroStatus> = core.status.hero
): [Dir | 'none', Partial<HeroStatus>][] {
// 第一章或序章,用不到这个函数
if (flags.chapter < 2) {
return [['none', getHeroStatusOf(hero, realStatus, x, y, floorId)]];
}
// 如果指定了勇士坐标
if (has(hero.x) && has(hero.y)) {
const { x, y, floorId } = hero;
if (has(floorId)) {
return [['none', getHeroStatusOf(hero, realStatus, x, y, floorId)]];
} else {
return [['none', getHeroStatusOf(hero, realStatus, x, y, floorId)]];
}
}
const needMap: Dir[] = ['left', 'down', 'right', 'up'];
const { width, height } = core.status.maps[floorId];
const blocks = core.getMapBlocksObj(floorId);
return needMap
.filter(v => {
const [tx, ty] = ofDir(x, y, v);
if (tx < 0 || ty < 0 || tx >= width || ty >= height) return false;
const index = `${tx},${ty}` as LocString;
const block = blocks[index];
if (block.event.noPass) return false;
if (!core.canMoveHero(tx, ty, backDir(v), floorId)) return false;
return true;
})
.map(v => {
const [tx, ty] = ofDir(x, y, v);
const status = getHeroStatusOf(hero, realStatus, tx, ty, floorId);
return [v, status];
});
}
declare global {
interface PluginDeclaration {

View File

@ -1,5 +1,5 @@
///<reference path="../../../src/types/core.d.ts" />
import { slide } from './utils.js';
import { slide } from './utils';
const list = ['tower6'];

View File

@ -52,10 +52,22 @@ export function ensureArray<T>(arr: T): T extends any[] ? T : T[] {
return arr instanceof Array ? arr : [arr];
}
export function ofDir(x: number, y: number, dir: Dir2): LocArr {
const { x: dx, y: dy } = core.utils.scan2[dir];
return [x + dx, y + dy];
}
declare global {
interface GamePluginUtils {
ofDir: typeof ofDir;
}
}
core.plugin.utils = {
slide,
backDir,
has,
maxGameScale
maxGameScale,
ofDir
};
core.has = has;