Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const names = ["Gvar Hamryd", "Rozlewisko Kai"];
- const _newNpc = window.newNpc;
- window.newNpc = function (npcs) {
- if (npcs !== undefined) {
- for (const npc of Object.values(npcs)) {
- if (names.includes(npc.nick)) {
- createFakeGateways(npc);
- }
- }
- }
- _newNpc.apply(this, arguments);
- }
- const _send = window._g;
- window._g = function (url) {
- if (url === "walk") {
- const {x, y} = window.hero;
- if (isFakeGatewayAtPosition(x, y)) {
- window.hero.autoWalkLock = true;
- url = `talk&id=${getFakeGatewayId(x, y)}`;
- }
- }
- _send.apply(this, arguments);
- }
- function createFakeGateways(npc) {
- const nearbyNodes = getNearbyNodes(npc.x, npc.y);
- for (const [x, y] of nearbyNodes) {
- craeteElementAtPosition(npc.nick, npc.id, x, y);
- setFakeGateway(npc.nick, npc.id, x, y);
- }
- }
- function getNearbyNodes(x, y) {
- const nodes = [];
- for (let i = y - 1; i <= y + 1; i++) {
- for (let j = x - 1; j <= x + 1; j++) {
- if (!isNodeBlockedAtPosition(j, i)) {
- nodes.push([j, i]);
- }
- }
- }
- return nodes;
- }
- function isNodeBlockedAtPosition(x, y) {
- if (x === undefined || y === undefined) return true;
- if (x < 0 || x > window.map.x || y < 0 || y > window.map.y) return true;
- return window.map.col[y * window.map.x + x] !== "0";
- }
- function craeteElementAtPosition(name, id, x, y) {
- const gw = document.createElement("div");
- gw.classList.add("gw");
- gw.classList.add("gwmap");
- gw.id = "gw" + id;
- gw.style.left = `${x * 32}px`;
- gw.style.top = `${y * 32}px`;
- gw.tip = name + "1";
- gw.addEventListener("click", e => window.hero.mClick(e));
- document.querySelector("#base").appendChild(gw);
- }
- function setFakeGateway(name, id, x, y) {
- const position = `${x}.${y}`;
- window.g.gwIds[id] = position;
- window.g.townname[id] = name + "1";
- window.g.gw[position] = 69;
- }
- function isFakeGatewayAtPosition(x, y) {
- const position = `${x}.${y}`;
- if (window.g.gw[position] && window.g.gw[position] === 69) return true;
- return false;
- }
- function getFakeGatewayId(x, y){
- const position = `${x}.${y}`;
- for(const [id, pos] of Object.entries(window.g.gwIds)){
- if(pos === position) return id;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement