优化瞬移判定和自动寻路算法
This commit is contained in:
parent
6f0a66bb11
commit
49ca100dfd
@ -1373,14 +1373,11 @@ showDisable: 隐藏点是否不返回null,true表示不返回null
|
||||
loadFloor: fn(floorId?: string, map?: ?)
|
||||
从文件或存档中加载某个楼层
|
||||
|
||||
generateMovableArray: fn(floorId?: string, x?: number, y?: number, direction?: string)
|
||||
generateMovableArray: fn(floorId?: string)
|
||||
可通行性判定
|
||||
例如:core.generateMovableArray(); // 判断当前地图主角从各点能向何方向移动
|
||||
floorId: 地图id,不填视为当前地图
|
||||
x: 起点横坐标,不填视为挨个判定
|
||||
y: 起点纵坐标,不填视为挨个判定
|
||||
direction: 可选,必须和坐标一起使用。填写后将只检查是否可向该方向移动并返回布尔值
|
||||
返回值:不设置坐标时为从各点可移动方向的三维数组,设置坐标但不设置方向时为该点可移动方向的一维数组,都设置时为布尔值
|
||||
返回值:从各点可移动方向的三维数组
|
||||
|
||||
terrainExists: fn(x: number, y: number, id?: string, floorId?: string) -> bool
|
||||
某个点是否存在(指定的)地形
|
||||
|
||||
@ -1883,6 +1883,10 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
|
||||
"!type": "number",
|
||||
"!doc": "新版大地图绘制方式的分界线"
|
||||
},
|
||||
"extend": {
|
||||
"!type": "number",
|
||||
"!doc": "新版大地图模式下向每一侧额外计算的数量"
|
||||
},
|
||||
"scale": {
|
||||
"!type": "number",
|
||||
"!doc": "缩略图的比例放缩"
|
||||
@ -3179,8 +3183,8 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
|
||||
"!type": "fn(floorId?: string, map?: ?)"
|
||||
},
|
||||
"generateMovableArray": {
|
||||
"!doc": "可通行性判定<br/>例如:core.generateMovableArray(); // 判断当前地图主角从各点能向何方向移动<br/>floorId: 地图id,不填视为当前地图<br/>x: 起点横坐标,不填视为挨个判定<br/>y: 起点纵坐标,不填视为挨个判定<br/>direction: 可选,必须和坐标一起使用。填写后将只检查是否可向该方向移动并返回布尔值<br/>返回值:不设置坐标时为从各点可移动方向的三维数组,设置坐标但不设置方向时为该点可移动方向的一维数组,都设置时为布尔值",
|
||||
"!type": "fn(floorId?: string, x?: number, y?: number, direction?: string)"
|
||||
"!doc": "可通行性判定<br/>例如:core.generateMovableArray(); // 判断当前地图主角从各点能向何方向移动<br/>floorId: 地图id,不填视为当前地图<br/>返回值:从各点可移动方向的三维数组",
|
||||
"!type": "fn(floorId?: string) -> [[[string]]]"
|
||||
},
|
||||
"terrainExists": {
|
||||
"!doc": "某个点是否存在(指定的)地形",
|
||||
|
||||
@ -1126,7 +1126,7 @@ control.prototype.updateDamage = function (floorId, ctx) {
|
||||
if (!onMap) {
|
||||
var width = core.floors[floorId].width, height = core.floors[floorId].height;
|
||||
// 地图过大的缩略图不绘制显伤
|
||||
if (width * height > core.status.damage.bigmapThreshold) return;
|
||||
if (width * height > (core.__SIZE__ + 2 * core.bigmap.extend) * (core.__SIZE__ + 2 * core.bigmap.extend)) return;
|
||||
}
|
||||
this._updateDamage_damage(floorId, onMap);
|
||||
this._updateDamage_extraDamage(floorId, onMap);
|
||||
@ -1143,12 +1143,10 @@ control.prototype._updateDamage_damage = function (floorId, onMap) {
|
||||
|
||||
// v2优化,只绘制范围内的部分
|
||||
if (onMap && core.bigmap.v2) {
|
||||
if (x < core.bigmap.posX - core.status.damage.bigmapLimit
|
||||
|| x > core.bigmap.posX + core.__SIZE__ + core.status.damage.bigmapLimit
|
||||
|| y < core.bigmap.posY - core.status.damage.bigmapLimit
|
||||
|| y > core.bigmap.posY + core.__SIZE__ + core.status.damage.bigmapLimit) {
|
||||
return;
|
||||
}
|
||||
if (x < core.bigmap.posX - core.bigmap.extend || x > core.bigmap.posX + core.__SIZE__ + core.bigmap.extend
|
||||
|| y < core.bigmap.posY - core.bigmap.extend || y > core.bigmap.posY + core.__SIZE__ + core.bigmap.extend) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!block.disable && block.event.cls.indexOf('enemy') == 0 && block.event.displayDamage !== false) {
|
||||
@ -1171,10 +1169,10 @@ control.prototype._updateDamage_extraDamage = function (floorId, onMap) {
|
||||
if (!core.flags.displayExtraDamage) return;
|
||||
|
||||
var width = core.floors[floorId].width, height = core.floors[floorId].height;
|
||||
var startX = onMap && core.bigmap.v2 ? Math.max(0, core.bigmap.posX - core.status.damage.bigmapLimit) : 0;
|
||||
var endX = onMap && core.bigmap.v2 ? Math.min(width, core.bigmap.posX + core.__SIZE__ + core.status.damage.bigmapLimit + 1) : width;
|
||||
var startY = onMap && core.bigmap.v2 ? Math.max(0, core.bigmap.posY - core.status.damage.bigmapLimit) : 0;
|
||||
var endY = onMap && core.bigmap.v2 ? Math.min(height, core.bigmap.posY + core.__SIZE__ + core.status.damage.bigmapLimit + 1) : height;
|
||||
var startX = onMap && core.bigmap.v2 ? Math.max(0, core.bigmap.posX - core.bigmap.extend) : 0;
|
||||
var endX = onMap && core.bigmap.v2 ? Math.min(width, core.bigmap.posX + core.__SIZE__ + core.bigmap.extend + 1) : width;
|
||||
var startY = onMap && core.bigmap.v2 ? Math.max(0, core.bigmap.posY - core.bigmap.extend) : 0;
|
||||
var endY = onMap && core.bigmap.v2 ? Math.min(height, core.bigmap.posY + core.__SIZE__ + core.bigmap.extend + 1) : height;
|
||||
|
||||
for (var x=startX;x<endX;x++) {
|
||||
for (var y=startY;y<endY;y++) {
|
||||
@ -1204,8 +1202,8 @@ control.prototype.drawDamage = function (ctx) {
|
||||
|
||||
if (onMap && core.bigmap.v2) {
|
||||
// 检查是否需要重算...
|
||||
if (Math.abs(core.bigmap.posX - core.status.damage.posX) >= core.status.damage.bigmapLimit - 1
|
||||
|| Math.abs(core.bigmap.posY - core.status.damage.posY) >= core.status.damage.bigmapLimit - 1) {
|
||||
if (Math.abs(core.bigmap.posX - core.status.damage.posX) >= core.bigmap.extend - 1
|
||||
|| Math.abs(core.bigmap.posY - core.status.damage.posY) >= core.bigmap.extend - 1) {
|
||||
return this.updateDamage();
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,6 +99,7 @@ function core() {
|
||||
height: this.__SIZE__,
|
||||
v2: false,
|
||||
threshold: 512,
|
||||
extend: 10,
|
||||
scale: 1.0,
|
||||
tempCanvas: null, // A temp canvas for drawing
|
||||
}
|
||||
@ -134,8 +135,6 @@ function core() {
|
||||
'damage': { // 每个点的显伤绘制
|
||||
'posX': 0,
|
||||
'posY': 0,
|
||||
'bigmapThreshold': 1024,
|
||||
'bigmapLimit': 10,
|
||||
'data': [],
|
||||
'extraData': [],
|
||||
},
|
||||
|
||||
64
libs/maps.js
64
libs/maps.js
@ -484,47 +484,53 @@ maps.prototype.getFgNumber = function (x, y, floorId) {
|
||||
// ------ 当前能否朝某方向移动,能否瞬间移动 ------ //
|
||||
|
||||
////// 生成全图的当前可移动信息 //////
|
||||
maps.prototype.generateMovableArray = function (floorId, x, y, direction) {
|
||||
maps.prototype.generateMovableArray = function (floorId) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
if (!floorId) return null;
|
||||
var arrays = this._generateMovableArray_arrays(floorId);
|
||||
|
||||
var width = core.floors[floorId].width, height = core.floors[floorId].height;
|
||||
var bgArray = this.getBgMapArray(floorId),
|
||||
fgArray = this.getFgMapArray(floorId),
|
||||
eventArray = this.getMapArray(floorId);
|
||||
|
||||
var generate = function (x, y, direction) {
|
||||
if (direction != null) {
|
||||
return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, {
|
||||
bgArray: bgArray, fgArray: fgArray, eventArray: eventArray
|
||||
});
|
||||
}
|
||||
return ["left", "down", "up", "right"].filter(function (direction) {
|
||||
return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, {
|
||||
bgArray: bgArray, fgArray: fgArray, eventArray: eventArray
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (x != null && y != null) return generate(x, y, direction);
|
||||
var array = [];
|
||||
for (var x = 0; x < width; x++) {
|
||||
array[x] = [];
|
||||
for (var y = 0; y < height; y++) {
|
||||
array[x][y] = generate(x, y, direction);
|
||||
for (var x = 0; x < width; ++x) {
|
||||
array[x] = Array(height).fill([]);
|
||||
}
|
||||
var v2 = floorId == core.status.floorId && core.bigmap.v2;
|
||||
var startX = v2 ? Math.max(0, core.bigmap.posX - core.bigmap.extend) : 0;
|
||||
var endX = v2 ? Math.min(width, core.bigmap.posX + core.__SIZE__ + core.bigmap.extend + 1) : width;
|
||||
var startY = v2 ? Math.max(0, core.bigmap.posY - core.bigmap.extend) : 0;
|
||||
var endY = v2 ? Math.min(height, core.bigmap.posY + core.__SIZE__ + core.bigmap.extend + 1) : height;
|
||||
|
||||
for (var x = startX; x < endX; x++) {
|
||||
for (var y = startY; y < endY; y++) {
|
||||
array[x][y] = ["left", "down", "up", "right"].filter(function (direction) {
|
||||
return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, arrays);
|
||||
});
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
maps.prototype._generateMovableArray_arrays = function (floorId) {
|
||||
return {
|
||||
bgArray: this.getBgMapArray(floorId),
|
||||
fgArray: this.getFgMapArray(floorId),
|
||||
eventArray: this.getMapArray(floorId)
|
||||
};
|
||||
}
|
||||
|
||||
////// 勇士能否前往某方向 //////
|
||||
maps.prototype.canMoveHero = function (x, y, direction, floorId) {
|
||||
if (x == null) x = core.getHeroLoc('x');
|
||||
if (y == null) y = core.getHeroLoc('y');
|
||||
direction = direction || core.getHeroLoc('direction');
|
||||
return this.generateMovableArray(floorId, x, y, direction);
|
||||
return this._canMoveHero_checkPoint(x, y, direction, floorId);
|
||||
}
|
||||
|
||||
maps.prototype._canMoveHero_checkPoint = function (x, y, direction, floorId, extraData) {
|
||||
maps.prototype._canMoveHero_checkPoint = function (x, y, direction, floorId, arrays) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
if (!floorId) return false;
|
||||
arrays = arrays || this._generateMovableArray_arrays(floorId);
|
||||
|
||||
// 1. 检查该点 cannotMove
|
||||
if (core.inArray((core.floors[floorId].cannotMove || {})[x + "," + y], direction))
|
||||
return false;
|
||||
@ -534,13 +540,9 @@ maps.prototype._canMoveHero_checkPoint = function (x, y, direction, floorId, ext
|
||||
return false;
|
||||
|
||||
// 2. 检查该点素材的 cannotOut 和下一个点的 cannotIn
|
||||
if (this._canMoveHero_checkCannotInOut([
|
||||
extraData.bgArray[y][x], extraData.fgArray[y][x], extraData.eventArray[y][x]
|
||||
], "cannotOut", direction))
|
||||
if (this._canMoveHero_checkCannotInOut(Object.keys(arrays).map(function (name) { return arrays[name][y][x]; }), "cannotOut", direction))
|
||||
return false;
|
||||
if (this._canMoveHero_checkCannotInOut([
|
||||
extraData.bgArray[ny][nx], extraData.fgArray[ny][nx], extraData.eventArray[ny][nx]
|
||||
], "cannotIn", direction))
|
||||
if (this._canMoveHero_checkCannotInOut(Object.keys(arrays).map(function (name) { return arrays[name][ny][nx]; }), "cannotIn", direction))
|
||||
return false;
|
||||
|
||||
// 3. 检查是否能进将死的领域
|
||||
|
||||
@ -434,107 +434,60 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
||||
}
|
||||
|
||||
////// 绘制背景层 //////
|
||||
core.maps.drawBg = function (floorId, ctx) {
|
||||
core.maps.drawBg = function (floorId, config) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
var onMap = ctx == null;
|
||||
if (onMap) {
|
||||
ctx = core.canvas.bg;
|
||||
core.clearMap(ctx);
|
||||
|
||||
config = config || {};
|
||||
if (config.ctx == null) {
|
||||
config.onMap = true;
|
||||
config.ctx = 'bg';
|
||||
core.clearMap('bg');
|
||||
core.status.floorAnimateObjs = this._getFloorImages(floorId);
|
||||
}
|
||||
core.maps._drawBg_drawBackground(floorId, ctx);
|
||||
|
||||
core.maps._drawBg_drawBackground(floorId, config);
|
||||
// ------ 调整这两行的顺序来控制是先绘制贴图还是先绘制背景图块;后绘制的覆盖先绘制的。
|
||||
core.maps._drawFloorImages(floorId, ctx, 'bg');
|
||||
core.maps._drawBgFgMap(floorId, ctx, 'bg', onMap);
|
||||
core.maps._drawFloorImages(floorId, config.ctx, 'bg', null, null, config.onMap);
|
||||
core.maps._drawBgFgMap(floorId, 'bg', config);
|
||||
// 绘制背景层2
|
||||
core.maps._drawBgFgMap(floorId, ctx, 'bg2', onMap);
|
||||
};
|
||||
if (config.onMap) {
|
||||
config.ctx = 'bg2';
|
||||
core.clearMap('bg2');
|
||||
}
|
||||
core.maps._drawBgFgMap(floorId, 'bg2', config);
|
||||
}
|
||||
|
||||
////// 绘制前景层 //////
|
||||
core.maps.drawFg = function (floorId, ctx) {
|
||||
core.maps.drawFg = function (floorId, config) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
var onMap = ctx == null;
|
||||
if (onMap) {
|
||||
ctx = core.canvas.fg;
|
||||
config = config || {};
|
||||
if (config.ctx == null) {
|
||||
config.onMap = true;
|
||||
config.ctx = 'fg';
|
||||
core.clearMap('fg');
|
||||
core.status.floorAnimateObjs = this._getFloorImages(floorId);
|
||||
}
|
||||
|
||||
// ------ 调整这两行的顺序来控制是先绘制贴图还是先绘制前景图块;后绘制的覆盖先绘制的。
|
||||
this._drawFloorImages(floorId, ctx, 'fg');
|
||||
this._drawBgFgMap(floorId, ctx, 'fg', onMap);
|
||||
core.maps._drawFloorImages(floorId, config.ctx, 'fg', null, null, config.onMap);
|
||||
core.maps._drawBgFgMap(floorId, 'fg', config);
|
||||
// 绘制前景层2
|
||||
this._drawBgFgMap(floorId, ctx, 'fg2', onMap);
|
||||
};
|
||||
/* cannotIn/cannotOut适配 start*/
|
||||
core.maps.generateMovableArray = function (floorId, x, y, direction) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
if (!floorId) return null;
|
||||
var width = core.floors[floorId].width,
|
||||
height = core.floors[floorId].height;
|
||||
var bgArray = this.getBgMapArray(floorId),
|
||||
bg2Array = this._getBgFgMapArray('bg2', floorId),
|
||||
fgArray = this.getFgMapArray(floorId),
|
||||
fg2Array = this._getBgFgMapArray('fg2', floorId),
|
||||
eventArray = this.getMapArray(floorId);
|
||||
|
||||
var generate = function (x, y, direction) {
|
||||
if (direction != null) {
|
||||
return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, {
|
||||
bgArray: bgArray,
|
||||
fgArray: fgArray,
|
||||
bg2Array: bg2Array,
|
||||
fg2Array: fg2Array,
|
||||
eventArray: eventArray
|
||||
});
|
||||
}
|
||||
return ["left", "down", "up", "right"].filter(function (direction) {
|
||||
return core.maps._canMoveHero_checkPoint(x, y, direction, floorId, {
|
||||
bgArray: bgArray,
|
||||
fgArray: fgArray,
|
||||
bg2Array: bg2Array,
|
||||
fg2Array: fg2Array,
|
||||
eventArray: eventArray
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (x != null && y != null) return generate(x, y, direction);
|
||||
var array = [];
|
||||
for (var x = 0; x < width; x++) {
|
||||
array[x] = [];
|
||||
for (var y = 0; y < height; y++) {
|
||||
array[x][y] = generate(x, y);
|
||||
}
|
||||
if (config.onMap) {
|
||||
config.ctx = 'fg2';
|
||||
core.clearMap('fg2');
|
||||
}
|
||||
return array;
|
||||
};
|
||||
core.maps._canMoveHero_checkPoint = function (x, y, direction, floorId, extraData) {
|
||||
// 1. 检查该点 cannotMove
|
||||
if (core.inArray((core.floors[floorId].cannotMove || {})[x + "," + y], direction))
|
||||
return false;
|
||||
|
||||
var nx = x + core.utils.scan[direction].x,
|
||||
ny = y + core.utils.scan[direction].y;
|
||||
if (nx < 0 || ny < 0 || nx >= core.floors[floorId].width || ny >= core.floors[floorId].height)
|
||||
return false;
|
||||
|
||||
// 2. 检查该点素材的 cannotOut 和下一个点的 cannotIn
|
||||
if (this._canMoveHero_checkCannotInOut([
|
||||
extraData.bgArray[y][x], extraData.bg2Array[y][x], extraData.fgArray[y][x], extraData.fg2Array[y][x], extraData.eventArray[y][x]
|
||||
], "cannotOut", direction))
|
||||
return false;
|
||||
if (this._canMoveHero_checkCannotInOut([
|
||||
extraData.bgArray[ny][nx], extraData.bg2Array[ny][nx], extraData.fgArray[ny][nx], extraData.fg2Array[ny][nx], extraData.eventArray[ny][nx]
|
||||
], "cannotIn", direction))
|
||||
return false;
|
||||
|
||||
// 3. 检查是否能进将死的领域
|
||||
if (floorId == core.status.floorId && !core.flags.canGoDeadZone &&
|
||||
core.status.hero.hp <= (core.status.checkBlock.damage[nx + "," + ny] || 0) &&
|
||||
extraData.eventArray[ny][nx] == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
core.maps._drawBgFgMap(floorId, 'fg2', config);
|
||||
}
|
||||
/* cannotIn/cannotOut适配 start*/
|
||||
core.maps._generateMovableArray_arrays = function (floorId) {
|
||||
return {
|
||||
bgArray: this.getBgMapArray(floorId),
|
||||
fgArray: this.getFgMapArray(floorId),
|
||||
eventArray: this.getMapArray(floorId),
|
||||
bg2Array: this._getBgFgMapArray('bg2', floorId),
|
||||
fg2Array: this._getBgFgMapArray('fg2', floorId)
|
||||
};
|
||||
}
|
||||
},
|
||||
"itemShop": function () {
|
||||
// 道具商店相关的插件
|
||||
|
||||
8
runtime.d.ts
vendored
8
runtime.d.ts
vendored
@ -1458,12 +1458,9 @@ declare class maps {
|
||||
* 可通行性判定
|
||||
* @example core.generateMovableArray(); // 判断当前地图主角从各点能向何方向移动
|
||||
* @param floorId 地图id,不填视为当前地图
|
||||
* @param x 起点横坐标,不填视为挨个判定
|
||||
* @param y 起点纵坐标,不填视为挨个判定
|
||||
* @param direction 可选,必须和坐标一起使用。填写后将只检查是否可向该方向移动并返回布尔值
|
||||
* @returns 不设置坐标时为从各点可移动方向的三维数组,设置坐标但不设置方向时为该点可移动方向的一维数组,都设置时为布尔值
|
||||
* @returns 从各点可移动方向的三维数组
|
||||
*/
|
||||
generateMovableArray(floorId?: string, x?: number, y?: number, direction?: direction): boolean | Array<direction | Array<Array<direction>>>
|
||||
generateMovableArray(floorId?: string): Array<Array<Array<direction>>>
|
||||
|
||||
/**
|
||||
* 单点单朝向的可通行性判定
|
||||
@ -2758,6 +2755,7 @@ type core = {
|
||||
height: number
|
||||
v2: boolean
|
||||
threshold: number
|
||||
extend: number
|
||||
scale: number
|
||||
tempCanvas: CanvasRenderingContext2D // A temp canvas for drawing
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user