HumanBreak/public/project/plugin/popup.js

122 lines
3.9 KiB
JavaScript
Raw Normal View History

2023-02-28 18:21:29 +08:00
///<reference path="../../../src/types/core.d.ts" />
2023-04-16 17:05:47 +08:00
export {};
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
// 伤害弹出
// 复写阻激夹域检测
control.prototype.checkBlock = function (forceMockery) {
var x = core.getHeroLoc('x'),
y = core.getHeroLoc('y'),
loc = x + ',' + y;
var damage = core.status.checkBlock.damage[loc];
if (damage) {
if (!main.replayChecking)
core.addPop(
(x - core.bigmap.offsetX / 32) * 32 + 12,
(y - core.bigmap.offsetY / 32) * 32 + 20,
-damage.toString()
);
core.status.hero.hp -= damage;
var text =
Object.keys(core.status.checkBlock.type[loc] || {}).join('') ||
'伤害';
core.drawTip('受到' + text + damage + '点');
core.drawHeroAnimate('zone');
this._checkBlock_disableQuickShop();
core.status.hero.statistics.extraDamage += damage;
if (core.status.hero.hp <= 0) {
core.status.hero.hp = 0;
core.updateStatusBar();
core.events.lose();
return;
} else {
core.updateStatusBar();
2023-02-28 17:49:34 +08:00
}
2023-04-16 17:05:47 +08:00
}
this._checkBlock_repulse(core.status.checkBlock.repulse[loc]);
checkMockery(loc, forceMockery);
};
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
control.prototype.moveHero = function (direction, callback) {
// 如果正在移动直接return
if (core.status.heroMoving != 0) return;
if (core.isset(direction)) core.setHeroLoc('direction', direction);
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
const nx = core.nextX();
const ny = core.nextY();
if (core.status.checkBlock.mockery[`${nx},${ny}`]) {
core.autosave();
}
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
if (callback) return this.moveAction(callback);
this._moveHero_moving();
};
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
/**
* 电摇嘲讽
* @param {LocString} loc
* @param {boolean} force
*/
function checkMockery(loc, force) {
if (core.status.lockControl && !force) return;
const mockery = core.status.checkBlock.mockery[loc];
if (mockery) {
mockery.sort((a, b) => (a[0] === b[0] ? a[1] - b[1] : a[0] - b[0]));
const action = [];
const [tx, ty] = mockery[0];
let { x, y } = core.status.hero.loc;
const dir = x > tx ? 'left' : x < tx ? 'right' : y > ty ? 'up' : 'down';
const { x: dx, y: dy } = core.utils.scan[dir];
2023-02-28 17:49:34 +08:00
2023-04-16 17:05:47 +08:00
action.push({ type: 'changePos', direction: dir });
const blocks = core.getMapBlocksObj();
while (1) {
x += dx;
y += dy;
const block = blocks[`${x},${y}`];
if (block) {
block.event.cls === '';
if (
[
'animates',
'autotile',
'tileset',
'npcs',
2023-04-22 20:33:58 +08:00
'npc48',
'terrains'
2023-04-16 17:05:47 +08:00
].includes(block.event.cls)
) {
action.push(
{
type: 'hide',
loc: [[x, y]],
remove: true,
time: 0
},
{
type: 'function',
function: `function() { core.removeGlobalAnimate(${x}, ${y}) }`
},
{
type: 'animate',
name: 'hand',
loc: [x, y],
async: true
}
);
}
if (block.event.cls.startsWith('enemy')) {
action.push({ type: 'moveAction' });
2023-02-28 17:49:34 +08:00
}
}
2023-04-16 17:05:47 +08:00
action.push({ type: 'moveAction' });
if (x === tx && y === ty) break;
2023-02-28 17:49:34 +08:00
}
2023-04-16 17:05:47 +08:00
action.push({
type: 'function',
function: `function() { core.checkBlock(true); }`
});
action.push({ type: 'stopAsync' });
core.insertAction(action);
2023-02-28 17:49:34 +08:00
}
2023-04-16 17:05:47 +08:00
}