"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();