Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script>
- function randomInteger(min, max) {
- var rand = min + Math.random() * (max + 1 - min);
- rand = Math.floor(rand);
- return rand;
- }
- function checkDex() {
- //Атакующий
- AttackerLevel = parseInt($('#AttackerLevel').val());
- AttackerDex = parseInt($('#AttackerDex').val());
- AttackerLuc = parseInt($('#AttackerLuc').val());
- AttackernPerAttack = AttackerDex * 0.5 + AttackerLevel;
- AttackernPerDefense = AttackerLuc * 0.125 + AttackernPerAttack;
- //Атакуемый
- AttackedLevel = parseInt($('#AttackedLevel').val());
- AttackedDex = parseInt($('#AttackedDex').val());
- AttackedLuc = parseInt($('#AttackedLuc').val());
- AttackednPerAttack = AttackedDex * 0.5 + AttackedLevel;
- AttackednPerDefense = AttackedLuc * 0.125 + AttackednPerAttack;
- //nAttackTypel = AttackednPerAttack + AttackernPerDefense;
- //nAttackTypem = AttackernPerAttack + AttackednPerDefense;
- nAttackTypem = AttackednPerAttack + AttackednPerDefense;
- nAttackTypek = AttackednPerAttack / (AttackernPerAttack + AttackernPerDefense);
- procent = AttackerLevel / (AttackerLevel + AttackedLevel) * 160.0 - (nAttackTypek * 100.0 - AttackernPerAttack / nAttackTypem * 100.0);
- console.log(nAttackTypek);
- if (procent >= 1) {
- if (procent > 99)
- procent = 99;
- }
- else {
- procent = 1;
- }
- if (randomInteger(0, 100) >= procent) {
- console.log('Вы не попали: ' + procent + '% шанс.');
- return 0;
- }
- console.log('Вы попали: ' + procent + '% шанс.');
- return 1;
- }
- </script>
- <table>
- <th>Атакующий</th>
- <th>Атакуемый</th>
- <tr>
- <td>
- <input type="text" id="AttackerLevel" placeholder="Уровень" value="60"><br>
- <input type="text" id="AttackerDex" placeholder="Ловкость" value="1500"><br>
- <input type="text" id="AttackerLuc" placeholder="Удача" value="11"><br>
- </td>
- <td>
- <input type="text" id="AttackedLevel" placeholder="Уровень" value="60"><br>
- <input type="text" id="AttackedDex" placeholder="Ловкость" value="3000"><br>
- <input type="text" id="AttackedLuc" placeholder="Удача" value="12"><br>
- </td>
- </tr>
- </table>
- <div id="chance"></div>
- <input type="submit" onclick="checkDex()">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement