shipyards
This commit is contained in:
parent
02f206d078
commit
fb3b6162fc
@ -9,5 +9,4 @@ ADD --chown=user . /app
|
|||||||
RUN chmod +x /app/main.py
|
RUN chmod +x /app/main.py
|
||||||
VOLUME /data
|
VOLUME /data
|
||||||
#ENTRYPOINT bash
|
#ENTRYPOINT bash
|
||||||
ENTRYPOINT [ "python3", "/app/main.py"]
|
CMD ["/bin/sh", "-c", "python3 /app/main.py -d /data ; bash -i"]
|
||||||
CMD ["-d", "/data"]
|
|
@ -4,6 +4,7 @@ from nullptr.models.waypoint import Waypoint
|
|||||||
from nullptr.models.marketplace import Marketplace
|
from nullptr.models.marketplace import Marketplace
|
||||||
from nullptr.models.jumpgate import Jumpgate
|
from nullptr.models.jumpgate import Jumpgate
|
||||||
from nullptr.models.ship import Ship
|
from nullptr.models.ship import Ship
|
||||||
|
from nullptr.models.shipyard import Shipyard
|
||||||
from .util import *
|
from .util import *
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
class ApiError(Exception):
|
class ApiError(Exception):
|
||||||
@ -117,7 +118,10 @@ class Api:
|
|||||||
return self.store.update(Jumpgate, data, symbol)
|
return self.store.update(Jumpgate, data, symbol)
|
||||||
|
|
||||||
def shipyard(self, wp):
|
def shipyard(self, wp):
|
||||||
return self.request('get', f'systems/{wp.system}/waypoints/{wp}/shipyard')
|
data = self.request('get', f'systems/{wp.system}/waypoints/{wp}/shipyard')
|
||||||
|
symbol = str(wp)
|
||||||
|
|
||||||
|
return self.store.update(Shipyard, data, symbol)
|
||||||
|
|
||||||
######## Fleet #########
|
######## Fleet #########
|
||||||
def list_ships(self):
|
def list_ships(self):
|
||||||
|
@ -71,5 +71,4 @@ class AtlasBuilder:
|
|||||||
#print(f'jumpgate at {w}')
|
#print(f'jumpgate at {w}')
|
||||||
self.sched(self.api.jumps, w)
|
self.sched(self.api.jumps, w)
|
||||||
if 'SHIPYARD' in w.traits:
|
if 'SHIPYARD' in w.traits:
|
||||||
# todo
|
self.sched(self.api.shipyard, w)
|
||||||
pass
|
|
||||||
|
@ -205,6 +205,8 @@ class Commander(CommandLine):
|
|||||||
self.api.marketplace(w)
|
self.api.marketplace(w)
|
||||||
if w.type == 'JUMP_GATE':
|
if w.type == 'JUMP_GATE':
|
||||||
self.api.jumps(w)
|
self.api.jumps(w)
|
||||||
|
if 'SHIPYARD' in w.traits:
|
||||||
|
self.api.shipyard(w)
|
||||||
|
|
||||||
def do_system(self, system_str):
|
def do_system(self, system_str):
|
||||||
system = self.store.get(System, system_str)
|
system = self.store.get(System, system_str)
|
||||||
@ -261,19 +263,14 @@ class Commander(CommandLine):
|
|||||||
else:
|
else:
|
||||||
waypoint = self.store.get(Waypoint, waypoint_str.upper())
|
waypoint = self.store.get(Waypoint, waypoint_str.upper())
|
||||||
r = self.api.jumps(waypoint)
|
r = self.api.jumps(waypoint)
|
||||||
pprint(r)
|
pprint(r, 5)
|
||||||
|
|
||||||
def do_shipyard(self, w=''):
|
def do_shipyard(self, w=''):
|
||||||
location = self.resolve_waypoint(w)
|
location = self.resolve_waypoint(w)
|
||||||
if location is None:
|
if location is None:
|
||||||
raise CommandError(f'waypoint {w} not found')
|
raise CommandError(f'waypoint {w} not found')
|
||||||
data = self.api.shipyard(location)
|
sy = self.api.shipyard(location)
|
||||||
if 'ships' in data:
|
pprint(sy, 5)
|
||||||
for s in must_get(data, 'ships'):
|
|
||||||
print(s['type'], s['purchasePrice'])
|
|
||||||
else:
|
|
||||||
for s in must_get(data, 'shipTypes'):
|
|
||||||
print(s['type'])
|
|
||||||
|
|
||||||
######## Commerce #########
|
######## Commerce #########
|
||||||
def do_refuel(self, source='market'):
|
def do_refuel(self, source='market'):
|
||||||
|
@ -10,5 +10,6 @@ from nullptr.models.contract import Contract
|
|||||||
from nullptr.models.survey import Survey
|
from nullptr.models.survey import Survey
|
||||||
from nullptr.models.atlas import Atlas
|
from nullptr.models.atlas import Atlas
|
||||||
from nullptr.models.crew import Crew
|
from nullptr.models.crew import Crew
|
||||||
|
from nullptr.models.shipyard import Shipyard
|
||||||
|
|
||||||
__all__ = [ 'Waypoint', 'Sector', 'Ship', 'Survey', 'System', 'Agent', 'Marketplace', 'Jumpgate', 'Contract', 'Base', 'Atlas', 'Crew' ]
|
__all__ = [ 'Waypoint', 'Sector', 'Ship', 'Survey', 'System', 'Agent', 'Marketplace', 'Jumpgate', 'Contract', 'Base', 'Atlas', 'Crew', 'Shipyard' ]
|
||||||
|
35
nullptr/models/shipyard.py
Normal file
35
nullptr/models/shipyard.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
from nullptr.models import Base
|
||||||
|
from time import time
|
||||||
|
from nullptr.util import *
|
||||||
|
|
||||||
|
class Shipyard(Base):
|
||||||
|
def define(self):
|
||||||
|
self.last_prices = 0
|
||||||
|
self.types = set()
|
||||||
|
self.prices:dict = {}
|
||||||
|
|
||||||
|
def get_waypoint(self):
|
||||||
|
return self.store.get('Waypoint', self.symbol, create=True)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def ext(self):
|
||||||
|
return 'syd'
|
||||||
|
|
||||||
|
def update(self, d):
|
||||||
|
if 'ships' in d:
|
||||||
|
self.last_prices = time()
|
||||||
|
for s in must_get(d, 'ships'):
|
||||||
|
self.prices[s['type']] = s['purchasePrice']
|
||||||
|
for s in must_get(d, 'shipTypes'):
|
||||||
|
self.types.add(s['type'])
|
||||||
|
|
||||||
|
def f(self, detail=1):
|
||||||
|
r = super().f(detail)
|
||||||
|
if detail > 2:
|
||||||
|
r += '\n'
|
||||||
|
for st in self.types:
|
||||||
|
price = "Unknown"
|
||||||
|
if st in self.prices:
|
||||||
|
price = self.prices[st]
|
||||||
|
r += f'{st:20} {price}\n'
|
||||||
|
return r
|
Loading…
Reference in New Issue
Block a user