PatrolObj.ts
2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import GlobalNode from "../../GlobalNode";
import { getGlobalNode } from "../BattleConst";
import { ObjData } from "./ObjData";
export class PatrolObj extends ObjData {
private _patroltype: number = -1;
/**0为入口 1为出口 */
get patrolType(): number { return this._patroltype; }
private _patrolIndex: number = 0;
get patrolIndex(): number { return this._patrolIndex; }
/**对应出口的位置,只有入口才有有效值 */
private brotherIndex: number = -1;
private _hited: string[] = [];
initPatrolData($index: number, $type: number, $brotherIndex: number) {
this.canSlide = false; //XXX 传送门不可下落,因为是成对出现的,下落有可能导致销毁
this._patroltype = $type;
this._patrolIndex = $index;
this.brotherIndex = $brotherIndex;
}
onCollisonToBall(collider: cc.Collider): void {
super.onCollisonToBall(collider);
if (this._patroltype == 0 && this.brotherIndex > -1 && !this._hited.includes(collider.node.uuid)) {
this._hited.push(collider.node.uuid);
let exitObj = this.map.objData.get(this.brotherIndex);
this.map.battle.addToRoundClear(this);
this.map.battle.addToRoundClear(exitObj);
collider.enabled = false; //先关闭碰撞,等当前物理步进结束后,再设置位置
getGlobalNode().getComponent(GlobalNode).scheduleOnce(() => {
collider.node.setPosition(exitObj.pixelPos.x, exitObj.pixelPos.y);
collider.enabled = true;
}, 0);
}
// else {
// cc.warn('patrol cannot find exit')
// }
}
clone(): PatrolObj {
return this.cloneValue(new PatrolObj());
}
protected cloneValue(target: PatrolObj): PatrolObj {
super.cloneValue(target);
target._patroltype = this._patroltype;
target._patrolIndex = this._patrolIndex;
target.brotherIndex = this.brotherIndex;
return target;
}
}