forked from Simonlamb1979/CreatureScriptsParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
94 lines (79 loc) · 3.11 KB
/
Utils.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static CreatureScriptsParser.Packets;
namespace CreatureScriptsParser
{
public static class Utils
{
public static string GetValueWithoutComma(this float value)
{
return value.ToString().Replace(",", ".");
}
public static string ConverNameToCoreFormat(string name)
{
return name.Replace("\'", "").Replace(" ", "").Replace("(", "").Replace(")", "").Replace("-", "");
}
public static uint GetCreatureEntryUsingGuid(List<object> packets, string guid)
{
var updaeObjectPacket = packets.FirstOrDefault(x => ((Packet)x).type == Packet.PacketTypes.SMSG_UPDATE_OBJECT && ((Packet)x).guid == guid && ((UpdateObjectPacket)x).updateType == UpdateObjectPacket.UpdateType.CreateObject);
if (updaeObjectPacket != null)
{
return ((UpdateObjectPacket)packets.FirstOrDefault(x => ((Packet)x).type == Packet.PacketTypes.SMSG_UPDATE_OBJECT && ((Packet)x).guid == guid && ((UpdateObjectPacket)x).updateType == UpdateObjectPacket.UpdateType.CreateObject)).creatureEntry;
}
else
return 0;
}
public static string GetCreatureNameFromDb(uint entry)
{
string sqlQuery = "SELECT `Name1` FROM `creature_template_wdb` WHERE `entry` = " + entry;
if (Sql.WorldDatabaseSelectQuery(sqlQuery).Tables["table"].Rows.Count != 0)
{
return Sql.WorldDatabaseSelectQuery(sqlQuery).Tables["table"].Select().First().ItemArray.First().ToString();
}
else
return "Unknown";
}
public static string GetSpellName(uint spellId)
{
if (Dbc.Dbc.SpellName.ContainsKey((int)spellId))
{
return Dbc.Dbc.SpellName[(int)spellId].Name;
}
return "Unknown";
}
public static string AddSpacesCount(uint count)
{
string spaces = "";
for (uint i = 0; i < count; i++)
{
spaces += ' ';
}
return spaces;
}
public static string ToFormattedString(this TimeSpan span)
{
return $"{span.Hours:00}:{span.Minutes:00}:{span.Seconds:00}.{span.Milliseconds:000}";
}
public static bool IsEmoteRelatedToText(string text, uint emoteId)
{
var query = Sql.WorldDatabaseSelectQuery("SELECT `emote` FROM `creature_text` WHERE `text` LIKE " + "'%" + text.Replace("'", "''") + "%'");
if (query.Tables["table"].Rows.Count != 0)
{
foreach (DataRow row in query.Tables["table"].Rows)
{
foreach (var item in row.ItemArray)
{
if (item.ToString() == emoteId.ToString())
return true;
}
}
return false;
}
return false;
}
}
}