forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemHandlerScript.cs
More file actions
129 lines (103 loc) · 3.41 KB
/
Copy pathItemHandlerScript.cs
File metadata and controls
129 lines (103 loc) · 3.41 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
126
127
128
129
using System.Collections.Generic;
using log4net;
using L2dotNET.model.playable;
using L2dotNET.model.player;
using L2dotNET.model.skills2;
using L2dotNET.Network.serverpackets;
using L2dotNET.world;
namespace L2dotNET.model.items
{
class ItemHandlerScript : ItemEffect
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ItemHandlerScript));
private readonly int _id;
public int EffectId = -1;
public int EffectLv;
public bool Pet = false;
public bool Player = true;
public bool Destroy = true;
public int PetId = -1;
public int SummonId = -1;
public int SummonStaticId = -1;
private SortedList<int, int> _exchangeItems;
public int SkillId;
public int SkillLv;
public ItemHandlerScript(int id)
{
_id = id;
}
public void AddExchangeItem(int itemId, int count)
{
if (_exchangeItems == null)
_exchangeItems = new SortedList<int, int>();
_exchangeItems.Add(itemId, count);
}
public override void UsePlayer(L2Player player, L2Item item)
{
if (!Player)
{
base.UsePlayer(player, item);
return;
}
if (Destroy)
player.DestroyItem(item, 1);
CalcSkill(player);
CalcEffect(player);
if (_exchangeItems != null)
{
foreach (int val in _exchangeItems.Keys)
player.AddItem(val, _exchangeItems[val]);
}
if (PetId != -1)
player.PetSummon(item, PetId);
if (SummonId != -1)
player.PetSummon(item, SummonId, false);
if (SummonStaticId != -1)
{
//NpcTable.Instance.SpawnNpc(SummonStaticID, player.X, player.Y, player.Z, player.Heading);
}
}
public override void UsePet(L2Pet pet, L2Item item)
{
if (!Pet)
{
base.UsePet(pet, item);
return;
}
CalcSkill(pet);
CalcEffect(pet);
if (SummonStaticId != -1)
{
//NpcTable.Instance.SpawnNpc(SummonStaticID, pet.X, pet.Y, pet.Z, pet.Heading);
}
}
private void CalcEffect(L2Character character)
{
if (EffectId == -1)
return;
Skill skill = SkillTable.Instance.Get(EffectId, EffectLv);
if (skill == null)
{
Log.Error($"ItemHandler: item {_id} with null effect {EffectId}/{EffectLv}");
return;
}
character.AddAbnormal(skill, character, true, false);
character.BroadcastPacket(new MagicSkillUse(character, character, skill, 100));
}
private void CalcSkill(L2Character character)
{
if (SkillId == -1)
return;
Skill skill = SkillTable.Instance.Get(SkillId, SkillLv);
if (skill == null)
{
Log.Error($"ItemHandler: item {_id} with null skill {SkillId}/{SkillLv}");
return;
}
if (character is L2Player)
((L2Player)character).CastSkill(skill, false, false);
else
character.CastSkill(skill);
}
}
}