Pendoria - Battle End Health Calculation

Show final health remaining

目前为 2022-10-07 提交的版本。查看 最新版本

// ==UserScript==
// @name         Pendoria - Battle End Health Calculation
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Show final health remaining
// @author       Xortrox, Kidel
// @match        https://pendoria.net/game
// @icon         https://www.google.com/s2/favicons?sz=64&domain=pendoria.net
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    socket.on('battle data', (data) => {
    // Skip 1 frame (might be unecessary if this is scheduled after other battle data listeners)
    setTimeout(() => {
        if (data?.victory) {
            const lifeLostPerRoundPlayer = (data.playerMaxLife - data.playerLife) / 1500;
            const lifeLostPerRoundMonster = (data.monsterMaxLife - data.monsterLife) / 1500;
    
            const roundsUntilMonsterDead = Math.ceil(data.monsterLife / lifeLostPerRoundMonster);
    
            console.log('monster dies in', roundsUntilMonsterDead, 'rounds');
            
            const playerLifeRemaining = data.playerLife - lifeLostPerRoundPlayer * roundsUntilMonsterDead;
            const playerLifeRemainingPercentage = (playerLifeRemaining / data.playerMaxLife * 100);
    
            console.log('player life left would be:', playerLifeRemaining, 'or:', playerLifeRemainingPercentage + '%');
    
            const monsterHealthDisplay = $('#mhp-value');
            monsterHealthDisplay.text(`0/${formatNumber(data.monsterMaxLife)} (0.0000%)`);
    
            const monsterHealthBackground = $('#mhp-background');
            monsterHealthBackground[0].style['width'] = 0;
            
            const playerHealthDisplay = $('#php-value');
            playerHealthDisplay.text(`${formatNumber(playerLifeRemaining)}/${formatNumber(data.playerMaxLife)} (${playerLifeRemainingPercentage.toFixed(4)}%)`);
    
            const playerHealthBackground = $('#php-background');
            playerHealthBackground[0].style['width'] = playerLifeRemainingPercentage + '%';
        }
    });
});
})();

QingJ © 2025

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