battle_damage_tooltip

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

目前為 2023-04-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         battle_damage_tooltip
// @namespace    http://tampermonkey.net/
// @version      0.5.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");

function set_Display(element_arr, displayProperty){
    element_arr.forEach(element=>{
        if (element == null) return
        element.style.display = displayProperty
    })
}
function elStringToEl(qSelector, htmlString){
    const parser = new DOMParser();
    const doc = parser.parseFromString(htmlString, 'text/html');
    return doc.querySelector(qSelector)
}
let newElements = {
    "#dmg_list_refresh" : `<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>`,
    "#choose_cre" : `<select style = "display : none; background-color: #333; color: white; margin: 10px" id = "choose_cre"></select>`,
    "#change_side" : `<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>`,
    "#collapse" : `<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>`
}
for (const qSelector in newElements){
    outer_chat.appendChild(elStringToEl(qSelector, newElements[qSelector]))
}
outer_chat.addEventListener('click', function(event) {
    let child = event.target
    switch(child.id){
        case "dmg_list_refresh":
            readjust_elements()
            refresh()
            break
        case "change_side":
            chosen.afterSideSwitchCre[chosen.side] = chosen.creature
            chosen.side = - chosen.side
            chosen.creature = chosen.afterSideSwitchCre[chosen.side]
            refresh()
            break
        case "collapse":
            battleHelper_display(false);
            [...chat.children].forEach(child=>{
                if (child.tagName == "P") child.remove()
            });
            refresh_button.innerHTML = "Открыть";

            set_Display([select, side_button, collapse_button, document.querySelector("#chosen_cre_heading")], "none")
            break
    }
})
outer_chat.addEventListener('change', function() {
    chosen.creature = select.value
    refresh()
});
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}
}

let defender_obj_id = 0
let selected_id = 0
function battleHelper_display(ifDisplay){
    [...outer_chat.children].forEach(child=>{
        if (["B","BR"].includes(child.tagName) || child.className == "cont"){
            child.style.display = ifDisplay ? "inline" : "none"
        }
    })
}
function refresh(){
    battleHelper_display(true)
    set_Display([select, side_button, collapse_button, document.querySelector("#chosen_cre_heading")], "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.children].forEach(child=>child.remove())
    let found_defender = false
    cre_list.forEach(creature => {
        if (![0,-1].includes(creature.nownumber) && creature.nametxt!="" && creature.side == chosen.side && creature.hero == undefined){
            let option_id = `cre_no${cre_list.indexOf(creature)}`
            select.appendChild(elStringToEl(`#${option_id}`, `<option id = "${option_id}" value = "${creature.nametxt} [${creature.nownumber}]">${creature.nametxt} [${creature.nownumber}] </option>`))
            if (!found_defender) {
                if (`${creature.nametxt} [${creature.nownumber}]` == chosen.creature) found_defender = true
                defender_obj_id = creature.obj_index
                selected_id = [...select.children].indexOf(select.lastChild)
            }
        }
    })
    let headingString = `<div id = "chosen_cre_heading" style="display:inline;">
  <span>Урон по </span><span style="color:#ffffff; font-size: 110%; font-weight: bold;">${cre_list[defender_obj_id-1].nametxt} [${cre_list[defender_obj_id-1].nownumber}] :</span>
</div>`
    let heading1 = document.querySelector("#chosen_cre_heading");
    heading1 && heading1.remove()
    chat.appendChild(elStringToEl("#chosen_cre_heading", headingString))
    cre_list.forEach(creature => {
        if (creature.side == -chosen.side) {
            if (creature.nownumber == 0 || creature.nametxt == "") return
            let dmg = get_dmg_info(creature.obj_index, defender_obj_id)
            let hp = creature.maxhealth
            let practical_overall_hp;
            if (cre_list[defender_obj_id-1].attack>creature.defence){
                practical_overall_hp = hp*creature.nownumber/(1+0.05*Math.abs(cre_list[defender_obj_id-1].attack-creature.defence))
            }
            else {
                practical_overall_hp = hp*creature.nownumber*(1+0.05*Math.abs(cre_list[defender_obj_id-1].attack-creature.defence))
            }
            let koef = (practical_overall_hp/((dmg.max + dmg.min)/2)).toFixed(2)
            let row_id = `row_no${cre_list.indexOf(creature)}`
            let row_html = `<p id = "${row_id}"><span style = "text-decoration: underline;color:#bfbfbf" >${creature.nametxt}</span> [${creature.nownumber}] --> <b style = "color:#bfbfbf">${Math.floor(dmg.min/hp)}-${Math.floor(dmg.max/hp)}</b> существ (${dmg.min}-${dmg.max}) (хп/урон <b>${koef}</b>)  </p>`;
            chat.appendChild(elStringToEl(`#${row_id}`, row_html))
        }
    })
    select.options.item(selected_id).selected = true
}