InvestData.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import Main from "../Main"
  2. import GameM from "../manager/GameM"
  3. import UiM from "../manager/UiM"
  4. import Invest from "../ui/Invest"
  5. import LogUtil from "../utils/LogUtil"
  6. import { HTTP_TYPE } from "./CommonData"
  7. /** 投资数据类 */
  8. export default class InvestData {
  9. private static instance: InvestData = null
  10. static get Instance(): InvestData {
  11. if (!InvestData.instance) {
  12. InvestData.instance = new InvestData()
  13. }
  14. return InvestData.instance
  15. }
  16. /** 看视频item */
  17. investItem = null
  18. /** 投资数据*/
  19. investData = []
  20. /** 视频加速投资时间 百分比减少*/
  21. investVideoTime = 0.5
  22. /** 加速卡加速投资时间 单位:s*/
  23. investCardTime = 3
  24. /** 剩余投资次数 */
  25. SurplusTimes = 0
  26. getInvestInfo() {
  27. let data = {}
  28. GameM.httpM.sendDatas(HTTP_TYPE.getInvestInfo, data, InvestData.Instance.getInvestInfoBack.bind(this))
  29. }
  30. getInvestInfoBack(data) {
  31. // LogUtil.logV('getInvestInfoBack ', data.InvestData)
  32. this.investData = data.InvestData
  33. this.SurplusTimes = data.SurplusTimes
  34. GameM.commonData.gameTime = data.timestamp * 1000
  35. this.freshRed()
  36. if (UiM.Instance.InvestNode) {
  37. UiM.Instance.InvestNode.getComponent(Invest).init(true)
  38. }
  39. }
  40. /**更新投资
  41. * @param index 投资Index
  42. * @param investMentType 更新类型 0.可投资(领取) 1.倒计时(投资) 2.可领取(投资完成)
  43. **/
  44. updateInvestProject(index, investMentType) {
  45. let data = {
  46. 'index': index,
  47. 'investMentType': investMentType
  48. }
  49. LogUtil.logV('updateInvestProject ', data)
  50. GameM.httpM.sendDatas(HTTP_TYPE.updateInvestProject, data, InvestData.Instance.updateInvestProjectBack.bind(this))
  51. }
  52. /** 更新投资返回 */
  53. updateInvestProjectBack(data, param) {
  54. this.investData = data.InvestData
  55. this.SurplusTimes = data.SurplusTimes
  56. GameM.commonData.gameTime = data.timestamp * 1000
  57. LogUtil.logV('updateInvestProjectBack ', data)
  58. this.freshRed()
  59. let invest = UiM.Instance.InvestNode.getComponent(Invest)
  60. if (param.investMentType == 0) {
  61. invest.onGetGold(param.index)
  62. }
  63. else if (param.investMentType == 1) {
  64. GameM.commonData.roleData.investTotal++
  65. GameM.commonData.updateRoleData()
  66. }
  67. invest.init(false)
  68. }
  69. /** 减少投资时间
  70. * @param index 投资Index
  71. * @param reduceTimeType 减少类型 1.减10分钟 2.减少50%
  72. */
  73. reduceTimeInvestProject(index, reduceTimeType) {
  74. let data = {
  75. 'index': index,
  76. 'reduceTimeType': reduceTimeType
  77. }
  78. LogUtil.logV('reduceTimeInvestProject ', data)
  79. GameM.httpM.sendDatas(HTTP_TYPE.reduceTimeInvestProject, data, InvestData.Instance.reduceTimeInvestProjectBack.bind(this))
  80. }
  81. /** 减少投资时间返回 */
  82. reduceTimeInvestProjectBack(data) {
  83. this.investData = data.InvestData
  84. GameM.commonData.gameTime = data.timestamp * 1000
  85. LogUtil.logV('reduceTimeInvestProjectBack ', data)
  86. UiM.Instance.InvestNode.getComponent(Invest).init(false)
  87. }
  88. /** 检查是否有投资项 */
  89. checkHasInvest() {
  90. let has = false
  91. let len = this.investData.length
  92. for (var i = 0; i < len; i++) {
  93. if (this.investData[i].state == 1) {
  94. has = true
  95. break
  96. }
  97. }
  98. return has
  99. }
  100. /** 刷新红点 */
  101. freshRed() {
  102. let state = this.SurplusTimes > 0 ? true : false
  103. UiM.Instance.hallNode.getComponent(Main).setInvestRed(state)
  104. }
  105. }