1
0

UserInfo.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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('11.196;68');
  149. // let str = TapTapTool.parseToString(objc);
  150. // console.log(str);
  151. // 初始化用户信息
  152. this.initUserInfo();
  153. // 轮询上报游戏数据
  154. this.reportFunc = () => {
  155. if (this._reportFailDuration > 0) {
  156. this._reportFailDuration -= 3;
  157. return;
  158. }
  159. this.doReport();
  160. };
  161. this.schedule(this.reportFunc, 3.0);
  162. //建筑每秒自动赚的钱
  163. this.addMoneyFunc = () => {
  164. this.buildingAddMoney();
  165. };
  166. this.schedule(this.addMoneyFunc, 1.0);
  167. },
  168. /**
  169. * 每秒增加金币
  170. */
  171. buildingAddMoney() {
  172. if (this.rateGold.n > 0) {
  173. // this.gold = TapTapTool.add(this.rateGold, this.gold);
  174. let add = TapTapTool.multiple(this.rateGold, GameModule.skill.multiple);
  175. this.gold = TapTapTool.add(this.gold, TapTapTool.multiple(add, this.perpetualMt));
  176. // this.gold += (this.rateGold * GameModule.skill.multiple * this.perpetualMt);
  177. this.secondRateTextAnimation();
  178. }
  179. },
  180. secondRateTextAnimation() {
  181. let fadeIn = cc.fadeIn(0.2);
  182. let delay = cc.delayTime(0.3);
  183. let fadeOut = cc.fadeOut(0.3);
  184. let action = cc.sequence(fadeIn, delay, fadeOut);
  185. this.rateRichText.node.runAction(action);
  186. },
  187. refreshSecondText() {
  188. if (this._rateGold.n > 0) {
  189. this.rateRichText.node.active = true;
  190. let rate = TapTapTool.multiple(GameModule.skill.multiple, this.perpetualMt);
  191. let newValue = TapTapTool.multiple(rate, this._rateGold);
  192. this.rateRichText.string = `<outline color=#ffffff width=3><color=#009100>+${TapTapTool.parseToString(newValue)}</c></outline>`;
  193. this.rateCoinRichText.string = `<b>${TapTapTool.parseToString(newValue)}</b>`;
  194. } else {
  195. this.rateRichText.node.active = false;
  196. }
  197. if (GameModule.userInfo.coinTap.n > 0) {
  198. this.clickCoinRichText.string = `<b>${TapTapTool.parseToString(GameModule.userInfo.coinTap)}</b>`;
  199. } else {
  200. this.clickCoinRichText.string = "<b>0</b>";
  201. }
  202. },
  203. /**
  204. * 每秒自动点击次数
  205. */
  206. autoClickGetGold() {
  207. GameEvent.fire(GameNotificationKey.AutoClickGold);
  208. },
  209. /**
  210. * 上报用户数据
  211. */
  212. doReport() {
  213. // return;
  214. let goldStr = this._gold.n + ";" + this._gold.e;
  215. DWTool.reportInfo(this.seq, goldStr, this.stars, this.clickCount, this.recordModify, this.recordUnlockModify)
  216. .then(() => {
  217. this._reportFailDuration = 0;
  218. this.recordModify = [];
  219. this.recordUnlockModify = [];
  220. this.seq += 1;
  221. }).catch(err => {
  222. if (err.code === -4) {
  223. this._reportFailDuration = 60;
  224. }
  225. console.log('上报失败 ' + err.msg);
  226. })
  227. },
  228. /**
  229. * 初始化用户数据
  230. */
  231. initUserInfo() {
  232. let userInfo = this.userInfo = Global.userData;
  233. if (userInfo != undefined) {
  234. this.updateUserRes({
  235. gold: userInfo.goldObj,
  236. stars: userInfo.ogStars,
  237. diamond: userInfo.diamond,
  238. ticket: userInfo.ticket,
  239. clickCount: userInfo.clickCount
  240. });
  241. this.perpetualMt = userInfo.mtObj;
  242. this.perpetualClickMt = userInfo.clickMtObj;
  243. this.buyStarCount = userInfo.buyStarCount;
  244. }
  245. },
  246. /**
  247. * 更新用户资源数据
  248. * @param {object} data 更新资源对象
  249. * @param {number} data.grossIncome 增加的金币
  250. * @param {number} data.stars 星星
  251. * @param {number} data.diamond 钻石
  252. * @param {number} data.ticket 艺人券
  253. */
  254. updateUserRes(data) {
  255. console.log("Update userData: ", JSON.stringify(data));
  256. if (data.gold) {
  257. this.gold = TapTapTool.add(data.gold, this.gold);
  258. }
  259. if (data.stars) {
  260. this.stars += parseInt(data.stars);
  261. }
  262. if (data.diamond) {
  263. this.diamond += parseInt(data.diamond);
  264. }
  265. if (data.ticket) {
  266. this.ticket += parseInt(data.ticket);
  267. }
  268. if (data.clickCount) {
  269. this.clickCount += parseInt(data.clickCount);
  270. }
  271. },
  272. updateRecordModify(buildingInfo) {
  273. for (let i = 0; i < this.recordModify.length; i++) {
  274. let temp = this.recordModify[i];
  275. if (buildingInfo.roomId == temp.roomId) {
  276. this.recordModify.splice(i, 1, buildingInfo);
  277. return;
  278. }
  279. }
  280. this.recordModify.push(buildingInfo);
  281. }
  282. });