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) } }