From 320f925fa10a92cd0795a61075e189a58cd2ab16 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 21 Sep 2020 13:40:33 -0600 Subject: [PATCH] Fix sand gather state machine --- game.py | 1 + jobs.py | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/game.py b/game.py index bb34a38..b114d93 100644 --- a/game.py +++ b/game.py @@ -298,6 +298,7 @@ class Game: reply = 'ok' if command == 'inv': + print(self.g.inv) inv_list = [] for i in self.g.inv.values(): if i.present: diff --git a/jobs.py b/jobs.py index 0461ada..1d68e9d 100644 --- a/jobs.py +++ b/jobs.py @@ -379,7 +379,7 @@ class CacheItemsStates: return None def init(self): - num_stacks = len(self.g.inv) + num_stacks = len([x for x in self.g.inv.values() if x.present]) print('inventory amount:', num_stacks) if num_stacks >= 27: self.state = self.find_cache_spot @@ -473,8 +473,8 @@ class CacheItemsStates: print('moving', slot) - inv_slot_num = slot_num - w_info.slot_diff - self.g.inv.pop(inv_slot_num, None) + #inv_slot_num = slot_num - w_info.slot_diff + #self.g.inv.pop(inv_slot_num, None) self.g.item_lock = True self.g.game.click_window(slot_num, 0, 1, slot) @@ -516,17 +516,29 @@ class JobStates: return None def gather_sand(self): - s = self.gather_sand_states - if s.state == s.idle: - s.state = s.init - elif s.state == s.done: - #s.state = s.init + s1 = self.gather_sand_states + s2 = self.sleep_with_bed_states + s3 = self.cache_items_states - self.prev_state = self.gather_sand - self.state = self.sleep_with_bed + if s1.state == s1.idle: + s1.state = s1.init + s2.state = s2.init + s3.state = s3.init + elif s1.state == s1.done: + if s2.state != s2.done: + s2.run() + return + + if s3.state != s3.done: + s3.run() + return + + s1.state = s1.init + s2.state = s2.init + s3.state = s3.init return - s.run() + s1.run() def lumberjack(self): s1 = self.lumberjack_states