IdlePixel Chance2Hit

Adds chance-to-hit indicators in combat.

  1. // ==UserScript==
  2. // @name IdlePixel Chance2Hit
  3. // @namespace com.anwinity.idlepixel
  4. // @version 1.2.6
  5. // @description Adds chance-to-hit indicators in combat.
  6. // @author Anwinity
  7. // @license MIT
  8. // @match *://idle-pixel.com/login/play*
  9. // @grant none
  10. // @require https://gf.qytechs.cn/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function hitChance(accuracy, defence) {
  17. if (defence % 2 == 0){
  18. return 1 / Math.max(1, defence/2 - accuracy + 1);
  19. }
  20. else {
  21. return ( hitChance(accuracy, defence-1) + hitChance(accuracy, defence+1) ) / 2;
  22. }
  23. }
  24.  
  25. function formatPercent(n) {
  26. n *= 100;
  27. n = n.toFixed(1);
  28. if(n.endsWith(".0")) {
  29. n = n.substring(0, n.length - 2);
  30. }
  31. return `${n}%`;
  32. }
  33.  
  34. const TRIGGER_ON_VARS = ["monster_name", "monster_accuracy", "monster_defence", "accuracy", "defence"];
  35.  
  36. class Chance2HitPlugin extends IdlePixelPlusPlugin {
  37. constructor() {
  38. super("chance2hit", {
  39. about: {
  40. name: GM_info.script.name,
  41. version: GM_info.script.version,
  42. author: GM_info.script.author,
  43. description: GM_info.script.description
  44. }
  45. });
  46. }
  47.  
  48. recalculateChances() {
  49. const monsterAccuracy = IdlePixelPlus.getVarOrDefault("monster_accuracy", 0, "int");
  50. const monsterDefence = IdlePixelPlus.getVarOrDefault("monster_defence", 0, "int");
  51. const playerAccuracy = IdlePixelPlus.getVarOrDefault("accuracy", 0, "int");
  52. const playerDefence = IdlePixelPlus.getVarOrDefault("defence", 0, "int");
  53. const monsterChanceToHit = formatPercent(hitChance(monsterAccuracy, playerDefence));
  54. const playerChanceToHit = formatPercent(hitChance(playerAccuracy, monsterDefence));
  55. $("#player-chance2hit").text(` ${monsterChanceToHit}`);
  56. $("#monster-chance2hit").text(` ${playerChanceToHit}`);
  57. }
  58.  
  59. onMessageReceived(data) {
  60. if(data.startsWith("SET_ITEMS=")) {
  61. if(TRIGGER_ON_VARS.some(key => data.includes(`${key}~`))) {
  62. this.recalculateChances();
  63. }
  64. }
  65. }
  66.  
  67. onLogin() {
  68. $("#panel-combat-canvas #combat_hero_accuracy").parent().after(`
  69. <div class="td-combat-stat-entry">
  70. <img class="img-15" src="https://idlepixel.s3.us-east-2.amazonaws.com/images/accuracy_white.png">
  71. <span style="color:white">Chance:</span>
  72. <span id="monster-chance2hit"></span>
  73. </div>`);
  74. $("#panel-combat-canvas #combat_monster_accuracy").parent().after(`
  75. <div class="td-combat-stat-entry">
  76. <img class="img-15" src="https://idlepixel.s3.us-east-2.amazonaws.com/images/accuracy_white.png">
  77. <span style="color:white">Chance:</span>
  78. <span id="player-chance2hit"></span>
  79. </div>`);
  80. }
  81.  
  82. }
  83.  
  84. const plugin = new Chance2HitPlugin();
  85. IdlePixelPlus.registerPlugin(plugin);
  86.  
  87. })();

QingJ © 2025

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