Efficiency Stat Script

Shows efficiency (attack per piece + downstack per piece)

2020-04-06 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

  1. // ==UserScript==
  2. // @name Efficiency Stat Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3.6
  5. // @description Shows efficiency (attack per piece + downstack per piece)
  6. // @author Oki
  7. // @match https://*.jstris.jezevec10.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /**************************
  12. Efficiency Stat Script
  13. **************************/
  14.  
  15.  
  16. (function() {
  17. window.addEventListener('load', function(){
  18.  
  19. STAT_POS = 970;
  20. STAT_NAME = "Eff"
  21.  
  22. STAT_POS2 = 1000;
  23. STAT_NAME2 = "VS"
  24.  
  25. enable_playing = true
  26. enable_replay = true
  27. enable_vsscore = true
  28.  
  29. var trim=a=>{a=a.slice(0,-1);a=a.substr(a.indexOf("{")+1);return a}
  30. var getParams=a=>{var params=a.slice(a.indexOf("(")+1);params=params.substr(0,params.indexOf(")")).split(",");return params}
  31.  
  32. x = true
  33.  
  34. function afterPlaceBlock() {
  35. if(this.clock == 0 && x){
  36. cat = this["v"]["kppElement"].id.slice(-1)
  37. if((GameCore['oldPieces'+cat] < this['placedBlocks']) || GameCore['oldPieces'+cat] == undefined){
  38. GameCore['downstack'+cat] += (GameCore['currentGarbage'+cat] - (JSON.stringify(this.matrix).split(8).length-1)/9)
  39. pieces = this['placedBlocks']
  40. GameCore['oldPieces'+cat] = pieces
  41. APP = this["gamedata"]["attack"] / pieces
  42. DPP = GameCore['downstack'+cat] / pieces
  43. EFF = (APP + DPP)
  44. time = this['actions'][this['ptr']]["t"]
  45. GameCore[STAT_NAME + "Timestamps"+cat] = GameCore[STAT_NAME + "Timestamps"+cat] || []
  46. GameCore[STAT_NAME + "Timestamps"+cat].push([(EFF).toFixed(2), time])
  47. } else {
  48. x = false
  49. }
  50. } else {
  51. x = false;
  52. ["1","2","P"].map(y=>{
  53. GameCore['downstack'+y] = 0;
  54. })
  55. }
  56.  
  57. }
  58.  
  59. function afterCheckLineClears() {
  60. GameCore['downstack'] += (GameCore['currentGarbageP'] - (JSON.stringify(this.matrix).split(8).length-1)/9)
  61. pieces = this["GameStats"]["stats"]["BLOCKS"].value
  62. APP = this["gamedata"]["attack"] / pieces
  63. DPP = GameCore['downstack'] / pieces
  64. if(enable_vsscore){
  65. PPS = this['getPPS']()
  66. if(this['GameStats'].get('VS'))this['GameStats'].get('VS').set(((APP + DPP)*PPS).toFixed(2));
  67. }
  68. if(this['GameStats'].get('EFF'))this['GameStats'].get('EFF').set((APP + DPP).toFixed(2));
  69. }
  70.  
  71. function beforeCheckLineClears() {
  72. cat = this["v"]["kppElement"] ? this["v"]["kppElement"].id.slice(-1) : "P"
  73. GameCore['currentGarbage'+cat] = (JSON.stringify(this.matrix).split(8).length-1)/9;
  74. }
  75.  
  76. if(enable_playing | enable_replay){
  77. var checkLineClearsFunc = GameCore['prototype']['checkLineClears'].toString()
  78. var params = getParams(checkLineClearsFunc)
  79. checkLineClearsFunc = trim(beforeCheckLineClears.toString()) + trim(checkLineClearsFunc)
  80. GameCore['prototype']['checkLineClears'] = new Function(...params, checkLineClearsFunc);
  81. }
  82.  
  83.  
  84.  
  85. if(enable_playing){
  86. if(typeof Game != "undefined"){
  87.  
  88. checkLineClearsFunc = GameCore['prototype']['checkLineClears'].toString()
  89. checkLineClearsFunc = trim(checkLineClearsFunc) + trim(afterCheckLineClears.toString())
  90. GameCore['prototype']['checkLineClears'] = new Function(...params, checkLineClearsFunc);
  91.  
  92. var readyGoFunc = Game['prototype']["startReadyGo"].toString()
  93. readyGoFunc = `
  94. GameCore['downstack']=0;
  95. this['GameStats'].addStat(new StatLine('EFF', '`+STAT_NAME+`', `+STAT_POS+`),true);
  96. this['GameStats'].addStat(new StatLine('VS', '`+STAT_NAME2+`', `+STAT_POS2+`),true);` + trim(readyGoFunc)
  97. Game['prototype']["startReadyGo"] = new Function(readyGoFunc);
  98.  
  99. }
  100. }
  101.  
  102.  
  103. if(enable_replay){
  104.  
  105. var website = "jstris.jezevec10.com"
  106. var url = window.location.href
  107. var parts = url.split("/")
  108.  
  109. if(typeof Replayer != "undefined"){
  110. Replayer["addStat"] = function(id,into,name) {
  111. var newStat = document.createElement("tr");
  112. newStat.innerHTML = '<td class="ter">'+name+'</td><td class="sval"><span id="'+id+'">0</span></td>'
  113. into.appendChild(newStat);
  114. }
  115. }
  116.  
  117. if(parts[3]=="replay" && parts[2].endsWith(website) && parts.length>4){
  118.  
  119. ["1","2","P"].map(y=>{GameCore['downstack'+y] = 0});
  120. var placeBlockFunc = GameCore['prototype']['placeBlock'].toString()
  121. var params2 = getParams(placeBlockFunc)
  122. placeBlockFunc = trim(placeBlockFunc) + trim(afterPlaceBlock.toString())
  123. GameCore['prototype']['placeBlock'] = new Function(...params2, placeBlockFunc);
  124.  
  125. if(parts[4]=="1v1"){
  126. Replayer["addStat"](STAT_NAME+"Element1",document.getElementsByTagName("tbody")[0],STAT_NAME)
  127. Replayer["addStat"](STAT_NAME+"Element2",document.getElementsByTagName("tbody")[2],STAT_NAME)
  128.  
  129. if(enable_vsscore){
  130. Replayer["addStat"](STAT_NAME2+"Element1",document.getElementsByTagName("tbody")[0],STAT_NAME2)
  131. Replayer["addStat"](STAT_NAME2+"Element2",document.getElementsByTagName("tbody")[2],STAT_NAME2)
  132. }
  133. } else {
  134. Replayer["addStat"](STAT_NAME+"ElementP",document.getElementsByClassName("moreStats")[0],STAT_NAME)
  135. if(enable_vsscore){
  136. Replayer["addStat"](STAT_NAME2+"ElementP",document.getElementsByClassName("moreStats")[0],STAT_NAME2)
  137. }
  138. }
  139.  
  140. Replayer['prototype']['getStat'] = function(cat) {
  141. if(stamps=GameCore[STAT_NAME+"Timestamps"+cat]){
  142. for (var i = 1; i < stamps.length; i++) {
  143. if(stamps[i][1]>this['clock']){
  144. return stamps[i-1][0]
  145. }
  146. }
  147. return stamps[stamps.length-1][0]
  148. }
  149. return 0
  150. };
  151.  
  152. var oldTextBar = View.prototype.updateTextBar.toString();
  153. oldTextBar = trim(oldTextBar) + `;
  154. var cat = this.kppElement.id.slice(-1);
  155. eval("`+STAT_NAME+`Element"+cat+"&&(`+STAT_NAME+`Element"+cat+".innerHTML = this.g.getStat(cat))");
  156. if(enable_vsscore){
  157. eval("`+STAT_NAME2+`Element"+cat+"&&(`+STAT_NAME2+`Element"+cat+".innerHTML = (PPS"+(cat=='P'?'':cat)+".innerHTML*this.g.getStat(cat)).toFixed(2))");
  158.  
  159. }`
  160.  
  161. View.prototype.updateTextBar = new Function(oldTextBar);
  162.  
  163. }
  164. }
  165.  
  166. });
  167. })();