1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 00:07:14 +03:00

Track cargo and materials

This commit is contained in:
Jonathan Harris 2017-03-01 00:45:47 +00:00
parent a1b163da96
commit a16a8ac2b3
3 changed files with 68 additions and 4 deletions

View File

@ -625,6 +625,10 @@ class AppWindow:
elif entry['event'] in ['ShipyardBuy', 'ShipyardSell']:
self.edsm.sellship(entry.get('SellShipID'))
# Send materials info to EDSM on startup or change
if entry['event'] in ['StartUp', 'LoadGame', 'MaterialCollected', 'MaterialDiscarded', 'ScientificResearch', 'EngineerCraft', 'Synthesis']:
self.edsm.setmaterials(monitor.state['Raw'], monitor.state['Manufactured'], monitor.state['Encoded'])
# Send paintjob info to EDSM on change
if entry['event'] in ['ModuleBuy', 'ModuleSell'] and entry['Slot'] == 'PaintJob':
self.edsm.updateship(monitor.state['ShipID'], monitor.state['ShipType'], [('paintJob', monitor.state['PaintJob'])])

View File

@ -210,6 +210,13 @@ class EDSM:
if balance is not None:
self.call('api-commander-v1/set-credits', '&balance=%d&loan=%d' % (balance, loan))
def setmaterials(self, raw, manufactured, encoded):
self.call('api-commander-v1/set-materials', "&type=data&values=%s" % json.dumps(encoded, separators = (',', ':')))
materials = {}
materials.update(raw)
materials.update(encoded)
self.call('api-commander-v1/set-materials', "&type=materials&values=%s" % json.dumps(materials, separators = (',', ':')))
def setshipid(self, shipid):
if shipid is not None:
self.call('api-commander-v1/set-ship-id', '&shipId=%d' % shipid)

View File

@ -1,5 +1,5 @@
import atexit
from collections import OrderedDict
from collections import defaultdict, OrderedDict
import json
import re
import threading
@ -93,8 +93,12 @@ class EDLogs(FileSystemEventHandler):
# Cmdr state shared with EDSM and plugins
self.state = {
'Cargo' : defaultdict(int),
'Credits' : None,
'Loan' : None,
'Raw' : defaultdict(int),
'Manufactured' : defaultdict(int),
'Encoded' : defaultdict(int),
'PaintJob' : None,
'Rank' : { 'Combat': None, 'Trade': None, 'Explore': None, 'Empire': None, 'Federation': None, 'CQC': None },
'ShipID' : None,
@ -253,18 +257,38 @@ class EDLogs(FileSystemEventHandler):
self.live = False
self.version = entry['gameversion']
self.is_beta = 'beta' in entry['gameversion'].lower()
self.cmdr = None
self.mode = None
self.group = None
self.body = None
self.system = None
self.station = None
self.coordinates = None
self.state = {
'Cargo' : defaultdict(int),
'Credits' : None,
'Loan' : None,
'Raw' : defaultdict(int),
'Manufactured' : defaultdict(int),
'Encoded' : defaultdict(int),
'PaintJob' : None,
'Rank' : { 'Combat': None, 'Trade': None, 'Explore': None, 'Empire': None, 'Federation': None, 'CQC': None },
'ShipID' : None,
'ShipIdent' : None,
'ShipName' : None,
'ShipType' : None,
}
elif entry['event'] == 'LoadGame':
self.live = True
self.cmdr = entry['Commander']
self.mode = entry.get('GameMode') # 'Open', 'Solo', 'Group', or None for CQC
self.group = entry.get('Group')
self.state = {
self.state.update({
'Credits' : entry['Credits'],
'Loan' : entry['Loan'],
'PaintJob' : None,
'Rank' : { 'Combat': None, 'Trade': None, 'Explore': None, 'Empire': None, 'Federation': None, 'CQC': None },
'ShipID' : entry.get('ShipID') if entry.get('Ship') not in ['TestBuggy', 'Empire_Fighter', 'Federation_Fighter', 'Independent_Fighter'] else None # None in CQC or if game starts in SRV/fighter
}
})
self.state['ShipIdent'] = self.state['ShipID'] and entry.get('ShipIdent')
self.state['ShipName'] = self.state['ShipID'] and entry.get('ShipName')
self.state['ShipType'] = self.state['ShipID'] and entry.get('Ship').lower()
@ -329,6 +353,35 @@ class EDLogs(FileSystemEventHandler):
if self.state['Rank'].get(k) is not None:
self.state['Rank'][k] = (self.state['Rank'][k][0], min(v, 100)) # perhaps not taken promotion mission yet
elif entry['event'] == 'Cargo':
self.live = True # First event in 2.3
self.state['Cargo'] = defaultdict(int)
self.state['Cargo'].update({ x['Name']: x['Count'] for x in entry['Inventory'] })
elif entry['event'] in ['CollectCargo', 'MarketBuy', 'MiningRefined']:
self.state['Cargo'][entry['Type']] += entry.get('Count', 1)
elif entry['event'] in ['EjectCargo', 'MarketSell']:
self.state['Cargo'][entry['Type']] -= entry.get('Count', 1)
if self.state['Cargo'][entry['Type']] <= 0:
self.state['Cargo'].pop(entry['Type'])
elif entry['event'] == 'Materials':
for category in ['Raw', 'Manufactured', 'Encoded']:
self.state[category] = defaultdict(int)
self.state[category].update({ x['Name']: x['Count'] for x in entry.get(category, []) })
elif entry['event'] == 'MaterialCollected':
self.state[entry['Category']][entry['Name']] += entry['Count']
elif entry['event'] in ['MaterialDiscarded', 'ScientificResearch']:
self.state[entry['Category']][entry['Name']] -= entry['Count']
if self.state[entry['Category']][entry['Name']] <= 0:
self.state[entry['Category']].pop(entry['Name'])
elif entry['event'] in ['EngineerCraft', 'Synthesis']:
for category in ['Raw', 'Manufactured', 'Encoded']:
for x in entry[entry['event'] == 'EngineerCraft' and 'Ingredients' or 'Materials']:
if x['Name'] in self.state[category]:
self.state[category][x['Name']] -= x['Count']
if self.state[category][x['Name']] <= 0:
self.state[category].pop(x['Name'])
return entry
except:
if __debug__: