光环绘制

This commit is contained in:
AncTe committed 2023-07-14 11:22:36 +08:00
1 parent faf5a5c0c3
commit f72d2161e5
10 files changed
+87 -180

No files matched your search

+25 -7
View File
@@ -54,6 +54,7 @@ interface HaloData<T extends keyof HaloType = keyof HaloType> {
type: T;
data: HaloType[T];
from: DamageEnemy;
special: number;
}
interface DamageDelta {
@@ -107,8 +108,8 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
* 计算怪物真实属性
* @param noCache 是否不使用缓存
*/
calRealAttribute(noCache: boolean = false) {
if (!noCache) return;
calRealAttribute() {
this.haloList = [];
this.list.forEach(v => {
v.reset();
v.preProvideHalo();
@@ -127,7 +128,7 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
* @param noCache 是否不使用缓存
*/
calDamage(noCache: boolean = false, onMap: boolean = false) {
if (noCache) this.calRealAttribute(noCache);
if (noCache) this.calRealAttribute();
this.list.forEach(v => {
v.calDamage(void 0, onMap);
});
@@ -137,9 +138,8 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
* 计算地图伤害
* @param noCache 是否不使用缓存
*/
calMapDamage(noCache: boolean = false) {
if (!noCache) return;
if (noCache) this.mapDamage = {};
calMapDamage() {
this.mapDamage = {};
const hero = getHeroStatusOn(
realStatus,
core.status.hero.loc.x,
@@ -200,7 +200,7 @@ export class EnemyCollection implements RangeCollection<DamageEnemy> {
) {
if (cal) {
this.calDamage(noCache, true);
this.calMapDamage(noCache);
this.calMapDamage();
}
core.status.damage.data = [];
core.status.damage.extraData = [];
@@ -527,6 +527,12 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
e.damageDecline += this.enemy.iceHalo ?? 0;
});
this.providedHalo.push(21);
col.haloList.push({
type: 'square',
data: { x: this.x, y: this.y, d: 7 },
special: 21,
from: this
});
}
// 冰封之核
@@ -535,6 +541,12 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
e.defBuff += this.enemy.iceCore ?? 0;
});
this.providedHalo.push(26);
col.haloList.push({
type: 'square',
data: { x: this.x, y: this.y, d: 5 },
special: 26,
from: this
});
}
// 火焰之核
@@ -543,6 +555,12 @@ export class DamageEnemy<T extends EnemyIds = EnemyIds> {
e.atkBuff += this.enemy.fireCore ?? 0;
});
this.providedHalo.push(27);
col.haloList.push({
type: 'square',
data: { x: this.x, y: this.y, d: 5 },
special: 27,
from: this
});
}
col.applyHalo('square', { x: this.x, y: this.y, d: 7 }, square7);
-55
View File
@@ -1,55 +0,0 @@
///<reference path="../../../src/types/core.d.ts" />
/**
* 绘制光环范围
* @param {CanvasRenderingContext2D} ctx
* @param {boolean} onMap
*/
export function drawHalo(ctx, onMap) {
if (main.replayChecking) return;
if (!core.getLocalStorage('showHalo', true)) return;
// todo: 不使用 core.status.checkBlock
const halo = core.status.checkBlock.halo;
ctx.save();
for (const [loc, range] of Object.entries(halo)) {
const [x, y] = loc.split(',').map(v => parseInt(v));
for (const r of range) {
const [type, value, color, border] = r.split(':');
if (type === 'square') {
// 正方形光环
const n = parseInt(value);
const r = Math.floor(n / 2);
let left = x - r,
right = x + r,
top = y - r,
bottom = y + r;
if (onMap && core.bigmap.v2) {
left -= core.bigmap.posX;
top -= core.bigmap.posY;
right -= core.bigmap.posX;
bottom -= core.bigmap.posY;
if (
right < -1 ||
left > core._PX_ / 32 + 1 ||
top < -1 ||
bottom > core._PY_ / 32 + 1
) {
continue;
}
}
ctx.fillStyle = color;
ctx.strokeStyle = border ?? color;
ctx.lineWidth = 1;
ctx.globalAlpha = 0.1;
ctx.fillRect(left * 32, top * 32, n * 32, n * 32);
ctx.globalAlpha = 0.6;
ctx.strokeRect(left * 32, top * 32, n * 32, n * 32);
}
}
}
ctx.restore();
}
core.plugin.halo = {
drawHalo
};
+50
View File
@@ -0,0 +1,50 @@
const haloColor: Record<number, string[]> = {
21: ['cyan'],
26: ['blue'],
27: ['red']
};
export function drawHalo(
ctx: CanvasRenderingContext2D,
onMap: boolean,
floorId: FloorIds
) {
if (main.replayChecking) return;
if (!core.getLocalStorage('showHalo', true)) return;
const list = core.status.maps[floorId].enemy.haloList;
ctx.save();
for (const halo of list) {
if (halo.type === 'square') {
const { x, y, d } = halo.data;
const [color, border] = haloColor[halo.special];
const r = Math.floor(d / 2);
let left = x - r,
right = x + r,
top = y - r,
bottom = y + r;
if (onMap && core.bigmap.v2) {
left -= core.bigmap.posX;
top -= core.bigmap.posY;
right -= core.bigmap.posX;
bottom -= core.bigmap.posY;
if (
right < -1 ||
left > core._PX_ / 32 + 1 ||
top < -1 ||
bottom > core._PY_ / 32 + 1
) {
continue;
}
}
ctx.fillStyle = color;
ctx.strokeStyle = border ?? color;
ctx.lineWidth = 1;
ctx.globalAlpha = 0.1;
ctx.fillRect(left * 32, top * 32, d * 32, d * 32);
ctx.globalAlpha = 0.6;
ctx.strokeRect(left * 32, top * 32, d * 32, d * 32);
}
}
ctx.restore();
}
+2 -4
View File
@@ -19,15 +19,13 @@ core.control.updateDamage = function (floorId = core.status.floorId, ctx) {
core.plugin.damage.ensureFloorDamage(floorId);
floor.enemy.calDamage(true, onMap);
floor.enemy.calMapDamage(true);
floor.enemy.calMapDamage();
core.status.damage.data = [];
floor.enemy.render();
// this._updateDamage_damage(floorId, onMap);
// this._updateDamage_extraDamage(floorId, onMap);
getItemDetail(floorId, onMap); // 宝石血瓶详细信息
this.drawDamage(ctx);
this.drawDamage(ctx, floorId);
};
// 获取宝石信息 并绘制
+3 -3
View File
@@ -1,5 +1,5 @@
///<reference path="../../../src/types/core.d.ts" />
export {};
import { drawHalo } from './halo';
// 伤害弹出
// 复写阻激夹域检测
@@ -40,9 +40,9 @@ control.prototype.checkBlock = function (forceMockery) {
/**
* @param {CanvasRenderingContext2D} ctx
*/
control.prototype._drawDamage_draw = function (ctx, onMap) {
control.prototype._drawDamage_draw = function (ctx, onMap, floorId) {
if (!core.hasItem('book')) return;
core.plugin.halo.drawHalo(ctx, onMap);
drawHalo(ctx, onMap, floorId);
core.setFont(ctx, "14px 'normal'");
core.setTextAlign(ctx, 'center');