| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import Main from "../Main"
- import GameM from "../manager/GameM"
- import UiM from "../manager/UiM"
- import Invest from "../ui/Invest"
- import LogUtil from "../utils/LogUtil"
- import { HTTP_TYPE } from "./CommonData"
- /** 投资数据类 */
- export default class InvestData {
- private static instance: InvestData = null
- static get Instance(): InvestData {
- if (!InvestData.instance) {
- InvestData.instance = new InvestData()
- }
- return InvestData.instance
- }
- /** 看视频item */
- investItem = null
- /** 投资数据*/
- investData = []
- /** 视频加速投资时间 百分比减少*/
- investVideoTime = 0.5
- /** 加速卡加速投资时间 单位:s*/
- investCardTime = 3
- /** 剩余投资次数 */
- SurplusTimes = 0
- getInvestInfo() {
- let data = {}
- GameM.httpM.sendDatas(HTTP_TYPE.getInvestInfo, data, InvestData.Instance.getInvestInfoBack.bind(this))
- }
- getInvestInfoBack(data) {
- // LogUtil.logV('getInvestInfoBack ', data.InvestData)
- this.investData = data.InvestData
- this.SurplusTimes = data.SurplusTimes
- GameM.commonData.gameTime = data.timestamp * 1000
- this.freshRed()
- if (UiM.Instance.InvestNode) {
- UiM.Instance.InvestNode.getComponent(Invest).init(true)
- }
- }
- /**更新投资
- * @param index 投资Index
- * @param investMentType 更新类型 0.可投资(领取) 1.倒计时(投资) 2.可领取(投资完成)
- **/
- updateInvestProject(index, investMentType) {
- let data = {
- 'index': index,
- 'investMentType': investMentType
- }
- LogUtil.logV('updateInvestProject ', data)
- GameM.httpM.sendDatas(HTTP_TYPE.updateInvestProject, data, InvestData.Instance.updateInvestProjectBack.bind(this))
- }
- /** 更新投资返回 */
- updateInvestProjectBack(data, param) {
- this.investData = data.InvestData
- this.SurplusTimes = data.SurplusTimes
- GameM.commonData.gameTime = data.timestamp * 1000
- LogUtil.logV('updateInvestProjectBack ', data)
- this.freshRed()
- let invest = UiM.Instance.InvestNode.getComponent(Invest)
- if (param.investMentType == 0) {
- invest.onGetGold(param.index)
- }
- else if (param.investMentType == 1) {
- GameM.commonData.roleData.investTotal++
- GameM.commonData.updateRoleData()
- }
- invest.init(false)
- }
- /** 减少投资时间
- * @param index 投资Index
- * @param reduceTimeType 减少类型 1.减10分钟 2.减少50%
- */
- reduceTimeInvestProject(index, reduceTimeType) {
- let data = {
- 'index': index,
- 'reduceTimeType': reduceTimeType
- }
- LogUtil.logV('reduceTimeInvestProject ', data)
- GameM.httpM.sendDatas(HTTP_TYPE.reduceTimeInvestProject, data, InvestData.Instance.reduceTimeInvestProjectBack.bind(this))
- }
- /** 减少投资时间返回 */
- reduceTimeInvestProjectBack(data) {
- this.investData = data.InvestData
- GameM.commonData.gameTime = data.timestamp * 1000
- LogUtil.logV('reduceTimeInvestProjectBack ', data)
- UiM.Instance.InvestNode.getComponent(Invest).init(false)
- }
- /** 检查是否有投资项 */
- checkHasInvest() {
- let has = false
- let len = this.investData.length
- for (var i = 0; i < len; i++) {
- if (this.investData[i].state == 1) {
- has = true
- break
- }
- }
- return has
- }
- /** 刷新红点 */
- freshRed() {
- let state = this.SurplusTimes > 0 ? true : false
- UiM.Instance.hallNode.getComponent(Main).setInvestRed(state)
- }
- }
|