-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUtils.cs
More file actions
133 lines (111 loc) · 4.5 KB
/
Utils.cs
File metadata and controls
133 lines (111 loc) · 4.5 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
130
131
132
133
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static CreatureScriptsParser.Packets;
namespace CreatureScriptsParser
{
public static class Utils
{
public static string GetFloatValueInCoreFormat(this float value)
{
if (value.ToString().Length > 1 && value.ToString().Contains(","))
return value.ToString().Replace(",", ".") + "f";
else
return value.ToString() + ".0f";
}
public static string GetValueWithoutComma(this float value)
{
return value.ToString().Replace(",", ".");
}
public static string ConverNameToCoreFormat(string name)
{
Regex lowCaseRegex = new Regex(@"\s+\w{1}");
foreach (Match match in lowCaseRegex.Matches(name))
{
if (char.IsLower(Convert.ToChar(match.Value.Replace(" ", ""))))
{
name = name.Replace(match.Value, match.Value.Replace(match.Value[1].ToString(), match.Value[1].ToString().ToUpper()));
}
}
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 (DB2.Db2.SpellName.ContainsKey((int)spellId))
{
return DB2.Db2.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;
}
public static bool IsSoundRelatedToText(string text, uint soundId)
{
var query = Sql.WorldDatabaseSelectQuery("SELECT `sound` 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() == soundId.ToString())
return true;
}
}
return false;
}
return false;
}
}
}