GameLogic_spin.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package slotpanda
  2. import (
  3. "encoding/json"
  4. "bet24.com/log"
  5. )
  6. func (this *GameLogic) spin(userId int, amount int, isChip bool, extra string) (bool, int, string) {
  7. // 是否有免费次数
  8. free, freeSpinResult, isChipFree := this.useFreeSpin(userId)
  9. if free {
  10. return true, 0, this.handleFreeResult(userId, freeSpinResult, isChipFree)
  11. }
  12. if amount <= 0 {
  13. return false, 0, this.sendSlotBet(userId, "Invalid Bet!", ErrCode_InvalidBet, amount)
  14. }
  15. scoreType := GAMEID*100 + 1
  16. status := 1
  17. isSuceeded := this.slotCommon.WriteMoney(userId, -amount, 0, status, scoreType, isChip)
  18. if !isSuceeded {
  19. log.Release("handleSlotBet WriteMoney failed,UserId[%d],amount[%d]", userId, amount)
  20. // 扣金币失败
  21. return false, 0, this.sendSlotBet(userId, "Not enough money!", ErrCode_NotEnoughMoney, amount)
  22. }
  23. // 获取结果并写分
  24. return true, amount, this.handleSlotResult(userId, amount, isChip)
  25. }
  26. func (this *GameLogic) sendSlotBet(userId int, errMsg string, errCode, amount int) string {
  27. data, _ := json.Marshal(SlotPanda_Bet{Amount: amount, ErrorMsg: errMsg, ErrCode: errCode})
  28. return string(data)
  29. }
  30. func (this *GameLogic) handleFreeResult(userId int, result FreeSpinResult, isChip bool) string {
  31. // 写分
  32. amount := result.getWinAmount()
  33. this.slotCommon.WriteResult(userId, result.BetAmount, amount, true, isChip, result.getDesc(), GAMEID)
  34. // 发送结果给客户端
  35. return this.sendFreeSlotResult(userId, result)
  36. }
  37. func (this *GameLogic) sendFreeSlotResult(userId int, result FreeSpinResult) string {
  38. data, _ := json.Marshal(result)
  39. return string(data)
  40. }
  41. func (this *GameLogic) handleSlotResult(userId int, amount int, isChip bool) string {
  42. //defer utils.TimeCost(fmt.Sprintf("slotpanda.handleSlotResult %d", userId))()
  43. controlType := this.slotCommon.GetControlType(userId, GAMEID)
  44. result, ok := this.getResult(userId, amount, controlType, isChip)
  45. if !ok {
  46. return this.sendSlotBet(userId, "User Not Exist", ErrCode_NotExist, amount)
  47. }
  48. bonusAmount := 0
  49. if result.Bonus != nil {
  50. bonusAmount = result.Bonus.BonusResult + result.Bonus.JackpotResult
  51. }
  52. this.slotCommon.WriteResult(userId, amount, result.WinAmount+bonusAmount, false, isChip, this.getResultDesc(result), GAMEID)
  53. // 发送结果给客户端
  54. return this.sendSlotResult(userId, result)
  55. }
  56. func (this *GameLogic) sendSlotResult(userId int, result SlotPanda_Result) string {
  57. data, _ := json.Marshal(result)
  58. return string(data)
  59. }