forked from ACEmulator/ACE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpellComponentsTable.cs
80 lines (66 loc) · 2.74 KB
/
SpellComponentsTable.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
using System.Collections.Generic;
using System.IO;
using ACE.DatLoader.Entity;
namespace ACE.DatLoader.FileTypes
{
[DatFileType(DatFileType.SpellComponentTable)]
public class SpellComponentsTable : FileType
{
public enum Type
{
Scarab = 1,
Herb = 2,
Powder = 3,
Potion = 4,
Talisman = 5,
Taper = 6,
PotionPea = 7,
TalismanPea = 5,
TaperPea = 7
}
internal const uint FILE_ID = 0x0E00000F;
public Dictionary<uint, SpellComponentBase> SpellComponents { get; } = new Dictionary<uint, SpellComponentBase>();
public override void Unpack(BinaryReader reader)
{
Id = reader.ReadUInt32();
uint numComps = reader.ReadUInt16(); // Should be 163 or 0xA3
reader.AlignBoundary();
SpellComponents.Unpack(reader, numComps);
}
public static string GetSpellWords(SpellComponentsTable comps, List<uint> formula)
{
string firstSpellWord = "";
string secondSpellWord = "";
string thirdSpellWord = "";
if (formula == null) return "";
// Locate the herb component in the Spell formula
for (int i = 0; i < formula.Count; i++)
{
if (comps.SpellComponents[formula[i]].Type == (uint)Type.Herb)
firstSpellWord = comps.SpellComponents[formula[i]].Text;
}
// Locate the powder component in the Spell formula
for (int i = 0; i < formula.Count; i++)
{
if (comps.SpellComponents[formula[i]].Type == (uint)Type.Powder)
secondSpellWord = comps.SpellComponents[formula[i]].Text;
}
// Locate the potion component in the Spell formula
for (int i = 0; i < formula.Count; i++)
{
if (comps.SpellComponents[formula[i]].Type == (uint)Type.Potion)
thirdSpellWord = comps.SpellComponents[formula[i]].Text;
}
// We need to make sure our second spell word, if any, is capitalized
// Some spell words have no "secondSpellWord", so we're basically making sure the third word is capitalized.
string secondSpellWordSet = (secondSpellWord + thirdSpellWord.ToLower());
if(secondSpellWordSet != "")
{
string firstLetter = secondSpellWordSet.Substring(0, 1).ToUpper();
secondSpellWordSet = firstLetter + secondSpellWordSet.Substring(1);
}
string result = $"{firstSpellWord} {secondSpellWordSet}";
return result.Trim();
}
}
}