-
Notifications
You must be signed in to change notification settings - Fork 37
/
Blueprint.vb
3079 lines (2472 loc) · 146 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 Integer
Private BaseBP As Boolean ' for knowing the base bp opposed to component bps
Private BlueprintName As String
Private BlueprintGroupID As Integer
Private ItemID As Long
Private ItemName 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
' Helps determine if this is a component that might need special processing
Private BBItemtoFind As Long
Private BBList As New List(Of BuildBuyItem)
Private NewBPRequest As Boolean
' 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 EIV As Double ' Estimated Item Value - 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
Private AlphaCloneTax As Double
Private TotalUsage As Double
' How much it costs to use each facility to manufacture items and parts
Private ManufacturingFacilityUsage As Double
Private IncludeManufacturingUsage As Boolean
Private ReprocessingUsage As Double
Private ComponentFacilityUsage As Double
Private CapComponentFacilityUsage As Double
Private ReactionFacilityUsage As Double ' This stores the main reaction usage if the reaction is a composite and has other reactions
Private TotalReactionFacilityUsage As Double ' Total of all reaction facilities usage for totaling all reactions below a composite or collection of composites
' 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, reactions, researching
Private ScienceSkill As Integer
Private AIImplantValue As Double ' Advanced Industry Implant on character
Private CopyImplantValue As Double ' Copy implant value for this character
Private CharAdvIndustialShipConstruction As Integer ' Industry skill for advanced indy ships (T2)
Private CharAdvCapitalShipConstruction As Integer ' Industry skill for advanced Cap ships (T2) - Lancers
Private Const AdvISCSkill As Integer = 3396
Private Const AdvCSCSkill As Integer = 77725
' 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
Public BuiltComponentList As BuiltItemList ' Saving all the materials for each built component
Private BPRawMats As Materials ' Saves all the raw materials on the bp that are not built
' Skills required to make it
Private ReqBuildSkills As New EVESkillList(UserApplicationSettings.UseActiveSkillLevels) ' Just this BP
Private ReqBuildComponentSkills As New EVESkillList(UserApplicationSettings.UseActiveSkillLevels) ' 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(UserApplicationSettings.UseActiveSkillLevels) ' For inventing this BP
Private ReqCopySkills As New EVESkillList(UserApplicationSettings.UseActiveSkillLevels) ' 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 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
Private T2T3MaterialType As BuildMatType ' How do we build T2 and T3 items for components that are reactions and how deep they want to go
Private SellExcessItems As Boolean
Private SellExcessAmount As Double
Private ExcessMaterials As Materials ' This contains all materials for the entire blueprint as a reference
Private BPExcessMaterials As Materials ' Just the excess for the bp
Private UsedExcessMaterials As Materials ' List of materials updated by using from full excess list for updating BP list
' What facility are they using to produce?
Private MainManufacturingFacility As IndustryFacility
Private ComponentManufacturingFacility As IndustryFacility
Private CapitalComponentManufacturingFacility As IndustryFacility ' For all capital parts
Private ReactionFacility As IndustryFacility
Private CopyFacility As IndustryFacility
Private InventionFacility As IndustryFacility
Private ReprocessingFacility As IndustryFacility
Private OreConversionSettings As ConversionToOreSettings
' 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
Private ReactionBPGroups As New List(Of Integer)(New Integer() {1888, 1889, 1890, 4097})
Private FulcrumBonusesApply 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,
ByVal BPProductionFacility As IndustryFacility, ByVal BPComponentProductionFacility As IndustryFacility,
ByVal BPCapComponentProductionFacility As IndustryFacility, ByVal BPReactionFacility As IndustryFacility,
ByVal BPSellExcessItems As Boolean, ByVal BuildT2T3MaterialType As BuildMatType, ByVal OriginalBlueprint As Boolean,
Optional ByRef BuildBuyList As List(Of BuildBuyItem) = Nothing,
Optional ByRef BPReprocessingFacility As IndustryFacility = Nothing,
Optional CompressedOreSettings As ConversionToOreSettings = Nothing)
Dim readerBP As SQLiteDataReader
Dim SQL As String = ""
SQL = "SELECT BLUEPRINT_ID, BLUEPRINT_GROUP_ID, ITEM_ID, ITEM_GROUP_ID, ITEM_CATEGORY_ID, "
SQL &= "TECH_LEVEL, PORTION_SIZE, BASE_PRODUCTION_TIME, MAX_PRODUCTION_LIMIT, ITEM_TYPE, RACE_ID, packagedVolume "
SQL &= "FROM ALL_BLUEPRINTS_FACT INNER JOIN INVENTORY_TYPES ON ALL_BLUEPRINTS_FACT.ITEM_ID = INVENTORY_TYPES.typeID "
SQL &= "WHERE BLUEPRINT_ID =" & BPBlueprintID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
readerBP = DBCommand.ExecuteReader
If readerBP.Read Then
' Set the variables
BlueprintID = readerBP.GetInt32(0)
BlueprintName = GetTypeName(readerBP.GetInt32(0))
BlueprintGroupID = readerBP.GetInt32(1)
ItemID = readerBP.GetInt64(2)
ItemName = GetTypeName(readerBP.GetInt32(2))
ItemGroupID = readerBP.GetInt32(3)
ItemCategoryID = readerBP.GetInt32(4)
TechLevel = readerBP.GetInt32(5)
PortionSize = readerBP.GetInt64(6)
BaseProductionTime = readerBP.GetInt64(7)
MaxProductionLimit = readerBP.GetInt32(8)
ItemType = readerBP.GetInt32(9)
If Not readerBP.IsDBNull(10) Then
BlueprintRace = readerBP.GetInt32(10)
Else
BlueprintRace = 0
End If
If Not readerBP.IsDBNull(11) Then
ItemVolume = readerBP.GetDouble(11) * PortionSize ' Ammo, blocks, bombs, etc have more items per run
Else
ItemVolume = 10
End If
Else
Exit Sub
End If
readerBP.Close()
' Settings
BPUserSettings = UserSettings
BaseBP = OriginalBlueprint
T2T3MaterialType = BuildT2T3MaterialType
RawMaterials = New Materials
ComponentMaterials = New Materials
InventionMaterials = New Materials
CopyMaterials = New Materials
TotalCopyCost = 0
CopyTime = 0
InventionTime = 0
ManufacturingFacilityUsage = 0
ComponentFacilityUsage = 0
CapComponentFacilityUsage = 0
ReactionFacilityUsage = 0
TotalReactionFacilityUsage = 0
ReprocessingUsage = 0
CopyUsage = 0
InventionUsage = 0
EIV = 0
JobFee = 0
AlphaCloneTax = 0
TotalUsage = 0
InventionDecryptor = NoDecryptor
Relic = ""
TotalInventedRuns = 0
NumInventionJobs = 0
' Do build/buy
BuildBuy = BPBuildBuy
If Not IsNothing(BuildBuyList) Then
BBList = BuildBuyList
NewBPRequest = False
Else
NewBPRequest = True
End If
SellExcessItems = BPSellExcessItems
SellExcessAmount = 0
BPExcessMaterials = New Materials
ExcessMaterials = New Materials
UsedExcessMaterials = New Materials
iME = BPME
iTE = BPTE
Taxes = 0
BrokerFees = 0
' 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)
If IsReaction(ItemGroupID) Then
' Advanced industry only affects manufacturing and research times
AdvancedIndustrySkill = 0
Else
AdvancedIndustrySkill = BPCharacter.Skills.GetSkillLevel(3388)
End If
IndustrySkill = BPCharacter.Skills.GetSkillLevel(3380)
ScienceSkill = BPCharacter.Skills.GetSkillLevel(3402)
' Add production implant from settings
AIImplantValue = 1 - UserSettings.ManufacturingImplantValue
' Production facilities
MainManufacturingFacility = BPProductionFacility
ComponentManufacturingFacility = BPComponentProductionFacility
CapitalComponentManufacturingFacility = BPCapComponentProductionFacility
ReactionFacility = BPReactionFacility
OreConversionSettings = CompressedOreSettings
ReprocessingFacility = BPReprocessingFacility
FulcrumBonusesApply = GetFulcrumBonusFlagforItem(MainManufacturingFacility.FacilityID, BlueprintID)
' See if we want to include the costs
IncludeManufacturingUsage = BPProductionFacility.IncludeActivityUsage
' Set the faction warfare bonus for the usage calculations
Select Case MainManufacturingFacility.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
' Full cost of items is portion size (ammo, bombs, etc) times runs times cost
ItemMarketCost = GetItemPrice(ItemID) * UserRuns * PortionSize
BuiltComponentList = New BuiltItemList
BPRawMats = New Materials
' 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
InventionTime = 0
InventionUsage = 0
InventionDecryptor = NoDecryptor
Relic = ""
' 3406 laboratory operation and 24624 is adv laboratory operation
NumberofLaboratoryLines = 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, right now though this is unlimited
MaxRunsPerBP = 0
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 BPCopyFacility As IndustryFacility, ByVal InventionItemTypeID As Long) As Integer
' 3406 laboratory operation and 24624 is adv laboratory operation
NumberofLaboratoryLines = NumLaboratoryLines
' Save copy and invention facility
CopyFacility = BPCopyFacility
InventionFacility = BPInventionFacility
' Refresh the data on these for blueprints - categoryID = 9
CopyFacility.RefreshMMTMCMBonuses(0, 9)
InventionFacility.RefreshMMTMCMBonuses(0, 9)
' 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 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 BrokerFeeData As BrokerFeeInfo, 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, BrokerFeeData, SetProductionCosts, IgnoreMinerals, IgnoreT1Item, ExcessMaterials)
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
' 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
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)
' 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
' First get the BP's that are components of the main item we are building for future calculations
Dim rsBPComps As SQLiteDataReader
Dim BPComponentIDs As New List(Of Integer)
DBCommand = New SQLiteCommand(String.Format("SELECT MATERIAL_ID FROM ALL_BLUEPRINT_MATERIALS_FACT WHERE BLUEPRINT_ID={0} AND ACTIVITY IN (1,11)
AND CONSUME = 1 AND MATERIAL_ID IN (SELECT ITEM_ID FROM ALL_BLUEPRINTS_FACT)", BlueprintID), EVEDB.DBREf)
rsBPComps = DBCommand.ExecuteReader
While rsBPComps.Read
' These are the only items that are built from the base BP
BPComponentIDs.Add(rsBPComps.GetInt32(0))
End While
Dim BatchExcessMats As New Materials ' Excess with first bp
rsBPComps.Close()
' 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), MainManufacturingFacility, ComponentManufacturingFacility,
CapitalComponentManufacturingFacility, ReactionFacility, SellExcessItems, T2T3MaterialType, True, BBList)
Call BatchBlueprint.BuildItem(SetTaxes, BrokerFeeData, SetProductionCosts, IgnoreMinerals, IgnoreT1Item, Nothing)
' 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
' Only add components from the build that are part of the main BP, any additional components will be added below
If BPComponentIDs.Contains(CInt(BI.ItemTypeID)) Then
Call BuiltComponentList.AddBuiltItem(BI)
End If
Next
' Save the raw mats on the bp only
If Not IsNothing(.GetBPRawMaterials.GetMaterialList) Then
Call BPRawMats.InsertMaterialList(.GetBPRawMaterials.GetMaterialList)
End If
' If we build this blueprint, add on the skills required
If BatchBlueprint.ReqBuildSkills.NumSkills <> 0 Then
ReqBuildSkills.InsertSkills(BatchBlueprint.ReqBuildSkills, True)
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
EIV += .GetEstimatedItemValue
' Base Fees for activity
JobFee += .GetJobFee
Select Case BatchBlueprint.GetItemGroupID
Case ReactionGroupID(BatchBlueprint.GetItemGroupID)
ReactionFacilityUsage += .GetReactionFacilityUsage
Case Else
' How much it costs to use each facility to manufacture items
ManufacturingFacilityUsage += .GetManufacturingFacilityUsage
End Select
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)
Dim TempBuiltComponents As BuiltItemList = CType(BuiltComponentList.Clone, BuiltItemList)
' Now build the components as x runs, with 1 bp, that are connected to the main blueprint
For i = 0 To TempBuiltComponents.GetBuiltItemList.Count - 1
Dim TempComponentFacility As IndustryFacility
Dim rsCheck As SQLiteDataReader
Dim SQL As String
Dim CategoryID As String = ""
Dim GroupID As Integer = 0
Dim OneItemMarketPrice As Double = 0
Dim PortionSize As Integer = 1
With TempBuiltComponents.GetBuiltItemList(i)
Application.DoEvents()
SQL = "SELECT ALL_BLUEPRINTS_FACT.ITEM_GROUP_ID, ALL_BLUEPRINTS_FACT.ITEM_CATEGORY_ID, ITEM_PRICES_FACT.PRICE, PORTION_SIZE "
SQL &= "FROM ALL_BLUEPRINTS_FACT, ITEM_PRICES_FACT WHERE ALL_BLUEPRINTS_FACT.ITEM_ID = ITEM_PRICES_FACT.ITEM_ID "
SQL &= "AND ALL_BLUEPRINTS_FACT.ITEM_ID = " & .ItemTypeID
DBCommand = New SQLiteCommand(SQL, EVEDB.DBREf)
rsCheck = DBCommand.ExecuteReader
If rsCheck.Read() Then
GroupID = rsCheck.GetInt32(0)
CategoryID = CStr(rsCheck.GetInt32(1))
OneItemMarketPrice = rsCheck.GetDouble(2)
PortionSize = rsCheck.GetInt32(3)
End If
rsCheck.Close()
' Build the T1 component
If GroupID = ItemIDs.AdvCapitalComponentGroupID Or GroupID = ItemIDs.CapitalComponentGroupID Then
' Use capital component facility
TempComponentFacility = CapitalComponentManufacturingFacility
ElseIf IsT1BaseItemforT2(CInt(CategoryID)) Then
' Want to build this in the manufacturing facility we are using for base T1 items used in T2
TempComponentFacility = MainManufacturingFacility
'ElseIf GroupID = ItemIDs.ReactionBiochemicalsGroupID Or GroupID = ItemIDs.ReactionCompositesGroupID Or GroupID = ItemIDs.ReactionPolymersGroupID Or GroupID = ItemIDs.ReactionsIntermediateGroupID Then
' TempComponentFacility = ReactionFacility
Else ' Components
TempComponentFacility = ComponentManufacturingFacility
End If
' Set the quantity to what was used - save the old required quantity for component list
Dim ComponentQuantity As Long = .ItemQuantity
Dim BuildQuantity As Long = CInt(Math.Ceiling(.UsedQuantity))
ComponentBlueprint = New Blueprint(.BPTypeID, BuildQuantity, .BuildME, .BuildTE, 1,
NumberofProductionLines, BPCharacter, BPUserSettings, BuildBuy, 0,
TempComponentFacility, ComponentManufacturingFacility,
CapitalComponentManufacturingFacility, ReactionFacility, SellExcessItems, T2T3MaterialType, True, BBList)
Call ComponentBlueprint.BuildItem(SetTaxes, BrokerFeeData, SetProductionCosts, IgnoreMinerals, IgnoreT1Item, ExcessMaterials)
'' Update the BuiltComponetList quantity with what the build quantity needs are
'For Each Mat In ComponentBlueprint.UsedExcessMaterials.GetMaterialList
' For Each BC In BuiltComponentList.GetBuiltItemList
' If BC.ItemTypeID = Mat.GetMaterialTypeID Then
' ' Update the built item
' BC.ItemQuantity = BC.ItemQuantity + Mat.GetQuantity
' BC.BPRuns = CLng(Math.Ceiling(BC.ItemQuantity / BC.PortionSize))
' Exit For
' End If
' Next
'Next
Dim ExtraItems As Long
Dim ExtraMaterial As Material = Nothing
' Also, if this built item is more than we need for the main blueprint, add it to excess
If ComponentQuantity < (ComponentBlueprint.PortionSize * ComponentBlueprint.GetUserRuns) Then
ExtraItems = (ComponentBlueprint.PortionSize * ComponentBlueprint.GetUserRuns) - ComponentQuantity
ExtraMaterial = New Material(.ItemTypeID, RemoveItemNameRuns(.ItemName), CategoryID, ExtraItems, .ItemVolume, 0, CStr(.BuildME), CStr(.BuildTE))
Call ExcessMaterials.InsertMaterial(ExtraMaterial)
End If
' Reset the component's material list for shopping list functionality
.BuildMaterials = CType(ComponentBlueprint.RawMaterials, Materials)
' Add any built components to the list as well
For Each BI In ComponentBlueprint.BuiltComponentList.GetBuiltItemList
Call BuiltComponentList.AddBuiltItem(BI)
Next
' Set the variables
.ManufacturingFacility = ComponentBlueprint.MainManufacturingFacility
.IncludeActivityCost = ComponentBlueprint.MainManufacturingFacility.IncludeActivityCost
.IncludeActivityTime = ComponentBlueprint.MainManufacturingFacility.IncludeActivityTime
.IncludeActivityUsage = ComponentBlueprint.MainManufacturingFacility.IncludeActivityUsage
Dim ItemPrice As Double = 0
Dim OwnedBP As Boolean
Call GetMETEforBP(ComponentBlueprint.BlueprintID, ComponentBlueprint.TechLevel, ComponentBlueprint.ItemGroupID, BPUserSettings.DefaultBPME, BPUserSettings.DefaultBPTE, OwnedBP)
' Reset item name
If .ItemName.Contains("(") Then
.ItemName = Trim(.ItemName.Substring(0, InStr(.ItemName, "(") - 1))
End If
' Figure out if we build or buy
Dim BuildFlag As Boolean = GetBuildFlag(ComponentBlueprint, OneItemMarketPrice, BuildQuantity, OwnedBP, SetTaxes, BrokerFeeData)
If (BuildBuy And BuildFlag) Then
' Market cost is greater than build cost, so set the mat cost to the build cost - or just building (not build/buy)
ItemPrice = ComponentBlueprint.GetRawMaterials.GetTotalMaterialsCost / .ItemQuantity
' Adjust the runs of this BP in the name for built bps
.ItemName = UpdateItemNamewithRuns(.ItemName, ComponentBlueprint.GetUserRuns)
Else
' Buying item
ItemPrice = OneItemMarketPrice
BuildFlag = False
End If
' If we build this blueprint, add on the skills required
If ComponentBlueprint.ReqBuildSkills.NumSkills <> 0 Then
ReqBuildComponentSkills.InsertSkills(ComponentBlueprint.ReqBuildSkills, True)
End If
' Add the built material to the component list now - this way we only add one blueprint produced material - use saved component quantity
Dim TempMat As New Material(.ItemTypeID, .ItemName, ComponentBlueprint.GetItemData.GroupName, .ItemQuantity, .ItemVolume, ItemPrice, CStr(.BuildME), CStr(.BuildTE), BuildFlag)
ComponentMaterials.InsertMaterial(TempMat)
' Building, so add the raw materials to the raw mats list
Call RawMaterials.InsertMaterialList(ComponentBlueprint.GetRawMaterials.GetMaterialList)
End With
' Add the production time of this component to the total production time
Call ComponentProductionTimes.Add(ComponentBlueprint.GetProductionTime)
' Get the usage
Select Case GroupID
Case ItemIDs.AdvCapitalComponentGroupID, ItemIDs.CapitalComponentGroupID
CapComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
Case ReactionGroupID(GroupID)
TotalReactionFacilityUsage += ComponentBlueprint.GetReactionFacilityUsage
Case Else
If ReactionBPGroups.Contains(BlueprintGroupID) Then
' Save the manufacturing cost for fuel blocks
ManufacturingFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
Else
ComponentFacilityUsage += ComponentBlueprint.GetManufacturingFacilityUsage
End If
End Select
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 <> "-" And BuildBuy 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 (totaled up in invention function)
BPProductionTime = (BPProductionTime * Batches) + CopyTime + InventionTime
' Set the total production time by adding just the components (invention and copy already included in bp production time
If Not IsNothing(ComponentProductionTimes) Then
TotalProductionTime = BPProductionTime + GetComponentProductionTime(ComponentProductionTimes)
End If
' Finally recalculate our prices
Call SetPriceData(SetTaxes, BrokerFeeData)
End If
Dim ReturnedExcess As New Materials
ReprocessingUsage = 0
' If the BP has a reprocessing facility, see if we want to convert minerals/ice to ore and then run this
If Not IsNothing(ReprocessingFacility) Then
If ReprocessingFacility.ConvertToOre Then
Dim ReplaceMinerals As New ConvertToOre(ReprocessingFacility, UserConversiontoOreSettings)
RawMaterials = ReplaceMinerals.GetOresfromMinerals(RawMaterials, ReturnedExcess, ReprocessingUsage)
' Add the excess minerals to the main excess function
Call ExcessMaterials.InsertMaterialList(ReturnedExcess.GetMaterialList)
' Adjust the price data again to handle the update to excess prices and reprocessing usage
Call SetPriceData(SetTaxes, BrokerFeeData)
End If
End If
End Sub
' Sets the material versions for our blueprint
Private Sub BuildItem(ByVal SetTaxes As Boolean, ByVal BrokerFeeData As BrokerFeeInfo, ByVal SetProductionCosts As Boolean,
ByVal IgnoreMinerals As Boolean, ByVal IgnoreT1Item As Boolean,
Optional ByRef ExcessBuildMaterials As Materials = Nothing)
' Database stuff
Dim SQL As String
Dim SQLAdd 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(BPUserSettings.UseActiveSkillLevels)
' The current material we are working with
Dim CurrentMaterial As Material
Dim CurrentMatQuantity As Long
Dim CurrentMaterialGroupID As Integer
Dim CurrentMaterialCategoryID As Integer
' The quantity that we want to use to build this item (may be different than quantity need if portionsize <> runs)
Dim BuildQuantity As Long = 0
Dim ComponentBPPortionSize As Long = 1
' Temp Materials for passing
Dim TempMaterials As New Materials
Dim TempNumBPs As Integer = 1
Dim SingleRunBuildCost As Double = -1
Dim SavedExcessMaterialList As New Materials
Dim SavedBPExcessMaterialList As New Materials
Dim SavedUpdateBPExcessMaterialList As New Materials
Dim Mat As Material
Dim LookupMaterial As Material
Dim UsedExcessMaterial As Material = Nothing
Dim ExtraItems As Long
Dim SellExcessAmount As Double = 0
Dim AdjCurrentMatQuantity As Long = 0
Dim ExtraMaterial As Material = Nothing
Dim RefUsedMat As Material = Nothing
Dim UsesReactions As Boolean = False
Dim IgnoreBuild As Boolean = False
' Select all materials to buid this BP
SQL = "SELECT ABM.BLUEPRINT_ID, MATERIAL_ID, QUANTITY, MATERIAL, MATERIAL_GROUP_ID, MATERIAL_CATEGORY_ID, "
SQL &= "ACTIVITY, MATERIAL_VOLUME, PRICE, ADJUSTED_PRICE, PORTION_SIZE, groupName "
SQL &= "FROM ALL_BLUEPRINT_MATERIALS_FACT AS ABM, INVENTORY_TYPES, INVENTORY_GROUPS "
SQL &= "LEFT OUTER JOIN ITEM_PRICES_FACT ON ABM.MATERIAL_ID = ITEM_PRICES_FACT.ITEM_ID "
SQL &= "LEFT OUTER JOIN ALL_BLUEPRINTS_FACT ON ALL_BLUEPRINTS_FACT.ITEM_ID = ABM.MATERIAL_ID "
SQL &= "WHERE ABM.BLUEPRINT_ID =" & CStr(BlueprintID) & " And ACTIVITY IN (1,11) "
SQL &= "AND MATERIAL_ID = INVENTORY_TYPES.typeID AND INVENTORY_TYPES.groupID = INVENTORY_GROUPS.groupID"
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
CurrentMaterialGroupID = readerBP.GetInt32(4)
CurrentMaterialCategoryID = readerBP.GetInt32(5)
' Adjust the number of runs I need for the main item based on what I have in the excess mats
Dim TempMat As Material = New Material(ItemID, ItemName, CStr(ItemGroupID), UserRuns * PortionSize, ItemVolume, 0, "", "")
Dim TempRuns As Long = TempMat.GetQuantity
UserRuns = CLng(Math.Ceiling(TempRuns / PortionSize))
If CurrentMaterialCategoryID = 16 Then
' It's a skill, so just add it to the main list of BP skills
ReqBuildSkills.InsertSkill(readerBP.GetInt64(1), readerBP.GetInt32(2), readerBP.GetInt32(2), readerBP.GetInt32(2), 0, False, 0, "", Nothing, True)
ElseIf AddMaterial(CurrentMaterialCategoryID, CurrentMaterialGroupID, IgnoreMinerals, IgnoreT1Item) Then
' Save a copy of the excess materials lists in case we need to replace it if we don't decide to build this component
If Not IsNothing(ExcessBuildMaterials) Then
If ExcessBuildMaterials.GetMaterialList.Count <> 0 Then
SavedExcessMaterialList = CType(ExcessBuildMaterials.Clone, Materials)
End If
End If
If Not IsNothing(BPExcessMaterials) Then
If BPExcessMaterials.GetMaterialList.Count <> 0 Then
SavedBPExcessMaterialList = CType(BPExcessMaterials.Clone, Materials)
End If
End If
' Set the current material - adjust with portion size though if sent
CurrentMaterial = New Material(readerBP.GetInt64(1), readerBP.GetString(3), readerBP.GetString(11), readerBP.GetInt64(2), readerBP.GetDouble(7), If(readerBP.IsDBNull(8), 0, readerBP.GetDouble(8)), "", "")
' Refresh the facility bonuses before we start calculations of ME/TE
Call MainManufacturingFacility.RefreshMMTMCMBonuses(ItemGroupID, ItemCategoryID)
' Save the base costs - before applying ME - if value is null (no price record) then set to 0
EIV += CurrentMaterial.GetQuantity * If(IsDBNull(readerBP.GetValue(9)), 0, readerBP.GetDouble(9))
' 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(MainManufacturingFacility), 2))))
' Update the quantity - just add the negative percent of the ME modifier to 1 and multiply
Call CurrentMaterial.SetQuantity(CurrentMatQuantity)
' Before going any further, see if we have this material in excess materials and if so, adjust the quantity that we will need to build
If IsNothing(ExcessBuildMaterials) Then
AdjCurrentMatQuantity = CurrentMatQuantity
Else
AdjCurrentMatQuantity = GetAdjustedQuantity(ExcessBuildMaterials, CurrentMaterial.GetMaterialTypeID, CurrentMatQuantity, RefUsedMat)
End If
If AdjCurrentMatQuantity = 0 Then
' If original blueprint and the component was already built, need to build it with the original mat quantity
' but Not add any materials to the list after completed so it shows the item needing to be built
If BaseBP Then
' Add to main list
' Set the name of the material to include the build runs if built
If BuildBuy Then
If RefUsedMat.GetBuildItem Then
RefUsedMat.SetName(UpdateItemNamewithRuns(RefUsedMat.GetMaterialName, RefUsedMat.GetQuantity))
' also, since this was already built in a component, we can't charge the cost to the main list
' so it matches up with the build buy costs, reset cost to 0
ComponentMaterials.InsertMaterial(RefUsedMat, 0)
Else
' Buying, so add to raw mat list too