TWeaker

Some little tweaks to game The-West

目前为 2015-01-16 提交的版本。查看 最新版本

// ==UserScript==
// @name TWeaker
// @namespace TomRobert
// @author Vbyec (updated by Tom Robert)
// @description Some little tweaks to game The-West
// @include http://*.the-west.*/game.php*
// @version 0.1.8
// @nocompat Chrome
// @grant none
//
// @history	0.1.4 Add Kick-o-matic autoload
// @history	0.1.5 Add English
// @history	0.1.6 Add Items controls and search
// @history 0.1.7 Add Spanish (pepe100)
// @history 0.1.8 Add German (Tom Robert), remove Kick-o-matic autoload
// ==/UserScript==
function exec(fn) {
  var script = document.createElement('script');
  script.setAttribute('type', 'application/javascript');
  script.textContent = '(' + fn + ')();';
  document.body.appendChild(script); // run the script
  document.body.removeChild(script); // clean up
}
exec(function () {
  Tweaker = {
    'scriptName': 'Tweaker',
    'author': 'Vbyec (updated by Tom Robert)',
    'scriptId': 'xxxx',
    'version': '0.1.8',
    'mingame': '2.08',
    'maxgame': Game.version.toString(),
    'website': 'https://gf.qytechs.cn/scripts/xxxx',
  };
  Tweaker.langs = {
    'ru_RU': {
      'language': 'Russian (ру́сский)',
      'ApiGui': '<b>How to use:</b><br><u>Ctrl+click:</u> Copy <i>*nickname*</i> to active chat.<br><u>Shift+click:</u> Copy "<i>*nickname* change with</i>" to active chat.<br><u>Backspace+click:</u> Open private chat with current player.<br>Automatically add some information (total dmg, last hit) to players description in fortbattle.<br>Write "<i>/items</i>" into chat to check out new items.<br>Write "<i>/items.s name</i>" into chat to find items by name.<br>Write "<i>/items.add</i>" into chat to update local DB.',
      'TotalDamage': 'Урона за бой',
      'LastHit': 'Последний выстрел',
      'KillShot': 'Скальп',
      'ChangeWith': 'смена с',
      'UserMessage': 'Похоже появились новые шмотки.',
      'itemsShorthelp': 'Первичная настрока локального хранилища вещей.',
      'itemsHelp': 'Первичная настрока локального хранилища вещей, если хранилище уже существует- проверка на появление новых вещей.',
      'itemssShorthelp': 'Поиск по названию предмета.',
      'itemssHelp': 'Поиск по части названия предмета. Регистронезависимый.',
      'itemssUsage': 'часть названия',
      'itemsaddShorthelp': 'Добавить новые предметы в локальную базу.',
      'itemsaddHelp': 'Добавить все новые предметы в локальную базу, чтобы они не показывали при.',
    },
    'en_US': {
      'language': 'None (English)',
      'ApiGui': '<b>How to use:</b><br><u>Ctrl+click:</u> Copy <i>*nickname*</i> to active chat.<br><u>Shift+click:</u> Copy "<i>*nickname* change with</i>" to active chat.<br><u>Backspace+click:</u> Open private chat with current player.<br>Automatically add some information (total dmg, last hit) to players description in fortbattle.<br>Write "<i>/items</i>" into chat to check out new items.<br>Write "<i>/items.s name</i>" into chat to find items by name.<br>Write "<i>/items.add</i>" into chat to update local DB.',
      'TotalDamage': 'Total damage',
      'LastHit': 'Last hit',
      'KillShot': 'Kill shot',
      'ChangeWith': 'change with',
      'UserMessage': 'New items found.',
      'itemsShorthelp': 'Check out new items.',
      'itemsHelp': 'Shows the items, which were last added to the local storage.',
      'itemssShorthelp': 'Find items by name.',
      'itemssHelp': 'Type in anything to search for items, where that part is included.',
      'itemssUsage': 'parte name',
      'itemsaddShorthelp': 'Update local DB.',
      'itemsaddHelp': 'Add new items to the local storage, which aren\'t registrated yet.',
    },
    'es_ES': {
      'language': 'Spanish (español)',
      'ApiGui': '<b>Uso:</b><br><u>Ctrl+click:</u> Copia <i>*nombre_jugador*</i> en el chat activo.<br><u>Shift+click:</u> Copia el texto "<i>*nombre_jugador* cambia con</i>" en el chat activo.<br><u>Backspace+click:</u> Abre chat privado con el jugador actual.<br>Automáticamente añade la siguiente información (daño total, último tiro) en la descripción de los jugadores en batallas de fuertes, simplemente marcando con el puntero del ratón el jugador en el fuerte.<br>Escribe "<i>/items</i>" en el chat para ver nuevos artículos.<br>Escribe "<i>/items.s nombre</i>" en el chat para encontrar artículos por nombre.<br>Escribe "<i>/items.add</i>" en el char para actualizar la Base de Datos local.',
      'TotalDamage': 'Daño Total',
      'LastHit': 'Último tiro',
      'KillShot': 'Desmayo',
      'ChangeWith': 'cambiar con',
      'UserMessage': 'Parece que hay ropa nueva.',
      'itemsShorthelp': 'Configuración inicial de artículos en la base de datos local.',
      'itemsHelp': 'La configuración inicial de la base de datos local, si ya existe la base de datos, comprueba los artículos nuevos.',
      'itemssShorthelp': 'Búsqueda por nombre de artículo.',
      'itemssHelp': 'Buscar por nombre de artículo, minúsculas.',
      'itemssUsage': 'parte del nombre',
      'itemsaddShorthelp': 'Agregar nuevos artículos a la base de datos local.',
      'itemsaddHelp': 'Agregar nuevos artículos a la base de datos local, los que no se muestran en el registro.',
    },
    'de_DE': {
      'language': 'German (Deutsch',
      'ApiGui': '<b>Funktionen:</b><br><u>Ctrl+Klick:</u> Kopiert <i>*nickname*</i> in den aktiven Chat.<br><u>Shift+Klick:</u> Kopiert "<i>*nickname* wechseln</i>" in den aktiven Chat.<br><u>Leertaste+Klick:</u> Öffnet privaten Chat mit dem angeklickten Spieler.<br>Fügt automatisch zusätzliche Informationen (Gesamter Schaden, letzter Treffer) zur Spielerbeschreibung im Fortkampf hinzu.<br>Tippe "<i>/items</i>" in den Chat um neue Items zu finden.<br>Tippe "<i>/items.s Kürzel</i>" in den Chat um Items mit dem Kürzel zu finden.<br>Tippe "<i>/items.add</i>" in den Chat, um den lokalen Speicher zu aktualisieren.',
      'TotalDamage': 'Gesamter Schaden',
      'LastHit': 'Letzter Treffer',
      'KillShot': 'Todesschuss',
      'ChangeWith': 'wechseln',
      'UserMessage': 'Neue Items gefunden.',
      'itemsShorthelp': 'Neue Items anschauen.',
      'itemsHelp': 'Zeige Items, welche zuletzt zum lokalen Speicher hinzugefügt wurden.',
      'itemssShorthelp': 'Finde Items mit Kürzel.',
      'itemssHelp': 'Durch Eingabe von Wortbruchstücken werden alle Items angezeigt, welche dazu gefunden werden.',
      'itemssUsage': 'Wortfetzen',
      'itemsaddShorthelp': 'Lokalen Speicher aktualisieren.',
      'itemsaddHelp': 'Ungespeicherte Items werden dem lokalen Speicher hinzugefügt.',
    },
  };
  Tweaker.getLang = function () {
    return Tweaker.langs.hasOwnProperty(Tweaker.getLocale()) ? Game.locale : 'en_US';
  };
  Tweaker.getLocale = function () {
    return Game.locale;
  };
  var lang = Tweaker.getLang();
  Tweaker.lang = Tweaker.langs[lang];
  //add Auto load Kick-o-matic
  /*if (localStorage.hasOwnProperty('AutoLoad_Kick-o-matic')) {
    if (localStorage['AutoLoad_Kick-o-matic']) {
      var MyScript = TheWestApi.register('Kick-o-matic', 'Kick-o-matic', '2.08', '2.09', 'Macabre2077', 'http://userscripts-mirror.org/scripts/show/96262');
      MyScript.loadScript('http://Vbyec.ru/96262.user.js');
    }
  } else {
    localStorage.setItem('AutoLoad_Kick-o-matic', 1);
  }*/
  var TweakerAPI = TheWestApi.register('TWeaker', Tweaker.scriptName, Tweaker.mingame, Tweaker.maxgame, Tweaker.author, Tweaker.website);
  TweakerAPI.setGui('<br><i>Language detected: </i>' + Tweaker.lang.language + '<br><br>Some little tweaks for The West.<br>Enables commands on forts (simply way to copy nickname of players).<br><br>' + Tweaker.lang.ApiGui + '<br><br><i>' + Tweaker.scriptName + ' v' + Tweaker.version + '</i>');
  // local DataBase of items.
  window.Items = {
    room: '',
    add_item: function (id, name) {
      localStorage.setItem('ItemId_' + id, name);
      return true;
    },
    get_name: function (id) {
      return localStorage.getItem('ItemId_' + id);
    },
    search: function (query) {
      localStorage.getItem('Item_count') ? '' : Items.init();
      for (var key in localStorage) {
        if (typeof key === 'string' && key.indexOf('ItemId') === 0) {
          var index = key.split('_') [1];
          if (Items.get_name(index).toLowerCase().indexOf(query.toLowerCase()) >= 0) {
            Items.show_in_chat('item=' + index + ' : ' + '[item=' + index + ']');
          }
        }
      }
    },
    check: function () {
      var count = 0;
      for (var i = 0; i < 999999; i++) {
        var item = ItemManager.get(i);
        if (item !== undefined) {
          count++;
        }
      }
      var prev_count = localStorage.getItem('Item_count') === null ? 0 : localStorage.getItem('Item_count');
      if (prev_count < count) {
        new UserMessage(Tweaker.lang.UserMessage, UserMessage.HINT).show();
        Items.show_new();
      } 
      else {
        Items.show_in_chat('No new items');
      }
    },
    show_new: function () {
      for (var i = 0; i < 999999; i++) {
        var item = ItemManager.get(i);
        if (item !== undefined && Items.get_name(item.item_id) === null) {
          Items.show_in_chat('item=' + item.item_id + ' : ' + '[item=' + item.item_id + ']');
        }
      }
    },
    init: function () {
      if (localStorage.getItem('Item_count') === null) {
        Items.add_all();
      } 
      else {
        Items.check();
      }
    },
    add_all: function () {
      var count = 0;
      for (var i = 0; i < 999999; i++) {
        var item = ItemManager.get(i);
        if (item !== undefined && Items.get_name(item.item_id) === null) {
          Items.add_item(item.item_id, item.name);
          count++;
        }
      }
      if (count > 0) {
        var prev_count = localStorage.getItem('Item_count') === null ? 0 : localStorage.getItem('Item_count');
        localStorage.setItem('Item_count', parseInt(prev_count) + count);
        Items.show_in_chat('Items added:' + count);
      } 
      else {
        Items.show_in_chat('No item to add');
      }
    },
    show_in_chat: function (text) {
      Items.room.addMessage(Game.TextHandler.parse(text) + '<br/>');
    }
  };
  Chat.Operations['^/items$'] = {
    cmd: 'items',
    shorthelp: Tweaker.lang.itemsShorthelp,
    help: Tweaker.lang.itemsHelp,
    usage: '/items',
    func: function (room, msg) {
      Items.room = room;
      Items.init();
    }
  };
  Chat.Operations['^/items.s (.+)$'] = {
    cmd: 'items.s',
    shorthelp: Tweaker.lang.itemssShorthelp,
    help: Tweaker.lang.itemssHelp,
    usage: '/items.s ' + Tweaker.lang.itemssUsage,
    func: function (room, msg, search) {
      Items.room = room;
      Items.search(search[1]);
    }
  };
  Chat.Operations['^/items.add$'] = {
    cmd: 'items.add',
    shorthelp: Tweaker.lang.itemsaddShorthelp,
    help: Tweaker.lang.itemsaddHelp,
    usage: '/items.add',
    func: function (room, msg) {
      Items.room = room;
      Items.add_all();
    }
  };
  FortBattleWindow.showBattleOrigin = FortBattleWindow.showBattle;
  FortBattleWindow.showBattle = function (response) {
    FortBattle.cacheAll(response);
    FortBattleWindow.showBattleOrigin.call(this, response);
  };
  // Add players on fort to localStorage
  //rewrite by while
  //@todo get fort position
  FortBattle.cacheAll = function (resp) {
    Ajax.remoteCallMode('players', 'get_data', {
      x: Character.position.x,
      y: Character.position.y,
      page: 0
    }, function (data) {
      data.players.forEach(function (player) {
        if (!localStorage.hasOwnProperty('PlayerId_' + player.player_id)) {
          localStorage.setItem('PlayerId_' + player.player_id, player.name);
        }
      });
      var count = data.pages;
      for (var i = 1; i < count; i++) {
        Ajax.remoteCallMode('players', 'get_data', {
          x: Character.position.x,
          y: Character.position.y,
          page: i
        }, function (data) {
          data.players.forEach(function (player) {
            if (!localStorage.hasOwnProperty('PlayerId_' + player.player_id)) {
              localStorage.setItem('PlayerId_' + player.player_id, player.name);
            }
          });
        });
      }
    });
  };
  // Show advance information about player
  FortBattle.getCharDataSheetOrigin = FortBattle.getCharDataSheet;
  FortBattle.getCharDataSheet = function (data) {
    return FortBattle.getCharDataSheetOrigin(data) + '<br/><div class=\'total_damage\'>' + Tweaker.lang.TotalDamage + ':<strong>%totalDmg%</strong> </div>' +
    '<div class=\'last_damage\'>' + Tweaker.lang.LastHit + ': <strong>%lastDmg%</strong></div>';
  };
  FortBattle.flashShowCharacterInfoOrigin = FortBattle.flashShowCharacterInfo;
  FortBattle.flashShowCharacterInfo = function (fortId, playerId, healthNow, healthMax, totalDmg, lastDmg, shotat, bonusdata, resp) {
    //Kill shot
    lastDmg = lastDmg < 15000 ? lastDmg : Tweaker.lang.KillShot;
    FortBattle.flashShowCharacterInfoOrigin(fortId, playerId, healthNow, healthMax, totalDmg, lastDmg, shotat, bonusdata);
    FortBattle.flashShowCharacterInfoEl(playerId);
  };
  FortBattle.flashShowCharacterInfoEl = function (playerId) {
    if (parseInt(Chat.MyId.split('_') [1]) === playerId)
    return;
    setTimeout(function () {
      document['onkeyup'] = null;
    }, 2500);
    document['onkeyup'] = function (e) {
      e = e || window.event;
      e.preventDefault();
      var active_chat_input = $('input.message:visible');
      var keyCode = e.keyCode ? e.keyCode : e.charCode;
      var nick = localStorage.getItem('PlayerId_' + playerId);
      switch (keyCode) {
        case 16:
          /* shift */
          if (!nick)
          return;
          active_chat_input.val(active_chat_input.val() + '*' + nick + '* ' + Tweaker.lang.ChangeWith + '  ');
          break
        case 17:
          /* ctrl */
          if (!nick)
          return;
          active_chat_input.val(active_chat_input.val() + '*' + nick + '* ');
          active_chat_input.focus();
          break
        case 8:
          /* backspace */
          var client = Chat.Resource.Manager.getClient('client_' + playerId);
          var room = Chat.Resource.Manager.acquireRoom(client);
          if (room)
          room.openClick();
          break
        default:
          break
      }
      document['onkeyup'] = null;
      /*smth*/
    };
  };
  EventHandler.listen('chat_init', function () {
    for (var room in Chat.Resource.Manager.getRooms()) {
      if (room.indexOf('room_town') === 0) {
        $('<p style=\'left: 50%; position: absolute; top: 44px; margin-left: -305px; color: white; font-weight: bolder; font-size: 18px;\'>' + Chat.Resource.Manager.getRooms() [room].topic + '</p>').appendTo('#ui_topbar');
      }
    }
  });
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址