|
|
@@ -1,6 +1,7 @@
|
|
|
import Util from "../../before/util/Util";
|
|
|
import FunBtns from "../game/FunBtns";
|
|
|
import Game from "../game/Game";
|
|
|
+import { StorageKey } from "./StorageData";
|
|
|
|
|
|
/**
|
|
|
* @description 游戏核心玩法数据
|
|
|
@@ -211,6 +212,7 @@ export class GameData {
|
|
|
this.playerProp.speedUpLeftTimes = res_data.speedUpLeftTimes;
|
|
|
this.playerProp.completeFarmTaskTimes = res_data.completeFarmTaskTimes;
|
|
|
this.playerProp.orderData = res_data.userOrderTaskInfo;
|
|
|
+ this.cloneOrderData();
|
|
|
|
|
|
mk.data.setTAUserID(gData.loginData.uin);
|
|
|
mk.data.setTAEventUser(0, 'logindays_total', this.playerProp.loginDays);
|
|
|
@@ -242,6 +244,42 @@ export class GameData {
|
|
|
// this.playerProp.completeFarmTaskTimes = 3;
|
|
|
}
|
|
|
|
|
|
+ public cloneOrderData(isRefresh = false) {
|
|
|
+
|
|
|
+ let value = mk.storage.getStorage(StorageKey.copyOrderData);
|
|
|
+ if (value && !isRefresh) {
|
|
|
+ this.playerProp.copyOrderData = value;
|
|
|
+ } else {
|
|
|
+ if (this.playerProp.orderData) {
|
|
|
+ this.playerProp.copyOrderData = [];
|
|
|
+ let len = this.playerProp.orderData.orderTaskList.length;
|
|
|
+ for (let i = 0; i != len; ++i) {
|
|
|
+ this.playerProp.copyOrderData.push(this.playerProp.orderData.orderTaskList[i].completeCount);
|
|
|
+ }
|
|
|
+ mk.storage.setStorage(StorageKey.copyOrderData, this.playerProp.copyOrderData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public updateOrderTaskCopyData(id: number) {
|
|
|
+ if (this.playerProp.orderData) {
|
|
|
+ let productJson = this.configs.Product;
|
|
|
+ let orderData = this.playerProp.orderData.orderTaskList;
|
|
|
+ let len = orderData.length;
|
|
|
+ for (let i = 0; i != len; ++i) {
|
|
|
+ let dataE = orderData[i];
|
|
|
+ if (dataE.Id <= productJson.length) {
|
|
|
+ let productData = productJson[dataE.Id - 1];
|
|
|
+ if (productData.picture == id) {
|
|
|
+ this.playerProp.copyOrderData[i]++;
|
|
|
+ mk.storage.setStorage(StorageKey.copyOrderData, this.playerProp.copyOrderData);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存单个数据
|
|
|
*/
|
|
|
@@ -446,69 +484,63 @@ export class GameData {
|
|
|
public needFreshArr = [];
|
|
|
|
|
|
/** 随机获取可种植物品 */
|
|
|
- getRandomPlantConfig(out?:any) {
|
|
|
+ getRandomPlantConfig(out?: any) {
|
|
|
let id = 0;
|
|
|
let isNoHaveCurTab = true;
|
|
|
let isNoAllComplete = false;
|
|
|
let isOrderDataInvalid = false;
|
|
|
+ let isMatchSuccess = false;
|
|
|
let productType = [];
|
|
|
let animalId = [];
|
|
|
- let data = gData.gameData.playerProp.orderData;
|
|
|
- let orderData = data.orderTaskList;
|
|
|
- if(data && orderData)
|
|
|
- {
|
|
|
- let productJson = gData.gameData.configs.Product;
|
|
|
- for(let i = 0; i != orderData.length; ++i)
|
|
|
- {
|
|
|
+ let data = this.playerProp.orderData;
|
|
|
+ let orderData = data.orderTaskList;
|
|
|
+ if (data && orderData) {
|
|
|
+ let productJson = this.configs.Product;
|
|
|
+ for (let i = 0; i != orderData.length; ++i) {
|
|
|
let dataE = orderData[i];
|
|
|
- if (dataE.completeCount < dataE.taskCount && dataE.Id <= productJson.length) {
|
|
|
-
|
|
|
- isNoAllComplete = true;
|
|
|
- let productData = productJson[dataE.Id - 1];
|
|
|
- if(productData.tab == ProductType.nzw)
|
|
|
- {
|
|
|
- let max = gData.gameData.getMaxProduct(ProductType.nzw);
|
|
|
- if(productData.picture <= max)
|
|
|
- {
|
|
|
- id = productData.picture;
|
|
|
- isNoHaveCurTab = false;
|
|
|
- mk.console.logSingle("getRandomPlantConfig=>", id);
|
|
|
- break;
|
|
|
- }
|
|
|
- }else if(productData.tab == ProductType.dw)
|
|
|
- {
|
|
|
- animalId.push(productData.picture);
|
|
|
- }else{
|
|
|
- productType.push(productData.tab);
|
|
|
+ if (this.playerProp.copyOrderData[i] < dataE.taskCount) {
|
|
|
+ if (dataE.Id <= productJson.length) {
|
|
|
+ isNoAllComplete = true;
|
|
|
+ let productData = productJson[dataE.Id - 1];
|
|
|
+ if (productData.tab == ProductType.nzw) {
|
|
|
+ let max = this.getMaxProduct(ProductType.nzw);
|
|
|
+ if (productData.picture <= max) {
|
|
|
+ id = productData.picture;
|
|
|
+ isNoHaveCurTab = false;
|
|
|
+ isMatchSuccess = true;
|
|
|
+ mk.console.logSingle("getRandomPlantConfig=>", id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else if (productData.tab == ProductType.dw) {
|
|
|
+ animalId.push(productData.picture);
|
|
|
+ } else {
|
|
|
+ productType.push(productData.tab);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ isOrderDataInvalid = true;
|
|
|
+ console.log("订单数据有问题,随机id");
|
|
|
+ break;
|
|
|
}
|
|
|
-
|
|
|
- }else{
|
|
|
- isOrderDataInvalid = true;
|
|
|
- id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
|
|
|
- console.log("订单数据有问题,随机id");
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
|
|
|
- console.log("订单数据没有合适的物品");
|
|
|
- }else{
|
|
|
+ if (!isMatchSuccess) {
|
|
|
+ id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
|
|
|
+ console.log("订单数据没有匹配成功");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
isOrderDataInvalid = true;
|
|
|
id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
|
|
|
console.log("订单数据为null");
|
|
|
}
|
|
|
|
|
|
- if(isOrderDataInvalid)
|
|
|
- {
|
|
|
+ if (isOrderDataInvalid) {
|
|
|
return this.getProductMap(id);
|
|
|
- }else{
|
|
|
- if(isNoHaveCurTab)
|
|
|
- {
|
|
|
- if(isNoAllComplete)
|
|
|
- {
|
|
|
+ } else {
|
|
|
+ if (isNoHaveCurTab) {
|
|
|
+ if (isNoAllComplete) {
|
|
|
let isHaveEmpty = false;
|
|
|
- for(let i = 0; i != productType.length; ++i)
|
|
|
- {
|
|
|
+ for (let i = 0; i != productType.length; ++i) {
|
|
|
let factoryIcon = gData.factorySystem.factoryIcons;
|
|
|
let len = factoryIcon.length;
|
|
|
for (var j = 0; j < len; j++) {
|
|
|
@@ -516,19 +548,17 @@ export class GameData {
|
|
|
if (tab == productType[j] && factoryIcon[j].data.state == FactroyState.Empty) {
|
|
|
isHaveEmpty = true;
|
|
|
out.state = 1;
|
|
|
- break;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(!isHaveEmpty)
|
|
|
- {
|
|
|
- for(let i = 0; i != animalId.length; ++i)
|
|
|
- {
|
|
|
+ if (!isHaveEmpty) {
|
|
|
+ for (let i = 0; i != animalId.length; ++i) {
|
|
|
let pastureIcon = gData.pastureSystem.pastureIcons;
|
|
|
let len = pastureIcon.length;
|
|
|
for (var j = 0; j < len; j++) {
|
|
|
- if (pastureIcon[j].data.productID ==animalId[i] && pastureIcon[j].data.state == PastureState.Empty) {
|
|
|
+ if (pastureIcon[j].data.productID == animalId[i] && pastureIcon[j].data.state == PastureState.Empty) {
|
|
|
isHaveEmpty = true;
|
|
|
out.state = 2;
|
|
|
break;
|
|
|
@@ -537,19 +567,18 @@ export class GameData {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if(isHaveEmpty)
|
|
|
- {
|
|
|
+ if (isHaveEmpty) {
|
|
|
return null;
|
|
|
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return this.getProductMap(id);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return this.getProductMap(id);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return this.getProductMap(id);
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
|
|
|
@@ -583,7 +612,7 @@ export class GameData {
|
|
|
return;
|
|
|
}
|
|
|
//-1无效,1:工厂有空位,2:饲养厂有空位
|
|
|
- let haveEmpty = {state: -1};
|
|
|
+ let haveEmpty = { state: -1 };
|
|
|
let next = gData.farmSystem.selectNextFarm(haveEmpty, sel);
|
|
|
if (!next) {
|
|
|
let next1 = gData.pastureSystem.nextPasture(haveEmpty);
|
|
|
@@ -1490,6 +1519,8 @@ class PlayerProp {
|
|
|
|
|
|
/** 订单数据 */
|
|
|
orderData = null;
|
|
|
+ /** 临时订单数据, 只用于种植优先选择作用 */
|
|
|
+ copyOrderData = null;
|
|
|
}
|
|
|
|
|
|
/**
|