From f948080bd07f5bdd22dc52cb59f1cfdde4296115 Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Tue, 12 Aug 2014 19:50:56 +0100 Subject: [PATCH] Add JDC jump checker (!hit) --- dropbot/bot.py | 32 +++++++++++++++++++++++++++++++- dropbot/map.py | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dropbot/bot.py b/dropbot/bot.py index 47b0a3c..572cd9a 100644 --- a/dropbot/bot.py +++ b/dropbot/bot.py @@ -7,7 +7,7 @@ from humanize import intcomma import pkgutil from json import loads as base_loads from random import choice -from dropbot.map import Map, base_range +from dropbot.map import Map, base_range, ship_class_to_range market_systems = [ @@ -323,4 +323,34 @@ class DropBot(ClientXMPP): len(self.map.nodes()), len([u for u, v, d in self.map.edges_iter(data=True) if d['link_type'] == 'gate']), len([u for u, v, d in self.map.edges_iter(data=True) if d['link_type'] == 'bridge']) + ) + + def cmd_hit(self, args, msg): + if len(args) != 2: + return '!hit ' + source, dest = args + + source = self._system_picker(source) + if isinstance(source, basestring): + return source + dest = self._system_picker(dest) + if isinstance(dest, basestring): + return dest + + ly = self.map.system_distance(source, dest) + + res = [] + for ship_class in base_range.keys(): + res1 = [] + for skill in [4, 5]: + if ship_class_to_range(ship_class, skill) >= ly: + res1.append('JDC{}'.format(skill)) + if len(res1): + res.append('{}: {}'.format(ship_class, ', '.join(res1))) + + return '{} -> {} ({}ly) Capable Ship Types:\n{}'.format( + self.map.get_system_name(source), + self.map.get_system_name(dest), + round(ly, 2), + '\n'.join(res) ) \ No newline at end of file diff --git a/dropbot/map.py b/dropbot/map.py index 0a7cb05..0474819 100644 --- a/dropbot/map.py +++ b/dropbot/map.py @@ -115,7 +115,7 @@ class Map(networkx.Graph): def system_distance(self, source, destination): """Calculates the distance in ly between two systems""" - return calc_distance(self.node[source], self.node[destination]) + return calc_distance(self.node[source]['coords'], self.node[destination]['coords']) def route_gate(self, source, destination, filter=None): """Route between two systems using gates (fastest)"""