summaryrefslogtreecommitdiff
path: root/DSACore/Auxiliary/WeaponImporter.cs
blob: 3375236234e2b0b52a3b3588d2f3c6dd56a675e6 (plain)
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DSACore.FireBase;
using DSACore.Models.Database.DSA;

namespace DSACore.Auxiliary
{
    public class WeaponImporter
    {
        private readonly List<RangedWeapon> Range = new List<RangedWeapon>();
        private readonly List<MeleeWeapon> Weapons = new List<MeleeWeapon>();

        public async Task DownloadWeapons()
        {
            var client = new HttpClient();


            for (var i = 1; i <= 25; i++)
            {
                var responseString =
                    await client.GetStringAsync("http://diarium.eu/dsa4-forge/ajax/categoryChanged/" + i);

                var talentRegex = new Regex(@"(?<=<option value="")([0-9]*)("">)(.*?)(?=<)");
                //Regex idsRegex = new Regex(@"(?<=<option value=\"")([0-9]*)");


                var talentMatch = talentRegex.Matches(responseString);
                //var idMatch = idsRegex.Matches(responseString);

                var lines = new List<string>();
                var ids = new List<int>();

                foreach (var matchGroup in talentMatch.ToList())
                    if (matchGroup.Success)
                    {
                        lines.Add(matchGroup.Groups[3].Value);
                        ids.Add(int.Parse(matchGroup.Groups[1].Value));
                    }


                for (var j = 0; j < lines.Count; j++)
                {
                    var talent = lines[j];

                    var values = await client.GetStringAsync("http://diarium.eu/dsa4-forge/ajax/calculate/" + i + "/" +
                                                             ids[j] + "/0/0/0/0/0/10/0/0/0");

                    values = Regex.Unescape(values.Replace(@"\t", ""));
                    // ... Use named group in regular expression.
                    var expression =
                        new Regex(
                            @"(((?<=(<td>))|(?<=(<td style=\""padding:2px\"">))).*?(?=<\/td>))|((?<=<span style=\""font-weight:bold;text-decoration:underline;\"">).*?(?=<\/span>))");

                    // ... See if we matched.
                    var matches = expression.Matches(values).Select(x => x.ToString()).ToList();

                    // ... Get group by name.
                    await AddMelee(i, talent, matches);
                    Console.Write(j + ",");
                    //await Task.Delay(TimeSpan.FromSeconds(5));
                }

                Console.WriteLine($"{i}: {ids.Count} => {Weapons.Count}");
                //await Task.Delay(TimeSpan.FromSeconds(5));
            }

            Console.ReadLine();
        }

        private async Task AddMelee(int i, string talent, List<string> matches)
        {
            var name = talent.Replace(' ', '_').Replace(".", "");
            if (!matches[1].Equals(string.Empty))
            {
                var temp = new MeleeWeapon(
                    name,
                    matches[1],
                    int.TryParse(matches[10], out var weight) ? weight : 0,
                    matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(),
                    matches[11])
                {
                    INI = int.TryParse(matches[3], out var ini) ? ini : 0,
                    MW = matches[4],
                    TpKK = matches[2]
                };

                Weapons.Add(temp);
                await Database.AddWeapon(temp);
            }

            /*if (i > 23)
            {
                var range = new RangedWeapon(
                    name,
                    matches[13],
                    int.TryParse(matches[10], out int weight) ? weight : 0,
                    matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(),
                    matches[11])
                {
                    AtMod = int.TryParse(matches[10], out int atMod) ? atMod : 0,
                    KKMod = int.TryParse(matches[11], out int kkMod) ? kkMod : 0,
                    AtReach = matches[3],
                    TpReach = matches[4],
                    LoadTime = int.TryParse(matches[5], out int loadTime) ? loadTime : 0
                };
                Range.Add(range);
                await Database.AddWeapon(range);
                return;
            }*/
            if (i > 18)
            {
                var range = new RangedWeapon(
                    name,
                    matches[13].Replace(' ', '+'),
                    int.TryParse(matches[10], out var weight) ? weight : 0,
                    matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(),
                    matches[11])
                {
                    AtMod = int.TryParse(matches[18], out var atMod) ? atMod : 0,
                    KKMod = int.TryParse(matches[17], out var kkMod) ? kkMod : 0,
                    AtReach = matches[14],
                    TpReach = matches[15],
                    LoadTime = int.TryParse(matches[18], out var loadTime) ? loadTime : 0
                };
                Range.Add(range);
                await Database.AddWeapon(range);
            }
        }

        private async Task AddRanged(int i, string talent, List<string> matches)
        {
            var name = talent.Replace(' ', '_').Replace(".", "");
            if (!matches[1].Equals(string.Empty))
            {
                var temp = new MeleeWeapon(
                    name,
                    matches[1],
                    int.TryParse(matches[10], out var weight) ? weight : 0,
                    matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(),
                    matches[11])
                {
                    INI = int.TryParse(matches[3], out var ini) ? ini : 0,
                    MW = matches[4],
                    TpKK = matches[2]
                };

                Weapons.Add(temp);
                await Database.AddWeapon(temp);
            }

            if (i > 18)
            {
                var range = new RangedWeapon(
                    name,
                    matches[13].Replace(' ', '+'),
                    int.TryParse(matches[10], out var weight) ? weight : 0,
                    matches[0].Split(':', StringSplitOptions.RemoveEmptyEntries).First(),
                    matches[11])
                {
                    AtMod = int.TryParse(matches[18], out var atMod) ? atMod : 0,
                    KKMod = int.TryParse(matches[17], out var kkMod) ? kkMod : 0,
                    AtReach = matches[14],
                    TpReach = matches[15],
                    LoadTime = int.TryParse(matches[18], out var loadTime) ? loadTime : 0
                };
                Range.Add(range);
                await Database.AddWeapon(range);
            }
        }
    }
}