2025-09-08 16:10:08 +08:00
|
|
|
|
import { BT } from "../BT";
|
2025-06-04 23:10:59 +08:00
|
|
|
|
import { Status } from "../header";
|
2025-09-03 10:54:07 +08:00
|
|
|
|
import { LeafNode } from "./AbstractNodes";
|
2025-06-04 23:10:59 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 次数等待节点(无子节点)
|
2025-09-02 17:05:46 +08:00
|
|
|
|
* 次数内,返回RUNNING
|
2025-06-04 23:10:59 +08:00
|
|
|
|
* 超次,返回SUCCESS
|
|
|
|
|
|
*/
|
2025-09-09 09:45:51 +08:00
|
|
|
|
@BT.ActionNode("WaitTicks", {
|
2025-09-08 16:10:08 +08:00
|
|
|
|
name: "等待次数",
|
2025-09-17 11:05:23 +08:00
|
|
|
|
group: "基础行为节点",
|
2025-09-09 09:45:51 +08:00
|
|
|
|
desc: "等待指定次数后返回成功",
|
2025-09-08 16:10:08 +08:00
|
|
|
|
})
|
2025-09-03 10:54:07 +08:00
|
|
|
|
export class WaitTicks extends LeafNode {
|
2025-09-09 09:45:51 +08:00
|
|
|
|
@BT.prop({ type: BT.ParamType.int, description: "最大等待次数", defaultValue: 0, step: 1 })
|
2025-09-02 17:05:46 +08:00
|
|
|
|
private _max: number;
|
|
|
|
|
|
private _value: number;
|
|
|
|
|
|
|
2025-06-04 23:10:59 +08:00
|
|
|
|
constructor(maxTicks: number = 0) {
|
|
|
|
|
|
super();
|
2025-09-02 17:05:46 +08:00
|
|
|
|
this._max = maxTicks;
|
|
|
|
|
|
this._value = 0;
|
2025-06-04 23:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 10:54:07 +08:00
|
|
|
|
protected override open(): void {
|
|
|
|
|
|
super.open();
|
2025-09-02 17:05:46 +08:00
|
|
|
|
this._value = 0;
|
2025-06-04 23:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 10:54:07 +08:00
|
|
|
|
public tick(): Status {
|
2025-09-02 17:05:46 +08:00
|
|
|
|
if (++this._value >= this._max) {
|
2025-06-04 23:10:59 +08:00
|
|
|
|
return Status.SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
return Status.RUNNING;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-02 17:05:46 +08:00
|
|
|
|
* 时间等待节点 时间(秒)
|
|
|
|
|
|
* 时间到后返回SUCCESS,否则返回RUNNING
|
2025-06-04 23:10:59 +08:00
|
|
|
|
*/
|
2025-09-09 09:45:51 +08:00
|
|
|
|
@BT.ActionNode("WaitTime", {
|
2025-09-08 16:10:08 +08:00
|
|
|
|
name: "等待时间",
|
2025-09-17 11:05:23 +08:00
|
|
|
|
group: "基础行为节点",
|
2025-09-09 09:45:51 +08:00
|
|
|
|
desc: "等待指定时间(秒)后返回成功",
|
2025-09-08 16:10:08 +08:00
|
|
|
|
})
|
2025-09-03 10:54:07 +08:00
|
|
|
|
export class WaitTime extends LeafNode {
|
2025-09-09 09:45:51 +08:00
|
|
|
|
@BT.prop({ type: BT.ParamType.float, description: "等待时间(秒)", defaultValue: 0, step: 0.01 })
|
2025-09-02 17:05:46 +08:00
|
|
|
|
private _max: number;
|
|
|
|
|
|
private _value: number = 0;
|
2025-06-04 23:10:59 +08:00
|
|
|
|
constructor(duration: number = 0) {
|
|
|
|
|
|
super();
|
2025-09-16 18:12:33 +08:00
|
|
|
|
this._max = duration;
|
2025-06-04 23:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 10:54:07 +08:00
|
|
|
|
protected override open(): void {
|
|
|
|
|
|
super.open();
|
2025-09-02 17:05:46 +08:00
|
|
|
|
this._value = new Date().getTime();
|
2025-06-04 23:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 10:54:07 +08:00
|
|
|
|
public tick(): Status {
|
2025-09-02 17:05:46 +08:00
|
|
|
|
const currTime = new Date().getTime();
|
2025-09-16 18:12:33 +08:00
|
|
|
|
if (currTime - this._value >= this._max * 1000) {
|
2025-06-04 23:10:59 +08:00
|
|
|
|
return Status.SUCCESS;
|
|
|
|
|
|
}
|
|
|
|
|
|
return Status.RUNNING;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|