|
@@ -2169,6 +2169,10 @@ class ScriptTerror(object):
|
|
|
if not sector in self.game.gamedata.warps:
|
|
|
continue
|
|
|
|
|
|
+ # Busted port
|
|
|
+ if not sector in self.game.gamedata.busts:
|
|
|
+ continue
|
|
|
+
|
|
|
warps = self.game.gamedata.warps[sector]
|
|
|
for w in warps:
|
|
|
# We can get there, and get back.
|
|
@@ -2215,6 +2219,10 @@ class ScriptTerror(object):
|
|
|
if not sector in self.game.gamedata.warps:
|
|
|
continue
|
|
|
|
|
|
+ # Busted port
|
|
|
+ if not sector in self.game.gamedata.busts:
|
|
|
+ continue
|
|
|
+
|
|
|
warps = self.game.gamedata.warps[sector]
|
|
|
for w in warps:
|
|
|
# We can get there, and get back.
|
|
@@ -3819,6 +3827,9 @@ class evilTrade(object):
|
|
|
self.credits = 0 # Credits player has
|
|
|
self.turns = 0 # Turns the player has
|
|
|
self.sector = 0 # Current sector
|
|
|
+ self.sectors = False # Do we need to update sector1 and 2?
|
|
|
+ self.sector1 = None
|
|
|
+ self.sector2 = None
|
|
|
self.target_sector = 0 # Next port to trade with
|
|
|
self.name = "" # Player name to include into stats for logs
|
|
|
|
|
@@ -3839,7 +3850,7 @@ class evilTrade(object):
|
|
|
|
|
|
def deactivate(self, andExit=False):
|
|
|
self.state = 0
|
|
|
- log.debug("ColoScript2.deactivate()")
|
|
|
+ log.debug("EvilTrade.deactivate()")
|
|
|
self.game.to_player = True
|
|
|
assert not self.save is None
|
|
|
self.observer.load(self.save)
|
|
@@ -3977,8 +3988,190 @@ class evilTrade(object):
|
|
|
# Now to go to evil trade pair \o/
|
|
|
# Ok so if we go to line 2117 we can see how to use find_nearest_tradepairs()
|
|
|
# Which will give us a starting point for what needs to be done for us trading
|
|
|
- self.send2player(self.nl + Boxes.alert("Done!"))
|
|
|
- self.deactivate(True)
|
|
|
+ log.info("find_nearest_evilpairs({0})".format(self.sector))
|
|
|
+ c = coiterate(
|
|
|
+ self.game.gamedata.find_nearest_evilpairs(self.sector, self)
|
|
|
+ )
|
|
|
+ c.addCallback(lambda unknown: self.evil())
|
|
|
+ self.state = 4
|
|
|
+ elif self.state == 4:
|
|
|
+ if prompt.startswith("Do you want to engage the TransWarp drive? "):
|
|
|
+ self.queue_player.put("N")
|
|
|
+ elif prompt.startswith(
|
|
|
+ "Engage the Autopilot? (Y/N/Single step/Express) [Y]"
|
|
|
+ ):
|
|
|
+ self.queue_player.put("E")
|
|
|
+ elif prompt.startswith(
|
|
|
+ "Stop in this sector (Y,N,E,I,R,S,D,P,?) (?=Help) [N] ?"
|
|
|
+ ):
|
|
|
+ self.queue_player.put("N")
|
|
|
+ elif re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ # We should be where we wanted to.
|
|
|
+ self.send2game("PT\r\r")
|
|
|
+ self.state = 5
|
|
|
+ elif self.state == 5:
|
|
|
+ if prompt.startswith("How many holds of Fuel Ore do you want to buy"):
|
|
|
+ self.send2game("0\r")
|
|
|
+ elif prompt.startswith("How many holds of Organics do you want to buy"):
|
|
|
+ self.send2game("0\r")
|
|
|
+ elif re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ self.send2game("PR\rS3\r")
|
|
|
+ self.state = 6
|
|
|
+ elif self.state == 7:
|
|
|
+ if re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ c = coiterate(self.find_next_evilpair())
|
|
|
+ c.addCallback(lambda unknown: self.evil())
|
|
|
+ self.state = 8
|
|
|
+ elif self.state == 8:
|
|
|
+ if prompt.startswith("Do you want to engage the TransWarp drive? "):
|
|
|
+ self.queue_player.put("N")
|
|
|
+ elif prompt.startswith(
|
|
|
+ "Engage the Autopilot? (Y/N/Single step/Express) [Y]"
|
|
|
+ ):
|
|
|
+ self.queue_player.put("E")
|
|
|
+ elif prompt.startswith(
|
|
|
+ "Stop in this sector (Y,N,E,I,R,S,D,P,?) (?=Help) [N] ?"
|
|
|
+ ):
|
|
|
+ self.queue_player.put("N")
|
|
|
+ elif re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ # We should be where we wanted to.
|
|
|
+ self.send2game("PT\r\r")
|
|
|
+ self.state = 9
|
|
|
+ elif self.state == 9:
|
|
|
+ if prompt.startswith("How many holds of Fuel Ore do you want to buy"):
|
|
|
+ self.send2game("0\r")
|
|
|
+ elif prompt.startswith("How many holds of Organics do you want to buy"):
|
|
|
+ self.send2game("0\r")
|
|
|
+ elif re.match(r"Command \[TL=.* \(\?=Help\)\? :", prompt):
|
|
|
+ self.send2game("PR\rS3\r")
|
|
|
+ self.state = 10
|
|
|
+
|
|
|
+ def evil(self):
|
|
|
+ if self.target_sector is None:
|
|
|
+ self.send2player(
|
|
|
+ self.nl + Boxes.alert("I don't see any ports to trade with.")
|
|
|
+ )
|
|
|
+ self.deactivate(True)
|
|
|
+ else:
|
|
|
+ self.send2game("{0}\r".format(self.target_sector))
|
|
|
+ if self.sectors == False:
|
|
|
+ self.sector1 = self.sector
|
|
|
+ self.sector2 = self.target_sector
|
|
|
+ self.sectors = True
|
|
|
+ self.sector = self.target_sector
|
|
|
+
|
|
|
+ def find_next_evilpair(self):
|
|
|
+ """ Find the next GOOD trade pair sector.
|
|
|
+
|
|
|
+ This is sequential (just like Trade report)
|
|
|
+ """
|
|
|
+
|
|
|
+ # This should be using the setting in the config, not a hard coded value!
|
|
|
+ # show_limit (galaxy.port_trade_show) is pct >= show_limit.
|
|
|
+ show_limit = self.game.gamedata.get_config("Display_Percent", "90")
|
|
|
+
|
|
|
+ try:
|
|
|
+ show_limit = int(show_limit)
|
|
|
+ except ValueError:
|
|
|
+ show_limit = 90
|
|
|
+
|
|
|
+ if show_limit < 15:
|
|
|
+ show_limit = 15
|
|
|
+ if show_limit > 90:
|
|
|
+ show_limit = 90
|
|
|
+
|
|
|
+ # Look for "GOOD" trades
|
|
|
+
|
|
|
+ for sector in sorted(self.game.gamedata.ports.keys()):
|
|
|
+ pd = self.game.gamedata.ports[sector]
|
|
|
+ if not GameData.port_burnt(pd):
|
|
|
+ # This happens when you trade with a StarDock
|
|
|
+ if "class" not in pd:
|
|
|
+ continue
|
|
|
+
|
|
|
+ pc = pd["class"]
|
|
|
+
|
|
|
+ # Ok, let's look into it.
|
|
|
+ if not sector in self.game.gamedata.warps:
|
|
|
+ continue
|
|
|
+
|
|
|
+ # Busted port
|
|
|
+ if not sector in self.game.gamedata.busts:
|
|
|
+ continue
|
|
|
+
|
|
|
+ warps = self.game.gamedata.warps[sector]
|
|
|
+ for w in warps:
|
|
|
+ # We can get there, and get back.
|
|
|
+ if (
|
|
|
+ w in self.game.gamedata.warps
|
|
|
+ and sector in self.game.gamedata.warps[w]
|
|
|
+ ):
|
|
|
+ # Ok, we can get there -- and get back!
|
|
|
+ if (
|
|
|
+ w > sector
|
|
|
+ and w in self.game.gamedata.ports
|
|
|
+ and not GameData.port_burnt(self.game.gamedata.ports[w])
|
|
|
+ ):
|
|
|
+ wd = self.game.gamedata.ports[w]
|
|
|
+ if "class" not in wd:
|
|
|
+ continue
|
|
|
+ wc = wd["class"]
|
|
|
+
|
|
|
+ if pc in (2, 3, 4, 8) and wc in (2, 3, 4, 8):
|
|
|
+ data = self.game.gamedata.port_trade_show(
|
|
|
+ sector, w, show_limit
|
|
|
+ )
|
|
|
+ if data:
|
|
|
+ self.target_sector = sector
|
|
|
+ return sector
|
|
|
+ yield
|
|
|
+
|
|
|
+ # Look for OK trades
|
|
|
+ for sector in sorted(self.game.gamedata.ports.keys()):
|
|
|
+ pd = self.game.gamedata.ports[sector]
|
|
|
+ if not GameData.port_burnt(pd):
|
|
|
+ if "class" not in pd:
|
|
|
+ continue
|
|
|
+ pc = pd["class"]
|
|
|
+
|
|
|
+ # Ok, let's look into it.
|
|
|
+ if not sector in self.game.gamedata.warps:
|
|
|
+ continue
|
|
|
+
|
|
|
+ # Busted port
|
|
|
+ if not sector in self.game.gamedata.busts:
|
|
|
+ continue
|
|
|
+
|
|
|
+ warps = self.game.gamedata.warps[sector]
|
|
|
+ for w in warps:
|
|
|
+ # We can get there, and get back.
|
|
|
+ if (
|
|
|
+ w in self.game.gamedata.warps
|
|
|
+ and sector in self.game.gamedata.warps[w]
|
|
|
+ ):
|
|
|
+ # Ok, we can get there -- and get back!
|
|
|
+ if (
|
|
|
+ w > sector
|
|
|
+ and w in self.game.gamedata.ports
|
|
|
+ and not GameData.port_burnt(self.game.gamedata.ports[w])
|
|
|
+ ):
|
|
|
+ wd = self.game.gamedata.ports[w]
|
|
|
+ if "class" not in wd:
|
|
|
+ continue
|
|
|
+ wc = wd["class"]
|
|
|
+
|
|
|
+ if GameData.port_trading(
|
|
|
+ pd["port"], self.game.gamedata.ports[w]["port"]
|
|
|
+ ):
|
|
|
+ data = self.game.gamedata.port_trade_show(
|
|
|
+ sector, w, show_limit
|
|
|
+ )
|
|
|
+ if data:
|
|
|
+ self.target_sector = sector
|
|
|
+ return sector
|
|
|
+ yield
|
|
|
+
|
|
|
+ self.target_sector = None
|
|
|
|
|
|
def game_line(self, line: str):
|
|
|
log.debug("L {0} | {1}".format(self.state, line))
|
|
@@ -4043,6 +4236,29 @@ class evilTrade(object):
|
|
|
work = line.replace("Credits : ", "").replace(",", "")
|
|
|
self.credits = int(work)
|
|
|
self.completeINFO = True
|
|
|
+ if self.state == 6:
|
|
|
+ if "Suddenly you're Busted!" in line:
|
|
|
+ # Oops! We got busted, let's stop.
|
|
|
+ self.deactivate(True)
|
|
|
+ elif "Success!" in line:
|
|
|
+ # Ok we passed that... now to move on.
|
|
|
+ self.state = 7
|
|
|
+ if self.state == 10:
|
|
|
+ if "Suddenly you're Busted!" in line:
|
|
|
+ # Oops! We got busted, let's stop.
|
|
|
+ self.deactivate(True)
|
|
|
+ elif "Success!" in line:
|
|
|
+ # Ok we passed that... now to move on.
|
|
|
+ self.loops -= 1
|
|
|
+ if self.loops >= 0:
|
|
|
+ self.send2player(
|
|
|
+ self.nl + Boxes.alert("Completed {0}".format(self.maxLoops))
|
|
|
+ )
|
|
|
+ self.deactivate(True)
|
|
|
+ else:
|
|
|
+ c = coiterate(self.find_next_evilpair())
|
|
|
+ c.addCallback(lambda unknown: self.evil())
|
|
|
+ self.state = 4
|
|
|
|
|
|
|
|
|
class ProxyMenu(object):
|
|
@@ -4821,4 +5037,3 @@ class ProxyMenu(object):
|
|
|
log.debug("welcome_back")
|
|
|
self.keepalive.start(30, True)
|
|
|
self.menu()
|
|
|
-
|