forked from jo3bingham/TibiaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppearanceStorage.cs
More file actions
58 lines (50 loc) · 1.92 KB
/
AppearanceStorage.cs
File metadata and controls
58 lines (50 loc) · 1.92 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
using System.IO;
using System.Linq;
using OXGaming.TibiaAPI.Constants;
namespace OXGaming.TibiaAPI.Appearances
{
public class AppearanceStorage
{
private Utilities.Appearances appearances;
private uint lastObjectId;
private uint lastOutfitId;
public void LoadAppearances(FileStream datFileStream)
{
appearances = Utilities.Appearances.Parser.ParseFrom(datFileStream);
lastObjectId = appearances.Object.Aggregate((last, current) => last.Id > current.Id ? last : current).Id;
lastOutfitId = appearances.Outfit.Aggregate((last, current) => last.Id > current.Id ? last : current).Id;
}
public ObjectInstance CreateObjectInstance(uint id, uint data)
{
if (id >= (uint)CreatureInstanceType.Creature && id <= lastObjectId)
{
return new ObjectInstance(id, appearances.Object.FirstOrDefault(i => i.Id == id), data);
}
return null;
}
public OutfitInstance CreateOutfitInstance(uint id, byte colorHead, byte colorTorso, byte colorLegs, byte colorDetail, byte addons)
{
if (id >= 0 && id <= lastOutfitId)
{
return new OutfitInstance(id, appearances.Outfit.FirstOrDefault(i => i.Id == id), colorHead, colorTorso, colorLegs, colorDetail, addons);
}
return null;
}
public Utilities.Appearance GetObjectType(uint id)
{
if (id > (uint)CreatureInstanceType.Creature && id <= lastObjectId)
{
return appearances.Object.FirstOrDefault(o => o.Id == id);
}
return null;
}
public Utilities.Appearance GetOutfitType(uint id)
{
if (id > 0 && id <= lastOutfitId)
{
appearances.Outfit.FirstOrDefault(i => i.Id == id);
}
return null;
}
}
}