Facebook
From toprak, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 155
  1. const Discord = require('discord.js');
  2. const { stripIndents } = require('common-tags');
  3. const { randomRange, verify } = require('../util/Util.js');
  4.  
  5. exports.run = async (client, message, args) => {
  6.  
  7.   this.fighting = new Set();
  8.  
  9.         let opponent = message.mentions.users.first()
  10.         if (!opponent) return message.reply("Oynamak istediğin kişiyi etiketlemelisin!")
  11.  
  12.   if (opponent.bot) return message.reply('Botlar ile oynayamazsın!');
  13.   if (opponent.id === message.author.id) return message.reply('Kendin ile düello atamazsın!');
  14.                 if (this.fighting.has(message.channel.id)) return message.reply('Kanal başına sadece bir düello meydana gelebilir.');
  15.                 this.fighting.add(message.channel.id);
  16.                 try {
  17.                         if (!opponent.bot) {
  18.                 await message.channel.send(`${opponent}, düello isteği geldi. Düello'yu kabul ediyor musun? (\`evet\` veya \`hayır\` olarak cevap veriniz.)`);
  19.                                 const verification = await verify(message.channel, opponent);
  20.                                 if (!verification) {
  21.                                         this.fighting.delete(message.channel.id);
  22.                                         return message.channel.send(`Düello kabul edilmedi...`);
  23.                                 }
  24.                         }
  25.                         let userHP = 500;
  26.                         let oppoHP = 500;
  27.                         let userTurn = false;
  28.                         let guard = false;
  29.                         const reset = (changeGuard = true) => {
  30.                                 userTurn = !userTurn;
  31.                                 if (changeGuard && guard) guard = false;
  32.                         };
  33.                         const dealDamage = damage => {
  34.                                 if (userTurn) oppoHP -= damage;
  35.                                 else userHP -= damage;
  36.                         };
  37.                         const forfeit = () => {
  38.                                 if (userTurn) userHP = 0;
  39.                                 else oppoHP = 0;
  40.                         };
  41.                         while (userHP > 0 && oppoHP > 0) { // eslint-disable-line no-unmodified-loop-condition
  42.                                 const user = userTurn ? message.author : opponent;
  43.                                 let choice;
  44.                                 if (!opponent.bot || (opponent.bot && userTurn)) {
  45.                                         await message.channel.send(stripIndents`
  46.                                                 ${user}, ne yapmak istersin? \`saldır\`, \`savun\`, \`ultra güç\`, veya \`kaç\`?
  47.                                                 **${message.author.username}**: ${userHP} :heartpulse:
  48.                                                 **${opponent.username}**: ${oppoHP} :heartpulse:
  49.                                         `);
  50.                                         const filter = res =>
  51.                                                 res.author.id === user.id && ['saldır', 'savun', 'ultra güç', 'kaç'].includes(res.content.toLowerCase());
  52.                                         const turn = await message.channel.awaitMessages(filter, {
  53.                                                 max: 1,
  54.                                                 time: 30000
  55.                                         });
  56.                                         if (!turn.size) {
  57.                                                 await message.reply(`Üzgünüm ama, süre doldu!`);
  58.                                                 reset();
  59.                                                 continue;
  60.                                         }
  61.                                         choice = turn.first().content.toLowerCase();
  62.                                 } else {
  63.                                         const choices = ['saldır', 'savun', 'ultra güç'];
  64.                                         choice = choices[Math.floor(Math.random() * choices.length)];
  65.                                 }
  66.                                 if (choice === 'saldır') {
  67.                                         const damage = Math.floor(Math.random() * (guard ? 10 : 100)) + 1;
  68.                                         await message.channel.send(`${user}, **${damage}** hasar vurdu!`);
  69.                                         dealDamage(damage);
  70.                                         reset();
  71.                                 } else if (choice === 'savun') {
  72.                                         await message.channel.send(`${user}, kendisini süper kalkan ile savundu!`);
  73.                                         guard = true;
  74.                                         reset(false);
  75.                                 } else if (choice === 'ultra güç') {
  76.                                         const miss = Math.floor(Math.random() * 4);
  77.                                         if (!miss) {
  78.                                                 const damage = randomRange(100, guard ? 150 : 300);
  79.                                                 await message.channel.send(`${user}, Çoook uzak galaksilerden gelen ultra sonik enerjiyi yeterki miktarda topladın ve **${damage}** hasar vurdun!!`);
  80.                                                 dealDamage(damage);
  81.                                         } else {
  82.                                                 await message.channel.send(`${user}, Çoook uzak galaksilerden gelen ultra sonik enerjiyi yeterli miktarda toplayamadığın için ulta güç kullanamadın!`);
  83.                                         }
  84.                                         reset();
  85.                                 } else if (choice === 'kaç') {
  86.                                         await message.channel.send(`${user}, kaçtı! Korkak!`);
  87.                                         forfeit();
  88.                                         break;
  89.                                 } else {
  90.                                         await message.reply('Ne yapmak istediğini anlamadım.');
  91.                                 }
  92.                         }
  93.                         this.fighting.delete(message.channel.id);
  94.             const winner = userHP > oppoHP ? message.author : opponent;
  95.                         return message.channel.send(`Oyun bitti! Tebrikler, **${winner}** kazandı! \n**${message.author.username}**: ${userHP} :heartpulse: \n**${opponent.username}**: ${oppoHP} :heartpulse:`);
  96.                 } catch (err) {
  97.                         this.fighting.delete(message.channel.id);
  98.                         throw err;
  99.                 }
  100.   }
  101.  
  102.  
  103.  
  104. exports.conf = {
  105.   enabled: true,
  106.   guildOnly: false,
  107.   aliases: [],
  108.   permLevel: 0,
  109.      kategori: "Eğlence"
  110.  
  111. };
  112.  
  113. exports.help = {
  114.   name: 'düello',
  115.   category: "eğlence",
  116.   description: 'İstediğiniz bir kişi ile düello atarsınız!',
  117.   usage: 'düello <@kullanıcı>'
  118. };
  119.