forked from Stridemann/PoeHUD_FullRareSetManager
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFullRareSetManagerCore.cs
1204 lines (940 loc) · 42.6 KB
/
FullRareSetManagerCore.cs
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using ExileCore;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.Elements;
using ExileCore.PoEMemory.Elements.InventoryElements;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Enums;
using ExileCore.Shared.Nodes;
using FullRareSetManager.SetParts;
using FullRareSetManager.Utilities;
using ImGuiNET;
using SharpDX;
namespace FullRareSetManager
{
public class FullRareSetManagerCore : BaseSettingsPlugin<FullRareSetManagerSettings>
{
private const int INPUT_DELAY = 15;
private bool _bDropAllItems;
private Inventory _currentOpenedStashTab;
private string _currentOpenedStashTabName;
private CurrentSetInfo _currentSetData;
private string _drawInfoString = "";
private DropAllToInventory _inventDrop;
private BaseSetPart[] _itemSetTypes;
private StashData _sData;
public ItemDisplayData[] DisplayData;
public FRSetManagerPublishInformation FrSetManagerPublishInformation;
private bool _allowScanTabs = true;
private Stopwatch _fixStopwatch = new Stopwatch();
public override void ReceiveEvent(string eventId, object args)
{
if (!Settings.Enable.Value) return;
if (eventId == "stashie_start_drop_items")
{
_fixStopwatch.Restart();
_allowScanTabs = false;
}
else if (eventId == "stashie_stop_drop_items")
{
_allowScanTabs = true;
}
else if (eventId == "stashie_finish_drop_items_to_stash_tab")
{
_fixStopwatch.Restart();
UpdateStashes();
UpdatePlayerInventory();
UpdateItemsSetsInfo();
}
}
public override bool Initialise()
{
Input.RegisterKey(Settings.DropToInventoryKey.Value);
_sData = StashData.Load(this);
if (_sData == null)
{
LogMessage(
"RareSetManager: Can't load cached items from file StashData.json. Creating new config. Open stash tabs for updating info. Tell to developer if this happen often enough.",
10);
_sData = new StashData();
}
_inventDrop = new DropAllToInventory(this);
DisplayData = new ItemDisplayData[8];
for (var i = 0; i <= 7; i++)
{
DisplayData[i] = new ItemDisplayData();
}
UpdateItemsSetsInfo();
Settings.WeaponTypePriority.SetListValues(new List<string> {"Two handed", "One handed"});
Settings.CalcByFreeSpace.OnValueChanged += delegate { UpdateItemsSetsInfo(); };
FrSetManagerPublishInformation = new FRSetManagerPublishInformation();
//WorldItemsController.OnEntityAdded += args => EntityAdded(args.Entity);
//WorldItemsController.OnEntityRemoved += args => EntityRemoved(args.Entity);
//WorldItemsController.OnItemPicked += WorldItemsControllerOnOnItemPicked;
return true;
}
public override void EntityAdded(Entity entity)
{
if (!Settings.EnableBorders.Value)
return;
if (entity.Type != EntityType.WorldItem)
return;
if (!Settings.Enable || GameController.Area.CurrentArea.IsTown ||
_currentAlerts.ContainsKey(entity))
return;
var item = entity.GetComponent<WorldItem>().ItemEntity;
var visitResult = ProcessItem(item);
if (visitResult == null)
return;
if (Settings.IgnoreOneHanded && visitResult.ItemType == StashItemType.OneHanded)
visitResult = null;
if (visitResult == null)
return;
var index = (int) visitResult.ItemType;
if (index > 7)
index = 0;
var displData = DisplayData[index];
_currentAlerts.Add(entity, displData);
}
public override void EntityRemoved(Entity entity)
{
if (!Settings.EnableBorders.Value)
return;
if (entity.Type != EntityType.WorldItem)
return;
if (Vector2.Distance(entity.GridPos, GameController.Player.GridPos) < 10)
{
//item picked by player?
var wi = entity.GetComponent<WorldItem>();
var filteredItemResult = ProcessItem(wi.ItemEntity);
if (filteredItemResult == null)
return;
filteredItemResult.BInPlayerInventory = true;
_sData.PlayerInventory.StashTabItems.Add(filteredItemResult);
UpdateItemsSetsInfo();
}
_currentAlerts.Remove(entity);
_currentLabels.Remove(entity.Address);
}
public override void AreaChange(AreaInstance area)
{
_currentLabels.Clear();
_currentAlerts.Clear();
}
public class ClassForPickit
{
public ItemDisplayData[] dataArray { get; set; }
public int MaxItemSet { get; set; }
}
public class FRSetManagerPublishInformation
{
public int GatheredWeapons { get; set; } = 0;
public int GatheredHelmets { get; set; } = 0;
public int GatheredBodyArmors { get; set; } = 0;
public int GatheredGloves { get; set; } = 0;
public int GatheredBoots { get; set; } = 0;
public int GatheredBelts { get; set; } = 0;
public int GatheredAmulets { get; set; } = 0;
public int GatheredRings { get; set; } = 0;
public int WantedSets { get; set; } = 0;
}
public override void Render()
{
if (!GameController.Game.IngameState.InGame) return;
FrSetManagerPublishInformation.WantedSets = Settings.MaxSets.Value;
var rareSetData = _itemSetTypes;
for (int i = 0; i < rareSetData.Length; i++)
{
BaseSetPart itemDisplayData = rareSetData[i];
switch (itemDisplayData.PartName)
{
case "Weapons":
FrSetManagerPublishInformation.GatheredWeapons = itemDisplayData.TotalSetsCount();
break;
case "Helmets":
FrSetManagerPublishInformation.GatheredHelmets = itemDisplayData.TotalSetsCount();
break;
case "Body Armors":
FrSetManagerPublishInformation.GatheredBodyArmors = itemDisplayData.TotalSetsCount();
break;
case "Gloves":
FrSetManagerPublishInformation.GatheredGloves = itemDisplayData.TotalSetsCount();
break;
case "Boots":
FrSetManagerPublishInformation.GatheredBoots = itemDisplayData.TotalSetsCount();
break;
case "Belts":
FrSetManagerPublishInformation.GatheredBelts = itemDisplayData.TotalSetsCount();
break;
case "Amulets":
FrSetManagerPublishInformation.GatheredAmulets = itemDisplayData.TotalSetsCount();
break;
case "Rings":
FrSetManagerPublishInformation.GatheredRings = itemDisplayData.TotalSetsCount();
break;
}
}
PublishEvent("frsm_display_data", FrSetManagerPublishInformation);
if (!_allowScanTabs)
{
if (_fixStopwatch.ElapsedMilliseconds > 3000)
_allowScanTabs = true;//fix for stashie doesn't send the finish drop items event
return;
}
var needUpdate = UpdatePlayerInventory();
var IngameState = GameController.Game.IngameState;
var stashIsVisible = IngameState.IngameUi.StashElement.IsVisible;
if (stashIsVisible)
needUpdate = UpdateStashes() || needUpdate;
if (needUpdate)
{
//Thread.Sleep(100);//Wait until item be placed to player invent. There should be some delay
UpdateItemsSetsInfo();
}
if (_bDropAllItems)
{
_bDropAllItems = false;
try
{
DropAllItems();
}
catch
{
LogError("There was an error while moving items.", 5);
}
finally
{
UpdatePlayerInventory();
UpdateItemsSetsInfo();
}
}
if (!_bDropAllItems)
DrawSetsInfo();
RenderLabels();
if (Settings.DropToInventoryKey.PressedOnce())
{
if (stashIsVisible && IngameState.IngameUi.InventoryPanel.IsVisible)
{
if (_currentSetData.BSetIsReady)
_bDropAllItems = true;
}
SellSetToVendor();
}
}
public void SellSetToVendor(int callCount = 1)
{
try
{
// Sell to vendor.
var gameWindow = GameController.Window.GetWindowRectangle().TopLeft;
var latency = (int) GameController.Game.IngameState.ServerData.Latency;
var npcTradingWindow = GameController.Game.IngameState.IngameUi.SellWindow;
if (!npcTradingWindow.IsVisible)
{
// The vendor sell window is not open, but is in memory (it would've went straigth to catch if that wasn't the case).
LogMessage("Error: npcTradingWindow is not visible (opened)!", 5);
}
var playerOfferItems = npcTradingWindow.YourOffer;
const int setItemsCount = 9;
const int uiButtonsCount = 2;
LogMessage($"Player has put in {playerOfferItems.ChildCount - uiButtonsCount} in the trading window.", 3);
if (playerOfferItems.ChildCount < setItemsCount + uiButtonsCount)
{
for (var i = 0; i < 8; i++)
{
var itemType = _itemSetTypes[i];
var items = itemType.GetPreparedItems();
if (items.Any(item => !item.BInPlayerInventory))
continue;
Keyboard.KeyDown(Keys.LControlKey);
foreach (var item in items)
{
var foundItem =
GameController.Game.IngameState.IngameUi.InventoryPanel[InventoryIndex.PlayerInventory]
.VisibleInventoryItems.FirstOrDefault(x => x.InventPosX == item.InventPosX && x.InventPosY == item.InventPosY);
if (foundItem == null)
{
LogError("FoundItem was null.", 3);
return;
}
Thread.Sleep(INPUT_DELAY);
Mouse.SetCursorPosAndLeftClick(foundItem.GetClientRect().Center + gameWindow,
Settings.ExtraDelay);
Thread.Sleep(latency + Settings.ExtraDelay);
}
}
Keyboard.KeyUp(Keys.LControlKey);
}
Thread.Sleep(INPUT_DELAY + Settings.ExtraDelay.Value);
var npcOfferItems = npcTradingWindow.OtherOffer;
foreach (var element in npcOfferItems.Children)
{
var item = element.AsObject<NormalInventoryItem>().Item;
if (string.IsNullOrEmpty(item.Metadata))
continue;
var itemName = GameController.Files.BaseItemTypes.Translate(item.Metadata).BaseName;
if (itemName == "Chaos Orb" || itemName == "Regal Orb") continue;
LogMessage($"Npc offered '{itemName}'", 3);
if (callCount >= 5) return;
var delay = INPUT_DELAY + Settings.ExtraDelay.Value;
LogMessage($"Trying to sell set again in {delay} ms.", 3);
Thread.Sleep(delay);
//SellSetToVendor(callCount++);
return;
}
Thread.Sleep(latency + Settings.ExtraDelay);
var acceptButton = npcTradingWindow.AcceptButton;
Settings.SetsAmountStatistics++;
Settings.SetsAmountStatisticsText = $"Total sets sold to vendor: {Settings.SetsAmountStatistics}";
if (Settings.AutoSell.Value)
{
Mouse.SetCursorPosAndLeftClick(acceptButton.GetClientRect().Center + gameWindow,
Settings.ExtraDelay.Value);
}
else
Mouse.SetCursorPos(acceptButton.GetClientRect().Center + gameWindow);
}
catch
{
LogMessage("We hit catch!", 3);
Keyboard.KeyUp(Keys.LControlKey);
Thread.Sleep(INPUT_DELAY);
// We are not talking to a vendor.
}
}
public void DropAllItems()
{
var stashPanel = GameController.IngameState.IngameUi.StashElement;
var stashNames = stashPanel.AllStashNames;
var gameWindowPos = GameController.Window.GetWindowRectangle();
var latency = (int) GameController.Game.IngameState.ServerData.Latency + Settings.ExtraDelay;
var cursorPosPreMoving = Mouse.GetCursorPosition();
// Iterrate through all the different item types.
for (var i = 0; i < 8; i++) //Check that we have enough items for any set
{
var part = _itemSetTypes[i];
var items = part.GetPreparedItems();
Keyboard.KeyDown(Keys.LControlKey);
Thread.Sleep(INPUT_DELAY);
try
{
foreach (var curPreparedItem in items)
{
// If items is already in our inventory, move on.
if (curPreparedItem.BInPlayerInventory)
continue;
// Get the index of the item we want to move from stash to inventory.
var invIndex = stashNames.IndexOf(curPreparedItem.StashName);
// Switch to the tab we want to go to.
if (!_inventDrop.SwitchToTab(invIndex, Settings))
{
//throw new Exception("Can't switch to tab");
Keyboard.KeyUp(Keys.LControlKey);
return;
}
Thread.Sleep(latency + Settings.ExtraDelay);
// Get the current visible stash tab.
_currentOpenedStashTab = stashPanel.VisibleStash;
var item = curPreparedItem;
var foundItem =
_currentOpenedStashTab.VisibleInventoryItems.FirstOrDefault(
x => x.InventPosX == item.InventPosX && x.InventPosY == item.InventPosY);
var curItemsCount = _currentOpenedStashTab.VisibleInventoryItems.Count;
if (foundItem != null)
{
// If we found the item.
Mouse.SetCursorPosAndLeftClick(foundItem.GetClientRect().Center + gameWindowPos.TopLeft,
Settings.ExtraDelay);
item.BInPlayerInventory = true;
Thread.Sleep(latency + 100 + Settings.ExtraDelay);
if (_currentOpenedStashTab.VisibleInventoryItems.Count == curItemsCount)
{
//LogError("Item was not dropped?? : " + curPreparedItem.ItemName + ", checking again...", 10);
Thread.Sleep(200);
if (_currentOpenedStashTab.VisibleInventoryItems.Count == curItemsCount)
{
LogError("Item was not dropped after additional delay: " + curPreparedItem.ItemName,
5);
}
}
}
else
{
LogError("We couldn't find the item we where looking for.\n" +
$"ItemName: {item.ItemName}.\n" +
$"Inventory Position: ({item.InventPosX},{item.InventPosY})", 5);
}
//Thread.Sleep(200);
if (!UpdateStashes())
LogError("There was item drop but it don't want to update stash!", 10);
}
}
catch (Exception ex)
{
LogError("Error move items: " + ex.Message, 4);
}
Keyboard.KeyUp(Keys.LControlKey);
//part.RemovePreparedItems();
}
UpdatePlayerInventory();
UpdateItemsSetsInfo();
Mouse.SetCursorPos(cursorPosPreMoving);
}
private void DrawSetsInfo()
{
var stash = GameController.IngameState.IngameUi.StashElement;
var leftPanelOpened = stash.IsVisible;
if (leftPanelOpened)
{
if (_currentSetData.BSetIsReady && _currentOpenedStashTab != null)
{
var visibleInventoryItems = _currentOpenedStashTab.VisibleInventoryItems;
if (visibleInventoryItems != null)
{
var stashTabRect = _currentOpenedStashTab.InventoryUIElement.GetClientRect();
var setItemsListRect = new RectangleF(stashTabRect.Right, stashTabRect.Bottom, 270, 240);
Graphics.DrawBox(setItemsListRect, new Color(0, 0, 0, 200));
Graphics.DrawFrame(setItemsListRect, Color.White, 2);
var drawPosX = setItemsListRect.X + 10;
var drawPosY = setItemsListRect.Y + 10;
Graphics.DrawText("Current " + (_currentSetData.SetType == 1 ? "Chaos" : "Regal") + " set:", new Vector2(drawPosX, drawPosY),
Color.White, 15);
drawPosY += 25;
for (var i = 0; i < 8; i++)
{
var part = _itemSetTypes[i];
var items = part.GetPreparedItems();
foreach (var curPreparedItem in items)
{
var inInventory = _sData.PlayerInventory.StashTabItems.Contains(curPreparedItem);
var curStashOpened = curPreparedItem.StashName == _currentOpenedStashTabName;
var color = Color.Gray;
if (inInventory)
color = Color.Green;
else if (curStashOpened)
color = Color.Yellow;
if (!inInventory && curStashOpened)
{
var item = curPreparedItem;
var foundItem =
visibleInventoryItems.FirstOrDefault(x => x.InventPosX == item.InventPosX && x.InventPosY == item.InventPosY);
if (foundItem != null)
Graphics.DrawFrame(foundItem.GetClientRect(), Color.Yellow, 2);
}
Graphics.DrawText(
curPreparedItem.StashName + " (" + curPreparedItem.ItemName + ") " +
(curPreparedItem.LowLvl ? "L" : "H"), new Vector2(drawPosX, drawPosY), color, 15);
drawPosY += 20;
}
}
}
}
}
if (Settings.ShowOnlyWithInventory)
{
if (!GameController.Game.IngameState.IngameUi.InventoryPanel.IsVisible)
return;
}
if (Settings.HideWhenLeftPanelOpened)
{
if (leftPanelOpened)
return;
}
var posX = Settings.PositionX.Value;
var posY = Settings.PositionY.Value;
var rect = new RectangleF(posX, posY, 230, 200);
Graphics.DrawBox(rect, new Color(0, 0, 0, 200));
Graphics.DrawFrame(rect, Color.White, 2);
posX += 10;
posY += 10;
Graphics.DrawText(_drawInfoString, new Vector2(posX, posY), Color.White, 15);
}
private void UpdateItemsSetsInfo()
{
_currentSetData = new CurrentSetInfo();
_itemSetTypes = new BaseSetPart[8];
_itemSetTypes[0] = new WeaponItemsSetPart("Weapons") {ItemCellsSize = 8};
_itemSetTypes[1] = new SingleItemSetPart("Helmets") {ItemCellsSize = 4};
_itemSetTypes[2] = new SingleItemSetPart("Body Armors") {ItemCellsSize = 6};
_itemSetTypes[3] = new SingleItemSetPart("Gloves") {ItemCellsSize = 4};
_itemSetTypes[4] = new SingleItemSetPart("Boots") {ItemCellsSize = 4};
_itemSetTypes[5] = new SingleItemSetPart("Belts") {ItemCellsSize = 2};
_itemSetTypes[6] = new SingleItemSetPart("Amulets") {ItemCellsSize = 1};
_itemSetTypes[7] = new RingItemsSetPart("Rings") {ItemCellsSize = 1};
for (var i = 0; i <= 7; i++)
{
DisplayData[i].BaseData = _itemSetTypes[i];
}
foreach (var item in _sData.PlayerInventory.StashTabItems)
{
var index = (int) item.ItemType;
if (index > 7)
index = 0; // Switch One/TwoHanded to 0(weapon)
var setPart = _itemSetTypes[index];
item.BInPlayerInventory = true;
setPart.AddItem(item);
}
const int StashCellsCount = 12 * 12;
foreach (var stash in _sData.StashTabs)
{
var stashTabItems = stash.Value.StashTabItems;
foreach (var item in stashTabItems)
{
var index = (int) item.ItemType;
if (index > 7)
index = 0; // Switch One/TwoHanded to 0(weapon)
var setPart = _itemSetTypes[index];
item.BInPlayerInventory = false;
setPart.AddItem(item);
setPart.StashTabItemsCount = stashTabItems.Count;
}
}
//Calculate sets:
_drawInfoString = "";
var chaosSetMaxCount = 0;
var regalSetMaxCount = int.MaxValue;
var minItemsCount = int.MaxValue;
var maxItemsCount = 0;
for (var i = 0; i <= 7; i++) //Check that we have enough items for any set
{
var setPart = _itemSetTypes[i];
var low = setPart.LowSetsCount();
var high = setPart.HighSetsCount();
var total = setPart.TotalSetsCount();
if (minItemsCount > total)
minItemsCount = total;
if (maxItemsCount < total)
maxItemsCount = total;
if (regalSetMaxCount > high)
regalSetMaxCount = high;
chaosSetMaxCount += low;
_drawInfoString += setPart.GetInfoString() + "\r\n";
var drawInfo = DisplayData[i];
drawInfo.TotalCount = total;
drawInfo.TotalLowCount = low;
drawInfo.TotalHighCount = high;
if (Settings.CalcByFreeSpace.Value)
{
var totalPossibleStashItemsCount = StashCellsCount / setPart.ItemCellsSize;
drawInfo.FreeSpaceCount = totalPossibleStashItemsCount -
(setPart.StashTabItemsCount + setPart.PlayerInventItemsCount());
if (drawInfo.FreeSpaceCount < 0)
drawInfo.FreeSpaceCount = 0;
drawInfo.PriorityPercent = (float) drawInfo.FreeSpaceCount / totalPossibleStashItemsCount;
if (drawInfo.PriorityPercent > 1)
drawInfo.PriorityPercent = 1;
drawInfo.PriorityPercent = 1 - drawInfo.PriorityPercent;
}
}
if (!Settings.CalcByFreeSpace.Value)
{
var maxSets = maxItemsCount;
if (Settings.MaxSets.Value > 0)
maxSets = Settings.MaxSets.Value;
for (var i = 0; i <= 7; i++)
{
var drawInfo = DisplayData[i];
if (drawInfo.TotalCount == 0)
drawInfo.PriorityPercent = 0;
else
{
drawInfo.PriorityPercent = (float) drawInfo.TotalCount / maxSets;
if (drawInfo.PriorityPercent > 1)
drawInfo.PriorityPercent = 1;
}
}
}
_drawInfoString += "\r\n";
var chaosSets = Math.Min(minItemsCount, chaosSetMaxCount);
_drawInfoString += "Chaos sets ready: " + chaosSets;
if (Settings.ShowRegalSets.Value)
{
_drawInfoString += "\r\n";
_drawInfoString += "Regal sets ready: " + regalSetMaxCount;
}
if (chaosSets <= 0 && regalSetMaxCount <= 0)
return;
{
var maxAvailableReplaceCount = 0;
var replaceIndex = -1;
var isLowSet = false;
for (var i = 0; i < 8; i++) //Check that we have enough items for any set
{
var part = _itemSetTypes[i];
var prepareResult = part.PrepareItemForSet(Settings);
isLowSet = isLowSet || prepareResult.LowSet;
if (maxAvailableReplaceCount >= prepareResult.AllowedReplacesCount || prepareResult.BInPlayerInvent)
continue;
maxAvailableReplaceCount = prepareResult.AllowedReplacesCount;
replaceIndex = i;
}
if (!isLowSet)
{
if (Settings.ShowRegalSets)
{
_currentSetData.BSetIsReady = true;
_currentSetData.SetType = 2;
return;
}
if (maxAvailableReplaceCount == 0)
{
//LogMessage("You want to make a regal set anyway? Ok.", 2);
_currentSetData.BSetIsReady = true;
_currentSetData.SetType = 2;
return;
}
if (replaceIndex != -1)
{
_itemSetTypes[replaceIndex].DoLowItemReplace();
_currentSetData.SetType = 1;
_currentSetData.BSetIsReady = true;
}
else
{
_currentSetData.BSetIsReady = true;
_currentSetData.SetType = 1;
}
}
else
{
_currentSetData.BSetIsReady = true;
_currentSetData.SetType = 1;
}
}
}
public bool UpdateStashes()
{
var stashPanel = GameController.IngameState.IngameUi.StashElement;
if (stashPanel == null)
{
LogMessage("ServerData.StashPanel is null", 3);
return false;
}
var needUpdateAllInfo = false;
_currentOpenedStashTabName = "";
_currentOpenedStashTab = stashPanel.VisibleStash;
if (_currentOpenedStashTab == null)
return false;
for (var i = 0; i < stashPanel.TotalStashes; i++)
{
var stashName = stashPanel.GetStashName(i);
if (Settings.OnlyAllowedStashTabs.Value)
{
if (!Settings.AllowedStashTabs.Contains(i))
continue;
}
var stash = stashPanel.GetStashInventoryByIndex(i);
var visibleInventoryItems = stash?.VisibleInventoryItems;
if (visibleInventoryItems == null)
continue;
if (_currentOpenedStashTab.Address == stash.Address)
_currentOpenedStashTabName = stashName;
var add = false;
if (!_sData.StashTabs.TryGetValue(stashName, out var curStashData))
{
curStashData = new StashTabData();
add = true;
}
var items = new List<StashItem>();
needUpdateAllInfo = true;
foreach (var invItem in visibleInventoryItems)
{
var item = invItem.Item;
var newStashItem = ProcessItem(item);
if (newStashItem == null)
{
if (Settings.ShowRedRectangleAroundIgnoredItems)
Graphics.DrawFrame(invItem.GetClientRect(), Color.Red, 2);
continue;
}
newStashItem.StashName = stashName;
newStashItem.InventPosX = invItem.InventPosX;
newStashItem.InventPosY = invItem.InventPosY;
newStashItem.BInPlayerInventory = false;
items.Add(newStashItem);
}
if (_currentOpenedStashTab.Address == stash.Address)//in case tab was closed before we finish update
{
curStashData.StashTabItems = items;
curStashData.ItemsCount = (int) stash.ItemCount;
}
if (add && curStashData.ItemsCount > 0)
_sData.StashTabs.Add(stashName, curStashData);
}
if (!needUpdateAllInfo)
return false;
return true;
}
private bool UpdatePlayerInventory()
{
// if (!GameController.Game.IngameState.IngameUi.InventoryPanel.IsVisible)
// return false;
var inventory = GameController.Game.IngameState.ServerData.PlayerInventories[0].Inventory;
if (_sData?.PlayerInventory == null)
return true;
_sData.PlayerInventory = new StashTabData();
var invItems = inventory;
if (invItems == null) return true;
foreach (var invItem in invItems.InventorySlotItems)
{
var item = invItem;
var newAddedItem = ProcessItem(item.Item);
if (newAddedItem == null) continue;
newAddedItem.InventPosX = (int)invItem.InventoryPosition.X;
newAddedItem.InventPosY = (int)invItem.InventoryPosition.Y;
newAddedItem.BInPlayerInventory = true;
_sData.PlayerInventory.StashTabItems.Add(newAddedItem);
}
_sData.PlayerInventory.ItemsCount = (int) inventory.TotalItemsCounts;
return true;
}
private StashItem ProcessItem(Entity item)
{
try
{
if (item == null) return null;
var mods = item?.GetComponent<Mods>();
if (mods?.ItemRarity != ItemRarity.Rare)
return null;
var bIdentified = mods.Identified;
if (bIdentified && !Settings.AllowIdentified)
return null;
if (mods.ItemLevel < 60)
return null;
var newItem = new StashItem
{
BIdentified = bIdentified,
LowLvl = mods.ItemLevel < 75
};
if (string.IsNullOrEmpty(item.Metadata))
{
LogError("Item metadata is empty. Can be fixed by restarting the game", 10);
return null;
}
if (Settings.IgnoreElderShaper.Value)
{
var baseComp = item.GetComponent<Base>();
if (baseComp.isElder || baseComp.isShaper)
return null;
}
var bit = GameController.Files.BaseItemTypes.Translate(item.Metadata);
if (bit == null)
return null;
newItem.ItemClass = bit.ClassName;
newItem.ItemName = bit.BaseName;
newItem.ItemType = GetStashItemTypeByClassName(newItem.ItemClass);
if (newItem.ItemType != StashItemType.Undefined)
return newItem;
}
catch (Exception e)
{
LogError($"Error in \"ProcessItem\": {e}", 10);
return null;
}
return null;
}
private StashItemType GetStashItemTypeByClassName(string className)
{
if (className.StartsWith("Two Hand"))
return StashItemType.TwoHanded;
if (className.StartsWith("One Hand") || className.StartsWith("Thrusting One Hand"))
return StashItemType.OneHanded;
switch (className)
{
case "Bow": return StashItemType.TwoHanded;
case "Staff": return StashItemType.TwoHanded;
case "Sceptre": return StashItemType.OneHanded;
case "Wand": return StashItemType.OneHanded;
case "Dagger": return StashItemType.OneHanded;
case "Claw": return StashItemType.OneHanded;
case "Shield": return StashItemType.OneHanded;
case "Rune Dagger": return StashItemType.OneHanded;
case "Warstaff": return StashItemType.TwoHanded;
case "Ring": return StashItemType.Ring;
case "Amulet": return StashItemType.Amulet;
case "Belt": return StashItemType.Belt;
case "Helmet": return StashItemType.Helmet;
case "Body Armour": return StashItemType.Body;
case "Boots": return StashItemType.Boots;
case "Gloves": return StashItemType.Gloves;
default:
return StashItemType.Undefined;
}
}
public override void DrawSettings()
{
base.DrawSettings();
var stashPanel = GameController.Game.IngameState.IngameUi.StashElement;
var realNames = stashPanel.AllStashNames;
var uniqId = 0;
if (ImGui.Button($"Add##{uniqId++}"))
{
Settings.AllowedStashTabs.Add(-1);
}
for (var i = 0; i < Settings.AllowedStashTabs.Count; i++)
{
var value = Settings.AllowedStashTabs[i];
if (ImGui.Combo(value < realNames.Count && value >= 0 ? realNames[value] : "??", ref value, realNames.ToArray(), realNames.Count))
{
Settings.AllowedStashTabs[i] = value;
}
ImGui.SameLine();