forked from lekeno/edr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch.2.3.2.txt
5231 lines (4559 loc) · 180 KB
/
patch.2.3.2.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
deleted file mode 100644
index a0ee4ca..0000000
--- a/.github/FUNDING.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-# These are supported funding model platforms
-
-patreon: lekeno
-custom: ['https://www.subscribestar.com/edr']
diff --git a/.gitignore b/.gitignore
index 67a38ef..37d94b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -107,6 +107,3 @@ edr/private/fbaa.p
edr/design notes.txt
*.p
edr/db/fleet
-
-# Ignore dev pre cache
-**/.dccache
\ No newline at end of file
diff --git a/edr/config/user_config_sample.ini b/edr/config/user_config_sample.ini
index d22a977..0e0bfaa 100644
--- a/edr/config/user_config_sample.ini
+++ b/edr/config/user_config_sample.ini
@@ -43,7 +43,7 @@ player_webhook =
; - voicechat_webhook: forwards voice comms messages sent by you to a channel of your choice on discord
; - local_webhook: forwards local messages sent by you to a channel of your choice on discord
; - starsystem_webhook: forwards star system wide messages sent by you to a channel of your choice on discord
-; - player_webhook: forwards direct messages to other players sent by you, to a channel of your choice on discord
+; - player_webhook: forwards direct messages sent by you to a channel of your choice on discord
;
; 1. Setup a Webhook in your favorite/personal discord server: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
; 2. Copy paste the Webhook URL in the settings below
@@ -60,9 +60,13 @@ player_webhook =
;
;
[discord_fleetcarrier]
-; This section is used for forwarding interesting infor about your fleet carrier to discord
-; - jump_webhook: forward jump schedule and cancellation to a channel of your choice on discord
+; This section is used for forwarding interesting information about your fleet carrier to discord
+; - jump_webhook: publish jump schedule and cancellation to a channel of your choice on discord
+; - bar_webhook: publish your fleet carrier's bar buy and sale orders.
+; - market_webhook: publish your fleet carrier's commoditiy market / bar's buy and sale orders.
;
; 1. Setup a Webhook in your favorite/personal discord server: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
; 2. Copy paste the Webhook URL in the settings below
-jump_webhook =
\ No newline at end of file
+; Note: the webhooks don't have to be different. For instance, one could have their jump_webhook, bar_webhook and market_webhook set to the same channel.
+jump_webhook =
+market_webhook =
\ No newline at end of file
diff --git a/edr/data/odyssey_mats.json b/edr/data/odyssey_mats.json
index 0dd3685..d426686 100644
--- a/edr/data/odyssey_mats.json
+++ b/edr/data/odyssey_mats.json
@@ -1,5 +1,5 @@
{
- "manufacturinginstructions": { "blueprints": 56, "type": "data", "locations": ["STO buildings", "RES buildings", "IND buildings", "HAB buildings", "Crashed satellite", "Mission reward"], "used": 56, "referer": "Rosa Dayette", "refer": "Yi Shen [Colonia]"},
+ "manufacturinginstructions": { "blueprints": 56, "type": "data", "locations": ["STO buildings", "RES buildings", "IND buildings", "HAB buildings", "Crashed satellite", "Mission reward"], "used": 56, "referer": "Rosa Dayette [Colonia]", "refer": "Yi Shen [Colonia]"},
"operationalmanual": { "blueprints": 33, "type": "data", "locations": ["MED room", "RES buildings", "IND buildings", "CMD buildings", "Crashed satellite", "Mission reward"], "used": 33},
"combattrainingmaterial": { "blueprints": 25, "type": "data", "locations": ["RES buildings", "HAB buildings", "CMD buildings", "Mission reward"], "used": 25},
"combatantperformance": { "blueprints": 25, "type": "data", "locations": ["HAB buildings", "CMD buildings", "Mission reward"], "used": 25},
@@ -7,7 +7,7 @@
"biometricdata": { "blueprints": 18, "type": "data", "locations": ["MED room", "CMD buildings", "Mission reward"], "used": 18},
"weapontestdata": { "blueprints": 18, "type": "data", "locations": ["CMD buildings", "Mission reward"], "used": 18},
"spectralanalysisdata": { "blueprints": 17, "type": "data", "locations": ["RES buildings", "CMD buildings", "Crashed satellite", "Mission reward"], "used": 17},
- "digitaldesigns": { "blueprints": 14, "type": "data", "locations": ["HAB buildings", "Mission reward"], "used": 14, "referer": "Eleanor Bresa", "refer":"Yi Shen [Colonia]"},
+ "digitaldesigns": { "blueprints": 14, "type": "data", "locations": ["HAB buildings", "Mission reward"], "used": 14, "referer": "Eleanor Bresa [Colonia]", "refer":"Yi Shen [Colonia]"},
"patrolroutes": { "blueprints": 14, "type": "data", "locations": ["Irregular markers", "CMD buildings", "Mission reward"], "used": 14},
"productionreports": { "blueprints": 14, "type": "data", "locations": ["RES buildings", "IND buildings", "AGRI buildings", "Mission reward"], "used": 14},
"riskassessments": { "blueprints": 14, "type": "data", "locations": ["RES buildings", "HAB buildings", "Mission reward"], "used": 14},
@@ -51,6 +51,9 @@
"opinionpolls": { "type": "data", "locations": ["HAB buildings", "CMD buildings"], "used": 0, "unlock": "Kit Fowler"},
"settlementdefenceplans": { "type": "data", "locations": ["Irregular markers", "CMD buildings"], "used": 0, "referer": "Hero Ferrari", "refer": "Wellington Beck"},
"smearcampaignplans": { "type": "data", "locations": ["HAB buildings", "CMD buildings"], "used": 0, "unlock": "Yarden Bond"},
+ "cocktailrecipes": { "type": "data", "locations": ["HAB buildings"], "used": 0, "unlock": "Rosa Dayette"},
+ "culinaryrecipes": { "type": "data", "locations": ["HAB buildings"], "used": 0, "unlock": "Rosa Dayette"},
+ "factionassociates": { "type": "data", "locations": ["HAB buildings"], "used": 0, "referer": "Baltanos [Colonia]", "refer": "Yi Shen [Colonia]"},
"accidentlogs": { "useless": true, "type": "data", "locations": ["RES buildings", "PWR buildings", "IND buildings", "HAB buildings", "EXT buildings", "AGRI buildings"], "used": 0},
"axcombatlogs": { "useless": true, "type": "data", "locations": ["CMD buildings"], "used": 0},
"blacklistdata": { "useless": true, "type": "data", "locations": ["CMD buildings", "Crashed satellite"], "used": 0},
@@ -58,11 +61,9 @@
"campaignplans": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"censusdata": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"chemicalweapondata": { "useless": true, "type": "data", "locations": [], "used": 0},
- "cocktailrecipes": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"conflicthistory": { "useless": true, "type": "data", "locations": ["CMD buildings"], "used": 0},
"criminalrecords": { "useless": true, "type": "data", "locations": ["CMD buildings"], "used": 0},
"cropyieldanalysis": { "useless": true, "type": "data", "locations": ["AGRI buildings"], "used": 0},
- "culinaryrecipes": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"dutyrota": { "useless": true, "type": "data", "locations": ["RES buildings", "PWR buildings", "IND buildings", "CMD buildings"], "used": 0},
"employeedirectory": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"employeeexpenses": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
@@ -70,7 +71,6 @@
"enhancedinterrogationrecordings": { "useless": true, "type": "data", "locations": ["CMD buildings"], "used": 0},
"espionagematerial": { "useless": true, "type": "data", "locations": [], "used": 0},
"explorationjournals": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
- "factionassociates": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"factiondonatorlist": { "useless": true, "type": "data", "locations": ["HAB buildings"], "used": 0},
"factionnews": { "useless": true, "type": "data", "locations": ["HAB buildings", "Crashed satellite"], "used": 0},
"fleetregistry": { "useless": true, "type": "data", "locations": [], "used": 0},
diff --git a/edr/edengineers.py b/edr/edengineers.py
index 046b022..98f37d7 100644
--- a/edr/edengineers.py
+++ b/edr/edengineers.py
@@ -298,6 +298,12 @@ class EDEngineers(object):
return True
return False
+ def is_necessary(self, material_name):
+ for name in self.engineers:
+ if self.engineers[name].relevant(material_name) and self.engineers[name].interested_in(material_name):
+ return True
+ return False
+
def is_unnecessary(self, material_name):
for name in self.engineers:
if self.engineers[name].relevant(material_name) and not self.engineers[name].interested_in(material_name):
diff --git a/edr/edentities.py b/edr/edentities.py
index c6197c1..9db8e11 100644
--- a/edr/edentities.py
+++ b/edr/edentities.py
@@ -10,7 +10,7 @@ from edvehicles import EDVehicleFactory
from edspacesuits import EDSuitFactory
from edinstance import EDInstance
from edrlog import EDRLog
-from edrconfig import EDRConfig #TODO replace config object with singleton
+from edrconfig import EDRConfig
from edreconbox import EDReconBox
from edrinventory import EDRInventory, EDRRemlokHelmet
from edri18n import _, _c
@@ -181,8 +181,9 @@ class EDRPowerplayUnknown(EDRPowerplay):
class EDFineOrBounty(object):
- def __init__(self, value):
+ def __init__(self, value, faction=None):
self.value = value
+ self.faction = faction
config = EDRConfig()
self.threshold = config.intel_bounty_threshold()
@@ -239,6 +240,7 @@ class EDPilot(object):
self.slf = None
self.shuttle = None
self.location = EDLocation()
+ self.last_station = None
self.powerplay = EDRPowerplayUnknown()
self.squadron = None
self.sqid = None
@@ -247,6 +249,8 @@ class EDPilot(object):
self.enemy = False
self._bounty = None
self._fine = None
+ self.bounties = {}
+ self.fines = {}
self.targeted_vehicle = None
self.timestamp = now
self.rank = rank
@@ -284,6 +288,8 @@ class EDPilot(object):
self.wanted = False
self._bounty = None
self._fine = None
+ self.bounties = {}
+ self.fines = {}
self.targeted_vehicle = None
self.shuttle = None
if self.mothership:
@@ -444,7 +450,7 @@ class EDPilot(object):
elif entry.get("Taxi", False):
self.in_taxi()
elif entry.get("Multicrew", False):
- # TODO multicrew, hmmm
+ # TODO multicrew
self.mothership = EDVehicleFactory.unknown_crew_vehicle()
self.in_mothership()
else:
@@ -512,6 +518,14 @@ class EDPilot(object):
if self.srv:
self.srv.safe()
+ def docked_at(self, entry):
+ self.docked()
+ if entry.get("StationType", None) == "FleetCarrier":
+ self.last_station = edrfleetcarrier.EDRFleetCarrier()
+ self.last_station.update_from_location_or_docking(entry)
+ else:
+ self.last_station = None # TODO
+
def hardpoints(self, deployed):
self._touch()
if self.piloted_vehicle:
@@ -605,6 +619,39 @@ class EDPilot(object):
else:
self._bounty = None
+ # TODO should be moved to the ship....
+ def add_bounty(self, credits, faction):
+ self._touch()
+ self.bounties[faction] = self.bounties.get(faction, 0) + credits
+
+ def add_fine(self, credits, faction):
+ self._touch()
+ self.fines[faction] = self.fines.get(faction, 0) + credits
+
+ def paid_all_bounties(self):
+ self._touch()
+ self.bounties = {}
+ self.bounty = 0
+
+ def paid_fine(self, entry):
+ true_amount = entry["Amount"] * (1.0 - entry.get("BrokerPercentage", 0)/100.0)
+ self.fine = max(0, self.fine - true_amount)
+
+ def paid_bounty(self, entry):
+ true_amount = entry["Amount"] * (1.0 - entry.get("BrokerPercentage", 0)/100.0)
+ self.bounty = max(0, self.bounty - true_amount)
+ if "Faction" in entry:
+ self.bounties[entry["Faction"]] = max(0, self.bounties[entry["Faction"]] - true_amount)
+
+ def is_wanted_by_faction(self, faction):
+ return self.bounties.get(faction, 0) > 0
+
+ def paid_all_fines(self):
+ self._touch()
+ self.fines = {}
+ self.fine = 0
+
+
@property
def fine(self):
if self._fine:
@@ -667,7 +714,6 @@ class EDPilot(object):
if event.get("event", None) in ["SuitLoadout", "SwitchSuitLoadout"]:
self.in_spacesuit()
self.spacesuit = EDSuitFactory.from_suitloadout_event(event)
- # TODO should this be more conservative?
self._touch()
return True
elif event.get("event", None) in ["LoadGame", "Loadout"]:
@@ -678,7 +724,6 @@ class EDPilot(object):
if EDSuitFactory.is_spacesuit(so_called_ship):
self.in_spacesuit()
self.spacesuit = EDSuitFactory.from_load_game_event(event)
- # TODO should this be more conservative?
self._touch()
return True
else:
@@ -1029,6 +1074,8 @@ class EDPlayerOne(EDPlayer):
self.slf = None
self.location = EDLocation()
self._bounty = None
+ self.bounties = {}
+ self.fines = {}
self.instance.reset()
self.to_normal_space()
self._touch()
@@ -1326,4 +1373,4 @@ class EDPlayerOne(EDPlayer):
def reset_stats(self):
self.mining_stats.reset()
- self.bounty_hunting_stats.reset()
+ self.bounty_hunting_stats.reset()
\ No newline at end of file
diff --git a/edr/edrautoupdater.py b/edr/edrautoupdater.py
index e565923..e214885 100644
--- a/edr/edrautoupdater.py
+++ b/edr/edrautoupdater.py
@@ -23,16 +23,7 @@ class EDRAutoUpdater(object):
self.output = EDRAutoUpdater.LATEST
- # WARNING:
- # - could potentially be abused to deploy malicious code and deploy updated features to EDR plugin
- # -
- # MITIGATION:
- # - disable this code manually via forked repo and adjust the REPO attribute accordingly.
- # - set permissions on the plugins folder to ensure UAC prevents this automatic updater
def download_latest(self):
- # MITIGATION: return true
- return True
-
if not os.path.exists(self.updates):
try:
os.makedirs(self.updates)
@@ -102,3 +93,4 @@ class EDRAutoUpdater(object):
if not assets:
return None
return assets[0].get("browser_download_url", None)
+
diff --git a/edr/edrclient.py b/edr/edrclient.py
index 821b592..baf0631 100644
--- a/edr/edrclient.py
+++ b/edr/edrclient.py
@@ -1,8 +1,10 @@
# coding= utf-8
from __future__ import absolute_import
+from copy import deepcopy
#from builtins import map, filter
import datetime
+import itertools
from sys import float_repr_style
import sys
import time
@@ -10,6 +12,7 @@ import random
import math
import re
import json
+from edrfleetcarrier import EDRFleetCarrier
try:
# for Python2
@@ -504,7 +507,6 @@ class EDRClient(object):
self._direct_fc_link = notebook.Label(frame, text=_(u"Configure your Fleet Carrier channel in config/user_config.ini"))
self._private_fc_link.grid(padx=10, row=18, column=1, sticky=tk.EW)
self._direct_fc_link.grid(padx=10, row=19, column=1, sticky=tk.EW)
- # ttkHyperlinkLabel.HyperlinkLabel(frame, text=_(u"Configure your Fleet Carrier channel in config/user_config.ini"), background=notebook.Label().cget('background'), url="https://example.org/TODO", underline=True)
if self.fc_jump_psa == _(u'Private'):
self._direct_fc_link.grid_remove()
elif self.fc_jump_psa == _(u'Direct'):
@@ -604,10 +606,7 @@ class EDRClient(object):
facts = [_(u"Crimes will not be reported.")]
else:
return False
- # TODO bug at 2022-04-04 06:41:06.827 UTC - INFO - 11408:3184:3184 <plugins>.EDR.edrlog.EDRLog.log:32: Updating system info (was missing or obsolete). HIP 69157 vs. HIP 69200
- # EDRLOG.log(u"Notify about {}; details: {}".format(header, details[0]), "DEBUG")
- # TypeError: 'dict_keys' object is not subscriptable
-
+
self.__notify(header, facts, clear_before = True)
return True
@@ -1109,7 +1108,7 @@ class EDRClient(object):
self.__notify(_("Mission rewards eval"), [_("Nothing noteworthy to share")], clear_before=True)
def eval(self, eval_type):
- canonical_commands = ["power", "backpack", "locker"]
+ canonical_commands = ["power", "backpack", "locker", "bar", "bar stock", "bar demand"]
synonym_commands = {"power": ["priority", "pp", "priorities"]}
supported_commands = set(canonical_commands + synonym_commands["power"])
if eval_type not in supported_commands:
@@ -1131,6 +1130,10 @@ class EDRClient(object):
self.eval_backpack()
elif eval_type == "locker":
self.eval_locker()
+ elif eval_type in ["bar", "bar stock"]:
+ self.eval_bar()
+ elif eval_type == "bar demand":
+ self.eval_bar(stock=False)
def eval_build(self):
if not self.player.mothership.update_modules():
@@ -1184,6 +1187,24 @@ class EDRClient(object):
elif not passive:
self.__notify(_("Storage assessment"), [_(u"Empty ship locker?")], clear_before=True)
+ def eval_bar(self, stock=True):
+ header = _("Bar: stock assessment") if stock else _("Bar: demand assessment")
+ if not self.player.last_station or not self.player.last_station.type == "FleetCarrier" or not self.player.last_station.bar:
+ self.__notify(header, [_(u"Unexpected state: either no fleet carrier, or no bar?")], clear_before = True)
+ return False
+
+ bar = self.player.last_station.bar
+ items = bar.items_in_stock() if stock else bar.items_in_demand()
+ if items:
+ details = self.__eval_good_micro_resources(items) if stock else self.__eval_bad_micro_resources(items)
+ if details:
+ legend = [_(u"Kind: best items (b=blueprint, u=upgrades, x=trading, e=eng. unlocks)")] if stock else [_(u"Kind: worst items (b=blueprint, u=upgrades, x=trading, e=eng. unlocks)")]
+ self.__notify(header, legend + details, clear_before=True)
+ return True
+ else:
+ self.__notify(header, [_(u"Nothing noteworthy")], clear_before = True)
+ return False
+
def __eval_micro_resources(self, micro_resources, from_backpack=False):
discardable = [self.player.inventory.oneliner(name, from_backpack) for name in micro_resources if (self.player.engineers.is_useless(name) and self.player.inventory.count(name, from_backpack=from_backpack, from_locker=not from_backpack))]
unnecessary = [self.player.inventory.oneliner(name, from_backpack) for name in micro_resources if (self.player.engineers.is_unnecessary(name) and self.player.inventory.count(name, from_backpack=from_backpack, from_locker=not from_backpack))]
@@ -1196,6 +1217,119 @@ class EDRClient(object):
details.append(_(u"Unnecessary: {}").format(", ".join(unnecessary)))
return details
+ def __eval_good_micro_resources(self, micro_resources):
+ self_unlocking = [self.player.remlok_helmet.describe_odyssey_material_short(name) for name in micro_resources if self.player.engineers.is_necessary(name)]
+ other_unlocking = [self.player.remlok_helmet.describe_odyssey_material_short(name) for name in micro_resources if (self.player.engineers.is_contributing(name) and self.player.engineers.is_unnecessary(name))]
+ engineering_assets = [[self.player.remlok_helmet.describe_odyssey_material_short(name, ignore_eng_unlocks=True), self.player.remlok_helmet.how_useful(name)] for name in micro_resources if self.player.remlok_helmet.is_assets(name) and self.player.remlok_helmet.how_useful(name) > 0]
+ engineering_goods = [[self.player.remlok_helmet.describe_odyssey_material_short(name, ignore_eng_unlocks=True), self.player.remlok_helmet.how_useful(name)] for name in micro_resources if self.player.remlok_helmet.is_goods(name) and self.player.remlok_helmet.how_useful(name) > 0]
+ engineering_data = [[self.player.remlok_helmet.describe_odyssey_material_short(name, ignore_eng_unlocks=True), self.player.remlok_helmet.how_useful(name)] for name in micro_resources if self.player.remlok_helmet.is_data(name) and self.player.remlok_helmet.how_useful(name) > 0]
+ sorted_engineering_assets = sorted(engineering_assets, key=lambda b: b[1], reverse=True)
+ sorted_engineering_goods = sorted(engineering_goods, key=lambda b: b[1], reverse=True)
+ sorted_engineering_data = sorted(engineering_data, key=lambda b: b[1], reverse=True)
+ details = []
+ if self_unlocking:
+ details.append(_(u"Unlocks: {}").format(", ".join(self_unlocking)))
+ if sorted_engineering_assets:
+ details.append(_(u"Assets: {}").format(", ".join([pair[0] for pair in sorted_engineering_assets])))
+ if sorted_engineering_goods:
+ details.append(_(u"Goods: {}").format(", ".join([pair[0] for pair in sorted_engineering_goods])))
+ if sorted_engineering_data:
+ details.append(_(u"Data: {}").format(", ".join([pair[0] for pair in sorted_engineering_data])))
+ if other_unlocking:
+ details.append(_(u"Unlocked: {}").format(", ".join(other_unlocking)))
+ return details
+
+ def __eval_bad_micro_resources(self, micro_resources):
+ other_unlocking = [self.player.remlok_helmet.describe_odyssey_material_short(name) for name in micro_resources if (self.player.engineers.is_contributing(name) and self.player.engineers.is_unnecessary(name) and self.player.inventory.count(name))]
+ engineering_assets = [[self.player.remlok_helmet.describe_odyssey_material_short(name, ignore_eng_unlocks=True), self.player.remlok_helmet.how_useful(name)] for name in micro_resources if self.player.remlok_helmet.is_assets(name) and self.player.inventory.count(name)]
+ engineering_goods = [[self.player.remlok_helmet.describe_odyssey_material_short(name, ignore_eng_unlocks=True), self.player.remlok_helmet.how_useful(name)] for name in micro_resources if self.player.remlok_helmet.is_goods(name) and self.player.inventory.count(name)]
+ engineering_data = [[self.player.remlok_helmet.describe_odyssey_material_short(name, ignore_eng_unlocks=True), self.player.remlok_helmet.how_useful(name)] for name in micro_resources if self.player.remlok_helmet.is_data(name) and self.player.inventory.count(name)]
+ sorted_engineering_assets = sorted(engineering_assets, key=lambda b: b[1])
+ sorted_engineering_goods = sorted(engineering_goods, key=lambda b: b[1])
+ sorted_engineering_data = sorted(engineering_data, key=lambda b: b[1])
+ details = []
+ if sorted_engineering_assets:
+ details.append(_(u"Assets: {}").format(", ".join([pair[0] for pair in sorted_engineering_assets])))
+ if sorted_engineering_goods:
+ details.append(_(u"Goods: {}").format(", ".join([pair[0] for pair in sorted_engineering_goods])))
+ if sorted_engineering_data:
+ details.append(_(u"Data: {}").format(", ".join([pair[0] for pair in sorted_engineering_data])))
+ if other_unlocking:
+ details.append(_(u"Unlocked: {}").format(", ".join(other_unlocking)))
+ return details
+
+ def __summarize_fc_market(self, sale_orders, purchase_orders, max_len=2048):
+ remaining = max_len
+ details_purchases = []
+ details_sales = []
+ if sale_orders:
+ sale_orders_with_value = [[sale_orders[order], self.player.remlok_helmet.how_useful(order), order] for order in sale_orders if self.player.remlok_helmet.how_useful(order) >= 0]
+ sorted_sale_orders = sorted(sale_orders_with_value, key=lambda b: b[1], reverse=True)
+ for order in sorted_sale_orders:
+ quantity = pretty_print_number(order[0]["quantity"])
+ item = order[0]["l10n"][:21].capitalize()
+ price = pretty_print_number(order[0]["price"])
+ worthy = self.player.remlok_helmet.worthiness_odyssey_material(order[2])
+ if worthy:
+ details_sales.append(f'{quantity: >5} {item: <21} {price: >7} {worthy: >15}')
+ else:
+ details_sales.append(f'{quantity: >5} {item: <21} {price: >7}')
+
+ for order in purchase_orders:
+ quantity = pretty_print_number(purchase_orders[order]["quantity"])
+ item = purchase_orders[order]["l10n"][:21].capitalize()
+ price = pretty_print_number(purchase_orders[order]["price"])
+ details_purchases.append(f'{quantity: >5} {item: <21} {price: >7}')
+
+
+ header_sales = ""
+ if details_sales:
+ header_sales += _(f'{"Units": >5} {"Item": <21} {"Credits": >7} {"Worthiness*": >15}\n')
+ header_sales += _(f'{" [Selling] ":-^50}\n')
+
+
+ header_purchases = ""
+ if details_purchases:
+ if header_sales:
+ header_purchases += "\n\n"
+ header_purchases += _(f'{" [Buying] ":-^50}\n')
+ else:
+ header_purchases += _(f'{"Units": >5} {"Item": <15} {"Credits": >7}\n')
+ header_purchases += _(f'{" [Buying] ":-^50}\n')
+
+ opening = "```"
+ closing = "```"
+ summary = opening
+ summary_footer = closing
+ if details_sales:
+ summary_footer = "\n\n*: b=blueprint u=upgrades x=trading e=eng. unlocks"
+ summary_footer += closing
+
+ included_sales = []
+ included_purchases = []
+ remaining -= len(summary) + len(header_sales) + len(header_purchases) + len(summary_footer)
+ for s,p in itertools.zip_longest(details_sales, details_purchases):
+ if remaining <= 0:
+ break
+ if s and len(s) <= remaining:
+ included_sales.append(s)
+ remaining -= len(s)+1
+ if p and len(p) <= remaining:
+ included_purchases.append(p)
+ remaining -= len(p)+1
+
+ if included_sales:
+ summary += header_sales
+ summary += "\n".join(included_sales)
+
+ if included_purchases:
+ summary += header_purchases
+ summary += "\n".join(included_purchases)
+
+ summary += summary_footer
+ return summary
+
+
def evict_system(self, star_system):
self.edrsystems.evict(star_system)
@@ -1861,6 +1995,44 @@ class EDRClient(object):
return False
+ def fc_materials(self, entry):
+ if self.player.last_station == None or self.player.last_station.type != "FleetCarrier":
+ self.player.last_station = EDRFleetCarrier()
+
+ if not self.player.last_station.update_from_fcmaterials(entry):
+ return False
+
+ if not self.player.last_station.bar:
+ return False
+ return True
+
+ def ack_station_pending_reports(self):
+ if self.player.last_station == None:
+ return False
+ if self.player.last_station.type != "FleetCarrier":
+ return False
+
+ if not self.player.last_station.bar:
+ return False
+
+ if not self.player.last_station.bar.has_changed():
+ return True
+
+ adjusted_entry = {
+ "timestamp": self.player.last_station.bar.timestamp.as_js_epoch(),
+ "name": self.player.last_station.name,
+ "callsign": self.player.last_station.callsign,
+ "starSystem": self.player.star_system,
+ "reportedBy": self.player.name
+ }
+
+ if self.player.last_station.bar.items:
+ adjusted_entry["items"] = deepcopy(self.player.last_station.bar.items)
+
+ if self.edrsystems.update_fc_materials(self.player.star_system, adjusted_entry):
+ self.status = _(u"Reported bartender resources")
+ self.player.last_station.bar.acknowledge()
+
def __throttling_duration(self):
now_epoch = EDTime.py_epoch_now()
if now_epoch > self._throttle_until_timestamp:
@@ -1907,7 +2079,7 @@ class EDRClient(object):
else:
self.status = _(u"Message sent to EDR central")
self.__notify(_(u"EDR central"), details, clear_before = True)
- self._throttle_until_timestamp = EDTime.py_epoch_now() + 60*5 #TODO parameterize
+ self._throttle_until_timestamp = EDTime.py_epoch_now() + 60*5
return True
return False
@@ -2444,24 +2616,37 @@ class EDRClient(object):
details.extend(description)
self.__notify(_("Remlok Insights"), details, clear_before=True)
- # TODO eval carrier, ship storage?
-
def fleet_carrier_update(self):
if self.player.fleet_carrier.has_market_changed():
timeframe = 60*15
market = self.player.fleet_carrier.json_market(timeframe)
text_summary = self.player.fleet_carrier.text_summary(timeframe)
- # TODO send market to endpoint
details = []
if market.get("sales", None):
details.append(_("{} sale orders").format(len(market["sales"])))
if market.get("purchases", None):
details.append(_("{} purchase orders").format(len(market["purchases"])))
+
+ fc = self.server.fc(self.player.fleet_carrier.callsign, self.player.fleet_carrier.name, self.player.fleet_carrier.position, may_create=True)
+ if market and fc:
+ if self.player.fleet_carrier.is_open_to_all():
+ fc_id = list(fc)[0] if fc else None
+ market["owner"] = self.player.name
+ if self.server.report_fc_market(fc_id, market):
+ details.append(_("Access: all => Market info sent."))
+ sale_orders = self.player.fleet_carrier.sale_orders_within(timeframe)
+ purchase_orders = self.player.fleet_carrier.purchase_orders_within(timeframe)
+ summary = self.__summarize_fc_market(sale_orders, purchase_orders)
+ market["summary"] = summary
+ if self.edrdiscord.fc_market_update(market):
+ details.append(_(u"Sent FC trading info to your discord channel."))
+
+ self.player.fleet_carrier.acknowledge_market()
+
if details:
copy(text_summary)
details.append(_("Summary placed in the clipboard"))
self.__notify(_("Fleet Carrier status summary"), details, clear_before=True)
- self.player.fleet_carrier.acknowledge_market()
def carrier_trade(self, entry):
if entry.get("event", "") != "CarrierTradeOrder":
@@ -2475,9 +2660,6 @@ class EDRClient(object):
self.__notify(_("Trading Insights for {}").format(l_item), description, clear_before=True)
self.player.fleet_carrier.trade_order(entry)
- # TODO report trade orders to facilitate transactions between players in a batch to avoid spamming PUTs
- # use "event":"Music", "MusicTrack":"FleetCarrier_Managment" and "event":"CarrierStats" to close
- # perhaps { "timestamp":"2022-04-06T21:24:52Z", "event":"Music", "MusicTrack":"NoTrack" } to close on exiting the carrier screen?
def system_guidance(self, system_name, passive=False):
description = self.edrsystems.describe_system(system_name, self.player.star_system == system_name)
@@ -2674,7 +2856,6 @@ class EDRClient(object):
return result
def show_material_profiles(self):
- # TODO verify clear before
profiles = self.edrresourcefinder.profiles()
self.__notify(_(u"Available materials profiles"), [" ;; ".join(profiles)], clear_before=True)
diff --git a/edr/edrconfig.py b/edr/edrconfig.py
index e389198..4e03ce8 100644
--- a/edr/edrconfig.py
+++ b/edr/edrconfig.py
@@ -225,6 +225,12 @@ class EDRConfig(object):
def fc_presence_max_age(self):
return int(self.config.get('fc', 'fc_presence_max_age'))
+ def fc_materials_max_age(self):
+ return int(self.config.get('fc', 'fc_materials_max_age'))
+
+ def fc_max_age(self):
+ return int(self.config.get('fc', 'fc_max_age'))
+
def instance_fight_staleness_threshold(self):
return int(self.config.get('instance', 'fight_staleness_threshold'))
diff --git a/edr/edrdiscord.py b/edr/edrdiscord.py
index 920c099..dc8decf 100644
--- a/edr/edrdiscord.py
+++ b/edr/edrdiscord.py
@@ -212,8 +212,11 @@ class EDRDiscordIntegration(object):
"player": EDRDiscordWebhook(user_config.discord_webhook_for_comms("player", incoming=False))
}
- self.fc_jump = EDRDiscordWebhook(user_config.discord_webhook_for_fc("jump"))
-
+ self.fc = {
+ "jump": EDRDiscordWebhook(user_config.discord_webhook_for_fc("jump")),
+ "market": EDRDiscordWebhook(user_config.discord_webhook_for_fc("market"))
+ }
+
self.cognitive_novelty_threshold = edr_config.cognitive_novelty_threshold()
self.cognitive_comms_cache = LRUCache(edr_config.lru_max_size(), edr_config.blips_max_age())
self.cognitive_outgoing_comms_cache = LRUCache(edr_config.lru_max_size(), edr_config.blips_max_age())
@@ -228,13 +231,22 @@ class EDRDiscordIntegration(object):
return False
def fc_jump_scheduled(self, jump_info):
- if not self.fc_jump:
+ if not self.fc or not self.fc["jump"]:
return False
dm = self.__create_discord_fc_jump_psa(jump_info)
if not dm:
return False
- return self.fc_jump.send(dm)
+ return self.fc["jump"].send(dm)
+
+ def fc_market_update(self, market_info):
+ if not self.fc or not self.fc["market"]:
+ return False
+ dm = self.__create_discord_fc_market_psa(market_info)
+ if not dm:
+ return False
+
+ return self.fc["market"].send(dm)
def __process_incoming(self, entry):
dm = self.__create_discord_message(entry)
@@ -461,7 +473,39 @@ class EDRDiscordIntegration(object):
dm.content = "`{}` has scheduled a fleet carrier jump from `{}` to `{}`.".format(jump_info["owner"], jump_info["from"], jump_info["to"])
- # TODO
+ dm.username = cfg["name"]
+ dm.avatar_url = cfg["icon_url"]
+ dm.tts = cfg["tts"]
+
+ de = EDRDiscordEmbed()
+ de.title = _(u"Flight Plan")
+ departureTime = EDTime()
+ dm.content += " timestamp: {}".format(jump_info["at"])
+ departureTime.from_js_epoch(jump_info["at"])
+ de.description = _("```From : {}\nTo : {}\nTime(UTC): {}```").format(jump_info["from"], jump_info["to"], departureTime.as_hhmmss())
+ de.author = {
+ "name": "{} | {}".format(jump_info["name"], jump_info["callsign"]),
+ "url": cfg["url"],
+ "icon_url": cfg["icon_url"]
+ }
+ de.timestamp = datetime.now(timezone.utc).isoformat()
+ de.color = self.__colorcoded_fc_access(jump_info["access"])
+ de.footer = {
+ "text": _("via ED Recon on behalf of Cmdr {}").format(player.name),
+ "icon_url": "https://lekeno.github.io/favicon-16x16.png"
+ }
+ de.thumbnail = {
+ "url": "https://lekeno.github.io/fc-jump.png"
+ }
+
+ if sender_profile:
+ df = EDRDiscordField(_(u"Landing"), _("```Access : {}\nNotorious: {}```").format(self.__readable_fc_docking(jump_info["access"]), self.__readable_fc_notorious(jump_info["allow_notorious"])), True)
+ de.fields.append(df)
+
+ dm.add_embed(de)
+ return dm
+
+ def __colorcoded_fc_access(self, access):
colorLUT = {
"none": 13632027,
"friends": 4886754,
@@ -470,6 +514,9 @@ class EDRDiscordIntegration(object):
"all": 8311585,
}
+ return colorLUT.get(access, 10197915)
+
+ def __readable_fc_docking(self, access):
dockingLUT = {
"none": "Owner only",
"friends": "Friends",
@@ -477,34 +524,59 @@ class EDRDiscordIntegration(object):
"squadronfriends": "Squadmates & friends",
"all": "Anybody"
}
+
+ return dockingLUT.get(access, "?")
+
+ def __readable_fc_notorious(self, allow_notorious):
+ return _("Allowed") if allow_notorious else _("Not allowed")
+
+ def __create_discord_fc_market_psa(self, market_info):
+ player = self.edrcmdrs.player
+ from_cmdr = player.name
+ channel = "fc"
+
+ cfg = self.__combined_cfg(from_cmdr, channel)
+
+ sender_profile = self.edrcmdrs.cmdr(from_cmdr, autocreate=False, check_inara_server=False)
+ dm = EDRDiscordMessage()
+ if not market_info["sales"] and not market_info["purchases"]:
+ dm.content = "`{}` no longer trading items at their fleet carrier ({} | {}).".format(market_info["owner"], market_info["name"], market_info["callsign"])
+ return dm
+
+ trading_kinds = []
+ if market_info["sales"]:
+ trading_kinds.append(_("selling"))
+ if market_info["purchases"]:
+ trading_kinds.append(_("buying"))
+ dm.content = "`{}` is {} items at their fleet carrier ({} | {}).".format(market_info["owner"], " & ".join(trading_kinds), market_info["name"], market_info["callsign"])
+
dm.username = cfg["name"]
dm.avatar_url = cfg["icon_url"]
dm.tts = cfg["tts"]
de = EDRDiscordEmbed()
- de.title = _(u"Flight Plan")
- departureTime = EDTime()
- dm.content += " timestamp: {}".format(jump_info["at"])
- departureTime.from_js_epoch(jump_info["at"])
- de.description = _("```From : {}\nTo : {}\nTime(UTC): {}```").format(jump_info["from"], jump_info["to"], departureTime.as_hhmmss())
+ de.title = _(u"Bar / Market trading")
+ de.description = market_info["summary"]
de.author = {
- "name": "{} | {}".format(jump_info["name"], jump_info["callsign"]),
+ "name": "{} | {}".format(market_info["name"], market_info["callsign"]),
"url": cfg["url"],
"icon_url": cfg["icon_url"]
}
de.timestamp = datetime.now(timezone.utc).isoformat()
- de.color = colorLUT[jump_info["access"]] or 10197915
+ de.color = self.__colorcoded_fc_access(market_info["access"])
de.footer = {
"text": _("via ED Recon on behalf of Cmdr {}").format(player.name),
"icon_url": "https://lekeno.github.io/favicon-16x16.png"
}
de.thumbnail = {
- "url": "https://lekeno.github.io/fc-jump.png"
+ "url": "https://lekeno.github.io/fc-trade.png"
}
if sender_profile:
- df = EDRDiscordField(_(u"Landing"), _("```Access : {}\nNotorious: {}```").format(dockingLUT[jump_info["access"]] or "?", _("Allowed") if jump_info["allow_notorious"] else _("Not allowed")), True)
+ df = EDRDiscordField(_(u"Landing"), _("```Access : {}\nNotorious: {}```").format(self.__readable_fc_docking(market_info["access"]), self.__readable_fc_notorious(market_info["allow_notorious"])), True)
+ de.fields.append(df)
+ df = EDRDiscordField(_(u"Location"), _("```System: {}\nBody : {}```").format(market_info["location"]["system"], market_info["location"]["body"] or "N/A"), True)
de.fields.append(df)
dm.add_embed(de)
diff --git a/edr/edrfleet.py b/edr/edrfleet.py
index 7b1d80d..ae57b7a 100644
--- a/edr/edrfleet.py
+++ b/edr/edrfleet.py
@@ -213,7 +213,7 @@ class EDRFleet(object):
src_system = transfer_event.get("System", None)
src_market_id = transfer_event.get("MarketID", None)
distance = transfer_event.get("Distance", None)
- eta = EDTime.py_epoch_now() + int(math.ceil(distance * 9.75 + 300)) #TODO refactor, 1 more copy of this in edrsystems
+ eta = EDTime.eta_transfer(distance)
self.db.execute('DELETE from transits WHERE ship_id=?', (ship_id, ))
self.db.execute('''INSERT INTO transits(ship_id, eta, source_system, source_market_id, destination_system, destination_market_id)
VALUES (?,?,?,?,?,?)''', (ship_id, eta, src_system, src_market_id, dst_system, dst_market_id))
diff --git a/edr/edrfleetcarrier.py b/edr/edrfleetcarrier.py
index b472403..bacfd7c 100644
--- a/edr/edrfleetcarrier.py
+++ b/edr/edrfleetcarrier.py
@@ -1,6 +1,7 @@
from __future__ import absolute_import
import copy
from pickle import TRUE
+import re
import edtime
from edrlog import EDRLog
@@ -10,6 +11,7 @@ EDRLOG = EDRLog()
class EDRFleetCarrier(object):
def __init__(self):
self.id = None
+ self.type = "FleetCarrier"
self.callsign = None
self.name = None
self.access = "none"
@@ -27,10 +29,12 @@ class EDRFleetCarrier(object):
self.services = {}
self.ship_packs = {}
self.module_packs = {}
+ self.bar = None
def __reset(self):
self.id = None
+ self.type = "FleetCarrier"
self.callsign = None
self.name = None
self.access = "none"
@@ -56,6 +60,26 @@ class EDRFleetCarrier(object):
self.callsign = buy_event.get("Callsign", None)
self._position["system"] = buy_event.get("Location", None)
+ def update_from_location_or_docking(self, entry):
+ if not entry.get("event", None) in ["Location", "Docked"]:
+ return False
+
+ if entry.get("StationType", None) != "FleetCarrier":
+ return False
+
+ if self.id and self.id != entry.get("MarketID", None):
+ self.__reset()
+
+ self.id = entry.get("MarketID", None)
+ self.callsign = entry.get("StationName", None)
+ self.name = entry.get("Name", None)
+ self._position = {
+ "system": entry.get("StarSystem", None),
+ "body": entry.get("Body", None)
+ }
+ # TODO "StationServices":[ "dock", "autodock", "commodities", "contacts", "exploration", "outfitting", "crewlounge", "rearm", "refuel", "repair", "shipyard", "engineer", "flightcontroller", "stationoperations", "stationMenu", "carriermanagement", "carrierfuel", "livery", "voucherredemption", "socialspace", "bartender", "vistagenomics", "pioneersupplies" ],
+ return True
+
def update_from_stats(self, fc_stats_event):
if self.id and self.id != fc_stats_event.get("CarrierID", None):
self.__reset()
@@ -73,6 +97,15 @@ class EDRFleetCarrier(object):
self.__tweak_service(crew_description)
self.ship_packs = fc_stats_event.get("ShipPacks", {})
self.module_packs = fc_stats_event.get("ModulePacks", {})
+
+ def update_from_fcmaterials(self, fc_materials_event):
+ if self.id and self.id != fc_materials_event.get("MarketID", None):
+ self.__reset()
+ self.id = fc_materials_event.get("MarketID", None)
+ self.callsign = fc_materials_event.get("CarrierID", None)
+ self.name = fc_materials_event.get("CarrierName", None)
+ self.bar = EDRFleetCarrierBar()
+ return self.bar.from_fcmaterials(fc_materials_event)
def jump_requested(self, jump_request_event):
if self.id and self.id != jump_request_event.get("CarrierID", None):
@@ -155,6 +188,9 @@ class EDRFleetCarrier(object):
def is_parked(self):
return self.departure["destination"] is None or self.departure["time"] is None
+ def is_open_to_all(self, include_notorious=False):
+ return self.access == "all" and self.allow_notorious if include_notorious else True
+
def json_jump_schedule(self):
self.__update_position()
if self.id is None:
@@ -238,23 +274,26 @@ class EDRFleetCarrier(object):
pass
def json_market(self, timeframe=None):
- # TODO within timeframe
self.__update_position()
if self.id is None:
return None
+ since = edtime.EDTime.js_epoch_now()
+ if timeframe:
+ since -= timeframe*1000
return {
"id": self.id,
"callsign": self.callsign,
"name": self.name,
- "location": self.position,
+ "location": self._position,
"access": self.access,
"allow_notorious": self.allow_notorious,
- "sales": self.__sale_orders_within(timeframe),
- "purchases": self.__purchase_orders_within(timeframe)
+ "sales": self.sale_orders_within(timeframe),
+ "purchases": self.purchase_orders_within(timeframe),
+ "timestamp": since
}
- def __sale_orders_within(self, timeframe):
+ def sale_orders_within(self, timeframe):
all = copy.deepcopy(self.sale_orders)
if timeframe is None:
return all
@@ -262,7 +301,7 @@ class EDRFleetCarrier(object):
return {item: values for item, values in all.items() if values["timestamp"] >= threshold}
- def __purchase_orders_within(self, timeframe):
+ def purchase_orders_within(self, timeframe):
all = copy.deepcopy(self.purchase_orders)
if timeframe is None:
return all
@@ -279,14 +318,14 @@ class EDRFleetCarrier(object):
# TODO add services, tax, etc.
details_purchases = []
details_sales = []
- orders = self.__purchase_orders_within(timeframe)
+ orders = self.purchase_orders_within(timeframe)
for order in orders:
quantity = orders[order]["quantity"]
item = orders[order]["l10n"][:30]
price = orders[order]["price"]
details_purchases.append(f'{quantity: >8} {item: <30} {price: >10n}')
- orders = self.__sale_orders_within(timeframe)
+ orders = self.sale_orders_within(timeframe)
for order in orders:
quantity = orders[order]["quantity"]
item = orders[order]["l10n"][:30]
@@ -380,3 +419,56 @@ class EDRFleetCarrier(object):
self.services[role]["enabled"] = enabled
if name:
self.services[role]["crew"] = name
+
+class EDRFleetCarrierBar(object):
+ def __init__(self):
+ self.items = {}
+ self.updated = False
+ self.timestamp = edtime.EDTime()
+
+ def from_fcmaterials(self, entry):
+ self.items = {}
+
+ if entry.get("event", "") != "FCMaterials":
+ return False
+
+ items = entry.get("Items", [])
+ self.timestamp = edtime.EDTime()
+ self.updated = True
+ for item in items:
+ listing = item
+ if listing["Stock"] > 0 or listing["Demand"] > 0:
+ name_regex = r"^\$([a-z]+)_name;$"
+ m = re.match(name_regex, listing["Name"])
+ if m:
+ name = m.group(1)
+ self.items[name] = {
+ "price": listing["Price"],
+ "stock": listing["Stock"],
+ "demand": listing["Demand"]
+ }
+
+ return True
+
+ def acknowledge(self):
+ self.bar_updated = False
+
+ def has_changed(self):
+ return self.updated
+
+ def items_in_stock(self):
+ in_stock = {}
+ for item in self.items:
+ if self.items[item]["stock"] > 0:
+ in_stock[item] = copy.deepcopy(self.items[item])
+
+ return in_stock