forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemHandler.cs
More file actions
125 lines (99 loc) · 3.78 KB
/
Copy pathItemHandler.cs
File metadata and controls
125 lines (99 loc) · 3.78 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using L2dotNET.Models.Items.Effects;
using NLog;
namespace L2dotNET.Models.Items
{
public class ItemHandler
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private static short _effects;
public static Dictionary<int, ItemEffect> Items { get; private set; }
public static void Initialize()
{
Items = new Dictionary<int, ItemEffect>();
Register(new EnchantScrolls());
Register(new Calculator());
LoadXml();
Log.Info($"Loaded {_effects} effects with {Items.Count} items.");
}
public static bool Process(L2Character character, L2Item item)
{
if (!Items.ContainsKey(item.Template.ItemId))
{
return false;
}
Items[item.Template.ItemId].Use(character, item);
return true;
}
private static void Register(ItemEffect effect)
{
foreach (int id in effect.Ids)
Items.Add(id, effect);
_effects++;
}
public static void LoadXml()
{
XElement xml = XElement.Parse(File.ReadAllText(@"scripts\itemhandler.xml"));
XElement ex = xml.Element("list");
if (ex == null)
{
return;
}
foreach (XElement m in ex.Elements())
{
if (m.Name != "item")
{
continue;
}
int id = Convert.ToInt32(m.Attribute("id").Value);
ItemHandlerScript itemHandler = new ItemHandlerScript(id);
if (m.Attribute("effect") != null)
{
string str = m.Attribute("effect").Value;
itemHandler.EffectId = Convert.ToInt32(str.Split('-')[0]);
itemHandler.EffectLvl = Convert.ToInt32(str.Split('-')[1]);
}
if (m.Attribute("skill") != null)
{
string str = m.Attribute("skill").Value;
itemHandler.SkillId = Convert.ToInt32(str.Split('-')[0]);
itemHandler.SkillLvl = Convert.ToInt32(str.Split('-')[1]);
}
if (m.Attribute("exchange") != null)
{
string str = m.Attribute("exchange").Value;
foreach (string st in str.Split(';'))
itemHandler.AddExchangeItem(Convert.ToInt32(st.Split('-')[0]), Convert.ToInt32(st.Split('-')[1]));
}
if (m.Attribute("pet") != null)
{
itemHandler.Pet = Convert.ToBoolean(m.Attribute("pet").Value);
}
if (m.Attribute("player") != null)
{
itemHandler.Player = Convert.ToBoolean(m.Attribute("player").Value);
}
if (m.Attribute("destroy") != null)
{
itemHandler.Destroy = Convert.ToBoolean(m.Attribute("destroy").Value);
}
if (m.Attribute("petId") != null)
{
itemHandler.PetId = Convert.ToInt32(m.Attribute("petId").Value);
}
if (m.Attribute("summonId") != null)
{
itemHandler.SummonId = Convert.ToInt32(m.Attribute("summonId").Value);
}
if (m.Attribute("summonStaticId") != null)
{
itemHandler.SummonStaticId = Convert.ToInt32(m.Attribute("summonStaticId").Value);
}
Items.Add(id, itemHandler);
}
}
}
}