# Wheel The better name which will be helpful for Google seacrh is "Fortune Wheel". Here, we call this game is just wheel, in which user pay for a turn of the wheel to get some reward. ## Code name `wheel`. ## Rules - User must place a bet to turn the wheel for one round. - User will win the money by the score of the wheel So, technically: - User must always pay first. They will always win, but the winning price might be smaller that the price they have paid. ## Consideration The wheel should be configurable. Visually aspect, the wheel score can distribtued evenly: ![Even wheel](./img/wheel-even.jpg) Or non even ![Non even wheel](./img/wheel-non-even.png) Thus, following things should be configurable **per partner**: - Number of segments. - Weight of each segment. - Score or the money that user can get for each segment - Display of segments (background color, icons, images ...) - Price that user must pay per turn. ## Technical design ### DB 3 tables main: - `wheel_config`: - Should ref `partner_id`, for partner to enable this game and config the - `id`, `ctime`, `mtime`, `status` - `bg_sound`: `sound/bg.wav` - `win_sound`: `sound/win.wav` - `bet_sound`: `sound/bet.wav` - `bet_amount`: `400` - `theme`: ``, - `wheel_segment_config`: - `id`, `ctime`, `mtime`, `status` - `label`: `abc` - `bg_color`: `#121212` - `reward_amount`: `400` - `icon`: `icon1.avg` - `order_number`: `2`, - `angle`: `10 degree` - `wheel_config_id`: ref to `wheel_config` - `wheel_game_record` - Should ref `user_id`, `transaction`, `wallet`, ... - `id`, `ctime`: read-only, hence, no `mtime` - `user_id` - `partner_id` - `reward_amount` - `wheel_type`: - `result_type`: `UserWin` (1), `UserLost` (2), `Draw` (3) - `bet_amount`: a bet money configure by partner API `api/game/wheel_config` ### Staff API - Create: should avoid conflict, as each partner ca only have 1 records in `wheel_config` table. RPC `/api/game/wheel_config Request: ```json { "bg_sound": "sound/bg.wav", "win_sound": "sound/win.wav", "bet_sound": "sound/bet.wav", "bet_amount": 400, "theme": "theme_default.png" } ``` Response: ```json { "id": 1, "bg_sound": "sound/bg.wav", "win_sound": "sound/win.wav", "bet_sound": "sound/bet.wav", "bet_amount": 400, "theme": "theme_default.png" } ``` RPC `/api/game/wheel_segment_config` Request: ```json [ { "wheel_config_id": 1, "label": "abc", "bg_color": "#121212", "icon": "icon1.svg", "order_number": 2, "angle": 10, "reward_amount": 200 }, { "wheel_config_id": 1, "label": "efg", "bg_color": "#131313", "icon": "icon2.svg", "order_number": 1, "angle": 10, "reward_amount": 200 } ] ``` - Update - Read - Delete: disable the game for the partner ### User API 2 API - `/api/game/wheel_config`, RPC style. - Input: nothing, we only need auth cookie to know which user, then find the `partner_id` and from that, find the correct record in `wheel_config`. - Output: `wheel_config` for partner. - `/api/game/wheel_segment_config`, RPC style. - Input: nothing, we only need auth cookie to know which user, then find the `partner_id` and from that, find the correct record in `wheel_segment_config`. - Output: `wheel_segment_config` for partner. RPC `/api/game/wheel/bet` Request: empty Response format for `UserLost` case: ```json { "type": 2, "bet_amount": 100 } ``` ### Implementation RPC `/api/game/wheel/bet` After client submit bet, the server should generate the result and calculate reward for user, then: - 2 new transactions should be created: - The first one is type `BET`, subtracts user balance by the amount their bet. - The second one is type `REWARD`, increase user balance by the winning amount. RPC `/api/game/wheel_config` The server save request common config game wheel from partner to DB. RPC `/api/game/wheel_segment_config` - The server processing request config segment of wheel and save it to DB. - The sum of `angle` less than or equal 360 degree ### Optimization > Optional for now, just make sure that the game work correctly. - `wheel_config` can be loaded and cached on first user of each partner. - When staff edit the config for any partner, we will refresh their cache, and also send a push notification to client to refresh their game config. For now, the client will just call `api/games/wheel_config` when init the game GUI.