fix:败移交换怪物属性

This commit is contained in:
ShakeFlower 2025-02-14 15:43:37 +08:00
parent c74804fc6d
commit 18783efcd2
2 changed files with 32 additions and 26 deletions

View File

@ -3089,6 +3089,31 @@ events.prototype.moveEnemyOnPoint = function (fromX, fromY, toX, toY, floorId, n
}
}
////// 将两个点的怪物属性交换 //////
events.prototype.switchEnemyOnPoint = function (fromX, fromY, toX, toY, floorId, norefresh) {
floorId = floorId || core.status.floorId;
const spos = fromX + "," + fromY,
aimpos = toX + "," + toY;
if (!flags.enemyOnPoint) return;
if (!flags.enemyOnPoint.hasOwnProperty(floorId)) return;
const enemyOnFloor = flags.enemyOnPoint[floorId];
let fromInfo, toInfo;
if (enemyOnFloor.hasOwnProperty(spos)) fromInfo = core.clone(enemyOnFloor[spos]);
if (enemyOnFloor.hasOwnProperty(aimpos)) toInfo = core.clone(enemyOnFloor[aimpos]);
// 删除旧位置信息
if (fromInfo) delete enemyOnFloor[spos];
if (toInfo) delete enemyOnFloor[aimpos];
// 设置新位置信息
if (fromInfo) enemyOnFloor[aimpos] = fromInfo;
if (toInfo) enemyOnFloor[spos] = toInfo;
if (!norefresh) core.updateStatusBar();
}
////// 设置楼层属性 //////
events.prototype.setFloorInfo = function (name, value, floorId, prefix) {
floorId = floorId || core.status.floorId;

View File

@ -319,8 +319,8 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
let failMoveInfo;
if (core.enemys.hasSpecial(special, 29)) {
for (let i = 2; i < core.__SIZE__ - 1; i++) {
const aimx = hx + core.utils.scan[direction] * i,
aimy = hy + core.utils.scan[direction] * i;
const aimx = hx + core.utils.scan[direction].x * i,
aimy = hy + core.utils.scan[direction].y * i;
if (aimx < 0 || aimx > core.__SIZE__ - 1 || aimy < 0 || aimy > core.__SIZE__ - 1) break;
if (['enemys', 'enemy48'].includes(core.getBlockCls(aimx, aimy))) {
failMoveInfo = { aimx, aimy, aimId: core.getBlockId(aimx, aimy) };
@ -416,25 +416,6 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
}
*/
function switchEnemyOnPoint(sx, sy, aimx, aimy) {
const spos = sx + "," + sy,
aimpos = aimx + "," + aimy;
if (!flags.enemyOnPoint) return;
if (!flags.enemyOnPoint.hasOwnProperty(core.status.floorId)) return;
const enemyOnFloor = flags.enemyOnPoint[core.status.floorId];
let sinfo, aiminfo;
if (enemyOnFloor.hasOwnProperty(spos)) sinfo = core.clone(enemyOnFloor[spos]);
if (enemyOnFloor.hasOwnProperty(aimpos)) aiminfo = core.clone(enemyOnFloor[aimpos]);
if (sinfo) {
delete enemyOnFloor[spos];
enemyOnFloor[aimpos] = sinfo;
}
if (aiminfo) {
delete enemyOnFloor[aimpos];
enemyOnFloor[spos] = aiminfo;
}
}
if (!failMove) {
// 如果事件不为空,将其插入
if (todo.length > 0) core.insertAction(todo, x, y);
@ -455,15 +436,15 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
}
}
else {
const { aimx, aimy, aimId } = failMoveInfo;
if (core.getBlockId(x, y) === enemyId && failMoveInfo
&& core.getBlockId(failMoveInfo.aimx, failMoveInfo.aimy) === failMoveInfo.aimId) {
&& core.getBlockId(aimx, aimy) === aimId) {
const doFailMove =
[{ "type": "setBlock", "number": enemyId, "loc": [[failMoveInfo.aimx, failMoveInfo.aimy]], "time": 50 },
{ "type": "setBlock", "number": failMoveInfo.aimId, "loc": [[x, y]], "time": 50 },
[{ "type": "setBlock", "number": enemyId, "loc": [[aimx, aimy]], "time": 50 },
{ "type": "setBlock", "number": aimId, "loc": [[x, y]], "time": 50 },
{ "type": "function", "function": `function () { core.switchEnemyOnPoint(${x},${y},${aimx},${aimy}) }` },
]
core.insertAction(doFailMove);
// to be tested: 怪物残血能否正确迁移数据
switchEnemyOnPoint(x, y, failMoveInfo.aimx, failMoveInfo.aimy);
}
}