new (function() { var self = this; this.calculateDistance2D = function(p, q) { var dx = p.x - q.x; var dy = p.y - q.y; var dist = Math.sqrt(dx*dx + dy*dy); return dist; }; this.getOtherById = function(id) { for (var i in g.other) { if (g.other[i].id == id) { return g.other[i]; } } return false; }; this.isNearHero = function(other) { if (!hero.x || !other.x) { return true; } var p = { x: hero.x, y: hero.y } var x = { x: other.x, y: other.y } for (var n in g.npc) { if(g.npc[n].wt > 79) { var q = { x: g.npc[n].x, y: g.npc[n].y } if (self.calculateDistance2D(p, q) <= 9 || self.calculateDistance2D(x, q) <= 9) { return true; } } } return false; }; this.isBrutalPvpTime = function() { var time = new Date().toLocaleString("en-US", {timeZone: "Europe/Warsaw"}); time = new Date(time); let hours = time.getHours(); let mins = time.getMinutes(); if ((hours >= 23 || hours <= 6) && mins > 0) { return true; } return false; }; this.canAttack = function(task) { let args = task.split('&'); for (var i in args) { if (args[i].startsWith("id")) { let otherArgs = args[i].split("="); if (!otherArgs[1].startsWith("-")) { let id = parseInt(otherArgs[1]); if (id) { let other = self.getOtherById(id); if (other.nick === undefined || hero.nick === undefined) { message("Wystąpił dziwny błąd w dodatku z blokadą ataku."); return false; } if (g.party[hero.id] !== undefined && g.party[hero.id] != false) { message(`Nie bij tej osoby jebany debilu!`); return false; } let maxLevelAdvantage = self.isNearHero(other) ? 5 : 25; if ((other.lvl > hero.lvl) || (hero.lvl - other.lvl) <= maxLevelAdvantage) { return true; } } } else { return true; } } } return false; }; (function(game) { _g = function(a, d) { if (a !== undefined && /fight&a=attack/.test(a)) { if (!self.isBrutalPvpTime() && !self.canAttack(a)) { message(`Nie możesz zaatakować tej osoby!`); return; } } game(a, d); }; })(_g); })();