Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Konctantin <gawrilyako@gmail.com>
  • Loading branch information
Konctantin committed Sep 23, 2010
1 parent 6d3252c commit ba03499
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 89 deletions.
6 changes: 3 additions & 3 deletions EventAI/DBC/DbcReader.cs
Expand Up @@ -14,7 +14,7 @@ static class DBCReader
string fileName = Path.Combine(DBC.DBC_PATH, (typeof(T).Name).Replace("Entry", String.Empty) + ".dbc");

if (!File.Exists(fileName))
throw new FileNotFoundException("Not found", fileName);
throw new FileNotFoundException("File not found: " + fileName);

using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read), Encoding.UTF8))
{
Expand All @@ -23,9 +23,9 @@ static class DBCReader
int size = Marshal.SizeOf(typeof(T));

if (!header.IsDBC)
throw new FileNotFoundException("Is not DBC files", fileName);
throw new Exception("Is not DBC files " + fileName);
if (header.RecordSize != size)
throw new AIException("Size of row in DBC file ({0}) != size of DBC struct ({1}) in DBC: {2}", header.RecordSize, size, fileName);
throw new Exception(string.Format("Size of row in DBC file ({0}) != size of DBC struct ({1}) in DBC: {2}", header.RecordSize, size, fileName));

// read dbc data
for (int r = 0; r < header.RecordsCount; ++r)
Expand Down
20 changes: 16 additions & 4 deletions EventAI/Enums/AIEnums.cs
Expand Up @@ -107,7 +107,7 @@ public enum EventType
/// <summary>
/// 16
/// </summary>
ЕСЛИ_ТЕРЯЕТ_БАФФ = 16,
ЕСЛИ_ДРУЖЕСТВЕННАЯ_ЦЕЛЬ_ТЕРЯЕТ_БАФФ = 16,
/// <summary>
/// 17
/// </summary>
Expand All @@ -127,19 +127,27 @@ public enum EventType
/// <summary>
/// 23
/// </summary>
ПРИ_ЗНАЧЕНИИ_БАФФА = 23,
ПРИ_ЗНАЧЕНИИ_АУРЫ = 23,
/// <summary>
/// 24
/// </summary>
ПРИ_ЗНАЧЕНИИ_БАФФА_ЦЕЛИ = 24,
ПРИ_ЗНАЧЕНИИ_АУРЫ_ЦЕЛИ = 24,
/// <summary>
/// 25
/// </summary>
ПРИ_СМЕРТИ_ВЫЗВАННОГО_СУЩЕСТВА = 25,
/// <summary>
/// 26
/// </summary>
ПРИ_ИСЧЕЗНОВЕНИИ_ВЫЗВАННОГО_СУЩЕСТВА = 26
ПРИ_ИСЧЕЗНОВЕНИИ_ВЫЗВАННОГО_СУЩЕСТВА = 26,
/// <summary>
/// 27
/// </summary>
ПРИ_ОТСУТСТВИИ_АУРЫ = 27,
/// <summary>
/// 28
/// </summary>
ПРИ_ОТСУТСТВИИ_АУРЫ_ЦЕЛИ = 28,
};

public enum ActionType
Expand Down Expand Up @@ -313,6 +321,10 @@ public enum ActionType
/// 42
/// </summary>
НЕВОЗМОЖНОСТЬ_АТАКОВАТЬ = 42,
/// <summary>
/// 43
/// </summary>
ОСЕДЛАТЬ_МАУНТА_ПО_ENTRY_ИЛИ_ИД_МОДЕЛИ = 43,
};

public enum ConditionType
Expand Down
1 change: 0 additions & 1 deletion EventAI/EventAI.csproj
Expand Up @@ -96,7 +96,6 @@
<DependentUpon>FormAboutBox.cs</DependentUpon>
</Compile>
<Compile Include="Enums\AIEnums.cs" />
<Compile Include="Extensions\AIException.cs" />
<Compile Include="AI\AIStruct.cs" />
<Compile Include="Extensions\ComboBoxExtensions.cs" />
<Compile Include="Info\CreatureInfo.cs" />
Expand Down
17 changes: 0 additions & 17 deletions EventAI/Extensions/AIException.cs

This file was deleted.

59 changes: 28 additions & 31 deletions EventAI/Extensions/ComboBoxExtensions.cs
@@ -1,5 +1,6 @@
using System;
using System.Data;
using System.Reflection;
using System.Collections.Generic;
using System.Windows.Forms;

Expand Down Expand Up @@ -34,58 +35,54 @@ public static int GetIntValue(this TextBox tb)
return tb.Text.ToInt32();
}

public static void SetEnumValues<T>(this ComboBox cb, string NoValue="", string remove="", bool size = true)
public static void SetEnumValues<T>(this ComboBox cb, string noValue = "", string remove = "", bool size = true)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NAME");
if (!typeof(T).IsEnum)
throw new ArgumentException("enumeratedType must be an enum");

Array enumeratedType = Enum.GetValues(typeof(T));

if(NoValue!="")
dt.Rows.Add(new Object[] { -1, NoValue });
if (enumeratedType == null)
throw new NullReferenceException();

foreach (var str in Enum.GetValues(typeof(T)))
{
dt.Rows.Add(new Object[]
{
(int)str,
"(" + ((int)str).ToString("00") + ") " + str.ToString().NormaliseString(remove)
});
}
var list = new List<KeyValuePair<int, string>>();
if (noValue != "")
list.Add(new KeyValuePair<int, string>(-1, noValue));

if(size)
cb.Size = new System.Drawing.Size(238, 21);
foreach (var value in enumeratedType)
list.Add(new KeyValuePair<int, string>((int)value,
"(" + ((int)value).ToString("00") + ") " + value.ToString().NormaliseString(remove)));

cb.DropDownStyle = ComboBoxStyle.DropDownList;
cb.DataSource = dt;
cb.DisplayMember = "NAME";
cb.ValueMember = "ID";
if (size) cb.Size = new System.Drawing.Size(238, 21);
cb.DropDownStyle = ComboBoxStyle.DropDownList;
cb.DataSource = list;
cb.ValueMember = "Key";
cb.DisplayMember = "Value";
}

public static void SetDbcData<T>(this ComboBox cb, Dictionary<uint, T> dict, string noValue = null)
{
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("NAME");

if (dict == null)
return;

var list = new List<KeyValuePair<int, string>>();

if (noValue != null)
dt.Rows.Add(new Object[] { -1, noValue });
list.Add(new KeyValuePair<int, string>(-1, noValue));

foreach (var str in dict.Values)
{
uint ID = str.GetType().GetField("ID").GetValue(str).ToUInt32();
var Name = str.GetType().GetProperty("Name").GetValue(str, null);
int ID = str.GetType().GetField("ID").GetValue(str).ToInt32();
var Name = str.GetType().GetProperty("Name").GetValue(str, null).ToString();

dt.Rows.Add(new Object[] { ID, "(" + ID.ToString("000") + ") " + Name });
list.Add(new KeyValuePair<int, string>(ID, string.Format("({0:000}) {1}", ID, Name)));
}

cb.DataSource = dt;
cb.DisplayMember = "NAME";
cb.ValueMember = "ID";
cb.DropDownStyle = ComboBoxStyle.DropDownList;
cb.Size = ComboboxSize;
cb.DataSource = list;
cb.ValueMember = "Key";
cb.DisplayMember = "Value";
}
}
}
6 changes: 3 additions & 3 deletions EventAI/Forms/ButtonHandler.cs
Expand Up @@ -36,7 +36,7 @@ private Size ComboboxSize
get { return new Size(180, 21); }
}

private FormMain MatherForm
private FormMain ParentForm
{
get { return (FormMain)_combobox.FindForm(); }
}
Expand Down Expand Up @@ -111,13 +111,13 @@ private void ShowForm(object sender, EventArgs e)
case BType.TEXT:
{
MySQLConnenct.SelectAIText();
MatherForm._tPanel.SelectedIndex = 1;
ParentForm._tPanel.SelectedIndex = 1;
}
break;
case BType.SUMMON:
{
MySQLConnenct.SelectAIText();
MatherForm._tPanel.SelectedIndex = 2;
ParentForm._tPanel.SelectedIndex = 2;
}
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion EventAI/Forms/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions EventAI/Forms/FormMain.cs
Expand Up @@ -128,9 +128,8 @@ private void _clbEventFlag_SelectedValueChanged(object sender, EventArgs e)

private void clbEventFlag_SelectedIndexChanged(object sender, EventArgs e)
{
if (_clbEventFlag.SelectedIndex == 5 || _clbEventFlag.SelectedIndex == 6)
if (_clbEventFlag.SelectedIndex == 6)
{
_clbEventFlag.SetItemChecked(5, false);
_clbEventFlag.SetItemChecked(6, false);
MessageBox.Show("Нельзя использовать зарезирвированые флаги!");
}
Expand Down
13 changes: 10 additions & 3 deletions EventAI/Info/Inscription.cs
Expand Up @@ -184,6 +184,11 @@ public static void ShowActionParametr(ComboBox combobox, ComboBox cb1, ComboBox
l2.Text = "При значении жизни";
cb1.SetEnumValues<ValueType>();
break;
case ActionType.ОСЕДЛАТЬ_МАУНТА_ПО_ENTRY_ИЛИ_ИД_МОДЕЛИ:

This comment has been minimized.

Copy link
@technoir42

technoir42 Sep 23, 2010

Какой ужс.

This comment has been minimized.

Copy link
@Konctantin

Konctantin Sep 23, 2010

Author Owner

пофик, это не главное...

This comment has been minimized.

Copy link
@Konctantin

Konctantin Sep 23, 2010

Author Owner

Предложите ваш вариант...

This comment has been minimized.

Copy link
@technoir42

technoir42 Sep 23, 2010

Я про кириллицу.

This comment has been minimized.

Copy link
@Konctantin

Konctantin Sep 23, 2010

Author Owner

А, так вот уже давненько хочу прикрутить локализацию, да только никак руки не доходят, а сейчас так еще и роботы привалило, что не до этого всего.

l1.Text = "Существо";
l2.Text = "Модель";
new ButtonHandler(cb1, BType.CREATURE);
break;
}

cb1.Visible = l1.Text != string.Empty;
Expand Down Expand Up @@ -257,7 +262,7 @@ public static void ShowEventType(ComboBox combobox, ComboBox cb1, ComboBox cb2,
l3.Text = "Минимальное время до повтора (мс)";
l4.Text = "Максимальное время до повтора (мс)";
break;
case EventType.ЕСЛИ_ТЕРЯЕТ_БАФФ:
case EventType.ЕСЛИ_ДРУЖЕСТВЕННАЯ_ЦЕЛЬ_ТЕРЯЕТ_БАФФ:
l1.Text = "ID спелла (заклинания)";
new ButtonHandler(cb1, BType.SPELL);
l2.Text = "В радиусе";
Expand All @@ -276,8 +281,10 @@ public static void ShowEventType(ComboBox combobox, ComboBox cb1, ComboBox cb2,
cb1.SetDbcData(DBC.Emotes);
cb2.SetEnumValues<ConditionType>();
break;
case EventType.ПРИ_ЗНАЧЕНИИ_БАФФА:
case EventType.ПРИ_ЗНАЧЕНИИ_БАФФА_ЦЕЛИ:
case EventType.ПРИ_ЗНАЧЕНИИ_АУРЫ:
case EventType.ПРИ_ЗНАЧЕНИИ_АУРЫ_ЦЕЛИ:
case EventType.ПРИ_ОТСУТСТВИИ_АУРЫ:
case EventType.ПРИ_ОТСУТСТВИИ_АУРЫ_ЦЕЛИ:
l1.Text = "ID спелла";
new ButtonHandler(cb1, BType.SPELL);
l2.Text = "Количество";
Expand Down
36 changes: 18 additions & 18 deletions EventAI/Program.cs
Expand Up @@ -25,16 +25,21 @@ static void Main()
Application.Exit();
return;
}

new Thread(LoadDBC).Start();

Application.Run(new FormMain());
try
{
LoadDBC();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
Application.Run(new FormMain());
}

private static void LoadDBC()
{
DBC.Spell = DBCReader.ReadDBC<SpellEntry>(DBC._SpellStrings);

DBC.SkillLine = DBCReader.ReadDBC<SkillLineEntry>(DBC._SkillLineStrings);
DBC.SpellRange = DBCReader.ReadDBC<SpellRangeEntry>(DBC._SpellRangeStrings);
DBC.Emotes = DBCReader.ReadDBC<EmotesEntry>(DBC._EmotesStrings);
Expand All @@ -44,29 +49,24 @@ private static void LoadDBC()
DBC.CreatureFamily = DBCReader.ReadDBC<CreatureFamilyEntry>(DBC._CreatureFamilyStrings);
DBC.CreatureType = DBCReader.ReadDBC<CreatureTypeEntry>(DBC._CreatureTypeStrings);
DBC.QuestType = DBCReader.ReadDBC<QuestInfoEntry>(DBC._QuestInfoStrings);

DBC.SpellDuration = DBCReader.ReadDBC<SpellDurationEntry>();
DBC.SkillLineAbility = DBCReader.ReadDBC<SkillLineAbilityEntry>();
DBC.SpellRadius = DBCReader.ReadDBC<SpellRadiusEntry>();
DBC.SpellCastTimes = DBCReader.ReadDBC<SpellCastTimesEntry>();

DBC.Locale = DetectedLocale;
DBC.Locale = DetectedLocale();
}

private static LocalesDBC DetectedLocale
private static LocalesDBC DetectedLocale()
{
get
byte locale = 0;
while (DBC.Spell[1].GetName(locale) == String.Empty)
{
byte locale = 0;
while (DBC.Spell[1].GetName(locale) == String.Empty)
{
++locale;

if (locale >= DBC.MAX_DBC_LOCALE)
throw new AIException("Detected unknown locale index {0}", locale);
}
return (LocalesDBC)locale;
++locale;
if (locale >= DBC.MAX_DBC_LOCALE)
throw new Exception("Detected unknown locale index " + locale);
}
return (LocalesDBC)locale;
}
}
}
Binary file modified EventAI/bin/Debug/EventAI.exe
Binary file not shown.

0 comments on commit ba03499

Please sign in to comment.