index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const MWABOX = 166901
  2. module.exports = function mwaBoxOpener(dispatch){
  3. let cid = null,
  4. enabled = false,
  5. location = null,
  6. timer = null,
  7. inventory = null;
  8. dispatch.hook('S_LOGIN', 1, event =>{cid = event.cid})
  9. dispatch.hook('C_PLAYER_LOCATION', 1, event =>{location = event})
  10. dispatch.hook('C_CHAT', 1, event => {
  11. if(/^<FONT>!mwa<\/FONT>$/i.test(event.message)) {
  12. if(enabled = !enabled) {
  13. message(' MWA box opener started.')
  14. timer = setInterval(openBox,200)
  15. }
  16. else
  17. stop()
  18. return false
  19. }
  20. })
  21. dispatch.hook('S_INVEN', 3, event =>{
  22. if(!enabled) return
  23. if(event.first) inventory = []
  24. else if(!inventory) return
  25. for(let item of event.items) inventory.push(item)
  26. if(!event.more) {
  27. let box = false
  28. for(let item of inventory) {
  29. if(item.slot < 40) continue
  30. if(item.item == MWABOX) box = true
  31. }
  32. if(!box) stop()
  33. inventory = null
  34. }
  35. })
  36. function openBox() {
  37. dispatch.toServer('C_USE_ITEM', 1, {
  38. ownerId: cid,
  39. item: MWABOX,
  40. id: 0,
  41. unk1: 0,
  42. unk2: 0,
  43. unk3: 0,
  44. unk4: 1,
  45. unk5: 0,
  46. unk6: 0,
  47. unk7: 0,
  48. x: location.x1,
  49. y: location.y1,
  50. z: location.z1,
  51. w: location.w,
  52. unk8: 0,
  53. unk9: 0,
  54. unk10: 0,
  55. unk11: 1
  56. })
  57. dispatch.toServer('C_GACHA_TRY', 1,{
  58. id:385851
  59. })
  60. }
  61. function stop() {
  62. clearInterval(timer)
  63. enabled = false
  64. inventory = null
  65. message(' MWA box opener stopped.')
  66. }
  67. function message(msg) {
  68. dispatch.toClient('S_CHAT', 1, {
  69. channel: 24,
  70. authorID: 0,
  71. unk1: 0,
  72. gm: 0,
  73. unk2: 0,
  74. authorName: '',
  75. message: '(Proxy)' + msg
  76. })
  77. }
  78. }