DH3 FP Notification

Adds fight points notification

目前为 2021-01-05 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name DH3 FP Notification
  3. // @namespace com.anwinity.dh3
  4. // @version 1.0.5
  5. // @description Adds fight points notification
  6. // @author Anwinity
  7. // @match dh3.diamondhunt.co
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const FP_COSTS = {
  15. fields: 900,
  16. forest: 1800,
  17. caves: 3600,
  18. lavaDungeon: 5400,
  19. northernFields: 7200,
  20. cemetery: 9000,
  21. ocean: 10800,
  22. dungeon: 13200
  23. };
  24.  
  25. const MAP_IDS = {
  26. fields: 1,
  27. forest: 1,
  28. caves: 2,
  29. lavaDungeon: 3,
  30. northernFields: 4,
  31. cemetery: 8,
  32. ocean: 10,
  33. dungeon: 16
  34. }
  35.  
  36. const scope = {
  37. area: "fields"
  38. };
  39.  
  40. function loadPreferences() {
  41. let area = localStorage.getItem("fp-notificiations.area") || "fields";
  42. scope.area = area;
  43. $("#fp-area").val(scope.area);
  44. }
  45.  
  46. function savePreferences() {
  47. localStorage.setItem("fp-notificiations.area", scope.area);
  48. }
  49.  
  50. function gotoArea() {
  51. if(scope.area == "full") {
  52. return;
  53. }
  54. clicksItem("fightMonsterButton");
  55. changeCombatMap(MAP_IDS[scope.area]);
  56. }
  57.  
  58. function fpNeeded() {
  59. if(scope.area == "full") {
  60. return parseInt(window.var_maxFightPoints);
  61. }
  62. let base = FP_COSTS[scope.area];
  63. let p = 1;
  64. if(window.var_cooldownRing1 == "1") {
  65. p -= 0.01;
  66. }
  67. if(window.var_cooldownRing2 == "1") {
  68. p -= 0.04;
  69. }
  70. if(window.var_cooldownRing3 == "1") {
  71. p -= 0.10;
  72. }
  73. if(window.var_cooldownRing4 == "1") {
  74. p -= 0.15;
  75. }
  76. return Math.ceil(base*p);
  77. }
  78.  
  79. function initUI() {
  80. const styles = document.createElement("style");
  81. styles.textContent = `
  82. span#notification-fightPoints {
  83. position: relative;
  84. }
  85. span#notification-fightPoints > #fp-area {
  86. position: absolute;
  87. bottom: 1px;
  88. right: 1px;
  89. margin: 0px;
  90. padding: 2px;
  91. background-color: rgba(1,1,1,0);
  92. border: 0px solid rgba(1,1,1,0);
  93. color: white;
  94. }
  95. span#notification-fightPoints > #fp-area > option {
  96. background-color: rgba(102, 0, 0, 0.9);
  97. }
  98. `;
  99. $("head").append(styles);
  100.  
  101. $("#notification-inCombat").after(`
  102. <span id="notification-fightPoints" class="notification-red"">
  103. <img src="images/fightPoints.png" class="img-50">
  104. <span id="fp-timer"></span>
  105. <select id="fp-area">
  106. <option value="fields">Fields</option>
  107. <option value="forest">Forest</option>
  108. <option value="caves">Caves</option>
  109. <option value="lavaDungeon">Lava</option>
  110. <option value="northernFields">N Fields</option>
  111. <option value="cemetery">Cemetery</option>
  112. <option value="ocean">Ocean</option>
  113. <option value="dungeon">Dungeon</option>
  114. <option value="full">Full FP</option>
  115. </select>
  116. </span>
  117. `);
  118.  
  119. $("#notification-fightPoints").click(function() {
  120. gotoArea();
  121. });
  122. let areaSelect = $("span#notification-fightPoints > #fp-area");
  123. areaSelect.click(function(e) {
  124. e.stopPropagation();
  125. });
  126. areaSelect.change(function() {
  127. let area = $(this).val();
  128. scope.area = area;
  129. savePreferences();
  130. updateUI(window.var_fightPoints);
  131. });
  132. }
  133.  
  134. function updateUI(fp) {
  135. if(typeof fp === "string") {
  136. fp = parseInt(fp);
  137. }
  138. let fpMax = parseInt(window.var_maxFightPoints);
  139. let fpReq = fpNeeded();
  140. let count = Math.floor(fp / fpReq);
  141. let fpNext = fpReq * (count+1);
  142. if(fpNext > fpMax) {
  143. fpNext = fpMax;
  144. }
  145. let fpDelta = fpNext - fp;
  146. let time = fpDelta==0 ? "--:--" : formatTime(fpDelta);
  147. if(scope.area == "full") {
  148. $("#fp-timer").html(`${time}`);
  149. }
  150. else {
  151. $("#fp-timer").html(`${count}x&nbsp;&nbsp;${time}`);
  152. }
  153. }
  154.  
  155. function overrideFunctions() {
  156. const originalSetItems = window.setItems;
  157. window.setItems = function(data) {
  158. originalSetItems.apply(this, arguments);
  159. if(data) {
  160. let m = data.match(/fightPoints~(\d+)/);
  161. if(m) {
  162. updateUI(m[1]);
  163. }
  164. }
  165. }
  166. }
  167.  
  168. function init() {
  169. if(!window.var_username) {
  170. setTimeout(init, 1000);
  171. return;
  172. }
  173.  
  174. initUI();
  175. overrideFunctions();
  176. loadPreferences();
  177. }
  178.  
  179. $(init);
  180.  
  181. })();