MonsterForm.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using Mir2Assistant.Common.Functions;
  2. using Mir2Assistant.Common.Models;
  3. using Mir2Assistant.Common.TabForms;
  4. using Mir2Assistant.Common.Utils;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace Mir2Assistant.TabForms.Demo.TabForms
  17. {
  18. /// <summary>
  19. /// 读怪,打怪
  20. /// </summary>
  21. [Order(3)]
  22. public partial class MonsterForm : Form, ITabForm
  23. {
  24. public MonsterForm()
  25. {
  26. InitializeComponent();
  27. }
  28. public string Title => "读怪、打怪";
  29. public MirGameInstanceModel? GameInstance { get; set; }
  30. private ObservableCollection<MonsterModel> monsters = new ObservableCollection<MonsterModel>();
  31. private ObservableCollection<SkillModel> skills = new ObservableCollection<SkillModel>();
  32. private void button1_Click(object sender, EventArgs e)
  33. {
  34. if (listBox1.SelectedItems.Count > 0)
  35. {
  36. var monster = listBox1.SelectedItems?[0] as MonsterModel;
  37. if (monster != null)
  38. {
  39. MonsterFunction.SlayingMonster(GameInstance!, monster.Addr);
  40. }
  41. }
  42. }
  43. private void MonsterForm_Load(object sender, EventArgs e)
  44. {
  45. //bindingSource1.DataSource = monsters;
  46. bindingSource2.DataSource = skills;
  47. listBox1.DataSource = bindingSource1;
  48. listBox1.DisplayMember = "Display";
  49. listBox2.DataSource = bindingSource2;
  50. listBox2.DisplayMember = "Display";
  51. }
  52. private void button2_Click(object sender, EventArgs e)
  53. {
  54. var memoryUtils = GameInstance!.MemoryUtils!;
  55. if (listBox1.SelectedItems.Count > 0)
  56. {
  57. var monster = listBox1.SelectedItems?[0] as MonsterModel;
  58. if (monster != null)
  59. {
  60. MonsterFunction.LockMonster(GameInstance!, monster.Addr);
  61. }
  62. }
  63. if (listBox2.SelectedItems.Count > 0)
  64. {
  65. var skill = listBox2.SelectedItems[0] as SkillModel;
  66. if (skill != null)
  67. {
  68. SkillFunction.SkillCall(GameInstance, skill.Addr!.Value);
  69. }
  70. }
  71. }
  72. private void timer1_Tick(object sender, EventArgs e)
  73. {
  74. var scrollOffset = listBox1.TopIndex;
  75. listBox1.BeginUpdate();
  76. bindingSource1.DataSource = GameInstance!.Monsters.Values.Where(o => o.TypeStr != "NPC").OrderBy(o => o.X).ThenBy(o => o.Y);
  77. listBox1.EndUpdate();
  78. //monsters.Clear();
  79. //foreach (var item in GameInstance!.Monsters.Values.Where(o => o.TypeStr != "NPC").OrderBy(o => o.X).ThenBy(o => o.Y))
  80. //{
  81. // monsters.Add(item);
  82. //}
  83. //bindingSource1.ResetBindings(false);
  84. listBox1.TopIndex = scrollOffset;
  85. if (skills.Count != GameInstance.Skills.Count)
  86. {
  87. skills.Clear();
  88. foreach (var item in GameInstance!.Skills)
  89. {
  90. skills.Add(item);
  91. }
  92. bindingSource2.ResetBindings(false);
  93. }
  94. }
  95. private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
  96. {
  97. e.DrawBackground();
  98. var name = (listBox1.Items[e.Index] as MonsterModel)?.Name;
  99. var text = (listBox1.Items[e.Index] as MonsterModel)?.Display;
  100. if (name == "沙漠霸主")
  101. {
  102. e.Graphics.DrawString(text, e.Font, Brushes.Red, e.Bounds);
  103. }
  104. else
  105. {
  106. e.Graphics.DrawString(text, e.Font, Brushes.Black, e.Bounds);
  107. }
  108. }
  109. }
  110. }