Form1.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  1. // At some point add in the option to use either MoveToLocation()
  2. // or MovementLoopAddLocation() for looping or for one time path
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. using System.Text;
  12. namespace Movement_Loop_Generator_2._0
  13. {
  14. public partial class Form1 : Form
  15. {
  16. float x;
  17. float y;
  18. float z;
  19. int rowNumber;
  20. List<DataStruct> dataLoc = new List<DataStruct>();
  21. Dictionary<string, string> NPCList = new Dictionary<string, string>();
  22. private OpenFileDialog file_dialog = new OpenFileDialog();
  23. FileStream fileStream;
  24. private long LastLengthLocation = -1;
  25. private String LastErrMsg = "";
  26. private Exception LastExceptionMsg = null;
  27. private bool suppress = false;
  28. public Form1()
  29. {
  30. InitializeComponent();
  31. userToolStripMenuItem.Text = Properties.Settings.Default.Author;
  32. //Thread.CurrentThread.CurrentCulture = new CultureInfo("eu-fr");
  33. }
  34. /*********************************************************************************************************************************
  35. * Drag and Drop handler
  36. *********************************************************************************************************************************/
  37. private void Form1_DragEnter(object sender, DragEventArgs e)
  38. {
  39. if (e.Data.GetDataPresent(DataFormats.FileDrop))
  40. e.Effect = DragDropEffects.All;
  41. else
  42. e.Effect = DragDropEffects.None;
  43. }
  44. private void Form1_DragDrop(object sender, DragEventArgs e)
  45. {
  46. string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, true);
  47. string filename = Path.GetFullPath(FileList[0]);
  48. ResetListView(true);
  49. ResetTextBoxes();
  50. NPCList.Clear();
  51. listBox_NPCs.Items.Clear();
  52. dataLoc.Clear();
  53. richTextBox_OutputView.Clear();
  54. this.textBox_LogFile.Text = filename;
  55. //richTextBox_OutputView.Text = "Clearing listview, textboxes, and location data.\nGetting spawn and author information.\nGetting spawn location data.\n" +
  56. //"Loading list with spawn location data.\n";
  57. if (checkBox_ReversePath.Checked == true)
  58. {
  59. checkBox_ReversePath.Checked = false;
  60. }
  61. ParseNPC();
  62. ListviewLoad();
  63. }
  64. /*********************************************************************************************************************************
  65. * Load DataStruct List
  66. *********************************************************************************************************************************/
  67. private void ParseData()
  68. {
  69. if (listBox_NPCs.SelectedIndex < 0)
  70. {
  71. return;
  72. }
  73. checkBox_ReversePath.Visible = true;
  74. bool found = false;
  75. int npcname_count = 0;
  76. string [] split = NPCList[listBox_NPCs.SelectedItem.ToString()].Split(' ');
  77. string npcname = split[0];
  78. if (split.Length > 1)
  79. {
  80. Int32.TryParse(split[1], out npcname_count);
  81. }
  82. string line;
  83. string locSpeed = "'loc_speed ";
  84. string locDelay = "'loc_delay ";
  85. string locStart = "'loc_start ";
  86. string locEnd = "'";
  87. string locStop = "'loc_stop'";
  88. int namecount = 0;
  89. int count = 0;
  90. int setSpeed = 0;
  91. int index;
  92. int setDelay = 0;
  93. int delindex;
  94. dataLoc = new List<DataStruct>();
  95. ResetListView(true);
  96. // Parse button throws an exception Unhandled if the logfile text box is empty
  97. LastLengthLocation = -1;
  98. try
  99. {
  100. while (OpenReadLine(out line))
  101. {
  102. if (line.Contains(locSpeed))
  103. {
  104. index = line.IndexOf("Unknown command: 'loc_speed") + 28;
  105. setSpeed = Convert.ToInt32(line.Substring(index, (line.Length - index) - 1));
  106. }
  107. if (line.Contains(locDelay))
  108. {
  109. delindex = line.IndexOf("Unknown command: 'loc_delay") + 28;
  110. setDelay = Convert.ToInt32(line.Substring(delindex, (line.Length - delindex) - 1));
  111. }
  112. // Test to see if I can advanced to the next name and get the loc from the second collect
  113. if (line.Contains(locStart + npcname + locEnd) && npcname_count < 1)
  114. {
  115. found = true;
  116. count++;
  117. }
  118. if (line.Contains(locStart + npcname + locEnd) && npcname_count >= 1)
  119. {
  120. if (npcname_count == namecount)
  121. {
  122. found = true;
  123. count++;
  124. namecount = 0;
  125. }
  126. else
  127. {
  128. found = false;
  129. namecount++;
  130. }
  131. }
  132. if (line.Contains(locStop))
  133. {
  134. if (count >= 1)
  135. {
  136. return;
  137. }
  138. else
  139. {
  140. found = false;
  141. }
  142. }
  143. if (found)
  144. {
  145. if (line.Contains("Your location is"))
  146. {
  147. Match matchPosition = Regex.Match(line, @"Your location is.*Your orientation is", RegexOptions.IgnoreCase);
  148. string[] location = matchPosition.Value.Replace(@"Your location is ", "").Replace(@". Your orientation is", "").Split(',');
  149. if (location.Count() == 3)
  150. {
  151. x = float.Parse(location[0].Trim(), CultureInfo.InvariantCulture);
  152. y = float.Parse(location[1].Trim(), CultureInfo.InvariantCulture);
  153. z = float.Parse(location[2].Trim(), CultureInfo.InvariantCulture);
  154. DataStruct locData;
  155. if (npcname_count >= 1)
  156. {
  157. locData.Name = npcname + "_" + npcname_count.ToString();
  158. }
  159. else
  160. {
  161. locData.Name = npcname;
  162. }
  163. locData.Author = Properties.Settings.Default.Author;
  164. locData.XLoc = x;
  165. locData.YLoc = y;
  166. locData.ZLoc = z;
  167. if (setSpeed > 0)
  168. {
  169. locData.Speed = setSpeed;
  170. setSpeed = 0;
  171. }
  172. else
  173. {
  174. locData.Speed = 2;
  175. }
  176. if (setDelay > 0)
  177. {
  178. locData.Delay = setDelay;
  179. setDelay = 0;
  180. }
  181. else
  182. {
  183. locData.Delay = 0;
  184. }
  185. locData.Function = textBox_Function.Text;
  186. dataLoc.Add(locData);
  187. }
  188. }
  189. }
  190. }
  191. }
  192. catch
  193. {
  194. MessageBox.Show("Cannot read log file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  195. }
  196. }
  197. private void ParseNPC()
  198. {
  199. string line;
  200. string locStart = "'loc_start ";
  201. int index = 0;
  202. int multipleNPC = 0;
  203. LastLengthLocation = -1;
  204. while (OpenReadLine(out line))
  205. {
  206. if (line.Contains(locStart))
  207. {
  208. index = line.IndexOf(locStart) + 11;
  209. string npc_name = line.Substring(index, (line.Length - index) - 1);
  210. if (NPCList.ContainsKey(npc_name))
  211. {
  212. multipleNPC++;
  213. string newNPCName = npc_name + " " + Convert.ToString(multipleNPC);
  214. NPCList.Add(newNPCName, newNPCName);
  215. listBox_NPCs.Items.Add(newNPCName);
  216. }
  217. else
  218. {
  219. NPCList.Add(npc_name, npc_name);
  220. listBox_NPCs.Items.Add(npc_name);
  221. }
  222. }
  223. }
  224. }
  225. /*********************************************************************************************************************************
  226. * List View & Rich TextBox Load
  227. *********************************************************************************************************************************/
  228. private void ListviewLoad()
  229. {
  230. foreach(DataStruct locData in dataLoc)
  231. {
  232. ListViewItem loc = new ListViewItem();
  233. loc.SubItems.Add(locData.XLoc.ToString(CultureInfo.InvariantCulture));
  234. loc.SubItems.Add(locData.YLoc.ToString(CultureInfo.InvariantCulture));
  235. loc.SubItems.Add(locData.ZLoc.ToString(CultureInfo.InvariantCulture));
  236. loc.SubItems.Add(locData.Speed.ToString(CultureInfo.InvariantCulture));
  237. loc.SubItems.Add(locData.Delay.ToString(CultureInfo.InvariantCulture));
  238. loc.SubItems.Add(locData.Function);
  239. listView_Loaded.Items.Add(loc);
  240. }
  241. }
  242. private void RTBLoad()
  243. {
  244. foreach (DataStruct locData in dataLoc)
  245. {
  246. string Output;
  247. string name = locData.Name;
  248. string author = locData.Author;
  249. string x = locData.XLoc.ToString();
  250. string y = locData.YLoc.ToString();
  251. string z = locData.ZLoc.ToString();
  252. string speed = locData.Speed.ToString();
  253. string delay = locData.Delay.ToString();
  254. string function = locData.Function;
  255. if (string.IsNullOrEmpty(function))
  256. {
  257. Output = "MovementLoopAddLocation(NPC, " + x + ", " + y + ", " + z + ", " + speed + ", " + delay + ")" + System.Environment.NewLine;
  258. this.richTextBox_OutputView.Text += Output;
  259. }
  260. else
  261. {
  262. Output = "MovementLoopAddLocation(NPC, " + x + ", " + y + ", " + z + ", " + speed + ", " + delay + ", " + function + ")" + System.Environment.NewLine;
  263. this.richTextBox_OutputView.Text += Output;
  264. }
  265. }
  266. }
  267. /*********************************************************************************************************************************
  268. * ListView Select Loads TextBoxes
  269. *********************************************************************************************************************************/
  270. private void listView_Loaded_SelectedIndexChanged(object sender, EventArgs e)
  271. {
  272. if (listView_Loaded.SelectedIndices.Count == 0 || listView_Loaded.SelectedIndices[0] == -1)
  273. {
  274. ResetListView(false);
  275. return;
  276. }
  277. ListViewItem loc = listView_Loaded.Items[listView_Loaded.SelectedIndices[0]];
  278. textBox_XLOC.Text = loc.SubItems[1].Text;
  279. textBox_YLOC.Text = loc.SubItems[2].Text;
  280. textBox_ZLOC.Text = loc.SubItems[3].Text;
  281. textBox_Speed.Text = loc.SubItems[4].Text;
  282. textBox_Delay.Text = loc.SubItems[5].Text;
  283. textBox_Function.Text = loc.SubItems[6].Text;
  284. rowNumber = listView_Loaded.FocusedItem.Index;
  285. richTextBox_OutputView.Clear();
  286. richTextBox_OutputView.Text = "Data Loaded";
  287. button_InsertAbove.Enabled = true;
  288. button_InsertBelow.Enabled = true;
  289. button_Update.Enabled = true;
  290. button_Remove.Enabled = true;
  291. button_Reset.Enabled = true;
  292. }
  293. /*********************************************************************************************************************************
  294. * Reset ListView & TextBoxes
  295. *********************************************************************************************************************************/
  296. private void ResetListView(bool include_listview)
  297. {
  298. if (include_listview)
  299. listView_Loaded.Items.Clear();
  300. }
  301. private void ResetTextBoxes()
  302. {
  303. textBox_XLOC.Clear();
  304. textBox_YLOC.Clear();
  305. textBox_ZLOC.Clear();
  306. textBox_Speed.Clear();
  307. textBox_Delay.Clear();
  308. textBox_Function.Clear();
  309. }
  310. /*********************************************************************************************************************************
  311. * Buttons
  312. *********************************************************************************************************************************/
  313. private void btn_Browse_Click(object sender, EventArgs e)
  314. {
  315. file_dialog.Title = "Load Log File";
  316. file_dialog.Filter = "Text|*.txt|All|*.*";
  317. if (this.file_dialog.ShowDialog() == DialogResult.OK)
  318. {
  319. CloseFile();
  320. this.textBox_LogFile.Text = this.file_dialog.FileName;
  321. ResetListView(true);
  322. ResetTextBoxes();
  323. NPCList.Clear();
  324. listBox_NPCs.Items.Clear();
  325. dataLoc.Clear();
  326. //richTextBox_OutputView.Text = "Clearing listview, textboxes, and location data.\nGetting spawn and author information.\nGetting spawn location data.\n" +
  327. //"Loading list with spawn location data.\n";
  328. rowNumber = 0; // resetting since setting reversepath to false calls this as part of the [] iterator
  329. if (checkBox_ReversePath.Checked == true)
  330. {
  331. checkBox_ReversePath.Checked = false;
  332. }
  333. ParseNPC();
  334. richTextBox_OutputView.Clear();
  335. int total_npcs = NPCList.Count;
  336. richTextBox_OutputView.Text = total_npcs + " NPC's Found and listed on the left\n\nDouble Click an NPC's name to load its waypoints.";
  337. ListviewLoad();
  338. }
  339. }
  340. private void textBox_LogFile_DoubleClick(object sender, EventArgs e)
  341. {
  342. btn_Browse_Click(sender, e);
  343. }
  344. private void button_Update_Click(object sender, EventArgs e)
  345. {
  346. richTextBox_OutputView.Clear();
  347. if (textBox_XLOC.Text == String.Empty || textBox_YLOC.Text == String.Empty || textBox_ZLOC.Text == String.Empty || textBox_Speed.Text == String.Empty)
  348. {
  349. listView_Loaded_SelectedIndexChanged(sender, e);
  350. }
  351. else
  352. {
  353. DataStruct locData = dataLoc[rowNumber];
  354. locData.XLoc = float.Parse(textBox_XLOC.Text);
  355. locData.YLoc = float.Parse(textBox_YLOC.Text);
  356. locData.ZLoc = float.Parse(textBox_ZLOC.Text);
  357. locData.Speed = Convert.ToInt32(textBox_Speed.Text);
  358. locData.Delay = Convert.ToInt32(textBox_Delay.Text);
  359. locData.Function = textBox_Function.Text;
  360. dataLoc.Insert(rowNumber, locData);
  361. dataLoc.RemoveAt(rowNumber + 1);
  362. ResetTextBoxes();
  363. ResetListView(true);
  364. ListviewLoad();
  365. richTextBox_OutputView.Text = "Updated Entry";
  366. }
  367. }
  368. private void button_InsertAbove_Click(object sender, EventArgs e)
  369. {
  370. richTextBox_OutputView.Clear();
  371. if (listView_Loaded.SelectedIndices.Count == 0 || listView_Loaded.SelectedIndices[0] == -1)
  372. {
  373. MessageBox.Show("You must select something from the list first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  374. return;
  375. }
  376. if (textBox_XLOC.Text == String.Empty || textBox_YLOC.Text == String.Empty || textBox_ZLOC.Text == String.Empty)
  377. {
  378. MessageBox.Show("You are missing either X, Y, or Z coordinates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  379. return;
  380. }
  381. if (string.IsNullOrEmpty(textBox_Speed.Text))
  382. {
  383. textBox_Speed.Text = "2";
  384. }
  385. if (string.IsNullOrEmpty(textBox_Delay.Text))
  386. {
  387. textBox_Delay.Text = "0";
  388. }
  389. DataStruct locData = dataLoc[rowNumber];
  390. locData.XLoc = float.Parse(textBox_XLOC.Text);
  391. locData.YLoc = float.Parse(textBox_YLOC.Text);
  392. locData.ZLoc = float.Parse(textBox_ZLOC.Text);
  393. locData.Speed = Convert.ToInt32(textBox_Speed.Text);
  394. locData.Delay = Convert.ToInt32(textBox_Delay.Text);
  395. locData.Function = textBox_Function.Text;
  396. dataLoc.Insert(rowNumber, locData);
  397. ResetTextBoxes();
  398. ResetListView(true);
  399. ListviewLoad();
  400. richTextBox_OutputView.Text = "Inserted New Entry";
  401. }
  402. private void button_InsertBelow_Click(object sender, EventArgs e)
  403. {
  404. richTextBox_OutputView.Clear();
  405. if (listView_Loaded.SelectedIndices.Count == 0 || listView_Loaded.SelectedIndices[0] == -1)
  406. {
  407. MessageBox.Show("You must select something from the list first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  408. return;
  409. }
  410. if (textBox_XLOC.Text == String.Empty || textBox_YLOC.Text == String.Empty || textBox_ZLOC.Text == String.Empty)
  411. {
  412. MessageBox.Show("You are missing either X, Y, or Z coordinates", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  413. return;
  414. }
  415. if (string.IsNullOrEmpty(textBox_Speed.Text))
  416. {
  417. textBox_Speed.Text = "2";
  418. }
  419. if (string.IsNullOrEmpty(textBox_Delay.Text))
  420. {
  421. textBox_Delay.Text = "0";
  422. }
  423. DataStruct locData = dataLoc[rowNumber];
  424. locData.XLoc = float.Parse(textBox_XLOC.Text);
  425. locData.YLoc = float.Parse(textBox_YLOC.Text);
  426. locData.ZLoc = float.Parse(textBox_ZLOC.Text);
  427. locData.Speed = Convert.ToInt32(textBox_Speed.Text);
  428. locData.Delay = Convert.ToInt32(textBox_Delay.Text);
  429. locData.Function = textBox_Function.Text;
  430. dataLoc.Insert(rowNumber + 1, locData);
  431. ResetTextBoxes();
  432. ResetListView(true);
  433. ListviewLoad();
  434. richTextBox_OutputView.Text = "Inserted New Entry";
  435. }
  436. private void button_Remove_Click(object sender, EventArgs e)
  437. {
  438. richTextBox_OutputView.Clear();
  439. DataStruct locData = dataLoc[rowNumber];
  440. dataLoc.RemoveAt(rowNumber);
  441. ResetTextBoxes();
  442. ResetListView(true);
  443. ListviewLoad();
  444. richTextBox_OutputView.Text = "Removed Selected Entry";
  445. }
  446. private void checkBox_ReversePath_CheckedChanged(object sender, EventArgs e)
  447. {
  448. // might be a reload so don't crash trying to pull beyond the array!
  449. if (dataLoc.Count() <= rowNumber)
  450. return;
  451. int rowCount = dataLoc.Count;
  452. // Throws an error here if the checkbox has been unchecked and checked a second time
  453. DataStruct locData = dataLoc[rowNumber];
  454. bool firstRun = true;
  455. // Reverse the path
  456. if (checkBox_ReversePath.Checked)
  457. {
  458. rowNumber = rowCount - 1;
  459. while (rowCount > 0)
  460. {
  461. if (firstRun == true)
  462. {
  463. rowCount = (rowCount - 2);
  464. firstRun = false;
  465. }
  466. else
  467. {
  468. rowCount--;
  469. }
  470. locData = dataLoc[rowCount];
  471. float tmpXLoc = locData.XLoc;
  472. float tmpYLoc = locData.YLoc;
  473. float tmpZLoc = locData.ZLoc;
  474. int tmpSpeed = locData.Speed;
  475. int tmpDelay = locData.Delay;
  476. string tmpFunction = locData.Function;
  477. locData.XLoc = tmpXLoc;
  478. locData.YLoc = tmpYLoc;
  479. locData.ZLoc = tmpZLoc;
  480. locData.Speed = tmpSpeed;
  481. locData.Delay = tmpDelay;
  482. locData.Function = tmpFunction;
  483. dataLoc.Add(locData);
  484. }
  485. ResetListView(true);
  486. ResetTextBoxes();
  487. richTextBox_OutputView.Clear();
  488. richTextBox_OutputView.Text = "The waypoints have been reverse, added to the current list of waypoints, and the spawn path will now loop";
  489. ListviewLoad();
  490. }
  491. else
  492. {
  493. // Revert Changes if checkbox is unchecked
  494. int revertrowcount = rowCount / 2;
  495. int count = 0;
  496. while (count < revertrowcount)
  497. {
  498. count++;
  499. dataLoc.RemoveAt(rowNumber);
  500. rowNumber--;
  501. }
  502. ResetListView(true);
  503. ResetTextBoxes();
  504. richTextBox_OutputView.Clear();
  505. ListviewLoad();
  506. }
  507. }
  508. private void button_Save_Click(object sender, EventArgs e)
  509. {
  510. richTextBox_OutputView.Clear();
  511. DateTime dateTime = DateTime.Now;
  512. List<string> checkfunctions = new List<string>();
  513. DataStruct locData = dataLoc[rowNumber];
  514. string spawnName = locData.Name + ".lua";
  515. StreamWriter streamWriter = new StreamWriter(spawnName);
  516. string script = "--[[\n\tScript Name\t\t:\t" + spawnName + "\n\tScript Purpose\t:\tWaypoint Path for " + spawnName + "\n\tScript Author\t:\t" +
  517. locData.Author + "\n\tScript Date\t\t:\t" + dateTime.ToString("MM/dd/yyyy hh:mm:ss tt") + "\n\tScript Notes\t:\tLocations collected from Live\n--]]\n\n" +
  518. "function spawn(NPC)\n\twaypoints(NPC)\nend\n\nfunction hailed(NPC, Spawn)\n\tFaceTarget(NPC, Spawn)\nend\n\nfunction respawn(NPC)\n\tspawn(NPC)\nend\n\n" +
  519. "function waypoints(NPC)";
  520. streamWriter.WriteLine(script);
  521. for (int i = 0; i < dataLoc.Count; i++)
  522. {
  523. //rowNumber = i;
  524. locData = dataLoc[i];
  525. if (!String.IsNullOrEmpty(locData.Function.ToString()))
  526. {
  527. string output = " MovementLoopAddLocation(NPC, " + locData.XLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.YLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.ZLoc.ToString(CultureInfo.InvariantCulture) + ", " +
  528. locData.Speed + ", " + locData.Delay + ", " +
  529. "\"" + locData.Function.ToString() + "\")";
  530. streamWriter.WriteLine(output);
  531. }
  532. else
  533. {
  534. string output = " MovementLoopAddLocation(NPC, " + locData.XLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.YLoc.ToString(CultureInfo.InvariantCulture) + ", " + locData.ZLoc.ToString(CultureInfo.InvariantCulture) + ", " +
  535. locData.Speed + ", " + locData.Delay + ")";
  536. streamWriter.WriteLine(output);
  537. }
  538. }
  539. streamWriter.WriteLine("end\n\n");
  540. for (int i = 0; i < dataLoc.Count; i++)
  541. {
  542. //need to check for duplicates of the movement function
  543. locData = dataLoc[i];
  544. if (!String.IsNullOrEmpty(locData.Function.ToString()))
  545. {
  546. string movementfunctions = "function " + locData.Function.ToString() + "(NPC)\n\t Say(NPC, " + "\"" + "This is the " + locData.Function.ToString() + " function\"" + ")\nend";
  547. streamWriter.WriteLine(movementfunctions + "\n\n");
  548. }
  549. }
  550. streamWriter.Close();
  551. richTextBox_OutputView.Text = "Saved to " + spawnName + "";
  552. }
  553. private void button_Reset_Click(object sender, EventArgs e)
  554. {
  555. richTextBox_OutputView.Clear();
  556. ResetTextBoxes();
  557. DataStruct locData = dataLoc[rowNumber];
  558. richTextBox_OutputView.Text = "Cleared Textboxes";
  559. }
  560. private void button_ParseDetalis_Click(object sender, EventArgs e)
  561. {
  562. ParseData();
  563. ListviewLoad();
  564. }
  565. /*********************************************************************************************************************************
  566. * MENU ITEMS
  567. *********************************************************************************************************************************/
  568. private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
  569. {
  570. Application.Exit();
  571. }
  572. private void collectWaypointsToolStripMenuItem_Click(object sender, EventArgs e)
  573. {
  574. MessageBox.Show("Begin by using this line" + System.Environment.NewLine +
  575. System.Environment.NewLine +
  576. "/loc_start <name of spawn>" + System.Environment.NewLine +
  577. "Example: /loc_start a trained wolf" + System.Environment.NewLine +
  578. System.Environment.NewLine +
  579. "Use /loc at each point the spawn stops/turns to log location" + System.Environment.NewLine +
  580. System.Environment.NewLine +
  581. "Use /loc_speed to change the movement between waypoints" + System.Environment.NewLine +
  582. "Example: /loc_speed 4"+ System.Environment.NewLine +
  583. "to make spawn run from point to point" + System.Environment.NewLine +
  584. System.Environment.NewLine +
  585. "Use /loc_delay to pause at a waypoint. /loc_delay 3" + System.Environment.NewLine +
  586. "Example /loc_delay 3" + System.Environment.NewLine +
  587. "to make spawn pause for 3 seconds" + System.Environment.NewLine +
  588. System.Environment.NewLine +
  589. "End the session by using this line" + System.Environment.NewLine +
  590. "/loc_stop", "Collecting location Waypoints", MessageBoxButtons.OK, MessageBoxIcon.Information);
  591. }
  592. private void editinglogsToolStripMenuItem_Click(object sender, EventArgs e)
  593. {
  594. MessageBox.Show("Choose a line of waypoints in the list to work on" + System.Environment.NewLine +
  595. "Edit the values in the boxes on the bottom" + System.Environment.NewLine +
  596. System.Environment.NewLine +
  597. "Use the Update button to update the line" + System.Environment.NewLine +
  598. System.Environment.NewLine +
  599. "Add a new waypoint to the list by using the Insert Above or Insert Below buttons" + System.Environment.NewLine +
  600. "Add a function here if the spawns does something at a stop/turn" + System.Environment.NewLine +
  601. "Otherwise leave blank"+ System.Environment.NewLine +
  602. "Note: If a function is added it auto creates a new function in the script" + System.Environment.NewLine +
  603. "Once script is saved you can edit the function in an editor" + System.Environment.NewLine +
  604. System.Environment.NewLine +
  605. "Once you are finished click on the Parse button to save or edit", "Editing Locations", MessageBoxButtons.OK, MessageBoxIcon.Information);
  606. }
  607. private void loadingLogsToolStripMenuItem_Click(object sender, EventArgs e)
  608. {
  609. MessageBox.Show("Use the browse button in the generator to locate your log." + System.Environment.NewLine +
  610. "these are located in your EverQuest II->logs folder inside the folder of your live client." + System.Environment.NewLine +
  611. System.Environment.NewLine +
  612. "Double click your spawn from the list on the left" + System.Environment.NewLine +
  613. "You can use the Parse button as well" + System.Environment.NewLine +
  614. "Example a trained wolf" + System.Environment.NewLine +
  615. "Note: Change the default author under file menu" + System.Environment.NewLine +
  616. "File->Settings->Author and edit in the textbox" + System.Environment.NewLine +
  617. "Hit enter to save.", "Loading Logs", MessageBoxButtons.OK, MessageBoxIcon.Information);
  618. }
  619. // This loads the saved settings for Author into the toolStripTextBox
  620. private void authorToolStripMenuItem_MouseEnter(object sender, EventArgs e)
  621. {
  622. toolStripTextBox_Author.Text = Properties.Settings.Default.Author;
  623. }
  624. //Code for toolStripTextBoxAuthor Key Event set in the toolStripTextBoxAuthor Properties
  625. private void toolStripTextBoxAuthor_KeyDown(object sender, KeyEventArgs e)
  626. {
  627. if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
  628. {
  629. Properties.Settings.Default.Author = toolStripTextBox_Author.Text;
  630. Properties.Settings.Default.Save();
  631. userToolStripMenuItem.Text = Properties.Settings.Default.Author;
  632. e.Handled = true;
  633. e.SuppressKeyPress = true;
  634. fileToolStripMenuItem.HideDropDown(); // Hides the menu after enter key is pressed
  635. }
  636. }
  637. private void listBox_NPCs_MouseDoubleClick(object sender, MouseEventArgs e)
  638. {
  639. if (checkBox_ReversePath.Checked == true)
  640. {
  641. checkBox_ReversePath.Checked = false;
  642. }
  643. ParseData();
  644. ListviewLoad();
  645. int total_wapoints = dataLoc.Count;
  646. richTextBox_OutputView.Text = richTextBox_OutputView.Text + "\n\n\n" + total_wapoints + " Waypoints were loaded\n\nClick a waypoint to edit it in the boxes below";
  647. }
  648. private bool OpenFile(out FileStream fileStream)
  649. {
  650. fileStream = null;
  651. try
  652. {
  653. fileStream = new FileStream(this.textBox_LogFile.Text, FileMode.Open, FileAccess.Read, System.IO.FileShare.ReadWrite, 8, FileOptions.SequentialScan);
  654. return true;
  655. }
  656. catch (Exception ex)
  657. {
  658. LastErrMsg = ex.Message;
  659. LastExceptionMsg = ex;
  660. DisplayError();
  661. }
  662. return false;
  663. }
  664. public bool ReadLine(out String line)
  665. {
  666. bool val = false;
  667. line = "";
  668. FileStream fs = null;
  669. if (fileStream == null)
  670. {
  671. if (OpenFile(out fs))
  672. {
  673. String lineRead = "";
  674. val = ReadLineDown(-1, out lineRead);
  675. line = lineRead;
  676. CloseFile();
  677. }
  678. }
  679. else
  680. {
  681. String lineRead = "";
  682. val = ReadLineDown(-1, out lineRead);
  683. line = lineRead;
  684. CloseFile();
  685. }
  686. return val;
  687. }
  688. public bool OpenReadLine(out String line)
  689. {
  690. bool val = false;
  691. line = "";
  692. FileStream fs = null;
  693. if (fileStream == null)
  694. {
  695. if (OpenFile(out fs))
  696. {
  697. String lineRead = "";
  698. fileStream = fs;
  699. val = ReadLineDown(-1, out lineRead);
  700. line = lineRead;
  701. }
  702. }
  703. else
  704. {
  705. String lineRead = "";
  706. val = ReadLineDown(-1, out lineRead);
  707. line = lineRead;
  708. }
  709. return val;
  710. }
  711. private bool ReadLineDown(int locToStart, out String line)
  712. {
  713. line = "";
  714. try
  715. {
  716. byte[] dataToRead = new byte[256];
  717. bool firstRun = false;
  718. if (LastLengthLocation == -1)
  719. {
  720. firstRun = true;
  721. LastLengthLocation = 0;
  722. }
  723. if (fileStream.Position < LastLengthLocation)
  724. {
  725. fileStream.Position = LastLengthLocation;
  726. }
  727. else
  728. {
  729. fileStream.Position = LastLengthLocation;
  730. }
  731. String strToConstruct = "";
  732. while (true)
  733. {
  734. int dataRead = fileStream.Read(dataToRead, 0, dataToRead.Length);
  735. if (dataRead < 1)
  736. return false;
  737. String out_ = Encoding.UTF8.GetString(dataToRead, 0, dataRead);
  738. int firstIdx = out_.IndexOf(Environment.NewLine);
  739. if (firstIdx < 0)
  740. {
  741. strToConstruct += out_;
  742. LastLengthLocation += out_.Length;
  743. continue;
  744. }
  745. else
  746. {
  747. strToConstruct += out_.Substring(0, firstIdx);
  748. LastLengthLocation += (firstIdx + Environment.NewLine.Length);
  749. break;
  750. }
  751. }
  752. line = strToConstruct;
  753. return true;
  754. }
  755. catch (Exception ex)
  756. {
  757. LastErrMsg = ex.Message;
  758. LastExceptionMsg = ex;
  759. DisplayError();
  760. }
  761. return false;
  762. }
  763. public bool CloseFile()
  764. {
  765. try
  766. {
  767. if(fileStream != null)
  768. fileStream.Close();
  769. fileStream = null;
  770. return true;
  771. }
  772. catch (Exception ex)
  773. {
  774. LastErrMsg = ex.Message;
  775. LastExceptionMsg = ex;
  776. DisplayError();
  777. }
  778. return false;
  779. }
  780. public void DisplayError()
  781. {
  782. if (suppress)
  783. return;
  784. if (MessageBox.Show("Error Message: " + LastErrMsg + "\n\nWould you like to STOP being shown errors? Selecting YES means no errors will be shown until tool restart", "ERROR!", MessageBoxButtons.YesNo) ==
  785. DialogResult.Yes)
  786. suppress = true;
  787. }
  788. /*********************************************************************************************************************************
  789. * Notes
  790. *********************************************************************************************************************************/
  791. }
  792. }