forked from IlliumIv/Stashie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRefill.cs
148 lines (116 loc) · 4.94 KB
/
Refill.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
using System;
using System.Collections.Generic;
using System.IO;
using ExileCore;
using ExileCore.Shared.Nodes;
using SharpDX;
namespace Stashie
{
public class RefillParser
{
private const string REFILL_CONFIG = "RefillCurrency.txt";
private const string SYMBOL_NAMEDIVIDER = ":";
private const char SYMBOL_PARAMETERSDIVIDER = ',';
private const string SYMBOL_IGNORE = "#";
private const string SYMBOL_IGNORE2 = "//";
public static List<RefillProcessor> Parse(string pluginDir)
{
var refills = new List<RefillProcessor>();
var refillConfigPath = Path.Combine(pluginDir, REFILL_CONFIG);
if (!File.Exists(refillConfigPath)) return refills;
var configLines = File.ReadAllLines(refillConfigPath);
for (var i = 0; i < configLines.Length; i++)
{
var configLine = configLines[i];
configLine = configLine.Replace("\t", "");
if (configLine.Replace(" ", "").Length == 0) continue;
if (configLine.StartsWith(SYMBOL_IGNORE) || configLine.StartsWith(SYMBOL_IGNORE2)) continue;
var newRefill = new RefillProcessor();
var nameIndex = configLine.IndexOf(SYMBOL_NAMEDIVIDER, StringComparison.Ordinal);
if (nameIndex == -1)
{
DebugWindow.LogMsg($"Refill parser: Can't find refill name in line: {configLine}. Name should have \":\" divider.", 10);
continue;
}
newRefill.MenuName = configLine.Substring(0, nameIndex);
TrimName(ref newRefill.MenuName);
configLine = configLine.Substring(nameIndex + SYMBOL_NAMEDIVIDER.Length);
var configLineParams = configLine.Split(SYMBOL_PARAMETERSDIVIDER);
if (configLineParams.Length != 4)
{
DebugWindow.LogMsg(
$"Refill parser: Config line should have 4 parameters (ClassName,StackSize,InventoryX,InventoryY): {configLine}, Ignoring refill..",
10);
continue;
}
newRefill.CurrencyClass = configLineParams[0];
TrimName(ref newRefill.CurrencyClass);
if (!int.TryParse(configLineParams[1], out newRefill.StackSize))
{
DebugWindow.LogMsg(
$"Refill parser: Can't parse StackSize from 2nd parameter in line: {configLine} (line num: {i + 1}), Ignoring refill..",
10);
continue;
}
if (!int.TryParse(configLineParams[2], out newRefill.InventPos.X))
{
DebugWindow.LogMsg(
$"Refill parser: Can't parse InventoryX from 3rd parameter in line: {configLine} (line num: {i + 1}), Ignoring refill..",
10);
continue;
}
if (newRefill.InventPos.X < 1 || newRefill.InventPos.X > 12)
{
DebugWindow.LogMsg(
$"Refill parser: InventoryX should be in range 1-12, current value: {newRefill.InventPos.X} (line num: {i + 1}), Ignoring refill..",
10);
continue;
}
if (!int.TryParse(configLineParams[3], out newRefill.InventPos.Y))
{
DebugWindow.LogMsg(
$"Refill parser: Can't parse InventoryY from 4th parameter in line: {configLine} (line num: {i + 1}), Ignoring refill..",
10);
continue;
}
if (newRefill.InventPos.Y < 1 || newRefill.InventPos.Y > 5)
{
DebugWindow.LogMsg(
$"Refill parser: InventPosY should be in range 1-5, current value: {newRefill.InventPos.Y} (line num: {i + 1}), Ignoring refill..",
10);
continue;
}
// Convert to zero based index.
newRefill.InventPos.X--;
newRefill.InventPos.Y--;
refills.Add(newRefill);
}
return refills;
}
private static void TrimName(ref string name)
{
name = name.TrimEnd(' ');
name = name.TrimStart(' ');
}
}
public class RefillProcessor
{
public RangeNode<int> AmountOption { get; set; }
public Vector2 ClickPos;
public string CurrencyClass;
public Point InventPos;
public string MenuName;
//Temp values:
public int OwnedCount;
public int StackSize;
public void Clear()
{
OwnedCount = 0;
}
}
public class RefillSettings
{
public int Amount;
public string RefillName;
}
}