ChatFunc.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using pomelo.connector;
  7. using CommonLang.Property;
  8. using pomelo.area;
  9. using SimpleJson;
  10. namespace XmdsBotTest.Runner
  11. {
  12. public class ChatFunc : BotRunner.RunnerModule
  13. {
  14. private pomelo.player.Player player;
  15. public ChatFunc() {
  16. module_name = "聊天";
  17. }
  18. public ChatFunc(BotRunner r) : base(r)
  19. {
  20. }
  21. protected internal override void OnGateBindPlayer(BindPlayerResponse e)
  22. {
  23. base.OnGateBindPlayer(e);
  24. player = e.s2c_player;
  25. }
  26. protected internal override void OnBattleActorReady(CommonAI.ZoneClient.ZoneLayer layer, CommonAI.ZoneClient.ZoneActor actor)
  27. {
  28. layer.AddTimeDelayMS(Config.CheckIntervalMS, (t) =>
  29. {
  30. if (Enable)
  31. {
  32. }
  33. });
  34. layer.AddTimePeriodicMS(Config.CheckIntervalMS, (t) =>
  35. {
  36. if (Enable)
  37. {
  38. sendChatRequest();
  39. }
  40. });
  41. }
  42. private static string[] chats = new string[]
  43. {
  44. "游戏很好玩!",
  45. "有个同名电视剧吧",
  46. "良心作品",
  47. "好样的,加油。。。",
  48. "加个朋友吧|<q {\"index\":5}></q>|",
  49. "你说什么|<q {\"index\":15}></q>|"
  50. };
  51. private static Random random = new Random();
  52. private void sendChatRequest()
  53. {
  54. JsonObject json = new JsonObject();
  55. json.Add("acceptRoleId", "");
  56. json.Add("s2c_color", 3723689983);
  57. json.Add("s2c_isAtAll", 0);
  58. json.Add("s2c_level", player.level);
  59. json.Add("s2c_name",player.name);
  60. json.Add("s2c_pro",player.pro);
  61. json.Add("s2c_titleMsg", "");
  62. json.Add("s2c_vip", player.vip);
  63. json.Add("s2c_zoneId", player.zoneId);
  64. string msg = null;
  65. if (random.Next(100) < 30)
  66. {
  67. msg = "|<q {\"index\":" + random.Next(35) + "}></q>||<q {\"index\":" + random.Next(35) + "}></q>||<q {\"index\":" + random.Next(35) + "}></q>|";
  68. }
  69. else
  70. {
  71. msg = chats[random.Next(chats.Length)];
  72. }
  73. //client.GameSocket.chatHandler.sendChatRequest(1, msg, json.ToString(),"",
  74. // (err, rsp) =>
  75. // { });
  76. }
  77. [Desc("聊天测试配置")]
  78. [Expandable]
  79. public class Config : ConfigBase
  80. {
  81. [Desc("聊天测试检测间隔")]
  82. public static int CheckIntervalMS = 30000;
  83. public override string ToString()
  84. {
  85. return "聊天配置";
  86. }
  87. public override void popG2DPropertyDialog()
  88. {
  89. CommonFroms.G2D.G2DPropertyDialog<ChatFunc.Config>.Show("修改配置", this);
  90. }
  91. }
  92. }
  93. }