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
123 lines (96 loc) · 3.8 KB
/
Copy pathItemHandler.cs
File metadata and controls
123 lines (96 loc) · 3.8 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using L2dotNET.Logging.Abstraction;
using L2dotNET.Models.Items.Effects;
namespace L2dotNET.Models.Items
{
public class ItemHandler
{
private static readonly ILog Log = LogProvider.GetCurrentClassLogger();
private static volatile ItemHandler _instance;
private static readonly object SyncRoot = new object();
public static ItemHandler Instance
{
get
{
if (_instance != null)
return _instance;
lock (SyncRoot)
{
if (_instance == null)
_instance = new ItemHandler();
}
return _instance;
}
}
public void Initialize()
{
Register(new EnchantScrolls());
Register(new Calculator());
LoadXml();
Log.Info($"Loaded {_effects} effects with {Items.Count} items.");
}
public SortedList<int, ItemEffect> Items = new SortedList<int, ItemEffect>();
public bool Process(L2Character character, L2Item item)
{
if (!Items.ContainsKey(item.Template.ItemId))
return false;
Items[item.Template.ItemId].Use(character, item);
return true;
}
private short _effects;
private void Register(ItemEffect effect)
{
foreach (int id in effect.Ids)
Items.Add(id, effect);
_effects++;
}
public 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 ih = new ItemHandlerScript(id);
if (m.Attribute("effect") != null)
{
string str = m.Attribute("effect").Value;
ih.EffectId = Convert.ToInt32(str.Split('-')[0]);
ih.EffectLv = Convert.ToInt32(str.Split('-')[1]);
}
if (m.Attribute("skill") != null)
{
string str = m.Attribute("skill").Value;
ih.SkillId = Convert.ToInt32(str.Split('-')[0]);
ih.SkillLv = Convert.ToInt32(str.Split('-')[1]);
}
if (m.Attribute("exchange") != null)
{
string str = m.Attribute("exchange").Value;
foreach (string st in str.Split(';'))
ih.AddExchangeItem(Convert.ToInt32(st.Split('-')[0]), Convert.ToInt32(st.Split('-')[1]));
}
if (m.Attribute("pet") != null)
ih.Pet = Convert.ToBoolean(m.Attribute("pet").Value);
if (m.Attribute("player") != null)
ih.Player = Convert.ToBoolean(m.Attribute("player").Value);
if (m.Attribute("destroy") != null)
ih.Destroy = Convert.ToBoolean(m.Attribute("destroy").Value);
if (m.Attribute("petId") != null)
ih.PetId = Convert.ToInt32(m.Attribute("petId").Value);
if (m.Attribute("summonId") != null)
ih.SummonId = Convert.ToInt32(m.Attribute("summonId").Value);
if (m.Attribute("summonStaticId") != null)
ih.SummonStaticId = Convert.ToInt32(m.Attribute("summonStaticId").Value);
Items.Add(id, ih);
}
}
}
}