Facebook
From szym, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 49
  1. new (function() {
  2.     var self = this;
  3.  
  4.     this.calculateDistance2D = function(p, q) {
  5.         var dx = p.x - q.x;        
  6.         var dy = p.y - q.y;        
  7.         var dist = Math.sqrt(dx*dx + dy*dy);
  8.         return dist;
  9.     };
  10.  
  11.     this.getOtherById = function(id) {
  12.         for (var i in g.other) {
  13.             if (g.other[i].id == id) {
  14.                 return g.other[i];
  15.             }
  16.         }
  17.         return false;
  18.     };
  19.  
  20.     this.isNearHero = function(other) {
  21.         if (!hero.x || !other.x) {
  22.             return true;
  23.         }
  24.         var p = {
  25.             x: hero.x,
  26.             y: hero.y
  27.         }
  28.         var x = {
  29.             x: other.x,
  30.             y: other.y
  31.         }
  32.         for (var n in g.npc) {
  33.             if(g.npc[n].wt > 79) {
  34.                 var q = {
  35.                     x: g.npc[n].x,
  36.                     y: g.npc[n].y
  37.                 }
  38.                 if (self.calculateDistance2D(p, q) <= 9 || self.calculateDistance2D(x, q) <= 9) {
  39.                     return true;
  40.                 }
  41.             }
  42.         }
  43.         return false;
  44.     };
  45.  
  46.     this.isBrutalPvpTime = function() {
  47.         var time = new Date().toLocaleString("en-US", {timeZone: "Europe/Warsaw"});
  48.         time = new Date(time);
  49.         let hours = time.getHours();
  50.         let mins = time.getMinutes();
  51.         if ((hours >= 23 || hours <= 6) && mins > 0) {
  52.             return true;
  53.         }
  54.         return false;
  55.     };
  56.  
  57.     this.canAttack = function(task) {
  58.         let args = task.split('&');
  59.         for (var i in args) {
  60.             if (args[i].startsWith("id")) {
  61.                 let otherArgs = args[i].split("=");
  62.                 if (!otherArgs[1].startsWith("-")) {
  63.                     let id = parseInt(otherArgs[1]);
  64.                     if (id) {
  65.                         let other = self.getOtherById(id);
  66.                         if (other.nick === undefined || hero.nick === undefined) {
  67.                             message("Wystąpił dziwny błąd w dodatku z blokadą ataku.");
  68.                             return false;
  69.                         }  
  70.                         if (g.party[hero.id] !== undefined && g.party[hero.id] != false) {
  71.                             message(`<span style="color: #ad0202;">Nie bij tej osoby jebany debilu!</span>`);
  72.                             return false;
  73.                         }
  74.                         let maxLevelAdvantage = self.isNearHero(other) ? 5 : 25;
  75.                         if ((other.lvl > hero.lvl) || (hero.lvl - other.lvl) <= maxLevelAdvantage) {
  76.                             return true;
  77.                         }
  78.                     }
  79.                 } else {
  80.                     return true;
  81.                 }
  82.             }
  83.         }
  84.         return false;
  85.     };
  86.  
  87.     (function(game) {
  88.         _g = function(a, d) {
  89.             if (a !== undefined && /fight&a=attack/.test(a)) {
  90.                 if (!self.isBrutalPvpTime() && !self.canAttack(a)) {
  91.                     message(`<span style="color: #ad0202;">Nie możesz zaatakować tej osoby!</span>`);
  92.                     return;
  93.                 }
  94.             }
  95.             game(a, d);
  96.         };
  97.     })(_g);
  98. })();