From 7775940177cea8a268c266e8d6a9690b0a317753 Mon Sep 17 00:00:00 2001 From: tacigar Date: Thu, 9 Jun 2016 15:08:16 +0900 Subject: [PATCH] Fix farming module --- modules/farming_module.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/farming_module.lua b/modules/farming_module.lua index c2075ff..c6a5c42 100644 --- a/modules/farming_module.lua +++ b/modules/farming_module.lua @@ -11,9 +11,11 @@ local state = { plant = 2, walk_to_plant = 3, walk_to_soil = 4, + walk_avoid = 5, } local max_punch_time = 20 local max_plant_time = 15 +local max_avoid_time = 15 local search_lenvec = {x = 3, y = 0, z = 3} @@ -75,6 +77,12 @@ local function to_walk(self) end +local function to_walk_avoid(self) + to_walk(self) + self.state = state.walk_avoid +end + + maidroid.register_module("maidroid:farming_module", { description = "Maidroid Module : Farming", inventory_image = "maidroid_farming_module.png", @@ -169,7 +177,7 @@ maidroid.register_module("maidroid:farming_module", { else to_walk(self) end else if pos.x == self.preposition.x or pos.z == self.preposition.z then - to_walk(self) + to_walk_avoid(self) end end @@ -183,9 +191,17 @@ maidroid.register_module("maidroid:farming_module", { else to_walk(self) end else if pos.x == self.preposition.x or pos.z == self.preposition.z then - to_walk(self) + to_walk_avoid(self) end end + + elseif self.state == state.walk_avoid then + if self.time_count > max_avoid_time then + self.state = state.walk + self.time_count = 0 + else + self.time_count = self.time_count + 1 + end end self.preposition = pos return