Game.ts 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601
  1. import Util from "../../before/util/Util";
  2. import JsbSystem from "../../mk/system/JsbSystem";
  3. import TimeUtil from "../../mk/utils/TimeUtil";
  4. import SetGray from "../component/SetGray";
  5. import { AdFun, RateConfig } from "../data/AdData";
  6. import { DataEventId, FarmState, GameProp, ProductType, VideoAdType } from "../data/GameData";
  7. import FunBtns from "./FunBtns";
  8. const { ccclass, property } = cc._decorator;
  9. @ccclass("RedPoinNode")
  10. export class RedPoinNode {
  11. @property({ type: cc.Node, displayName: "等级奖励" })
  12. node_gradeReward: cc.Node = null;
  13. @property({ type: cc.Node, displayName: "签到" })
  14. node_sign: cc.Node = null;
  15. @property({ type: cc.Node, displayName: '轮盘' })
  16. node_turnable: cc.Node = null;
  17. }
  18. @ccclass
  19. export default class Game extends cc.Component {
  20. @property({ type: cc.Node, displayName: "功能按钮" })
  21. node_btn: cc.Node = null;
  22. @property({ type: cc.Label, displayName: "红包币" })
  23. lbl_redMoney: cc.Label = null;
  24. @property({ type: cc.Sprite, displayName: "红包提现" })
  25. btn_cashOutNormal: cc.Sprite = null;
  26. @property({ type: cc.Sprite, displayName: "金猪提现" })
  27. btn_cashOutGold: cc.Sprite = null;
  28. @property({ type: cc.Node, displayName: "红包币图标" })
  29. icon_hb: cc.Node = null;
  30. @property({ type: cc.Node, displayName: "金猪币图标" })
  31. icon_zb: cc.Node = null;
  32. @property({ type: cc.Node, displayName: "顶部ui组" })
  33. node_top_ui: cc.Node = null;
  34. @property({ type: RedPoinNode, displayName: "红点组" })
  35. nodeRedPoint: RedPoinNode = null;
  36. @property({ type: cc.Sprite, displayName: "要种植植物图片" })
  37. icon_plant: cc.Sprite = null;
  38. @property({ type: cc.Sprite, displayName: "要种植植物名称" })
  39. icon_plantName: cc.Sprite = null;
  40. @property({ type: cc.Label, displayName: "种植次数文本" })
  41. lbl_leftTimes: cc.Label = null;
  42. @property({ type: cc.RichText, displayName: '任务文本' })
  43. lbl_task: cc.RichText = null;
  44. @property({ type: cc.Node, displayName: '任务红包节点' })
  45. node_taskHb: cc.Node = null;
  46. @property({ type: cc.Node, displayName: '生产按钮节点' })
  47. btn_product: cc.Node = null;
  48. @property({ type: cc.Label, displayName: '等级文本' })
  49. lbl_farmLevel: cc.Label = null;
  50. @property({ type: cc.Sprite, displayName: '等级进度' })
  51. sp_levelPer: cc.Sprite = null;
  52. @property({ type: cc.Animation, displayName: '增加效果文本' })
  53. ani_add: cc.Animation = null;
  54. @property({ type: cc.Node, displayName: '任务红包手' })
  55. node_hand: cc.Node = null;
  56. @property({ type: cc.Sprite, displayName: '等级名字' })
  57. sp_gradeName: cc.Sprite = null;
  58. @property({ type: cc.Node, displayName: '增加效果文本2' })
  59. ani_add2: cc.Node = null;
  60. @property({ type: cc.Node, displayName: '增加效果文本3' })
  61. ani_add3: cc.Node = null;
  62. @property({ type: cc.Node, displayName: '加经验效果' })
  63. node_addExp: cc.Node = null;
  64. @property({ type: cc.Label, displayName: '加经验文本' })
  65. lbl_addExp: cc.Label = null;
  66. @property({ type: cc.Node, displayName: '加红包币效果' })
  67. node_addHb: cc.Node = null;
  68. @property({ type: cc.Label, displayName: '加红包币文本' })
  69. lbl_addHb: cc.Label = null;
  70. //图鉴部分
  71. @property({ type: cc.Node, displayName: '图鉴ui总节点' })
  72. node_farmMapUI: cc.Node = null;
  73. @property({ type: cc.Node, displayName: '图鉴领奖节点' })
  74. node_farmMapGetReward: cc.Node = null;
  75. @property({ type: cc.Node, displayName: '图鉴种植节点' })
  76. node_farmMapProduct: cc.Node = null;
  77. @property({ type: cc.RichText, displayName: '描述' })
  78. lbl_farmMapDes: cc.RichText = null;
  79. @property({ displayName: '数字组', type: cc.Label })
  80. lbl_value: cc.Label[] = [];
  81. //订单部分
  82. @property({ displayName: '农作物图标', type: cc.Sprite })
  83. sp_cropIcon: cc.Sprite[] = [];
  84. @property({ displayName: '农作物名字', type: cc.Label })
  85. lbl_cropName: cc.Label[] = [];
  86. @property({ displayName: '农作物进度', type: cc.Label })
  87. lbl_progress: cc.Label[] = [];
  88. @property({ displayName: '进度完成对勾', type: cc.Sprite })
  89. sp_mark: cc.Sprite[] = [];
  90. @property({ displayName: '订单红包币数字组', type: cc.Label })
  91. lbl_redMoneyValue: cc.Label[] = [];
  92. @property({ displayName: '领奖按钮', type: SetGray })
  93. node_getOrderReward: SetGray = null;
  94. @property({ displayName: '手指', type: cc.Node })
  95. node_orderHand: cc.Node = null;
  96. @property({ type: cc.Node, displayName: '增加效果文本2' })
  97. ani_add4: cc.Node = null;
  98. @property({ displayName: '现金', type: cc.Label })
  99. lbl_addCash: cc.Label = null;
  100. @property({ displayName: '红包币图标', type: cc.Node })
  101. node_orderHb: cc.Node = null;
  102. @property({ displayName: '额外订单ui节点', type: cc.Node })
  103. node_extraOrderUi: cc.Node = null;
  104. @property({ displayName: '额外订单背景节点', type: cc.Node })
  105. node_bgUi: cc.Node = null;
  106. @property({ displayName: '订单显示', type: cc.Node })
  107. node_crop: cc.Node[] = [];
  108. @property({ displayName: '订单红包', type: cc.Node })
  109. node_orderHbIcon: cc.Node = null;
  110. @property({ displayName: '显示现金', type: cc.Node })
  111. node_showCash: cc.Node = null;
  112. @property({ displayName: '显示红包币', type: cc.Node })
  113. node_showRedMoney: cc.Node = null;
  114. @property({ displayName: '订单红包币', type: cc.Label })
  115. lbl_orderRedMoney: cc.Label = null;
  116. @property({ displayName: '提现进度', type: cc.Sprite })
  117. pro_tixian: cc.Sprite = null;
  118. @property({ displayName: '提现进度文本', type: cc.Label })
  119. lbl_cashPro: cc.Label = null;
  120. @property({ displayName: '富翁银行进度', type: cc.Sprite })
  121. pro_bank: cc.Sprite = null;
  122. @property({ displayName: '富翁银行文本', type: cc.Label })
  123. lbl_bankPro: cc.Label = null;
  124. @property({ displayName: '富翁银行按钮', type: cc.Node })
  125. btn_safebox: cc.Node = null;
  126. posY = 0;
  127. /** 是否开始增加次数倒计时 */
  128. private lastTimeSpan = 0;
  129. private span = 0;
  130. private autoPopSign = true;
  131. private isShowAddProductTimesUI = false;
  132. private is
  133. onLoad() {
  134. this.posY = this.ani_add2.y;
  135. this.ani_add.node.active = false;
  136. gData.gameData.gameStyle = this;
  137. this.span = gData.gameData.ProductionRecovery * 60 * 1000;
  138. gData.gameData.checkTaskFinishUnLock();
  139. gData.gameData.maxProductToServer = true;
  140. gData.gameData.updateMaxProduct();
  141. this.registerCallBack();
  142. console.log("===[Jsbsystem 显示开屏广告================================")
  143. if (mk.ad.ifShowAd) {
  144. let rand = Math.random();
  145. let rate = gData.adData.getPerByEcpm(RateConfig.RC_splash);
  146. if (rand <= rate) {
  147. JsbSystem.showSplash();
  148. }
  149. }
  150. this.initRefreshEvent();
  151. if (gData.gameData.orderRewardType == 1) {
  152. this.node_showCash.active = false;
  153. this.node_showRedMoney.active = true;
  154. }
  155. if (gData.gameData.playerProp.orderData) {
  156. this.initOrderUI();
  157. } else {
  158. mk.event.register("initOrderUi", this.initOrderUI.bind(this), this);
  159. }
  160. let times = gData.gameData.getProp(GameProp.plantTimes);
  161. console.log(`cashTimes======${times}`);
  162. if (times == undefined) {
  163. times = 0;
  164. }
  165. if (times < gData.gameData.showRichBankIconLimit) {
  166. this.btn_safebox.active = false;
  167. mk.event.register("showRichBankIcon", this.showRichBankIcon.bind(this), this);
  168. }
  169. }
  170. async showRichBankIcon() {
  171. this.btn_safebox.active = true;
  172. mk.event.remove("showRichBankIcon", this);
  173. if (!gData.safeDepositBoxData.currentRichBankCashTaskIndex) {
  174. let response = await mk.http.sendData('newrichbank/getRichBankInfo', {});
  175. if (response && response.errcode == 0) {
  176. let res_data = response.data;
  177. //gData.safeDepositBoxData.richBankCashAmount = res_data.richBankCashAmount;
  178. gData.safeDepositBoxData.currentRichBankCashTaskIndex = res_data.currentRichBankCashTaskIndex;
  179. gData.safeDepositBoxData.isStartBankTask = res_data.isStartRichBankTask;
  180. //gData.safeDepositBoxData.richBankDailyVideoTimes = res_data.richBankDailyVideoTimes;
  181. gData.safeDepositBoxData.richbankLoginDays = res_data.richbankLoginDays;
  182. //gData.safeDepositBoxData.richBankDailyTotelVideoTimes = res_data.richBankDailyTotelVideoTimes;
  183. //gData.safeDepositBoxData.richBankTotelLoginDays = res_data.richBankTotelLoginDays;
  184. console.log(`currentRichBankCashTaskIndex 11======== ${res_data.currentRichBankCashTaskIndex}`);
  185. console.log(`richBankDailyTotelVideoTimes 11======== ${res_data.richBankDailyTotelVideoTimes}`);
  186. }
  187. }
  188. }
  189. start() {
  190. this.initMusic();
  191. this.initBtns();
  192. this.initInfo();
  193. //this.autoOpenPanel();
  194. this.runGuideWeak();
  195. this.initLeftTimes();
  196. this.initFarmExpUI();
  197. this.initCashProBar();
  198. this.initBankProBar();
  199. // if(gData.sign.redPoint() && this.autoPopSign)
  200. // {
  201. // let id = gData.gameData.getProp(GameProp.guideID);
  202. // if(id >= 1)
  203. // {
  204. // mk.ui.openPanel('module/sign/sign');
  205. // }
  206. // this.autoPopSign = false;
  207. // }
  208. // //test
  209. // gData.gameData.setProp(GameProp.guideID, 0);
  210. // mk.guide.open(10);
  211. if (gData.gameData.funOpenData[11] == "1") {
  212. let isPopUi = mk.ui.isPopPanel();
  213. if (!isPopUi) {
  214. let isTeach = mk.guide.open(10);
  215. if (isTeach) {
  216. mk.event.register("event_guide", this.initGuideEvent.bind(this), this);
  217. //mk.guide.continueCallBack = this.judgeContinueTeach;
  218. }
  219. }
  220. }
  221. let value = mk.storage.getStorage('loadingFinish');
  222. if (!value) {
  223. mk.storage.setStorage('loadingFinish', 1);
  224. mk.data.sendDataEvent(DataEventId.loading, 'loading结束');
  225. }
  226. setTimeout(() => {
  227. gData.safeDepositBoxData.deleteJGTags();
  228. }, 1000)
  229. }
  230. update(dt) {
  231. if (gData.gameData.init_coin) {
  232. this.changeInfo();
  233. }
  234. if (gData.gameData.init_head) {
  235. this.initHead();
  236. }
  237. if (gData.gameData.init_red_point) {
  238. this.initRedPoint();
  239. }
  240. if (gData.gameData.init_makeInfo) {
  241. this.initCanPlantInfo();
  242. }
  243. if (gData.gameData.init_leftTimes) {
  244. this.initLeftTimes();
  245. }
  246. if (gData.gameData.init_task) {
  247. this.changeTaskUI();
  248. }
  249. if (gData.gameData.init_expLevel) {
  250. this.initFarmExpUI();
  251. }
  252. if (gData.walletCashOutData.init_cashOut) {
  253. this.initCashProBar();
  254. }
  255. if (gData.safeDepositBoxData.freshQipao) {
  256. this.initBankProBar();
  257. }
  258. gData.adData.startPopRed(dt);
  259. gData.gameData.firstCheckNext();
  260. let add = 0;
  261. let needAdd = true;
  262. let offset = 0;
  263. if (gData.gameData.leftTimes < gData.gameData.maxTimes && this.lastTimeSpan != 0) {
  264. let pass = Date.now() - this.lastTimeSpan;
  265. if (pass >= this.span) {
  266. add = Math.floor(pass / this.span);
  267. this.lastTimeSpan += (add * this.span);
  268. mk.storage.setStorage('lastTimeSpan', this.lastTimeSpan);
  269. offset = gData.gameData.maxTimes - gData.gameData.leftTimes;
  270. gData.gameData.changeLeftTimes(add, false, this.isShowAddProductTimesUI);
  271. }
  272. }
  273. //注释离线收益次数
  274. // if (!this.isShowAddProductTimesUI && needAdd) {
  275. // this.isShowAddProductTimesUI = true;
  276. // if (add > 0) {
  277. // add = add > offset ? offset : add;
  278. // if (add > 0) {
  279. // //add = add > gData.gameData.maxTimes ? gData.gameData.maxTimes : add;
  280. // gData.gameData.restoreProductTimes = add;
  281. // mk.ui.openPanel('module/speedUpUI/restoreProductTimes');
  282. // mk.data.sendDataEvent(DataEventId.offlineProductTimes, "离线生产次数弹出");
  283. // }
  284. // }
  285. // }
  286. if (this.startTimes) {
  287. this.btnCD += dt;
  288. if (this.btnCD >= 1) {
  289. this.startTimes = false;
  290. this.btnCD = 0;
  291. }
  292. }
  293. }
  294. lateUpdate() {
  295. gData.gameData.init_head = false;
  296. gData.safeDepositBoxData.freshQipao = false;
  297. gData.walletCashOutData.init_cashOut = false;
  298. }
  299. private initMusic() {
  300. mk.audio.playMusic("bgm");
  301. }
  302. /**
  303. * 根据配置,添加开启的功能按钮
  304. */
  305. private initBtns() {
  306. // let sc = this.node_btn.getComponent(FunBtns) as FunBtns;
  307. // sc.init();
  308. }
  309. private initInfo() {
  310. this.lbl_redMoney.string = gData.gameData.playerProp.redMoney / 100 + "";
  311. gData.gameData.init_coin = false;
  312. if (gData.gameData.playerProp.userFarmTaskInfo) {
  313. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  314. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  315. if (gData.gameData.init_redBagTask) {
  316. this.lbl_task.string = `<b><color=#8D4D32>点击领取任务!</c></b>`
  317. this.node_hand.active = true;
  318. } else {
  319. this.lbl_task.string = `<b><color=#8D4D32>进行${count}次生产</c><color=#D73D25>(${com}/${count})</color></b>`
  320. if (com >= count) {
  321. this.node_hand.active = true;
  322. } else {
  323. this.node_hand.active = false;
  324. }
  325. }
  326. }
  327. }
  328. private changeInfo() {
  329. //this.lbl_redMoney.node.getComponent(mk.component.numberAnim).setValue(gData.gameData.playerProp.redMoney);
  330. cc.tween(this.lbl_redMoney.node).to(0.1, { scale: 1.2 }).to(0.05, { scale: 1 }).start();
  331. this.lbl_redMoney.string = gData.gameData.playerProp.redMoney / 100 + "";
  332. gData.gameData.init_coin = false;
  333. if (gData.gameData.addHb > 0) {
  334. let add = Math.round(gData.gameData.addHb / 100);
  335. gData.gameData.addHb = 0;
  336. if (add > 0) {
  337. this.lbl_addHb.string = "+" + add.toString();
  338. cc.Tween.stopAllByTarget(this.node_addHb);
  339. this.node_addHb.active = true;
  340. this.node_addHb.scale = 0;
  341. cc.tween(this.node_addHb).to(0.1, { scale: 1 }).delay(1.5).call(() => {
  342. this.node_addHb.active = false;
  343. }).start();
  344. }
  345. }
  346. }
  347. private async initHead() {
  348. //let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
  349. //this.img_head.spriteFrame = new cc.SpriteFrame(result);
  350. }
  351. isRefreshTask = false;
  352. private changeTaskUI() {
  353. //cc.tween(this.lbl_task.node).to(0.1, { scale: 1.2 }).to(0.1, { scale: 1 }).start();
  354. if (!this.isRefreshTask) {
  355. this.isRefreshTask = true;
  356. cc.tween(this.lbl_task.node).delay(0.6).to(0.1, { scale: 1.2 }).to(0.1, { scale: 1 }).call(() => {
  357. if (gData.gameData.playerProp.userFarmTaskInfo) {
  358. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  359. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  360. this.lbl_task.string = `<b><color=#8D4D32>进行${count}次生产</c><color=#D73D25>(${com}/${count})</color></b>`
  361. if (com >= count) {
  362. this.node_hand.active = true;
  363. } else {
  364. this.node_hand.active = false;
  365. }
  366. // if (gData.gameData.playerProp.completeFarmTaskTimes < 1) {
  367. // mk.tip.pop("百元红包进度+1");
  368. // }
  369. this.isRefreshTask = false;
  370. }
  371. }).start();
  372. }
  373. gData.gameData.init_task = false;
  374. }
  375. private async initFarmExpUI() {
  376. let preLv = parseInt(this.lbl_farmLevel.string);
  377. let curLevel = gData.gameData.playerProp.gradeLevel;
  378. this.lbl_farmLevel.string = curLevel.toString();
  379. //升级
  380. if (curLevel > preLv) {
  381. mk.ui.openPanel('game/prefab/uiPanel/LevelUpPanel');
  382. }
  383. if (gData.gameData.configs.UpgradeReward.length > curLevel) {
  384. let needExp = gData.gameData.configs.UpgradeReward[curLevel].exp - gData.gameData.configs.UpgradeReward[curLevel - 1].exp;
  385. let curExp = gData.gameData.playerProp.farmExpValue - gData.gameData.configs.UpgradeReward[curLevel - 1].exp;
  386. this.sp_levelPer.fillRange = curExp / needExp;
  387. }
  388. let nameIndex = 1;
  389. if (gData.gameData.playerProp.farmGradeData) {
  390. let data = gData.gameData.playerProp.farmGradeData.farmGradeRewardList;
  391. if (data) {
  392. let len = data.length;
  393. for (let i = 0; i != len; ++i) {
  394. if (gData.gameData.playerProp.farmExpValue >= data[i].expMax) {
  395. nameIndex = i + 1;
  396. }
  397. }
  398. }
  399. }
  400. gData.gameData.playerProp.farmGradeName = nameIndex;
  401. this.sp_gradeName.spriteFrame = await mk.loader.load('module/gradeReward/texture/name' + nameIndex, cc.SpriteFrame);
  402. gData.gameData.init_expLevel = false;
  403. }
  404. private initCashProBar() {
  405. let minMoney = gData.walletCashOutData.getMinCanCashMoney();
  406. if (!minMoney) {
  407. console.warn('未获取到当前最小提现金额');
  408. this.pro_tixian.node.parent.active = false;
  409. return;
  410. }
  411. this.pro_tixian.node.parent.active = true;
  412. let per = gData.gameData.playerProp.redMoney * 0.01 / minMoney;
  413. if (per > 1) {
  414. per = 1;
  415. }
  416. this.pro_tixian.fillRange = per;
  417. this.lbl_cashPro.string = `${Math.floor(per * 100)}%`;
  418. if (per == 1) {
  419. this.btn_cashOutGold.getComponent(cc.Animation).play();
  420. }
  421. else {
  422. this.btn_cashOutGold.getComponent(cc.Animation).setCurrentTime(0);
  423. this.btn_cashOutGold.getComponent(cc.Animation).stop();
  424. }
  425. }
  426. private initBankProBar() {
  427. if (!gData.safeDepositBoxData.currentRichBankCashTaskIndex || gData.safeDepositBoxData.isStartBankTask) {
  428. this.pro_bank.node.parent.active = false;
  429. }
  430. else {
  431. this.pro_bank.node.parent.active = true;
  432. let config = gData.safeDepositBoxData.getBankTaskIndexExtra();
  433. let money = config.money
  434. let showMoney = Math.floor(money / 100) > 0 ? (money / 100) + "" : (money / 100).toFixed(2)
  435. let putinMoney: number = gData.safeDepositBoxData.richBankCashAmount
  436. if (putinMoney == null || putinMoney == undefined) {
  437. putinMoney = 0
  438. }
  439. let per = (putinMoney * 0.01) / parseFloat(showMoney);
  440. if (per > 1) {
  441. per = 1;
  442. }
  443. this.pro_bank.fillRange = per;
  444. this.lbl_bankPro.string = `${Math.floor(per * 100)}%`
  445. }
  446. }
  447. /**
  448. * 初始化红点
  449. */
  450. private initRedPoint() {
  451. let showSign = gData.sign.redPoint()
  452. this.nodeRedPoint.node_sign.active = showSign;
  453. this.nodeRedPoint.node_turnable.active = gData.turnable.leftTimes > 0;
  454. let isShow = false;
  455. let data = gData.gameData.playerProp.farmGradeData.farmGradeRewardList;
  456. if (data) {
  457. let len = data.length;
  458. for (let i = 0; i != len; ++i) {
  459. if (data[i].status == 1) {
  460. isShow = true;
  461. break;
  462. }
  463. }
  464. }
  465. this.nodeRedPoint.node_gradeReward.active = isShow;
  466. gData.gameData.init_red_point = false;
  467. }
  468. /**
  469. * 自动打开面板
  470. * - isAutoOpenPanel 1自动开 2不自动开 其他不处理
  471. */
  472. private autoOpenPanel() {
  473. if (!gData.gameData.isNewPlayer()) {
  474. mk.ui.openPanel('module/pigBank/pigBank');
  475. gData.gameData.setProp(GameProp.isAutoOpenPanel, 1)
  476. }
  477. }
  478. /**
  479. * 开始运行弱引导
  480. */
  481. private runGuideWeak() {
  482. gData.guideWeakData.enable = true;
  483. }
  484. private async initCanPlantInfo() {
  485. gData.gameData.init_makeInfo = false;
  486. if (gData.gameData.nextCanProduct) {
  487. let iconPath = '';
  488. let namePath = '';
  489. if (gData.gameData.nextCanProduct.tab == ProductType.nzw) {
  490. iconPath = "game/coregame/texture/plant_icons/plantIcon_";
  491. namePath = "game/coregame/texture/plant_icons/nameIcon/plant_name_";
  492. }
  493. else if (gData.gameData.nextCanProduct.tab == ProductType.dw) {
  494. iconPath = 'game/coregame/texture/factory_icons/factory_';
  495. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  496. }
  497. else {
  498. iconPath = 'game/coregame/texture/factory_icons/factory_';
  499. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  500. }
  501. this.icon_plant.spriteFrame = await mk.loader.load(iconPath + gData.gameData.nextCanProduct.picture, cc.SpriteFrame);
  502. this.icon_plantName.spriteFrame = await mk.loader.load(namePath + gData.gameData.nextCanProduct.picture, cc.SpriteFrame);
  503. }
  504. }
  505. private initLeftTimes() {
  506. this.lbl_leftTimes.string = `${gData.gameData.leftTimes}/${gData.gameData.maxTimes}`;
  507. if (gData.gameData.leftTimes < gData.gameData.maxTimes) {
  508. this.lastTimeSpan = parseInt(mk.storage.getStorage('lastTimeSpan'));
  509. if (!this.lastTimeSpan) {
  510. this.lastTimeSpan = Date.now();
  511. mk.storage.setStorage('lastTimeSpan', this.lastTimeSpan);
  512. }
  513. }
  514. else {
  515. this.lastTimeSpan = 0;
  516. mk.storage.setStorage('lastTimeSpan', this.lastTimeSpan);
  517. }
  518. gData.gameData.init_leftTimes = false;
  519. }
  520. private onCount() {
  521. }
  522. /** 点击互推 */
  523. public onClickHuTui() {
  524. mk.data.sendDataEvent(DataEventId.button_click, "互推icon");
  525. gData.moreGame.userBehaveLog(4, gData.moreGame.placement_id, gData.moreGame.nebulaAppId);
  526. }
  527. /** 点击福利 */
  528. public onClickFuli() {
  529. if (gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >= gData.gameData.welfareOpenLimit) {
  530. mk.ui.openPanel('module/blessingBag/blessingBag');
  531. mk.data.sendDataEvent(DataEventId.button_click, "福利icon");
  532. let isClickIcon = mk.storage.getStorage("clickBlessIcon")
  533. if (!isClickIcon) {
  534. JsbSystem.addJGTags("点击过福利icon");
  535. mk.storage.setStorage("clickBlessIcon", 1);
  536. }
  537. } else {
  538. mk.tip.pop(`订单提现${gData.gameData.welfareOpenLimit}次后开启`);
  539. }
  540. }
  541. /** 点击漂浮红包 */
  542. public onClickQipaoRedBag(event) {
  543. mk.audio.playEffect("button");
  544. mk.data.sendDataEvent(DataEventId.button_click, "飘浮红包icon");
  545. mk.ad.videoAdType = VideoAdType.video_init_13;
  546. // mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  547. gData.adData.curSelQipao = event.target;
  548. gData.adData.curRedBagAdFun = AdFun.bubble;
  549. mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  550. }
  551. /** 点击红包提现 */
  552. public onClickRedBagCash() {
  553. mk.data.sendDataEvent(DataEventId.button_click, "常规提现-提现icon");
  554. }
  555. /** */
  556. public onClickTurntable() {
  557. mk.data.sendDataEvent(DataEventId.button_click, "抽奖icon");
  558. mk.console.logSingle('VVVV ', 'onClickTurntable');
  559. }
  560. /** 点击签到 */
  561. public onClickSign() {
  562. mk.data.sendDataEvent(DataEventId.button_click, "签到icon");
  563. mk.console.logSingle('VVVV ', 'onClickSign');
  564. }
  565. /** 点击账单提现 */
  566. public onClickCashOutBill() {
  567. mk.data.sendDataEvent(DataEventId.button_click, "提现账单icon");
  568. }
  569. /**点击分享 */
  570. public onClickShare() {
  571. mk.data.sendDataEvent(DataEventId.button_click, "邀请icon");
  572. if (!gData.loginData.isAuth) {
  573. // JsbSystem.WxAuth();
  574. mk.ui.openPanel('module/authUI/authUI');
  575. return;
  576. }
  577. JsbSystem.shareInviteUrl(gData.gameData.shareUrl, gData.gameData.shareTitle, gData.gameData.shareDes, gData.gameData.shareImgUrl);
  578. }
  579. /** 点击农场等级奖励 */
  580. public onClickGradeReward() {
  581. mk.data.sendDataEvent(DataEventId.button_click, "农场等级领奖按钮");
  582. }
  583. /** 点击红包币提现 */
  584. public onClickWalletCash() {
  585. mk.data.sendDataEvent(DataEventId.button_click, "红包币提现按钮");
  586. }
  587. /** 点击任务 */
  588. public onClickTask() {
  589. mk.data.sendDataEvent(DataEventId.button_click, "任务红包icon");
  590. }
  591. /** 点击种植 */
  592. public async onClickPlant() {
  593. mk.audio.playEffect("button");
  594. if (gData.gameData.leftTimes <= 0) {
  595. // mk.tip.pop('生产次数不足');
  596. // if(!mk.guide.isGuiding())
  597. // {
  598. // mk.ui.openPanel('module/speedUpUI/productReward');
  599. // }
  600. let str = gData.gameData.prohibitProductionAd[gData.loginData.userChannel].split(",");
  601. if (str[1 - gData.loginData.isMatched] == "1") {
  602. if (gData.gameData.playerProp.curProductionAdTimes >= gData.gameData.productionAdMaxTimes) {
  603. mk.tip.pop('今日领取生产次数已达上限!');
  604. return;
  605. }
  606. }
  607. mk.ui.openPanel('module/speedUpUI/productReward');
  608. return;
  609. }
  610. if (gData.gameData.isProducting) {
  611. //mk.tip.pop('点击太快了');
  612. return;
  613. }
  614. let flyRed = await gData.gameData.makeProduct();
  615. //任务红包刷新逻辑
  616. if (flyRed) {
  617. //mk.audio.playEffect('redmoney');
  618. if (gData.gameData.playerProp.userFarmTaskInfo) {
  619. let com = gData.gameData.playerProp.userFarmTaskInfo.completeCount;
  620. let count = gData.gameData.playerProp.userFarmTaskInfo.taskCount;
  621. let addAni = cc.instantiate(this.ani_add3);
  622. addAni.parent = this.ani_add3.parent;
  623. addAni.getComponent(cc.Label).string = `百元红包:${com}/${count}`;
  624. cc.tween(addAni).call(() => {
  625. addAni.opacity = 255;
  626. }).by(0.8, { y: 100 }).to(0.4, { opacity: 0 }).call(() => {
  627. addAni.destroy();
  628. }).start();
  629. }
  630. this.dpFlyRedAni();
  631. }
  632. mk.data.sendDataEvent(DataEventId.button_click, "一键生产按钮");
  633. }
  634. public dpFlyRedAni(starPos: cc.Vec2 = null) {
  635. if (starPos) {
  636. if (this.node_orderHb && this.node_orderHb.parent) {
  637. // let pos = this.node_taskHb.parent.convertToWorldSpaceAR(this.node_taskHb.getPosition());
  638. let pos = this.node_orderHb.parent.convertToWorldSpaceAR(this.node_orderHb.getPosition());
  639. mk.fly.PlayCoinAnim(1, 5, starPos, pos, () => {
  640. //gData.gameData.init_task = true;
  641. }, 0.8);
  642. } else {
  643. //gData.gameData.init_task = true;
  644. }
  645. } else {
  646. if (this.node_taskHb && this.node_taskHb.parent && this.btn_product) {
  647. let pos = this.node_taskHb.parent.convertToWorldSpaceAR(this.node_taskHb.getPosition());
  648. mk.fly.PlayCoinAnim(1, 5, this.btn_product, pos, () => {
  649. //gData.gameData.init_task = true;
  650. }, 0.8);
  651. } else {
  652. //gData.gameData.init_task = true;
  653. }
  654. }
  655. }
  656. public doFlyExpAni(exp: number, startPos: cc.Node, data) {
  657. // let pos = this.lbl_farmLevel.node.parent.convertToWorldSpaceAR(this.lbl_farmLevel.node.getPosition());
  658. //飞向农舍
  659. let nongshe = cc.find('Canvas/主容器/coregame/MapIconGroup/农舍');
  660. let pos = nongshe.parent.convertToWorldSpaceAR(nongshe.getPosition());
  661. let num = 3;
  662. // if (gData.harvestData.isMatchOrder) {
  663. // num = 3;
  664. // }
  665. mk.fly.PlayCoinAnim(2, num, startPos, pos, () => {
  666. if (gData.gameData.playerProp.gradeLevel < data.farmLevel) {
  667. gData.gameData.playerProp.gradeLevel = data.farmLevel;
  668. mk.data.setTAEventUser(0, 'farm_lv', gData.gameData.playerProp.gradeLevel);
  669. }
  670. gData.gameData.playerProp.farmExpValue = data.userExp;
  671. gData.gameData.playerProp.farmGradeData = data.userFarmGrageRewardInfo;
  672. // gData.gameData.init_add = true;
  673. gData.gameData.init_red_point = true;
  674. this.playAdd(exp);
  675. }, 1.2)
  676. }
  677. public registerCallBack() {
  678. JsbSystem.callBack = null;
  679. JsbSystem.callBack = () => {
  680. mk.ui.openPanel('module/speedUpUI/productReward2');
  681. }
  682. }
  683. public playAdd(exp, type = 1) {
  684. if (type == 1) {
  685. // this.ani_add.node.getComponent(cc.Label).string = `+${exp}`;
  686. // this.ani_add.node.active = true;
  687. // this.ani_add.play();
  688. cc.Tween.stopAllByTarget(this.node_addExp);
  689. this.node_addExp.active = true;
  690. this.node_addExp.scale = 0;
  691. this.lbl_addExp.string = `+${exp}`;
  692. cc.tween(this.node_addExp).to(0.1, { scale: 1 }).delay(1.5).call(() => {
  693. this.node_addExp.active = false;
  694. }).start();
  695. } else {
  696. this.ani_add2.getComponent(cc.Label).string = `生产次数+${exp}`;
  697. cc.tween(this.ani_add2).delay(1.3).call(() => {
  698. this.ani_add2.opacity = 255;
  699. }).by(0.8, { y: 100 }).to(0.4, { opacity: 0 }).call(() => {
  700. this.ani_add2.y = this.posY;
  701. }).start();
  702. }
  703. // gData.gameData.init_add = false;
  704. }
  705. //图鉴部分logic
  706. public initRefreshEvent() {
  707. mk.event.register("initFarmMapUi", this.initFarmMapUi.bind(this), this);
  708. mk.event.register("refreshFarmMapUI", this.refreshFarmMapUI.bind(this), this);
  709. mk.event.register("moveUpAndDownFarmMapUI", this.moveUpAndDownFarmMapUI.bind(this), this);
  710. this.initFarmMapUi();
  711. this.showChangePart();
  712. }
  713. public moveUpAndDownFarmMapUI(isMoveUp) {
  714. cc.Tween.stopAllByTarget(this.node_farmMapUI);
  715. if (isMoveUp) {
  716. cc.tween(this.node_farmMapUI).to(0.2, { y: 540 }).start();
  717. } else {
  718. cc.tween(this.node_farmMapUI).to(0.2, { y: 240 }).start();
  719. }
  720. }
  721. public clickFarmMapUIBtn() {
  722. mk.audio.playEffect("button");
  723. mk.data.sendDataEvent(DataEventId.button_click, "图鉴浮窗icon");
  724. if (this.productType == ProductType.nzw) {
  725. if (gData.farmSystem.currSelectFarm) {
  726. if (gData.farmSystem.currSelectFarm.data.state != FarmState.Empty) {
  727. gData.farmSystem.currSelectFarm = null;
  728. let farms = gData.farmSystem.farms;
  729. for (let i = 0; i < farms.length; i++) {
  730. if (farms[i].data.state == FarmState.Empty) {
  731. gData.farmSystem.currSelectFarm = farms[i];
  732. break;
  733. }
  734. }
  735. if (!gData.farmSystem.currSelectFarm) {
  736. gData.farmSystem.currSelectFarm = farms[0];
  737. }
  738. }
  739. } else {
  740. let farms = gData.farmSystem.farms;
  741. for (let i = 0; i < farms.length; i++) {
  742. if (farms[i].data.state == FarmState.Empty) {
  743. gData.farmSystem.currSelectFarm = farms[i];
  744. break;
  745. }
  746. }
  747. if (!gData.farmSystem.currSelectFarm) {
  748. gData.farmSystem.currSelectFarm = farms[0];
  749. }
  750. }
  751. } else {
  752. let factorys = gData.factorySystem.factoryIcons;
  753. for (let i = 0; i != factorys.length; ++i) {
  754. if (factorys[i].tab == this.productType) {
  755. gData.factorySystem.currSelectFactory = factorys[i];
  756. break;
  757. }
  758. }
  759. }
  760. gData.plantData.openPanel(this.productType, 1, this.productIndex - 1);
  761. }
  762. private uiShowType = 3;
  763. private productType = ProductType.nzw;
  764. private productIndex = 0;
  765. public async initFarmMapUi() {
  766. // let plantPath = '';
  767. // let namePath = '';
  768. // if (gData.farmMapData.chooseType == ProductType.nzw) {
  769. // plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  770. // namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_';
  771. // }
  772. // else {
  773. // plantPath = 'game/coregame/texture/factory_icons/factory_';
  774. // namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  775. // }
  776. if (gData.gameData.funOpenData[12] == "0") {
  777. this.node_farmMapUI.active = false;
  778. return;
  779. }
  780. //1:有可领奖的,2:正在解锁,3:所有奖励都领取完
  781. this.uiShowType = 3;
  782. for (let key in ProductType) {
  783. let max = gData.gameData.getMaxProductExtra(ProductType[key]);
  784. if (max) {
  785. let list_data = gData.gameData.getProductArrByType(ProductType[key]);
  786. for (let i = 0; i != list_data.length; ++i) {
  787. let data = list_data[i];
  788. //剔除前三个农作物
  789. let extraCondition = true;
  790. if (ProductType[key] == ProductType.nzw) {
  791. extraCondition = (data.picture > 10003);
  792. }
  793. if (extraCondition && data.picture <= max) {
  794. let state = gData.gameData.getFarmMapRewardState(this.getIndex(data));
  795. if (state == 0) {
  796. this.uiShowType = 1;
  797. this.productType = ProductType[key];
  798. this.productIndex = i;
  799. this.node_farmMapGetReward.active = true;
  800. this.node_farmMapProduct.active = false;
  801. this.node_farmMapUI.active = true;
  802. this.node_farmMapUI.width = 320;
  803. //this.sp_farmMapIcon.spriteFrame = await mk.loader.load(plantPath + data.picture, cc.SpriteFrame);
  804. return;
  805. }
  806. } else if (data.picture - 1 == max && data.unlock == 1) {
  807. this.uiShowType = 2
  808. this.productType = ProductType[key];
  809. this.productIndex = i;
  810. this.node_farmMapGetReward.active = false;
  811. this.node_farmMapProduct.active = true;
  812. this.node_farmMapUI.active = true;
  813. let times = gData.gameData.getProductMakeTimesById(data.picture - 1);
  814. let plantName = gData.gameData.getProductMap(data.picture - 1).name;
  815. let des = this.getDesByType(data);
  816. let len = plantName.length;
  817. this.node_farmMapUI.width = 300 + (len - 2) * 20 + (len - 2) * 5;
  818. this.lbl_farmMapDes.string = `<color=#7E411F>${des}<color=#FF0000>${data.value}</c>次${plantName} <color=#FF0000>${times}</c>/${data.value}</color>`;
  819. //this.sp_farmMapIcon.spriteFrame = await mk.loader.load('module/farmMap/texture/gift', cc.SpriteFrame);
  820. return;
  821. }
  822. }
  823. }
  824. }
  825. if (this.uiShowType == 3) {
  826. this.node_farmMapUI.active = false;
  827. }
  828. }
  829. public refreshFarmMapUI() {
  830. if (this.uiShowType == 2) {
  831. let list_data = gData.gameData.getProductArrByType(this.productType);
  832. let data = list_data[this.productIndex];
  833. let times = gData.gameData.getProductMakeTimesById(data.picture - 1);
  834. let plantName = gData.gameData.getProductMap(data.picture - 1).name;
  835. let des = this.getDesByType(data);
  836. this.lbl_farmMapDes.string = `<color=#7E411F>${des}<color=#FF0000>${data.value}</c>次${plantName} <color=#FF0000>${times}</c>/${data.value}</color>`;
  837. }
  838. }
  839. private btnCD = 0;
  840. private startTimes = false;
  841. public clickGetFarmMapRewardBtn() {
  842. mk.audio.playEffect("button");
  843. if (!this.startTimes) {
  844. this.startTimes = true;
  845. this.btnCD = 0;
  846. } else {
  847. return;
  848. }
  849. mk.data.sendDataEvent(DataEventId.button_click, "图鉴浮窗icon");
  850. mk.audio.playEffect("button");
  851. mk.ad.videoAdType = VideoAdType.video_init_6;
  852. mk.ad.watchAd(async (success) => {
  853. if (success) {
  854. await gData.adData.watchVideo(AdFun.farmMap);
  855. if (gData.farmMapData.init_award) {
  856. gData.farmMapData.init_award = false;
  857. gData.reward.adData = gData.farmMapData.adData;
  858. mk.ui.openPanel('module/reward/reward');
  859. gData.farmMapData.isStateChange = true;
  860. let list_data = gData.gameData.getProductArrByType(this.productType);
  861. let data = list_data[this.productIndex];
  862. gData.gameData.setFarmMapRewardState(this.getIndexExtra(data), 1);
  863. this.initFarmMapUi();
  864. }
  865. }
  866. })
  867. }
  868. showChangePart() {
  869. //this.changePart.active = true
  870. let len = this.lbl_value.length;
  871. let len2 = this.lbl_redMoneyValue.length;
  872. this.schedule(() => {
  873. //图鉴部分
  874. for (var i = 0; i < len; i++) {
  875. let ran = Util.rnd(0, 9);
  876. this.lbl_value[i].string = `${ran}`;
  877. }
  878. //订单部分
  879. // for (var i = 0; i < len2; i++) {
  880. // let ran = Util.rnd(0, 9);
  881. // this.lbl_redMoneyValue[i].string = `${ran}`;
  882. // }
  883. }, 0.1)
  884. }
  885. getIndex(data) {
  886. let index: any = {};
  887. index.i = 0;
  888. index.j = 0;
  889. switch (data.tab) {
  890. case '农作物':
  891. index.i = 0;
  892. index.j = data.picture - 10001;
  893. break;
  894. case '动物':
  895. index.i = 1;
  896. index.j = data.picture - 20001;
  897. break;
  898. case '爆米花厂':
  899. index.i = 2;
  900. index.j = data.picture - 20004;
  901. break;
  902. case '糕点铺':
  903. index.i = 3;
  904. index.j = data.picture - 20013;
  905. break;
  906. case '制糖厂':
  907. index.i = 4;
  908. index.j = data.picture - 20010;
  909. break;
  910. case '炼乳厂':
  911. index.i = 5;
  912. index.j = data.picture - 20007;
  913. break;
  914. case '功夫面馆':
  915. index.i = 6;
  916. index.j = data.picture - 20025;
  917. break;
  918. case '快餐店':
  919. index.i = 7;
  920. index.j = data.picture - 20019;
  921. break;
  922. }
  923. return index;
  924. }
  925. getIndexExtra(data) {
  926. let index: any = {};
  927. index.i = 0;
  928. index.j = 0;
  929. switch (data.tab) {
  930. case '农作物':
  931. index.i = 0;
  932. index.j = data.picture - 10001;
  933. break;
  934. case '动物':
  935. index.i = 1;
  936. index.j = data.picture - 20001;
  937. break;
  938. case '爆米花厂':
  939. index.i = 2;
  940. index.j = data.picture - 20004;
  941. break;
  942. case '糕点铺':
  943. index.i = 3;
  944. index.j = data.picture - 20013;
  945. break;
  946. case '制糖厂':
  947. index.i = 4;
  948. index.j = data.picture - 20010;
  949. break;
  950. case '炼乳厂':
  951. index.i = 5;
  952. index.j = data.picture - 20007;
  953. break;
  954. case '功夫面馆':
  955. index.i = 6;
  956. index.j = data.picture - 20025;
  957. break;
  958. case '快餐店':
  959. index.i = 7;
  960. index.j = data.picture - 20019;
  961. break;
  962. }
  963. return index;
  964. }
  965. getDesByType(data) {
  966. let des = ''
  967. switch (data.tab) {
  968. case '农作物':
  969. des = '种植';
  970. break;
  971. case '动物':
  972. des = '养殖';
  973. break;
  974. case '爆米花厂':
  975. case '糕点铺':
  976. case '制糖厂':
  977. case '炼乳厂':
  978. case '功夫面馆':
  979. case '快餐店':
  980. des = '制作';
  981. break;
  982. }
  983. return des;
  984. }
  985. //订单部分
  986. private orderPicIdArray = [];
  987. private isGray = true;
  988. public async initOrderUI(init = true) {
  989. this.orderPicIdArray = [];
  990. this.isGray = true;
  991. let productJson = gData.gameData.configs.Product;
  992. let data = gData.gameData.playerProp.orderData;
  993. mk.console.logSingle('initOrderUI ', data);
  994. if (data) {
  995. //红包币
  996. if (gData.gameData.orderRewardType == 1) {
  997. this.lbl_orderRedMoney.string = data.redMoneyAddition / 100 + "";
  998. } else {
  999. this.lbl_addCash.string = (data.cashMoney / 100).toFixed(2);
  1000. }
  1001. let len = data.orderTaskList.length;
  1002. if (len == 3) {
  1003. let completeCount = 0;
  1004. for (let i = 0; i != len; ++i) {
  1005. let dataE = data.orderTaskList[i];
  1006. mk.console.logSingle('dataE ' + i, dataE);
  1007. if (dataE.Id <= productJson.length) {
  1008. let productData = productJson[dataE.Id - 1];
  1009. let plantPath = '';
  1010. let namePath = '';
  1011. if (productData.tab == ProductType.nzw) {
  1012. plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  1013. namePath = 'game/coregame/texture/plant_icons/nameIcon/plant_name_';
  1014. }
  1015. else {
  1016. plantPath = 'game/coregame/texture/factory_icons/factory_';
  1017. namePath = 'game/coregame/texture/factory_icons/factoryNams/factory_name_icon_';
  1018. }
  1019. if (dataE.completeCount >= dataE.taskCount) {
  1020. this.lbl_progress[i].node.active = false;
  1021. this.sp_mark[i].node.active = true;
  1022. ++completeCount;
  1023. } else {
  1024. this.lbl_progress[i].node.active = true;
  1025. this.sp_mark[i].node.active = false;
  1026. this.lbl_progress[i].string = `${dataE.completeCount}/${dataE.taskCount}`;
  1027. }
  1028. this.orderPicIdArray.push({ "ID": dataE.Id, "picID": productData.picture });
  1029. this.lbl_cropName[i].string = productData.name;
  1030. this.sp_cropIcon[i].spriteFrame = await mk.loader.load(plantPath + productData.picture, cc.SpriteFrame);
  1031. } else {
  1032. return;
  1033. }
  1034. }
  1035. if (completeCount >= 3) {
  1036. this.isGray = false;
  1037. this.node_getOrderReward.setGray(false, true);
  1038. this.node_getOrderReward.getComponent(cc.Animation).play();
  1039. this.node_orderHand.active = true;
  1040. } else {
  1041. this.isGray = true;
  1042. this.node_getOrderReward.setGray(true, true);
  1043. this.node_getOrderReward.getComponent(cc.Animation).setCurrentTime(0);
  1044. this.node_getOrderReward.getComponent(cc.Animation).stop();
  1045. this.node_orderHand.active = false;
  1046. }
  1047. }
  1048. }
  1049. }
  1050. public clickGetOrderRewardBtn() {
  1051. mk.audio.playEffect("button");
  1052. if (this.isGray) {
  1053. mk.tip.pop("完成订单即可提现");
  1054. } else {
  1055. //smk.tip.pop("测试使用==订单领奖");
  1056. //mk.data.sendDataEvent(DataEventId.button_click, "订单领奖按钮");
  1057. if (!gData.loginData.isAuth) {
  1058. // JsbSystem.WxAuth();
  1059. gData.gameData.authUIType = 0;
  1060. mk.ui.openPanel('module/authUI/authUI');
  1061. return;
  1062. }
  1063. mk.data.sendDataEvent(DataEventId.Sundry, "订单领奖按钮");
  1064. this.getOrderReward();
  1065. }
  1066. }
  1067. public getIsCanGetOrderReward() {
  1068. return !this.isGray;
  1069. }
  1070. public async getOrderReward(isGame = true) {
  1071. // mk.ui.openPanel('game/prefab/uiPanel/OrderDrawPanel');
  1072. // return;
  1073. //现金提现
  1074. if (gData.gameData.orderRewardType == 2) {
  1075. if (cc.sys.isNative) {
  1076. if (!gData.loginData.isAuth) {
  1077. // JsbSystem.WxAuth();
  1078. gData.gameData.authUIType = 0;
  1079. mk.ui.openPanel('module/authUI/authUI');
  1080. return;
  1081. }
  1082. }
  1083. let response = await mk.http.sendData('orderTaskTree/receiveRewardCash', {});
  1084. if (response.errcode != 0) {
  1085. if (response.errcode == 405) {
  1086. mk.tip.pop("今日提现额度已到上限,请明天再提现");
  1087. mk.data.sendDataEvent(DataEventId.cashLimit, "提现触发上限");
  1088. }
  1089. return null;
  1090. }
  1091. let addMoney = gData.gameData.playerProp.orderData.cashMoney;
  1092. gData.gameData.playerProp.orderData = response.data.userOrderTaskInfo;
  1093. gData.safeDepositBoxData.setCashRecordDataLength();
  1094. //处理提现逻辑
  1095. gData.cashPro.isOrderCashOut = true;
  1096. gData.cashPro.callBack = this.getRewardCallBack.bind(this);
  1097. gData.receiptNotice.receip_rmb = addMoney;
  1098. mk.ui.openPanel('module/newNotice/newNotice');
  1099. //[FC]新增 当前订单种植数据清空
  1100. gData.gameData.setProp(GameProp.orderPlantTimes, {});
  1101. if (isGame) {
  1102. this.node_crop.forEach((v) => {
  1103. v.active = false;
  1104. })
  1105. this.node_orderHbIcon.active = false;
  1106. this.node_getOrderReward.node.active = false;
  1107. } else {
  1108. this.showRefreshLogic();
  1109. }
  1110. } else {
  1111. let data = {};
  1112. let response = await mk.http.sendData('orderTaskTree/receiveReward', data);
  1113. if (response.errcode != 0) {
  1114. return null;
  1115. }
  1116. // let addMoney = gData.gameData.playerProp.orderData.redMoneyAddition;
  1117. let addMoney = response.data.orderRedMoney;
  1118. console.log("====[response.data.orderRedMoney", response.data.orderRedMoney);
  1119. gData.gameData.playerProp.orderData = response.data.userOrderTaskInfo;
  1120. //处理红包币逻辑
  1121. gData.reward.closeUICallBack = this.getRewardCallBack.bind(this);
  1122. gData.reward.adData = { videoRedMoney: { videoRewardList: null } };
  1123. gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: 1, rewardNum: addMoney }]
  1124. mk.ui.openPanel('module/reward/reward');
  1125. //[FC]新增 当前订单种植数据清空
  1126. gData.gameData.setProp(GameProp.orderPlantTimes, {});
  1127. if (isGame) {
  1128. gData.gameData.isDoOrderRefreshAni = true;
  1129. this.node_crop.forEach((v) => {
  1130. v.active = false;
  1131. })
  1132. this.node_orderHbIcon.active = false;
  1133. this.node_getOrderReward.node.active = false;
  1134. } else {
  1135. this.showRefreshLogic();
  1136. }
  1137. }
  1138. }
  1139. //停止农民产红包币
  1140. isStopFarm = false;
  1141. public getRewardCallBack() {
  1142. this.node_extraOrderUi.active = true;
  1143. this.node_bgUi.scale = 0;
  1144. cc.tween(this.node_bgUi).to(0.4, { scale: 1.4 }).start();
  1145. if (gData.gameData.funOpenData[1] == '1') {
  1146. gData.gameData.funOpenData[1] = "0";
  1147. this.isStopFarm = true;
  1148. }
  1149. }
  1150. public showRefreshLogic() {
  1151. gData.gameData.isDoOrderRefreshAni = false;
  1152. this.node_crop.forEach((v) => {
  1153. v.active = true;
  1154. })
  1155. this.node_orderHbIcon.active = false;
  1156. this.node_getOrderReward.node.active = true;
  1157. this.initOrderUI(false);
  1158. this.showTips();
  1159. gData.gameData.init_order = true;
  1160. gData.gameData.checkTaskFinishUnLock();
  1161. if (gData.gameData.orderRewardType == 2) {
  1162. gData.gameData.richBankTeachTag = true;
  1163. gData.safeDepositBoxData.updateQipao();
  1164. }
  1165. gData.cashNormal.getRecord();
  1166. if (this.isStopFarm) {
  1167. this.isStopFarm = false;
  1168. gData.gameData.funOpenData[1] = '1';
  1169. }
  1170. }
  1171. showTips() {
  1172. mk.tip.pop("提现成功,订单已刷新");
  1173. }
  1174. async doCropFlyLogic(plantId: number, farmNode: cc.Node = null, parentNode: cc.Node = null, isNzw = false) {
  1175. if (gData.gameData.funOpenData[11] == "0" || !gData.gameData.playerProp.orderData) {
  1176. return;
  1177. }
  1178. for (let i = 0; i != this.orderPicIdArray.length; ++i) {
  1179. if (plantId == this.orderPicIdArray[i].picID) {
  1180. let data = gData.gameData.playerProp.orderData.orderTaskList[i];
  1181. if (data.completeCount < data.taskCount) {
  1182. // let plantPath = '';
  1183. // if (isNzw) {
  1184. // plantPath = 'game/coregame/texture/plant_icons/plantIcon_';
  1185. // }
  1186. // else {
  1187. // plantPath = 'game/coregame/texture/factory_icons/factory_';
  1188. // }
  1189. await this.updataOrderProgress(this.orderPicIdArray[i].ID);
  1190. //await mk.time.WaitForSeconds(1);
  1191. // for (let index = 0; index != 4; ++index) {
  1192. // let crop = await mk.pool.getPrefab('game/prefab/crop');
  1193. // let sf = await mk.loader.load(plantPath + plantId, cc.SpriteFrame);
  1194. // crop.getComponent(cc.Sprite).spriteFrame = sf;
  1195. // mk.fly.playFlyAniExtra(farmNode, this.sp_cropIcon[i].node, crop, 0.6, index * 0.2, () => {
  1196. // if (index == 2) {
  1197. // this.doFlyOrderAni(i);
  1198. // }
  1199. // });
  1200. // }
  1201. if (farmNode) {
  1202. let addAni = cc.instantiate(this.ani_add4);
  1203. addAni.parent = farmNode;
  1204. addAni.setPosition(cc.Vec2.ZERO);
  1205. cc.tween(addAni).call(() => {
  1206. addAni.opacity = 255;
  1207. }).by(0.8, { y: 100 }).to(0.4, { opacity: 0 }).call(() => {
  1208. addAni.destroy();
  1209. }).start();
  1210. }
  1211. }
  1212. this.doFlyOrderAni(i, parentNode);
  1213. break;
  1214. }
  1215. }
  1216. }
  1217. public doFlyOrderAni(index, parentNode = null) {
  1218. let orderData = gData.gameData.playerProp.orderData;
  1219. if (orderData) {
  1220. let isComplete = true;
  1221. let len = orderData.orderTaskList.length;
  1222. for (let i = 0; i != len; ++i) {
  1223. let dataE = orderData.orderTaskList;
  1224. if (dataE[i].completeCount < dataE[i].taskCount) {
  1225. isComplete = false;
  1226. break;
  1227. }
  1228. }
  1229. if (isComplete) {
  1230. this.isGray = false;
  1231. this.node_getOrderReward.setGray(false, true);
  1232. this.node_getOrderReward.getComponent(cc.Animation).play();
  1233. this.node_orderHand.active = true;
  1234. mk.ui.closeAllUI();
  1235. if (gData.gameData.funOpenData[11] == "1") {
  1236. let isGuide = mk.guide.open(12);
  1237. if (!isGuide) {
  1238. mk.tip.pop("订单已完成,快提现吧!");
  1239. }
  1240. } else {
  1241. mk.tip.pop("订单已完成,快提现吧!");
  1242. }
  1243. }
  1244. if (parentNode) {
  1245. let pos = this.node_orderHb.parent.convertToWorldSpaceAR(this.node_orderHb.getPosition());
  1246. mk.fly.PlayCoinAnim(1, 5, parentNode, pos, () => {
  1247. //this.refreshOrderUI(index);
  1248. if (gData.gameData.orderRewardType == 1) {
  1249. cc.tween(this.node_showRedMoney).to(0.1, { scale: 1.3 }).to(0.1, { scale: 1 }).start();
  1250. }
  1251. }, 0.8);
  1252. } else {
  1253. let pos = this.node_orderHb.parent.convertToWorldSpaceAR(this.node_orderHb.getPosition());
  1254. mk.fly.PlayCoinAnim(1, 5, this.btn_product, pos, () => {
  1255. //this.refreshOrderUI(index);
  1256. if (gData.gameData.orderRewardType == 1) {
  1257. cc.tween(this.node_showRedMoney).to(0.1, { scale: 1.3 }).to(0.1, { scale: 1 }).start();
  1258. }
  1259. }, 0.8);
  1260. }
  1261. this.refreshOrderUI(index);
  1262. // if (!isComplet && this.node_orderHb && this.btn_product) {
  1263. // let pos = this.node_orderHb.parent.convertToWorldSpaceAR(this.node_orderHb.getPosition());
  1264. // mk.fly.PlayCoinAnim(1, 5, this.btn_product, pos, () => {
  1265. // this.lbl_progress[index].string = `${dataE.completeCount}/${dataE.taskCount}`;
  1266. // cc.Tween.stopAllByTarget(this.lbl_progress[index].node);
  1267. // cc.tween(this.lbl_progress[index].node).to(0.1, { scale: 1.4 }).to(0.05, { scale: 1 }).start();
  1268. // }, 0.8);
  1269. // }
  1270. }
  1271. }
  1272. public refreshOrderUI(index) {
  1273. let orderData = gData.gameData.playerProp.orderData;
  1274. let dataE = orderData.orderTaskList[index];
  1275. if (dataE) {
  1276. if (dataE.completeCount == dataE.taskCount) {
  1277. this.lbl_progress[index].node.active = false;
  1278. this.sp_mark[index].node.active = true;
  1279. } else {
  1280. this.lbl_progress[index].string = `${dataE.completeCount}/${dataE.taskCount}`;
  1281. cc.Tween.stopAllByTarget(this.lbl_progress[index].node);
  1282. cc.tween(this.lbl_progress[index].node).to(0.1, { scale: 1.4 }).to(0.05, { scale: 1 }).start();
  1283. }
  1284. }
  1285. }
  1286. public async updataOrderProgress(id) {
  1287. let data = { "id": id };
  1288. let response = await mk.http.sendData('orderTaskTree/updateUserOrderTaskInfo', data);
  1289. if (response.errcode != 0) {
  1290. return null;
  1291. }
  1292. gData.gameData.playerProp.orderData = response.data.userOrderTaskInfo;
  1293. }
  1294. public clickOrderUIBtn() {
  1295. mk.audio.playEffect("button");
  1296. // //test
  1297. // mk.ui.openPanel('game/prefab/uiPanel/OrderDrawPanel');
  1298. // return
  1299. if (mk.guide.isGuiding()) {
  1300. // let data = gData.gameData.playerProp.orderData;
  1301. // let orderData = data.orderTaskList;
  1302. // let copyData = gData.gameData.playerProp.copyOrderData;
  1303. // if (data && orderData && copyData) {
  1304. // let num = 0;
  1305. // for (let i = 0; i != orderData.length; ++i) {
  1306. // num += (orderData[i].taskCount - copyData[i])
  1307. // }
  1308. // mk.guide.curDes = `<color=8A4312><color=ff0000>继续生产</c>${num}次,很快就\n可以完成订单了!</color>`;
  1309. // //mk.guide.open(2, curDes);
  1310. // }
  1311. // let leftTimes = gData.gameData.leftTimes;
  1312. // if(leftTimes > 0)
  1313. // {
  1314. // mk.guide.curDes = `<color=8A4312><color=ff0000>继续生产${leftTimes}次</c>,很快就\n可以完成订单了!</color>`;
  1315. // }
  1316. } else {
  1317. if (this.isGray) {
  1318. mk.tip.pop("完成订单即可提现");
  1319. } else {
  1320. mk.tip.pop("订单已完成,快提现吧");
  1321. }
  1322. }
  1323. }
  1324. public judgeContinueTeach() {
  1325. // let data = gData.gameData.playerProp.orderData;
  1326. // let orderData = data.orderTaskList;
  1327. // let copyData = gData.gameData.playerProp.copyOrderData;
  1328. // if (data && orderData && copyData) {
  1329. // let num = 0;
  1330. // for (let i = 0; i != orderData.length; ++i) {
  1331. // num += (orderData[i].taskCount - copyData[i])
  1332. // }
  1333. // mk.guide.curDes = `<color=8A4312>继续生产${num}次,很快就\n可以提现了!</color>`;
  1334. // if (num > 0) {
  1335. // return true;
  1336. // } else {
  1337. // return false;
  1338. // }
  1339. // } else {
  1340. // return false;
  1341. // }
  1342. let leftTimes = gData.gameData.leftTimes;
  1343. if (leftTimes > 0) {
  1344. mk.guide.curDes = `<color=8A4312><color=ff0000>继续生产${leftTimes}次</c>,很快就\n可以完成订单了!</color>`;
  1345. return true;
  1346. } else {
  1347. // if(gData.gameData.moveMapNode)
  1348. // {
  1349. // gData.gameData.moveMapNode.move(new cc.Vec3(0, -370, 0));
  1350. // }
  1351. return false;
  1352. }
  1353. }
  1354. public initGuideEvent() {
  1355. if (gData.farmSystem._lastSeletFarm) {
  1356. gData.farmSystem._lastSeletFarm.clickGuideBtn();
  1357. }
  1358. }
  1359. //富翁银行
  1360. /** 点击富翁银行 */
  1361. public async onClickSafeDepositBox() {
  1362. mk.audio.playEffect('button');
  1363. let plantTimes = gData.gameData.getProp(GameProp.plantTimes);
  1364. if (plantTimes == undefined) {
  1365. plantTimes = 0;
  1366. }
  1367. if (plantTimes < gData.gameData.showRichBankIconLimit) {
  1368. mk.tip.pop(`种植${gData.gameData.showRichBankIconLimit}次后开启`)
  1369. return;
  1370. }
  1371. if (!gData.loginData.isAuth) {
  1372. mk.ui.openPanel('module/authUI/authUI');
  1373. return;
  1374. }
  1375. console.log(`currentRichBankCashTaskIndex 22======== ${gData.safeDepositBoxData.currentRichBankCashTaskIndex}`);
  1376. if (gData.safeDepositBoxData.currentRichBankCashTaskIndex) {
  1377. mk.ui.openPanel("module/safeDepositBox/SafeDepositBox");
  1378. mk.data.sendDataEvent(DataEventId.button_click, "富翁银行icon");
  1379. }
  1380. }
  1381. isAdd = true;
  1382. public setJGTags() {
  1383. //JsbSystem.addJGTags("富翁银行任务");
  1384. //let curDes = `<color=8A4312>再生产${23}次,就可以收获\n啦,完成订单立即<color=ff0000>提现</color>!</color>`;
  1385. //mk.guide.open(11, curDes);
  1386. if (this.isAdd) {
  1387. this.isAdd = false;
  1388. JsbSystem.addJGTags("开玩笑");
  1389. } else {
  1390. this.isAdd = true;
  1391. JsbSystem.deleteTags("开玩笑");
  1392. }
  1393. }
  1394. public getAllTags() {
  1395. JsbSystem.getAllTags();
  1396. }
  1397. }