|
@@ -4335,6 +4335,209 @@ class evilTrade(object):
|
|
|
self.state = 4
|
|
|
|
|
|
|
|
|
+class bustViewer(object):
|
|
|
+ """ Display all busts
|
|
|
+
|
|
|
+ Perhaps also add it so we can manually reset/clear busts?
|
|
|
+ Or maybe...
|
|
|
+ We make galaxy's maint_busts() configurable so the check in days is in the config
|
|
|
+
|
|
|
+ States:
|
|
|
+ 0 = Perform convertion of self.game.gamedata.busts into a more understandable format.
|
|
|
+ 1 = Display/List all busts perferably just their sector numbers and when (what date) did that occur.
|
|
|
+
|
|
|
+ Optionals:
|
|
|
+ 1. Give numbering to state 0 so you can select a specific bust to be perhaps removed and/or add a remove all option.
|
|
|
+ (Dangerous, might not want to allow someone to manually reset all that)
|
|
|
+ 2. Add math that calculates the age in days for that particular bust. (Then add this to state 1 Display/List)
|
|
|
+ (Ok well this one should be really easy make a string/tuple storing month/day/year for both now and the bust then,)
|
|
|
+ (compare them one by one against eachother if 0 we know it's not that category) <- Should always be days since we are clearing them out automatically
|
|
|
+ """
|
|
|
+
|
|
|
+ def __init__(self, game):
|
|
|
+ self.game = game
|
|
|
+ self.queue_game = game.queue_game
|
|
|
+ self.queue_player = game.queue_player
|
|
|
+ self.observer = game.observer
|
|
|
+ self.r = Style.RESET_ALL
|
|
|
+ self.c = merge(Style.BRIGHT + Fore.YELLOW)
|
|
|
+ self.nl = "\n\r"
|
|
|
+
|
|
|
+
|
|
|
+ self.busted = {}
|
|
|
+ self.age = {}
|
|
|
+ self.state = 0
|
|
|
+
|
|
|
+ self.prompt = game.buffer
|
|
|
+ self.save = self.observer.save()
|
|
|
+ self.observer.connect("player", self.player)
|
|
|
+ self.observer.connect("prompt", self.game_prompt)
|
|
|
+ self.observer.connect("game-line", self.game_line)
|
|
|
+
|
|
|
+ self.defer = None
|
|
|
+ self.to_player = self.game.to_player
|
|
|
+ self.game.to_player = False
|
|
|
+ self.send2game("D")
|
|
|
+
|
|
|
+ def whenDone(self):
|
|
|
+ self.defer = defer.Deferred()
|
|
|
+ return self.defer
|
|
|
+
|
|
|
+ def deactivate(self, andExit=False):
|
|
|
+ self.state = 0
|
|
|
+ log.debug("bustViewer.deactivate()")
|
|
|
+ self.game.to_player = True
|
|
|
+ assert not self.save is None
|
|
|
+ self.observer.load(self.save)
|
|
|
+ self.save = None
|
|
|
+ if self.defer:
|
|
|
+ if andExit:
|
|
|
+ self.defer.callback({"exit": True})
|
|
|
+ else:
|
|
|
+ self.defer.callback("done")
|
|
|
+ self.defer = None
|
|
|
+
|
|
|
+ def player(self, chunk: bytes):
|
|
|
+ self.deactivate(True)
|
|
|
+
|
|
|
+ def send2game(self, txt):
|
|
|
+ self.queue_player.put(txt)
|
|
|
+
|
|
|
+ def send2player(self, txt):
|
|
|
+ self.queue_game.put(txt)
|
|
|
+
|
|
|
+ def calcAge(self, dt):
|
|
|
+ rightNow = pendulum.now()
|
|
|
+ result = rightNow.diff(dt).in_days()
|
|
|
+ log.debug("calcAge('{0}') got {1} days".format(dt.to_datetime_string(), result))
|
|
|
+ return result
|
|
|
+
|
|
|
+ def game_prompt(self, prompt: str):
|
|
|
+ log.debug("P {0} | {1}".format(self.state, prompt))
|
|
|
+ if self.state == 0:
|
|
|
+
|
|
|
+ for s in self.game.gamedata.busts:
|
|
|
+ d = self.game.gamedata.busts[s]
|
|
|
+ d1 = pendulum.parse(d)
|
|
|
+ log.debug("{0} on {1}".format(s, d))
|
|
|
+ self.busted[s] = "{0:02d}-{1:02d}-{2:04d}".format(
|
|
|
+ d1.month, d1.day, d1.year
|
|
|
+ )
|
|
|
+ self.age[s] = self.calcAge(d1)
|
|
|
+ self.state += 1
|
|
|
+ self.send2game("D")
|
|
|
+ elif self.state == 1:
|
|
|
+
|
|
|
+ tc = merge(Style.BRIGHT + Fore.YELLOW + Back.BLUE)
|
|
|
+ c1 = merge(Style.BRIGHT + Fore.WHITE + Back.BLUE)
|
|
|
+ c2 = merge(Style.BRIGHT + Fore.CYAN + Back.BLUE)
|
|
|
+
|
|
|
+ box = Boxes(42, color=tc)
|
|
|
+ self.queue_game.put(box.top())
|
|
|
+ self.queue_game.put(
|
|
|
+ box.row(
|
|
|
+ tc
|
|
|
+ + " {0:10} {1:<20} {2:8} ".format(
|
|
|
+ "Sector", "Date Busted On", "Days old"
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ self.queue_game.put(box.middle())
|
|
|
+ for s in self.busted:
|
|
|
+ if self.age[s]:
|
|
|
+ self.queue_game.put(
|
|
|
+ box.row(
|
|
|
+ c1
|
|
|
+ + " {0:<10} {1:<20} {2:8} ".format(
|
|
|
+ s, self.busted[s], self.age[s]
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ self.queue_game.put(
|
|
|
+ box.row(
|
|
|
+ c1 + " {0:<10} {1:<20} ".format(s, self.busted[s])
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ self.queue_game.put(box.bottom())
|
|
|
+ self.deactivate(True)
|
|
|
+
|
|
|
+ def game_line(self, line: str):
|
|
|
+ log.debug("L {0} | {1}".format(self.state, line))
|
|
|
+
|
|
|
+
|
|
|
+class firstActivate(object):
|
|
|
+ """ Uppon first time activation of the proxy what happens
|
|
|
+
|
|
|
+ States:
|
|
|
+ 0 = Send V and gather information on when busts were cleared
|
|
|
+ 1 = Calcualte date from pendulum.now().subtract(days=
|
|
|
+ 2 = If pendulum.now() is greater than our date to clear then self.game.gamedata.reset_busts()
|
|
|
+
|
|
|
+ Well drat... while in a game you can't access when busts were cleared. :(
|
|
|
+ """
|
|
|
+
|
|
|
+ def __init__(self, game):
|
|
|
+ self.game = game
|
|
|
+ self.queue_game = game.queue_game
|
|
|
+ self.queue_player = game.queue_player
|
|
|
+ self.observer = game.observer
|
|
|
+ self.r = Style.RESET_ALL
|
|
|
+ self.c = merge(Style.BRIGHT + Fore.YELLOW)
|
|
|
+ self.nl = "\n\r"
|
|
|
+
|
|
|
+
|
|
|
+ self.state = 0
|
|
|
+
|
|
|
+ self.prompt = game.buffer
|
|
|
+ self.save = self.observer.save()
|
|
|
+ self.observer.connect("player", self.player)
|
|
|
+ self.observer.connect("prompt", self.game_prompt)
|
|
|
+ self.observer.connect("game-line", self.game_line)
|
|
|
+
|
|
|
+ self.defer = None
|
|
|
+ self.to_player = self.game.to_player
|
|
|
+ self.game.to_player = False
|
|
|
+ self.send2game("V")
|
|
|
+
|
|
|
+ def whenDone(self):
|
|
|
+ self.defer = defer.Deferred()
|
|
|
+ return self.defer
|
|
|
+
|
|
|
+ def deactivate(self, andExit=False):
|
|
|
+ self.state = 0
|
|
|
+ log.debug("firstActivate.deactivate()")
|
|
|
+ self.game.to_player = True
|
|
|
+ assert not self.save is None
|
|
|
+ self.observer.load(self.save)
|
|
|
+ self.save = None
|
|
|
+ if self.defer:
|
|
|
+ if andExit:
|
|
|
+ self.defer.callback({"exit": True})
|
|
|
+ else:
|
|
|
+ self.defer.callback("done")
|
|
|
+ self.defer = None
|
|
|
+
|
|
|
+ def player(self, chunk: bytes):
|
|
|
+ self.deactivate(True)
|
|
|
+
|
|
|
+ def send2game(self, txt):
|
|
|
+ self.queue_player.put(txt)
|
|
|
+
|
|
|
+ def send2player(self, txt):
|
|
|
+ self.queue_game.put(txt)
|
|
|
+
|
|
|
+ def game_prompt(self, prompt: str):
|
|
|
+ log.debug("P {0} | {1}".format(self.state, prompt))
|
|
|
+ if self.state == 0:
|
|
|
+ if prompt.startswith("Command"):
|
|
|
+ self.deactivate()
|
|
|
+
|
|
|
+ def game_line(self, line: str):
|
|
|
+ log.debug("L {0} | {1}".format(self.state, line))
|
|
|
+
|
|
|
+
|
|
|
class ProxyMenu(object):
|
|
|
""" Display ProxyMenu
|
|
|
|
|
@@ -4384,15 +4587,31 @@ class ProxyMenu(object):
|
|
|
self.defer = None
|
|
|
self.game.to_player = True
|
|
|
|
|
|
- self.keepalive = task.LoopingCall(self.awake)
|
|
|
- self.keepalive.start(30)
|
|
|
- self.menu()
|
|
|
+
|
|
|
+ if self.game.gamedata.activated == False:
|
|
|
+ self.game.gamedata.activated = True
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ log.debug("First time activation dectected!")
|
|
|
+ first = firstActivate(self.game)
|
|
|
+ d = first.whenDone()
|
|
|
+ d.addCallback(self.pre_back)
|
|
|
+ d.addErrback(self.pre_back)
|
|
|
+ else:
|
|
|
+
|
|
|
+ self.pre_back()
|
|
|
|
|
|
def __del__(self):
|
|
|
log.debug("ProxyMenu {0} RIP".format(self))
|
|
|
|
|
|
self.game.to_player = True
|
|
|
|
|
|
+ def pre_back(self, stuffz=None):
|
|
|
+ self.keepalive = task.LoopingCall(self.awake)
|
|
|
+ self.keepalive.start(30)
|
|
|
+ self.menu()
|
|
|
+
|
|
|
def whenDone(self):
|
|
|
self.defer = defer.Deferred()
|
|
|
|
|
@@ -4430,6 +4649,7 @@ class ProxyMenu(object):
|
|
|
menu_item("W", "Warp CIM Report ({0})".format(len(self.game.gamedata.warps)))
|
|
|
menu_item("R", "Restock Report")
|
|
|
menu_item("T", "Trading Report")
|
|
|
+ menu_item("B", "Display Busts ({0})".format(len(self.game.gamedata.busts)))
|
|
|
menu_item("S", "Scripts")
|
|
|
menu_item("X", "eXit")
|
|
|
bottom = box.bottom()
|
|
@@ -4670,6 +4890,14 @@ class ProxyMenu(object):
|
|
|
d.addCallback(self.activate_macro)
|
|
|
d.addErrback(self.welcome_back)
|
|
|
return
|
|
|
+ elif key == "B":
|
|
|
+ self.queue_game.put(self.c + key + self.r + self.nl)
|
|
|
+
|
|
|
+ busting = bustViewer(self.game)
|
|
|
+ d = busting.whenDone()
|
|
|
+ d.addCallback(self.welcome_back)
|
|
|
+ d.addErrback(self.welcome_back)
|
|
|
+ return
|
|
|
elif key == "S":
|
|
|
self.queue_game.put(self.c + key + self.r + self.nl)
|
|
|
|