|
1 | 1 | ---Utility functions for game state extraction and data processing |
2 | 2 | utils = {} |
3 | 3 | local json = require("json") |
| 4 | +local socket = require("socket") |
4 | 5 |
|
5 | 6 | -- ========================================================================== |
6 | 7 | -- Game State Extraction |
|
634 | 635 | -- heuristic based on empirical testing to ensure smooth gameplay without delays. |
635 | 636 | local EVENT_QUEUE_THRESHOLD = 3 |
636 | 637 |
|
| 638 | +-- Timestamp storage for delayed conditions |
| 639 | +local condition_timestamps = {} |
| 640 | + |
637 | 641 | ---Completion conditions for different game actions to determine when action execution is complete |
638 | 642 | ---These are shared between API and LOG systems to ensure consistent timing |
639 | 643 | ---@type table<string, table> |
@@ -728,13 +732,47 @@ utils.COMPLETION_CONDITIONS = { |
728 | 732 |
|
729 | 733 | shop = { |
730 | 734 | buy_card = function() |
731 | | - return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE |
| 735 | + local base_condition = G.STATE == G.STATES.SHOP |
| 736 | + and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD - 1 -- need to reduve the threshold |
| 737 | + and G.STATE_COMPLETE |
| 738 | + |
| 739 | + if not base_condition then |
| 740 | + -- Reset timestamp if base condition is not met |
| 741 | + condition_timestamps.shop_buy_card = nil |
| 742 | + return false |
| 743 | + end |
| 744 | + |
| 745 | + -- Base condition is met, start timing |
| 746 | + if not condition_timestamps.shop_buy_card then |
| 747 | + condition_timestamps.shop_buy_card = socket.gettime() |
| 748 | + end |
| 749 | + |
| 750 | + -- Check if 0.1 seconds have passed |
| 751 | + local elapsed = socket.gettime() - condition_timestamps.shop_buy_card |
| 752 | + return elapsed > 0.1 |
732 | 753 | end, |
733 | 754 | next_round = function() |
734 | 755 | return G.STATE == G.STATES.BLIND_SELECT and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE |
735 | 756 | end, |
736 | 757 | reroll = function() |
737 | | - return G.STATE == G.STATES.SHOP and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD and G.STATE_COMPLETE |
| 758 | + local base_condition = G.STATE == G.STATES.SHOP |
| 759 | + and #G.E_MANAGER.queues.base < EVENT_QUEUE_THRESHOLD - 1 -- need to reduve the threshold |
| 760 | + and G.STATE_COMPLETE |
| 761 | + |
| 762 | + if not base_condition then |
| 763 | + -- Reset timestamp if base condition is not met |
| 764 | + condition_timestamps.shop_reroll = nil |
| 765 | + return false |
| 766 | + end |
| 767 | + |
| 768 | + -- Base condition is met, start timing |
| 769 | + if not condition_timestamps.shop_reroll then |
| 770 | + condition_timestamps.shop_reroll = socket.gettime() |
| 771 | + end |
| 772 | + |
| 773 | + -- Check if 0.3 seconds have passed |
| 774 | + local elapsed = socket.gettime() - condition_timestamps.shop_reroll |
| 775 | + return elapsed > 0.30 |
738 | 776 | end, |
739 | 777 | }, |
740 | 778 | } |
|
0 commit comments