|
|
@@ -77,7 +77,7 @@ export class GameData {
|
|
|
mk.console.logSingle("getInfoCrypt", response.data);
|
|
|
this.initPlayerProp(response.data)
|
|
|
this.initProps(response.data.gameUserData);
|
|
|
-
|
|
|
+
|
|
|
data = {};
|
|
|
response = await mk.http.sendData('user/adShowConfig', data);
|
|
|
if (response.errcode != 0) {
|
|
|
@@ -109,8 +109,8 @@ export class GameData {
|
|
|
this.configs = data;
|
|
|
this.funOpenData = this.configs.ServerConfig.Functionswitch.split(",");
|
|
|
|
|
|
+ //从服务器解析配置
|
|
|
// this.setProductMapFromJson();
|
|
|
- gData.configData.loadConfig();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -135,9 +135,6 @@ export class GameData {
|
|
|
this.gameData.versioncfg = res_data.versioncfg;
|
|
|
this.gameData.isFirstRedMoney = res_data.isFirstRedMoney;
|
|
|
gData.adData.watchNumToday = res_data.dayVideoTimesForRedMoney == null ? 0 : res_data.dayVideoTimesForRedMoney;
|
|
|
-
|
|
|
- this.setFramDataMapByServer();
|
|
|
- this.setPastureDataMapByServer();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -173,7 +170,7 @@ export class GameData {
|
|
|
}
|
|
|
|
|
|
/** 获取属性 */
|
|
|
- public getProp(key: GameProp): number {
|
|
|
+ public getProp(key: GameProp): any {
|
|
|
if (this.props == null) {
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -202,6 +199,10 @@ export class GameData {
|
|
|
for (let key in data) {
|
|
|
this.props.set(parseInt(key), data[key]);
|
|
|
}
|
|
|
+
|
|
|
+ this.setFramDataMapByServer();
|
|
|
+ this.setPastureDataMapByServer();
|
|
|
+ this.setFactoryDataMapByServer();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -291,21 +292,8 @@ 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);
|
|
|
+ let id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
|
|
|
return this.getProductMap(id);
|
|
|
}
|
|
|
|
|
|
@@ -334,6 +322,11 @@ export class GameData {
|
|
|
|
|
|
/** 服务器数据设置到本地 */
|
|
|
public setFramDataMapByServer() {
|
|
|
+ this._farmData = this.getProp(GameProp.farmData);
|
|
|
+ if (!this._farmData) {
|
|
|
+ this._farmData = [];
|
|
|
+ }
|
|
|
+
|
|
|
let len = this._farmData.length;
|
|
|
//新玩家初始化农田数据
|
|
|
if (len < 18) {
|
|
|
@@ -355,7 +348,7 @@ export class GameData {
|
|
|
}
|
|
|
|
|
|
//第一次初始数据
|
|
|
- this.setMaxPlantID(this._maxCanPlantID);
|
|
|
+ this.setMaxProduct(ProductType.nzw, 10003);
|
|
|
//更新到服务器
|
|
|
this.setProp(GameProp.farmData, this._farmData);
|
|
|
}
|
|
|
@@ -378,15 +371,15 @@ export class GameData {
|
|
|
let productJson = gData.configData.configMap.get('product');
|
|
|
let len = productJson.length;
|
|
|
let product = null;
|
|
|
+ let tab = '';
|
|
|
+ let arr = [];
|
|
|
for (var i = 0; i < len; i++) {
|
|
|
product = productJson[i];
|
|
|
- this._productMap.set(product['picture'], product);
|
|
|
- let arr = [];
|
|
|
- if (this.getProductArrByType(product['tab'])) {
|
|
|
- arr = this.getProductArrByType(product['tab']);
|
|
|
- }
|
|
|
- else {
|
|
|
- this._productTypeMap.set(product['tab'], arr);
|
|
|
+ this._productMap.set(product.picture, product);
|
|
|
+ if (tab != product.tab) {
|
|
|
+ arr = [];
|
|
|
+ this._productTypeMap.set(product.tab, arr);
|
|
|
+ tab = product.tab;
|
|
|
}
|
|
|
arr.push(product);
|
|
|
}
|
|
|
@@ -430,13 +423,14 @@ export class GameData {
|
|
|
this._productMakeTimesData.push(data);
|
|
|
}
|
|
|
|
|
|
- //设置可种植植物最大id
|
|
|
+ //设置可种植/生产最大id
|
|
|
let nextID = id + 1;
|
|
|
+ let curConfig = this.getProductMap(id);
|
|
|
let nextConfig = this.getProductMap(nextID);
|
|
|
if (nextConfig) {
|
|
|
- if (nextConfig.tab == '农作物' && nextID > this.getMaxPlantID()) {
|
|
|
+ if (nextConfig.tab == curConfig.tab && nextID > this.getMaxProduct(curConfig.tab)) {
|
|
|
if (nextConfig.unlock == 1 && nextConfig.value <= times) {
|
|
|
- this.setMaxPlantID(nextID);
|
|
|
+ this.setMaxProduct(curConfig.tab, nextID);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -483,6 +477,11 @@ export class GameData {
|
|
|
|
|
|
/** 服务器数据设置到本地 */
|
|
|
public setPastureDataMapByServer() {
|
|
|
+ this._pastureData = this.getProp(GameProp.pastureData);
|
|
|
+ if (!this._pastureData) {
|
|
|
+ this._pastureData = [];
|
|
|
+ }
|
|
|
+
|
|
|
let len = this._pastureData.length;
|
|
|
//新玩家初始化农田数据
|
|
|
if (len < 3) {
|
|
|
@@ -491,7 +490,9 @@ export class GameData {
|
|
|
let id = 30001;
|
|
|
let data = null;
|
|
|
for (var i = 0; i < len1; i++) {
|
|
|
- data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
|
|
|
+ // data = { id: id, state: PastureState.Lock, productID: arr[i].picture, growSpan: 0 };
|
|
|
+ //test
|
|
|
+ data = { id: id, state: PastureState.Empty, productID: arr[i].picture, growSpan: 0 };
|
|
|
this._pastureData.push(data);
|
|
|
this._pastureDataMap.set(id, data);
|
|
|
id++;
|
|
|
@@ -505,6 +506,122 @@ export class GameData {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //------------- 工厂数据-----------
|
|
|
+ /** 工厂数据 服务器数据 */
|
|
|
+ private _factoryData = [];
|
|
|
+ /** 工厂字典 本地数据,方便操作*/
|
|
|
+ private _factoryDataMap: Map<number, any> = new Map();
|
|
|
+
|
|
|
+ public setFactoryDataMap(id, data, sendToServer = true) {
|
|
|
+ this._factoryDataMap.set(id, data);
|
|
|
+ let len = this._factoryData.length;
|
|
|
+ for (var i = 0; i < len; i++) {
|
|
|
+ if (this._factoryData[i].id == id) {
|
|
|
+ this._factoryData[i].state = data.state;
|
|
|
+ this._factoryData[i].productID = data.productID;
|
|
|
+ this._factoryData[i].growSpan = data.growSpan;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.needFreshArr.push(id);
|
|
|
+ //更新到服务器
|
|
|
+ if (sendToServer) {
|
|
|
+ this.setProp(GameProp.factoryData, this._factoryData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public getFactoryDataMap(id) {
|
|
|
+ return this._factoryDataMap.get(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 服务器数据设置到本地 */
|
|
|
+ public setFactoryDataMapByServer() {
|
|
|
+ this._factoryData = this.getProp(GameProp.factoryData);
|
|
|
+ if (!this._factoryData) {
|
|
|
+ this._factoryData = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ let len = this._factoryData.length;
|
|
|
+ //新玩家初始化农田数据
|
|
|
+ if (len < 3) {
|
|
|
+ let id = 30004;
|
|
|
+ let data = null;
|
|
|
+ for (var i = 0; i < 6; i++) {
|
|
|
+ // data = { id: id, state: FactroyState.Lock, productID: 0, growSpan: 0 };
|
|
|
+ //test
|
|
|
+ data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
|
|
|
+ this._factoryData.push(data);
|
|
|
+ this._factoryDataMap.set(id, data);
|
|
|
+ id++;
|
|
|
+ }
|
|
|
+ //更新到服务器
|
|
|
+ this.setProp(GameProp.factoryData, this._factoryData);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for (var i = 0; i < len; i++) {
|
|
|
+ this._factoryDataMap.set(this._factoryData[i].id, this._factoryData[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /** 最大可种植/生产商品数组 */
|
|
|
+ private _maxProduct = [];
|
|
|
+
|
|
|
+ public getMaxProduct(tab) {
|
|
|
+ if (this._maxProduct) {
|
|
|
+ let len = this._maxProduct.length;
|
|
|
+ let data = null;
|
|
|
+ for (var i = 0; i < len; i++) {
|
|
|
+ data = this._maxProduct[i];
|
|
|
+ if (data.tab == tab) {
|
|
|
+ return data.productID;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public setMaxProduct(tab, id) {
|
|
|
+ if (!this._maxProduct) {
|
|
|
+ this._maxProduct = [];
|
|
|
+ }
|
|
|
+ let len = this._maxProduct.length;
|
|
|
+ let data = null;
|
|
|
+ let has = false;
|
|
|
+ for (var i = 0; i < len; i++) {
|
|
|
+ data = this._maxProduct[i];
|
|
|
+ if (data.tab == tab) {
|
|
|
+ data.productID = id;
|
|
|
+ has = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!has) {
|
|
|
+ data = { tab: tab, productID: id };
|
|
|
+ this._maxProduct.push(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setProp(GameProp.maxProduct, this._maxProduct);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 农场升级时检查最大可种植/生产商品 */
|
|
|
+ public checkMaxProduct() {
|
|
|
+ for (var key in ProductType) {
|
|
|
+ let tab = ProductType[key]
|
|
|
+ let curmax = this.getMaxProduct(tab);
|
|
|
+ if (!curmax) {
|
|
|
+ let configArr = this.getProductArrByType(tab);
|
|
|
+ if (gData.gameData.gameData.gradeLevel >= configArr[0].value && this.getMaxProduct(tab) <= configArr[0].value) {
|
|
|
+ this.setMaxProduct(tab, configArr[0].picture);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -534,12 +651,17 @@ export enum GameProp {
|
|
|
/** 产品生产次数 */
|
|
|
productMakeTimes = 12,
|
|
|
|
|
|
- /** 最大可种植id */
|
|
|
- maxCanPlantID = 13,
|
|
|
+ /** 可生产最大产品字典 */
|
|
|
+ maxProduct = 13,
|
|
|
|
|
|
/** 养殖场数据 */
|
|
|
pastureData = 14,
|
|
|
|
|
|
+ /** 工厂数据 */
|
|
|
+ factoryData = 15,
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/** ------------------ 转盘数据 ------------------------------ */
|
|
|
turnable_leftTimes = 20,
|
|
|
@@ -665,7 +787,7 @@ class PlayerProp {
|
|
|
isFirstRedMoney = 0;
|
|
|
|
|
|
//玩家等级
|
|
|
- gradeLevel = 1;
|
|
|
+ gradeLevel = 6;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -869,6 +991,7 @@ export enum ProductType {
|
|
|
bmhc = '爆米花厂',
|
|
|
gdp = '糕点铺',
|
|
|
ztc = '制糖厂',
|
|
|
+ lrc = '炼乳厂',
|
|
|
gfmg = '功夫面馆',
|
|
|
kcd = '快餐店'
|
|
|
}
|
|
|
@@ -878,4 +1001,12 @@ export enum AnimalState {
|
|
|
Hanger,
|
|
|
Eat,
|
|
|
Wait
|
|
|
+}
|
|
|
+
|
|
|
+export enum FactroyState {
|
|
|
+ Lock,
|
|
|
+ Empty,
|
|
|
+ Producting,
|
|
|
+ Ripe,
|
|
|
+ Sick
|
|
|
}
|