SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cmd.hear(/^(?:бой)$/i, async (message) => {
  2. let users = await User.find({})
  3.  
  4. if(users.length < 2) return message.send("Недостаточно игроков для проведения игры!")
  5. let ctx = message
  6. const { createCanvas, loadImage } = require('canvas');
  7. const canvas = createCanvas(750, 600);
  8. const img = await loadImage('cit.png')
  9. const ctxx = canvas.getContext('2d');
  10. ctxx.drawImage(img, 0, 0, 800, 600);
  11.  
  12. const spaceship1 = await loadImage(`./canvas/spaceshipgreen.png`)
  13. const spaceship2 = await loadImage(`./canvas/spaceshipred.png`)
  14. const spaceship3 = await loadImage(`./canvas/spaceshipturbo.png`)
  15. const spaceship4 = await loadImage(`./canvas/spaceshipturbo2.png`)
  16. let target = users.filter(x=>x.id != message.senderId).sort(() => {
  17. return 0.5 - Math.random();
  18. })
  19.  
  20. let km = utils.random(3, 10);
  21. if(!target) return message.send("Противник не найден!")
  22. // if(message.user.balance<km * 10000) return message.send("У Вас недостаточно средств для проведения боя!")
  23. // if(target.balance<km * 10000) return message.send("У противника недостаточно средств для проведения боя!")
  24. if(utils.random(0,1) > 0) {
  25. await message.user.dec("balance", 5);
  26. if(message.user.spaceship == 1) {
  27. ctxx.drawImage(spaceship1, 350, 180, 500, 550);
  28. }
  29. } else if(message.user.spaceship == 2) {
  30. ctxx.drawImage(spaceship2, 350, 180, 500, 550);
  31.  
  32. } else if(message.user.spaceship == 3) {
  33. ctxx.drawImage(spaceship3, 350, 180, 500, 550);
  34.  
  35. } else if(message.user.spaceship == 4) {
  36. ctxx.drawImage(spaceship4, 350, 180, 500, 550);
  37. ctxx.drawImage(img, 0, 0, 1280, 720);
  38. ctxx.font = 'bold 23px sans, serif';
  39. ctxx.fillText(`❗ Вы проиграли гонку!\nВы отдали сопернику (${target.tag}) : ${utils.spaces(5)}₽ `, 48, 558);
  40. }
  41.  
  42. await message.user.inc("balance", km * 10000)
  43. await target.dec("balance",km * 10000)
  44. ctxx.drawImage(img, 0, 0, 1280, 720);
  45. if(users.spaceship == 1) {
  46. ctxx.drawImage(spaceship1, 350, 180, 500, 550);
  47. } else if(message.user.spaceship == 2) {
  48. ctxx.drawImage(spaceship2, 350, 180, 500, 550);
  49.  
  50. } else if(message.user.spaceship == 3) {
  51. ctxx.drawImage(spaceship3, 350, 180, 500, 550);
  52. } else if(message.user.spaceship == 4) {
  53. ctxx.drawImage(spaceship4, 350, 180, 500, 550);
  54. ctx.font = '23px Ubuntu';
  55. ctx.fillStyle = '#FFF';
  56. ctx.fillText(`Вы одержали победу!
  57. Ваш соперник (${target.tag}) дал вам ${utils.spaces(km * 1000000)}₽`, 48, 594);
  58.  
  59. return ctx.sendPhoto({
  60. value: canvas.toBuffer()
  61.  
  62. })
  63. }
  64. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top