2023-06-11 18:51:03 +00:00
|
|
|
|
2023-06-13 20:29:04 +00:00
|
|
|
from .system_member import SystemMember
|
2023-06-16 12:41:11 +00:00
|
|
|
from time import time
|
|
|
|
from nullptr.util import *
|
|
|
|
from dataclasses import field
|
2023-06-11 18:51:03 +00:00
|
|
|
|
2023-06-13 20:29:04 +00:00
|
|
|
class Marketplace(SystemMember):
|
2023-06-18 17:15:51 +00:00
|
|
|
def define(self):
|
|
|
|
self.imports:list = []
|
|
|
|
self.exports:list = []
|
|
|
|
self.exchange:list = []
|
|
|
|
self.prices:dict = {}
|
|
|
|
self.last_prices:int = 0
|
2023-06-11 18:51:03 +00:00
|
|
|
|
|
|
|
def update(self, d):
|
|
|
|
self.setlst('imports', d, 'imports', 'symbol')
|
|
|
|
self.setlst('exports', d, 'exports', 'symbol')
|
|
|
|
self.setlst('exchange', d, 'exchange', 'symbol')
|
2023-06-16 12:41:11 +00:00
|
|
|
if 'tradeGoods' in d:
|
|
|
|
self.last_prices = time()
|
2023-06-16 21:05:47 +00:00
|
|
|
prices = {}
|
2023-06-16 12:41:11 +00:00
|
|
|
for g in mg(d, 'tradeGoods'):
|
2023-06-16 21:05:47 +00:00
|
|
|
price = {}
|
|
|
|
symbol= mg(g, 'symbol')
|
|
|
|
price['symbol'] = symbol
|
|
|
|
price['buy'] = mg(g, 'purchasePrice')
|
|
|
|
price['sell'] = mg(g, 'sellPrice')
|
|
|
|
prices[symbol] = price
|
|
|
|
self.prices = prices
|
|
|
|
|
2023-06-11 18:51:03 +00:00
|
|
|
@classmethod
|
|
|
|
def ext(self):
|
|
|
|
return 'mkt'
|
|
|
|
|
2023-06-17 18:23:24 +00:00
|
|
|
def rtype(self, r):
|
|
|
|
if r in self.imports:
|
|
|
|
return 'I'
|
|
|
|
if r in self.exports:
|
|
|
|
return 'E'
|
|
|
|
if r in self.exchange:
|
|
|
|
return 'X'
|
|
|
|
return '?'
|
|
|
|
|
2023-06-11 18:51:03 +00:00
|
|
|
def path(self):
|
2023-06-12 20:36:58 +00:00
|
|
|
sector, system, _ = self.symbol.split('-')
|
|
|
|
return f'atlas/{sector}/{system[0:1]}/{system}/{self.symbol}.{self.ext()}'
|
2023-06-16 21:05:47 +00:00
|
|
|
|
|
|
|
def f(self, detail=1):
|
|
|
|
r = self.symbol
|
|
|
|
if detail > 1:
|
|
|
|
r += '\n'
|
|
|
|
for p in self.prices.values():
|
2023-06-17 18:23:24 +00:00
|
|
|
t = self.rtype(p['symbol'])
|
|
|
|
r += f'{t} {p["symbol"]:25s} {p["sell"]:5d} {p["buy"]:5d}\n'
|
2023-06-16 21:05:47 +00:00
|
|
|
return r
|