1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-09 20:02:11 +03:00

Send fleet details

This commit is contained in:
Jonathan Harris 2017-11-12 03:52:17 +00:00
parent 3645d821dc
commit 26d0a585ea

View File

@ -16,9 +16,6 @@ import myNotebook as nb
from config import appname, applongname, appversion, config from config import appname, applongname, appversion, config
import companion import companion
import coriolis
import edshipyard
import outfitting
import plug import plug
if __debug__: if __debug__:
@ -39,10 +36,12 @@ this.cmdr = None
this.multicrew = False # don't send captain's ship info to Inara while on a crew this.multicrew = False # don't send captain's ship info to Inara while on a crew
this.newuser = False # just entered API Key this.newuser = False # just entered API Key
this.undocked = False # just undocked this.undocked = False # just undocked
this.started_docked = False # Skip Docked event after Location if started docked this.suppress_docked = False # Skip Docked event after Location if started docked
this.cargo = None this.cargo = None
this.materials = None this.materials = None
this.lastcredits = 0 # Send credit update soon after Startup / new game this.lastcredits = 0 # Send credit update soon after Startup / new game
this.needfleet = True # Send full fleet update soon after Startup / new game
this.shipswap = False # just swapped ship
def plugin_start(): def plugin_start():
this.thread = Thread(target = worker, name = 'Inara worker') this.thread = Thread(target = worker, name = 'Inara worker')
@ -147,13 +146,18 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
# clear cached state # clear cached state
this.events = [] this.events = []
this.undocked = False this.undocked = False
this.started_docked = False this.suppress_docked = False
this.cargo = None this.cargo = None
this.materials = None this.materials = None
this.lastcredits = 0 this.lastcredits = 0
elif entry['event'] in ['Resurrect', 'ShipyardBuy', 'ShipyardSell']: this.needfleet = True
this.shipswap = False
elif entry['event'] in ['Resurrect', 'ShipyardBuy', 'ShipyardSell', 'SellShipOnRebuy']:
# Events that mean a significant change in credits so we should send credits after next "Update" # Events that mean a significant change in credits so we should send credits after next "Update"
this.lastcredits = 0 this.lastcredits = 0
elif entry['event'] in ['ShipyardNew', 'ShipyardSwap'] or (entry['event'] == 'Location' and entry['Docked']):
this.suppress_docked = True
# Send location and status on new game or StartUp. Assumes Location is the last event on a new game (other than Docked). # Send location and status on new game or StartUp. Assumes Location is the last event on a new game (other than Docked).
# Always send an update on Docked, FSDJump, Undocked+SuperCruise, Promotion and EngineerProgress. # Always send an update on Docked, FSDJump, Undocked+SuperCruise, Promotion and EngineerProgress.
@ -218,40 +222,50 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
('rankValue', 1), ('rankValue', 1),
])) ]))
# Update ship
if (entry['event'] in ['StartUp', 'Location', 'ShipyardNew'] or
(entry['event'] == 'Loadout' and this.shipswap) or
this.newuser):
if entry['event'] == 'ShipyardNew':
add_event('addCommanderShip', entry['timestamp'],
OrderedDict([
('shipType', state['ShipType']),
('shipGameID', state['ShipID']),
]))
add_event('setCommanderShip', entry['timestamp'],
OrderedDict([
('shipType', state['ShipType']),
('shipGameID', state['ShipID']),
('shipName', state['ShipName']), # Can be None
('shipIdent', state['ShipIdent']), # Can be None
('isCurrentShip', True),
]))
this.shipswap = False
# Update location # Update location
if (entry['event'] == 'Location' or this.newuser) and system: if (entry['event'] == 'Location' or this.newuser) and system:
this.newuser = False
this.undocked = False this.undocked = False
this.started_docked = entry.get('Docked') add_event('setCommanderTravelLocation', entry['timestamp'],
if this.started_docked: OrderedDict([
add_event('setCommanderTravelLocation', entry['timestamp'], ('starsystemName', system),
OrderedDict([ ('stationName', station), # Can be None
('starsystemName', system), ('shipType', state['ShipType']),
('stationName', station), ('shipGameID', state['ShipID']),
('shipType', companion.ship_map.get(state['ShipType'], state['ShipType'])), ]))
('shipGameID', state['ShipID']),
]))
else:
add_event('setCommanderTravelLocation', entry['timestamp'],
OrderedDict([
('starsystemName', system),
('shipType', companion.ship_map.get(state['ShipType'], state['ShipType'])),
('shipGameID', state['ShipID']),
]))
elif entry['event'] == 'Docked': elif entry['event'] == 'Docked':
if this.undocked: if this.undocked:
# Undocked and now docking again. Don't send. # Undocked and now docking again. Don't send.
this.undocked = False this.undocked = False
elif this.started_docked: elif this.suppress_docked:
# Don't send Docked event on new game - i.e. following 'Location' event # Don't send Docked event on new game - i.e. following 'Location' event
this.started_docked = False this.suppress_docked = False
else: else:
add_event('addCommanderTravelDock', entry['timestamp'], add_event('addCommanderTravelDock', entry['timestamp'],
OrderedDict([ OrderedDict([
('starsystemName', system), ('starsystemName', system),
('stationName', station), ('stationName', station),
('shipType', companion.ship_map.get(state['ShipType'], state['ShipType'])), ('shipType', state['ShipType']),
('shipGameID', state['ShipID']), ('shipGameID', state['ShipID']),
])) ]))
@ -264,7 +278,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
add_event('setCommanderTravelLocation', entry['timestamp'], add_event('setCommanderTravelLocation', entry['timestamp'],
OrderedDict([ OrderedDict([
('starsystemName', system), ('starsystemName', system),
('shipType', companion.ship_map.get(state['ShipType'], state['ShipType'])), ('shipType', state['ShipType']),
('shipGameID', state['ShipID']), ('shipGameID', state['ShipID']),
])) ]))
this.undocked = False this.undocked = False
@ -275,7 +289,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
OrderedDict([ OrderedDict([
('starsystemName', entry['StarSystem']), ('starsystemName', entry['StarSystem']),
('jumpDistance', entry['JumpDist']), ('jumpDistance', entry['JumpDist']),
('shipType', companion.ship_map.get(state['ShipType'], state['ShipType'])), ('shipType', state['ShipType']),
('shipGameID', state['ShipID']), ('shipGameID', state['ShipID']),
])) ]))
@ -306,6 +320,45 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
# Events that don't need to be sent immediately but will be sent on the next mandatory event # Events that don't need to be sent immediately but will be sent on the next mandatory event
# #
# Selling / swapping ships
if entry['event'] in ['ShipyardBuy', 'ShipyardSell', 'SellShipOnRebuy', 'ShipyardSwap']:
if entry['event'] == 'ShipyardSwap':
this.shipswap = True # Don't know new ship name and ident 'til the following Loadout event
if 'StoreShipID' in entry:
add_event('setCommanderShipDock', entry['timestamp'],
OrderedDict([
('shipType', entry['StoreOldShip']),
('shipGameID', entry['StoreShipID']),
('starsystemName', system),
('stationName', station),
]))
elif 'SellShipID' in entry:
add_event('delCommanderShip', entry['timestamp'],
OrderedDict([
('shipType', entry.get('SellOldShip', entry['ShipType'])),
('shipGameID', entry['SellShipID']),
]))
elif entry['event'] == 'SetUserShipName':
add_event('setCommanderShip', entry['timestamp'],
OrderedDict([
('shipType', state['ShipType']),
('shipGameID', state['ShipID']),
('shipName', state['ShipName']), # Can be None
('shipIdent', state['ShipIdent']), # Can be None
('isCurrentShip', True),
]))
elif entry['event'] == 'ShipyardTransfer':
add_event('setCommanderShipDock', entry['timestamp'],
OrderedDict([
('shipType', entry['ShipType']),
('shipGameID', entry['ShipID']),
('starsystemName', system),
('stationName', station),
('transferTime', entry['TransferTime']),
]))
# Missions # Missions
if entry['event'] == 'MissionAccepted': if entry['event'] == 'MissionAccepted':
data = OrderedDict([ data = OrderedDict([
@ -439,6 +492,7 @@ def journal_entry(cmdr, is_beta, system, station, entry, state):
data['isTopRank'] = goal['PlayerInTopRank'] data['isTopRank'] = goal['PlayerInTopRank']
add_event('setCommanderCommunityGoalProgress', entry['timestamp'], data) add_event('setCommanderCommunityGoalProgress', entry['timestamp'], data)
this.newuser = False
def cmdr_data(data, is_beta): def cmdr_data(data, is_beta):
@ -446,12 +500,36 @@ def cmdr_data(data, is_beta):
if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr): if config.getint('inara_out') and not is_beta and not this.multicrew and credentials(this.cmdr):
timestamp = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
assets = data['commander']['credits'] - data['commander'].get('debt', 0)
for ship in companion.listify(data.get('ships', [])):
if ship:
assets += ship['value']['total']
if this.needfleet:
add_event('setCommanderShip', timestamp,
OrderedDict([
('shipType', ship['name']),
('shipGameID', ship['id']),
('shipName', ship.get('shipName')), # Can be None
('shipIdent', ship.get('shipID')), # Can be None
('isCurrentShip', ship['id'] == data['commander']['currentShipId']),
('shipHullValue', ship['value']['hull']),
('shipModulesValue', ship['value']['modules']),
]))
if ship['id'] != data['commander']['currentShipId']:
add_event('setCommanderShipDock', timestamp,
OrderedDict([
('shipType', ship['name']),
('shipGameID', ship['id']),
('starsystemName', ship['starsystem']['name']),
('stationName', ship['station']['name']),
]))
this.needfleet = False
if not (CREDIT_RATIO > this.lastcredits / data['commander']['credits'] > 1/CREDIT_RATIO): if not (CREDIT_RATIO > this.lastcredits / data['commander']['credits'] > 1/CREDIT_RATIO):
assets = (data['commander']['credits'] +
-data['commander'].get('debt', 0) +
sum([x['value']['total'] for x in companion.listify(data.get('ships', [])) if x]))
this.events = [x for x in this.events if x['eventName'] != 'setCommanderCredits'] # Remove any unsent this.events = [x for x in this.events if x['eventName'] != 'setCommanderCredits'] # Remove any unsent
add_event('setCommanderCredits', time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()), add_event('setCommanderCredits', timestamp,
OrderedDict([ OrderedDict([
('commanderCredits', data['commander']['credits']), ('commanderCredits', data['commander']['credits']),
('commanderAssets', assets), ('commanderAssets', assets),