-
Notifications
You must be signed in to change notification settings - Fork 16
/
StatSkill.cs
188 lines (163 loc) · 6.39 KB
/
StatSkill.cs
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
176
177
178
179
180
181
182
183
184
185
186
187
188
using System;
using System.Collections.Generic;
using EOLib.Domain.Character;
using EOLib.Net.Handlers;
namespace EOLib.Net.API
{
public enum SkillMasterReply
{
// ReSharper disable once UnusedMember.Global
ErrorRemoveItems = 1,
ErrorWrongClass = 2
}
public struct Skill
{
private readonly short m_id;
private readonly byte m_levelReq;
private readonly byte m_classReq;
private readonly int m_goldCost;
private readonly short[] m_skillReq; //ids of other skills that are required to know before learning this skill
private readonly short m_strReq;
private readonly short m_intReq;
private readonly short m_wisReq;
private readonly short m_agiReq;
private readonly short m_conReq;
private readonly short m_chaReq;
public short ID => m_id;
public byte LevelReq => m_levelReq;
public byte ClassReq => m_classReq;
public int GoldReq => m_goldCost;
public short[] SkillReq => m_skillReq;
public short StrReq => m_strReq;
public short IntReq => m_intReq;
public short WisReq => m_wisReq;
public short AgiReq => m_agiReq;
public short ConReq => m_conReq;
public short ChaReq => m_chaReq;
internal Skill(OldPacket pkt)
{
m_id = pkt.GetShort();
m_levelReq = pkt.GetChar();
m_classReq = pkt.GetChar();
m_goldCost = pkt.GetInt();
m_skillReq = new[]
{
pkt.GetShort(),
pkt.GetShort(),
pkt.GetShort(),
pkt.GetShort()
};
m_strReq = pkt.GetShort();
m_intReq = pkt.GetShort();
m_wisReq = pkt.GetShort();
m_agiReq = pkt.GetShort();
m_conReq = pkt.GetShort();
m_chaReq = pkt.GetShort();
}
}
public struct StatResetData
{
private readonly short m_statpts, m_skillpts, m_hp, m_maxhp, m_tp, m_maxtp, m_maxsp;
private readonly short m_str, m_int, m_wis, m_agi, m_con, m_cha;
private readonly short m_mindam, m_maxdam, m_acc, m_evade, m_armor;
public short StatPoints => m_statpts;
public short SkillPoints => m_skillpts;
public short HP => m_hp;
public short MaxHP => m_maxhp;
public short TP => m_tp;
public short MaxTP => m_maxtp;
public short MaxSP => m_maxsp;
public short Str => m_str;
public short Int => m_int;
public short Wis => m_wis;
public short Agi => m_agi;
public short Con => m_con;
public short Cha => m_cha;
public short MinDam => m_mindam;
public short MaxDam => m_maxdam;
public short Accuracy => m_acc;
public short Evade => m_evade;
public short Armor => m_armor;
internal StatResetData(OldPacket pkt)
{
m_statpts = pkt.GetShort();
m_skillpts = pkt.GetShort();
m_hp = pkt.GetShort();
m_maxhp = pkt.GetShort();
m_tp = pkt.GetShort();
m_maxtp = pkt.GetShort();
m_maxsp = pkt.GetShort();
m_str = pkt.GetShort();
m_int = pkt.GetShort();
m_wis = pkt.GetShort();
m_agi = pkt.GetShort();
m_con = pkt.GetShort();
m_cha = pkt.GetShort();
m_mindam = pkt.GetShort();
m_maxdam = pkt.GetShort();
m_acc = pkt.GetShort();
m_evade = pkt.GetShort();
m_armor = pkt.GetShort();
}
}
public delegate void SpellLearnErrorEvent(SkillMasterReply reply, short classID);
public delegate void SpellForgetEvent(short spellID);
partial class PacketAPI
{
public event SpellLearnErrorEvent OnSpellLearnError;
public event SpellForgetEvent OnSpellForget;
public event Action<StatResetData> OnCharacterStatsReset;
private void _createStatSkillMembers()
{
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Reply), _handleStatSkillReply, true);
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Remove), _handleStatSkillRemove, true);
m_client.AddPacketHandler(new FamilyActionPair(PacketFamily.StatSkill, PacketAction.Junk), _handleStatSkillJunk, true);
}
public bool LearnSpell(short spellID)
{
if (!m_client.ConnectedAndInitialized || !Initialized)
return false;
OldPacket pkt = new OldPacket(PacketFamily.StatSkill, PacketAction.Take);
pkt.AddInt(1234); //shop ID, ignored by eoserv - eomain may require this to be correct
pkt.AddShort(spellID);
return m_client.SendPacket(pkt);
}
public bool ForgetSpell(short spellID)
{
if (!m_client.ConnectedAndInitialized || !Initialized)
return false;
OldPacket pkt = new OldPacket(PacketFamily.StatSkill, PacketAction.Remove);
pkt.AddInt(1234); //shop ID, ignored by eoserv - eomain may require this to be correct
pkt.AddShort(spellID);
return m_client.SendPacket(pkt);
}
public bool ResetCharacterStatSkill()
{
OldPacket pkt = new OldPacket(PacketFamily.StatSkill, PacketAction.Junk);
pkt.AddInt(1234); //shop ID, ignored by eoserv - eomain may require this to be correct
return !m_client.ConnectedAndInitialized || !Initialized || m_client.SendPacket(pkt);
}
//handlers
//error learning a skill
private void _handleStatSkillReply(OldPacket pkt)
{
//short - should always be SKILLMASTER_REMOVE_ITEMS (1) or SKILLMASTER_WRONG_CLASS (2)
//short - character class
if (OnSpellLearnError != null)
OnSpellLearnError((SkillMasterReply)pkt.GetShort(), pkt.GetShort());
}
//forgetting a skill
private void _handleStatSkillRemove(OldPacket pkt)
{
//short - spell id
if (OnSpellForget != null)
OnSpellForget(pkt.GetShort());
}
//reset character
private void _handleStatSkillJunk(OldPacket pkt)
{
if (OnCharacterStatsReset != null)
OnCharacterStatsReset(new StatResetData(pkt));
}
}
}