battle_damage_tooltip

Показывает урон всех вражеских стеков по одному своему. Выбор существа и стороны по кнопке. Урон не полностью корректен, так что нужно помнить про погрешность. В конце строки отображается хп аткаующего отряда. Кнопка "Свернуть" теперь сворачивают боольшую часть находящегося в чате скрипта battleHelper от omne

当前为 2023-04-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         battle_damage_tooltip
// @namespace    http://tampermonkey.net/
// @version      0.4.0.1
// @description  Показывает урон всех вражеских стеков по одному своему. Выбор существа и стороны по кнопке. Урон не полностью корректен, так что нужно помнить про погрешность. В конце строки отображается хп  аткаующего отряда. Кнопка "Свернуть" теперь сворачивают боольшую часть находящегося в чате скрипта battleHelper от omne
// @author       You
// @license      None
// @match       https://www.heroeswm.ru/war*
// @match       https://my.lordswm.com/war*
// @match       https://www.lordswm.com/war*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
// Странные способы в некоторых местах обусловлены конфликтом со скриптом battleHelper от omne
let chosen = {side: 1, creature: "Высшие вампиры", afterSideSwitchCre: {"-1": "", "1": ""}}
let outer_chat = document.getElementById("chat_format");//
outer_chat.innerHTML+= '<button id = "dmg_list_refresh" style="background-color: #3d3d29; color: white; padding: 5px 10px; border: none; border-radius: 4px; font-size: 10px; cursor: pointer">Открыть</button><select style = "display : none; background-color: #333; color: white; margin: 10px" id = "choose_cre"></select>'
outer_chat.innerHTML+= '<button id = "change_side" style="background-color: #6b6b47; color: white; padding: 5px 10px; border: none; border-radius: 4px; font-size: 10px; cursor: pointer; display: none">Сменить сторону</button>'
outer_chat.innerHTML+= '<button id = "collapse" style="background-color: #000000; color: white; padding: 5px 10px; border: none; border-radius: 4px; font-size: 10px; cursor: pointer; display: none; margin:10px">Свернуть</button>'
outer_chat.addEventListener('click', function(event) {
    let child = event.target
    switch(child.id){
        case "dmg_list_refresh":
            readjust_elements()
            refresh()
            break
        case "change_side":
            //readjust_elements()
            chosen.afterSideSwitchCre[chosen.side] = chosen.creature
            chosen.side = - chosen.side
            chosen.creature = chosen.afterSideSwitchCre[chosen.side]
            refresh()
            break
        case "collapse":
            // readjust_elements();
            battleHelper_display(false);
            [...chat.children].forEach(child=>{
                if (child.tagName == "P") child.remove()
            })
            refresh_button.innerHTML = "Открыть"
            /*help_button.style.display = */select.style.display = side_button.style.display = collapse_button.style.display = "none"
            break
    }
})
//outer_chat.innerHTML+= '<style>.tooltip{position:relative;display:inline-block;border-bottom:1px dotted #000}.tooltip .tooltiptext{visibility:hidden;width:120px;background-color:#555;color:#fff;text-align:center;border-radius:6px;padding:5px 0;position:absolute;z-index:1;bottom:125%;left:50%;margin-left:-60px;opacity:0;transition:opacity .3s}.tooltip .tooltiptext::after{content:"";position:absolute;top:100%;left:50%;margin-left:-5px;border-width:5px;border-style:solid;border-color:#555 transparent transparent transparent}.tooltip:hover .tooltiptext{visibility:visible;opacity:1}</style>'
//outer_chat.innerHTML+= '<button class="tooltip" id = "help" style="background-color: #555; color: white; padding: 5px 10px; border: none; border-radius: 4px; font-size: 10px; margin: 10px; display:none">?<span class="tooltiptext">tooltip</span></button>'
//let help_button = document.getElementById("help")
let chat = document.getElementById("chat_inside");
let select = document.getElementById("choose_cre")
let refresh_button = document.getElementById("dmg_list_refresh")
let side_button = document.getElementById("change_side")
let collapse_button = document.getElementById("collapse")

function readjust_elements(){
    chat = document.getElementById("chat_inside");
    select = document.getElementById("choose_cre")
    refresh_button = document.getElementById("dmg_list_refresh")
    side_button = document.getElementById("change_side")
    collapse_button = document.getElementById("collapse")
}

function get_dmg_info(cre1_id, cre2_id){
    window.stage.pole.attackmonster(cre1_id, window.stage.pole.obj[cre1_id].x, window.stage.pole.obj[cre1_id].y, window.stage.pole.obj[cre2_id].x, window.stage.pole.obj[cre2_id].y, cre2_id)
    return {min: window.PhysicalDamage, max: window.PhysicalDamage2}
}
outer_chat.addEventListener('change', function() {
    //readjust_elements()
    chosen.creature = select.value
    refresh()
});
let defender_obj_id = 0
let selected_id = 0
function battleHelper_display(ifDisplay){
/*    if (!ifDisplay){
        for (let i = 1; i<=6; i++){
            outer_chat.innerText = outer_chat.innerText.replace(`Команда №${i}`)
        }
    }*/
    [...outer_chat.children].forEach(child=>{
        if (child.tagName == "B"||child.tagName == "BR" || child.className == "cont"){
            child.style.display = ifDisplay ? "inline" : "none"
        }
    })

}
function refresh(){
    battleHelper_display(true)
    /*help_button.style.display = */select.style.display = side_button.style.display = collapse_button.style.display = "inline"
    refresh_button.innerHTML = "Обновить"
    let cre_list = Object.values(window.stage.pole.obj);
    cre_list.sort(function(a, b) {
        return a.obj_index - b.obj_index;
    });
    [...chat.children].forEach(child=>{
        if (child.tagName == "P") child.remove()
    })
    select.innerHTML = ""
    let found_defender = false
    cre_list.forEach(creature => {
        if (![0,-1].includes(creature.nownumber) && creature.nametxt!="" && creature.side == chosen.side && creature.hero == undefined){
            select.innerHTML+=`<option value = "${creature.nametxt}">${creature.nametxt} [${creature.nownumber}] </option>`
            if (!found_defender) {
                if (creature.nametxt == chosen.creature){
                    defender_obj_id = creature.obj_index
                    selected_id = [...select.children].indexOf(select.lastChild)
                    found_defender = true
                }
                else {
                    defender_obj_id = creature.obj_index
                    selected_id = [...select.children].indexOf(select.lastChild)
                }
            }
        }
    })
    cre_list.forEach(creature => {
        if (creature.side == -chosen.side) {
            if (creature.nownumber == 0 || creature.nametxt == "") return
            let data = get_dmg_info(creature.obj_index, defender_obj_id)
            let hp = cre_list[defender_obj_id-1].maxhealth
            let row = `<p><b>${creature.nametxt}</b> [${creature.nownumber}] --> <b>${cre_list[defender_obj_id-1].nametxt}</b> [${cre_list[defender_obj_id-1].nownumber}] : <b>${Math.round(data.min/hp)}-${Math.round(data.max/hp)} существ</b> (${data.min}-${data.max}) (${creature.maxhealth*creature.nownumber} хп)  </p>`;
            chat.innerHTML += row;
        }
    })
    select.options.item(selected_id).selected = true
}