BetPanel.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. var TempBonus = require("TempBonus");
  2. var BetPanel = cc.Class({
  3. extends: cc.Component,
  4. properties: {
  5. Atlas:cc.SpriteAtlas,
  6. CashLbl:cc.Label,
  7. costLbl:cc.Label,
  8. cost:cc.Integer,
  9. CoinNode:cc.Node,
  10. CoinEffect:cc.Animation,
  11. zhenNode:cc.Node,
  12. stateBet:false,
  13. rate:0,
  14. IsWin:false,
  15. tmpWinRatio:0,//临时赢钱概率
  16. },
  17. ShowPanel:function (data) {
  18. this.CoinNode.active = false;
  19. this.stateBet = false;
  20. this.tmpWinRatio = 0;
  21. this.zhenNode.rotation = 0;
  22. this.costLbl.string = "花费金额:"+cc.Mgr.global.BetInitCost;
  23. this.CashLbl.string = cc.Mgr.UserDataMgr.Cash;
  24. },
  25. ClickBet:function(){
  26. cc.Mgr.AudioMgr.playSFX("click");
  27. if(this.stateBet == true)
  28. return
  29. if(cc.Mgr.UserDataMgr.Cash < cc.Mgr.global.BetInitCost)
  30. {
  31. var param = {};
  32. param.forWhat = "";
  33. param.text = cc.Mgr.global.getTranslation("MoneyNotEnough");
  34. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonTip, param);
  35. return;
  36. }
  37. this.stateBet = true;
  38. this.GoToBet();
  39. },
  40. CaculateWinRatio:function(){
  41. var seed = Math.random();
  42. this.IsWin = true;
  43. (this.zhenNode.rotation / 60) % 6;
  44. var rotateAngle = 360 * 6;
  45. if(seed < cc.Mgr.global.BetWinNullRatio)
  46. {
  47. this.IsWin = false;
  48. this.rate = 0;
  49. var sd = Math.random();
  50. if(sd < 0.33)
  51. rotateAngle += 0;
  52. else if(sd < 0.66)
  53. rotateAngle += 2 * 60;
  54. else
  55. rotateAngle += 4 * 60;
  56. }
  57. else if(seed < cc.Mgr.global.BetWinThreeRatio)
  58. {
  59. this.rate = 3;
  60. rotateAngle += 1 * 60;
  61. }
  62. else if(seed < cc.Mgr.global.BetWinFourRatio)
  63. {
  64. this.rate = 4;
  65. rotateAngle += 3 * 60;
  66. }
  67. else
  68. {
  69. this.rate = 5;
  70. rotateAngle += 5 * 60;
  71. }
  72. return rotateAngle;
  73. },
  74. //0 2 4 位置是 谢谢惠顾
  75. //1 3 5 是win
  76. GoToBet:function(){
  77. var self = this;
  78. var seed = Math.floor(Math.random() * 6) + 1;
  79. cc.Mgr.UserDataMgr.Cash -= cc.Mgr.global.BetInitCost;
  80. var x = this.CaculateWinRatio();
  81. var rotation = cc.rotateTo(3, x).easing(cc.easeSineInOut());
  82. var finished = cc.callFunc(()=>{
  83. cc.log("这就是结局================" + this.zhenNode.rotation);
  84. self.EndBet();
  85. },this);
  86. var action = cc.sequence(rotation, finished);
  87. this.zhenNode.runAction(action);
  88. },
  89. ShowResult:function(){
  90. if(this.IsWin)
  91. {
  92. var param = {};
  93. var getMoney = (cc.Mgr.global.BetInitCost * this.rate);
  94. if(cc.Mgr.global.TempAdsBetBonus == TempBonus.BetBonus)
  95. {
  96. getMoney = Math.floor(cc.Mgr.global.BetInitCost * this.rate * 1.2);
  97. //cc.Mgr.global.TempAdsBetBonus = TempBonus.NULL;
  98. }
  99. cc.Mgr.UserDataMgr.Cash += getMoney;
  100. param.text = cc.Mgr.global.getTranslation("BetWin")+ "\n奖励:" + getMoney;
  101. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonTip, param);
  102. this.tmpWinRatio = 0;//临时概率清零
  103. }
  104. else
  105. {
  106. var param = {};
  107. param.text = cc.Mgr.global.getTranslation("BetLose");
  108. cc.director.GlobalEvent.emit(cc.Mgr.Event.OpenCommonTip, param);
  109. this.tmpWinRatio += 0.05;
  110. if(this.tmpWinRatio > 0.25)
  111. {
  112. this.tmpWinRatio = 0.25;
  113. }
  114. }
  115. cc.Mgr.global.BetInitCost = cc.Mgr.global.BetInitCost * 2;
  116. cc.director.GlobalEvent.emit(cc.Mgr.Event.RefreshCashAsset, {});
  117. this.costLbl.string = "花费金额:"+cc.Mgr.global.BetInitCost;
  118. this.CashLbl.string = cc.Mgr.UserDataMgr.Cash;
  119. },
  120. EndBet:function(){
  121. if(this.IsWin)
  122. {
  123. this.CoinNode.active = true;
  124. this.CoinEffect.play("betCoin");
  125. cc.Mgr.AudioMgr.playSFX("goods_4");
  126. }
  127. else
  128. {
  129. this.stateBet = false;
  130. cc.Mgr.AudioMgr.playSFX("lose");
  131. this.ShowResult();
  132. }
  133. },
  134. EndCoinEffect:function(){
  135. this.CoinNode.active = false;
  136. this.stateBet = false;
  137. this.ShowResult();
  138. },
  139. ClosePanel:function(){
  140. cc.Mgr.AudioMgr.playSFX("click");
  141. this.node.active = false;
  142. },
  143. });
  144. module.exports = BetPanel;