GuildItemForm.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. using Server.MirObjects;
  2. using Server.MirObjects.Monsters;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. namespace Server.Systems
  13. {
  14. public partial class GuildItemForm : Form
  15. {
  16. public GuildObject Guild { get; set; }
  17. public string GuildName;
  18. public SMain main;
  19. public GuildItemForm()
  20. {
  21. InitializeComponent();
  22. this.Load += GuildItemForm_Load;
  23. }
  24. #region Load Guild Notice
  25. public void SetGuildNotice(List<string> notice)
  26. {
  27. GuildNoticeBox.Text = string.Join(Environment.NewLine, notice);
  28. }
  29. #endregion
  30. #region Load Member Count
  31. public void SetMemberCount(int memberCount, int memberCap)
  32. {
  33. MemberCountLabel.Text = $"Members: {memberCount}/{memberCap}";
  34. }
  35. #endregion
  36. #region Load Guild Points
  37. public void SetGuildPoints(byte sparePoints)
  38. {
  39. GuildPointsLabel.Text = $"Points: {sparePoints}";
  40. }
  41. #endregion
  42. #region Load Guild EXP
  43. public void SetGuildExperience(long experience)
  44. {
  45. GuildEXPLabel.Text = $"EXP: {experience}";
  46. }
  47. #endregion
  48. #region Load Guild Ranks
  49. public void SetGuildRanks(List<GuildRank> ranks)
  50. {
  51. GuildRanksListView.Items.Clear();
  52. foreach (var rank in ranks)
  53. {
  54. ListViewItem item = new ListViewItem(rank.Name);
  55. GuildRanksListView.Items.Add(item);
  56. }
  57. }
  58. #endregion
  59. #region Load Guild Chat
  60. public void LoadGuildChat()
  61. {
  62. if (main == null || Guild == null) return;
  63. GuildChatBox.Clear();
  64. string[] chatLogLines = main.ChatLogTextBox.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
  65. foreach (var line in chatLogLines)
  66. {
  67. if (line.Contains($"SYSTEM to Guild: '{GuildName}':"))
  68. {
  69. GuildChatBox.AppendText(line + Environment.NewLine);
  70. continue;
  71. }
  72. int guildMessageIndex = line.IndexOf(": !~");
  73. if (guildMessageIndex > -1)
  74. {
  75. int playerNameStart = line.IndexOf("]: ") + 3;
  76. int playerNameEnd = line.IndexOf(":", playerNameStart);
  77. if (playerNameStart > 0 && playerNameEnd > playerNameStart)
  78. {
  79. string playerName = line.Substring(playerNameStart, playerNameEnd - playerNameStart).Trim();
  80. if (Guild.Ranks.Any(rank => rank.Members.Any(member => member.Name == playerName)))
  81. {
  82. GuildChatBox.AppendText(line + Environment.NewLine);
  83. }
  84. }
  85. }
  86. }
  87. }
  88. #endregion
  89. #region Buff List
  90. public void SetBuffList(List<GuildBuff> activeBuffs, List<GuildBuffInfo> allBuffInfos)
  91. {
  92. BuffListView.Items.Clear();
  93. // Dictionary to quickly check if a buff is active
  94. var activeBuffsById = activeBuffs.ToDictionary(buff => buff.Id);
  95. foreach (var buffInfo in allBuffInfos)
  96. {
  97. ListViewItem item = new ListViewItem(buffInfo.Id.ToString());
  98. // Display the name of the buff
  99. item.SubItems.Add(buffInfo.Name);
  100. // Check if this buff is active
  101. if (activeBuffsById.TryGetValue(buffInfo.Id, out GuildBuff activeBuff))
  102. {
  103. // Buff is active
  104. item.SubItems.Add("Active");
  105. item.SubItems.Add(activeBuff.ActiveTimeRemaining.ToString());
  106. }
  107. else
  108. {
  109. // Buff is inactive
  110. item.SubItems.Add("Inactive");
  111. item.SubItems.Add("0"); // No time remaining for inactive buff
  112. }
  113. BuffListView.Items.Add(item);
  114. }
  115. }
  116. #endregion
  117. #region Delete Button
  118. private void DeleteButton_Click(object sender, EventArgs e)
  119. {
  120. if (MemberListView == null) return;
  121. if (MemberListView.SelectedItems == null) return;
  122. Server.MirObjects.GuildObject Guild = SMain.Envir.GetGuild(GuildName);
  123. if (Guild == null) return;
  124. foreach (var m in MemberListView.SelectedItems)
  125. {
  126. var lm = (ListViewItem)m;
  127. Guild.DeleteMember(lm.SubItems[0].Text);
  128. MemberListView.Items.Remove(lm);
  129. main.ProcessGuildViewTab();
  130. break;
  131. }
  132. }
  133. #endregion
  134. #region Update Guild Notice
  135. private void RefreshNoticeButton_Click(object sender, EventArgs e)
  136. {
  137. var guild = SMain.Envir.GetGuild(GuildName);
  138. if (guild == null) return;
  139. List<string> newNotice = GuildNoticeBox.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None).ToList();
  140. // Log the guild notice update
  141. string noticeUpdateLog = $"Guild: '{GuildName}' notice changed by SYSTEM.";
  142. SMain.EnqueueChat(noticeUpdateLog);
  143. Logger.GetLogger(LogType.Server).Info(noticeUpdateLog);
  144. guild.NewNotice(newNotice);
  145. SetGuildNotice(guild.Info.Notice);
  146. }
  147. #endregion
  148. #region Send Guild Message
  149. private void SendGuildMessageButton_Click(object sender, EventArgs e)
  150. {
  151. var guild = SMain.Envir.GetGuild(GuildName);
  152. if (guild == null) return;
  153. string message = SendGuildMesageBox.Text.Trim();
  154. if (string.IsNullOrEmpty(message)) return;
  155. guild.SendMessage($"SYSTEM: {message}", ChatType.Guild);
  156. string timestamp = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
  157. GuildChatBox.AppendText($"[{timestamp}]: SYSTEM: {message}" + Environment.NewLine);
  158. string logMessage = $"SYSTEM to Guild: '{GuildName}': {message}";
  159. SMain.EnqueueChat(logMessage);
  160. SendGuildMesageBox.Clear();
  161. }
  162. #endregion
  163. #region Load Form
  164. private void GuildItemForm_Load(object sender, EventArgs e)
  165. {
  166. LoadGuildChat();
  167. }
  168. #endregion
  169. }
  170. }