"use strict"; cc._RF.push(module, 'f6b19vur6xPQqbmVGQGH3i5', 'BlockData'); // scripts/kernel/battle/map/BlockData.ts "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.BlockData = void 0; var SoundManager_1 = require("../../../component/SoundManager"); var Global_1 = require("../../../Global"); var BlockColorTableMgr_1 = require("../../table/BlockColorTableMgr"); var ObjData_1 = require("./ObjData"); var BlockData = /** @class */ (function (_super) { __extends(BlockData, _super); function BlockData() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._hp = 1; _this._contentY = 0; _this.skill = null; _this._isProtected = false; return _this; //#endregion } Object.defineProperty(BlockData.prototype, "hp", { get: function () { return this._hp; }, enumerable: false, configurable: true }); Object.defineProperty(BlockData.prototype, "contentY", { /**最大内容范围内的Y坐标 */ get: function () { return this._contentY; }, enumerable: false, configurable: true }); Object.defineProperty(BlockData.prototype, "isProtected", { /**是否在被闸门保护状态 */ get: function () { return this._isProtected; }, enumerable: false, configurable: true }); //#region life cycle BlockData.prototype.init = function (map, type, gridX, gridY) { //屏蔽,调用initBlock return; }; BlockData.prototype.initBlock = function (map, type, hp, gridX, gridY) { _super.prototype.init.call(this, map, type, gridX, gridY); this._contentY = gridY; this._hp = hp; this._imgName = this.getImgName(); }; /**子类需覆写,返回对应的类型 */ BlockData.prototype.clone = function () { //XXX 新增属性需要在此处增加处理 return this.cloneValue(new BlockData()); }; /**和球发生碰撞 */ BlockData.prototype.onCollisonToBall = function (collider) { if (!this._deaded && !this.isProtected) { _super.prototype.onCollisonToBall.call(this, collider); this.skill && this.skill.onCollisionToBall(); if (this._hp >= 1) { this.adJustHp(-1); } } }; BlockData.prototype.onDead = function () { _super.prototype.onDead.call(this); this.skill && this.skill.onDead(); SoundManager_1.SoundManager.ins.playEffect(Global_1.SoundName.BREAK); }; BlockData.prototype.onDestroy = function () { this.skill && this.skill.destroy(); }; //#endregion //#region public method BlockData.prototype.addSkill = function (skill) { this.skill = skill; skill.onAddedToBlock(); }; BlockData.prototype.adJustHp = function (delta) { if (delta < 0) { //先只处理扣血 this._hp += delta; if (this._hp > 0) { var imgName = this.getImgName(); if (this._imgName != imgName) { this._imgName = imgName; this._IView.onImgChanged(); } SoundManager_1.SoundManager.ins.playEffect(Global_1.SoundName.HIT); } if (this._hp <= 0) { this._hp = 0; this.dead(); } } }; BlockData.prototype.setIsProtected = function (value) { if (this._isProtected != value) { this._isProtected = value; } }; //#endregion //#region child override BlockData.prototype.cloneValue = function (target) { _super.prototype.cloneValue.call(this, target); target._hp = this._hp; // target._skillImgName = this._skillImgName; target._contentY = this._contentY; if (this.skill) { target.skill = this.skill; target.skill.owner = target; //指向新的格子 target.skill.onAddedToBlock(); //重新触发一下 } return target; }; BlockData.prototype.getImgName = function () { return BlockColorTableMgr_1.BlockColorTableMgr.ins.getByHp(this._hp).Img; }; BlockData.prototype.setGridPos = function (gridX, gridY) { this.map.blockData.delete(this.index); //删除旧索引 // super.setGridPos(gridX, gridY, false); _super.prototype.setGridPos.call(this, gridX, gridY); this.map.blockData.set(this.index, this); //增加新索引 this._contentY = this.gridPos.y; }; return BlockData; }(ObjData_1.ObjData)); exports.BlockData = BlockData; cc._RF.pop();