Sfoglia il codice sorgente

随机种植部分代码

kaka 4 anni fa
parent
commit
acf04efb10

+ 1 - 0
assets/script/before/main/FarmIcon.ts

@@ -164,6 +164,7 @@ export class FarmIcon extends cc.Component {
         this._state = FarmState.Ripe;
         this.data.state = FarmState.Ripe;
         gData.gameData.setFarmDataMap(this.configID, this.data);
+        gData.gameData.addProductMakeTimesById(this.plantID);
     }
 
     private async onPlantAnimationFinish() {

+ 40 - 4
assets/script/game/data/GameData.ts

@@ -1,3 +1,4 @@
+import Util from "../../before/util/Util";
 import FunBtns from "../game/FunBtns";
 import Game from "../game/Game";
 
@@ -281,6 +282,24 @@ export class GameData {
     //刷新农田
     public needFreshArr = [];
 
+    /** 最大可种植植物ID */
+    private _maxCanPlantID = 10003;
+
+    /** 设置最大可种植id 用于判断随机种植植物*/
+    setMaxPlantID(id) {
+        this._maxCanPlantID = id;
+        this.setProp(GameProp.maxCanPlantID, this._maxCanPlantID);
+    }
+
+    getMaxPlantID() {
+        return this._maxCanPlantID;
+    }
+
+    getRandomPlantConfig() {
+        let id = Util.rnd(10001, this._maxCanPlantID);
+        return this.getProductMap(id);
+    }
+
     public setFarmDataMap(id, data, sendToServer = true) {
         this._farmDataMap.set(id, data);
         let len = this._farmData.length;
@@ -294,10 +313,10 @@ export class GameData {
         }
 
         this.needFreshArr.push(id);
-        // //更新到服务器
-        // if (sendToServer) {
-        //     this.setProp(GameProp.farmData, this._farmData);
-        // }
+        //更新到服务器
+        if (sendToServer) {
+            this.setProp(GameProp.farmData, this._farmData);
+        }
     }
 
     public getFarmDataMap(id) {
@@ -325,6 +344,9 @@ export class GameData {
                 this._farmDataMap.set(id, data);
                 id++;
             }
+
+            //第一次初始数据
+            this.setMaxPlantID(this._maxCanPlantID);
             //更新到服务器
             this.setProp(GameProp.farmData, this._farmData);
         }
@@ -399,6 +421,17 @@ export class GameData {
             this._productMakeTimesData.push(data);
         }
 
+        //设置可种植植物最大id
+        let nextID = id + 1;
+        let nextConfig = this.getProductMap(nextID);
+        if (nextConfig) {
+            if (nextConfig.tab == '农作物' && nextID > this.getMaxPlantID()) {
+                if (nextConfig.unlock == 1 && nextConfig.value <= times) {
+                    this.setMaxPlantID(nextID);
+                }
+            }
+        }
+
         this.setProp(GameProp.productMakeTimes, this._productMakeTimesData);
     }
 
@@ -438,6 +471,9 @@ export enum GameProp {
     /** 产品生产次数 */
     productMakeTimes = 12,
 
+    /** 最大可种植id */
+    maxCanPlantID = 13,
+
 
     /** ------------------ 转盘数据 ------------------------------ */
     turnable_leftTimes = 20,

+ 13 - 0
assets/script/game/game/Game.ts

@@ -54,6 +54,8 @@ export default class Game extends cc.Component {
     @property({ type: RedPoinNode, displayName: "红点组" })
     nodeRedPoint: RedPoinNode = null;
 
+    /** 可种植植物配置 */
+    private canPlantConfig = null;
 
     onLoad() {
         gData.gameData.gameStyle = this;
@@ -68,6 +70,7 @@ export default class Game extends cc.Component {
         this.initInfo();
         this.autoOpenPanel();
         this.runGuideWeak();
+        this.initCanPlantInfo();
 
         mk.guide.open(1);
         // // 测试代码
@@ -214,6 +217,11 @@ export default class Game extends cc.Component {
         gData.guideWeakData.enable = true;
     }
 
+    private initCanPlantInfo() {
+        this.canPlantConfig = gData.gameData.getRandomPlantConfig();
+        
+    }
+
     //测试道具获取效果
     private testFly() {
         mk.fly.PlayCoinAnim(1, 20, null, cc.v2(0, 0));
@@ -282,5 +290,10 @@ export default class Game extends cc.Component {
         }
         JsbSystem.sharePic();
     }
+
+    /** 点击种植 */
+    public onClickPlant() {
+
+    }
 }