| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- import { BitmapFontC } from "../../game/component/BitmapFontC";
- import { GameProp, ProductType } from "../../game/data/GameData";
- import Util from "../util/Util";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export class FarmCountDown extends cc.Component {
- @property({ type: cc.Component.EventHandler, tooltip: "成熟回调" }) onRiped: cc.Component.EventHandler = null;
- @property({ type: cc.Component.EventHandler, tooltip: "生虫回调" }) onSick: cc.Component.EventHandler = null;
- @property({ type: cc.Component.EventHandler, tooltip: "加速按钮回调" }) onSpeedButton: cc.Component.EventHandler = null;
- @property({ type: cc.Node, tooltip: "常驻计时器组" }) normalGroup: cc.Node = null;
- @property({ type: cc.Sprite, tooltip: "常驻进度条" }) normalProgress: cc.Sprite = null;
- @property({ type: BitmapFontC, tooltip: "常驻计时" }) normalCount: BitmapFontC = null;
- @property({ type: cc.Node, tooltip: "可收获图标" }) ripedIcon: cc.Node = null;
- @property({ type: cc.Node, tooltip: "生病图标" }) sickIcon: cc.Node = null;
- @property({ type: cc.Sprite, tooltip: "生病图标" }) clockIcon: cc.Sprite = null;
- private counting = false;
- /**成熟时间戳 */
- private ripeTime = 0;
- /**总时长 */
- private totleTime = 0;
- private isDataed = false;
- private isRipeInit = false;
- private productConfig = null;
- public async setData(data) {
- if (!this.isDataed) {
- this.isDataed = true;
- this.productConfig = gData.gameData.getProductMap(data.productID);
- this.ripeTime = data.growSpan;
- this.totleTime = this.productConfig.time;
- this.normalGroup.active = true;
- this.sickIcon.active = false;
- this.counting = true;
- this.normalCount.string = '';
- this.normalProgress.fillRange = 0;
- if (this.clockIcon) {
- let plantPath = 'game/coregame/texture/factory_icons/factory_';
- this.clockIcon.spriteFrame = await mk.loader.load(plantPath + this.productConfig.picture, cc.SpriteFrame);
- }
- }
- }
- update() {
- let now = Date.now();
- if (this.counting && now < this.ripeTime) {
- let timeString = Util.ParseTime2Format(Math.floor((this.ripeTime - now) * 0.001), 'm:s');
- this.normalCount.string = timeString;
- this.normalProgress.fillRange = 1 - ((this.ripeTime - now) / (this.totleTime * 1000));
- } else if (this.counting && now > this.ripeTime) {
- if (!this.isRipeInit) {
- this.isRipeInit = true;
- console.log('onRiped start');
- this.riped();
- }
- }
- }
- public cleanRiped(): void {
- this.isRipeInit = false;
- this.isDataed = false;
- this.ripedIcon.active = false;
- this.sickIcon.active = false;
- }
- public async onSpeed() {
- //通信 暂时注释
- // if (g.userData.diamond >= 25) {
- // let result = await this.http.send("/api/product/quickProduct", { buildID: this.buildID });
- // if (result.code == 0) {
- // platform.reportThinking("diamond_decrease", JSON.stringify({ previous_number: g.userData.diamond, decrease_number: result.data, current_number: g.userData.diamond - result.data, reasons: "speed" }));
- // g.userData.diamond -= result.data;
- // this.riped();
- // this.selectGroup.active = false;
- // this.onSpeedButton && this.onSpeedButton.emit(null);
- // return;
- // }
- // }
- // WindowManager.showTips("钻石不足");
- }
- /** 设置显示
- * @param state 0 生虫 1 成熟
- */
- async setState(state) {
- this.normalProgress.fillRange = 0;
- this.normalCount.string = '';
- this.normalGroup.active = false;
- if (state == 0) {
- this.sickIcon.active = true;
- this.ripedIcon.active = false;
- }
- else if (state == 1) {
- this.sickIcon.active = false;
- this.ripedIcon.active = true;
- }
- }
- public riped(sendToServer = true): void {
- this.counting = false;
- this.normalGroup.active = false;
- let sick = false;
- let cashTimes = gData.gameData.getProp(GameProp.cashTimes);
- if (gData.gameData.playerProp.orderData && gData.gameData.playerProp.orderData.overTimes >= 1 && cashTimes >= gData.gameData.insectAutoShowLimit && Math.random() < parseFloat(gData.gameData.configs.ServerConfig.StopProduction)) {
- if (this.productConfig.tab == ProductType.nzw) {
- if (gData.gameData.RawInsectCurArr[0] < parseInt(gData.gameData.RawInsectArr[0])) {
- sick = true;
- gData.gameData.RawInsectCurArr[0]++;
- }
- }
- else if (this.productConfig.tab == ProductType.dw) {
- if (gData.gameData.RawInsectCurArr[1] < parseInt(gData.gameData.RawInsectArr[1])) {
- sick = true;
- gData.gameData.RawInsectCurArr[1]++;
- }
- }
- else if (gData.gameData.RawInsectCurArr[2] < parseInt(gData.gameData.RawInsectArr[2])) {
- sick = true;
- gData.gameData.RawInsectCurArr[2]++;
- }
- }
- if (sick) {
- console.log('onRiped ' + 1111);
- this.sickIcon.active = true;
- this.onSick && this.onSick.emit([sendToServer]);
- }
- else {
- console.log('onRiped ' + 2222);
- this.ripedIcon.active = true;
- this.onRiped && this.onRiped.emit([sendToServer]);
- }
- }
- }
|