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.
462 lines
13 KiB
462 lines
13 KiB
|
|
import User from "../../FrameWork/User/User";
|
|
import AppPlatform from "../../FrameWork/Util/AppPlatform";
|
|
import Common5 from "../../Platform/th/Common5";
|
|
import TaskManager from "../JuQingChat/TaskManager";
|
|
import UserManager from "../Manager/UserManager";
|
|
import PrefabManage, { GameType } from "../PrefabManager/PrefabManage";
|
|
import GameBase from "../SCommon/GameBase";
|
|
import CaiShangEnd from "./CaiShangEnd";
|
|
import CaiShangManager from "./CaiShangManager";
|
|
import CaiShangTip from "./CaiShangTip";
|
|
|
|
const {ccclass, property} = cc._decorator;
|
|
enum CURSTATE {
|
|
BUYSTATE,
|
|
SAlESTAE,
|
|
}
|
|
@ccclass
|
|
export default class CaiShangLevel2 extends GameBase {
|
|
@property(cc.SpriteFrame)
|
|
renwuIconArray: cc.SpriteFrame[] = [];
|
|
|
|
@property(cc.Sprite)
|
|
myicon: cc.Sprite = null;
|
|
@property(cc.Sprite)
|
|
othericon: cc.Sprite = null;
|
|
|
|
@property(cc.Label)
|
|
gujiaLabel: cc.Label = null;
|
|
@property(cc.Label)
|
|
maiRuJiaLabel: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
shouyiLabel: cc.Label = null;
|
|
@property(cc.Label)
|
|
chiCangShiZhiMoney: cc.Label = null;
|
|
|
|
|
|
@property(cc.ProgressBar)
|
|
progressBar: cc.ProgressBar = null;
|
|
@property(cc.Node)
|
|
fire: cc.Node = null;
|
|
|
|
@property(cc.Label)
|
|
gongsiLabel: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
timeLabel: cc.Label = null;
|
|
@property(cc.Label)
|
|
descLabel: cc.Label = null;
|
|
@property(cc.Label)
|
|
gupiaoshuLabel: cc.Label = null;
|
|
|
|
@property(cc.Label)
|
|
gubenLab: cc.Label = null;
|
|
|
|
@property(cc.Node)
|
|
zoushitu: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
saleNode: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
buyNode: cc.Node = null;
|
|
|
|
@property(cc.Node)
|
|
zhangBtn: cc.Node = null;
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
chazhi = 3
|
|
|
|
// onLoad () {}
|
|
shouyiMoney = 0
|
|
shouyiAdIndex = 0
|
|
buyMoney = 0
|
|
tishengIndex = 0.15
|
|
times = 120
|
|
data_ = null
|
|
|
|
proIndex = 0.5
|
|
_timeIndex = 0
|
|
isStartGame = false
|
|
progressBarNode:cc.Node = null
|
|
|
|
lineNode: cc.Node = null
|
|
fixGujiaNum = 0
|
|
curGujiaNum = 0
|
|
gupiaoshuNum = 0
|
|
gupiaoIndex= -1
|
|
gupiaoLi = 1
|
|
posyList = []
|
|
curShiZhi = 0
|
|
leftRiseTimes:number = 0
|
|
|
|
surState = CURSTATE.BUYSTATE
|
|
vdYingliMoney = 0 //盈利的钱
|
|
duijiaDuihua = [
|
|
'对家已买入1万股股票',
|
|
'对家已买入10万股股票',
|
|
'对家已买入18万股股票',
|
|
'对家已买入200万股股票',
|
|
'对家已买入80万股股票',
|
|
'对家已买入47万股股票',
|
|
]
|
|
spendMoney = 0
|
|
isMaiRu = false
|
|
zhangBtnUseNum = 3
|
|
|
|
onLoad() {
|
|
super.onLoad()
|
|
}
|
|
|
|
onDestroy(): void {
|
|
super.onDestroy()
|
|
}
|
|
|
|
start () {
|
|
// this.gupiaoshuNum = CaiShangManager.getGupiaoNum()
|
|
// this.curGujiaNum = this.data_.menkanMoney
|
|
|
|
// // let gujia = CaiShangManager.getOneGupiaoMoney(this.data_.menkanMoney,this.gupiaoshuNum)
|
|
// this.curShiZhi = this.data_.menkanMoney
|
|
// this.gujiaLabel.string = Common5.getNumberChangeHanzi(gujia) +''
|
|
this.progressBarNode = this.progressBar.node.getChildByName('bar')
|
|
this.duihuaAnim()
|
|
}
|
|
|
|
|
|
//formatTime3_custom
|
|
|
|
setData(data){
|
|
console.log(data)
|
|
this.data_ = data
|
|
this.gupiaoshuNum = CaiShangManager.getGupiaoNum()
|
|
this.curShiZhi = this.data_.menkanMoney
|
|
this.curGujiaNum = Math.floor(this.curShiZhi/this.gupiaoshuNum)
|
|
|
|
this.refreView()
|
|
}
|
|
|
|
duihuaAnim(){
|
|
this.descLabel.node.scale = 0.1
|
|
cc.tween(this.descLabel.node)
|
|
.call(()=>{
|
|
|
|
let randomRate = Common5.getRandomNum(0,this.duijiaDuihua.length)
|
|
let str = this.duijiaDuihua[randomRate]
|
|
this.descLabel.string = str
|
|
})
|
|
.to(1.0, {scale:1},{easing:'backOut'})
|
|
.delay(5.0)
|
|
.to(0.1, {scale:0.1})
|
|
.union()
|
|
.repeatForever()
|
|
.start()
|
|
}
|
|
refreView(){
|
|
if( !this.lineNode){
|
|
this.lineNode= new cc.Node();
|
|
this.lineNode.parent = this.zoushitu;
|
|
let yuandian = this.zoushitu.getChildByName('yuandian')
|
|
this.lineNode.setPosition(yuandian.getPosition())
|
|
let line = this.lineNode.addComponent(cc.Graphics);
|
|
|
|
//设置线条宽度
|
|
line.lineWidth = 5;
|
|
//设置线条颜色
|
|
line.strokeColor = cc.color(102,178,216)
|
|
|
|
line.clear();
|
|
|
|
}
|
|
|
|
|
|
this.progressBarNode = this.progressBar.node.getChildByName('bar')
|
|
let img = User.getHeadImg()
|
|
Common5.getSpriteFrameFromBundle("allRes","GameRes/ui/setting/headIcon/"+img, this.myicon);
|
|
this.othericon.spriteFrame = this.renwuIconArray[this.data_.id]
|
|
|
|
// let gupiaoshu = CaiShangManager.getGupiaoNum()
|
|
// this.gupiaoshuLabel.string = gupiaoshu+''
|
|
|
|
let gujia = CaiShangManager.getOneGupiaoMoney(this.data_.menkanMoney,this.gupiaoshuNum)
|
|
// this.gujiaLabel.string = Common5.getNumberChangeHanzi(gujia) +''
|
|
// this.gupiaoshuNum = gupiaoshu
|
|
this.curGujiaNum = gujia
|
|
this.fixGujiaNum = gujia
|
|
let timeStr = Common5.formatTime3_custom(this.times)
|
|
this.timeLabel.string = timeStr
|
|
|
|
this.shouyiLabel.string = Common5.getNumberChangeHanzi(this.shouyiMoney) +''
|
|
|
|
this.progressBar.progress = this.proIndex
|
|
|
|
cc.tween(this.fire)
|
|
.delay(0.1)
|
|
.to(0.1, {x: this.progressBarNode.width})
|
|
.start()
|
|
|
|
this.gongsiLabel.string = this.data_.GongSiName
|
|
|
|
this.descLabel.string = ''
|
|
|
|
|
|
this.buyNode.active = true
|
|
this.saleNode.active = false
|
|
|
|
}
|
|
|
|
zhangClickEvent(event){
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
let target = event.target
|
|
this.isStartGame = false
|
|
let tab = {
|
|
onClose: (finish)=>{
|
|
if (finish) {
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
Common5.ReportDY("inLevel", `任务${mainId}-AD-股市操盘五连涨`);
|
|
|
|
let randomIndex = Math.floor(Math.random()*2)+3
|
|
this.leftRiseTimes = randomIndex
|
|
this.isStartGame = true
|
|
}else{
|
|
Common5.showTips_custom("广告未观看完");
|
|
this.isStartGame = true
|
|
}
|
|
},onFailed:()=>{
|
|
this.isStartGame = true
|
|
}
|
|
}
|
|
AppPlatform.playVideo_custom(tab)
|
|
|
|
}
|
|
|
|
buyClickEvent(event){
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
this.isMaiRu = true
|
|
this.surState = CURSTATE.SAlESTAE
|
|
let target = event.target
|
|
this.isStartGame = true
|
|
if( this.gupiaoIndex == 0){
|
|
let line = this.lineNode.addComponent(cc.Graphics);
|
|
line.clear();
|
|
}
|
|
this.gupiaoshuNum = Math.floor(this.curShiZhi/this.curGujiaNum)
|
|
let money = this.gupiaoshuNum* this.curGujiaNum
|
|
if(UserManager.getCurMoney() -money >=0 ){
|
|
target.active = false
|
|
this.saleNode.active = true
|
|
UserManager.subMoney(money)
|
|
let str ='你已成功买入'+this.gupiaoshuNum +'股股票'
|
|
this.descLabel.string = str
|
|
this.spendMoney = money
|
|
this.gubenLab.string =Common5.getNumberChangeHanzi(money) +''
|
|
|
|
this.maiRuJiaLabel.string = Common5.getNumberChangeHanzi(this.curGujiaNum) +''
|
|
|
|
}else{
|
|
Common5.showTips_customTime('余额不足!',1)
|
|
}
|
|
}
|
|
|
|
saleClickEvent(event){
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
this.isMaiRu = false
|
|
let target = event.target
|
|
|
|
this.surState = CURSTATE.BUYSTATE
|
|
target.active = false
|
|
this.buyNode.active = true
|
|
|
|
let money = this.gupiaoshuNum* this.curGujiaNum
|
|
money = money+this.vdYingliMoney
|
|
|
|
this.vdYingliMoney = 0
|
|
UserManager.addMoney(money)
|
|
this.gubenLab.string ='0'
|
|
this.refreView()
|
|
}
|
|
|
|
tiGaoShouyiClickEvent(event){
|
|
// Common5.playEffect("CommonRes/sound/按键点击")
|
|
let target = event.target
|
|
this.isStartGame = false
|
|
let tab = {
|
|
onClose: (finish)=>{
|
|
if (finish) {
|
|
let mainTaskInfo: any = TaskManager.getCurUnLockMainTaskInfo()
|
|
let mainId = mainTaskInfo.Id
|
|
Common5.ReportDY("inLevel", `任务${mainId}-AD-股市操盘盈利+15%`);
|
|
|
|
this.shouyiAdIndex += 1
|
|
|
|
let shouyi = Math.abs(this.shouyiMoney)*0.15
|
|
this.vdYingliMoney+=shouyi
|
|
this.isStartGame = true
|
|
}else{
|
|
Common5.showTips_custom("广告未观看完");
|
|
this.isStartGame = true
|
|
}
|
|
},onFailed:()=>{
|
|
this.isStartGame = true
|
|
}
|
|
}
|
|
AppPlatform.playVideo_custom(tab)
|
|
|
|
|
|
}
|
|
|
|
update (dt) {
|
|
if(!this.isStartGame){
|
|
return
|
|
}
|
|
|
|
this._timeIndex+=dt
|
|
if( this._timeIndex >= 1){
|
|
this._timeIndex = 0
|
|
|
|
this.times-=1
|
|
let timeStr = Common5.formatTime3_custom(this.times)
|
|
this.gupiaoIndex++
|
|
this.timeLabel.string = timeStr
|
|
if(this.times <=0){
|
|
|
|
this.times = 0
|
|
this.gupiaoIndex = 0
|
|
this.posyList.length = 0
|
|
this.posyList = []
|
|
this.isStartGame = false
|
|
this.showEndLayer()
|
|
}
|
|
//画图
|
|
this.drawLine()
|
|
}
|
|
}
|
|
|
|
//441
|
|
drawLine () {
|
|
|
|
let line = this.lineNode.addComponent(cc.Graphics);
|
|
// //设置线条宽度
|
|
line.lineWidth = 5;
|
|
//设置线条颜色
|
|
line.strokeColor = cc.color(102,178,216)
|
|
|
|
|
|
// console.log('drawLine')
|
|
line.clear();
|
|
|
|
let posY = 0
|
|
|
|
let trueRate = CaiShangManager.createDropOrGainsRate(this.data_, this.fixGujiaNum, this.curGujiaNum,this.leftRiseTimes)
|
|
if(this.leftRiseTimes > 0){
|
|
this.leftRiseTimes --
|
|
}
|
|
this.gupiaoLi += parseFloat(trueRate)/100 //涨跌的利率
|
|
|
|
this.curGujiaNum = this.gupiaoLi * this.fixGujiaNum //当前股价
|
|
|
|
this.gujiaLabel.string = Common5.getNumberChangeHanzi(this.curGujiaNum) +''
|
|
if(this.isMaiRu){
|
|
let shizhi = this.gupiaoshuNum*this.curGujiaNum
|
|
this.chiCangShiZhiMoney.string = Common5.getNumberChangeHanzi(shizhi) +''
|
|
this.curShiZhi = shizhi
|
|
this.shouyiMoney = this.curShiZhi - this.data_.menkanMoney
|
|
this.shouyiLabel.string = Common5.getNumberChangeHanzi(this.shouyiMoney) +''
|
|
}
|
|
|
|
|
|
if(this.surState == CURSTATE.SAlESTAE){
|
|
// this.shouyiMoney = (this.curGujiaNum-this.fixGujiaNum)*this.gupiaoshuNum
|
|
}
|
|
|
|
|
|
// if( this.shouyiAdIndex > 0){
|
|
// this.shouyiMoney
|
|
// }
|
|
|
|
// console.log(this.gupiaoLi,"trueRate+++++++++++")
|
|
|
|
// this.shouyiLabel.string = Common5.getNumberChangeHanzi(this.shouyiMoney+this.vdYingliMoney) +''
|
|
|
|
|
|
if(this.gupiaoLi>1){
|
|
posY = 100*(this.gupiaoLi-1)
|
|
}else{
|
|
posY = -100*(1-this.gupiaoLi)
|
|
}
|
|
this.posyList.push(posY)
|
|
|
|
// let posY_ = this.posyList[this.gupiaoIndex]
|
|
// if (this.gupiaoIndex == 0) {
|
|
// //创建线条起始点
|
|
// line.moveTo(0, posY_);
|
|
// }else {
|
|
// //与前一段线条相连
|
|
// line.lineTo(this.gupiaoIndex*3.675, posY_);
|
|
// }
|
|
|
|
|
|
for (let i = 0; i < this.posyList.length; i++){
|
|
let posY_ = this.posyList[i]
|
|
if (i === 0) {
|
|
//创建线条起始点
|
|
line.moveTo(0, posY_);
|
|
}
|
|
else {
|
|
//与前一段线条相连
|
|
line.lineTo(i*3.675, posY_);
|
|
}
|
|
}
|
|
|
|
line.stroke();
|
|
|
|
}
|
|
|
|
exitGameNode(){
|
|
if(this.times == 0){
|
|
this.showEndLayer()
|
|
}else{
|
|
this.showTipsLayer()
|
|
}
|
|
}
|
|
|
|
showTipsLayer(){
|
|
|
|
let money = 0
|
|
if(this.surState == CURSTATE.BUYSTATE){
|
|
money = 0
|
|
}else{
|
|
money = this.gupiaoshuNum* this.curGujiaNum
|
|
money = money+this.vdYingliMoney
|
|
}
|
|
|
|
PrefabManage.loadPrefabByType(GameType.CaiShangLevel3, null, (prefab)=>{
|
|
let script_:CaiShangTip = prefab.getComponent('CaiShangTip')
|
|
script_.setTipView(this.node, money)
|
|
})
|
|
}
|
|
|
|
showEndLayer(){
|
|
let money = 0
|
|
if(this.surState == CURSTATE.BUYSTATE){
|
|
money = 0
|
|
}else{
|
|
money = this.gupiaoshuNum* this.curGujiaNum
|
|
money = money+this.vdYingliMoney
|
|
}
|
|
PrefabManage.loadPrefabByType(GameType.CaiShangLevel4, null, (prefab)=>{
|
|
let script_:CaiShangEnd = prefab.getComponent('CaiShangEnd')
|
|
script_.setEndView(this.node, money, this.shouyiMoney)
|
|
})
|
|
}
|
|
|
|
createPoint(x){
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|