123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050 |
- const DWTool = require('../utils/DWTool');
- const { RoomState, GameNotificationKey, LevelHomeArtistItemStyle } = require("../utils/GameEnum");
- const GameModule = require("../utils/GameModule");
- const ThemeManager = require("../utils/ThemeManger");
- const HomeApi = require("../net/HomeApi");
- const CityList = require("../data/city");
- // const StateMachine = require('../lib/StateMachine');
- // const StateMachineHistory = require('../lib/StateMachineHistory');
- cc.Class({
- extends: cc.Component,
- properties: {
- // Public Properties
- bgNode: cc.Node,
- /** 当前显示的图片 */
- buildSprite: cc.Sprite,
- /** 柱子 */
- pillarTop: cc.Sprite,
- pillarBottom: cc.Sprite,
- pillarRight: cc.Sprite,
- pillarLeft: cc.Sprite,
- bottomBg: cc.Sprite,
- lockBtnFrames: [cc.SpriteFrame],
- /** 升级按钮的两种状态图 */
- updateBtnFrames: [cc.SpriteFrame],
- /** 未解锁状态的节点 */
- lockNode: cc.Node,
- /** 需要花费所有金币 */
- costLabel: cc.Label,
- /** 未解锁的建筑名称 */
- unLockBuildName: cc.RichText,
- /** 未解锁需要花费多少金币 */
- unlockRichText: cc.RichText,
- /** 建筑昵称 */
- buildNameLabel: cc.Label,
- /** 这里当做升级建筑按钮 */
- updateBtn: cc.Sprite,
- /** 解锁按钮 */
- lockBtn: cc.Sprite,
- /** 将要解锁建筑的类型图 */
- unlockBuildingType: cc.Sprite,
- lockBottomNode: cc.Node,
- /** 等级节点 */
- levelProgressNode: cc.Node,
- /** 等级进度条 */
- levelProgressBar: cc.ProgressBar,
- /** 等级 */
- levelProgressLabel: cc.Label,
- /** 生产金币节点 */
- rateProgressNode: cc.Node,
- /** 生产金币进度条 */
- rateProgressBar: cc.ProgressBar,
- /** 生产了多少金币 */
- rateProgressLabel: cc.Label,
- /** 倒计时 */
- countdownLabel: cc.Label,
- /** 金币满了提示 */
- coinFullTip: cc.Node,
- artistList: cc.Node,
- artistListItem: cc.Prefab,
- openDoorSkeletion: sp.Skeleton,
- updateSkeletion: sp.Skeleton,
- // 显示加成的节点
- additionNode: cc.Node,
- // 显示加成倍数
- additionLabel: cc.Label,
- // 加成的骨骼
- additionSkeleton: sp.Skeleton,
- // 满级提示
- maxNode: cc.Node,
- //入驻艺人提醒
- residentTipNode: cc.Node,
- // 加成倍数,默认倍率为x1,即无加成
- addition: {
- get: function () {
- if (!this._addition) {
- this._addition = 1;
- }
- return this._addition;
- },
- set: function (value) {
- this._addition = value;
- if (this._addition === 1) {
- this.additionNode.active = false;
- // this.additionSkeleton.setAnimation(0, 'jiasutiao_2', true);
- // this.rateProgressBar.barSprite.node.active = true;
- } else {
- this.additionNode.active = true;
- this.additionLabel.string = `X${this._addition}`;
- // this.rateProgressBar.barSprite.node.active = false;
- }
- }
- },
- coinArrayMax: {
- default: 3,
- type: cc.Integer,
- tooltip: "当前楼层最大存储金币数"
- },
- coinWrap: cc.Node,
- propWrap: cc.Node,
- coinPrefab: cc.Prefab,
- propPrefab: cc.Prefab,
- countDown: {
- get: function () {
- if (!this._countDown) {
- this._countDown = 0;
- }
- return this._countDown;
- },
- set: function (value) {
- this._countDown = value;
- this.countdownLabel.string = DWTool.calculateTime(this._countDown);
- this._preCountDown = this._countDown;
- }
- },
- rate: {
- get: function () {
- if (!this._rate) {
- this._rate = 0;
- }
- return this._rate;
- },
- set: function (value) {
- this._rate = value * this.addition;
- this.rateProgressLabel.string = DWTool.coinParse(this._rate);
- }
- },
- notPickupCount: {
- get: function () {
- if (!this._notPickupCount) {
- this._notPickupCount = 0;
- }
- return this._notPickupCount;
- },
- set: function (value) {
- this._notPickupCount = value;
- this.buildingInfo.coinCount = value;
- this.isNeedToReport = true;
- }
- },
- },
- // LIFE-CYCLE CALLBACKS:
- onLoad() {
- this.isNeedToReport = false;
- this.coinArray = [];
- this._currentTime = 0;
- this.isFirstLoad = true;
- this.humanList = [];
- this.isHasProp = false;
- this.updateSkeletion.node.active = false;
- this._rateProgressWidth = this.rateProgressBar.barSprite.node.width;
- this.openDoorSkeletion.setCompleteListener(() => {
- // 升级建筑
- this.updateBuilding();
- GameEvent.fire(GameNotificationKey.PlaySuccessAnimation);
- });
- let self = this;
- this.unlockBuildingEvent = _.debounce(() => {
- // 如果当前不够钱, 点击不生效
- if (GameModule.userInfo.grossIncome < self.buildingInfo.unlockScore) { return; }
- // 点完立刻隐藏
- self.lockBtn.node.active = false;
- let position = self.lockBtn.node.convertToWorldSpace(cc.v2(self.lockBtn.node.width / 2, self.lockBtn.node.height / 2));
- GameEvent.fire(GameNotificationKey.PlayUpdateCoinAnimation, position);
- self.openDoorSkeletion.setAnimation(1, "changjing_kaiqi2");
- self.lockBottomNode.runAction(cc.fadeOut(0.7));
- // this.lockBottomNode.active = false;
- }, 1000, true);
- // 监听自定义事件
- this.setEventListener();
- // 升级建筑事件
- this.updateBtn.node.on(cc.Node.EventType.TOUCH_END, () => {
- this.updateBuildingEvent();
- GameModule.audioMng.playUpdateBuilding();
- }, this);
- this.schedule(() => {
- if (this.isNeedToReport) {
- this.isNeedToReport = false;
- GameModule.userInfo.updateRecordModify(this.buildingInfo);
- }
- }, 2.0);
- this.guideEvent = _.debounce(() => {
- GameModule.homeGuide.getComponent('HomeGuide').handleGuideState17(this.artists);
- }, 1000, true);
- // 配置界面上的金币
- this.configCoins();
- // 配置界面上的道具
- this.configProp();
- },
- onDestroy() {
- GameEvent.off(GameNotificationKey.ResidentArtist, this);
- GameEvent.off(GameNotificationKey.RefreshLevelHomeArtistList, this);
- GameEvent.off(GameNotificationKey.LevelHomeItemBuildingAllFull, this);
- GameEvent.off(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, this);
- },
- setEventListener() {
- // 这个是入驻艺人成功时调用的
- GameEvent.on(GameNotificationKey.ResidentArtist, this, (uid, buildingId) => {
- if (this.node.active && this.uid === uid && this.buildingInfo.buildingId === buildingId) {
- HomeApi.friendGetArtistsInBuilding(this.uid, this.buildingInfo.buildingId, (data) => {
- // 为了不让当前的金币出现多种不同金额的币种, 当列表刷新时, 要收取一次
- if (this.state === RoomState.Update || this.state === RoomState.Full) {
- // 清空当前用来存储金币节点
- this.currentCoin = null;
- for (let i = 0; i < this.coinArrayMax; i++) {
- this.pickupCoin(this.coinArray[i], false);
- }
- }
- }, (code, msg) => {
- console.log(msg);
- })
- }
- });
- // 这个是召回驱赶艺人时调用的
- GameEvent.on(GameNotificationKey.RefreshLevelHomeArtistList, this, (uid, buildingId) => {
- if (this.node.active && this.uid === uid && this.buildingInfo.buildingId === buildingId) {
- HomeApi.friendGetArtistsInBuilding(this.uid, this.buildingInfo.buildingId, (data) => {
- this.artists = data.list || [];
- this.artistListLayout();
- }, (code, msg) => {
- console.log(msg);
- })
- }
- });
- // 所有建筑满级之后调用
- GameEvent.on(GameNotificationKey.LevelHomeItemBuildingAllFull, this, () => {
- if (this.isFirstLoad) { // 代表游戏一打开, 就是满级的
- this.currentCoin = null;
- this.coinWrap.active = false;
- this.artistList.active = false;
- this.coinFullTip.active = false;
- } else {
- GameModule.userInfo.updateRecordModify(this.buildingInfo);
- this.currentCoin = null;
- for (let i = 0; i < this.coinArrayMax; i++) {
- this.pickupCoin(this.coinArray[i]);
- }
- // 需要把艺人也都清空了
- for (let child of this.humanList) { child.destroy(); }
- this.coinWrap.active = false;
- this.artistList.active = false;
- this.coinFullTip.active = false;
- }
- })
- // 离线收益金币动画
- // 只显示最底部一层的金币收取
- // 其他楼层金币直接隐藏
- GameEvent.on(GameNotificationKey.HandleOfflineIncomeAnim, this, () => {
- // 清空当前用来存储金币节点
- this.currentCoin = null;
- let showAnim = this.index == 5 ? true : false
- for (let i = 0; i < this.coinArrayMax; i++) {
- this.pickupCoinWithNoIncom(this.coinArray[i], showAnim);
- }
- })
- GameEvent.on(GameNotificationKey.ReceiveLevelHomeItemPropUpdate, this, (buildingItem) => {
- if (buildingItem.buildingId != this.buildingInfo.buildingId) { return; }
- console.log(buildingItem);
- this.showProp(buildingItem.item);
- });
- },
- // 解锁建筑事件
- unlockBuilding() {
- this.unlockBuildingEvent();
- },
- updateBuildingEvent() {
- if (this.state === RoomState.Update) {
- // 清空当前用来存储金币节点
- this.currentCoin = null;
- for (let i = 0; i < this.coinArrayMax; i++) {
- this.pickupCoin(this.coinArray[i]);
- }
- let position = this.updateBtn.node.convertToWorldSpace(cc.v2(this.updateBtn.node.width / 2, this.updateBtn.node.height / 2));
- GameEvent.fire(GameNotificationKey.PlayUpdateCoinAnimation, position);
- this.updateBuilding();
- // if (!this.updateSkeletion.node.active) {
- this.updateSkeletion.node.active = true;
- this.updateSkeletion.setAnimation(0, "changjing_sj");
- this.updateSkeletion.setCompleteListener(() => {
- this.updateSkeletion.node.active = false;
- });
- // }
- // 如果好友列表功能已经开放
- if (GameModule.tab) {
- this.artists = GameModule.tab.getComponent('Tab').artists;
- // 尝试触发艺人入驻引导
- // this.guideEvent();
- }
- }
- },
- configCoins() {
- for (let i = 0; i < this.coinArrayMax; i++) {
- // 初始化
- let coinNode = cc.instantiate(this.coinPrefab)
- this.coinWrap.addChild(coinNode);
- coinNode = coinNode.getComponent("LevelHomeCoin");
- coinNode.index = i;
- this.coinHide(coinNode)
- this.coinArray[i] = coinNode;
- coinNode.node.on(cc.Node.EventType.TOUCH_END, (event) => {
- this.pickupCoin(coinNode);
- }, this);
- }
- },
- configProp() {
- let propNode = cc.instantiate(this.propPrefab)
- this.propScript = propNode.getComponent('LevelHomePropItem')
- this.propWrap.addChild(propNode);
- this.hideProp();
- },
- hideProp() {
- this.isHasProp = false;
- this.propScript.node.position = cc.v2(150, -108);
- this.propScript.node.active = false;
- this.propScript.isPlay = false;
- this.propScript.isPlaying = false;
- },
- showProp(propData, isPlayAnimation=true) {
- if (!this.isHasProp) {
- this.isHasProp = true;
- this.propScript.init(this.buildingInfo.buildingId, propData, (showFrame, showText) => {
- // 显示领取动画
- this.parent.showActGift(showFrame, showText)
- this.hideProp();
- });
- if (isPlayAnimation) {
- this.propScript.showAnimation();
- } else {
- this.propScript.node.position = cc.v2(150, -28);
- this.propScript.node.active = true;
- }
-
- } else {
- this.propScript.updateProp(propData);
- this.propScript.updateAnimation();
- }
- },
- /**
- * Public Method, 用来设置建筑背景图
- * @param {number} cityId 城市id
- * @param {number} index 楼层
- */
- init(parent, cityId, index) {
- if (arguments.length < 1) {
- throw new Error("init Missing parameter...");
- }
- this.parent = parent;
- this.cityId = cityId;
- this.index = index;
- this.isFirstLoad = true;
- ThemeManager.setBuildItemColor(this.cityId, this.bgNode);
- ThemeManager.setItemBuildSpriteFrame(this.cityId, this.buildSprite, index);
- ThemeManager.setItemPillarTopSpriteFrame(this.cityId, this.pillarTop);
- ThemeManager.setItemPillarBottomSpriteFrame(this.cityId, this.pillarBottom);
- ThemeManager.setItemPillarRightSpriteFrame(this.cityId, this.pillarRight);
- ThemeManager.setItemPillarLeftSpriteFrame(this.cityId, this.pillarLeft);
- ThemeManager.setItemDownSpriteFrame(this.cityId, this.bottomBg);
- let lockBottomSprite = this.lockBottomNode.getComponent(cc.Sprite);
- ThemeManager.setItemLockDownSpriteFrame(this.cityId, lockBottomSprite);
- },
- /**
- * Public Method, 配置建筑的内部样式
- * @param {*} buildingInfo 建筑信息
- * @param {*} uid 当前用户的uid
- */
- config(buildingInfo, uid, unlockBuildingRecord, resetCallback) {
- // console.log(buildingInfo.coinCount);
- this.unlockBuildingRecord = unlockBuildingRecord;
- if (resetCallback) {
- this.resetCallback = resetCallback;
- }
- if (buildingInfo.buildingId == 1) {
- if (buildingInfo.level == 0) {
- // 监听完成引导系统state1的事件
- GameModule.homeGuide.on('Fire_state1', this.unlockBuildingEvent, this)
- // 触发引导系统state1状态
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state1')
- }
- }
- this.buildingInfo = buildingInfo;
- this.uid = uid;
- this.artists = this.buildingInfo.artists;
- // 这里设置一些只需要设置一次的数据
- this.countDown = buildingInfo.rateUnit;
- this.buildNameLabel.string = buildingInfo.name;
- this._notPickupCount = buildingInfo.coinCount;
- // console.log(buildingInfo.coinCount, this.coinArrayMax);
- if (buildingInfo.coinCount === this.coinArrayMax * 10) {
- this.rateProgressBar.progress = 1;
- this.countdownLabel.string = DWTool.calculateTime(0);
- }
- this.levelProgressLabel.string = `LV.${buildingInfo.level}`;
- if (this.isFirstLoad) {
- this.isFirstLoad = false;
- this.artistListLayout();
- }
- //城市开发完毕的时候不显示艺人入驻按钮
- if (GameModule.userInfo.levelHomeItemFullCount != 5 && this.cityId === Global.devCityId) {
- this.artistList.active = true;
- } else {
- this.artistList.active = false;
- }
- this.initializeCoinPosition();
- this.layout(buildingInfo);
- },
- /** 初始化金币的位置 */
- initializeCoinPosition() {
- // 2018年08月18日15:25, 子奇要求我去好友家园时, 不显示未收取金币
- // 城市已经开发完毕不显示金币
- if (this.cityId === Global.devCityId && GameModule.userInfo.levelHomeItemFullCount != 5) {
- this.coinWrap.active = true;
- } else {
- this.coinWrap.active = false;
- return;
- }
- if (!this.buildingInfo.coinCount) {
- for (let i = 0; i < this.coinArrayMax; i++) {
- let coin = this.coinArray[i];
- this.coinHide(coin);
- }
- return;
- }
- for (let i = 0; i < this.coinArrayMax; i++) {
- let coin = this.coinArray[i];
- while (this.buildingInfo.coinCount != 0 && coin.coinCount != 10) {
- coin.coinCount += 1;
- this.buildingInfo.coinCount -= 1;
- }
- if (coin.coinCount != 0) {
- let x = -140 + (85 * i);
- coin.isPlay = true;
- coin.node.position = cc.v2(x, -28);
- coin.node.active = true;
- if (this.addition > 1) {
- let rate = this.buildingInfo.rate * this.addition;
- coin.totalRate = rate * coin.coinCount;
- } else {
- coin.totalRate = this.buildingInfo.rate * coin.coinCount;
- }
- coin.initStatic(i);
- }
- }
- },
- artistListLayout() {
- for (let child of this.artistList.children) { child.destroy(); }
- for (let child of this.humanList) { child.destroy(); }
- let self = this;
- let addAddItemToList = function (showTop = false, showBottom = false) {
- let addArtistItem = cc.instantiate(self.artistListItem);
- self.artistList.addChild(addArtistItem);
- let addArtistScript = addArtistItem.getComponent('LevelHomeArtistItem');
- addArtistScript.initWithBuildingInfo(self.buildingInfo, self.uid, true, showTop, showBottom);
- }
- let addArtistItemToList = function (artist, showTop = false, showBottom = false) {
- let artistItem = cc.instantiate(self.artistListItem);
- self.artistList.addChild(artistItem);
- let artistScript = artistItem.getComponent('LevelHomeArtistItem');
- artistScript.initWithArtistData(self.buildingInfo, self.uid, true, artist, showTop, showBottom);
- }
- let addHuman = function (artist, index) {
- DWTool.loadResPrefab("./prefabs/artist_man")
- .then((prefab) => {
- let human = cc.instantiate(prefab);
- human.getComponent('ArtistMan').init(artist);
- human.getComponent('ArtistMan').direction = (index > 0) ? 1 : -1;
- self.node.addChild(human);
- self.humanList.push(human);
- });
- }
- this.addition = 1;
- // 当没有自己艺人, 也没有好友艺人入驻时, 这里还得区分主态和客态
- if (this.artists.length === 0) {
- // 没有艺人不显示倍数
- addAddItemToList(true);
- } else {
- // 有艺人入驻要显示倍数
- this.additionNode.active = true;
- if (this.artists.length === 1) {
- let artist = this.artists[0];
- this.addition += artist.stationJobLevel;
- // 这里要区分主态和客态, 去别人家园时, 如果有一个是客态自己的艺人, 那么另一个就是可以入驻的按钮
- if (artist.role === 2) {
- addArtistItemToList(artist, true);
- addHuman(artist, (Math.random() - 0.5) * 2);
- } else {
- addAddItemToList(true, true);
- addArtistItemToList(artist);
- addHuman(artist, (Math.random() - 0.5) * 2);
- }
- } else {
- for (let i = 0; i < this.artists.length; i++) {
- let artist = this.artists[i];
- this.addition += artist.stationJobLevel;
- if (i === 0) {
- addArtistItemToList(artist, true, true);
- } else {
- addArtistItemToList(artist);
- }
- addHuman(artist, i);
- }
- }
- }
- },
- layout(buildingInfo) {
- // 判断是否有下一级, 没有的话就是满级
- if (buildingInfo.hasNext === 1 && buildingInfo.level <= Global.BuildingManager.getLevelCount(buildingInfo.buildingId)) {
- // 判断是否已经解锁
- if (buildingInfo.isUnlocked) {
- /**
- * 2018年09月26日 要求将进度条改成每25级就清空, 重新走, 原来的实现如下:
- * this.levelProgressBar.progress = buildingInfo.level / Global.BuildingManager.getLevelCount(buildingInfo.buildingId);
- */
- let ratio = buildingInfo.level % 25;
- this.levelProgressBar.progress = ratio / 25;
- this.artistList.active = true;
- this.lockNode.active = false;
- this.costLabel.string = DWTool.coinParse(buildingInfo.nextUpScore);
- this.rate = buildingInfo.rate;
- // 判断是否有足够的金额解锁
- if (GameModule.userInfo.grossIncome >= buildingInfo.nextUpScore) {
- if (buildingInfo.buildingId === 1 && buildingInfo.level === 1) {
- // 第三个引导
- GameModule.homeGuide.on('Fire_state3', this.updateBuildingEvent, this)
- // 触发引导系统state3状态
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state3')
- }
- this.setState(RoomState.Update);
- } else {
- this.setState(RoomState.UnLock);
- }
- } else {
- this.artistList.active = false;
- this.countDown = 0;
- this._currentTime = 0;
- this.rateProgressBar.progress = 0;
- this.totalRate = 0;
- this.lockNode.active = true;
- this.costLabel.string = 0;
- this.hideProp();
- this.unLockBuildName.string = `<b><color=#ffffff>${buildingInfo.name}</c></b>`;
- this.unlockRichText.string = `<img src='alert_coin'/><b><color=#ffffff> ${DWTool.coinParse(buildingInfo.unlockScore)}</c><b/>`;
- // 判断是否有足够的金额解锁
- if (GameModule.userInfo.grossIncome >= buildingInfo.unlockScore) {
- if (this.unlockBuildingRecord[0] === 1 && this.buildingInfo.buildingId === 2) { // 如果第一层已经解锁, 才能执行下一个引导
- setTimeout(() => {
- // 监听完成引导系统state4的事件
- GameModule.homeGuide.on('Fire_state4', this.unlockBuildingEvent, this)
- // 触发引导系统state4状态
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state4')
- }, 500);
- } else if (this.unlockBuildingRecord[1] === 1 && this.buildingInfo.buildingId === 3) {
- setTimeout(() => {
- // 监听完成引导系统state5的事件
- GameModule.homeGuide.on('Fire_state5', this.unlockBuildingEvent, this)
- // 触发引导系统state5状态
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state5')
- }, 500)
- }
- this.unlockBuildingType.node.active = true;
- this.lockBtn.spriteFrame = this.lockBtnFrames[1];
- this.lockBtn.node.getComponent(cc.Button).interactable = true;
- } else {
- this.unlockBuildingType.node.active = false;
- this.lockBtn.spriteFrame = this.lockBtnFrames[0];
- this.lockBtn.node.getComponent(cc.Button).interactable = false;
- }
- this.setState(RoomState.Lock);
- }
- } else {
- this.rate = buildingInfo.rate;
- this.levelProgressBar.progress = 1.0;
- this.setState(RoomState.Full);
- }
- },
- setState(state) {
- if (this.state === state) { return; }
- switch (state) {
- case RoomState.Lock:
- this.openDoorSkeletion.node.active = true;
- this.openDoorSkeletion.clearTracks();
- this.openDoorSkeletion.setToSetupPose();
- this.lockBtn.node.active = true;
- this.lockBottomNode.stopAllActions();
- this.lockBottomNode.opacity = 255;
- this.lockBottomNode.active = true;
- this.lockNode.active = true;
- this.updateBtn.node.active = false;
- this.updateBtn.spriteFrame = this.updateBtnFrames[0];
- this.updateBtn.node.getComponent(cc.Button).interactable = false;
- this.maxNode.active = false;
- break;
- case RoomState.UnLock:
- this.openDoorSkeletion.node.active = false;
- this.lockBtn.node.active = false;
- this.lockBottomNode.active = false;
- this.updateBtn.node.active = true;
- this.lockNode.active = false;
- this.updateBtn.spriteFrame = this.updateBtnFrames[0];
- this.updateBtn.node.getComponent(cc.Button).interactable = false;
- this.maxNode.active = false;
- break;
- case RoomState.Update:
- this.openDoorSkeletion.node.active = false;
- this.lockBtn.node.active = false;
- this.lockBottomNode.active = false;
- this.updateBtn.node.active = true;
- this.lockNode.active = false;
- this.updateBtn.spriteFrame = this.updateBtnFrames[1];
- this.updateBtn.node.getComponent(cc.Button).interactable = true;
- this.maxNode.active = false;
- break;
- case RoomState.Full:
- this.openDoorSkeletion.node.active = false;
- this.lockBtn.node.active = false;
- this.lockBottomNode.active = false;
- this.lockNode.active = false;
- this.maxNode.active = true;
- this.updateBtn.node.active = false;
- default:
- break;
- }
- this.state = state;
- },
- // 升级建筑
- updateBuilding() {
- // 从配置文件里获取
- let maxLevel = Global.BuildingManager.getLevelCount(this.buildingInfo.buildingId);
- let nextLevel = this.buildingInfo.level + 1;
- let level = nextLevel > maxLevel ? maxLevel : nextLevel;
- let buildModel = Global.BuildingManager.getBuildingInfo(this.cityId, this.buildingInfo.buildingId, level);
- this.isLevelSpeedUp(buildModel);
- // 将已有入驻的艺人赋值给新的model, 保持一个引用
- buildModel.artists = this.buildingInfo.artists;
- if (this.buildingInfo.isUnlocked) {
- // 当前楼层已解锁
- GameModule.userInfo.grossIncome -= this.buildingInfo.nextUpScore;
- GameModule.userInfo.updateRecordModify(buildModel);
- } else {
- // 当前楼层未解锁
- this.unlockBuildingRecord[this.buildingInfo.buildingId - 1] = 1;
- GameModule.userInfo.grossIncome -= this.buildingInfo.unlockScore;
- HomeApi.buildingUnlock(this.buildingInfo.buildingId, () => {
- }, (err) => {
- console.log(`============> ${this.buildingInfo.buildingId}解锁失败!!!! <============`)
- })
- // GameModule.userInfo.recordUnlockModify.push(buildModel);
- // // 成功解锁后立刻调用上报,提交ub
- // GameModule.userInfo.doReport()
- }
- GameModule.userInfo.stars += 1;
- if (this.resetCallback) {
- this.resetCallback(buildModel);
- }
- this.config(buildModel, this.uid);
- // 如果满级了, 就发通知告诉userinfo
- if (buildModel.hasNext != 1 && this.cityId != CityList[CityList.length-1].id) {
- GameEvent.fire(GameNotificationKey.LevelHomeItemBuildingFull);
- }
- if (buildModel.level === 1) {
- GameEvent.fire(GameNotificationKey.LevelHomeItemUnlock);
- }
- },
- /**
- * 升级到某个特定等级,根据配置表的金币生产速度和时间,判断是否需要弹出金币x2或者时间-50%的通知。
- */
- isLevelSpeedUp(buildingInfo) {
- if (buildingInfo.level <= 2) {
- return;
- }
- if (buildingInfo.rate >= this.buildingInfo.rate * 2) {
- GameEvent.fire(GameNotificationKey.LevelHomeSpeedUp, buildingInfo.name, 1);
- } else if (buildingInfo.rateUnit === this.buildingInfo.rateUnit / 2) {
- GameEvent.fire(GameNotificationKey.LevelHomeSpeedUp, buildingInfo.name, 2);
- }
- },
- // 收取金币
- pickupCoin(coin, isShowAnimation = true) {
- if (this.currentCoin === coin) {
- this.currentCoin = null;
- }
- if (isShowAnimation) {
- let pos = coin.node.convertToWorldSpace(cc.v2(coin.node.width / 2, coin.node.height / 2));
- this.showCollectAnim(pos, coin.coinCount)
- }
- // 点击一次金币, 就将notPickupCount减去coinNode.coinCount
- this.notPickupCount -= coin.coinCount;
- // console.log(`收入: ${buildingInfo.rate * coin.coinCount}`);
- GameModule.userInfo.grossIncome += (this.buildingInfo.rate * coin.coinCount * this._addition);
- this.coinHide(coin);
- },
- // 收取金币,不增加收益
- pickupCoinWithNoIncom(coin, isShowAnimation = true) {
- if (this.currentCoin === coin) {
- this.currentCoin = null;
- }
- if (isShowAnimation) {
- let pos = coin.node.convertToWorldSpace(cc.v2(coin.node.width / 2, coin.node.height / 2));
- this.showCollectAnim(pos, coin.coinCount)
- }
- // 点击一次金币, 就将notPickupCount减去coinNode.coinCount
- this.notPickupCount -= coin.coinCount;
- this.coinHide(coin);
- },
- showCollectAnim(pos, colNums) {
- let canvasNode = cc.find("Canvas");
- let grossCoin = GameModule.userInfo.grossCoin;
- let grossCoinPos = grossCoin.node.convertToWorldSpace(cc.v2(grossCoin.node.width / 2, grossCoin.node.height / 2));
- // let colNums = 5
- let vSize = cc.view.getVisibleSize();
- let target = cc.v2(grossCoinPos.x - vSize.width / 2, grossCoinPos.y - vSize.height / 2)
- let i = 0;
- let runSt = setInterval(() => {
- if (i == colNums) {
- clearInterval(runSt)
- } else {
- let ran = (Math.random() - 0.5) * 2 * 3;
- let newCoin = cc.instantiate(this.coinPrefab);
- let posX = pos.x - vSize.width / 2;
- let posY = pos.y - vSize.height / 2;
- canvasNode.addChild(newCoin)
- newCoin.x = posX + ran * 15;
- newCoin.y = posY + 30 + ran * 15;
- newCoin.active = true;
- newCoin = newCoin.getComponent("LevelHomeCoin")
- newCoin.initAnim()
- let cbNotiStart = cc.callFunc(() => {
- GameEvent.fire(GameNotificationKey.UserCollectCoin, true);
- })
- let cbDestroy = cc.callFunc(() => {
- newCoin.node.destroy();
- })
- let act = cc.sequence(cc.moveTo(1, target), cbDestroy, cbNotiStart)
- newCoin.node.runAction(act.easing(cc.easeIn(2.1)));
- i++
- }
- }, 100);
- },
- coinHide(coin) {
- // 算出金币的x值, 70是金币宽度, -130是第一个金币的x值
- let x = -140 + (85 * coin.index);
- // 重置金币状态
- coin.node.position = cc.v2(x, -108);
- coin.node.active = false;
- coin.isPlay = false;
- coin.isPlaying = false;
- coin.coinCount = 0;
- coin.totalRate = 0;
- },
- getFreeCoin() {
- for (let i = 0; i < this.coinArrayMax; i++) {
- let coinNode = this.coinArray[i];
- if (coinNode.coinCount != 10) {
- return coinNode;
- }
- }
- return null;
- },
- generateCoin() {
- if (this.currentCoin && this.currentCoin.coinCount < 10) {
- this.currentCoin.totalRate += this.rate;
- this.currentCoin.coinCount += 1;
- this.currentCoin.updateAnimation();
- } else {
- this.currentCoin = this.getFreeCoin();
- if (this.currentCoin) {
- this.currentCoin.totalRate += this.rate;
- this.currentCoin.coinCount += 1;
- if (this.buildingInfo.buildingId === 1 && this.buildingInfo.level === 1 && this.notPickupCount === 1) {
- // 监听完成引导系统state2的事件
- GameModule.homeGuide.on('Fire_state2', () => {
- this.pickupCoin(this.currentCoin);
- }, this);
- // 触发引导系统state1状态
- GameModule.homeGuide.getComponent('HomeGuide').handleState('state2');
- }
- if (!this.currentCoin.isPlay) {
- this.currentCoin.showAnimation();
- } else {
- this.currentCoin.updateAnimation();
- }
- }
- }
- },
- update(dt) {
- if (this.buildingInfo) {
- // 不断刷新界面
- this.layout(this.buildingInfo);
- // 只有已经解锁进度条才会走
- if (this.buildingInfo.isUnlocked) {
- // 进度条走完, 开始生产金币
- if (Math.floor(this.rateProgressBar.progress) === 1) {
- this.rateProgressBar.progress = 1;
- if (GameModule.userInfo.levelHomeItemFullCount != 5 && // 是否满级
- this.cityId === Global.devCityId) { // 当前访问的是不是这个city
- if (this.notPickupCount >= this.coinArrayMax * 10) {
- this.rateProgressLabel.node.active = false;
- this.coinFullTip.active = true;
- } else {
- this.coinFullTip.active = false;
- this.notPickupCount += 1;
- this.generateCoin();
- this.rateProgressBar.progress = 0;
- this._currentTime = 0;
- }
- } else { // 满级后的状态
- this.rateProgressBar.progress = 0;
- this._currentTime = 0;
- this.coinFullTip.active = false;
- this.rateProgressLabel.node.active = true;
- }
- } else {
- this.rateProgressLabel.node.active = true;
- this.coinFullTip.active = false;
- this._currentTime += dt;
- this.rateProgressBar.progress = this._currentTime / this.countDown;
- if (Math.floor(this.rateProgressBar.progress) === 1) {
- this.rateProgressBar.progress = 1;
- }
- let resultCountDown = this.countDown - Math.floor(this._currentTime);
- if (this._preCountDown !== resultCountDown) {
- this.countdownLabel.string = DWTool.calculateTime(resultCountDown);
- this._preCountDown = resultCountDown;
- }
- }
- }
- }
- },
- setResidentTip(show) {
- this.residentTipNode.active = show;
- }
- });
|