forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharTemplateTable.cs
More file actions
102 lines (82 loc) · 3.21 KB
/
Copy pathCharTemplateTable.cs
File metadata and controls
102 lines (82 loc) · 3.21 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using L2dotNET.DataContracts.Shared.Enums;
using L2dotNET.Enums;
using L2dotNET.Templates;
using NLog;
namespace L2dotNET.Tables
{
public static class CharTemplateTable
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private static Dictionary<int, PcTemplate> _templates;
public static void Initialize()
{
_templates = new Dictionary<int, PcTemplate>();
XmlDocument doc = new XmlDocument();
string[] xmlFilesArray = Directory.GetFiles(@"data\xml\classes\");
foreach (string i in xmlFilesArray)
{
doc.Load(i);
XmlNodeList nodes = doc.DocumentElement?.SelectNodes("/list/class");
if (nodes == null)
{
continue;
}
foreach (XmlNode node in nodes)
{
XmlElement ownerElement = node.Attributes?[0].OwnerElement;
if (ownerElement == null || node.Attributes == null || ownerElement.Name != "class")
{
continue;
}
XmlNamedNodeMap attrs = node.Attributes;
ClassId classId = ClassId.Values.FirstOrDefault(x => (int)x.Id == Convert.ToInt32(attrs.Item(0).Value));
StatsSet set = new StatsSet();
for (XmlNode cd = node.FirstChild; cd?.NextSibling != null; cd = cd.NextSibling)
{
if (cd.NextSibling.Name == "set")
{
attrs = cd.NextSibling.Attributes;
if (attrs == null)
{
continue;
}
string name = attrs.GetNamedItem("name").Value;
string value = attrs.GetNamedItem("val").Value;
set.Set(name, value);
}
else if (cd.NextSibling.Name == "items")
{
attrs = cd.NextSibling.Attributes;
if (attrs == null)
{
continue;
}
string value = attrs.GetNamedItem("val").Value;
set.Set("items", value);
}
}
PcTemplate pcTempl = new PcTemplate(classId, set);
_templates.Add((int)pcTempl.ClassId.Id, pcTempl);
}
}
Log.Info($"Loaded {_templates.Count} character templates.");
}
public static PcTemplate GetTemplate(ClassIds classId)
{
return _templates[(int)classId];
}
public static PcTemplate GetTemplate(int classId)
{
return _templates[classId];
}
public static List<PcTemplate> GetTemplates()
{
return _templates.Values.ToList();
}
}
}