jaggerid

Untitled

Jul 24th, 2021
960
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const earthTrait = 0
  2.   , ligthingTrait = 1
  3.   , waterTrait = 2
  4.   , fireTrait = 3
  5.   , powerTrait = 4;
  6. let weapons = [];
  7. function selectWeapon(t) {
  8.     let a = weapons[t];
  9.     a.weaponTrait == waterTrait ? $("#weaponWater").prop("checked", !0) : $("#weaponWater").prop("checked", !1),
  10.     a.weaponTrait == earthTrait ? $("#weaponEarth").prop("checked", !0) : $("#weaponEarth").prop("checked", !1),
  11.     a.weaponTrait == fireTrait ? $("#weaponFire").prop("checked", !0) : $("#weaponFire").prop("checked", !1),
  12.     a.weaponTrait == ligthingTrait ? $("#weaponLighting").prop("checked", !0) : $("#weaponLighting").prop("checked", !1),
  13.     a.stat1Trait == waterTrait ? $("#stat1Water").prop("checked", !0) : $("#stat1Water").prop("checked", !1),
  14.     a.stat1Trait == earthTrait ? $("#stat1Earth").prop("checked", !0) : $("#stat1Earth").prop("checked", !1),
  15.     a.stat1Trait == fireTrait ? $("#stat1Fire").prop("checked", !0) : $("#stat1Fire").prop("checked", !1),
  16.     a.stat1Trait == ligthingTrait ? $("#stat1Lighting").prop("checked", !0) : $("#stat1Lighting").prop("checked", !1),
  17.     a.stat1Trait == powerTrait ? $("#stat1Power").prop("checked", !0) : $("#stat1Power").prop("checked", !1),
  18.     a.stat2Trait == waterTrait ? $("#stat2Water").prop("checked", !0) : $("#stat2Water").prop("checked", !1),
  19.     a.stat2Trait == earthTrait ? $("#stat2Earth").prop("checked", !0) : $("#stat2Earth").prop("checked", !1),
  20.     a.stat2Trait == fireTrait ? $("#stat2Fire").prop("checked", !0) : $("#stat2Fire").prop("checked", !1),
  21.     a.stat2Trait == ligthingTrait ? $("#stat2Lighting").prop("checked", !0) : $("#stat2Lighting").prop("checked", !1),
  22.     a.stat2Trait == powerTrait ? $("#stat2Power").prop("checked", !0) : $("#stat2Power").prop("checked", !1),
  23.     a.stat3Trait == waterTrait ? $("#stat3Water").prop("checked", !0) : $("#stat3Water").prop("checked", !1),
  24.     a.stat3Trait == earthTrait ? $("#stat3Earth").prop("checked", !0) : $("#stat3Earth").prop("checked", !1),
  25.     a.stat3Trait == fireTrait ? $("#stat3Fire").prop("checked", !0) : $("#stat3Fire").prop("checked", !1),
  26.     a.stat3Trait == ligthingTrait ? $("#stat3Lighting").prop("checked", !0) : $("#stat3Lighting").prop("checked", !1),
  27.     a.stat3Trait == powerTrait ? $("#stat3Power").prop("checked", !0) : $("#stat3Power").prop("checked", !1),
  28.     $("#weaponPower").val(a.weaponPower),
  29.     $("#stat1").val(a.stat1),
  30.     $("#stat2").val(a.stat2),
  31.     $("#stat3").val(a.stat3)
  32. }
  33. function loadWeapons() {
  34.     $("#saved-weapons").empty();
  35.     let t = getCookie("weapons");
  36.     if (null == t)
  37.         return [];
  38.     let a = t.split("|")
  39.       , e = [];
  40.     for (let t = 0; t < a.length - 1; t++) {
  41.         let i = a[t].split("&");
  42.         e.push({
  43.             weaponTrait: i[0],
  44.             weaponPower: i[1],
  45.             stat1: i[2],
  46.             stat1Trait: i[3],
  47.             stat2: i[4],
  48.             stat2Trait: i[5],
  49.             stat3: i[6],
  50.             stat3Trait: i[7]
  51.         });
  52.         let r = '\n        <div class="col-12 col-md-3">\n            <div class="card mb-3">\n                <div class="card-header bg-info text-center">\n                    <div>' + getHtmlIconByTrait(i[0]) + '</div>\n                </div>\n                <div class="card-body bg-secondary">\n                    <div class="form-group text-center font-weight-bold">\n                        <div class="pb-1"><span>' + i[2] + " " + getHtmlIconByTrait(i[3]) + '</span></div>\n                        <div class="pb-1"><span>' + i[4] + " " + getHtmlIconByTrait(i[5]) + '</span></div>\n                        <div class="pb-1"><span>' + i[6] + " " + getHtmlIconByTrait(i[7]) + '</span></div>\n                        <div class="pb-1"><span>Bonus Power: ' + i[1] + '</span></div>\n                        <div class="col-12 text-center pt-2">\n                            <button id="fight" type="button" class="btn btn-md btn-primary btn-icon-text mr-2 mb-2" onclick="selectWeapon(' + t + ')">Load </button>\n                            <button id="fight" type="button" class="btn btn-md btn-primary btn-icon-text mr-2 mb-2" onclick="removeWeapon(' + t + ')">Delete </button>\n                        </div>\n                    </div>\n                </div>\n            </div>\n        </div>';
  53.         $("#saved-weapons").append(r)
  54.     }
  55.     return console.log(e),
  56.     e
  57. }
  58. function removeWeapon(t) {
  59.     weapons.splice(t, 1);
  60.     let a = "";
  61.     for (let t = 0; t < weapons.length; t++) {
  62.         const e = weapons[t];
  63.         a = a + (e.weaponTrait + "&" + e.weaponPower + "&" + e.stat1 + "&" + e.stat1Trait + "&" + e.stat2 + "&" + e.stat2Trait + "&" + e.stat3 + "&" + e.stat3Trait) + "|"
  64.     }
  65.     setCookie("weapons", a, 30),
  66.     loadWeapons()
  67. }
  68. function getCookie(t) {
  69.     for (var a = t + "=", e = document.cookie.split(";"), i = 0; i < e.length; i++) {
  70.         for (var r = e[i]; " " == r.charAt(0); )
  71.             r = r.substring(1, r.length);
  72.         if (0 == r.indexOf(a))
  73.             return r.substring(a.length, r.length)
  74.     }
  75.     return null
  76. }
  77. function eraseCookie(t) {
  78.     document.cookie = t + "=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;"
  79. }
  80. function getHtmlIconByTrait(t) {
  81.     return t == earthTrait ? '<i class="mdi mdi-earth"></i>' : t == waterTrait ? '<i class="mdi mdi-water"></i>' : t == fireTrait ? '<i class="mdi mdi-fire"></i>' : t == ligthingTrait ? '<i class="mdi mdi-weather-lightning"></i>' : t == powerTrait ? '<i class="mdi mdi-sword"></i>' : ""
  82. }
  83. function saveWeapon() {
  84.     try {
  85.         let t = parseInt($("input[name=weaponTrait]:checked").val())
  86.           , a = parseInt($("input[name=stat1Radio]:checked").val())
  87.           , e = parseInt($("input[name=stat2Radio]:checked").val())
  88.           , i = parseInt($("input[name=stat3Radio]:checked").val())
  89.           , r = validateInput($("#weaponPower"))
  90.           , n = validateInput($("#stat1"))
  91.           , o = validateInput($("#stat2"))
  92.           , s = validateInput($("#stat3"));
  93.         if (!existsWeapon(t, r, n, a, o, e, s, i)) {
  94.             weapons.push({
  95.                 weaponTrait: t,
  96.                 weaponPower: r,
  97.                 stat1: n,
  98.                 stat1Trait: a,
  99.                 stat2: o,
  100.                 stat2Trait: e,
  101.                 stat3: s,
  102.                 stat3Trait: i
  103.             });
  104.             let p = "";
  105.             for (let t = 0; t < weapons.length; t++) {
  106.                 const a = weapons[t];
  107.                 p = p + (a.weaponTrait + "&" + a.weaponPower + "&" + a.stat1 + "&" + a.stat1Trait + "&" + a.stat2 + "&" + a.stat2Trait + "&" + a.stat3 + "&" + a.stat3Trait) + "|"
  108.             }
  109.             setCookie("weapons", p, 30),
  110.             loadWeapons()
  111.         }
  112.     } catch (t) {
  113.         $("#warning").text("Error in parsing inputs, all stats and powers must be defined.")
  114.     }
  115. }
  116. function existsWeapon(t, a, e, i, r, n, o, s) {
  117.     for (let p = 0; p < weapons.length; p++) {
  118.         const c = weapons[p];
  119.         if (t == c.weaponTrait && a == c.weaponPower && e == c.stat1 && i == c.stat1Trait && r == c.stat2 && n == c.stat2Trait && o == c.stat3 && s == c.stat3Trait)
  120.             return !0
  121.     }
  122.     return !1
  123. }
  124. function setCookie(t, a, e) {
  125.     var i = "";
  126.     if (e) {
  127.         var r = new Date;
  128.         r.setTime(r.getTime() + 24 * e * 60 * 60 * 1e3),
  129.         i = "; expires=" + r.toUTCString()
  130.     }
  131.     document.cookie = t + "=" + (a || "") + i + "; path=/"
  132. }
  133. function validateInput(t) {
  134.     let a = t.val();
  135.     if (!isNaN(parseFloat(a)) && isFinite(a))
  136.         return parseFloat(a);
  137.     throw "Not number"
  138. }
  139. $(document).ready(function() {
  140.     function t(t, a, e) {
  141.         let i = 1;
  142.         var r, n;
  143.         return t == a && (i += .075),
  144.         n = e,
  145.         ((r = t) == fireTrait && n == earthTrait || r == waterTrait && n == fireTrait || r == ligthingTrait && n == waterTrait || r == earthTrait && n == ligthingTrait) && (i += .075),
  146.         function(t, a) {
  147.             return t == fireTrait && a == waterTrait || t == waterTrait && a == ligthingTrait || t == ligthingTrait && a == earthTrait || t == earthTrait && a == fireTrait
  148.         }(t, e) && (i -= .075),
  149.         i
  150.     }
  151.     function a(t, a) {
  152.         return t = Math.ceil(t),
  153.         a = Math.floor(a),
  154.         Math.floor(Math.random() * (a - t + 1)) + t
  155.     }
  156.     $("#cryptoblades-donate").click(function() {
  157.         window.open("https://bscscan.com/address/0xfabdda0ddcffc76b3d80c2dc44224c1f4c45501e", "_blank").focus()
  158.     }),
  159.     $("#save-weapon").click(function() {
  160.         saveWeapon()
  161.     }),
  162.     $("#fight").click(function() {
  163.         try {
  164.             let e = parseInt($("input[name=heroTrait]:checked").val())
  165.               , i = parseInt($("input[name=weaponTrait]:checked").val())
  166.               , r = parseInt($("input[name=stat1Radio]:checked").val())
  167.               , n = parseInt($("input[name=stat2Radio]:checked").val())
  168.               , o = parseInt($("input[name=stat3Radio]:checked").val())
  169.               , s = parseInt($("input[name=enemy1Radio]:checked").val())
  170.               , p = parseInt($("input[name=enemy2Radio]:checked").val())
  171.               , c = parseInt($("input[name=enemy3Radio]:checked").val())
  172.               , d = parseInt($("input[name=enemy4Radio]:checked").val());
  173.             !function(e, i, r, n, o, s, p, c, d, l, h, T, w, u, g, f, v, k) {
  174.                 let m, b, I = function(t, a, e, i, r, n, o) {
  175.                     let s = 1;
  176.                     a > 0 && e >= 0 && (s += e == t ? .0026750000000000003 * a : e == powerTrait ? .002575 * a : .0025 * a);
  177.                     i > 0 && r >= 0 && (s += r == t ? .0026750000000000003 * i : r == powerTrait ? .002575 * i : .0025 * i);
  178.                     n > 0 && o >= 0 && (s += o == t ? .0026750000000000003 * n : o == powerTrait ? .002575 * n : .0025 * n);
  179.                     return s
  180.                 }(n, o, s, p, c, d, l), y = e * I + r, x = Math.ceil(h - .1 * h), M = Math.floor(h + .1 * h), W = Math.ceil(y - .1 * y), P = Math.floor(y + .1 * y), F = Math.ceil(w - .1 * w), E = Math.floor(w + .1 * w), C = Math.ceil(y - .1 * y), L = Math.floor(y + .1 * y), R = Math.ceil(g - .1 * g), B = Math.floor(g + .1 * g), H = Math.ceil(y - .1 * y), N = Math.floor(y + .1 * y), D = Math.ceil(v - .1 * v), A = Math.floor(v + .1 * v), G = Math.ceil(y - .1 * y), J = Math.floor(y + .1 * y), O = t(i, n, T), S = t(i, n, u), U = t(i, n, f), _ = t(i, n, k), j = 0, q = 0, z = 0, K = 0;
  181.                 for (let t = 0; t < 500; t++)
  182.                     m = a(W, P) * O,
  183.                     b = a(x, M),
  184.                     m >= b && j++,
  185.                     m = a(C, L) * S,
  186.                     b = a(F, E),
  187.                     m >= b && q++,
  188.                     m = a(H, N) * U,
  189.                     b = a(R, B),
  190.                     m >= b && z++,
  191.                     m = a(G, J) * _,
  192.                     b = a(D, A),
  193.                     m >= b && K++;
  194.                 $("#enemy1Chance").text((j / 500 * 100).toFixed(2) + " %"),
  195.                 $("#enemy2Chance").text((q / 500 * 100).toFixed(2) + " %"),
  196.                 $("#enemy3Chance").text((z / 500 * 100).toFixed(2) + " %"),
  197.                 $("#enemy4Chance").text((K / 500 * 100).toFixed(2) + " %")
  198.             }(validateInput($("#heroPower")), e, validateInput($("#weaponPower")), i, validateInput($("#stat1")), r, validateInput($("#stat2")), n, validateInput($("#stat3")), o, validateInput($("#enemy1")), s, validateInput($("#enemy2")), p, validateInput($("#enemy3")), c, validateInput($("#enemy4")), d)
  199.         } catch (t) {
  200.             $("#warning").text("Error in parsing inputs, all stats and powers must be defined.")
  201.         }
  202.     })
  203. }),
  204. window.addEventListener("load", function() {
  205.     weapons = loadWeapons()
  206. });
  207.  
RAW Paste Data