mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-04-19 17:16:08 +08:00
fix: 捕捉
This commit is contained in:
parent
b1a28b6b3d
commit
0084dafaf0
@ -2833,6 +2833,9 @@ events.prototype._action_function = function (data, x, y, prefix) {
|
||||
if (typeof func == 'string' && func.indexOf('function') == 0) {
|
||||
eval('(' + func + ')()');
|
||||
}
|
||||
if (typeof func === 'function') {
|
||||
func();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
var enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80 =
|
||||
{
|
||||
"greenSlime": {"name":"绿头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
|
||||
"greenSlime": {"name":"绿头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[27]},
|
||||
"redSlime": {"name":"红头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[16,18],"value":10},
|
||||
"blackSlime": {"name":"青头怪","hp":0,"atk":0,"def":0,"money":0,"exp":0,"point":0,"special":[]},
|
||||
"slimelord": {"name":"怪王","hp":100,"atk":120,"def":0,"money":10,"exp":0,"point":0,"special":[1,9]},
|
||||
|
@ -30,7 +30,7 @@ main.floors.sample1=
|
||||
[ 0, 0, 0,151, 0, 0, 0,152,152,221, 0,221,153],
|
||||
[ 0, 0, 0,151, 0, 0, 0,121, 0, 0, 0, 0,153],
|
||||
[151, 0,151,151, 0,153,153,153,153,153,153,153,153],
|
||||
[ 0, 0, 0, 0, 0, 0, 0,164, 0, 0,163, 0, 0],
|
||||
[ 0, 0, 0, 0,201, 0, 0,164, 0, 0,163, 0, 0],
|
||||
[ 1, 1, 1, 1, 0, 20, 0, 0, 0,162, 0,161, 0],
|
||||
[ 1, 0,123, 1, 0, 20,124, 0,121, 0,122, 0,126],
|
||||
[ 1, 0, 0, 1, 88, 20, 0, 0, 0, 0, 0, 0, 0]
|
||||
@ -626,5 +626,12 @@ main.floors.sample1=
|
||||
},
|
||||
"width": 13,
|
||||
"height": 13,
|
||||
"beforeBattle": {}
|
||||
"beforeBattle": {},
|
||||
"cannotMoveIn": {},
|
||||
"bg2map": [
|
||||
|
||||
],
|
||||
"fg2map": [
|
||||
|
||||
]
|
||||
}
|
@ -1059,14 +1059,10 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = {
|
||||
let x = this.x;
|
||||
let y = this.y;
|
||||
const { x: dx, y: dy } = core.utils.scan[dir];
|
||||
this.col.list.forEach(v => {
|
||||
if (v.x === x + dx * 2 && v.y === y + dy * 2) {
|
||||
const loc = `${x + dx},${y + dy}`;
|
||||
this.setMapDamage(damage, loc, 0);
|
||||
damage[loc].ambush = damage[loc].ambush ?? [];
|
||||
damage[loc].ambush.push(this);
|
||||
}
|
||||
});
|
||||
const loc = `${x + dx},${y + dy}`;
|
||||
this.setMapDamage(damage, loc, 0);
|
||||
damage[loc].ambush = damage[loc].ambush ?? [];
|
||||
damage[loc].ambush.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1307,10 +1303,9 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = {
|
||||
for (const enemy of info.ambush) {
|
||||
actions.push({
|
||||
type: 'function',
|
||||
function:
|
||||
'function() { ' +
|
||||
`core.battle(${enemy.x}, ${enemy.y}, true, core.doAction); ` +
|
||||
'}',
|
||||
function: () => {
|
||||
core.battle(enemy, void 0, true, core.doAction);
|
||||
},
|
||||
async: true
|
||||
});
|
||||
}
|
||||
|
@ -23,25 +23,37 @@ export function getEnemy(
|
||||
|
||||
function init() {
|
||||
core.enemys.canBattle = function canBattle(
|
||||
x: number,
|
||||
x: number | DamageEnemy,
|
||||
y: number,
|
||||
floorId: FloorIds = core.status.floorId
|
||||
) {
|
||||
const enemy = getEnemy(x, y, floorId);
|
||||
const { damage } = enemy!.calDamage();
|
||||
const enemy = typeof x === 'number' ? getEnemy(x, y, floorId) : x;
|
||||
if (!enemy) {
|
||||
throw new Error(
|
||||
`Cannot get enemy on x:${x}, y:${y}, floor: ${floorId}`
|
||||
);
|
||||
}
|
||||
const { damage } = enemy.calDamage();
|
||||
|
||||
return damage < core.status.hero.hp;
|
||||
};
|
||||
|
||||
core.events.battle = function battle(
|
||||
x: number,
|
||||
x: number | DamageEnemy,
|
||||
y: number,
|
||||
force: boolean = false,
|
||||
callback?: () => void
|
||||
) {
|
||||
core.saveAndStopAutomaticRoute();
|
||||
const enemy = getEnemy(x, y);
|
||||
const isLoc = typeof x === 'number';
|
||||
const enemy = isLoc ? getEnemy(x, y) : x;
|
||||
if (!enemy) {
|
||||
throw new Error(
|
||||
`Cannot battle with enemy since no enemy on ${x},${y}`
|
||||
);
|
||||
}
|
||||
// 非强制战斗
|
||||
// @ts-ignore
|
||||
if (!core.canBattle(x, y) && !force && !core.status.event.id) {
|
||||
core.stopSound();
|
||||
core.playSound('操作失败');
|
||||
@ -52,7 +64,7 @@ function init() {
|
||||
if (!core.status.event.id) core.autosave(true);
|
||||
// 战前事件
|
||||
// 战后事件
|
||||
core.afterBattle(enemy, x, y);
|
||||
core.afterBattle(enemy, isLoc ? x : enemy.x, y);
|
||||
callback?.();
|
||||
};
|
||||
|
||||
@ -149,5 +161,22 @@ loading.once('coreInit', init);
|
||||
declare global {
|
||||
interface Enemys {
|
||||
getCurrentEnemys(floorId: FloorIds): CurrentEnemy[];
|
||||
canBattle(enemy: DamageEnemy, _?: number, floorId?: FloorIds): boolean;
|
||||
canBattle(x: number, y: number, floorId?: FloorIds): boolean;
|
||||
}
|
||||
|
||||
interface Events {
|
||||
battle(
|
||||
enemy: DamageEnemy,
|
||||
_?: number,
|
||||
force?: boolean,
|
||||
callback?: () => void
|
||||
): void;
|
||||
battle(
|
||||
x: number,
|
||||
y?: number,
|
||||
force?: boolean,
|
||||
callback?: () => void
|
||||
): void;
|
||||
}
|
||||
}
|
||||
|
16
src/types/enemy.d.ts
vendored
16
src/types/enemy.d.ts
vendored
@ -253,22 +253,6 @@ interface Enemys {
|
||||
getEnemys(): {
|
||||
[P in EnemyIds]: Enemy<P>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 判定主角当前能否打败某只敌人
|
||||
* @example core.canBattle('greenSlime',0,0,'MT0') // 能否打败主塔0层左上角的绿头怪(假设有)
|
||||
* @param enemy 敌人id或敌人对象
|
||||
* @param x 敌人的横坐标
|
||||
* @param y 敌人的纵坐标
|
||||
* @param floorId 敌人所在的地图
|
||||
* @returns true表示可以打败,false表示无法打败
|
||||
*/
|
||||
canBattle(
|
||||
x: number,
|
||||
y: number,
|
||||
floorId?: FloorIds,
|
||||
dir?: Dir | 'none' | (Dir | 'none')[]
|
||||
): boolean;
|
||||
}
|
||||
|
||||
declare const enemys: new () => Enemys;
|
||||
|
16
src/types/event.d.ts
vendored
16
src/types/event.d.ts
vendored
@ -99,22 +99,6 @@ interface Events extends EventData {
|
||||
*/
|
||||
trigger(x: number, y: number, callback?: () => void): void;
|
||||
|
||||
/**
|
||||
* 战斗,如果填写了坐标就会删除该点的敌人并触发战后事件
|
||||
* @example core.battle('greenSlime'); // 和从天而降的绿头怪战斗(如果打得过)
|
||||
* @param id 敌人id,必填
|
||||
* @param x 敌人的横坐标
|
||||
* @param y 敌人的纵坐标
|
||||
* @param force true表示强制战斗
|
||||
* @param callback 回调函数
|
||||
*/
|
||||
battle(
|
||||
x: number,
|
||||
y: number,
|
||||
force: boolean = false,
|
||||
callback?: () => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* 开门(包括三种基础墙)
|
||||
* @example core.openDoor(0, 0, true, core.jumpHero); // 打开左上角的门,需要钥匙,然后主角原地跳跃半秒
|
||||
|
Loading…
Reference in New Issue
Block a user