ModuleEquip.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using System.Collections.Generic;
  2. using pomelo.item;
  3. using ZeusBattleClientBot;
  4. using pomelo.area;
  5. using pomelo.connector;
  6. using CommonLang.Reflection;
  7. namespace ZeusBotTest.Runner
  8. {
  9. public class ModuleEquip : BotRunner.RunnerModule
  10. {
  11. List<Grid> Equips;
  12. List<Grid> Bags;
  13. int pro;
  14. int upLevel;
  15. Dictionary<int, string> proTable;
  16. Dictionary<string, ItemDetail> ItemDetails;
  17. Dictionary<string, int> equipPosition;
  18. bool isFirstBind = true;
  19. public ModuleEquip(BotRunner r) : base(r)
  20. {
  21. proTable = new Dictionary<int, string>();
  22. ItemDetails = new Dictionary<string, ItemDetail>();
  23. equipPosition = new Dictionary<string, int>();
  24. this.proTable[1] = "狂战士";
  25. this.proTable[2] = "刺客";
  26. this.proTable[3] = "魔法师";
  27. this.proTable[4] = "猎人";
  28. this.proTable[5] = "牧师";
  29. this.equipPosition["主手"] = 1;
  30. this.equipPosition["副手"] = 2;
  31. this.equipPosition["头部"] = 3;
  32. this.equipPosition["上衣"] = 4;
  33. this.equipPosition["腿部"] = 5;
  34. this.equipPosition["腰部"] = 6;
  35. this.equipPosition["手套"] = 7;
  36. this.equipPosition["鞋子"] = 8;
  37. this.equipPosition["勋章"] = 9;
  38. this.equipPosition["项链"] = 10;
  39. this.equipPosition["戒指"] = 11;
  40. this.equipPosition["护身符"] = 12;
  41. client.GameSocket.listen<BagItemUpdatePush>(on_item_update);
  42. client.GameSocket.listen<EquipmentSimplePush>(on_equip_update);
  43. client.GameSocket.listen<ItemDetailPush>(on_item_detail_update);
  44. }
  45. protected internal override void OnGateBindPlayer(BindPlayerResponse e)
  46. {
  47. base.OnGateBindPlayer(e);
  48. Equips = e.s2c_player.equipments.equips;
  49. Bags = e.s2c_player.store.bag.bagGrids;
  50. pro = e.s2c_player.pro;
  51. upLevel = 0;
  52. try_get_all_equip_detail();
  53. if (isFirstBind)
  54. {
  55. runner.do_gm_add_item();
  56. runner.do_gm_add_gold(99999999);
  57. isFirstBind = false;
  58. }
  59. }
  60. protected internal override void OnBattleActorReady(CommonAI.ZoneClient.ZoneLayer layer, CommonAI.ZoneClient.ZoneActor actor)
  61. {
  62. layer.AddTimeDelayMS(Config.CheckIntervalMS, (t) =>
  63. {
  64. if (Enable)
  65. {
  66. }
  67. });
  68. layer.AddTimePeriodicMS(Config.CheckIntervalMS, (t) =>
  69. {
  70. if (Enable)
  71. {
  72. try_equip();
  73. //try_un_equip();
  74. try_equip_melt();
  75. }
  76. });
  77. }
  78. private void try_get_all_equip_detail()
  79. {
  80. client.GameSocket.itemHandler.getAllEquipDetailsRequest(
  81. (err, rsp) =>
  82. {
  83. foreach (var item in rsp.s2c_items)
  84. {
  85. ItemDetails[item.id] = item;
  86. }
  87. });
  88. }
  89. private void try_un_equip()
  90. {
  91. int randValue = bot.Random.Next(0, Equips.Count - 1);
  92. client.GameSocket.equipHandler.unEquipRequest(
  93. Equips[randValue].gridIndex, (err, rsp) =>
  94. { });
  95. }
  96. private void try_equip()
  97. {
  98. foreach (var bag in Bags)
  99. {
  100. if (bag.item.itemType < 1 || bag.item.itemType > 4) continue;
  101. object qc;
  102. int qid;
  103. Dictionary<string, object> template = BotClientManager.GetItemTemplate(bag.item.code);
  104. if (!template.TryGetValue("Pro", out qc) || proTable[pro] != qc.ToString()) continue;
  105. if (!template.TryGetValue("UpReq", out qc) || !int.TryParse(qc.ToString(), out qid) || (qid > 0 && qid > upLevel)) continue;
  106. ItemDetail ItemDetail = ItemDetails[bag.item.id];
  107. if (null == ItemDetail) continue;
  108. if (null == ItemDetail.equipDetail) continue;
  109. if (0 == ItemDetail.equipDetail.isIdentfied) continue;
  110. if (!template.TryGetValue("Type", out qc)) continue;
  111. //武器不用换
  112. if (equipPosition[qc.ToString()] == 1) continue;
  113. Item equip = get_equip_by_pos(equipPosition[qc.ToString()]);
  114. if(null != equip)
  115. {
  116. ItemDetail equipDetail = ItemDetails[equip.id];
  117. if(null != equipDetail && ItemDetail.equipDetail.score < equipDetail.equipDetail.score)
  118. {
  119. continue;
  120. }
  121. }
  122. client.GameSocket.equipHandler.equipRequest(
  123. bag.gridIndex, (err, rsp) =>
  124. { });
  125. }
  126. }
  127. private void on_item_update(BagItemUpdatePush e)
  128. {
  129. foreach (var i in e.s2c_data)
  130. {
  131. foreach (var bag in Bags)
  132. {
  133. if (i.gridIndex == bag.gridIndex)
  134. {
  135. bag.item = i.item;
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. private void on_equip_update(EquipmentSimplePush e)
  142. {
  143. foreach (var i in e.s2c_data)
  144. {
  145. foreach (var equip in Equips)
  146. {
  147. if (i.gridIndex == equip.gridIndex)
  148. {
  149. equip.item = i.item;
  150. break;
  151. }
  152. }
  153. }
  154. }
  155. private void on_item_detail_update(ItemDetailPush e)
  156. {
  157. foreach (var i in e.s2c_data)
  158. {
  159. ItemDetails[i.id] = i;
  160. }
  161. }
  162. private Item get_equip_by_pos(int pos)
  163. {
  164. foreach (var equip in Equips)
  165. {
  166. if(equip.gridIndex == pos)
  167. {
  168. return equip.item;
  169. }
  170. }
  171. return null;
  172. }
  173. private void try_equip_melt()
  174. {
  175. List<int> indexs = new List<int>();
  176. foreach (var bag in Bags)
  177. {
  178. if (bag.item.itemType < 1 || bag.item.itemType > 4) continue;
  179. object qc;
  180. int qid;
  181. Dictionary<string, object> template = BotClientManager.GetItemTemplate(bag.item.code);
  182. if (!template.TryGetValue("NoMelt", out qc) || !int.TryParse(qc.ToString(), out qid) || (qid == 1)) continue;
  183. indexs.Add(bag.gridIndex);
  184. }
  185. client.GameSocket.equipHandler.equipMeltRequest(
  186. indexs, (err, rsp) =>
  187. { });
  188. }
  189. [Desc("装备配置")]
  190. [Expandable]
  191. public class Config
  192. {
  193. [Desc("装备检测间隔")]
  194. public static int CheckIntervalMS = 5000;
  195. public override string ToString()
  196. {
  197. return "装备配置";
  198. }
  199. }
  200. }
  201. }