cc365d77-b1d9-4abe-a382-f7261e0ff0bf.js 23.3 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
"use strict";
cc._RF.push(module, 'cc36513sdlKvqOC9yYeD/C/', 'MapData');
// scripts/kernel/battle/map/MapData.ts

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapData = void 0;
var SoundManager_1 = require("../../../component/SoundManager");
var Global_1 = require("../../../Global");
var BattleConst_1 = require("../BattleConst");
var BigBombBlockData_1 = require("./BigBombBlockData");
var BlockData_1 = require("./BlockData");
var BlockSkillBomb_1 = require("./blockSkill/BlockSkillBomb");
var BlockSkillDiamond_1 = require("./blockSkill/BlockSkillDiamond");
var BlockSkillFirework_1 = require("./blockSkill/BlockSkillFirework");
var BlockSkillNail_1 = require("./blockSkill/BlockSkillNail");
var BlockSkillSwitcher_1 = require("./blockSkill/BlockSkillSwitcher");
var LaserObj_1 = require("./LaserObj");
var ObjDataUtil_1 = require("./ObjDataUtil");
var PatrolObj_1 = require("./PatrolObj");
var PlusOneObj_1 = require("./PlusOneObj");
var PotObj_1 = require("./PotObj");
var RectBlockData_1 = require("./RectBlockData");
var RotaterObj_1 = require("./RotaterObj");
var SolidColorBlockData_1 = require("./SolidColorBlockData");
var SpliterObj_1 = require("./SpliterObj");
var StaticNailBlockData_1 = require("./StaticNailBlockData");
var TrangleBlockData_1 = require("./TrangleBlockData");
/**格子0,0点在左上角,向右下方增长,格子坐标都为正数 */
var MapData = /** @class */ (function () {
    function MapData() {
        this._gridSize = cc.v2(0, 0);
        this._mapGridSize = cc.v2(0, 0);
        this._blockData = new Map();
        this._rectBlockList = [];
        this._objData = new Map();
        this._id = 0;
        this._levelId = 0;
        this._totalScore = 0;
        this._curScore = 0;
        this._roundBlockCombo = 0;
        this._maxContentY = 0;
        /**战斗引用 */
        this.battle = null;
        this._retCache = new cc.Vec2(0, 0);
    }
    Object.defineProperty(MapData.prototype, "gridSize", {
        /**单个格子的像素尺寸 */
        get: function () { return this._gridSize; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "mapGridSize", {
        /**地图的格子尺寸 */
        get: function () { return this._mapGridSize; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "blockData", {
        /** objData的子集,只包含砖块,由blockdata自己维护 */
        get: function () { return this._blockData; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "objData", {
        /**所有物体, 由objdata自己维护 */
        get: function () { return this._objData; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "id", {
        /**唯一uid */
        get: function () { return this._id; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "levelId", {
        get: function () { return this._levelId; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "totalScore", {
        /**所有砖块的总分 */
        get: function () { return this._totalScore; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "curScore", {
        /**当前的得分 */
        get: function () { return this._curScore; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "viewSplitRow", {
        get: function () { return this._viewSplitRow; },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MapData.prototype, "maxContentY", {
        /**有物件(圆点技能、砖块)的最大Y坐标 */
        get: function () { return this._maxContentY; },
        enumerable: false,
        configurable: true
    });
    MapData.prototype.clone = function () {
        var ret = new MapData();
        MapData.UID++;
        ret._id = MapData.UID;
        ret._levelId = this._levelId;
        ret._gridSize.set(this._gridSize);
        ret._mapGridSize.set(this._mapGridSize);
        ret._totalScore = this._totalScore;
        ret._curScore = this._curScore;
        ret._viewSplitRow = this._viewSplitRow;
        ret._maxContentY = this._maxContentY;
        this._objData.forEach(function (value, key, map) {
            var newData = value.clone();
            newData.map = ret;
            ret._objData.set(key, newData);
            if (newData instanceof BlockData_1.BlockData) {
                ret._blockData.set(key, newData);
                if (newData instanceof RectBlockData_1.RectBlockData) {
                    ret._rectBlockList.push(newData);
                }
            }
        }, this);
        return ret;
    };
    MapData.prototype.init = function (tiledMap) {
        MapData.UID++;
        this._id = MapData.UID;
        this._levelId = Number(tiledMap.tmxAsset.name.split('-')[1]);
        var gridSize = tiledMap.getTileSize();
        this._gridSize.x = gridSize.width;
        this._gridSize.y = gridSize.height;
        var mapSize = tiledMap.getMapSize();
        this._mapGridSize.x = mapSize.width;
        this._mapGridSize.y = mapSize.height;
        this._viewSplitRow = mapSize.height - Math.floor(mapSize.width * 1.27) - 1;
        var skillLayer = tiledMap.getLayer('0');
        for (var x = 0; x < mapSize.width; ++x) {
            for (var y = 0; y < mapSize.height; ++y) {
                var layers = tiledMap.getLayers();
                for (var i = 0; i < layers.length; ++i) {
                    var layer = layers[i];
                    var gid = layer.getTileGIDAt(x, y);
                    var isSkillLayer = (layer == skillLayer);
                    //#region 规则
                    //圆点技能(不带数字,不需要和砖块组合)可以放所有层
                    //需要和砖块组合的技能(有数字的),只能放在0层
                    //#endregion
                    if (gid > 0) {
                        var hp = (isSkillLayer ? 0 : Number(layer.getLayerName()));
                        var skillGid = isSkillLayer ? gid : (skillLayer ? skillLayer.getTileGIDAt(x, y) : 0); //技能层直接使用gid,否则 读取技能层的gid, 没有技能层则为0
                        //不带砖块的技能
                        if (gid == BattleConst_1.ObjType.PLUS_ONE) {
                            //+1球
                            var foo = new PlusOneObj_1.PlusOneObj();
                            foo.init(this, BattleConst_1.ObjType.PLUS_ONE, x, y);
                        }
                        else if (gid == BattleConst_1.ObjType.SPLITER) {
                            var foo = new SpliterObj_1.SpliterObj();
                            foo.init(this, BattleConst_1.ObjType.SPLITER, x, y);
                        }
                        else if (gid >= BattleConst_1.ObjType.LANCER_1 && gid <= BattleConst_1.ObjType.LANCER_3) {
                            var foo = new LaserObj_1.LaserObj();
                            foo.init(this, gid, x, y);
                        }
                        else if (gid == BattleConst_1.ObjType.BIG_BOMB || gid == BattleConst_1.ObjType.BIG_BOMB_33) {
                            var foo = new BigBombBlockData_1.BigBombBlockData();
                            if (gid == BattleConst_1.ObjType.BIG_BOMB) {
                                foo.initBlock(this, gid, hp, x, y - 1, 2, 2);
                                this._rectBlockList.push(foo);
                            }
                            else if (gid == BattleConst_1.ObjType.BIG_BOMB_33) {
                                foo.initBlock(this, gid, hp, x, y - 2, 3, 3);
                                this._rectBlockList.push(foo);
                            }
                        }
                        else if (gid == BattleConst_1.ObjType.POT) {
                            var foo = new PotObj_1.PotObj();
                            foo.init(this, gid, x, y);
                        }
                        else if (gid == BattleConst_1.ObjType.ROTATER) {
                            var foo = new RotaterObj_1.RotaterObj();
                            foo.init(this, gid, x, y);
                        }
                        else if (gid == BattleConst_1.ObjType.STATIC_IRON) {
                            var foo = new StaticNailBlockData_1.StaticNailBlockData();
                            foo.init(this, gid, x, y);
                        }
                        else if (gid == BattleConst_1.ObjType.PATROL) {
                            var foo = new PatrolObj_1.PatrolObj();
                            foo.init(this, gid, x, y);
                        }
                        else if (!isSkillLayer) {
                            //不在技能层,才创建砖块
                            var blockData = void 0;
                            var type = BattleConst_1.ObjType.NORMAL;
                            if (gid >= BattleConst_1.ObjType.TRANGLE_1 && gid <= BattleConst_1.ObjType.TRANGLE_4) {
                                blockData = new TrangleBlockData_1.TrangleBlockData();
                                type = gid;
                            }
                            else {
                                if (gid >= BattleConst_1.ObjType.SOLID_1 && gid <= BattleConst_1.ObjType.SOLID_13) {
                                    blockData = new SolidColorBlockData_1.SolidColorBlockData();
                                    type = gid;
                                }
                                else {
                                    //普通砖块
                                    blockData = new BlockData_1.BlockData();
                                }
                                if (skillGid == BattleConst_1.ObjType.DIAMOND) {
                                    // type = ObjType.DIAMOND;
                                    blockData.addSkill(new BlockSkillDiamond_1.BlockSkillDiamond(blockData));
                                }
                                else if (skillGid == BattleConst_1.ObjType.BOMB) {
                                    // type = ObjType.BOMB;
                                    blockData.addSkill(new BlockSkillBomb_1.BlockSkillBomb(blockData));
                                }
                                else if (skillGid == BattleConst_1.ObjType.STATIC) {
                                    blockData.addSkill(new BlockSkillNail_1.BlockSkillNail(blockData));
                                }
                                else if (skillGid >= BattleConst_1.ObjType.FIREWORK_VERTICAL && skillGid <= BattleConst_1.ObjType.FIREWORK_DOUBLE) {
                                    blockData.addSkill(new BlockSkillFirework_1.BlockSkillFirework(blockData, skillGid - 42));
                                }
                                else if (skillGid == BattleConst_1.ObjType.SWITCHER) {
                                    blockData.addSkill(new BlockSkillSwitcher_1.BlockSkillSwitcher(blockData, false));
                                }
                            }
                            blockData.initBlock(this, type, hp, x, y);
                        }
                        if (y > this._maxContentY) {
                            this._maxContentY = y;
                        }
                    }
                }
            }
        }
        var patrolList = [];
        var objLayer = tiledMap.getObjectGroup('obj');
        if (objLayer) {
            var objs = objLayer.getObjects();
            for (var i = 0; i < objs.length; ++i) {
                var type = objs[i]['type'];
                if (type == 'rect') {
                    var pos = objs[i]['offset'];
                    var indexX = Math.floor(pos.x / this.gridSize.x);
                    var indexY = Math.floor(pos.y / this.gridSize.y);
                    var endIndexX = Math.floor((pos.x + objs[i]['width']) / this.gridSize.x);
                    var endIndexY = Math.floor((pos.y + objs[i]['height']) / this.gridSize.y);
                    var index = ObjDataUtil_1.ObjDataUtil.getIndex(indexX, indexY);
                    var block = this._blockData.get(index);
                    if (block) {
                        var width = endIndexX - indexX + 1;
                        var height = endIndexY - indexY + 1;
                        //已经创建的单个格子
                        var foo = void 0;
                        if (block instanceof SolidColorBlockData_1.SolidColorBlockData) {
                            foo = new SolidColorBlockData_1.SolidColorBlockData();
                            foo.initBlock(this, block.type, block.hp, block.gridPos.x, block.gridPos.y, width, height);
                        }
                        else {
                            foo = new RectBlockData_1.RectBlockData();
                            foo.initBlock(this, BattleConst_1.ObjType.NORMAL, block.hp, block.gridPos.x, block.gridPos.y, width, height);
                        }
                        // block.addSkill()
                        if (block.skill) {
                            foo.addSkill(block.skill);
                            block.skill = null;
                        }
                        this._rectBlockList.push(foo);
                        if (foo.contentY > this._maxContentY) {
                            this._maxContentY = foo.contentY;
                        }
                    }
                }
                else if (type && type.includes('trans')) {
                    var pos = objs[i]['offset'];
                    var patrolType = -1;
                    if (type.includes('transIn')) {
                        patrolType = 0; //入口
                    }
                    else if (type.includes('transOut')) {
                        patrolType = 1; //出口
                    }
                    if (patrolType > -1) {
                        //配置有效
                        var patrolIndex = Number(type.split('-')[1]);
                        var indexX = Math.floor(pos.x / this.gridSize.x);
                        var indexY = Math.floor(pos.y / this.gridSize.y);
                        var objIndex = ObjDataUtil_1.ObjDataUtil.getIndex(indexX, indexY);
                        var obj = this.objData.get(objIndex);
                        if (obj && obj instanceof PatrolObj_1.PatrolObj) {
                            var foo = { patrolType: patrolType, patrolIndex: patrolIndex, mapIndex: objIndex };
                            patrolList.push(foo);
                        }
                    }
                }
                else if (type && type == 'switcherOpen') {
                    var pos = objs[i]['offset'];
                    // let patrolType = -1;
                    // if (type.includes('transIn')) {
                    //     patrolType = 0;//入口
                    // }
                    // else if (type.includes('transOut')) {
                    //     patrolType = 1; //出口
                    // }
                    // if (patrolType > -1) {
                    // 配置有效
                    // let patrolIndex = Number(type.split('-')[1]);
                    var indexX = Math.floor(pos.x / this.gridSize.x);
                    var indexY = Math.floor(pos.y / this.gridSize.y);
                    var objIndex = ObjDataUtil_1.ObjDataUtil.getIndex(indexX, indexY);
                    var obj = this.objData.get(objIndex);
                    if (obj && obj instanceof BlockData_1.BlockData && obj.skill instanceof BlockSkillSwitcher_1.BlockSkillSwitcher) {
                        obj.skill.setDefaultState(true);
                    }
                    // }
                }
            }
        }
        patrolList.sort(function (a, b) {
            if (a.patrolIndex - b.patrolIndex == 0) {
                return a.patrolType - b.patrolType;
            }
            else {
                return a.patrolIndex - b.patrolIndex;
            }
        }); //按 index 从小到大 入口、出口的顺序排列
        for (var i = 0; i < patrolList.length; ++i) {
            var obj = this.objData.get(patrolList[i].mapIndex);
            obj.initPatrolData(patrolList[i].patrolIndex, patrolList[i].patrolType, i % 2 == 0 ? patrolList[i + 1].mapIndex : patrolList[i - 1].mapIndex);
        }
        var blockNum = this._blockData.size;
        for (var i = 0; i < blockNum; ++i) {
            this._totalScore += (i * 10);
        }
        // console.log();
    };
    /**
     *
     * @param gridPos
     * @returns 返回实例是唯一的实例,不可缓存,可缓存返回实例的副本
     */
    MapData.prototype.getPixelPosByGridPos = function (gridPos) {
        var totalWidth = this._mapGridSize.x * this._gridSize.x;
        var totalHeight = this._mapGridSize.y * this._gridSize.y;
        this._retCache.x = gridPos.x * this._gridSize.x + this._gridSize.x / 2;
        this._retCache.y = gridPos.y * this._gridSize.y + this._gridSize.y / 2;
        this._retCache.x -= totalWidth / 2;
        this._retCache.y = -this._retCache.y + totalHeight / 2;
        return this._retCache;
    };
    MapData.prototype.onObjDead = function (obj) {
        // if(this._rectBlockList.includes(obj))
        if (obj instanceof BlockData_1.BlockData) {
            var index = obj.index;
            if (this._blockData.has(index)) {
                this._blockData.delete(index);
                if (obj instanceof RectBlockData_1.RectBlockData) {
                    this._roundBlockCombo += (obj.widthGrid * obj.heightGrid); //大格子按面积数计算连击
                    var index_1 = this._rectBlockList.indexOf(obj);
                    if (index_1 > -1) {
                        this._rectBlockList.splice(index_1, 1);
                    }
                }
                else {
                    this._roundBlockCombo++;
                }
                this._curScore += (this._roundBlockCombo * 10);
                this.battle && this.battle.onBlockDead(this._roundBlockCombo);
            }
        }
        if (this._objData.has(obj.index)) {
            this._objData.delete(obj.index);
            this.battle && this.battle.onObjDead();
        }
    };
    /**
     *
     * @returns 是否有格子到达最下层
     */
    MapData.prototype.slideDown = function () {
        var list = [];
        var ret = false;
        /**倒数第二行警告 */
        var warn = false;
        this._objData.forEach(function (value, key, map) {
            list.push(value);
        }, this);
        list.sort(function (a, b) {
            // let aValue = a.gridPos.y;
            // if(a instanceof RectBlockData) {
            //     aValue = 
            // }
            // let bValue = b.gridPos.y;
            return b.gridPos.y - a.gridPos.y;
        }); //靠下的格子排数组前面
        for (var i = 0; i < list.length; ++i) {
            var value = list[i];
            if (!value.canSlide) {
                continue;
            }
            var canSlide = true;
            // let nextY:number = value.
            if (value instanceof RectBlockData_1.RectBlockData) {
                if (value.canSlide) {
                    //检查每一列的下一格
                    for (var x = 0; x < value.widthGrid; ++x) {
                        // let nextBlock = this.getBlockByGridPos(value.gridPos.x + x, value.contentY + 1);
                        // if (nextBlock) {
                        //     canSlide = false;
                        //     break;
                        // }
                        // else {
                        //     let nextIndex = ObjDataUtil.getIndex(value.gridPos.x + x, value.contentY + 1); 
                        //     if (this._objData.has(nextIndex)) {
                        //         canSlide = false;
                        //         break;
                        //     }
                        // }
                        if (!this.isGridEmpty(value.gridPos.x + x, value.contentY + 1)) {
                            canSlide = false;
                            break;
                        }
                    }
                }
                else {
                    canSlide = false;
                }
            }
            else {
                // if (this.getBlockByGridPos(value.gridPos.x, value.gridPos.y + 1)) {
                //     canSlide = false; //下一行有格子
                // }
                // else {
                //     let nextIndex = value.index + 1;//下一行的Index
                //     if (this._objData.has(nextIndex)) {
                //         canSlide = false; //下一行有任意物件
                //     }
                // }
                if (!this.isGridEmpty(value.gridPos.x, value.gridPos.y + 1)) {
                    canSlide = false;
                }
            }
            if (canSlide && value.slideDown()) {
                if (!warn) {
                    if (value instanceof BlockData_1.BlockData && value.contentY == this.mapGridSize.y - 2) {
                        warn = true;
                    }
                }
                if (value.isReachedDownBorder()) {
                    if (value instanceof BlockData_1.BlockData) {
                        ret = true;
                    }
                    else {
                        //非block及其子类的销毁
                        value.dead();
                    }
                }
            }
        }
        if (warn && !ret) {
            SoundManager_1.SoundManager.ins.playEffect(Global_1.SoundName.WARNING);
        }
        return ret;
    };
    MapData.prototype.isGridEmpty = function (gridX, gridY) {
        var index = ObjDataUtil_1.ObjDataUtil.getIndex(gridX, gridY);
        if (this._objData.has(index)) {
            return false;
        }
        else {
            if (this.getBlockByGridPos(gridX, gridY)) {
                return false;
            }
        }
        return true;
        // if (this.getBlockByGridPos(gridX, gridY)) {
        //     canSlide = false; //下一行有格子
        // }
        // else {
        //     let nextIndex = value.index + 1;//下一行的Index
        //     if (this._objData.has(nextIndex)) {
        //         canSlide = false; //下一行有任意物件
        //     }
        // }
    };
    MapData.prototype.roundFinish = function () {
        this._roundBlockCombo = 0;
    };
    MapData.prototype.getBlockByGridPos = function (gridX, gridY) {
        var index = ObjDataUtil_1.ObjDataUtil.getIndex(gridX, gridY);
        if (this._blockData.has(index)) {
            //快速判断
            return this._blockData.get(index);
        }
        else {
            //检索大格子
            for (var i = 0; i < this._rectBlockList.length; ++i) {
                // if(gridX == d)
                var rect = this._rectBlockList[i];
                if (gridX >= rect.gridPos.x && gridX <= rect.gridPos.x + rect.widthGrid - 1 &&
                    gridY >= rect.gridPos.y && gridY <= rect.gridPos.y + rect.heightGrid - 1) {
                    return rect;
                }
            }
            return null;
        }
    };
    MapData.prototype.battleStart = function () {
        this._objData.forEach(function (value, key, map) {
            value.onBattleStart();
        }, this);
    };
    MapData.UID = 0;
    return MapData;
}());
exports.MapData = MapData;

cc._RF.pop();