@cc-component/cc-pathfinding 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -64,8 +64,10 @@ declare global {
|
|
|
64
64
|
* @param allowOverlap 为 true 时该单位进入"允许重叠"模式,
|
|
65
65
|
* 与其他同样开启该开关的单位可以走到同一格(互相穿过,不再互相绕行/互相等待),
|
|
66
66
|
* 与终点是否相同无关
|
|
67
|
+
* @param moveDuration 本次移动的"单格移动时长",单位秒(越小越快);
|
|
68
|
+
* 不传或传 <= 0 时使用 InitMovementController 配置的默认值
|
|
67
69
|
*/
|
|
68
|
-
export function MoveTo(playerNode: Node, target: { row: number, col: number }, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap?: boolean): void
|
|
70
|
+
export function MoveTo(playerNode: Node, target: { row: number, col: number }, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap?: boolean, moveDuration?: number): void
|
|
69
71
|
/** 取消移动 */
|
|
70
72
|
export function CancelMove(playerNode: Node, preserveCurrent?: boolean): void
|
|
71
73
|
/** 销毁移动控制器 */
|
|
@@ -58,8 +58,9 @@ export class GridMovementController {
|
|
|
58
58
|
* allowOverlap:为 true 时该单位进入"允许重叠"模式,
|
|
59
59
|
* 与其他同样开启该开关的单位可以走到同一格(互相穿过、不互相绕行、不互相等待),
|
|
60
60
|
* 与终点是否相同无关;未开启的单位之间、以及开启与未开启之间仍保持互斥。
|
|
61
|
+
* moveDuration:本次移动的"单格移动时长",单位秒;不传或传非法值时用控制器的默认值。
|
|
61
62
|
*/
|
|
62
|
-
moveTo(playerNode: Node, target: Cell, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false): void {
|
|
63
|
+
moveTo(playerNode: Node, target: Cell, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false, moveDuration?: number): void {
|
|
63
64
|
const start = this.getPosition(playerNode);
|
|
64
65
|
if (start.row === target.row && start.col === target.col) {
|
|
65
66
|
return;
|
|
@@ -68,13 +69,13 @@ export class GridMovementController {
|
|
|
68
69
|
this.cancel(playerNode, true);
|
|
69
70
|
const route = this.traceRoute(start, target, attackDistance, openColor, allowOverlap, this.movementOwners.get(playerNode));
|
|
70
71
|
if (!route || route.length === 0 || this.isPathBlocked(start, target, route, attackDistance)) {
|
|
71
|
-
this.retryPathfinding(playerNode, target, attackDistance, openColor, callBack, allowOverlap);
|
|
72
|
+
this.retryPathfinding(playerNode, target, attackDistance, openColor, callBack, allowOverlap, moveDuration);
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
this.clearPathfindingRetry(playerNode);
|
|
76
77
|
route.shift();
|
|
77
|
-
this.startMovement(playerNode, route, start, target, attackDistance, openColor, callBack, allowOverlap);
|
|
78
|
+
this.startMovement(playerNode, route, start, target, attackDistance, openColor, callBack, allowOverlap, moveDuration);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/** 强制中止当前移动,可选择保留当前格子的临时占用。 */
|
|
@@ -121,7 +122,7 @@ export class GridMovementController {
|
|
|
121
122
|
* 执行逐格移动。
|
|
122
123
|
* 每次移动前会尝试保留下一格,失败说明被占用,就重新规划路径或延时重试。
|
|
123
124
|
*/
|
|
124
|
-
private startMovement(playerNode: Node, route: Cell[], start: Cell, target: Cell, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false): void {
|
|
125
|
+
private startMovement(playerNode: Node, route: Cell[], start: Cell, target: Cell, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false, moveDuration?: number): void {
|
|
125
126
|
const previousOwner = this.movementOwners.get(playerNode);
|
|
126
127
|
if (previousOwner) {
|
|
127
128
|
this.pathState.release(previousOwner);
|
|
@@ -130,6 +131,8 @@ export class GridMovementController {
|
|
|
130
131
|
this.movementOwners.set(playerNode, owner);
|
|
131
132
|
const shareToken = this.getShareToken(allowOverlap);
|
|
132
133
|
this.pathState.reserveCurrent(start, owner, shareToken);
|
|
134
|
+
// 单格移动时长:本次指定优先,否则用控制器默认值
|
|
135
|
+
const duration = this.resolveMoveDuration(moveDuration);
|
|
133
136
|
const version = this.bumpVersion(playerNode);
|
|
134
137
|
let previous = start;
|
|
135
138
|
let index = 0;
|
|
@@ -194,7 +197,7 @@ export class GridMovementController {
|
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
tween(playerNode)
|
|
197
|
-
.to(
|
|
200
|
+
.to(duration, { worldPosition: PathfindingModule.GetMapPosition(next.row, next.col) })
|
|
198
201
|
.call(() => {
|
|
199
202
|
this.pathState.completeMove(previous, next, owner, shareToken);
|
|
200
203
|
this.positions.set(playerNode, { row: next.row, col: next.col });
|
|
@@ -231,12 +234,17 @@ export class GridMovementController {
|
|
|
231
234
|
return allowOverlap ? GridMovementController.OVERLAP_TOKEN : null;
|
|
232
235
|
}
|
|
233
236
|
|
|
237
|
+
/** 单格移动时长:未指定或非法时回退到控制器默认值(单位秒) */
|
|
238
|
+
private resolveMoveDuration(moveDuration?: number): number {
|
|
239
|
+
return (typeof moveDuration === 'number' && moveDuration > 0) ? moveDuration : this.moveDuration;
|
|
240
|
+
}
|
|
241
|
+
|
|
234
242
|
/** 路径规划失败时,做一次延迟重试,避免因为瞬时占用导致立刻失败。 */
|
|
235
|
-
private retryPathfinding(playerNode: Node, target: Cell, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false): void {
|
|
243
|
+
private retryPathfinding(playerNode: Node, target: Cell, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false, moveDuration?: number): void {
|
|
236
244
|
this.clearPathfindingRetry(playerNode);
|
|
237
245
|
const retry = () => {
|
|
238
246
|
this.clearPathfindingRetry(playerNode);
|
|
239
|
-
this.moveTo(playerNode, target, attackDistance, openColor, callBack, allowOverlap);
|
|
247
|
+
this.moveTo(playerNode, target, attackDistance, openColor, callBack, allowOverlap, moveDuration);
|
|
240
248
|
};
|
|
241
249
|
this.movementRetryCallbacks.set(playerNode, retry);
|
|
242
250
|
this.scheduler.scheduleOnce(retry, this.retryDelay);
|
|
@@ -46,9 +46,11 @@ export class PathfindingModule {
|
|
|
46
46
|
* allowOverlap:为 true 时该单位进入"允许重叠"模式,
|
|
47
47
|
* 与其他同样开启该开关的单位可以走到同一格(互相穿过,不再互相绕行/互相等待),
|
|
48
48
|
* 与终点是否相同无关;未开启的单位之间、以及开启与未开启之间仍保持互斥。
|
|
49
|
+
* moveDuration:本次移动的"单格移动时长",单位秒(数字越小走得越快)。
|
|
50
|
+
* 不传或传 <= 0 时使用 InitMovementController 配置的默认值。
|
|
49
51
|
*/
|
|
50
|
-
static MoveTo(playerNode: Node, target: { row: number, col: number }, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false): void {
|
|
51
|
-
this.movementController?.moveTo(playerNode, target, attackDistance, openColor, callBack, allowOverlap);
|
|
52
|
+
static MoveTo(playerNode: Node, target: { row: number, col: number }, attackDistance: AttackDistance, openColor: boolean, callBack?: () => void, allowOverlap = false, moveDuration?: number): void {
|
|
53
|
+
this.movementController?.moveTo(playerNode, target, attackDistance, openColor, callBack, allowOverlap, moveDuration);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
static CancelMove(playerNode: Node, preserveCurrent = false): void {
|