UserDataMgr.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  1. var ItemType = require("ItemType");
  2. var RewardType = require("RewardType");
  3. var MateBonusType = require("MateBonusType");
  4. var SkillType = require("SkillType");
  5. var MateUnLockType = require("MateUnLockType");
  6. var MateGetType = require("MateGetType");
  7. var UserState = require("UserState");
  8. var AchieveCondData = require("AchieveCondData");
  9. var AchieveCond = require("AchieveCond");
  10. //以下的数据要做永久保存
  11. var SkillStruct = require("SkillStruct");
  12. var AchieveStruct = require("AchieveStruct");
  13. var RecordStruct = require("RecordStruct");
  14. //下面的数值是不会永久保存的 指只会当局游戏保存
  15. var GoodsStruct = require("GoodsStruct");
  16. var CarStruct = require("CarStruct");
  17. var HouseStruct = require("HouseStruct");
  18. var CompanyStruct = require("CompanyStruct");
  19. var MateStruct = require("MateStruct");
  20. //数据操作结构
  21. var UserDataMgr = cc.Class({
  22. extends: cc.Component,
  23. properties:{
  24. //本地保存数据
  25. tutorialInBus:false,
  26. tutorialInDate:false,
  27. tutorialInMarket:false,
  28. tutorialStockBonus:false,
  29. tutorialMatePoint:false,
  30. VideoLastTime:"",//每天看视频时间记录
  31. VideoAdsTimes:cc.Integer,//次数
  32. playTimes:cc.Integer,//游戏次数
  33. playerName:"Alex",
  34. Sex:cc.Integer, //1 man 2 woman
  35. SkillList:{
  36. default:[],
  37. type:[SkillStruct],
  38. },
  39. AchievementList:{
  40. default:[],
  41. type:[AchieveStruct],
  42. },
  43. RecordList:{
  44. default:[],
  45. type:[RecordStruct],
  46. },
  47. MarryAge:cc.Integer,
  48. MarryRoleId:cc.Integer,
  49. DivorceAge:cc.Integer,
  50. FundationAge:cc.Integer,
  51. FundationCompanyId:cc.Integer,
  52. BankruptAge:cc.Integer,
  53. MillionAge:cc.Integer,
  54. TenMillionAge:cc.Integer,
  55. HundredMillionAge:cc.Integer,
  56. //非本地保存数据
  57. RetireAge:cc.Integer, //退休年龄 这个值跟成就有关
  58. BetWinRatio:0.15, //賭博贏概率
  59. DateSuccescRatio:0.2, //約會成功概率
  60. //BetCost:cc.Integer,//赌博花费
  61. HighAssets:cc.Integer,//资产巅峰值
  62. InitMoney:cc.Integer,//刚出来闯荡时候的所有资产
  63. Cash:cc.Integer,//现金
  64. HpPoint:cc.Integer,//健康指数
  65. Age:cc.Integer,//年龄
  66. Honor:cc.Integer, //头衔 1 百万富翁 等等 这个在玩到一亿元之后会有新的玩意
  67. Reputation:cc.Integer, //名声指数
  68. AssetsMoney:cc.Integer, //总资产
  69. WareHouseCapcity:cc.Integer,//仓库剩余容量
  70. WareHouseAllCapcity:cc.Integer,//仓库总容量
  71. hasCompany:false,//是否已经创办公司
  72. CanGetStockProfit:false, //能否计算股票收益了
  73. RecoverYear:0,// 从恢复健康 剩余年限
  74. SkillBonusPoint:0,//技能点
  75. //加成点 伴侣加成 技能加成
  76. TreatBonus: 0.0, //治疗花费降低百分点
  77. WareHouseCapcityBonus:0, //仓储加成
  78. CashBonus:0, //金钱加成 每年加成
  79. CashRationBonus:0,
  80. ReputationBonus:0, //名声加成 每年
  81. HpPointBonus:0, //健康加成
  82. WareHouseBonusEveryYear:0, //每年的仓储加成
  83. RetireBonus:0, //增加退休年限
  84. DateBonus:0.0, //增加约会成功概率
  85. InitMoneyBonus:0,//增加初始现金
  86. StockAddBonus:0.0, //增加公司收益
  87. StockUpBonus:0.0, //股票上涨 概率增加
  88. DateMoneyBonus:0.0, //约会花费降低
  89. BetBonus:0.0, //赌博赢钱概率上升
  90. SkillPointGetBonus:0.0 ,//结算技能点获得提升
  91. ReputationInitBonus:0, //初始名声加成
  92. CarBuyBonus:0, //购买汽车价格降低
  93. EventCostBonus:0, //事件消耗金钱降低
  94. HouseBuyBonuse:0, //购买房屋 价格降低
  95. HistoryHighAssets:0,// 记录历史退休最高资产
  96. userState:{
  97. default:UserState.OK,
  98. type:UserState,
  99. },// 玩家状态
  100. EventDataIdList:{
  101. default:[],
  102. type:[cc.Integer],
  103. },//事件弹出 Id列表
  104. GoodsList:{
  105. default:[],
  106. type:[GoodsStruct],
  107. },
  108. CarList:{
  109. default:[],
  110. type:[CarStruct],
  111. },
  112. HouseList:{
  113. default:[],
  114. type:[HouseStruct],
  115. },
  116. CompanyList:{
  117. default:[],
  118. type:[CompanyStruct],
  119. },
  120. MateList:{
  121. default:[],
  122. type:[MateStruct],
  123. },
  124. //当前显示的五个物品 每次只显示五个物品 只保存 Id
  125. ShowGoodsList:{
  126. default:[],
  127. type:[cc.Integer],
  128. },
  129. },
  130. JudeGoodsOwned:function(Id){
  131. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  132. if(this.GoodsList[i].Id == Id && this.GoodsList[i].ownNum > 0)
  133. {
  134. return true;
  135. }
  136. }
  137. return false;
  138. },
  139. //清理市场显示数据
  140. ClearShowGoodsList:function(){
  141. this.ShowGoodsList.splice(0, this.ShowGoodsList.length);
  142. },
  143. //向显示数组中插入一个 显示数据 Id
  144. InsertGoodsIdToList:function(Id){
  145. this.ShowGoodsList.push(Id);
  146. },
  147. //检查Id 是否当前显示
  148. CheckIdIsInShowList:function(Id){
  149. var flag = false;
  150. for (var i = this.ShowGoodsList.length - 1; i >= 0; i--) {
  151. if(this.ShowGoodsList[i] == Id)
  152. {
  153. flag = true;
  154. break;
  155. }
  156. }
  157. return flag;
  158. },
  159. initData:function () {
  160. cc.Mgr.initData = false;
  161. this.userState = UserState.OK;//健康状态
  162. cc.Mgr.global.InitEventHappenAge();
  163. //本地存储数据
  164. var StorageData = cc.sys.localStorage.getItem('XMB_userdata'); //作为一个整体保存起来
  165. if(StorageData == null || StorageData == "")
  166. {
  167. //cc.log("还没有保存过持久数据");
  168. var userdata = {};
  169. userdata.SkillList = null;
  170. userdata.AchievementList = null;
  171. userdata.playerName = "";
  172. userdata.Sex = 1;
  173. userdata.playTimes = 0;
  174. userdata.SkillBonusPoint = 0;
  175. userdata.tutorialInBus = false;
  176. userdata.tutorialInDate = false;
  177. userdata.tutorialInMarket = false;
  178. userdata.tutorialStockBonus = false;
  179. userdata.tutorialMatePoint = false;
  180. userdata.VideoAdsTimes = 0;
  181. userdata.VideoLastTime = "";
  182. userdata.HistoryHighAssets = 0;
  183. this.VideoLastTime = "";
  184. this.VideoAdsTimes = 0;
  185. this.playerName = userdata.playerName;
  186. this.Sex = userdata.Sex;
  187. this.playTimes = userdata.playTimes;
  188. this.tutorialInBus = userdata.tutorialInBus;
  189. this.tutorialInMarket = userdata.tutorialInMarket;
  190. this.tutorialInDate = userdata.tutorialInDate;
  191. this.tutorialStockBonus = userdata.tutorialStockBonus;
  192. this.tutorialMatePoint = userdata.tutorialMatePoint;
  193. this.SkillBonusPoint = userdata.SkillBonusPoint;
  194. var SkillList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.Skill);
  195. for (var i = 0; i < SkillList.length; i++) {
  196. var data = SkillList[i];
  197. var sk = new SkillStruct();
  198. sk.name = data.name;
  199. sk.icon = data.icon;
  200. sk.Id = data.Id;
  201. sk.desId = data.desId;
  202. sk.subId = data.subId;
  203. sk.Uplv = data.upLevel;
  204. sk.skillType = data.skillType;
  205. sk.level = 0;
  206. this.SkillList[i] = sk;
  207. }
  208. var AchievementList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.Achieve);
  209. for (var i = 0; i < AchievementList.length; i++) {
  210. var data = AchievementList[i];
  211. var ac = new AchieveStruct();
  212. ac.Id = data.Id;
  213. ac.icon = data.icon;
  214. ac.name = data.name;
  215. ac.desId = data.desId;
  216. ac.hasFinish = false;
  217. this.AchievementList[i] = ac;
  218. }
  219. userdata.SkillList = this.SkillList;
  220. userdata.AchievementList = this.AchievementList;
  221. userdata.RecordList = this.RecordList;
  222. cc.sys.localStorage.setItem('XMB_userdata',JSON.stringify(userdata));
  223. }
  224. else
  225. {
  226. //cc.log("有之前保存的持久数据存在");
  227. var Data = JSON.parse(StorageData);
  228. this.playerName = Data.playerName;
  229. this.Sex = Data.Sex;
  230. this.playTimes = Data.playTimes;
  231. this.tutorialInBus = Data.tutorialInBus;
  232. this.tutorialInMarket = Data.tutorialInMarket;
  233. this.tutorialInDate = Data.tutorialInDate;
  234. this.tutorialStockBonus = Data.tutorialStockBonus;
  235. this.tutorialMatePoint = Data.tutorialMatePoint;
  236. this.HistoryHighAssets = Data.HistoryHighAssets;
  237. this.SkillList = Data.SkillList;
  238. this.SkillBonusPoint = Data.SkillBonusPoint;
  239. this.AchievementList = Data.AchievementList;
  240. this.VideoLastTime = Data.VideoLastTime;
  241. var testDate = new Date();
  242. //cc.log("++++++++++++++++++++++++++ " + testDate.toDateString());
  243. if(Data.VideoLastTime != testDate.toDateString())
  244. {
  245. this.VideoAdsTimes = 0;
  246. }
  247. else
  248. {
  249. this.VideoAdsTimes = Data.VideoAdsTimes;
  250. }
  251. if(Data.RecordList != null)
  252. this.RecordList = Data.RecordList;
  253. }
  254. //获取其实天赋点加成
  255. this.GetInitSkillBonus(this.SkillList);
  256. this.MarryAge = 0;
  257. this.MarryRoleId = 0;
  258. this.DivorceAge = 0;
  259. this.FundationAge = 0;
  260. this.FundationCompanyId = 0;
  261. this.BankruptAge = 0;
  262. this.MillionAge = 0;
  263. this.TenMillionAge = 0;
  264. this.HundredMillionAge = 0;
  265. //初始化 玩一局的数据
  266. this.retireAge = cc.Mgr.global.RetireInitAge + this.RetireBonus;
  267. this.BetWinRatio = cc.Mgr.global.BetWinRatio + (this.BetBonus / 100); //后面还会要加上加成
  268. this.DateSuccescRatio = cc.Mgr.global.DateSuccescRatio + (this.DateBonus / 100);
  269. this.Cash = 0;
  270. this.HighAssets = 0;
  271. this.HpPoint = 100;
  272. this.RecoverYear = 0;
  273. this.userState = UserState.OK;
  274. this.Age = 20;
  275. this.Honor = 0; //没有头衔
  276. this.Reputation = this.ReputationInitBonus; //名声
  277. this.AssetsMoney = 0;//资产
  278. this.WareHouseBonusEveryYear = 0;
  279. this.WareHouseCapcity = cc.Mgr.global.InitWareHouseCapcity + this.WareHouseCapcityBonus;//仓库容量初始定100 这个值到时要根据 成就定
  280. this.WareHouseAllCapcity = cc.Mgr.global.InitWareHouseCapcity + this.WareHouseCapcityBonus;
  281. this.hasCompany = false;//没有公司
  282. this.CanGetStockProfit = false;//还不能计算股票收益
  283. var GoodsList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.Goods);
  284. for (var i = 0; i < GoodsList.length; i++) {
  285. var data = GoodsList[i];
  286. var ac = new GoodsStruct();
  287. ac.name = data.name;
  288. ac.Id = data.Id;
  289. ac.icon = data.icon;
  290. ac.ownNum = 0;
  291. ac.buyPrice = 0; //买入价格
  292. ac.marketPrice = 0;//市场价格
  293. this.GoodsList[i] = ac;
  294. }
  295. var CarList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.Car);
  296. for (var i = 0; i < CarList.length; i++) {
  297. var data = CarList[i];
  298. var ac = new CarStruct();
  299. ac.Id = data.Id;
  300. ac.icon = data.icon;
  301. ac.name = data.name;
  302. ac.ownNum = 0;
  303. ac.price = data.price;
  304. ac.addBonus = data.addBonus;
  305. ac.addHp = data.addHp;
  306. ac.addDate = data.addDate;
  307. this.CarList[i] = ac;
  308. }
  309. var HouseList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.House);
  310. for (var i = 0; i < HouseList.length; i++) {
  311. var data = HouseList[i];
  312. var ac = new HouseStruct();
  313. ac.Id = data.Id;
  314. ac.icon = data.icon;
  315. ac.name = data.name;
  316. ac.ownNum = 0;
  317. ac.price = data.price;
  318. ac.addBonus = data.addBonus;
  319. ac.addHp = data.addHp;
  320. this.HouseList[i] = ac;
  321. }
  322. var CompanyList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.Company);
  323. for (var i = 0; i < CompanyList.length; i++) {
  324. var data = CompanyList[i];
  325. var ac = new CompanyStruct();
  326. ac.Id = data.Id;
  327. ac.icon = data.icon;
  328. ac.name = data.name;
  329. ac.bonusRatio = data.bonusRatio;
  330. ac.isOwned = false;
  331. ac.stockNum = 0;
  332. ac.stockCost = 0;
  333. ac.bankruptPrice = data.outPrice;
  334. ac.stockPrice = data.inPrice;
  335. ac.LimitYear = data.LimitYear;
  336. this.CompanyList[i] = ac;
  337. }
  338. var MateList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.Mate);
  339. for (var i = 0; i < MateList.length; i++) {
  340. var data = MateList[i];
  341. var ac = new MateStruct();
  342. ac.Id = data.Id;
  343. ac.icon = data.icon;
  344. ac.name = data.name;
  345. ac.sex = data.sex;
  346. ac.LovePoint = 0;
  347. ac.canDate = false;
  348. ac.unlockCond = data.unlockCond;
  349. if(data.unlockCond == MateUnLockType.NULL)
  350. {
  351. ac.canDate = true;
  352. }
  353. ////cc.log(data.name + " 是否可以直接约会 " + data.unlockCond);
  354. ac.curLevel = 0;//等级
  355. ac.UpLv = false;//没有满级
  356. this.MateList[i] = ac;
  357. }
  358. //保存下 事件Id 每次刷一次事件 就会剔除一次
  359. var EventList = cc.Mgr.MapDataMgr.getDataListByItemType(ItemType.EventData);
  360. for (var i = 0; i < EventList.length; i++) {
  361. var data = EventList[i];
  362. this.EventDataIdList[i] = data.Id;
  363. }
  364. cc.Mgr.initData = true;
  365. },
  366. //初始 天赋技能获得加成数据
  367. GetInitSkillBonus:function(skillList)
  368. {
  369. this.TreatBonus = 0; //治疗花费降低百分点
  370. this.WareHouseCapcityBonus = 0; //仓储加成
  371. this.CashBonus = 0; //金钱加成 每年加成
  372. this.CashRationBonus = 0;
  373. this.ReputationBonus = 0; //名声加成 每年
  374. this.HpPointBonus = 0; //健康加成
  375. this.RetireBonus = 0; //增加退休年限
  376. this.DateBonus = 0; //增加约会成功概率
  377. this.InitMoneyBonus = 0; //增加初始现金
  378. this.StockAddBonus = 0; //增加公司收益
  379. this.StockUpBonus = 0; //股票上涨 概率增加
  380. this.DateMoneyBonus = 0; //约会花费降低
  381. this.BetBonus = 0; //赌博赢钱概率上升
  382. this.SkillPointGetBonus = 0; //结算技能点提升
  383. this.ReputationInitBonus = 0; //初始名声加成
  384. this.CarBuyBonus = 0; //购买汽车价格降低
  385. this.EventCostBonus = 0; //事件消耗金钱降低
  386. this.HouseBuyBonuse = 0; //购买房屋 价格降低
  387. for (var i = 0; i < skillList.length; i++) {
  388. var data = skillList[i];
  389. //获得数据
  390. var bonus = cc.Mgr.MapDataMgr.getSkillAddBonusByTwoIdAndLv(data.Id, data.subId, data.level);
  391. ////cc.log(data.skillType + "++++++++++++初始技能加成+++++++++++"+bonus);
  392. switch (data.skillType) {
  393. case SkillType.WLNS:
  394. this.WareHouseCapcityBonus = bonus; //已經計算
  395. break;
  396. case SkillType.THY:
  397. this.DateBonus = bonus; //百分比 已經計算
  398. break;
  399. case SkillType.XSJY:
  400. this.CashRationBonus = bonus; //已经加入计算
  401. break;
  402. case SkillType.FGZJ:
  403. this.InitMoneyBonus = bonus; //已经计算
  404. break;
  405. case SkillType.GSGL:
  406. this.StockAddBonus = bonus; //百分百 已经计算
  407. break;
  408. case SkillType.TPGS:
  409. this.StockUpBonus = bonus; //百分比 已经计算
  410. break;
  411. case SkillType.JZCC:
  412. this.SkillPointGetBonus = bonus; //百分比 已經計算
  413. break;
  414. case SkillType.MLSZ:
  415. this.DateMoneyBonus = bonus; //百分比 一计算
  416. break;
  417. case SkillType.DS:
  418. this.BetBonus = bonus; //百分比 已經計算
  419. break;
  420. case SkillType.LDYZ:
  421. this.RetireBonus = bonus; //已經算進去
  422. break;
  423. case SkillType.NSCM:
  424. this.ReputationInitBonus = bonus; //已經計算
  425. break;
  426. case SkillType.QCDR:
  427. this.CarBuyBonus = bonus; //百分比 一計算
  428. break;
  429. case SkillType.HYLL:
  430. this.EventCostBonus = bonus; //百分比 一计算
  431. break;
  432. case SkillType.DCZJ:
  433. this.HouseBuyBonuse = bonus; //百分比 一計算
  434. break;
  435. }
  436. }
  437. },
  438. //获取每年都会获得的加成数额
  439. GetBonusRewardEveryYear:function () {
  440. // 包括 金钱 名声 健康值
  441. this.Cash += this.CashBonus;
  442. this.Cash = Math.floor(this.Cash * (1+this.CashRationBonus));
  443. if(this.Cash < 100)
  444. this.Cash = 0;
  445. this.Reputation += this.ReputationBonus;
  446. if(this.Reputation < 0)
  447. this.Reputation = 0;
  448. this.HpPoint += this.HpPointBonus;
  449. if(this.HpPoint > 100)
  450. {
  451. this.HpPoint = 100;
  452. }
  453. this.WareHouseCapcity += this.WareHouseBonusEveryYear;
  454. this.WareHouseAllCapcity += this.WareHouseBonusEveryYear;
  455. if(this.WareHouseCapcity > 200)
  456. this.WareHouseCapcity = 200;
  457. if(this.WareHouseAllCapcity > 200)
  458. this.WareHouseAllCapcity = 200;
  459. },
  460. //获取一次事件id 并从数列中剔除这个 Id
  461. GetEventDataAndSpliceId:function(){
  462. var len = this.EventDataIdList.length;
  463. //cc.log("11 事件数据剩余个数 = " + len);
  464. var seed = Math.floor(Math.random() * len);
  465. var out = this.EventDataIdList[seed];
  466. this.EventDataIdList.splice(seed, 1);
  467. //cc.log(out + " 事件数据剩余个数 = " + this.EventDataIdList.length);
  468. return out;
  469. },
  470. RefreshHistoryHighAsset:function(asset){
  471. this.HistoryHighAssets = asset;
  472. },
  473. //保存本地数据
  474. SaveUserData:function(){
  475. var userdata = {};
  476. userdata.playerName = this.playerName;
  477. userdata.Sex = this.Sex;
  478. userdata.SkillList = this.SkillList;
  479. //引导步骤
  480. userdata.tutorialInMarket = this.tutorialInMarket;
  481. userdata.tutorialInDate = this.tutorialInDate;
  482. userdata.tutorialInBus = this.tutorialInBus;
  483. userdata.tutorialStockBonus = this.tutorialStockBonus;
  484. userdata.tutorialMatePoint = this.tutorialMatePoint;
  485. userdata.HistoryHighAssets = this.HistoryHighAssets;
  486. userdata.VideoAdsTimes = this.VideoAdsTimes;
  487. userdata.VideoLastTime = this.VideoLastTime;
  488. userdata.playTimes = this.playTimes;
  489. userdata.AchievementList = this.AchievementList;
  490. userdata.RecordList = this.RecordList;
  491. userdata.SkillBonusPoint = this.SkillBonusPoint;
  492. cc.sys.localStorage.setItem('XMB_userdata',JSON.stringify(userdata));
  493. },
  494. CreateRecord:function(){
  495. var reD = new RecordStruct();
  496. var asLv = 0;
  497. var td = Math.floor(this.AssetsMoney / 1000000);
  498. if(td > 0 && td < 10)
  499. {
  500. asLv = 1;
  501. }
  502. else if(td > 10 && td < 100)
  503. {
  504. asLv = 2;
  505. }
  506. else if(td > 100)
  507. {
  508. asLv = 3;
  509. }
  510. reD.retireAge = this.Age;
  511. reD.level = asLv;
  512. reD.assets = this.AssetsMoney;
  513. reD.highAssets = this.HighAssets;
  514. this.RecordList.push(reD);
  515. //this.SaveUserData();
  516. },
  517. //升级技能点
  518. UpGradeSkill:function(Id, subId, toLv){
  519. var isOk = false;
  520. var NeedCost = cc.Mgr.MapDataMgr.getUpgradeCostByTwoId(Id, subId, toLv);
  521. if(this.SkillBonusPoint < NeedCost)
  522. return false;
  523. //不要求升级满技能即可升级下一个技能
  524. for (var i = 0; i < this.SkillList.length; i++) {
  525. if(this.SkillList[i].Id == Id && this.SkillList[i].subId + 1 == subId)
  526. {
  527. if(this.SkillList[i].level == 0)
  528. {
  529. //cc.log("上一个技能还没有升级到满级");
  530. return false;
  531. }
  532. //if(this.SkillList[i].level != this.SkillList[i].Uplv)
  533. //{
  534. //cc.log("上一个技能还没有升级到满级");
  535. // return false;
  536. //}
  537. }
  538. }
  539. for (var i = 0; i < this.SkillList.length; i++) {
  540. if(this.SkillList[i].Id ==Id && this.SkillList[i].subId == subId)
  541. {
  542. if(this.SkillList[i].level < this.SkillList[i].Uplv)
  543. {
  544. this.SkillList[i].level++;
  545. this.SkillBonusPoint -= NeedCost;
  546. isOk = true;
  547. }
  548. else
  549. {
  550. isOk = false;
  551. }
  552. break;
  553. }
  554. }
  555. return isOk;
  556. },
  557. CanShowUpTip:function(Id, subId, toLv){
  558. var isOk = false;
  559. var NeedCost = cc.Mgr.MapDataMgr.getUpgradeCostByTwoId(Id, subId, toLv);
  560. if(this.SkillBonusPoint < NeedCost)
  561. return false;
  562. for (var i = 0; i < this.SkillList.length; i++) {
  563. if(this.SkillList[i].Id == Id && this.SkillList[i].subId + 1 == subId)
  564. {
  565. if(this.SkillList[i].level == 0)
  566. {
  567. //cc.log("上一个技能还没有升级到满级");
  568. return false;
  569. }
  570. //if(this.SkillList[i].level != this.SkillList[i].Uplv)
  571. //{
  572. //cc.log("上一个技能还没有升级到满级");
  573. // return false;
  574. //}
  575. }
  576. }
  577. for (var i = 0; i < this.SkillList.length; i++) {
  578. if(this.SkillList[i].Id ==Id && this.SkillList[i].subId == subId)
  579. {
  580. if(this.SkillList[i].level < this.SkillList[i].Uplv)
  581. {
  582. isOk = true;
  583. }
  584. else
  585. {
  586. isOk = false;
  587. }
  588. break;
  589. }
  590. }
  591. return isOk;
  592. },
  593. //完成指定成就
  594. FinishAchievement:function(Id){
  595. var isOk = false;
  596. for (var i = 0; i < this.AchievementList.length; i++) {
  597. if(this.AchievementList[i].Id == Id)
  598. {
  599. this.AchievementList[i].hasFinish = true;
  600. isOk = true;
  601. break;
  602. }
  603. }
  604. return isOk;
  605. },
  606. //买入物品
  607. BuyGoods:function(data){ //data 包含 Id buyprire buynum
  608. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  609. if(data.Id == this.GoodsList[i].Id)
  610. {
  611. return this.GoodsList[i].RefeshDataAfterBuy(data);
  612. }
  613. }
  614. },
  615. //出售物品
  616. SaleGoods:function(data){
  617. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  618. if(data.Id == this.GoodsList[i].Id)
  619. {
  620. return this.GoodsList[i].RefeshDataAfterSale(data);
  621. }
  622. }
  623. },
  624. //创办公司
  625. CreateCompany:function(data){
  626. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  627. if(data.Id == this.CompanyList[i].Id)
  628. {
  629. return this.CompanyList[i].RefreshDataAfterOper(data);
  630. }
  631. }
  632. },
  633. //查看一下是否已经拥有五種物品
  634. CheckOwnedGoodsNum:function(){
  635. var Num = 0;
  636. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  637. if(this.GoodsList[i].ownNum > 0)
  638. {
  639. Num += 1;
  640. }
  641. }
  642. var Isfull = false;
  643. if(Num == 5)
  644. {
  645. Isfull = true;
  646. }
  647. return Isfull;
  648. },
  649. //购买股票
  650. BuyStocks:function(data){
  651. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  652. if(data.Id == this.CompanyList[i].Id)
  653. {
  654. return this.CompanyList[i].RefreshDataAfterOper(data);
  655. }
  656. }
  657. },
  658. //出售股票
  659. SaleStocks:function(data){
  660. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  661. if(data.Id == this.CompanyList[i].Id)
  662. {
  663. return this.CompanyList[i].RefreshDataAfterSale(data);
  664. }
  665. }
  666. },
  667. BuySaleCommonItem:function(data){
  668. //cc.log("=============" + data.Type + " Id = "+ data.Id)
  669. if(data.Type == ItemType.Car)
  670. {
  671. for (var i = this.CarList.length - 1; i >= 0; i--) {
  672. if(this.CarList[i].Id == data.Id)
  673. {
  674. this.CarList[i].RefreshData(data.addNum);
  675. }
  676. }
  677. }
  678. else if(data.Type == ItemType.House)
  679. {
  680. for (var i = this.HouseList.length - 1; i >= 0; i--) {
  681. if(this.HouseList[i].Id == data.Id)
  682. {
  683. this.HouseList[i].RefreshData(data.addNum);
  684. }
  685. }
  686. }
  687. },
  688. //刷新约会的亲密度
  689. RefreshMateData:function(Id){
  690. for (var i = this.MateList.length - 1; i >= 0; i--) {
  691. if(Id == this.MateList[i].Id)
  692. {
  693. return this.MateList[i].RefreshAfterLvUp();
  694. }
  695. }
  696. },
  697. //根據id解除婚姻
  698. DisvorceMateById:function(Id){
  699. for (var i = 0; i < this.MateList.length; i++) {
  700. if(this.MateList[i].Id == Id)
  701. {
  702. this.MateList[i].ReturnInitState();
  703. var data = cc.Mgr.MapDataMgr.getDataByItemTypeAndId(ItemType.Mate, Id);
  704. this.DeleteMateBonusReward(data.bonusList);
  705. //现金 股票减少 名声 健康受损
  706. this.Cash = Math.floor(this.Cash * 0.8);
  707. this.HpPoint = Math.floor(this.HpPoint * 0.8);
  708. this.Reputation = Math.floor(this.Reputation * 0.8);
  709. this.DisvorceDelStocks();
  710. break;
  711. }
  712. }
  713. },
  714. DisvorceDelStocks:function(){
  715. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  716. if(this.CompanyList[i].stockNum > 0)
  717. {
  718. this.CompanyList[i].RefreshDataAfterDisvorce();
  719. return;
  720. }
  721. }
  722. },
  723. //获得伴侣加成 结婚后获得
  724. getMateBonusReward:function(data){
  725. for (var i = 0; i < data.length; i++) {
  726. var dt = data[i];
  727. //cc.log("+++++++++++++++++++++oooooo+++++++++++++++++++++++" + dt.bonusNum);
  728. if(dt.bonusType == MateBonusType.NULL)
  729. {
  730. //cc.log("伴侣加成什么也没有");
  731. }
  732. else if(dt.bonusType == MateBonusType.HP)
  733. {
  734. this.HpPointBonus += dt.bonusNum;
  735. }
  736. else if(dt.bonusType == MateBonusType.Money)
  737. {
  738. this.CashBonus += dt.bonusNum;
  739. }
  740. else if(dt.bonusType == MateBonusType.Reputation)
  741. {
  742. this.ReputationBonus += dt.bonusNum;
  743. }
  744. else if(dt.bonusType == MateBonusType.WareHouseCapcity)
  745. {
  746. this.WareHouseCapcity += dt.bonusNum;
  747. this.WareHouseAllCapcity += dt.bonusNum;
  748. this.WareHouseBonusEveryYear += dt.bonusNum;
  749. if(this.WareHouseAllCapcity > 200)
  750. this.WareHouseAllCapcity = 200;
  751. if(this.WareHouseCapcity > 200)
  752. this.WareHouseCapcity = 200;
  753. }
  754. else if(dt.bonusType == MateBonusType.Treat)
  755. {
  756. this.TreatBonus += dt.bonusNum;
  757. }
  758. }
  759. },
  760. //移除伴侣获得的天赋加成
  761. DeleteMateBonusReward:function(data)
  762. {
  763. for (var i = 0; i < data.length; i++) {
  764. var dt = data[i];
  765. //cc.log("+++++++++++++++++++++oooooo+++++++++++++++++++++++" + dt.bonusNum);
  766. if(dt.bonusType == MateBonusType.NULL)
  767. {
  768. //cc.log("伴侣加成什么也没有");
  769. }
  770. else if(dt.bonusType == MateBonusType.HP)
  771. {
  772. this.HpPointBonus -= dt.bonusNum;
  773. }
  774. else if(dt.bonusType == MateBonusType.Money)
  775. {
  776. this.CashBonus -= dt.bonusNum;
  777. }
  778. else if(dt.bonusType == MateBonusType.Reputation)
  779. {
  780. this.ReputationBonus -= dt.bonusNum;
  781. if(this.ReputationBonus < 0)
  782. this.ReputationBonus = 0;
  783. }
  784. else if(dt.bonusType == MateBonusType.WareHouseCapcity)
  785. {
  786. //this.WareHouseCapcity -= dt.bonusNum;
  787. //this.WareHouseAllCapcity -= dt.bonusNum;
  788. this.WareHouseBonusEveryYear -= dt.bonusNum;
  789. if(this.WareHouseBonusEveryYear < 0)
  790. this.WareHouseBonusEveryYear = 0;
  791. }
  792. else if(dt.bonusType == MateBonusType.Treat)
  793. {
  794. this.TreatBonus -= dt.bonusNum;
  795. }
  796. }
  797. },
  798. getOwnDataListByType:function(itemType){
  799. var dataList = null;
  800. switch (itemType) {
  801. case ItemType.Goods:
  802. dataList = this.GoodsList;
  803. break;
  804. case ItemType.Skill:
  805. dataList = this.SkillList;
  806. break;
  807. case ItemType.Car:
  808. dataList = this.CarList;
  809. break;
  810. case ItemType.House:
  811. dataList = this.HouseList;
  812. break;
  813. case ItemType.Achieve:
  814. dataList = this.AchievementList;
  815. break;
  816. case ItemType.Company:
  817. dataList = this.CompanyList;
  818. break;
  819. case ItemType.Mate:
  820. dataList = this.MateList;
  821. break;
  822. }
  823. return dataList;
  824. },
  825. //获取已有数据 根据 类型和Id
  826. getDataByItemTypeAndId:function(itemType, Id){
  827. var dataList = null;
  828. switch (itemType) {
  829. case ItemType.Goods:
  830. dataList = this.GoodsList;
  831. break;
  832. case ItemType.Skill:
  833. dataList = this.SkillList;
  834. break;
  835. case ItemType.Car:
  836. dataList = this.CarList;
  837. break;
  838. case ItemType.House:
  839. dataList = this.HouseList;
  840. break;
  841. case ItemType.Achieve:
  842. dataList = this.AchievementList;
  843. break;
  844. case ItemType.Company:
  845. dataList = this.CompanyList;
  846. break;
  847. case ItemType.Mate:
  848. dataList = this.MateList;
  849. break;
  850. }
  851. if(dataList != null)
  852. {
  853. for (var i = dataList.length - 1; i >= 0; i--)
  854. {
  855. if(Id == dataList[i].Id)
  856. {
  857. return dataList[i];
  858. }
  859. }
  860. }
  861. //如果没有数据 为 null
  862. return null;
  863. },
  864. //刷新物品市场价格
  865. RefreshGoodsMarKetPrice:function(Id,marketPrice){
  866. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  867. if(Id == this.GoodsList[i].Id)
  868. {
  869. this.GoodsList[i].marketPrice = marketPrice;
  870. break;
  871. }
  872. }
  873. },
  874. //刷新股票商场价格和成本
  875. RefreshStockData:function(Id, param){
  876. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  877. if(Id == this.CompanyList[i].Id)
  878. {
  879. this.CompanyList[i].stockPrice = param.stockPrice;
  880. this.CompanyList[i].stockCost = param.stockCost;
  881. break;
  882. }
  883. }
  884. },
  885. //获取拥有的物品对应数据
  886. getGoodsDataById:function(Id){
  887. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  888. if(Id == this.GoodsList[i].Id)
  889. {
  890. return this.GoodsList[i];
  891. }
  892. }
  893. },
  894. //刷新个人资产 //caculateStock 是否計算股票收益
  895. RefreshUserAssets:function(caculateStock){
  896. var lastAsset = this.AssetsMoney;
  897. var assets = 0;
  898. //计算所拥有物品总价
  899. for (var i = this.GoodsList.length - 1; i >= 0; i--) {
  900. var data = this.GoodsList[i];
  901. var flag = this.CheckIdIsInShowList(data.Id);
  902. if(flag == true)
  903. {
  904. assets += data.ownNum * data.marketPrice;
  905. }
  906. else
  907. {
  908. assets += data.ownNum * data.buyPrice;
  909. }
  910. }
  911. //计算房屋拥有
  912. for (var i = this.HouseList.length - 1; i >= 0; i--) {
  913. var dt = this.HouseList[i];
  914. if(dt.ownNum > 0)
  915. {
  916. ////cc.log(dt.Id + " 房子的数量和价格 " + dt.ownNum + " " + dt.price);
  917. assets += dt.ownNum * dt.price;
  918. }
  919. }
  920. //计算车子所有
  921. for (var i = this.CarList.length - 1; i >= 0; i--) {
  922. var dt = this.CarList[i];
  923. if(dt.ownNum > 0)
  924. {
  925. assets += dt.ownNum * dt.price;
  926. }
  927. }
  928. //后面再加上 股票收益
  929. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  930. var da = this.CompanyList[i];
  931. if(da.stockNum > 0)
  932. {
  933. //this.Reputation += cc.Mgr.global.HasCompanyReputationAdd;
  934. assets += Math.floor(da.stockNum * da.stockPrice);
  935. if(this.CanGetStockProfit == true && caculateStock == true)
  936. {
  937. this.Cash += Math.floor(da.stockNum * da.stockPrice * (da.bonusRatio + (this.StockAddBonus / 100)));
  938. }
  939. }
  940. }
  941. assets += this.Cash;
  942. //资产暴涨时候健康迅速下降 暴涨5倍下降30
  943. this.AssetsMoney = assets;
  944. this.JudeFinishAnyAchievement(5); //成就 Id = 5 资产相关
  945. this.JudeFinishAnyAchievement(4); //成就 Id = 6
  946. cc.log(lastAsset + " L =========他妈的资产问题======== N " + assets);
  947. if(assets > this.HighAssets)
  948. {
  949. this.HighAssets = assets;
  950. }
  951. if(assets > 1000000 && this.MillionAge == 0)
  952. {
  953. this.MillionAge = this.Age;
  954. }
  955. if(assets > 10000000 && this.TenMillionAge == 0)
  956. {
  957. this.TenMillionAge = this.Age;
  958. }
  959. if(assets > 100000000 && this.HundredMillionAge == 0)
  960. {
  961. this.HundredMillionAge = this.Age;
  962. }
  963. if(Math.floor(assets / lastAsset) >= cc.Mgr.global.AssetExplorRate || (assets / lastAsset) <= cc.Mgr.global.AssetExplorDownRate)
  964. {
  965. if(this.userState == UserState.NotOK)
  966. return;
  967. this.HpPoint -= cc.Mgr.global.AssetBurden;
  968. if(this.HpPoint < cc.Mgr.global.HealthLine)
  969. {
  970. this.userState = UserState.NotOK;
  971. cc.Mgr.global.goToHospital += 1;
  972. this.RecoverYear = cc.Mgr.global.YearRecover;
  973. var param = {};
  974. param.forWhat = "HealthLine";
  975. param.text = cc.Mgr.global.getTranslation("RecoverHealth");
  976. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonTip, param);
  977. //this.UnLockMateByInHospital(MateUnLockType.InHospital, this.Sex);
  978. }
  979. else
  980. {
  981. var param = {};
  982. param.forWhat = "";
  983. param.text = cc.Mgr.global.getTranslation("RecoverHealthD");
  984. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonTip, param);
  985. }
  986. }
  987. },
  988. JudeFinishAnyAchievement:function (Id) {
  989. //cc.log(this.AchievementList.length + "======================判断成就是否完成" + Id);
  990. for (var i = 0; i < this.AchievementList.length; i++) {
  991. if(this.AchievementList[i].Id == Id)
  992. {
  993. if(this.AchievementList[i].hasFinish == true)
  994. {
  995. //cc.log("该成就已经完成了");
  996. return;
  997. }
  998. }
  999. }
  1000. var acD = cc.Mgr.MapDataMgr.getDataByItemTypeAndId(ItemType.Achieve, Id);
  1001. cc.log("======================判断成就是否完成 = " + acD.name);
  1002. var condList = acD.condList;
  1003. var finished = this.JudeCanFinishAchievementByCond(condList);
  1004. if(finished)
  1005. {
  1006. for (var i = 0; i < this.AchievementList.length; i++) {
  1007. if(this.AchievementList[i].Id == Id)
  1008. {
  1009. this.AchievementList[i].hasFinish = true;
  1010. return;
  1011. }
  1012. }
  1013. }
  1014. },
  1015. CaculateReputationFromCompany:function(){
  1016. //后面再加上 股票造成的
  1017. for (var i = this.CompanyList.length - 1; i >= 0; i--) {
  1018. var da = this.CompanyList[i];
  1019. if(da.stockNum > 0)
  1020. {
  1021. this.Reputation += cc.Mgr.global.HasCompanyReputationAdd;
  1022. return;
  1023. }
  1024. }
  1025. },
  1026. JudeCanFinishAchievementByCond:function(condList){
  1027. var finishedList = [];
  1028. for (var i = 0; i < condList.length; i++) {
  1029. var cond = condList[i];
  1030. var finished = false;
  1031. cc.log("类型要求 = " + cond.condType + " 数值要求 = " + cond.value);
  1032. switch (cond.condType) {
  1033. case AchieveCond.AssetMoneyUp:
  1034. finished = this.JudeAssetCond(cond.value);
  1035. break;
  1036. case AchieveCond.InHospital:
  1037. finished = this.JudegoToHosTimesCond(cond.value);
  1038. break;
  1039. case AchieveCond.Bankrupt:
  1040. finished = this.JudeBankruptTimesCond(cond.value);
  1041. break;
  1042. case AchieveCond.CreateBusiness:
  1043. finished = this.JudeCreateCompanyCond(cond.value);
  1044. break;
  1045. case AchieveCond.AgeCond:
  1046. finished = this.JudeAgeCond(cond.value);
  1047. break;
  1048. case AchieveCond.HasMarryCond:
  1049. finished = this.JudeHasMarryCond();
  1050. break;
  1051. case AchieveCond.LovePointCond:
  1052. finished = this.JudeLovePointCond(cond.value);
  1053. break;
  1054. case AchieveCond.AssetMoneyDown:
  1055. finished = this.JudeAssetDownCond(cond.value);
  1056. break;
  1057. case AchieveCond.NoMarryCond:
  1058. finished = this.JudeNotMarryCond(cond.value);
  1059. break;
  1060. case AchieveCond.AgeCondUp:
  1061. finished = this.JudeAgeCondUp(cond.value);
  1062. break;
  1063. }
  1064. cc.log("是否完成 = " + finished);
  1065. finishedList.push(finished);
  1066. }
  1067. for (var i = 0; i < finishedList.length; i++) {
  1068. if(finishedList[i] == false)
  1069. return false;
  1070. }
  1071. return true;
  1072. },
  1073. JudeAssetDownCond:function (value) {
  1074. if(this.AssetsMoney < value * 1000000)
  1075. return true;
  1076. else
  1077. return false;
  1078. },
  1079. //成就完成 资产限制
  1080. JudeAssetCond:function (value) {
  1081. if(this.AssetsMoney >= value * 1000000)
  1082. return true;
  1083. else
  1084. return false;
  1085. },
  1086. //成就完成 年龄限制 小于
  1087. JudeAgeCond:function (value) {
  1088. if(this.Age <= value)
  1089. return true;
  1090. else
  1091. return false;
  1092. },
  1093. JudeAgeCondUp:function(value){
  1094. if(this.Age >= value)
  1095. return true;
  1096. else
  1097. return false;
  1098. },
  1099. //成就完成 进医院次数
  1100. JudegoToHosTimesCond:function (value) {
  1101. if(cc.Mgr.global.goToHospital > value)
  1102. return true;
  1103. else
  1104. return false;
  1105. },
  1106. //成就完成 破产次数
  1107. JudeBankruptTimesCond:function (value) {
  1108. if(cc.Mgr.global.BankruptTimes > value)
  1109. return true;
  1110. else
  1111. return false;
  1112. },
  1113. //成就完成 创业次数
  1114. JudeCreateCompanyCond:function (value) {
  1115. if(cc.Mgr.global.CreateCompanyTimes > value)
  1116. return true;
  1117. else
  1118. return false;
  1119. },
  1120. //成就完成 是否已婚
  1121. JudeHasMarryCond:function () {
  1122. for (var i = 0; i < this.MateList.length; i++) {
  1123. if(this.MateList[i].LovePoint == 100)
  1124. {
  1125. return true;
  1126. }
  1127. }
  1128. return false;
  1129. },
  1130. JudeHasCar:function(){
  1131. for (var i = this.CarList.length - 1; i >= 0; i--) {
  1132. if(this.CarList[i].ownNum > 0)
  1133. {
  1134. return true;
  1135. }
  1136. }
  1137. return false;
  1138. },
  1139. JudeHasCarById:function(Id){
  1140. for (var i = this.CarList.length - 1; i >= 0; i--) {
  1141. if(this.CarList[i].ownNum > 0 && this.CarList[i].Id == Id)
  1142. {
  1143. return true;
  1144. }
  1145. }
  1146. return false;
  1147. },
  1148. JudeHasHouse:function(){
  1149. for (var i = this.HouseList.length - 1; i >= 0; i--) {
  1150. if(this.HouseList[i].ownNum > 0)
  1151. {
  1152. return true;
  1153. }
  1154. }
  1155. return false;
  1156. },
  1157. JudeHasHouseById:function(Id){
  1158. for (var i = this.HouseList.length - 1; i >= 0; i--) {
  1159. if(this.HouseList[i].ownNum > 0 && this.HouseList[i].Id == Id)
  1160. {
  1161. return true;
  1162. }
  1163. }
  1164. return false;
  1165. },
  1166. //成就完成 是否未婚
  1167. JudeNotMarryCond:function () {
  1168. for (var i = 0; i < this.MateList.length; i++) {
  1169. if(this.MateList[i].LovePoint == 100)
  1170. {
  1171. return false;
  1172. }
  1173. }
  1174. return true;
  1175. },
  1176. //成就完成 亲密度人数
  1177. JudeLovePointCond:function(value){
  1178. var num = 0;
  1179. for (var i = 0; i < this.MateList.length; i++) {
  1180. if(this.MateList[i].LovePoint == 99)
  1181. {
  1182. num += 1;
  1183. }
  1184. }
  1185. if(num >= value)
  1186. return true;
  1187. else
  1188. return false;
  1189. },
  1190. //刷新用户年龄
  1191. RefreshUserAge:function(){
  1192. this.Age += 1;
  1193. if(this.Age == (this.retireAge + 1) && cc.Mgr.global.useRetireAds == false)
  1194. {
  1195. cc.director.GlobalEvent.emit(cc.Mgr.Event.UseRetireAdsSkill, {});
  1196. }
  1197. else if(this.Age > this.retireAge && cc.Mgr.global.useRetireAds == true)
  1198. {
  1199. cc.director.GlobalEvent.emit(cc.Mgr.Event.Retire, {});
  1200. }
  1201. this.CaculateReputationFromCompany();
  1202. },
  1203. //刷新个人健康指数
  1204. RefreshHealthHp:function(){
  1205. if(this.RecoverYear > 0 && this.userState == UserState.NotOK)
  1206. {
  1207. this.RecoverYear -= 1;
  1208. return;
  1209. }
  1210. else if(this.RecoverYear == 0 && this.userState == UserState.NotOK)
  1211. {
  1212. this.RecoverYear = 0;
  1213. this.userState = UserState.OK;
  1214. this.HpPoint = 100;
  1215. return;
  1216. }
  1217. if(this.Age >= cc.Mgr.global.HealthSubAge && this.HpPoint > 0)
  1218. {
  1219. var seed = 2 + Math.floor(Math.random()*3);
  1220. this.HpPoint -= seed;
  1221. if(this.HpPoint < cc.Mgr.global.HealthLine)
  1222. {
  1223. this.userState = UserState.NotOK;
  1224. cc.Mgr.global.goToHospital += 1;
  1225. this.RecoverYear = cc.Mgr.global.YearRecover;
  1226. var param = {};
  1227. param.forWhat = "HealthLine";
  1228. param.text = cc.Mgr.global.getTranslation("RecoverHealth");
  1229. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonTip, param);
  1230. //this.UnLockMateByInHospital(MateUnLockType.InHospital, this.Sex);
  1231. }
  1232. }
  1233. },
  1234. //技能天赋数据获取
  1235. getSkillDataByTwoId:function(Id, subId){
  1236. var dt = null;
  1237. for (var i = this.SkillList.length - 1; i >= 0; i--) {
  1238. var data = this.SkillList[i];
  1239. if(data.Id == Id && data.subId == subId)
  1240. {
  1241. dt = data;
  1242. return data;
  1243. }
  1244. }
  1245. return dt;
  1246. },
  1247. getSkillListById:function(Id){
  1248. var param = [];
  1249. for (var i = this.SkillList.length - 1; i >= 0; i--) {
  1250. var data = this.SkillList[i];
  1251. if(data.Id == Id)
  1252. {
  1253. param.push(data);
  1254. }
  1255. }
  1256. return param;
  1257. },
  1258. //花销和获得根据
  1259. GetOrCostDataByRewardType:function(rewardType, num, subId) //对于物品 会有一个subId
  1260. {
  1261. var Pdata = {};
  1262. Pdata.Id = -1;
  1263. Pdata.companyId = -1;
  1264. //cc.log("++++++rewardType++++++" + rewardType);
  1265. if(rewardType == RewardType.NULL)
  1266. {
  1267. //cc.log("啥也没有");
  1268. }
  1269. else if(rewardType == RewardType.Cash)
  1270. {
  1271. if(num < 0) //好运连连
  1272. {
  1273. num = num + Math.floor((-num)* this.EventCostBonus);
  1274. }
  1275. else
  1276. {
  1277. num + Math.floor(num* this.EventCostBonus);
  1278. }
  1279. this.Cash += num;
  1280. if(this.Cash < 0)
  1281. this.Cash = 0;
  1282. }
  1283. else if(rewardType == RewardType.HP)
  1284. {
  1285. this.HpPoint += num;
  1286. if(this.HpPoint >100)
  1287. this.HpPoint =100;
  1288. }
  1289. else if(rewardType == RewardType.Reputation)
  1290. {
  1291. this.Reputation += num;
  1292. if(this.Reputation < 0)
  1293. this.Reputation = 0;
  1294. }
  1295. else if(rewardType == RewardType.Goods)
  1296. {
  1297. for (var i = 0; i < this.GoodsList.length; i++) {
  1298. if(this.GoodsList[i].Id == subId)
  1299. {
  1300. if(this.WareHouseCapcity >= num)
  1301. {
  1302. var averagePrice = Math.floor((this.GoodsList[i].buyPrice * this.GoodsList[i].ownNum) / (this.GoodsList[i].ownNum + num));
  1303. this.GoodsList[i].ownNum += num;
  1304. //仓库减少数值
  1305. this.WareHouseCapcity -= num;
  1306. Pdata.Id = subId;
  1307. Pdata.buyPrice = averagePrice;//this.GoodsList[i].buyPrice;
  1308. Pdata.ownNum = this.GoodsList[i].ownNum;
  1309. }
  1310. break;
  1311. }
  1312. }
  1313. }
  1314. else if(rewardType == RewardType.Car)
  1315. {
  1316. for (var i = 0; i < this.CarList.length; i++) {
  1317. if(this.CarList[i].Id == subId)
  1318. {
  1319. this.CarList[i].ownNum += num;
  1320. this.Reputation += this.CarList[i].addBonus;
  1321. this.HpPoint += this.CarList[i].addHp;
  1322. if(this.HpPoint > 100)
  1323. this.HpPoint = 100;
  1324. break;
  1325. }
  1326. }
  1327. }
  1328. else if(rewardType == RewardType.House)
  1329. {
  1330. for (var i = 0; i < this.HouseList.length; i++) {
  1331. if(this.HouseList[i].Id == subId)
  1332. {
  1333. this.HouseList[i].ownNum += num;
  1334. this.Reputation += this.HouseList[i].addBonus;
  1335. this.HpPoint += this.HouseList[i].addHp;
  1336. if(this.HpPoint > 100)
  1337. this.HpPoint = 100;
  1338. break;
  1339. }
  1340. }
  1341. }
  1342. else if(rewardType == RewardType.Stock)
  1343. {
  1344. for (var i = 0; i < this.CompanyList.length; i++) {
  1345. if(this.CompanyList[i].Id == subId)
  1346. {
  1347. this.CompanyList[i].stockNum += num;
  1348. Pdata.companyId = subId;
  1349. break;
  1350. }
  1351. }
  1352. }
  1353. else if(rewardType == RewardType.StockPrice)
  1354. {
  1355. for (var i = 0; i < this.CompanyList.length; i++) {
  1356. if(this.CompanyList[i].Id == subId)
  1357. {
  1358. if(this.CompanyList[i].stockNum > 0)
  1359. {
  1360. this.CompanyList[i].stockPrice += num;
  1361. Pdata.companyId = subId;
  1362. break;
  1363. }
  1364. }
  1365. }
  1366. }
  1367. return Pdata;
  1368. },
  1369. //判断是否有房
  1370. JudeHasHouse:function(value){
  1371. var flag = false;
  1372. if(value == 0)
  1373. {
  1374. for (var i = 0; i < this.HouseList.length; i++) {
  1375. if(this.HouseList[i].ownNum > 0)
  1376. {
  1377. return true;
  1378. }
  1379. }
  1380. }
  1381. else
  1382. {
  1383. for (var i = 0; i < this.HouseList.length; i++) {
  1384. if(this.HouseList[i].ownNum > 0 && value == this.HouseList[i].Id)
  1385. {
  1386. return true;
  1387. }
  1388. }
  1389. }
  1390. return flag;
  1391. },
  1392. //判断是否有车
  1393. JudeHasCar:function(value){
  1394. var flag = false;
  1395. if(value == 0)
  1396. {
  1397. for (var i = 0; i < this.CarList.length; i++) {
  1398. if(this.CarList[i].ownNum > 0)
  1399. {
  1400. return true;
  1401. }
  1402. }
  1403. }
  1404. else
  1405. {
  1406. for (var i = 0; i < this.CarList.length; i++) {
  1407. if(this.CarList[i].ownNum > 0 && this.CarList[i].Id == value)
  1408. {
  1409. return true;
  1410. }
  1411. }
  1412. }
  1413. return flag;
  1414. },
  1415. //判断资产是否满足一定要求
  1416. JudeAsset:function(needNum)
  1417. {
  1418. var flag = false;
  1419. if(needNum <= this.AssetsMoney)
  1420. {
  1421. return true;
  1422. }
  1423. return flag;
  1424. },
  1425. //判断名声是否满足要求
  1426. JudeReputation:function(needNum){
  1427. var flag = false;
  1428. if(needNum <= this.Reputation)
  1429. {
  1430. return true;
  1431. }
  1432. return flag;
  1433. },
  1434. //判断健康是否满足要求
  1435. JudeHpPoint:function(needNum){
  1436. var flag = false;
  1437. if(needNum <= this.HpPoint)
  1438. {
  1439. return true;
  1440. }
  1441. return flag;
  1442. },
  1443. //判断是否有公司
  1444. JudeHasCompany:function(){
  1445. return this.hasCompany;
  1446. },
  1447. //开放该条件下的一个 可约会对象
  1448. UnLockOneMate:function(unlockCond, offSex){
  1449. var Id = -1;
  1450. for (var i = 0; i < this.MateList.length; i++) {
  1451. //var dt = cc.Mgr.MapDataMgr.getDataByItemTypeAndId(ItemType.Mate , this.MateList[i].Id);
  1452. if(this.MateList[i].sex == offSex && this.MateList[i].canDate == false && this.MateList[i].unlockCond == unlockCond)
  1453. {
  1454. this.MateList[i].canDate = true;
  1455. Id = this.MateList[i].Id;
  1456. var param = {};
  1457. param.icon = this.MateList[i].icon;
  1458. param.des = cc.Mgr.global.getTranslation("UnLockMate_" + Id);
  1459. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenUnLockMate, param);
  1460. return Id;
  1461. }
  1462. }
  1463. return Id;
  1464. },
  1465. UnLockMateByInHospital:function(unlockCond, offSex){
  1466. var Id = -1;
  1467. for (var i = 0; i < this.MateList.length; i++) {
  1468. //var dt = cc.Mgr.MapDataMgr.getDataByItemTypeAndId(ItemType.Mate , this.MateList[i].Id);
  1469. if(this.MateList[i].sex == offSex && this.MateList[i].canDate == false && this.MateList[i].unlockCond == unlockCond)
  1470. {
  1471. this.MateList[i].canDate = true;
  1472. Id = this.MateList[i].Id;
  1473. var param = {};
  1474. param.icon = this.MateList[i].icon;
  1475. param.des = cc.Mgr.global.getTranslation("UnLockMateByInHos");
  1476. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenUnLockMate, param);
  1477. return Id;
  1478. }
  1479. }
  1480. return Id;
  1481. },
  1482. //判断是否已经拥有一个伴侣
  1483. JudeHasAnyMate:function(){
  1484. var flag = false;
  1485. for (var i = 0; i < this.MateList.length; i++) {
  1486. //cc.log("是否已经结婚了 "+ this.MateList[i].Uplv);
  1487. if(this.MateList[i].UpLv == true)
  1488. {
  1489. flag = true;
  1490. return flag;
  1491. }
  1492. }
  1493. return flag;
  1494. },
  1495. });
  1496. module.exports = UserDataMgr