|
|
@@ -54,6 +54,13 @@ export default class Game extends cc.Component {
|
|
|
icon_plant: cc.Sprite = null;
|
|
|
@property({ type: cc.Sprite, displayName: "要种植植物名称" })
|
|
|
icon_plantName: cc.Sprite = null;
|
|
|
+ @property({ type: cc.Label, displayName: "种植次数文本" })
|
|
|
+ lbl_leftTimes: cc.Label = null;
|
|
|
+
|
|
|
+ /** 是否开始增加次数倒计时 */
|
|
|
+ private leftTimesScheduleOn = false;
|
|
|
+ private lastTimeSpan = 0;
|
|
|
+ private span = 0;
|
|
|
|
|
|
/** 可种植植物配置 */
|
|
|
private canPlantConfig = null;
|
|
|
@@ -61,6 +68,7 @@ export default class Game extends cc.Component {
|
|
|
onLoad() {
|
|
|
gData.gameData.gameStyle = this;
|
|
|
mk.ui.closePanel("login");
|
|
|
+ this.span = gData.gameData.ProductionRecovery * 60 * 1000;
|
|
|
gData.gameData.checkMaxProduct();
|
|
|
this.loadMain();
|
|
|
}
|
|
|
@@ -73,6 +81,7 @@ export default class Game extends cc.Component {
|
|
|
this.autoOpenPanel();
|
|
|
this.runGuideWeak();
|
|
|
this.initCanPlantInfo();
|
|
|
+ this.initLeftTimes();
|
|
|
|
|
|
mk.guide.open(1);
|
|
|
// // 测试代码
|
|
|
@@ -119,6 +128,24 @@ export default class Game extends cc.Component {
|
|
|
if (gData.gameData.init_red_point) {
|
|
|
this.initRedPoint();
|
|
|
}
|
|
|
+
|
|
|
+ if (gData.gameData.init_leftTimes) {
|
|
|
+ this.initLeftTimes();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gData.gameData.leftTimes < gData.gameData.maxTimes && this.lastTimeSpan != 0) {
|
|
|
+ let pass = Date.now() - this.lastTimeSpan;
|
|
|
+ if (pass >= this.span) {
|
|
|
+ let add = Math.floor(pass / this.span);
|
|
|
+ this.lastTimeSpan += (add * this.span);
|
|
|
+ mk.storage.setStorage('lastTimeSpan', this.lastTimeSpan);
|
|
|
+ gData.gameData.leftTimes += add;
|
|
|
+ gData.gameData.leftTimes = (gData.gameData.leftTimes > gData.gameData.maxTimes ? gData.gameData.maxTimes : gData.gameData.leftTimes);
|
|
|
+ gData.gameData.setProp(GameProp.leftTimes, gData.gameData.leftTimes);
|
|
|
+
|
|
|
+ gData.gameData.init_leftTimes = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
lateUpdate() {
|
|
|
gData.gameData.init_head = false;
|
|
|
@@ -206,6 +233,33 @@ export default class Game extends cc.Component {
|
|
|
this.icon_plantName.spriteFrame = await mk.loader.load("game/coregame/texture/plant_icons/nameIcon/plant_name_" + this.canPlantConfig.picture, cc.SpriteFrame);
|
|
|
}
|
|
|
|
|
|
+ private initLeftTimes() {
|
|
|
+ this.lbl_leftTimes.string = `${gData.gameData.leftTimes}/${gData.gameData.maxTimes}`;
|
|
|
+ if (gData.gameData.leftTimes < gData.gameData.maxTimes) {
|
|
|
+ this.lastTimeSpan = parseInt(mk.storage.getStorage('lastTimeSpan'));
|
|
|
+ if (!this.lastTimeSpan) {
|
|
|
+ this.lastTimeSpan = Date.now();
|
|
|
+ mk.storage.setStorage('lastTimeSpan', this.lastTimeSpan);
|
|
|
+ }
|
|
|
+
|
|
|
+ // if (!this.leftTimesScheduleOn) {
|
|
|
+ // this.schedule(this.onCount, 1);
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // this.unschedule(this.onCount);
|
|
|
+ // this.leftTimesScheduleOn = false;
|
|
|
+ this.lastTimeSpan = 0;
|
|
|
+ mk.storage.setStorage('lastTimeSpan', this.lastTimeSpan);
|
|
|
+ }
|
|
|
+
|
|
|
+ gData.gameData.init_leftTimes = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private onCount() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
//测试道具获取效果
|
|
|
private testFly() {
|
|
|
mk.fly.PlayCoinAnim(1, 20, null, cc.v2(0, 0));
|
|
|
@@ -277,6 +331,11 @@ export default class Game extends cc.Component {
|
|
|
|
|
|
/** 点击种植 */
|
|
|
public onClickPlant() {
|
|
|
+ if (gData.gameData.leftTimes <= 0) {
|
|
|
+ mk.tip.pop('生产次数不足');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (!gData.farmSystem.currSelectFarm) {
|
|
|
let next = gData.farmSystem.selectNextFarm();
|
|
|
if (!next) {
|