不同方向的伤害显示

This commit is contained in:
unanmed 2023-07-12 12:01:35 +08:00
parent 847dce5c80
commit d09da5711b
4 changed files with 126 additions and 42 deletions

View File

@ -1587,25 +1587,8 @@ control.prototype._drawDamage_draw = function (ctx, onMap) {
core.plugin.halo.drawHalo(ctx, onMap);
core.setFont(ctx, "14px 'normal'");
core.setTextAlign(ctx, 'left');
core.status.damage.data.forEach(function (one) {
var px = one.px,
py = one.py;
if (onMap && core.bigmap.v2) {
px -= core.bigmap.posX * 32;
py -= core.bigmap.posY * 32;
if (
px < -32 * 2 ||
px > core._PX_ + 32 ||
py < -32 ||
py > core._PY_ + 32
)
return;
}
core.fillBoldText(ctx, one.text, px, py, one.color);
});
core.setTextAlign(ctx, 'center');
core.setTextBaseline(ctx, 'middle');
core.status.damage.extraData.forEach(function (one) {
var px = one.px,
py = one.py;
@ -1624,6 +1607,25 @@ control.prototype._drawDamage_draw = function (ctx, onMap) {
core.fillBoldText(ctx, one.text, px, py, one.color);
core.setAlpha(ctx, alpha);
});
core.setTextAlign(ctx, 'left');
core.setTextBaseline(ctx, 'alphabetic');
core.status.damage.data.forEach(function (one) {
var px = one.px,
py = one.py;
if (onMap && core.bigmap.v2) {
px -= core.bigmap.posX * 32;
py -= core.bigmap.posY * 32;
if (
px < -32 * 2 ||
px > core._PX_ + 32 ||
py < -32 ||
py > core._PY_ + 32
)
return;
}
core.fillBoldText(ctx, one.text, px, py, one.color);
});
};
// ------ 录像相关 ------ //

View File

@ -1,3 +1,4 @@
import { boundary, equal } from './utils';
import { getHeroStatusOf, getHeroStatusOn } from './hero';
import { Range, RangeCollection } from './range';
import {
@ -32,7 +33,7 @@ interface EnemyInfo {
interface DamageInfo {
damage: number;
/** 从勇士位置指向怪物的方向 */
/** 从怪物位置指向勇士的方向 */
dir: Dir | 'none';
x?: number;
y?: number;
@ -203,16 +204,55 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
`Unexpected null of enemy's damage. Loc: '${v.x},${v.y}'. Floor: ${v.floorId}`
);
}
for (const dam of v.damage) {
if (dam.dir === 'none') {
// 怪物本身所在位置
const { damage, color } = formatDamage(dam.damage);
core.status.damage.data.push({
text: damage,
px: 32 * v.x! + 1,
py: 32 * (v.y! + 1) - 1,
color: color
});
if (equal(v.damage, 'damage')) {
// 伤害全部相等,绘制在怪物本身所在位置
const { damage, color } = formatDamage(v.damage[0].damage);
core.status.damage.data.push({
text: damage,
px: 32 * v.x! + 1,
py: 32 * (v.y! + 1) - 1,
color: color
});
} else {
const [min, max] = boundary(v.damage, 'damage');
const delta = max - min;
const { damage, color } = formatDamage(min);
// 在怪物位置绘制最低的伤害
core.status.damage.data.push({
text: damage,
px: 32 * v.x! + 1,
py: 32 * (v.y! + 1) - 1,
color: color
});
// 然后根据位置依次绘制对应位置的伤害
for (const dam of v.damage) {
const d = (dam.damage - min) / delta;
const color = core.arrayToRGB([d * 255, 255 - d * 255, 0]);
if (dam.dir === 'down' || dam.dir === 'up') {
const dir = dam.dir === 'down' ? '↑' : '↓';
core.status.damage.extraData.push({
text: dir,
px: 32 * v.x! + 16,
py:
32 * v.y! +
16 +
core.utils.scan[dam.dir].y * 16,
color: color,
alpha: 1
});
} else if (dam.dir === 'left' || dam.dir === 'right') {
const dir = dam.dir === 'left' ? '→' : '←';
core.status.damage.extraData.push({
text: dir,
px:
32 * v.x! +
16 +
core.utils.scan[dam.dir].x * 16,
py: 32 * v.y! + 16,
color: color,
alpha: 1
});
}
}
}
});
@ -259,7 +299,7 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
core.status.damage.extraData.push({
text: damage,
px: 32 * x + 16,
py: 32 * (y + 1) - 14,
py: 32 * y + 16,
color,
alpha: 1
});
@ -435,10 +475,10 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
* @param progress
*/
ensureCaled(progress: number) {
if (progress <= 1) this.preProvideHalo();
if (progress <= 2) this.calAttribute();
if (progress <= 3) this.provideHalo();
if (progress <= 4) this.getRealInfo();
if (progress >= 1) this.preProvideHalo();
if (progress >= 2) this.calAttribute();
if (progress >= 3) this.provideHalo();
if (progress >= 4) this.getRealInfo();
}
getHaloSpecials(): number[] {
@ -591,8 +631,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
let x = this.x;
let y = this.y;
const { x: dx, y: dy } = core.utils.scan[dir];
while (1) {
if (x < 0 || y < 0 || x >= w || y >= h) break;
while (x >= 0 && y >= 0 && x < w && y < h) {
x += dx;
y += dy;
const loc = `${x},${y}` as LocString;
@ -707,7 +746,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
/**
*
* @param num
* @param dir
* @param dir
* @param hero
*/
calCritical(
@ -767,6 +806,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
let curr = hero.atk!;
let start = curr;
let end = seckill;
let ori = origin.damage;
let i = 0;
while (1) {
@ -798,11 +838,12 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
for (let i = 0; i < d.length - 1; i++) {
const [a, dam] = d[i];
const [na, ndam] = d[i + 1];
if (na < damage) {
if (ndam < damage) {
start = a;
end = na;
cal = true;
}
ori = dam;
}
}
});
@ -813,7 +854,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
const damage =
calDamageWith(this.info, { atk: curr, def }) ?? Infinity;
damageCache[curr] = damage;
if (damage < origin.damage) {
if (damage < ori) {
end = curr;
} else {
start = curr;
@ -832,7 +873,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
/**
* n防减伤
* @param num
* @param dir
* @param dir
* @param hero
*/
calDefDamage(
@ -915,6 +956,7 @@ const skills: [unlock: string, condition: string][] = [
* @param x
* @param y
* @param floorId
* @returns
*/
export function getNeedCalDir(
x?: number,
@ -941,7 +983,8 @@ export function getNeedCalDir(
if (tx < 0 || ty < 0 || tx >= width || ty >= height) return false;
const index = `${tx},${ty}` as LocString;
const block = blocks[index];
if (!block || block.event.noPass) return false;
if (!block) return true;
if (block.event.noPass) return false;
if (!core.canMoveHero(tx, ty, backDir(v), floorId)) return false;
return true;

View File

@ -97,6 +97,45 @@ export function formatDamage(damage: number): DamageString {
return { damage: dam, color: color as Color };
}
export function equal(arr: number[]): boolean;
export function equal<T>(arr: T[], key: keyof T): boolean;
export function equal(arr: any, key?: any) {
if (has(key)) {
for (let i = 1; i < arr.length; i++) {
if (arr[i][key] !== arr[0][key]) return false;
}
return true;
} else {
for (let i = 1; i < arr.length; i++) {
if (arr[i] !== arr[0]) return false;
}
return true;
}
}
export function boundary(arr: number[]): [number, number];
export function boundary<T>(arr: T[], key: keyof T): [number, number];
export function boundary(arr: any, key?: any) {
if (has(key)) {
let min = arr[0][key];
let max = arr[0][key];
for (let i = 1; i < arr.length; i++) {
const ele = arr[i][key];
if (ele < min) min = ele;
if (ele > max) max = ele;
}
return [min, max];
} else {
let min = arr[0];
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
const ele = arr[i];
if (ele < min) min = ele;
if (ele > max) max = ele;
}
return [min, max];
}
}
declare global {
interface GamePluginUtils {
ofDir: typeof ofDir;

2
src/types/util.d.ts vendored
View File

@ -265,7 +265,7 @@ interface Utils {
* @param color 255
* @returns 使
*/
arrayToRGB(color: RGBArray): string;
arrayToRGB(color: RGBArray): _RGBA;
/**
*