ModuleEquip.cs 7.7 KB

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