game.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* Import modules. */
  2. import { defineStore } from 'pinia'
  3. import { v4 as uuidv4 } from 'uuid'
  4. import _newGame from './game/new.ts'
  5. import _rollDice from './game/rollDice.ts'
  6. /**
  7. * Game Store
  8. */
  9. export const useGameStore = defineStore('game', {
  10. state: () => ({
  11. _playid: null,
  12. _authHash: null,
  13. _address: null,
  14. _payout: null,
  15. _seed: null,
  16. _position: null,
  17. _satoshis: null,
  18. }),
  19. getters: {
  20. playid(_state) {
  21. return _state._playid
  22. },
  23. authHash(_state) {
  24. return _state._authHash
  25. },
  26. gameid(_state) {
  27. return '6b7d9eaf-9a3b-488e-bc0a-1c14d5f1aafd' // Wally Dice
  28. },
  29. /* Set Return To Player (RTP) value (as a percentage %). */
  30. // NOTE: Maximum RTP must not exceed 99.0%.
  31. // NOTE: Minimum RTP must be at least 95.0%.
  32. rtp(_state) {
  33. return 97.0 // 97% return to player
  34. },
  35. payout(_state) {
  36. return _state._payout
  37. },
  38. address(_state) {
  39. return _state._address
  40. },
  41. seed(_state) {
  42. return _state._seed
  43. },
  44. position(_state) {
  45. return _state._position
  46. },
  47. satoshis(_state) {
  48. return _state._satoshis
  49. },
  50. },
  51. actions: {
  52. async init() {
  53. /* Reset gameplay.*/
  54. this.resetGameplay()
  55. },
  56. newGame() {
  57. /* Start new game. */
  58. _newGame.bind(this)()
  59. },
  60. setPlayid(_playid) {
  61. this._playid = _playid
  62. },
  63. setAuthHash(_authHash) {
  64. this._authHash = _authHash
  65. },
  66. setAddress(_address) {
  67. this._address = _address
  68. },
  69. setSatoshis(_satoshis) {
  70. this._satoshis = _satoshis
  71. },
  72. rollDice() {
  73. /* Roll dice. */
  74. _rollDice.bind(this)()
  75. },
  76. resetGameplay() {
  77. this._authHash = null
  78. this._address = null
  79. this._playid = null
  80. this._payout = null
  81. this._seed = uuidv4()
  82. this._position = null
  83. },
  84. deleteSession() {
  85. /* Reset session. */
  86. this._session = null
  87. },
  88. },
  89. })