UserInfo.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. const GameModule = require("../utils/GameModule");
  2. const DWTool = require("../utils/DWTool");
  3. const Api = require('../net/Api');
  4. const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
  5. const TapTapTool = require("../utils/TapTapTool");
  6. // var cityList = require('../data/city');
  7. // const BuildingModel = require('./utils/BuildingModel');
  8. // const AlertManager = require('./utils/AlertManager');
  9. // const ReportType = require("./utils/GameEnum").ReportType;
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. _reportFailDuration: 0,
  14. grossIncomeLabel: cc.Label,
  15. grossCoin: sp.Skeleton,
  16. grossIncomeRichText: cc.RichText,
  17. rateRichText: cc.RichText,
  18. clickCoinRichText: cc.RichText,
  19. rateCoinRichText: cc.RichText,
  20. headSprite: cc.Sprite,
  21. starsLabel: cc.Label,
  22. starsProgress: cc.ProgressBar,
  23. diamondLabel: cc.Label,
  24. recordModify: [],
  25. recordUnlockModify: [],
  26. _stars: 0,
  27. stars: {
  28. get: function () {
  29. return this._stars;
  30. },
  31. set: function (value) {
  32. console.log('星星增加数 ' + value);
  33. this._stars = value;
  34. }
  35. },
  36. _gold: 0,
  37. gold: {
  38. get: function () {
  39. return this._gold;
  40. },
  41. set: function (value) {
  42. this._gold = value;
  43. this.grossIncomeRichText.string = `<outline color=#ffffff width=3><color=#009100>${TapTapTool.parseToString(this._gold)}</c></outline>`;
  44. }
  45. },
  46. //建筑每秒自动生成的金币数
  47. _rateGold: 0,
  48. rateGold: {
  49. get: function () {
  50. return this._rateGold;
  51. },
  52. set: function (value) {
  53. this._rateGold = value;
  54. if (this._rateGold.n > 0) {
  55. this.rateRichText.node.active = true;
  56. let rate = TapTapTool.multiple(GameModule.skill.multiple, this.perpetualMt);
  57. let newValue = TapTapTool.multiple(rate, this._rateGold);
  58. this.rateRichText.string = `<outline color=#ffffff width=3><color=#009100>+${TapTapTool.parseToString(newValue)}</c></outline>`;
  59. this.rateCoinRichText.string = `<b>${TapTapTool.parseToString(newValue)}</b>`;
  60. } else {
  61. this.rateRichText.node.active = false;
  62. this.rateCoinRichText.string = "<b>0</b>";
  63. }
  64. }
  65. },
  66. //自动每次点击需要的秒数
  67. _secondClick: 0,
  68. secondClick: {
  69. get: function () {
  70. return this._secondClick;
  71. },
  72. set: function (value) {
  73. this._secondClick = value < 0 ? 0 : parseFloat(value);
  74. this.unschedule(this.autoClickGetGold, this);
  75. if (this._secondClick > 0) {
  76. this.schedule(this.autoClickGetGold, this._secondClick);
  77. }
  78. }
  79. },
  80. _diamond: 0,
  81. diamond: {
  82. get: function () {
  83. return this._diamond;
  84. },
  85. set: function (value) {
  86. this._diamond = value;
  87. this.diamondLabel.string = this._diamond;
  88. }
  89. },
  90. _clickCount: 0,
  91. clickCount: {
  92. get: function () {
  93. return this._clickCount;
  94. },
  95. set: function (value) {
  96. this._clickCount = value;
  97. }
  98. },
  99. _buyStarCount: 0,
  100. buyStarCount: {
  101. get: function () {
  102. return this._buyStarCount;
  103. },
  104. set: function (value) {
  105. this._buyStarCount = value;
  106. }
  107. },
  108. _buildingLevel: 1,
  109. buildingLevel: {
  110. get: function () {
  111. return this._buildingLevel;
  112. },
  113. set: function (value) {
  114. this._buildingLevel = value;
  115. // 把用户的总部等级上报给微信
  116. DWTool.submitWechatScore(this._buildingLevel);
  117. }
  118. },
  119. // //获得奖励的永久产出倍数
  120. // perpetualMt: {
  121. // default: 1,
  122. // visible: false,
  123. // type: cc.Float
  124. // },
  125. // //获得奖励的永久点击倍数
  126. // perpetualClickMt: {
  127. // default: 1,
  128. // visible: false,
  129. // type: cc.Float
  130. // },
  131. //入驻在建筑的明星加成倍数
  132. // starMt: {
  133. // default: 1,
  134. // visible: false,
  135. // type: cc.Float
  136. // },
  137. levelHomeItemFullCount: 0
  138. },
  139. onLoad() {
  140. GameModule.userInfo = this;
  141. this._rate = 0;
  142. this._isPlayAnimation = false;
  143. this.seq = 1;
  144. this._rateGold = {'n': 0, 'e': 0};
  145. this._gold = {'n': 0, 'e': 0};
  146. this.coinTap = {'n': 0, 'e': 0};
  147. this.buildingLevel = Global.userData.buildingLevel;
  148. // let objc = TapTapTool.goldStrToClass('3.265;29');
  149. // let str = TapTapTool.parseToString(objc);
  150. // let sub = TapTapTool.compare({'n': 323, 'e': 25}, objc);
  151. // console.log(sub);
  152. // console.log(str);
  153. // 初始化用户信息
  154. this.initUserInfo();
  155. // 轮询上报游戏数据
  156. this.reportFunc = () => {
  157. if (this._reportFailDuration > 0) {
  158. this._reportFailDuration -= 3;
  159. return;
  160. }
  161. this.doReport();
  162. };
  163. this.schedule(this.reportFunc, 3.0);
  164. //建筑每秒自动赚的钱
  165. this.addMoneyFunc = () => {
  166. this.buildingAddMoney();
  167. };
  168. this.schedule(this.addMoneyFunc, 1.0);
  169. },
  170. /**
  171. * 每秒增加金币
  172. */
  173. buildingAddMoney() {
  174. if (this.rateGold.n > 0) {
  175. // this.gold = TapTapTool.add(this.rateGold, this.gold);
  176. let add = TapTapTool.multiple(this.rateGold, GameModule.skill.multiple);
  177. this.gold = TapTapTool.add(this.gold, TapTapTool.multiple(add, this.perpetualMt));
  178. // this.gold += (this.rateGold * GameModule.skill.multiple * this.perpetualMt);
  179. this.secondRateTextAnimation();
  180. }
  181. },
  182. secondRateTextAnimation() {
  183. let fadeIn = cc.fadeIn(0.2);
  184. let delay = cc.delayTime(0.3);
  185. let fadeOut = cc.fadeOut(0.3);
  186. let action = cc.sequence(fadeIn, delay, fadeOut);
  187. this.rateRichText.node.runAction(action);
  188. },
  189. refreshSecondText() {
  190. if (this._rateGold.n > 0) {
  191. this.rateRichText.node.active = true;
  192. let rate = TapTapTool.multiple(GameModule.skill.multiple, this.perpetualMt);
  193. let newValue = TapTapTool.multiple(rate, this._rateGold);
  194. this.rateRichText.string = `<outline color=#ffffff width=3><color=#009100>+${TapTapTool.parseToString(newValue)}</c></outline>`;
  195. this.rateCoinRichText.string = `<b>${TapTapTool.parseToString(newValue)}</b>`;
  196. } else {
  197. this.rateRichText.node.active = false;
  198. }
  199. if (GameModule.userInfo.coinTap.n > 0) {
  200. this.clickCoinRichText.string = `<b>${TapTapTool.parseToString(GameModule.userInfo.coinTap)}</b>`;
  201. } else {
  202. this.clickCoinRichText.string = "<b>0</b>";
  203. }
  204. },
  205. /**
  206. * 每秒自动点击次数
  207. */
  208. autoClickGetGold() {
  209. GameEvent.fire(GameNotificationKey.AutoClickGold);
  210. },
  211. /**
  212. * 上报用户数据
  213. */
  214. doReport() {
  215. // return;
  216. let goldStr = this._gold.n + ";" + this._gold.e;
  217. DWTool.reportInfo(this.seq, goldStr, this.stars, this.clickCount, this.recordModify, this.recordUnlockModify)
  218. .then(() => {
  219. this._reportFailDuration = 0;
  220. this.recordModify = [];
  221. this.recordUnlockModify = [];
  222. this.seq += 1;
  223. }).catch(err => {
  224. if (err.code === -4) {
  225. this._reportFailDuration = 60;
  226. }
  227. console.log('上报失败 ' + err.msg);
  228. })
  229. },
  230. /**
  231. * 初始化用户数据
  232. */
  233. initUserInfo() {
  234. let userInfo = this.userInfo = Global.userData;
  235. if (userInfo != undefined) {
  236. this.updateUserRes({
  237. gold: userInfo.goldObj,
  238. stars: userInfo.ogStars,
  239. diamond: userInfo.diamond,
  240. ticket: userInfo.ticket,
  241. clickCount: userInfo.clickCount
  242. });
  243. this.perpetualMt = userInfo.mtObj;
  244. this.perpetualClickMt = userInfo.clickMtObj;
  245. this.buyStarCount = userInfo.buyStarCount;
  246. }
  247. },
  248. /**
  249. * 更新用户资源数据
  250. * @param {object} data 更新资源对象
  251. * @param {number} data.grossIncome 增加的金币
  252. * @param {number} data.stars 星星
  253. * @param {number} data.diamond 钻石
  254. * @param {number} data.ticket 艺人券
  255. */
  256. updateUserRes(data) {
  257. console.log("Update userData: ", JSON.stringify(data));
  258. if (data.gold) {
  259. this.gold = TapTapTool.add(data.gold, this.gold);
  260. }
  261. if (data.stars) {
  262. this.stars += parseInt(data.stars);
  263. }
  264. if (data.diamond) {
  265. this.diamond += parseInt(data.diamond);
  266. }
  267. if (data.ticket) {
  268. this.ticket += parseInt(data.ticket);
  269. }
  270. if (data.clickCount) {
  271. this.clickCount += parseInt(data.clickCount);
  272. }
  273. },
  274. updateRecordModify(buildingInfo) {
  275. for (let i = 0; i < this.recordModify.length; i++) {
  276. let temp = this.recordModify[i];
  277. if (buildingInfo.roomId == temp.roomId) {
  278. this.recordModify.splice(i, 1, buildingInfo);
  279. return;
  280. }
  281. }
  282. this.recordModify.push(buildingInfo);
  283. }
  284. });