| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190 |
- var reGameStates = require('GameStates');
- var AConfig = require('../Config');
- import utils from "../Network/netUtils";
- import GameNet from "../Network/GameNet"
- import gameToast from "../Network/gameToast"
- //全局数据类
- cc.Class({
- extends: cc.Component,
- properties: {
- //记录全部道路的index
- GameData_highwayIndex: {
- default: [],
- type: [cc.Integer],
- visible: false,
- serializable: false,
- },
- //记录建筑物存储的信息
- GameData_buildings: {
- default: [],
- visible: false,
- serializable: false,
- },
- HighWayPrefabs: cc.Prefab,
- //MyMapNode
- //建筑物的节点
- BuildingsParent: {
- default: null,
- type: cc.Node,
- },
- ManageUI: {
- default: null,
- type: cc.Node,
- },
- GameVersion: {
- default: -1,
- type: cc.Integer,
- },
- //读取数据
- readData: {
- default: null,
- visible: false,
- },
- /**
- * 接口
- * todo cnt和snb 由钱包读取
- */
- CNT: {
- default: 0,
- visible: false,
- },
- SNB: {
- default: 0,
- visible: false,
- },
- //读取的土地文件
- ConfigLand: {
- default: null,
- visible: false
- }
- },
- onLoad() {
- //初始化GameData全局变量
- GlobalD.GameData = this;
- this.GameConfig();
- },
- GameConfig() {
- this.AddBuildingCost = 5;
- this.RemoveBuildingCost = 5;
- //
- this.Dapp = {
- UserInfo: null
- }
- },
- start() {
- this._tiledMap = GlobalD.TiledMap._tiledMap;
- //调用初始化dapp
- this.isDebugMode(GlobalD.dapp);
- },
- /**
- * 根据 不存在dapp 的话,使用本地测试
- * @param {*} bInit
- */
- isDebugMode: function (bInit) {
- if (bInit) {
- //读取网络数据
- try {
- GlobalD.dapp.cntBalance().then((cntBalance) => {
- //会延迟返回
- console.log("获取cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
- GlobalD.GameData.SetCNT(cntBalance);
- });
- } catch (err) {
- console.error(err) // 初始化失败,运行环境不是钱包环境
- }
- //登录时候已经初始化好snb了
- this.SNB = GlobalD.UserInfo.snb;
- this.readData = userData.readData;
- // cc.log('playerPullInfo 读取到数据?:', this.readData)
- this.InitNextworkData();
- this.InitSceneInfo();
- // 自动存储数据
- /**
- * todo 如果退出游戏,触发一次存储。
- */
- this.AutoSaveData = function () {
- this.pushData(true);
- };
- this.schedule(this.AutoSaveData, 20);
- } else {
- // 清除
- cc.log("本地数据重新开始,并且不初始化");
- // this.onClearAllData();
- this.Init();
- this.InitSceneInfo();
- this.AutoSaveData = function () {
- this.pushData(false);
- };
- this.schedule(this.AutoSaveData, 20);
- }
- },
- getData: function () {
- //如果开局没有读取到网络数据,就这里初始化
- if (userData.readData == null) {
- cc.log("本地数据:", cc.sys.localStorage.getItem('userdata'));
- let userdata = cc.sys.localStorage.getItem('userdata');
- if (userdata) {
- this.readData = JSON.parse(userdata);
- }
- this.Init();
- this.InitSceneInfo();
- } else {
- this.readData = userData.readData;
- cc.log('读取到数据?:', this.readData)
- this.Init();
- this.InitSceneInfo();
- }
- },
- InitSceneInfo() {
- //根据顺序生成
- //初始化时间ui
- cc.find("GameNode/ManageTimer").getComponent('ManageTimer').Init();
- //初始化金钱ui,gold,diamond, cnt,snb,
- cc.find("GameNode/ManageGolden").getComponent('ManageGolden').InitManageGlodenUI();
- // //初始化地图物件
- // cc.find("GameNode/ManageMap").getComponent('ManageMap').InitManageMap();
- GlobalD.TiledMap.onInitSolid();
- //初始化生成房屋
- /**
- * dapp设定: 如果固定土地冲突,删除冲突的建筑和回收仓库
- */
- this.ManageUI.getComponent('ManageBuildings').InitBuildings();
- //初始化道路
- /**
- * 原本游戏设定是先生产道路,现在为了方便处理等房屋生产后,再处理公路
- * dapp设定: 如果固定土地冲突,删除对应的公路
- */
- this.onSpawnHighway();
- //初始化生成人物
- /**
- * dapp设定: 如果固定土地位置冲突,把人物生成位置放置到主路
- * onSpawnWorkerAIFromStoredData 此函数处理
- */
- cc.find('GameNode/ManageWorker').getComponent('ManageWorker').InitWorkerAI();
- let _BFirstLoadGame = this.readData ? this.readData.BFirstLoadGame : 0;
- //初始化新手教学
- GlobalD.ManageTask.InitTask(_BFirstLoadGame);
- this.ManageUI.getComponent('ManageUI').Init();
- },
- InitNextworkData() {
- console.log("this.readData", this.readData);
- this.Golden = this.readData.Golden;
- this.Diamond = this.readData.Diamond;
- this.shareGive = this.readData.shareGive;
- //签到分享给钻石金币
- this.signInGive = this.readData.signInGive;
- //每个月 给的 低保
- this.EveryGive = this.readData.EveryGive;
- //公共分享
- this.publicGive = this.readData.publicGive;
- // cc.log('初始化网络数据');
- //读取日期数据
- this.GameYear = this.readData.GameYear;
- this.GameMonth = this.readData.GameMonth;
- this.GameDay = this.readData.GameDay;
- //读取金币
- this.Golden = this.readData.Golden;
- //读取钻石
- this.Diamond = this.readData.Diamond;
- // cc.log('this.readData.Diamond', this.readData.Diamond);
- //读取工人等级
- this.WorkerLV = this.readData.WorkerLV;
- //工人数量
- this.WorkerNum = this.readData.WorkerNum;
- //工人容量
- this.WorkerCapacity = this.readData.WorkerCapacity;
- this.GameDate = this.readData.GameDate;
- this.LastTimeEveryDayRewardsDate = this.readData.LastTimeEveryDayRewardsDate;
- this.LastTimeLuckDate = this.readData.LastTimeLuckDate;
- this.EveryDayRewardsArray = this.readData.EveryDayRewardsArray;//.split('_');
- this.TerritoryStateArray = this.readData.TerritoryStateArray;//.split('_');
- //面板状态
- this.BuildingStateArray = this.readData.BuildingStateArray;//.split('_');
- //解锁设置为 不用解锁
- // this.BuildingLockStateArray.forEach((value, index, array) => {
- // array[index] = 1;
- // })
- this.BuildingLockStateArray = this.readData.BuildingLockStateArray;//.split('_');
- this.BuildingNumArray = this.readData.BuildingNumArray;//.split('_');
- this.DiamondNumArray = this.readData.DiamondNumArray;//.split('_');
- this.FoodTradeState = this.readData.FoodTradeState;
- this.WoodTradeState = this.readData.WoodTradeState;
- this.MineralTradeState = this.readData.MineralTradeState;
- //工人工作信息
- if (this.readData.characterInfoArray) {
- this.CharacterInfoArray = this.readData.characterInfoArray;
- } else {
- this.CharacterInfoArray = [];
- }
- //道路数据
- if (this.readData.highwayIndex)
- this.GameData_highwayIndex = this.readData.highwayIndex;
- //建筑物数据
- if (this.readData.buildingsInfo)
- this.GameData_buildings = this.readData.buildingsInfo;
- this.LotteryTimes = this.readData.LotteryTimes;
- //任务
- if (this.readData.TaskIconCountClick)
- task.TaskIconCountClick = this.readData.TaskIconCountClick;
- },
- /**
- * 初始化
- */
- Init: function () {
- let _BFirstLoadGame = false;// this.readData ? this.readData.BFirstLoadGame : 0;
- //date
- this.GameYear = 0;
- this.GameMonth = 0;
- this.GameDay = 0;
- this.GameDate = '0000/00/01';
- /**
- * 新增 CNT 和 SNB
- */
- this.CNT = 0;
- this.SNB = 0;
- this.Golden = 2000;
- this.Diamond = 100;
- this.WorkerLV = 0;
- this.WorkerNum = 0;
- this.CharacterInfoArray = [];
- this.WorkerCapacity = 5;
- this.TerritoryStateArray = [1, 1, 1, 1, 1, 1, 1, 1];//测试,全开地图
- /**
- * 添加建筑往后添加,到时候ManageBuildings 脚本 会初始化根据顺序
- * BuildingStateArray---相关 GetBuildingStateArray 获取建筑状态
- * BuildingNumArray ---相关 GetBuildingNumArray 获取建筑数量
- * BuildingFrameArray ---相关 ManageUI 添加面板是否解锁之类的相关预制
- */
- this.BuildingStateArray = [
- 1, //公路
- 1, //路铲
- 1, //拆迁
- 1, //农舍
- 1, //单元楼
- 1, //别墅
- 1, //农田
- 1,//伐木场
- 1, //矿坑
- 1, //加工厂
- 1,//冷饮摊
- 1,//贩卖机
- 1,//面包房
- 1,//早餐车
- 1, //饮茶店
- 1,//点心店
- 1, //美食店
- 1,//西餐厅
- 1, //花店
- 1, //美发店
- 1,//洋装店
- 1, //珠宝店
- 1, //电影院
- 1,//路灯
- 1, //绿化带
- 1, //花坛
- 1,//喷泉
- 1, //警察局
- 1,//游乐场
- 1, //蓝色城堡
- 1, //粉色城堡
- 1, //Holy Farmland
- 1 //Holy Farmland seed
- ];
- this.BuildingLockStateArray = [
- 1, //公路
- 1, //路铲
- 1, //拆迁
- 1, //农舍
- 0, //单元楼
- 0, //别墅
- 1, //农田
- 0,//伐木场
- 0, //矿坑
- 1, //加工厂
- 0,//冷饮摊
- 0,//贩卖机
- 0,//面包房
- 0,//早餐车
- 0, //饮茶店
- 0,//点心店
- 0, //美食店
- 0,//西餐厅
- 0, //花店
- 0, //美发店
- 0,//洋装店
- 0, //珠宝店
- 0, //电影院
- 1,//路灯
- 1, //绿化带
- 1, //花坛
- 0,//喷泉
- 0, //警察局
- 0,//游乐场
- 0, //蓝色城堡
- 0, //粉色城堡
- 1, //Holy Farmland
- 1, //Holy Farmland seed
- ];
- //建筑物数量
- this.BuildingNumArray = [
- 0, //公路
- 0, //路铲
- 0, //拆迁
- 4, //农舍
- 1, //单元楼
- 1, //别墅
- 4, //农田
- 1,//伐木场
- 1, //矿坑
- 2, //加工厂
- 2,//冷饮摊
- 1,//贩卖机
- 1,//面包房
- 1,//早餐车
- 1, //饮茶店
- 1,//点心店
- 1, //美食店
- 1,//西餐厅
- 1, //花店
- 1, //美发店
- 1,//洋装店
- 1, //珠宝店
- 1, //电影院
- 1,//路灯
- 1, //绿化带
- 1, //花坛
- 1,//喷泉
- 1, //警察局
- 1,//游乐场
- 1, //蓝色城堡
- 1, //粉色城堡
- 1, //Holy Farmland
- 1, //Holy Farmland seed
- ];
- this.DiamondNumArray = AConfig.DiamondArray;
- //todo 钻石消耗默认值
- this.DiamondNumArray.forEach((value, index, array) => {
- array[index] = 0;
- })
- cc.log('钻石消耗默认值', this.DiamondNumArray);
- this.EveryDayRewardsArray = [0, 0, 0, 0, 0, 0, 0];
- this.LastTimeEveryDayRewardsDate = '0000/00/00';
- this.LastTimeLuckDate = '0000/00/00';
- this.FoodTradeState = 1;
- this.WoodTradeState = 1;
- this.MineralTradeState = 1;
- //转盘分享给钻石金币
- this.shareGive = [200, 5];
- //签到分享给钻石金币
- this.signInGive = [200, 5];
- //每个月 给的 低保
- this.EveryGive = [500, 10];
- //公共分享
- this.publicGive = [200, 50];
- //每天抽奖次数
- this.LotteryTimes = 10;
- // 1 === _BFirstLoadGame
- if (_BFirstLoadGame) {
- console.log("this.readData", this.readData);
- // cc.log('初始化网络数据');
- //读取日期数据
- this.GameYear = this.readData.GameYear;
- this.GameMonth = this.readData.GameMonth;
- this.GameDay = this.readData.GameDay;
- /**
- * 接口
- * todo cnt和snb 由钱包读取
- */
- this.CNT = 0;
- this.SNB = 0;
- //读取金币
- this.Golden = this.readData.Golden;
- //读取钻石
- this.Diamond = this.readData.Diamond;
- // cc.log('this.readData.Diamond', this.readData.Diamond);
- //读取工人等级
- this.WorkerLV = this.readData.WorkerLV;
- //工人数量
- this.WorkerNum = this.readData.WorkerNum;
- //工人容量
- this.WorkerCapacity = this.readData.WorkerCapacity;
- this.GameDate = this.readData.GameDate;
- this.LastTimeEveryDayRewardsDate = this.readData.LastTimeEveryDayRewardsDate;
- this.LastTimeLuckDate = this.readData.LastTimeLuckDate;
- this.EveryDayRewardsArray = this.readData.EveryDayRewardsArray;//.split('_');
- this.TerritoryStateArray = this.readData.TerritoryStateArray;//.split('_');
- //面板状态
- this.BuildingStateArray = this.readData.BuildingStateArray;//.split('_');
- //解锁设置为 不用解锁
- this.BuildingLockStateArray.forEach((value, index, array) => {
- array[index] = 1;
- })
- // this.BuildingLockStateArray = this.readData.BuildingLockStateArray.split('_');
- this.BuildingNumArray = this.readData.BuildingNumArray;//.split('_');
- this.DiamondNumArray = this.readData.DiamondNumArray;//.split('_');
- this.FoodTradeState = this.readData.FoodTradeState;
- this.WoodTradeState = this.readData.WoodTradeState;
- this.MineralTradeState = this.readData.MineralTradeState;
- //工人工作信息
- if (this.readData.characterInfoArray)
- this.CharacterInfoArray = this.readData.characterInfoArray;
- //道路数据
- if (this.readData.highwayIndex)
- this.GameData_highwayIndex = this.readData.highwayIndex;
- //建筑物数据
- if (this.readData.buildingsInfo)
- this.GameData_buildings = this.readData.buildingsInfo;
- this.LotteryTimes = this.readData.LotteryTimes;
- //任务
- if (this.readData.TaskIconCountClick)
- task.TaskIconCountClick = this.readData.TaskIconCountClick;
- //测试5W
- // this.PlusDiamond(50000);
- }
- },
- //GET / SET /Plus
- GetGameDate: function () {
- return this.GameDate;
- },
- SetGameDate: function (num) {
- this.GameDate = num;
- },
- PlusGameDate: function (num) {
- this.GameDate += num;
- },
- GetGolden: function () {
- return parseInt(this.Golden);
- },
- GetGoldenCallBack(_CallBack) {
- if (_CallBack)
- _CallBack({ resGolden: parseInt(this.Golden) });
- },
- SetGolden: function (Num) {
- let LastMoney = this.Golden;
- this.Golden = Num;
- let CurrentMoney = Num;
- this.ManageUI.getComponent('ManageUI').GoldenChangeCallBack(this.GetGolden(), LastMoney, CurrentMoney);
- },
- PlusGolden: function (Num) {
- if (this.Golden + Num < 0) {
- this.SetGolden(0);
- }
- else {
- this.SetGolden(this.Golden + Num);
- }
- // task.task50W();
- },
- GetDiamond: function () {
- return parseInt(this.Diamond);
- },
- SetDiamond: function (num) {
- let LastMoney = this.Diamond;
- this.Diamond = num;
- let CurrentMoney = num;
- this.ManageUI.getComponent('ManageUI').DiamondChangeCallBack(this.GetDiamond(), LastMoney, CurrentMoney);
- },
- PlusDiamond: function (num) {
- if (this.Diamond + num < 0) {
- this.SetDiamond(0);
- }
- else {
- this.SetDiamond(this.Diamond + num);
- }
- },
- /**
- * 游戏里面的cnt 和神农呗
- */
- GetCNT: function () {
- return parseFloat(this.CNT);
- },
- SetCNT: function (Num) {
- this.CNT = Num;
- this.ManageUI.getComponent('ManageUI').CNTChangeCallBack(this.CNT);
- },
- GetSNB: function () {
- return parseFloat(this.SNB);
- },
- SetSNB: function (Num) {
- this.SNB = Num;
- this.ManageUI.getComponent('ManageUI').SNBChangeCallBack(this.SNB);
- },
- GetWorkerLV: function () {
- return parseInt(this.WorkerLV);
- },
- SetWorkerLV: function (num) {
- this.WorkerLV = num;
- },
- PlusWorkerLV: function (num) {
- this.WorkerLV += num;
- },
- GetWorkerNum: function () {
- return parseInt(this.WorkerNum);
- },
- SetWorkerNum: function (num) {
- this.WorkerNum = num;
- },
- PlusWorkerNum: function (num) {
- this.WorkerNum += num;
- },
- GetLastTimeEveryDayRewardsDate: function () {
- return this.LastTimeEveryDayRewardsDate;
- },
- //获取转盘 时间
- GetLastTimeLuckDate: function () {
- return this.LastTimeLuckDate;
- },
- //设置转盘时间
- SetLastTimeLuckDate: function (DateString) {
- this.LastTimeLuckDate = DateString;
- },
- SetLastTimeEveryDayRewardsDate: function (DateString) {
- this.LastTimeEveryDayRewardsDate = DateString;
- },
- //工人信息数组
- GetWorkerCharacterInfoArray: function () {
- return this.CharacterInfoArray;
- },
- SetWorkerCharacterInfoArray: function (item) {
- this.CharacterInfoArray = item;
- },
- /*** */
- GetWorkerCapacity: function () {
- return parseInt((this.WorkerCapacity));
- },
- SetWorkerCapacity: function (num) {
- this.WorkerCapacity = num;
- },
- PlusWorkerCapacity: function (num) {
- this.WorkerCapacity += num;
- },
- GetTerritoryStateArray: function () {
- return this.TerritoryStateArray;
- },
- SetTerritoryStateArray: function (aTerritoryStateArray) {
- this.TerritoryStateArray = aTerritoryStateArray;
- },
- PlusTerritoryStateArray: function (Item) {
- this.TerritoryStateArray.push(Item);
- },
- GetBuildingStateArray: function () {
- return this.BuildingStateArray;
- },
- SetBuildingStateArray: function (aBuildingStateArray) {
- this.BuildingStateArray = aBuildingStateArray;
- },
- PlusBuildingStateArray: function (Item) {
- this.BuildingStateArray.push(Item);
- },
- GetBuildingLockStateArray: function () {
- return this.BuildingLockStateArray;
- },
- SetBuildingLockStateArray: function (aArray) {
- this.BuildingLockStateArray = aArray;
- },
- PlusBuildingLockStateArray: function (Item) {
- this.BuildingLockStateArray.push(Item);
- },
- GetBuildingNumArray: function () {
- return this.BuildingNumArray;
- },
- SetBuildingNumArray: function (aBuildingNumArray) {
- this.BuildingNumArray = aBuildingNumArray;
- },
- PlusBuildingNumArray: function (Item) {
- this.BuildingNumArray.push(Item);
- },
- //操作钻石数据
- GetDiamondNumArray: function () {
- return this.DiamondNumArray;
- },
- SetDiamondNumArray: function (aDiamondNumArray) {
- this.DiamondNumArray = aDiamondNumArray;
- },
- GetEveryDayRewardsArray: function () {
- return this.EveryDayRewardsArray;
- },
- SetEveryDayRewardsArray: function (aArray) {
- this.EveryDayRewardsArray = aArray;
- },
- PlusEveryDayRewardsArray: function (Item) {
- this.EveryDayRewardsArray.push(Item);
- },
- GetFoodTradeState: function () {
- return parseInt((this.FoodTradeState));
- },
- SetFoodTradeState: function (num) {
- this.FoodTradeState = num;
- },
- PlusFoodTradeState: function (num) {
- this.FoodTradeState += num;
- },
- GetWoodTradeState: function () {
- return parseInt((this.WoodTradeState));
- },
- SetWoodTradeState: function (num) {
- this.WoodTradeState = num;
- },
- PlusWoodTradeState: function (num) {
- this.WoodTradeState += num;
- },
- GetMineralTradeState: function () {
- return parseInt((this.MineralTradeState));
- },
- SetMineralTradeState: function (num) {
- this.MineralTradeState = num;
- },
- PlusMineralTradeState: function (num) {
- this.MineralTradeState += num;
- },
- GetLotteryTimes: function () {
- return parseInt((this.LotteryTimes));
- },
- SetLotteryTimes: function (num) {
- this.LotteryTimes = num;
- },
- PlusLotteryTimes: function (num) {
- this.LotteryTimes += num;
- },
- //初始化道路
- onSpawnHighway() {
- // 获取InitPoint层
- let InitPos = this._tiledMap.getLayer('InitPoint');
- InitPos.enabled = false;
- //创建公路数据
- if (this.readData && this.readData.allHighwayStylesAndIndex) {
- //保存到内存中
- this.GameData_highwayIndex = this.readData.highwayIndex;
- //先赋值道路的对象数组
- let _AllHighwayAIndex = Object.assign([], this.readData.allHighwayStylesAndIndex);
- //获取最后建造公路的层级
- this.HighwayLayer = this._tiledMap.getLayer('Highway');
- for (let i = 0; i < _AllHighwayAIndex.length; i++) {
- let _tiledPos = GlobalD.TiledMap.analyticalIndexData(_AllHighwayAIndex[i].highwayInfoIndex);
- /**
- * 解决固定土地时候,道路 和房子 冲突
- *
- */
- if (GlobalD.game.getManageGameIndexArrayAt(cc.v2(_tiledPos.x, _tiledPos.y))) {
- continue;
- }
- let highwayTemp = cc.instantiate(this.HighWayPrefabs);
- highwayTemp.parent = this.HighwayLayer.node;
- let tiledTile = highwayTemp.addComponent('TiledTile');
- tiledTile.x = _tiledPos.x;
- tiledTile.y = _tiledPos.y;
- //地图设置可行走区域公路设置
- AStar.setMapSolid(_tiledPos.x, _tiledPos.y, 0);
- // _buildId ==0 是公路
- let _buildId = 0;
- let occupyTemp = cc.v2(_buildId, _AllHighwayAIndex[i].highwayInfoIndex);
- GlobalD.game.OccupyArray.push(occupyTemp);
- highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(_AllHighwayAIndex[i].highwayInfoType);
- GlobalD.game.AllHighwayStylesAndIndex.push(_AllHighwayAIndex[i]);
- }
- console.log("end");
- } else {
- //如果用户没有存储数据
- //根据InitPoint 的数据,创建初始化的地图数据 的初始化数据
- this.HighwayLayer = this._tiledMap.getLayer('Highway');
- for (var i = 0; i < 32; i++) {
- //去除中间两条路
- if (i == 16 || i == 17) continue;
- for (var j = 0; j < 32; j++) {
- let tilesPos = cc.v2(i, j);
- if (InitPos.getTileGIDAt(tilesPos)) {
- let index = GlobalD.TiledMap.getIndex(tilesPos);
- this.GameData_highwayIndex.push(index);
- let highwayTemp = cc.instantiate(this.HighWayPrefabs);
- highwayTemp.parent = this.HighwayLayer.node;
- let tiledTile = highwayTemp.addComponent('TiledTile');
- tiledTile.x = tilesPos.x;
- tiledTile.y = tilesPos.y;
- // cc.log('onSpawnHighway2');
- //地图设置可行走区域公路设置
- AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
- // _buildId ==0 是公路
- let _buildId = 0;
- let occupyTemp = cc.v2(_buildId, index);
- GlobalD.game.OccupyArray.push(occupyTemp);
- let tile = InitPos.getTiledTileAt(tilesPos.x, tilesPos.y, true);
- let _MoveType = reGameStates.HighwayType.moveX;
- // if (tile.gid == 15) {
- // _MoveType = reGameStates.HighwayType.moveX;
- // } else
- if (tile.gid == 16) {
- _MoveType = reGameStates.HighwayType.moveY;
- } else if (tile.gid == 11) {
- _MoveType = reGameStates.HighwayType.ZebraCrossingX;
- } else if (tile.gid == 12) {
- _MoveType = reGameStates.HighwayType.ZebraCrossingY;
- }
- // return;
- //更换公路样式
- GlobalD.game.onCreateDifferentRoadStyles({
- _buildId: _buildId,
- _highwayType: _MoveType,
- _roadIndex: index,
- _hightwayNode: highwayTemp
- });
- }
- }
- }
- }
- //外面的两条路
- let initRoad = this._tiledMap.getLayer('Road');
- initRoad.enabled = false;
- for (var i = 16; i < 18; i++) {
- for (var j = 0; j < 32; j++) {
- let tilesPos = cc.v2(i, j);
- // cc.log('road tilesPos',tilesPos)
- if (initRoad.getTileGIDAt(tilesPos)) {
- let index = GlobalD.TiledMap.getIndex(tilesPos);
- this.GameData_highwayIndex.push(index);
- let highwayTemp = cc.instantiate(this.HighWayPrefabs);
- highwayTemp.parent = this.HighwayLayer.node;
- let tiledTile = highwayTemp.addComponent('TiledTile');
- tiledTile.x = tilesPos.x;
- tiledTile.y = tilesPos.y;
- // cc.log('initRoad');
- //地图设置可行走区域公路设置
- AStar.setMapSolid(tilesPos.x, tilesPos.y, 0);
- let _buildId = 0;
- let occupyTemp = cc.v2(_buildId, index);
- GlobalD.game.OccupyArray.push(occupyTemp);
- //更换公路样式
- // if (j >= 25 && j <= 27 || j >= 19 && j <= 21 || j >= 9 && j <= 11)
- // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.none);
- // else
- // highwayTemp.getComponent('HighwayInfo').onChangeHighwayStyles(reGameStates.HighwayType.moveY);
- }
- }
- }
- },
- //清除所有的数据
- onClearAllData() {
- this.unschedule(this.AutoSaveData);
- //任务索引
- cc.sys.localStorage.removeItem('userdata');
- //跳回登录场景
- // cc.director.loadScene('Login');
- },
- //保存数据请求
- /**
- *
- * 现在转服务器存储,原本所有相关操作通过服务器计算。
- * 一、目前涉及到的是 SNT 和 SNB 两个货币相关,和买田地操作 (可以理解为租聘,三种类型)
- *
- * isNetwork:true,上传到网络
- *
- */
- pushData: function (isNetwork) {
- // cc.log(this.EveryDayRewardsArray);
- // console.log(this.readData.BFirstLoadGame);
- var datas = {
- version: this.GameVersion,
- // 转后台处理
- BFirstLoadGame: 1,//只要push数据,就证明已经开始第一次游戏了
- /**游戏不修改,默认值 start */
- shareGive: this.shareGive,
- //签到分享给钻石金币
- signInGive: this.signInGive,
- //每个月 给的 低保
- EveryGive: this.EveryGive,
- //公共分享
- publicGive: this.publicGive,
- /**游戏不修改,默认值 end */
- //时间
- GameYear: this.GameYear,
- GameMonth: this.GameMonth,
- GameDay: this.GameDay,
- //这里只是单纯的存储起来
- CNT: this.CNT,
- SNB: this.SNB,
- Golden: this.Golden,
- Diamond: this.Diamond,
- WorkerLV: this.WorkerLV,
- WorkerNum: this.WorkerNum,
- WorkerCapacity: this.WorkerCapacity,
- GameDate: this.GameDate,
- LastTimeEveryDayRewardsDate: this.LastTimeEveryDayRewardsDate,
- LastTimeLuckDate: this.LastTimeLuckDate,
- EveryDayRewardsArray: this.EveryDayRewardsArray,//.join('_'),
- TerritoryStateArray: this.TerritoryStateArray,//.join('_'),
- //面板状态
- BuildingStateArray: this.BuildingStateArray,//.join('_'),
- BuildingLockStateArray: this.BuildingLockStateArray,//.join('_'),
- /**
- * SNB和CNT相关,需要后台筛选 田地 和 种子。单独处理
- */
- BuildingNumArray: this.BuildingNumArray,//.join('_'),
- DiamondNumArray: this.DiamondNumArray,//.join('_'),
- FoodTradeState: this.FoodTradeState,
- WoodTradeState: this.WoodTradeState,
- MineralTradeState: this.MineralTradeState,
- LotteryTimes: this.LotteryTimes,
- /**
- * 这些数据不用服务器初始化
- */
- //工人工作信息
- characterInfoArray: this.CharacterInfoArray,
- //道路数据
- highwayIndex: this.GameData_highwayIndex,
- allHighwayStylesAndIndex: GlobalD.game.AllHighwayStylesAndIndex,
- //建筑物数据
- buildingsInfo: this.GameData_buildings,
- //任务
- TaskIconCountClick: task.TaskIconCountClick
- }
- if (isNetwork) {
- var data = [];
- // data["openid"] = userData.openId;
- // data["userdata"] = JSON.stringify(datas);
- data["playerData"] = JSON.stringify(datas);
- /** 推送信息 */
- utils.post(utils.api.playerPushInfo, data, (res, playerPushInfoTemp) => {
- // console.log('playerPushInfoTemp', playerPushInfoTemp);
- })
- } else {
- console.log("存储本地:" + isNetwork);
- //保存用户数据到本地
- cc.sys.localStorage.setItem('userdata', JSON.stringify(datas));
- }
- },
- /**
- * 暂时不需要从这里读取
- */
- getLandConfig() {
- // "data": [
- // {
- // "id": 1,
- // "configLandId": 1,
- // "userId": "4",
- // "name": "1",
- // "isLease": 1,
- // "leaseTime": "2022-01-10 21:25:17",
- // "leaseMultiple": null,
- // "isPlant": 1,
- // "plantStart": "2022-01-10 21:25:22",
- // "plantMature": 1,
- // "landDescribe": "1",
- // "createTime": "2022-01-10 21:25:30",
- // "updateTime": "2022-01-10 21:25:33"
- // }
- // ],
- utils.get(utils.api.landConfig, {}, (res, value) => {
- if (0 === value.code) {
- this.ConfigLand = value.data;
- } else {
- console.warn("未能读取到config土地?");
- }
- })
- },
- //获取用户全部租赁土地
- getUserLandList() {
- // "data": [
- // {
- // "id": 1,
- // "configLandId": 1,
- // "userId": "4",
- // "name": "1",
- // "isLease": 1,
- // "leaseTime": "2022-01-10 21:25:17",
- // "leaseMultiple": null,
- // "isPlant": 1,
- // "plantStart": "2022-01-10 21:25:22",
- // "plantMature": 1,
- // "landDescribe": "1",
- // "createTime": "2022-01-10 21:25:30",
- // "updateTime": "2022-01-10 21:25:33"
- // }
- // ],
- utils.get(utils.api.userLandList, {}, (res, vaule) => {
- })
- },
- //获取用户已租赁土地的状态
- getLandState() {
- // {
- // "id": 1,
- // "configLandId": 1,
- // "userId": "4",
- // "name": "1",
- // "isLease": 1,
- // "leaseTime": "2022-01-10 21:25:17",
- // "leaseMultiple": null,
- // "isPlant": 1,
- // "plantStart": "2022-01-10 21:25:22",
- // "plantMature": 1,
- // "landDescribe": "1",
- // "createTime": "2022-01-10 21:25:30",
- // "updateTime": "2022-01-10 21:25:33"
- // }
- utils.get(utils.api.landState, { landId: 1 }, (res, vaule) => {
- })
- },
- //获取商城种子
- getMallSeed(callback) {
- // "data": [
- // {
- // "id": 1,
- // "mallType": "0",
- // "picture": null,
- // "name": "白菜种子",
- // "maturity": 100,
- // "planting": 100,
- // "harvestQuantity": 2500,
- // "harvestCount": 2500,
- // "harvestName": "大白菜",
- // "price": 99,
- // "amount": 0,
- // "withered": 200,
- // "createTime": "2022-01-10 16:45:18",
- // "updateTime": "2022-01-10 16:45:26"
- // },
- // {
- // "id": 2,
- // "mallType": "0",
- // "picture": null,
- // "name": "辣椒种子",
- // "maturity": 100,
- // "planting": 100,
- // "harvestQuantity": 2500,
- // "harvestCount": 2500,
- // "harvestName": "辣椒",
- // "price": 99,
- // "amount": 0,
- // "withered": 200,
- // "createTime": "2022-01-10 16:45:23",
- // "updateTime": "2022-01-10 16:45:28"
- // }
- // ],
- utils.get(utils.api.mallSeed, {}, (res, vaule) => {
- callback(res, vaule);
- })
- },
- getWarehouseSeedAndFruit(callback) {
- // "data": {
- // "seed": [
- // {
- // amount: 0
- // createTime: "2022-01-10 16:45:18"
- // harvestCount: 2500
- // harvestName: "大白菜"
- // harvestQuantity: 2500
- // id: 1
- // mallType: "0"
- // maturity: 100
- // name: "白菜种子"
- // picture: null
- // planting: 100
- // priceCnt: 99.99
- // priceSnb: 495.99
- // updateTime: "2022-01-10 16:45:26"
- // withered: 200
- // }
- // ],
- // "fruit": [
- // {
- // createTime: "2022-01-10 16:45:18"
- // id: 1
- // name: "白菜"
- // picture: null
- // priceCnt: 9.99
- // priceSnb: 99
- // updateTime: "2022-01-10 16:45:26"
- // }
- // ]
- // },
- utils.get(utils.api.getSeedAndFruit, {}, (res, vaule) => {
- callback(res, vaule);
- })
- },
- //种植种子
- // data:{landId:1,seedId:1}
- onPlant(data, callback) {
- utils.get(utils.api.plant, data, (res, vaule) => {
- callback(res, vaule);
- })
- },
- //收取果实
- onAddFruit(data, callback) {
- utils.post(utils.api.addFruit, data, (res, vaule) => {
- callback(res, vaule);
- })
- },
- //出售果实
- onSaleFruit(data, callback) {
- utils.post(utils.api.saleFruit, data, (res, vaule) => {
- callback(res, vaule);
- })
- },
- //赠送果实
- onGrantFruit(data, callback) {
- utils.post(utils.api.grantFruit, data, (res, vaule) => {
- callback(res, vaule);
- })
- },
-
- /**
- * 支付cnt操作
- * @param {*} amount // 需支付金额
- * @param {*} payType 支付类型,1购买土地租凭, 2自然灾害防护,3野兽防护
- * @param {*} itemType 操作物品的id
- */
- payCNT(cntAmount, payType, itemType, callback) {
- if (!GlobalD.dapp) {
- console.warn("GlobalD.dapp未初始化,不能payCNT!");
- return;
- }
- //
- if (GlobalD.GameData.GetCNT() < cntAmount) {
- console.log("cnt 不足,GetCNT:", GlobalD.GameData.GetCNT(), "消费的cntAmount", cntAmount);
- gameToast.getInstance().show(cc.find("Canvas/UICamera"), "CNT不足!", 2, () => {
- console.log("finish toast!");
- }, this);
- return;
- }
- GlobalD.dapp.payCnt(cntAmount, payType, itemType).then((data) => {
- const [err, tx] = data;
- if (err === null) {
- // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
- console.log(tx) // 交易hash,唯一标识符
- } else {
- console.log(err)
- }
- if (callback) {
- callback(data);
- }
- });
- },
- /**
- * 神农呗转换CNT ,比例是5:1
- * @param {*} snbAmount
- * @param {*} callback
- * @returns
- */
- onSnbToCnt(snbAmount, callback) {
- if (!GlobalD.dapp) {
- console.warn("GlobalD.dapp未初始化,不能onSnbToCnt!");
- return;
- }
- if (GlobalD.GameData.GetSNB() <= 0) {
- console.log("神农呗数量GetSNB:", GlobalD.GameData.GetSNB(), "替换snbAmount:", snbAmount);
- gameToast.getInstance().show(cc.find("Canvas/UICamera"), "神农呗数量不足!", 2, () => {
- console.log("finish toast!");
- }, this);
- return;
- }
- GlobalD.dapp.snbToCnt(snbAmount).then((data) => {
- const [err, tx] = data;
- if (err === null) {
- // TODO 成功, 兑换为链上操作,需要提供回调接口给这边服务端确认交易成功后修改扣除SNB数量
- console.log(tx) // 交易hash,唯一标识符
- //扣除对应的神农呗,本地修改显示
- GlobalD.GameData.SetSNB(GlobalD.GameData.GetSNB() - snbAmount);
- } else {
- console.log(err)
- }
- if (callback) {
- callback(data);
- }
- });
- },
- //获取 神农呗转 CNT 日志
- onGetSnbToCntInfo(page,limit,callback) {
- if (!GlobalD.dapp) {
- console.warn("GlobalD.dapp未初始化,不能onGetSnbToCntInfo!");
- return;
- }
- GlobalD.dapp.swapLog(page, limit).then((data) => {
- const { err, res } = data;
- if (err ===null) {
- console.log(res) //
- }
- if (callback) {
- callback(data);
- }
- });
- }
- });
|