"use strict"; cc._RF.push(module, '919e1h4ZJBAP4dbui7PdiqP', 'Battle'); // scripts/kernel/battle/Battle.ts "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Battle = void 0; var SaveDataManager_1 = require("../../component/SaveDataManager"); var Global_1 = require("../../Global"); var Ball_1 = require("../../prefabs/Ball"); var UIManager_1 = require("../../ui/UIManager"); var UITitleData_1 = require("../../ui/uiView/UITitleData"); var GlobalNode_1 = require("../GlobalNode"); var PhysicsControl_1 = require("../physics/PhysicsControl"); var TableDefine_1 = require("../table/TableDefine"); var BattleConst_1 = require("./BattleConst"); var BattleManager_1 = require("./BattleManager"); var BattleProfit_1 = require("./BattleProfit"); var MapManager_1 = require("./map/MapManager"); var MapUtil_1 = require("./map/MapUtil"); var UserSkillBomb_1 = require("./userSkill/UserSkillBomb"); var UserSkillDoubleShoot_1 = require("./userSkill/UserSkillDoubleShoot"); var UserSkillShield_1 = require("./userSkill/UserSkillShield"); var UserSkillShuriken_1 = require("./userSkill/UserSkillShuriken"); /**单局战斗数据模型 */ var Battle = /** @class */ (function () { function Battle() { this._marblesBornPosNextRound = cc.v2(); this._round = 0; this._roundRunning = false; this._roundLastTime = 0; this._marblesNum = 50; this._marblesToShoot = 0; /**已发射的弹球 */ this._marblesCount = 0; this._marblesCollectCount = 0; this._shootVec = cc.v2(); this._shootInterval = 0; this._shootIntervalCount = 0; this._marblesPool = []; this._roundClearList = []; /**彩虹护盾次数 */ this.shieldCount = 0; /**地图缩放值 */ this.scale = 1; this.doubleShoot = false; this._levelId = 0; this._speedUp = false; /**复活次数 */ this.reviveCount = 0; this.bigBombTriggered = false; this._collecting = false; this._updateObj = []; this._updateObjToRemoved = []; this._ballTargetCache = cc.v3(); this._doubleShootVec = cc.v2(); //#endregion } Object.defineProperty(Battle.prototype, "mapView", { get: function () { return this._mapView; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "mapData", { get: function () { return this._mapData; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "marblesBornPos", { get: function () { return this._marblesBornPos; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "marblesBornPosNextRound", { get: function () { return this._marblesBornPosNextRound; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "round", { /**回合数,开始射击时 +1 */ get: function () { return this._round; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "roundRunning", { get: function () { return this._roundRunning; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "marblesNum", { get: function () { return this._marblesNum; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "marblesCollectCount", { /**已收集的弹球 */ get: function () { return this._marblesCollectCount; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "profit", { /**战斗收益 */ get: function () { return this._profit; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "prefabCollection", { get: function () { return this._prefabCollection; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "levelId", { get: function () { return this._levelId; }, enumerable: false, configurable: true }); Object.defineProperty(Battle.prototype, "speedUp", { get: function () { return this._speedUp; }, enumerable: false, configurable: true }); //#region public method Battle.prototype.init = function (levelId, callBack, thisObj, prefab) { /** * Project Marbles * Date: 2022.4 * * Programme made by Sean * Art by Qin Wu, Yan Fan, Weirui Yu * * Some other morons are included, these morons do not care about quailty of game, we paid lots of works, and they did not make any progress, totally useless crap. */ this._levelId = levelId; this._profit = new BattleProfit_1.BattleProfit(this); this._callBack = callBack; this._callBackThisObj = thisObj; // this._blockPrefab = blockPrefab; // this._ballPrefab = ballPrefab; this._prefabCollection = cc.instantiate(prefab); var config = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 2); //发射弹球频率 this._shootInterval = config.Value; config = Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, levelId == 1 ? 7 : 8); //弹球数量 this._marblesNum = config.Value + (UITitleData_1.UITitleData.isBattleBonus ? 10 : 0); if (this._levelId == 0) { MapManager_1.MapManager.ins.loadMap('test1', this.onMapLoadFinish, this); } else { MapManager_1.MapManager.ins.loadMap('map-' + levelId.toString(), this.onMapLoadFinish, this); } }; Battle.prototype.update = function (dt) { if (this._roundRunning) { this._roundLastTime += dt; //加速控制 if (this._roundLastTime > Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 4).Value && PhysicsControl_1.PhysicsControl.TIME_SCALE != Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 5).Value) { this._speedUp = true; PhysicsControl_1.PhysicsControl.ins.setTimeScale(Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 5).Value); } } if (this._marblesToShoot > 0) { this._shootIntervalCount += dt; if (this._shootIntervalCount >= this._shootInterval) { // this._shootIntervalCount -= this._shootInterval; this._shootIntervalCount = 0; //直接重置为0,使小球间隔更均匀,但是时间上不够准确 this.shootMarbles(); } } if (this._updateObjToRemoved.length > 0) { for (var i = 0; i < this._updateObjToRemoved.length; ++i) { var index = this._updateObj.indexOf(this._updateObjToRemoved[i]); if (index > -1) { this._updateObj.splice(index, 1); } } } this._updateObjToRemoved.length = 0; if (this._updateObj.length > 0) { for (var i = 0; i < this._updateObj.length; ++i) { this._updateObj[i].onUpdate(dt); } } PhysicsControl_1.PhysicsControl.ins.update(dt); }; Battle.prototype.regUpdateObj = function (obj) { if (!this._updateObj.includes(obj)) { this._updateObj.push(obj); } }; Battle.prototype.unregUpdateObj = function (obj) { if (!this._updateObjToRemoved.includes(obj)) { this._updateObjToRemoved.push(obj); } }; Battle.prototype.destroy = function () { this._updateObj.length = 0; this._updateObjToRemoved.length = 0; PhysicsControl_1.PhysicsControl.ins.setPhysicsEnable(false); }; Battle.prototype.shoot = function (dir) { if (!this._roundRunning) { BattleManager_1.BattleManager.ins.shootTouchEnable = false; this._shootIntervalCount = 0; PhysicsControl_1.PhysicsControl.ins.setPhysicsEnable(true); PhysicsControl_1.PhysicsControl.ins.setTimeScale(1); this._marblesToShoot = this._marblesNum * (this.doubleShoot ? 2 : 1); this._shootVec.set(dir); this._shootVec.normalizeSelf(); var speed = this.getPhysiceBallSpeed(); this._shootVec.multiplyScalar(speed); this._doubleShootVec.set(this._shootVec); this._doubleShootVec.x = -this._doubleShootVec.x; this.onRoundStart(); } }; Battle.prototype.marblesCollected = function (collisonWorldPoint, ballNode) { if (this.shieldCount > 0) { this.shieldCount--; if (this.shieldCount == 0) { BattleManager_1.BattleManager.ins.eventNode.emit(BattleConst_1.BattleEvent.SKILL_END, BattleConst_1.UserSkill.SHIELD); } return; } if (this._marblesCollectCount == 0) { ++this._marblesCollectCount; this._mapView.convertToNodeSpaceAR(collisonWorldPoint, this._marblesBornPosNextRound); // this._marblesBornPosNextRound.y += 15; this._marblesBornPosNextRound.y = -this._mapView.height / 2 + 15; this._ballTargetCache.x = this._marblesBornPosNextRound.x; this._ballTargetCache.y = this._marblesBornPosNextRound.y; BattleManager_1.BattleManager.ins.eventNode.emit(BattleConst_1.BattleEvent.BORN_POS_CHANGE); ballNode.active = false; } else { this.doCollect(ballNode); } }; Battle.prototype.collectAll = function () { if (!this._collecting && this.roundRunning) { this._collecting = true; this._marblesToShoot = 0; var count = 0; for (var i = 0; i < this._marblesPool.length; ++i) { if (this._marblesPool[i].active && !this._marblesPool[i].getComponent(Ball_1.default).collecting) { this.doCollect(this._marblesPool[i]); count++; } } // console.log('collected', count); // if (count == 0) { if (count == 0 && this._marblesCollectCount == this._marblesCount) { //球都收完了 // console.log('收完了'); this.onRoundFinish(); } } // roundFinish && this.roundFinish(); }; /**结算战斗 */ Battle.prototype.finishBattle = function (win, delay) { if (delay === void 0) { delay = true; } this._marblesToShoot = 0; win && (this._profit.star = MapUtil_1.MapUtil.getStarRate(this._mapData)); if (win && this._levelId > SaveDataManager_1.SaveDataManager.ins.runtimeData.curLevel) { SaveDataManager_1.SaveDataManager.ins.runtimeData.curLevel = this._levelId; SaveDataManager_1.SaveDataManager.ins.saveData(); } if (delay) { BattleConst_1.getGlobalNode().getComponent(GlobalNode_1.default).scheduleOnce(function () { UIManager_1.UIManager.ins.openWindow(win ? Global_1.WindowName.BATTLE_RESULT_PRE_ANI : Global_1.WindowName.BATTLE_RESULT, win); }, 1); } else { UIManager_1.UIManager.ins.openWindow(win ? Global_1.WindowName.BATTLE_RESULT_PRE_ANI : Global_1.WindowName.BATTLE_RESULT, win); } }; Battle.prototype.addMarbles = function (num) { this._marblesNum += num; }; Battle.prototype.addToRoundClear = function (target) { if (this._roundClearList.indexOf(target) == -1) { this._roundClearList.push(target); } }; Battle.prototype.useSkill = function (skillId, free) { if (free === void 0) { free = false; } if (skillId == BattleConst_1.UserSkill.BOMB) { new UserSkillBomb_1.UserSkillBomb(this, skillId).start(free); } else if (skillId == BattleConst_1.UserSkill.SHURIKEN) { new UserSkillShuriken_1.UserSkillShuriken(this).start(free); } else if (skillId == BattleConst_1.UserSkill.SHIELD) { new UserSkillShield_1.UserSkillShield(this, skillId).start(free); } else if (skillId == BattleConst_1.UserSkill.DOUBLE_SHOOT) { new UserSkillDoubleShoot_1.UserSkillDoubleShoot(this, skillId).start(free); } }; /**获取小球在物理引擎中的速度,将地图的缩放计算在内 */ Battle.prototype.getPhysiceBallSpeed = function () { return Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 3).Value * this.scale; }; //#endregion //#region event Battle.prototype.onBlockDead = function (combo) { BattleManager_1.BattleManager.ins.eventNode.emit(BattleConst_1.BattleEvent.BLOCK_COMBO, combo); if (this._mapData.blockData.size == 0) { // this.finishBattle(true); if (this.bigBombTriggered) { this.onRoundFinish(); } else { if (this.roundRunning) { this.collectAll(); } else { //非回合中,使用道具消除了砖块 this.onRoundFinish(); } } } }; Battle.prototype.onObjDead = function () { }; Battle.prototype.onMarblesCollectedFinish = function () { ++this._marblesCollectCount; if (!this.bigBombTriggered) { // if (this.doubleShoot) { // if (this._marblesCollectCount == this._marblesNum * 2) { // this.onRoundFinish(); // } // } // else { // if (this._marblesCollectCount == this._marblesNum) { // this.onRoundFinish(); // } // } if (this._marblesCollectCount == this._marblesCount) { // console.log('自己收完了'); this.onRoundFinish(); } } }; Battle.prototype.onRoundStart = function () { this._roundRunning = true; this._roundLastTime = 0; this._marblesCount = 0; this._marblesCollectCount = 0; BattleManager_1.BattleManager.ins.eventNode.emit(BattleConst_1.BattleEvent.ROUND_START); }; Battle.prototype.onRoundFinish = function () { this._round++; this._roundRunning = false; this._speedUp = false; this._collecting = false; this._mapData.roundFinish(); this.doubleShoot && (this.doubleShoot = false); for (var i = 0; i < this._roundClearList.length; ++i) { this._roundClearList[i].dead(); } this._roundClearList.length = 0; this._profit.roundFinish(); this._marblesBornPos.set(this._marblesBornPosNextRound); PhysicsControl_1.PhysicsControl.ins.setTimeScale(1); PhysicsControl_1.PhysicsControl.ins.setPhysicsEnable(false); var lose = this._mapData.slideDown(); BattleManager_1.BattleManager.ins.eventNode.emit(BattleConst_1.BattleEvent.ROUND_END); if (lose) { // this.finishBattle(false); UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.REVIVE); } else { if (this._mapData.blockData.size == 0) { this.finishBattle(true); // this.collectAll(true); } else { BattleManager_1.BattleManager.ins.shootTouchEnable = true; } } }; //#endregion //#region private method Battle.prototype.onMapLoadFinish = function (data) { this._mapData = data; this._mapData.battle = this; this._mapView = MapManager_1.MapManager.ins.renderMap(data, this._prefabCollection); //弹球出生点 this._marblesBornPos = cc.v2(0, -this._mapView.height / 2 + 15); this._marblesBornPosNextRound.set(this._marblesBornPos); this._ballTargetCache.x = this._marblesBornPos.x; this._ballTargetCache.y = this._marblesBornPos.y; for (var i = 0; i < this._marblesNum; ++i) { this._marblesPool.push(this.makeMarbleNode()); } this._mapData.battleStart(); this._callBack.call(this._callBackThisObj); }; Battle.prototype.shootMarbles = function () { if (this._marblesToShoot > 0) { var marbles = void 0; if (this._marblesCount < this._marblesPool.length) { marbles = this._marblesPool[this._marblesCount]; } else { marbles = this.makeMarbleNode(); this._marblesPool.push(marbles); } marbles.setPosition(this.marblesBornPos); if (this.doubleShoot) { if (this._marblesCount % 2 == 0) { marbles.getComponent(cc.RigidBody).linearVelocity = this._shootVec; } else { marbles.getComponent(cc.RigidBody).linearVelocity = this._doubleShootVec; } } else { marbles.getComponent(cc.RigidBody).linearVelocity = this._shootVec; } !marbles.parent && this._mapView.ballLayer.addChild(marbles); marbles.active = true; this._marblesCount++; this._marblesToShoot--; } }; Battle.prototype.makeMarbleNode = function () { var ball = cc.instantiate(this._prefabCollection.getChildByName('ball')); ball.setPosition(this.marblesBornPos); ball.getComponent(cc.RigidBody).linearVelocity.x = 0; ball.getComponent(cc.RigidBody).linearVelocity.y = 0; ball.active = false; return ball; }; Battle.prototype.doCollect = function (ballNode) { ballNode.getComponent(Ball_1.default).collecting = true; ballNode.getComponent(cc.PhysicsCollider).enabled = false; ballNode.getComponent(cc.RigidBody).linearVelocity = cc.Vec2.ZERO; var dis = cc.Vec3.distance(ballNode.position, this._ballTargetCache); var time = dis / Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 3).Value; if (time <= 0.02) { this.finishCollect(ballNode); } else { // PhysicsControl.ins.setTimeScale((tMgr.getConfig(TableName.GAME_PLAY, 5) as GamePlayTable).Value); this._speedUp && (time = time / Global_1.tMgr.getConfig(TableDefine_1.TableName.GAME_PLAY, 5).Value); cc.tween(ballNode).to(time, { position: this._ballTargetCache }).call(this.finishCollect.bind(this)).start(); } }; Battle.prototype.finishCollect = function (ballNode) { ballNode.active = false; ballNode.getComponent(cc.PhysicsCollider).enabled = true; // ballNode.getComponent(cc.RigidBody).enabled = true; ballNode.getComponent(Ball_1.default).collecting = false; BattleManager_1.BattleManager.ins.curBattle.onMarblesCollectedFinish(); }; return Battle; }()); exports.Battle = Battle; cc._RF.pop();