f8dbf79f-696e-4983-b989-c582a841e463.js
6.42 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"use strict";
cc._RF.push(module, 'f8dbfefaW5Jg7mJxYKoQeRj', 'ObjData');
// scripts/kernel/battle/map/ObjData.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjData = void 0;
var BattleConst_1 = require("../BattleConst");
var ObjDataUtil_1 = require("./ObjDataUtil");
var ObjData = /** @class */ (function () {
function ObjData() {
// private static getIndex(gridX: number, gridY: number): number {
// return gridX * 10000 + gridY;
// }
this._gridPos = cc.v2(0, 0);
this._pixelPos = cc.v2(0, 0);
/**所属地图引用 */
this.map = null;
this.canSlide = true;
this._imgName = '';
this._uid = 0;
this._droped = false;
this._type = BattleConst_1.ObjType.NONE;
this._index = 0;
this._deaded = false;
//#endregion
}
Object.defineProperty(ObjData.prototype, "gridPos", {
get: function () { return this._gridPos; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "pixelPos", {
get: function () { return this._pixelPos; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "imgName", {
/**图标层要显示的图片名 */
get: function () { return this._imgName; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "uid", {
get: function () { return this._uid; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "droped", {
get: function () { return this._droped; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "type", {
get: function () { return this._type; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "index", {
/**根据格子位置产生的索引值 */
get: function () { return this._index; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "isDead", {
get: function () { return this._deaded; },
enumerable: false,
configurable: true
});
Object.defineProperty(ObjData.prototype, "isVisible", {
/**是否可见(未降到可视区域的格子不可见) */
get: function () { return (this.gridPos.y > this.map.viewSplitRow); },
enumerable: false,
configurable: true
});
//#region public method
/**绑定显示对象 */
ObjData.prototype.bindView = function (view) {
this._IView = view;
};
/**掉落到地图最下端 */
ObjData.prototype.dropDown = function () {
this._droped = true;
this.setGridPos(this.gridPos.x, this.map.mapGridSize.y - 1);
this._IView && this._IView.onDroped();
};
ObjData.prototype.setGridPos = function (gridX, gridY, syncToMapData) {
// let oldIndex = ObjData.getIndex(this._gridPos.x, this._gridPos.y);
if (syncToMapData === void 0) { syncToMapData = true; }
if (syncToMapData && this.map.objData.has(this._index)) {
this.map.objData.delete(this._index);
}
this._gridPos.x = gridX;
this._gridPos.y = gridY;
this._pixelPos.set(this.map.getPixelPosByGridPos(this._gridPos));
this._index = this.droped ? -this._uid : ObjDataUtil_1.ObjDataUtil.getIndex(this._gridPos.x, this._gridPos.y);
if (syncToMapData && !this.map.objData.has(this._index)) {
this.map.objData.set(this._index, this);
}
};
ObjData.prototype.dead = function () {
if (!this._deaded) {
this._deaded = true;
this.map.onObjDead(this); //有可能导致回合结束, 移动此格子,在移动时加判断死亡
this.onDead();
this._IView && this._IView.onDead();
this._IView = null;
}
};
/**向下滑动一格, 当物件未达到最下沿时可以滑动
* @returns 是否产生了滑动
*/
ObjData.prototype.slideDown = function () {
if (this._deaded) {
return false; //死亡后
}
if (this._gridPos.y < this.map.mapGridSize.y - 1) {
this.setGridPos(this._gridPos.x, this._gridPos.y + 1);
return true;
}
return false;
};
/**是否到达了地图最下端 */
ObjData.prototype.isReachedDownBorder = function () {
if (!this._droped && this.gridPos.y >= (this.map.mapGridSize.y - 1)) {
return true;
}
return false;
};
//#endregion
//#region life cycle
ObjData.prototype.init = function (map, type, gridX, gridY) {
// ObjData.UID++;
this._uid = ObjData.UID++;
this.map = map;
this._type = type;
this._index = ObjDataUtil_1.ObjDataUtil.getIndex(gridX, gridY);
this.setGridPos(gridX, gridY);
};
/**子类需覆写,返回对应的类型 */
ObjData.prototype.clone = function () {
//XXX 新增属性需要在此处增加处理
return this.cloneValue(new ObjData());
};
ObjData.prototype.destroy = function () {
this.onDestroy();
this._gridPos = null;
this._pixelPos = null;
this.map = null;
this._IView = null;
};
/**和球发生碰撞 */
ObjData.prototype.onCollisonToBall = function (collider) {
if (!this._deaded) { //销毁后有物理组件没有销毁,还会进入回调
this._IView.onHit();
}
};
ObjData.prototype.onDead = function () {
// this.map.onObjDead(this);
};
/**实际战斗时会调用, 预览时不会,在 BattleEvent.BATTLE_START 之前 */
ObjData.prototype.onBattleStart = function () {
};
ObjData.prototype.onDestroy = function () {
};
//#endregion
//#region child override
ObjData.prototype.cloneValue = function (target) {
target._uid = ObjData.UID++;
target._gridPos.set(this._gridPos);
target._pixelPos.set(this._pixelPos);
target._imgName = this._imgName;
target._type = this.type;
target._index = this._index;
target._droped = this._droped;
target.canSlide = this.canSlide;
// console.log();
return target;
};
ObjData.UID = 0;
return ObjData;
}());
exports.ObjData = ObjData;
cc._RF.pop();