forked from EVEIPH/EVE-IPH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlueprint.vb
2504 lines (1966 loc) · 112 KB
/
Blueprint.vb
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
' Class for Blueprint functions
Imports System.Data.SQLite
Public Class Blueprint
' Base variables
Private BlueprintID As Long
Private BlueprintName As String
Private BlueprintGroup As String
Private ItemID As Long
Private ItemName As String
Private ItemCategory As String
Private ItemCategoryID As Integer
Private ItemGroup As String
Private ItemGroupID As Integer
Private TechLevel As Integer
Private PortionSize As Long ' Number of items produced by one run of blueprint
Private BaseProductionTime As Long ' In seconds
Private MaxProductionLimit As Integer
Private ItemType As Integer
Private BlueprintRace As Integer
Private ItemVolume As Double ' Volume of produced item (1 item only)
' If we compare the components for building or buying
Private BuildBuy As Boolean
Private HasBuildableComponents As Boolean = False
Private AdditionalCosts As Double
' Taxes/Fees
' • Buy - When you buy something off the market (Buy from someone’s Sell Order – So Minimum Sell), you don’t pay taxes or broker fees
' o No Tax, No Broker Fee
' • Sell Order - When you set up a sell order, you pay broker fees up front and taxes for items when sold. (This will be min sell usually)
' o Tax, Broker Fee
' • Buy Order - When you set up buy order, you pay broker fees up front but no tax when someone sells to you. (This is max buy usually).
' o No Tax, Broker Fee
' • Sell - When you Sell to a buy order (simple sell), you only pay taxes. (This will be Max buy)
' o Tax, No Broker Fee
Private Taxes As Double ' See Above - Sell Order or Sell
Private DisplayTaxes As Double ' Public updatable number for display updates, for easy updates when clicked
Private BrokerFees As Double ' See above - Sell Order or Buy Order
Private DisplayBrokerFees As Double ' Public updatable number for display updates, for easy updates when clicked
' New cost variables
Private BaseJobCost As Double ' Total per material used * average price
Private BaseCopyJobCost As Double ' Total job cost for copying (need to use the BPC job cost)
Private BaseInventionJobCost As Double ' Total job cost for invention (need to use the BPC job cost)
' Base Fees for activity
Private JobFee As Double
' How much it costs to use each facility to manufacture items and parts
Private ManufacturingFacilityUsage As Double
Private IncludeManufacturingUsage As Boolean
Private ComponentFacilityUsage As Double
Private CapComponentFacilityUsage As Double
' Team costs
Private ManufacturingTeamFee As Double
Private ComponentTeamFee As Double
Private InventionTeamFee As Double
Private CopyTeamFee As Double
' Variables for calcuations
Private BPProductionTime As Double ' Production Time for 1 Run of Blueprint
Private TotalProductionTime As Double ' Production Time for 1 run of BP plus any components (this is to compare buying components vs. making them)
Private iME As Integer ' ME of Blueprint
Private iTE As Integer ' TE of Blueprint
Private UserRuns As Long ' Number of runs for blueprint the user selects
Private NumberofBlueprints As Integer ' Number of blueprints that the user is running
Private NumberofProductionLines As Integer ' Number of production lines the user is using
Private NumberofLaboratoryLines As Integer ' Number of laboratory lines the user is using
Private ComponentProductionTimes As New List(Of Double) ' A list of production times for components in this BP
' Character skills we are making this blueprint with
Private BPCharacter As Character ' The character for this BP
Private IndustrySkill As Integer ' Industry skill level of character
Private AdvancedIndustrySkill As Integer ' Old Production Efficiency skill, now reduces TE on building and researching
Private ScienceSkill As Integer
Private AIImplantValue As Double ' Advanced Industry Implant on character
Private CopyImplantValue As Double ' Copy implant value for this character
' Can do variables
Private CanInventRE As Boolean ' if the sent character for the blueprint can invent it from a T1 or artifact
Private CanBuildBP As Boolean ' if the user can build this BP
Private CanBuildAll As Boolean ' if the user can build this BP and all components
' Material lists
Public RawMaterials As Materials ' The list of All Raw materials for this item including the raw mats to make the buildable components in info list
Public ComponentMaterials As Materials ' List of all the required materials to make the item as shown in info list
' Saving all the materials for each built component
Public BuiltComponentList As BuiltItemList
' Saves all the raw materials on the bp that are not built
Private BPRawMats As Materials
' Skills required to make it
Private ReqBuildSkills As New EVESkillList ' Just this BP
Private ReqBuildComponentSkills As New EVESkillList ' All the skills to build just the components
' Invention variables
Private MaxRunsPerBP As Integer ' The max runs for a copy or invented bpc. Zero is unlimited runs
Private ReqInventionSkills As New EVESkillList ' For inventing this BP
Private ReqCopySkills As New EVESkillList ' For copying the BPC
Public InventionMaterials As Materials
Public CopyMaterials As Materials ' Some copies require items
Private InventionChance As Double
Private InventionDecryptor As New Decryptor
Private Relic As String ' Name of relic
Private TotalInventedRuns As Integer ' Number of runs all the invention jobs will produce
Private SingleInventedBPCRuns As Integer ' The runs on one bp invented
Private NumInventionJobs As Integer ' Number of invention jobs we will do
Private PerInventionRunCost As Double ' The cost per invention run based on the probability of success
Private TotalCopyCost As Double ' Total Cost of the BPCs for the T2 item - for copy materials for things like data sheets, etc when needed, and get enough successful inventions for these runs
Private CopyCost As Double ' Cost for the runs given
Private CopyTime As Double ' Total time in seconds to copy the BPCs needed for the T2 item
Private CopyUsage As Double ' Total Cost to make a copy
Private IncludeCopyTime As Boolean
Private IncludeCopyCosts As Boolean
Private IncludeCopyUsage As Boolean
Private TotalInventionCost As Double ' Total cost for all the invention runs to get enough successful inventions for these runs
Private InventionCost As Double ' Cost for the runs given
Private InventionTime As Double ' Total time in seconds to invent this bp
Private InventionUsage As Double ' Total cost to do this activity in a facility
Private IncludeInventionCosts As Boolean
Private IncludeInventionTime As Boolean
Private IncludeInventionUsage As Boolean ' just the facility usage, not the full cost use for both T2 and T3
Private AdvManufacturingSkillLevelBonus As Double ' The total TE reduction from skills required to invent and build this item (T2/T3)
Private InventionBPCTypeID As Long ' BP used to invent the BP we are building
' Price Variables
Private ItemMarketCost As Double ' Market cost of item
Private TotalRawCost As Double
Private TotalComponentCost As Double
Private TotalRawProfit As Double
Private TotalComponentProfit As Double
Private TotalRawProfitPercent As Double
Private TotalComponentProfitPercent As Double
Private TotalIPHRaw As Double
Private TotalIPHComponent As Double
' Save all the settings here, which has all the standings, fees, etc in it
Private BPUserSettings As ApplicationSettings
' What team they are using for this job
Private ManufacturingTeam As IndustryTeam
Private ComponentManufacturingTeam As IndustryTeam
Private InventionTeam As IndustryTeam
Private CopyTeam As IndustryTeam
' What facility are they using to produce?
Private ManufacturingFacility As IndustryFacility
Private ComponentManufacturingFacility As IndustryFacility
Private CapitalComponentManufacturingFacility As IndustryFacility ' For all capital parts
Private CopyFacility As IndustryFacility
Private InventionFacility As IndustryFacility
' This is to save the entire chain of blueprints on each line we have used and runs for each one
Private ProductionChain As List(Of List(Of Integer))
Private FWManufacturingCostBonus As Double
Private FWCopyingCostBonus As Double
Private FWInventionCostBonus As Double
' Helps determine if this is a component that might need special processing
Private IsComponentBP As Boolean
' BP Constructor
Public Sub New(ByVal BPBlueprintID As Long, ByVal BPRuns As Long, ByVal BPME As Integer, ByVal BPTE As Integer,
ByVal NumBlueprints As Integer, ByVal NumProductionLines As Integer, ByVal UserCharacter As Character, _
ByVal UserSettings As ApplicationSettings, ByVal BPBuildBuy As Boolean, ByVal UserAddlCosts As Double, BPProductionTeam As IndustryTeam, _
ByVal BPProductionFacility As IndustryFacility, ByVal BPComponentProductionTeam As IndustryTeam, ByVal BPComponentProductionFacility As IndustryFacility, _
ByVal BPCapComponentProductionFacility As IndustryFacility, Optional ByVal ComponentBP As Boolean = False)
Dim readerBP As SQLiteDataReader
Dim readerCost As SQLiteDataReader
Dim SQL As String = ""
SQL = "SELECT BLUEPRINT_ID, BLUEPRINT_NAME, BLUEPRINT_GROUP, ITEM_ID, ITEM_NAME, ITEM_CATEGORY_ID, ITEM_CATEGORY,"
SQL = SQL & "ITEM_GROUP_ID, ITEM_GROUP, TECH_LEVEL, PORTION_SIZE, BASE_PRODUCTION_TIME,"
SQL = SQL & "MAX_PRODUCTION_LIMIT, ITEM_TYPE, RACE_ID, VOLUME "
SQL = SQL & "FROM ALL_BLUEPRINTS INNER JOIN INVENTORY_TYPES ON ALL_BLUEPRINTS.ITEM_ID = INVENTORY_TYPES.typeID "
SQL = SQL & "WHERE BLUEPRINT_ID =" & BPBlueprintID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerBP = DBCommand.ExecuteReader
If readerBP.Read Then
' Set the variables
BlueprintID = readerBP.GetInt64(0)
BlueprintName = readerBP.GetString(1)
BlueprintGroup = readerBP.GetString(2)
ItemID = readerBP.GetInt64(3)
ItemName = readerBP.GetString(4)
ItemCategoryID = readerBP.GetInt32(5)
ItemCategory = readerBP.GetString(6)
ItemGroupID = readerBP.GetInt32(7)
ItemGroup = readerBP.GetString(8)
TechLevel = readerBP.GetInt32(9)
PortionSize = readerBP.GetInt64(10)
BaseProductionTime = readerBP.GetInt64(11)
MaxProductionLimit = readerBP.GetInt32(12)
ItemType = readerBP.GetInt32(13)
If Not readerBP.IsDBNull(12) Then
BlueprintRace = readerBP.GetInt32(14)
Else
BlueprintRace = 0
End If
ItemVolume = readerBP.GetDouble(15) * PortionSize ' Ammo, blocks, bombs, etc have more items per run
Else
Exit Sub
End If
readerBP.Close()
' Settings
BPUserSettings = UserSettings
RawMaterials = New Materials
ComponentMaterials = New Materials
InventionMaterials = New Materials
CopyMaterials = New Materials
TotalCopyCost = 0
CopyTime = 0
InventionTime = 0
ManufacturingFacilityUsage = 0
ComponentFacilityUsage = 0
CapComponentFacilityUsage = 0
CopyUsage = 0
InventionUsage = 0
BaseJobCost = 0
JobFee = 0
ManufacturingTeamFee = 0
ComponentTeamFee = 0
InventionDecryptor = NoDecryptor
Relic = ""
TotalInventedRuns = 0
NumInventionJobs = 0
' Do build/buy
BuildBuy = BPBuildBuy
iME = BPME
iTE = BPTE
Taxes = 0
BrokerFees = 0
' See if we want to include the costs
IncludeManufacturingUsage = BPProductionFacility.IncludeActivityUsage
' If they send zero lines, then set to the user skills
If NumProductionLines = 0 Then ' 3387 mass production and 24625 is adv mass production
NumberofProductionLines = BPCharacter.Skills.GetSkillLevel(3387) + BPCharacter.Skills.GetSkillLevel(24625) + 1
Else
NumberofProductionLines = NumProductionLines
End If
UserRuns = BPRuns
NumberofBlueprints = NumBlueprints
AdditionalCosts = UserAddlCosts
'If TechLevel > 1 Then
' UserRuns = CInt(Math.Ceiling(BPRuns / PortionSize))
'Else
UserRuns = BPRuns
'End If
BPCharacter = UserCharacter
' Set the skills to use for this blueprint - changed to type ID's due to name changes (1/29/2014)
AdvancedIndustrySkill = BPCharacter.Skills.GetSkillLevel(3388)
IndustrySkill = BPCharacter.Skills.GetSkillLevel(3380)
ScienceSkill = BPCharacter.Skills.GetSkillLevel(3402)
' Add production implant from settings
AIImplantValue = 1 - UserSettings.ManufacturingImplantValue
' Teams
ManufacturingTeam = BPProductionTeam
ComponentManufacturingTeam = BPComponentProductionTeam
' Production facilities
ManufacturingFacility = BPProductionFacility
ComponentManufacturingFacility = BPComponentProductionFacility
CapitalComponentManufacturingFacility = BPCapComponentProductionFacility
' Set the faction warfare bonus for the usage calculations
Select Case ManufacturingFacility.FWUpgradeLevel
Case 1
FWManufacturingCostBonus = 0.9
Case 2
FWManufacturingCostBonus = 0.8
Case 3
FWManufacturingCostBonus = 0.7
Case 4
FWManufacturingCostBonus = 0.6
Case 5
FWManufacturingCostBonus = 0.5
Case Else
FWManufacturingCostBonus = 1
End Select
' Set the flag if the user sent to this blueprint can invent it
CanInventRE = False ' Can invent T1 BP to this T2 BP
CanBuildBP = True ' Can build BP (assume we can until we change it)
CanBuildAll = True ' Can build all components (assume we can until we change it)
HasBuildableComponents = False
' Look up the cost for the final item
SQL = "SELECT PRICE FROM ITEM_PRICES WHERE ITEM_ID =" & ItemID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerCost = DBCommand.ExecuteReader
Dim ItemCost As Double
If readerCost.Read Then
ItemCost = readerCost.GetDouble(0)
Else
ItemCost = 0
End If
' Full cost of items is portion size (ammo, bombs, etc) times runs times cost
ItemMarketCost = ItemCost * UserRuns * PortionSize
BuiltComponentList = New BuiltItemList
BPRawMats = New Materials
readerCost.Close()
readerCost = Nothing
readerBP.Close()
readerBP = Nothing
DBCommand = Nothing
' Set the invention variables to default
IncludeInventionCosts = False
IncludeInventionTime = False
IncludeInventionUsage = False
IncludeCopyCosts = False
IncludeCopyTime = False
IncludeCopyUsage = False
InventionChance = 0
TotalInventedRuns = 0
SingleInventedBPCRuns = 0
NumInventionJobs = 0
TotalCopyCost = 0
CopyTime = 0
CopyUsage = 0
TotalInventionCost = 0
InventionTime = 0
InventionUsage = 0
InventionDecryptor = NoDecryptor
Relic = ""
' 3406 laboratory operation and 24624 is adv laboratory operation
NumberofLaboratoryLines = 0
' Save teams
InventionTeam = NoTeam
CopyTeam = NoTeam
InventionTeamFee = 0
CopyTeamFee = 0
' Save copy and invention facility
CopyFacility = NoFacility
InventionFacility = NoFacility
' Invention variable inputs - The BPC or Relic first
InventionBPCTypeID = 0
' Set the Decryptor data
InventionDecryptor = NoDecryptor
' Implement passing in the runs per copy later based on user API, right now though this is unlimited
MaxRunsPerBP = 0
IsComponentBP = ComponentBP
ProductionChain = New List(Of List(Of Integer))
End Sub
Public Function InventBlueprint(ByVal NumLaboratoryLines As Integer, ByVal BPDecryptor As Decryptor, _
ByVal BPInventionFacility As IndustryFacility, ByVal BPInventionTeam As IndustryTeam, _
ByVal BPCopyFacility As IndustryFacility, ByVal BPCopyTeam As IndustryTeam, ByVal InventionItemTypeID As Long) As Integer
' Don't invent these
If BlueprintName.Contains("Edition") Or BlueprintName.Contains("Polarized") Or BlueprintName.Contains("'Augmented'") Then
Return 0
End If
' 3406 laboratory operation and 24624 is adv laboratory operation
NumberofLaboratoryLines = NumLaboratoryLines
' Save teams
InventionTeam = BPInventionTeam
CopyTeam = BPCopyTeam
InventionTeamFee = 0
CopyTeamFee = 0
' Save copy and invention facility
CopyFacility = BPCopyFacility
InventionFacility = BPInventionFacility
' Set the FW bonus levels
Select Case CopyFacility.FWUpgradeLevel
Case 1
FWCopyingCostBonus = 0.9
Case 2
FWCopyingCostBonus = 0.8
Case 3
FWCopyingCostBonus = 0.7
Case 4
FWCopyingCostBonus = 0.6
Case 5
FWCopyingCostBonus = 0.5
Case Else
FWCopyingCostBonus = 1
End Select
Select Case InventionFacility.FWUpgradeLevel
Case 1
FWInventionCostBonus = 0.9
Case 2
FWInventionCostBonus = 0.8
Case 3
FWInventionCostBonus = 0.7
Case 4
FWInventionCostBonus = 0.6
Case 5
FWInventionCostBonus = 0.5
Case Else
FWInventionCostBonus = 1
End Select
' Invention variable inputs - The BPC or Relic first
InventionBPCTypeID = InventionItemTypeID
' Set the Decryptor data
InventionDecryptor = BPDecryptor
' Invention and Copy costs/times are set after getting the full base job materials
IncludeInventionCosts = InventionFacility.IncludeActivityCost
IncludeInventionTime = InventionFacility.IncludeActivityTime
IncludeInventionUsage = InventionFacility.IncludeActivityUsage
IncludeCopyCosts = CopyFacility.IncludeActivityCost
IncludeCopyTime = CopyFacility.IncludeActivityTime
IncludeCopyUsage = CopyFacility.IncludeActivityUsage
' Set the invention data
' Set the T2/T3 skills to invent from the T1 version
Call SetInventionSkills()
' Set the T2/T3 skills to copy from the T1 BPC
Call SetCopySkills()
' Set the invention flag
CanInventRE = UserHasReqSkills(BPCharacter.Skills, ReqInventionSkills)
' Use typical invention costs to invent this
Dim InventedBPs As Integer = InventREBlueprint(Not CanInventRE)
' Save the max runs per invented bpc
MaxRunsPerBP = SingleInventedBPCRuns
' Reset the number of bps needed based on the runs we have
NumberofBlueprints = CInt(Math.Ceiling(UserRuns / MaxRunsPerBP))
Return InventedBPs
End Function
' Base build function that takes a look at the number of blueprints the user wants to use and then builts each blueprint batch
Public Sub BuildItems(ByVal SetTaxes As Boolean, ByVal SetBrokerFees As Boolean, ByVal SetProductionCosts As Boolean, _
ByVal IgnoreMinerals As Boolean, ByVal IgnoreT1Item As Boolean)
' Need to check for the number of BPs sent and run multiple Sessions if necessary. Also, look at the number of lines per batch
If NumberofBlueprints = 1 Then
'Just run the normal function and it will set everything
Call BuildItem(SetTaxes, SetBrokerFees, SetProductionCosts, IgnoreMinerals, IgnoreT1Item)
Else ' Multi bps
Dim BatchBlueprint As Blueprint
Dim ComponentBlueprint As Blueprint
Dim RunsPerLine As Integer
Dim ExtraRuns As Integer
Dim AdjRunsperBP As Integer
Dim BatchList As New List(Of Integer)
Dim Batches As Integer
If UserRuns < NumberofBlueprints Then
' Can't run more bps than runs, so reset to the runs - 1 bp per run
NumberofBlueprints = CInt(UserRuns)
End If
' For bps with unlimited runs, assume that the most efficient is to run max runs on each line in one batch,
' so reset if bps are greater than lines
If MaxRunsPerBP = 0 Then
If NumberofBlueprints > NumberofProductionLines Then
' We can't run more bps than the lines entered, so reset this
NumberofBlueprints = NumberofProductionLines
End If
Batches = 1
Else
' How many batches do we run in the production chain?
Batches = CInt(Math.Ceiling(UserRuns / (MaxRunsPerBP * NumberofProductionLines)))
End If
' set the minimum per bp, shouldn't go over the runs per bp since the user sends in the total numbps they need
RunsPerLine = CInt(Math.Floor(UserRuns / NumberofBlueprints))
ExtraRuns = CInt(UserRuns - (RunsPerLine * NumberofBlueprints))
' To track how many runs we have used in the batch setup
Dim RunTracker As Long = 0
Dim TestList As New List(Of Integer)
' Fill a list of runs per bp
For i = 0 To Batches - 1
For j = 0 To NumberofProductionLines - 1
' As we add the runs, adjust with extra runs proportionally until they are gone
If ExtraRuns <> 0 Then
' Since it's a fraction of a total batch run, this will always just be one until gone ** not right?
AdjRunsperBP = RunsPerLine + 1
ExtraRuns = ExtraRuns - 1 ' Adjust extra
Else
' No extra runs, so just add the original runs now
AdjRunsperBP = RunsPerLine
End If
BatchList.Add(AdjRunsperBP)
TestList.Add(AdjRunsperBP)
' If we have used up all the runs, then exit the loop
RunTracker += AdjRunsperBP
If RunTracker = UserRuns Then
Exit For
End If
If AdjRunsperBP = MaxRunsPerBP Then
' Reset the adjusteded runs per bp to match invented amount, or if zero let it keep summing up for T1
AdjRunsperBP = 0
End If
Next
' Add the above batchlist to the chain
ProductionChain.Add(BatchList)
' Reset the batch list
BatchList = New List(Of Integer)
Next
' Now we just build each BP for the runs in the batch and total up all the variables - apply additional costs per batch
' Need to revisit for efficiency - will run one batch for each unique runs in the production chain and muliply by number of unique run batches
For i = 0 To ProductionChain.Count - 1
For j = 0 To ProductionChain(i).Count - 1
Application.DoEvents()
BatchBlueprint = New Blueprint(BlueprintID, ProductionChain(i)(j), iME, iTE, 1, NumberofProductionLines, BPCharacter, BPUserSettings, BuildBuy, _
CDbl(AdditionalCosts / ProductionChain.Count), ManufacturingTeam, ManufacturingFacility, ComponentManufacturingTeam, _
ComponentManufacturingFacility, CapitalComponentManufacturingFacility)
Call BatchBlueprint.BuildItem(SetTaxes, SetBrokerFees, SetProductionCosts, IgnoreMinerals, IgnoreT1Item)
' Sum up all the stuff that is batch dependent
With BatchBlueprint
' Save all the variables
If BatchBlueprint.HasBuildableComponents And HasBuildableComponents = False Then
HasBuildableComponents = True
End If
' Assumption is that we can build the bp
If Not BatchBlueprint.CanBuildBP And CanBuildBP = True Then
CanBuildBP = False
End If
If Not BatchBlueprint.CanBuildAll And CanBuildAll = True Then
CanBuildAll = False
End If
' Material lists - don't copy the raw mats yet, will be rebuilt below
If Not IsNothing(.GetComponentMaterials.GetMaterialList) Then
For k = 0 To .GetComponentMaterials.GetMaterialList.Count - 1
' Only add materials we are not building, built materials will get added below
If .GetComponentMaterials.GetMaterialList(k).GetBuildItem = False Then
Call ComponentMaterials.InsertMaterial(.GetComponentMaterials.GetMaterialList(k))
End If
Next
End If
' Add all new components to the blueprint list to rebuild later
For Each BI In .GetComponentsList.GetBuiltItemList
Call BuiltComponentList.AddBuiltItem(BI)
Next
' Save the raw mats on the bp only
If Not IsNothing(.GetBPRawMaterials.GetMaterialList) Then
Call BPRawMats.InsertMaterialList(.GetBPRawMaterials.GetMaterialList)
End If
' Don't add this, it's only the largest time from the batch session and then multiply it later
If .GetProductionTime > BPProductionTime Then
BPProductionTime = .GetProductionTime
End If
Taxes += .GetSalesTaxes
BrokerFees += .GetSalesBrokerFees
' New cost variables
BaseJobCost += .GetBaseJobCost
' Base Fees for activity
JobFee += .GetJobFee
' How much it costs to use each facility to manufacture items
ManufacturingFacilityUsage += .GetManufacturingFacilityUsage
' Team costs
ManufacturingTeamFee += .GetManufacturingTeamFee
ComponentTeamFee += .GetComponentTeamFee
InventionTeamFee = 0 ' No invention teams
CopyTeamFee += .CopyTeamFee
End With
Next
Next
' Finally we need to calculate each component again as 1 bp and 1 batch so that the numbers line up
' We assume that we will build all the components first before doing Sessions - this makes shopping list updates easier
' Will revisit but the number of components is set by the blueprint
' First copy in all the raw mats from the blueprint
For i = 0 To BPRawMats.GetMaterialList.Count - 1
Call RawMaterials.InsertMaterial(BPRawMats.GetMaterialList(i))
Next
' Reset the production times
ComponentProductionTimes = New List(Of Double)
' Now build the components as x runs, with 1 bp
For i = 0 To BuiltComponentList.GetBuiltItemList.Count - 1
Dim TempComponentFacility As IndustryFacility
Dim SQL As String
Dim rsCheck As SQLiteDataReader
Dim CategoryName As String = ""
Dim GroupID As Integer = 0
Dim MarketPrice As Double = 0
Dim PortionSize As Integer = 1
With BuiltComponentList.GetBuiltItemList(i)
Application.DoEvents()
SQL = "SELECT ALL_BLUEPRINTS.ITEM_GROUP_ID, ALL_BLUEPRINTS.ITEM_CATEGORY, ITEM_PRICES.PRICE, PORTION_SIZE "
SQL = SQL & "FROM ALL_BLUEPRINTS, ITEM_PRICES WHERE ALL_BLUEPRINTS.ITEM_ID = ITEM_PRICES.ITEM_ID "
SQL = SQL & "AND ALL_BLUEPRINTS.ITEM_ID = " & .ItemTypeID
DBCommand = New SQLiteCommand(Sql, EVEDB.DBREf)
rsCheck = DBCommand.ExecuteReader
If rsCheck.Read() Then
GroupID = rsCheck.GetInt32(0)
CategoryName = rsCheck.GetString(1)
MarketPrice = rsCheck.GetDouble(2)
PortionSize = rsCheck.GetInt32(3)
End If
' Build the T1 component
If GroupID = AdvCapitalComponentGroupID Or GroupID = CapitalComponentGroupID Then
' Use capital component facility
TempComponentFacility = CapitalComponentManufacturingFacility
ElseIf IsT1BaseItemforT2(CategoryName) Then
' Want to build this in the manufacturing facility we are using for base T1 items used in T2
TempComponentFacility = ManufacturingFacility
Else ' Components
TempComponentFacility = ComponentManufacturingFacility
End If
' Adjust the runs by portion size
Dim TempItemQuantity = CLng(Math.Ceiling(.ItemQuantity / PortionSize))
ComponentBlueprint = New Blueprint(.BPTypeID, TempItemQuantity, .BuildME, .BuildTE, 1, _
NumberofProductionLines, BPCharacter, BPUserSettings, BuildBuy, _
0, ManufacturingTeam, TempComponentFacility, ComponentManufacturingTeam, _
ComponentManufacturingFacility, CapitalComponentManufacturingFacility, True)
Call ComponentBlueprint.BuildItem(SetTaxes, SetBrokerFees, SetProductionCosts, IgnoreMinerals, IgnoreT1Item)
' Now add all the raw materials from this bp
Call RawMaterials.InsertMaterialList(ComponentBlueprint.GetRawMaterials.GetMaterialList)
' Reset the component's material list for shopping list functionality
BuiltComponentList.GetBuiltItemList(i).BuildMaterials = CType(ComponentBlueprint.RawMaterials, Materials)
' Set the variables
BuiltComponentList.GetBuiltItemList(i).FacilityMEModifier = ComponentBlueprint.ManufacturingFacility.MaterialMultiplier ' Save MM used on component
BuiltComponentList.GetBuiltItemList(i).FacilityType = ComponentBlueprint.ManufacturingFacility.FacilityType
BuiltComponentList.GetBuiltItemList(i).IncludeActivityCost = ComponentBlueprint.ManufacturingFacility.IncludeActivityCost
BuiltComponentList.GetBuiltItemList(i).IncludeActivityTime = ComponentBlueprint.ManufacturingFacility.IncludeActivityTime
BuiltComponentList.GetBuiltItemList(i).IncludeActivityUsage = ComponentBlueprint.ManufacturingFacility.IncludeActivityUsage
' See if we need to add the system on to the end of the build location for POS
If BuiltComponentList.GetBuiltItemList(i).FacilityType = POSFacility Then
BuiltComponentList.GetBuiltItemList(i).FacilityLocation = ComponentBlueprint.ManufacturingFacility.FacilityName & " (" & ComponentBlueprint.GetManufacturingFacility.SolarSystemName & ")"
Else
BuiltComponentList.GetBuiltItemList(i).FacilityLocation = ComponentBlueprint.ManufacturingFacility.FacilityName
End If
Dim ItemPrice As Double = 0
Dim OwnedBP As Boolean
Call GetMETEforBP(ComponentBlueprint.BlueprintID, ComponentBlueprint.TechLevel, BPUserSettings.DefaultBPME, BPUserSettings.DefaultBPTE, OwnedBP)
If BuildBuy And ((MarketPrice * .ItemQuantity > ComponentBlueprint.GetRawMaterials.GetTotalMaterialsCost _
And (BPUserSettings.SuggestBuildBPNotOwned)) _
Or (OwnedBP And Not BPUserSettings.SuggestBuildBPNotOwned) _
Or MarketPrice = 0) Then
' Market cost is greater than build cost, so set the mat cost to the build cost
ItemPrice = ComponentBlueprint.GetRawMaterials.GetTotalMaterialsCost / .ItemQuantity
Else
ItemPrice = MarketPrice
End If
' Add the built material to the component list now - this way we only add one blueprint produced material
Dim TempMat As New Material(.ItemTypeID, .ItemName, ComponentBlueprint.GetItemGroup, .ItemQuantity, .ItemVolume, _
ItemPrice, CStr(.BuildME), CStr(.BuildTE), True)
ComponentMaterials.InsertMaterial(TempMat)
End With
' Add the production time of this component to the total production time
Call ComponentProductionTimes.Add(ComponentBlueprint.GetProductionTime)
' Get the usage
If GroupID = AdvCapitalComponentGroupID Or GroupID = CapitalComponentGroupID Then
CapComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
Else
ComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
End If
Next
' Add any items that are not built but could be to the raw list
For j = 0 To ComponentMaterials.GetMaterialList.Count - 1
If ComponentMaterials.GetMaterialList(j).GetBuildItem = False And ComponentMaterials.GetMaterialList(j).GetItemME <> "-" Then
Call RawMaterials.InsertMaterial(ComponentMaterials.GetMaterialList(j))
End If
Next
' Update the bp production time to equal the longest runs per line times the number of batches - add in copy and invention time if we invented
BPProductionTime = (BPProductionTime + CopyTime + InventionTime) * Batches
' Set the total production time
If Not IsNothing(ComponentProductionTimes) Then
TotalProductionTime = BPProductionTime + GetComponentProductionTime(ComponentProductionTimes) + CopyTime + InventionTime
End If
' Finally recalculate our prices
Call SetPriceData(SetTaxes, SetBrokerFees)
End If
End Sub
' Sets the material versions for our blueprint
Private Sub BuildItem(ByVal SetTaxes As Boolean, ByVal SetBrokerFees As Boolean, ByVal SetProductionCosts As Boolean, _
ByVal IgnoreMinerals As Boolean, ByVal IgnoreT1Item As Boolean)
' Database stuff
Dim SQL As String
Dim readerBP As SQLiteDataReader
Dim readerME As SQLiteDataReader
Dim TempME As Integer
Dim TempTE As Integer
Dim OwnedBP As Boolean = False
' Recursion variables
Dim ComponentBlueprint As Blueprint = Nothing
Dim TempSkills As New EVESkillList
' The current material we are working with
Dim CurrentMaterial As Material
Dim CurrentMatQuantity As Long
Dim CurrentMaterialCategory As String
Dim tempMatQuantity As Long
Dim fudgeRAM As Boolean
' Temp Materials for passing
Dim TempMaterials As New Materials
Dim TempNumBPs As Integer = 1
' Select all materials to buid this BP
SQL = "SELECT ABM.BLUEPRINT_ID, MATERIAL_ID, QUANTITY, MATERIAL, MATERIAL_CATEGORY, ACTIVITY, "
SQL = SQL & "MATERIAL_VOLUME, PRICE, ADJUSTED_PRICE, groupID, MATERIAL_GROUP, PORTION_SIZE "
SQL = SQL & "FROM ALL_BLUEPRINT_MATERIALS AS ABM "
SQL = SQL & "LEFT OUTER JOIN ITEM_PRICES ON ABM.MATERIAL_ID = ITEM_PRICES.ITEM_ID, INVENTORY_TYPES "
SQL = SQL & "LEFT OUTER JOIN ALL_BLUEPRINTS ON ALL_BLUEPRINTS.ITEM_ID = ABM.MATERIAL_ID "
SQL = SQL & "WHERE ABM.BLUEPRINT_ID =" & BlueprintID & " AND ACTIVITY = 1 AND MATERIAL_ID = INVENTORY_TYPES.typeID "
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerBP = DBCommand.ExecuteReader
' For each material in the blueprint, calculate the total mats
' and load them into the list
While readerBP.Read
CurrentMaterialCategory = readerBP.GetString(4)
If CurrentMaterialCategory = "Skill" Then
' It's a skill, so just add it to the main list of BP skills
ReqBuildSkills.InsertSkill(readerBP.GetInt64(1), readerBP.GetInt32(2), 0, False, 0, "", Nothing, True)
ElseIf AddMaterial(CurrentMaterialCategory, readerBP.GetString(10), IgnoreMinerals, IgnoreT1Item) Then
' Set the current material - adjust with portion size though if sent
CurrentMaterial = New Material(readerBP.GetInt64(1), readerBP.GetString(3), CurrentMaterialCategory, readerBP.GetInt64(2), readerBP.GetDouble(6), If(readerBP.IsDBNull(7), 0, readerBP.GetDouble(7)), "", "")
' Save the base costs - before applying ME - if value is null (no price record) then set to 0
BaseJobCost += CurrentMaterial.GetQuantity * If(IsDBNull(readerBP.GetValue(8)), 0, readerBP.GetDouble(8))
' Set the quantity: required = max(runs,ceil(round(runs * baseQuantity * materialModifier,2))
CurrentMatQuantity = CLng(Math.Max(UserRuns, Math.Ceiling(Math.Round(UserRuns * CurrentMaterial.GetQuantity * SetBPMaterialModifier(), 2))))
If Not IsDBNull(readerBP.GetValue(11)) Then
' Divide by the portion size if this item has one (component buildable)
tempMatQuantity = CLng(CurrentMatQuantity)
CurrentMatQuantity = CLng(Math.Ceiling(CurrentMatQuantity / readerBP.GetInt64(11)))
if (tempMatQuantity <> CurrentMatQuantity)
fudgeRAM = True
End If
End If
' Update the quantity - just add the negative percent of the ME modifier to 1 and multiply
Call CurrentMaterial.SetQuantity(CurrentMatQuantity)
' If it has a value in ALL_BLUEPRINTS, then the item can be built from it's own BP
SQL = "SELECT BLUEPRINT_ID, TECH_LEVEL FROM ALL_BLUEPRINTS WHERE ITEM_ID =" & CurrentMaterial.GetMaterialTypeID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerME = DBCommand.ExecuteReader
' Treat augmented drones, polarized weapons, and all ship skins as just base blueprints - don't build the T2 items that they use (yet)
If readerME.Read And Not (BlueprintName.Contains("'Augmented'") And CurrentMaterial.GetMaterialGroup = "Drone") _
And Not BlueprintName.Contains("Edition") And Not BlueprintName.Contains("Polarized") Then
' We can build it from another BP
HasBuildableComponents = True
' Look up the ME/TE and owned data for the bp
Call GetMETEforBP(readerME.GetInt64(0), readerME.GetInt32(1), TempME, TempTE, OwnedBP)
' Update the current material's ME
CurrentMaterial.SetItemME(CStr(TempME))
Dim TempComponentFacility As IndustryFacility
' Build the T1 component
If readerBP.GetDouble(9) = AdvCapitalComponentGroupID Or readerBP.GetDouble(9) = CapitalComponentGroupID Then
' Use capital component facility
TempComponentFacility = CapitalComponentManufacturingFacility
ElseIf IsT1BaseItemforT2(CurrentMaterialCategory) Then
' Want to build this in the manufacturing facility we are using for base T1 items used in T2
TempComponentFacility = ManufacturingFacility
Else ' Components
TempComponentFacility = ComponentManufacturingFacility
End If
' For now only assume 1 bp and 1 line to build it - Later this section will have to be updated to use the remaining lines or maybe lines = numbps
ComponentBlueprint = New Blueprint(readerME.GetInt64(0), CLng(CurrentMaterial.GetQuantity), TempME, TempTE, _
1, 1, BPCharacter, BPUserSettings, BuildBuy, _
0, ComponentManufacturingTeam, TempComponentFacility, _
ComponentManufacturingTeam, ComponentManufacturingFacility, CapitalComponentManufacturingFacility, True)
' Set this blueprint with the quantity needed and get it's mats
Call ComponentBlueprint.BuildItem(SetTaxes, SetBrokerFees, SetProductionCosts, IgnoreMinerals, IgnoreT1Item)
' Determine if the component should be bought, or we should build it and add to the correct list
If BuildBuy Then
' Only build BPs that we own (if the user wants us to limit this) and the mat cost is greater than build, or no mat cost loaded (no market price so no idea if it's cheaper to buy or not) - Build it
If CurrentMaterial.GetTotalCost = 0 Or (CurrentMaterial.GetTotalCost > ComponentBlueprint.GetTotalRawCost _
And ((BPUserSettings.SuggestBuildBPNotOwned) Or _
(OwnedBP And Not BPUserSettings.SuggestBuildBPNotOwned))) Then
'*** BUILD ***
' We want to build this item
CurrentMaterial.SetBuildItem(True)
' Save the production time for this component
Call ComponentProductionTimes.Add(ComponentBlueprint.GetProductionTime)
' Get the skills for BP to build it and add them to the list
TempSkills = ComponentBlueprint.GetReqBPSkills
' Building this, so add fees to current (taxes for mats added in building item)
ManufacturingFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
' Get the component usage
Select Case ComponentBlueprint.GetItemGroupID
Case AdvCapitalComponentGroupID, CapitalComponentGroupID
CapComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
Case Else
ComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
End Select
' Save the component team fees
ComponentTeamFee += ComponentBlueprint.GetManufacturingTeamFee
' Since we are building this item, set the material cost to build cost per item, not buy
CurrentMaterial.SetBuildCost(ComponentBlueprint.GetRawMaterials.GetTotalMaterialsCost / CurrentMaterial.GetQuantity)
' Insert the raw mats of this blueprint
RawMaterials.InsertMaterialList(ComponentBlueprint.GetRawMaterials.GetMaterialList)
' Save the item built, it's ME and the materials it used
Dim TempBuiltItem As New BuiltItem
TempBuiltItem.BPTypeID = readerME.GetInt64(0)
TempBuiltItem.ItemTypeID = CurrentMaterial.GetMaterialTypeID
TempBuiltItem.ItemName = CurrentMaterial.GetMaterialName
TempBuiltItem.ItemQuantity = CurrentMaterial.GetQuantity
TempBuiltItem.BuildME = TempME
TempBuiltItem.BuildTE = TempTE
TempBuiltItem.ItemVolume = CurrentMaterial.GetVolume
TempBuiltItem.BuildMaterials = ComponentBlueprint.GetRawMaterials
TempBuiltItem.FacilityMEModifier = ComponentBlueprint.ManufacturingFacility.MaterialMultiplier ' Save MM used on component
TempBuiltItem.FacilityType = ComponentBlueprint.ManufacturingFacility.FacilityType
TempBuiltItem.IncludeActivityCost = ComponentBlueprint.ManufacturingFacility.IncludeActivityCost
TempBuiltItem.IncludeActivityTime = ComponentBlueprint.ManufacturingFacility.IncludeActivityTime
TempBuiltItem.IncludeActivityUsage = ComponentBlueprint.ManufacturingFacility.IncludeActivityUsage
' See if we need to add the system on to the end of the build location for POS
If TempBuiltItem.FacilityType = POSFacility Then
TempBuiltItem.FacilityLocation = ComponentBlueprint.ManufacturingFacility.FacilityName & " (" & ComponentBlueprint.GetManufacturingFacility.SolarSystemName & ")"
Else
TempBuiltItem.FacilityLocation = ComponentBlueprint.ManufacturingFacility.FacilityName
End If
BuiltComponentList.AddBuiltItem(CType(TempBuiltItem.Clone, BuiltItem))
Else ' *** BUY ***
' We want to buy this item, don't add raw mats but add the component to the buy list (raw mats)
CurrentMaterial.SetBuildItem(False)
' Also, not adding the build time to the lists
RawMaterials.InsertMaterial(CurrentMaterial)
End If
' Finally, insert all components into the build/buy list
ComponentMaterials.InsertMaterial(CurrentMaterial)
Else ' *** BUILD COMPONENT ALWAYS ***
' We want to build this item
CurrentMaterial.SetBuildItem(True)
' Save the production time for this component
Call ComponentProductionTimes.Add(ComponentBlueprint.GetProductionTime)
' Get the skills for BP to build it and add them to the list
TempSkills = ComponentBlueprint.GetReqBPSkills
' Get the component usage
Select Case ComponentBlueprint.GetItemGroupID
Case AdvCapitalComponentGroupID, CapitalComponentGroupID
CapComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
Case Else
ComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
End Select
' Save the component team fees
ComponentTeamFee += ComponentBlueprint.GetManufacturingTeamFee
' Insert the raw mats of this blueprint
RawMaterials.InsertMaterialList(ComponentBlueprint.GetRawMaterials.GetMaterialList)
If fudgeRAM Then
CurrentMaterial.SetQuantity(tempMatQuantity)