觉醒时刻
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

351 lines
12 KiB

import { ryw_Event } from "../../../FrameWork/Event/EventEnum";
import EventMgr from "../../../FrameWork/Event/EventMgr";
import GameReport from "../../../FrameWork/Report/ZyZyReport";
import User from "../../../FrameWork/User/User";
import Common5 from "../../../Platform/th/Common5";
import JuQingManager from "../../JuQingChat/JuQingManager";
import TaskManager, { MainTaskIdEnum } from "../../JuQingChat/TaskManager";
import UserManager from "../../Manager/UserManager";
import PrefabManage from "../../PrefabManager/PrefabManage";
import StockManager from "./StockManager";
const { ccclass, property } = cc._decorator;
enum AddSub {
Add,
Sub
}
@ccclass
export default class BuyStockBox extends cc.Component {
@property(cc.Node)
stockName: cc.Node = null
@property(cc.Node)
huafei: cc.Node = null
@property(cc.Node)
amount: cc.Node = null
@property(cc.Node)
leftStockNum: cc.Node = null
@property(cc.Node)
btn_reduce: cc.Node = null
@property(cc.Node)
btn_add: cc.Node = null
curStockName: string = ""
curAmount: number = 1
curPrice: number = 0
stockSum: number = 0
onLoad() {
this.openTouchEvent(this.btn_add)
this.openTouchEvent(this.btn_reduce)
}
initBoxContent(stockConfig) {
this.curPrice = stockConfig.curPrice
this.curStockName = stockConfig.stockName
let singConfig = StockManager.getSingleCompanyConfig(stockConfig.stockName)
this.stockSum = singConfig.stockSum
let myStockHistoryData = User.getMyStockData()
let curStockHistoryData = myStockHistoryData[this.curStockName]
let historyProssess = (curStockHistoryData ? curStockHistoryData.prossess : 0)
console.log(this.curPrice, this.curStockName, this.stockSum, historyProssess, 'this.curStockName +++++++===')
this.stockName.getComponent(cc.Label).string = stockConfig.stockName
this.huafei.getComponent(cc.Label).string = Common5.getNumberChangeHanzi(stockConfig.curPrice, '1', 1) + ""
this.amount.getComponent(cc.Label).string = "1"
if (this.stockSum - this.curAmount - historyProssess <= 0) {
this.leftStockNum.getComponent(cc.Label).string = "还剩(0股)"
this.amount.getComponent(cc.Label).string = "0"
this.huafei.getComponent(cc.Label).string = '0'
this.curAmount = 0
} else {
this.leftStockNum.getComponent(cc.Label).string = "还剩(" + (this.stockSum - this.curAmount - historyProssess) + "股)"
}
//this.leftStockNum.getComponent(cc.Label).string = "还剩("+(this.stockSum - this.curAmount - historyProssess)+"股)"
}
onBtnClose() {
// Common5.playEffect("CommonRes/sound/按键点击")
this.node.active = false
this.reportKey(() => {
GameReport.BtnsReport('关闭买入')
})
}
//购买
onBtnSure() {
// Common5.playEffect("CommonRes/sound/按键点击")
this.reportKey(() => {
GameReport.BtnsReport('确认买入')
})
if (this.curAmount == 0) {
//Common5.showTips_customTime('当前股票卖完了换一支股票吧',1)
PrefabManage.showTextTips('当前股票卖完了换一支股票吧')
return
}
let allMoney = User.getMoney()
let expendMoney = this.curAmount * this.curPrice
console.log("钱总数==花钱==", allMoney, expendMoney)
if (expendMoney > allMoney) {
//Common5.showTips_customTime('余额不足挣钱去吧',1)
PrefabManage.showTextTips('余额不足挣钱去吧')
} else {
UserManager.subMoney(expendMoney)
this.refreshMyStockStorageData()
}
this.node.active = false
}
refreshLabelShow(leftAmount) {
this.huafei.getComponent(cc.Label).string = Common5.getNumberChangeHanzi(this.curAmount * this.curPrice, '1', 1) + ""
console.log(this.curAmount, 'this.curAmount+++=')
console.log(this.curPrice, 'this.curPrice+++=')
let bb = Common5.getNumberChangeHanzi(this.curAmount, '1')
this.amount.getComponent(cc.Label).string = bb + ""
let aa = Common5.getNumberChangeHanzi(leftAmount, '1')
this.leftStockNum.getComponent(cc.Label).string = "还剩(" + aa + "股)"
}
//刷新我的股票购买数据
refreshMyStockStorageData() {
let myStockHistoryData = User.getMyStockData()
console.log("已存在数据==", myStockHistoryData)
let curStockHistoryData = myStockHistoryData[this.curStockName]
let newProssess = this.curAmount
//已经购买过该股票
if (curStockHistoryData) {
let historyBuyPrice = curStockHistoryData.buyPrice
let historyProssess = curStockHistoryData.prossess
newProssess = historyProssess + this.curAmount
let newBuyPrice = Math.floor((historyBuyPrice * historyProssess + this.curPrice * this.curAmount) / newProssess)
let buyStockTab = {
stockName: this.curStockName,
buyPrice: newBuyPrice,
prossess: newProssess
}
User.setMyStockData(buyStockTab)
//首次购买该股票
} else {
newProssess = this.curAmount
let buyStockTab = {
stockName: this.curStockName,
buyPrice: this.curPrice,
prossess: newProssess
}
User.setMyStockData(buyStockTab)
}
if (this.curStockName == '钱氏集团' && newProssess >= this.stockSum) {
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
if (mainId == MainTaskIdEnum.MainTask_1106) {
// JuQingManager.unLockNewJuQing('WX_2002');
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_1106);
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_1201);
EventMgr.emitEvent_custom(ryw_Event.EnterNextGame, true)
}
}else if (this.curStockName == '傅氏医疗' && newProssess >= this.stockSum) {
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
if (mainId == MainTaskIdEnum.MainTask_1404) {
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_1404);
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_1405);
}
}else if (this.curStockName == '傅氏股票' && newProssess >= this.stockSum) {
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
if (mainId == MainTaskIdEnum.MainTask_1806) {
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_1806);
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_1901);
}
}else if (this.curStockName == '安氏集团' && newProssess >= this.stockSum) {
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
if (mainId == MainTaskIdEnum.MainTask_2104) {
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_2104);
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_2105);
}
}else if (this.curStockName == '龙氏集团' && newProssess >= this.stockSum) {
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
let mainId = mainTaskInfo.Id
if (mainId == MainTaskIdEnum.MainTask_2404) {
TaskManager.finishCurMainTask(MainTaskIdEnum.MainTask_2404);
TaskManager.setCurUnLockMainTaskInfo(MainTaskIdEnum.MainTask_2405);
}
}
EventMgr.emitEvent_custom(ryw_Event.updateStockView);
}
openTouchEvent(node) {
node.on(cc.Node.EventType.TOUCH_START, this.touchStartNode, this)
node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveNode, this)
node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndNode, this)
node.on(cc.Node.EventType.TOUCH_END, this.touchEndNode, this)
}
touchStartNode(event) {
// Common5.playEffect("CommonRes/sound/按键点击")
let target = event.target
target.scale = 1.05
if (target.name == 'btn_reduce') {
this.addOrSubMoneyCommon(AddSub.Sub)
this.reportKey(() => {
GameReport.BtnsReport('买入减')
})
} else if (target.name == 'btn_add') {
this.addOrSubMoneyCommon(AddSub.Add)
this.reportKey(() => {
GameReport.BtnsReport('买入加')
})
}
}
touchMoveNode(event) {
}
addOrSubMoneyCommon(type) {
if (AddSub.Sub == type) {
this.curAmount -= 1
} else if (AddSub.Add == type) {
this.curAmount += 1
}
let callFunc = () => {
if (this.curAmount < 1) {
this.curAmount = 1
}
if (this.curAmount * this.curPrice >= User.getMoney()) {
this.curAmount = Math.floor(User.getMoney() / this.curPrice)
} else {
}
let myStockHistoryData = User.getMyStockData()
let curStockHistoryData = myStockHistoryData[this.curStockName]
let historyProssess = curStockHistoryData ? curStockHistoryData.prossess : 0
console.log("this.stockSum=", this.stockSum)
console.log("this.curAmount=", this.curAmount)
console.log("historyProssess=", historyProssess)
let leftAmount = this.stockSum - this.curAmount - historyProssess
if (leftAmount <= 0) {
leftAmount = 0
}
if (this.stockSum - historyProssess <= 0) {
this.curAmount = 0
}
if (this.curAmount >= this.stockSum) {
this.curAmount = this.stockSum
}
this.refreshLabelShow(leftAmount)
}
callFunc()
cc.tween(this.node)
.delay(0.3)
.call(() => {
let random = Common5.getRandomNum(100, 20000)
if (AddSub.Sub == type) {
this.curAmount -= random
} else if (AddSub.Add == type) {
this.curAmount += random
}
callFunc()
})
.union()
.repeatForever()
.start()
}
touchEndNode(event) {
let target = event.target
target.scale = 1.00
this.node.stopAllActions()
}
buyMaxClick() {
this.reportKey(() => {
GameReport.BtnsReport('最大买入')
})
let myStockHistoryData = User.getMyStockData()
let curStockHistoryData = myStockHistoryData[this.curStockName]
let historyProssess = curStockHistoryData ? curStockHistoryData.prossess : 0
if (this.stockSum * this.curPrice >= User.getMoney()) {
this.curAmount = Math.floor(User.getMoney() / this.curPrice)
this.curAmount = this.stockSum - historyProssess
if (this.curAmount <= 0) {
this.curAmount = 0
}
} else {
this.curAmount = this.stockSum - historyProssess
if (this.curAmount <= 0) {
this.curAmount = 0
}
}
let leftAmount = this.stockSum - this.curAmount - historyProssess
if (leftAmount <= 0) {
leftAmount = 0
}
console.log("this.stockSum=", this.stockSum)
console.log("this.curAmount=", this.curAmount)
console.log("historyProssess=", historyProssess)
this.refreshLabelShow(leftAmount)
}
buyMinClick() {
this.reportKey(() => {
GameReport.BtnsReport('最小买入')
})
this.curAmount = 1
let myStockHistoryData = User.getMyStockData()
let curStockHistoryData = myStockHistoryData[this.curStockName]
let historyProssess = curStockHistoryData ? curStockHistoryData.prossess : 0
let leftAmount = this.stockSum - this.curAmount - historyProssess
if (leftAmount <= 0) {
leftAmount = 0
this.curAmount = 0
}
this.refreshLabelShow(leftAmount)
}
protected reportKey(callfunc: Function) {
GameReport.SetCurGame("股票");
callfunc()
}
}