This commit is contained in:
unanmed 2023-06-30 22:34:39 +08:00
parent 553a589236
commit 24ff4b682f
3 changed files with 115 additions and 2 deletions

View File

@ -1,6 +1,14 @@
import { getHeroStatusOf, getHeroStatusOn } from './hero'; import { getHeroStatusOf, getHeroStatusOn } from './hero';
import { Range, RangeCollection } from './range'; import { Range, RangeCollection } from './range';
import { backDir, checkV2, ensureArray, has, manhattan, ofDir } from './utils'; import {
backDir,
checkV2,
ensureArray,
formatDamage,
has,
manhattan,
ofDir
} from './utils';
interface HaloType { interface HaloType {
square: { square: {
@ -97,7 +105,6 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
v.calRealAttribute(); v.calRealAttribute();
} }
v.calDamage(void 0, onMap); v.calDamage(void 0, onMap);
console.log(v.damage);
}); });
} }
@ -116,6 +123,7 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
this.list.forEach(v => { this.list.forEach(v => {
v.calMapDamage(this.mapDamage, hero); v.calMapDamage(this.mapDamage, hero);
}); });
console.log(this.mapDamage);
} }
/** /**
@ -157,6 +165,89 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
v.preProvideHalo(); v.preProvideHalo();
}); });
} }
render(onMap?: boolean): void;
render(onMap: boolean, cal: boolean, noCache: boolean): void;
render(
onMap: boolean = false,
cal: boolean = false,
noCache: boolean = false
) {
if (cal) {
this.calDamage(noCache, true);
this.calMapDamage(noCache);
}
// 怪物伤害
this.list.forEach(v => {
if (onMap && !checkV2(v.x, v.y)) return;
if (!v.damage) {
throw new Error(
`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
});
}
}
});
// 地图伤害
const floor = core.status.maps[this.floorId];
const width = floor.width;
const height = floor.height;
const objs = core.getMapBlocksObj(this.floorId);
const startX =
onMap && core.bigmap.v2
? Math.max(0, core.bigmap.posX - core.bigmap.extend)
: 0;
const endX =
onMap && core.bigmap.v2
? Math.min(
width,
core.bigmap.posX + core._WIDTH_ + core.bigmap.extend + 1
)
: width;
const startY =
onMap && core.bigmap.v2
? Math.max(0, core.bigmap.posY - core.bigmap.extend)
: 0;
const endY =
onMap && core.bigmap.v2
? Math.min(
height,
core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend + 1
)
: height;
for (let x = startX; x < endX; x++) {
for (let y = startY; y < endY; y++) {
const id = `${x},${y}` as LocString;
const dam = this.mapDamage[id];
if (!dam || objs[id]?.event.noPass) continue;
if (dam.damage === 0) continue;
const damage = core.formatBigNumber(dam.damage, true);
const color = dam.damage < 0 ? '#6eff6a' : '#fa3';
core.status.damage.extraData.push({
text: damage,
px: 32 * x + 16,
py: 32 * (y + 1) - 14,
color,
alpha: 1
});
}
}
}
} }
export class DamageEnemy<T extends EnemyIds = EnemyIds> { export class DamageEnemy<T extends EnemyIds = EnemyIds> {
@ -491,6 +582,7 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
const loc = `${x},${y}` as LocString; const loc = `${x},${y}` as LocString;
const block = objs[loc]; const block = objs[loc];
if ( if (
block &&
block.event.noPass && block.event.noPass &&
block.event.cls !== 'enemys' && block.event.cls !== 'enemys' &&
block.event.cls !== 'enemy48' && block.event.cls !== 'enemy48' &&

View File

@ -18,8 +18,11 @@ core.control.updateDamage = function (floorId = core.status.floorId, ctx) {
// 计算伤害 // 计算伤害
core.plugin.damage.ensureFloorDamage(floorId); core.plugin.damage.ensureFloorDamage(floorId);
floor.enemy.calDamage(true, onMap); floor.enemy.calDamage(true, onMap);
floor.enemy.calMapDamage(true);
core.status.damage.data = []; core.status.damage.data = [];
floor.enemy.render();
// this._updateDamage_damage(floorId, onMap); // this._updateDamage_damage(floorId, onMap);
// this._updateDamage_extraDamage(floorId, onMap); // this._updateDamage_extraDamage(floorId, onMap);
getItemDetail(floorId, onMap); // 宝石血瓶详细信息 getItemDetail(floorId, onMap); // 宝石血瓶详细信息

View File

@ -79,6 +79,24 @@ export function checkV2(x?: number, y?: number) {
); );
} }
export function formatDamage(damage: number): DamageString {
let dam = '';
let color = '';
if (!Number.isFinite(damage)) {
dam = '???';
color = '#f22';
} else {
dam = core.formatBigNumber(damage, true);
if (damage <= 0) color = '#1f1';
else if (damage < core.status.hero.hp / 3) color = '#fff';
else if (damage < (core.status.hero.hp * 2) / 3) color = '#ff0';
else if (damage < core.status.hero.hp) color = '#f93';
else color = '#f22';
}
return { damage: dam, color: color as Color };
}
declare global { declare global {
interface GamePluginUtils { interface GamePluginUtils {
ofDir: typeof ofDir; ofDir: typeof ofDir;