|
import { calculate_damage_range } from "../helpers"; |
|
import { injectIntoParent, replaceInParentFunction, wrapFunction } from "../helpers/inject"; |
|
|
|
/** |
|
* This function will add links to selected inventory items |
|
* to directly send items to nearby characters. |
|
* The whole stack will be sent so be careful. |
|
*/ |
|
function addSendItemShortcut(selector: string) { |
|
const targets = []; |
|
|
|
const values = Object.values(parent.entities); |
|
|
|
for (let index = 0; index < values.length; index++) { |
|
const entity = values[index]; |
|
|
|
if (!is_character(entity)) { |
|
continue; |
|
} |
|
|
|
if (distance(character, entity) > 400) { |
|
continue; |
|
} |
|
|
|
targets.push(entity); |
|
} |
|
|
|
targets.sort((a, b) => a.owner.localeCompare(b.owner)); |
|
|
|
if (targets.length && selector === ".inventory-item") { |
|
for (let index = 0; index < targets.length; index++) { |
|
const target = targets[index]; |
|
|
|
// @ts-ignore |
|
html += parent.button_line({ |
|
name: `<span style='color:gray'>[s]</span><span style='color:white'>:</span> Send to ${target.name}`, |
|
// @ts-ignore |
|
onclick: `parent.code_eval(\`send_item('${target.name}', ${args.num}, 10000)\`)`, |
|
// @ts-ignore |
|
color: colors.gold, |
|
}); |
|
} |
|
} |
|
} |
|
|
|
function addStandInfoToComputer() { |
|
// @ts-ignore |
|
html += |
|
"<div class='clickable' onclick='socket.emit(\"trade_history\",{});' style=\"color: #44484F\">TRADE HISTORY</div>"; |
|
|
|
if (character.stand) { |
|
// @ts-ignore |
|
html += |
|
"<div class='clickable' onclick='close_merchant();' style=\"color: #8E5E2C\">CLOSE</div>"; |
|
} else { |
|
// @ts-ignore |
|
html += `<div class='clickable' onclick='open_merchant(locate_item("computer"));' style="color: #8E5E2C">OPEN</div>`; |
|
} |
|
} |
|
|
|
const RENDER_GOLD2_MARKER = `html+=bold_prop_line("Base Gold",G.base_gold[args.monster][mname]+" <span class='gray'>("+G.maps[mname].name+")</span>","gold"); |
|
}`; |
|
function addAnotherGoldLineForMonsters() { |
|
// @ts-ignore |
|
for (mname in G.base_gold[args.monster]) { |
|
// @ts-ignore |
|
if (!G.maps[mname] || G.maps[mname].ignore) continue; |
|
|
|
// @ts-ignore |
|
html += bold_prop_line( |
|
"With goldm", |
|
// @ts-ignore |
|
`[${to_pretty_num( |
|
// @ts-ignore |
|
Math.round(G.base_gold[args.monster][mname] * character.goldm * 0.64), |
|
)} - ${to_pretty_num( |
|
// @ts-ignore |
|
Math.round(G.base_gold[args.monster][mname] * character.goldm * (0.64 + 0.8)), |
|
)}] <span class='gray'>(${ |
|
// @ts-ignore |
|
G.maps[mname].name |
|
})</span>`, |
|
"gold", |
|
); |
|
} |
|
} |
|
|
|
const RENDER_DAMAGE_MARKER = ` if(item.achievements) //args.monster`; |
|
function addDamageRange() { |
|
// @ts-ignore |
|
if (args.monster) { |
|
// @ts-ignore |
|
const dmg = inj__calculate_damage_range(item, "attack"); |
|
|
|
// @ts-ignore |
|
html += bold_prop_line( |
|
"Damage range", |
|
// @ts-ignore |
|
`${Math.floor(dmg[0])} - ${Math.floor(dmg[1])}`, |
|
// @ts-ignore |
|
colors.attack, |
|
); |
|
} |
|
} |
|
|
|
function addSpecialCorner() { |
|
// @ts-ignore |
|
if (actual && actual.p) { |
|
let corner = ""; |
|
|
|
// @ts-ignore |
|
switch (actual.p) { |
|
case "festive": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:#79ff7e'>F</div></div></div>`; |
|
break; |
|
} |
|
case "firehazard": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:#f79b11'>H</div></div></div>`; |
|
break; |
|
} |
|
case "glitched": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:grey'>#</div></div></div>`; |
|
break; |
|
} |
|
case "gooped": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:#64B867'>G</div></div></div>`; |
|
break; |
|
} |
|
case "legacy": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:white''>L</div></div></div>`; |
|
break; |
|
} |
|
case "lucky": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:#00f3ff''>L</div></div></div>`; |
|
break; |
|
} |
|
case "shiny": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:#99b2d8''>S</div></div></div>`; |
|
break; |
|
} |
|
case "superfast": { |
|
corner = `<div class='trruui imu' style='border-color: grey; color:#c681dc''>U</div></div></div>`; |
|
break; |
|
} |
|
default: { |
|
corner = `<div class='trruui imu' style='border-color: black; color:grey''>?</div></div></div>`; |
|
} |
|
} |
|
|
|
// @ts-ignore |
|
html = html.replace(/<\/div><\/div>$/, corner); |
|
} |
|
} |
|
|
|
function extendDropUi() { |
|
const TO_REPLACE = ` if(def[0]*mult>=1) html+="<div style='vertical-align: middle; display: inline-block; font-size: 24px; line-height: 50px; height: 50px; margin-left: 5px; margin-right: 8px'>"+to_pretty_float(def[0]*mult)+" / 1</div>"; |
|
else if(1/(def[0]*mult)>=1.1 && 1/(def[0]*mult)<10 && parseInt(1/(def[0]*mult))*10!=parseInt(10/(def[0]*mult))) html+="<div style='vertical-align: middle; display: inline-block; font-size: 24px; line-height: 50px; height: 50px; margin-left: 5px; margin-right: 8px'>10 / "+to_pretty_num(round(10/(def[0]*mult)))+"</div>"; |
|
else html+="<div style='vertical-align: middle; display: inline-block; font-size: 24px; line-height: 50px; height: 50px; margin-left: 5px; margin-right: 8px'>1 / "+(((1/(def[0]*mult))>=2)&&to_pretty_num(round(1/(def[0]*mult)))||to_pretty_float(1/(def[0]*mult)))+"</div>";`; |
|
|
|
const REPLACEMENT = wrapFunction(() => { |
|
const DISPLAY_HUMAN_PERCENT = false; |
|
const DISPLAY_LUCKM_PROBA = true; |
|
|
|
const __telo_proba = def[0] * mult; |
|
const __telo_proba_percent = Math.min(Math.round(__telo_proba * 10000000) / 100000, 100); |
|
const __telo_proba_luckm = Math.min(__telo_proba * character.luckm, 1); |
|
const __telo_proba_luckm_percent = Math.min( |
|
Math.round(__telo_proba_luckm * 10000) / 100, |
|
100, |
|
); |
|
|
|
if (__telo_proba >= 1) { |
|
html += `<div style="vertical-align: middle; display: inline-block; font-size: 24px; line-height: 50px; height: 50px; margin-left: 5px; margin-right: 8px">`; |
|
html += `<div style="position: relative; white-space: nowrap; display: inline-block;">`; |
|
html += `<span>${to_pretty_float(__telo_proba)} / 1</span>`; |
|
|
|
if (DISPLAY_LUCKM_PROBA) { |
|
html += `<span title="With ${ |
|
character.luckm |
|
} luckm" style="margin-left: 10px; color: #49ff3e;">(${to_pretty_float( |
|
__telo_proba_luckm, |
|
)} / 1)</span>`; |
|
} |
|
|
|
html += `</div></div>`; |
|
} else { |
|
html += `<div style="vertical-align: middle; display: inline-block; font-size: 24px; line-height: 50px; height: 50px; margin-left: 5px; margin-right: 8px">`; |
|
html += `<div style="position: relative; white-space: nowrap; display: inline-block;">`; |
|
html += `<span>1 / ${ |
|
(1 / __telo_proba >= 2 && to_pretty_num(round(1 / __telo_proba))) || |
|
to_pretty_float(1 / __telo_proba) |
|
}</span>`; |
|
|
|
if (DISPLAY_HUMAN_PERCENT && __telo_proba_percent > 0) { |
|
html += `<div style="z-index: 1;position: absolute;top: 1px;left: 0;height: 16px;font-size: 22px;line-height: 13px;display: inline-block;">${__telo_proba_percent}%</div>`; |
|
} |
|
|
|
if (DISPLAY_LUCKM_PROBA) { |
|
html += `<span title="With ${ |
|
character.luckm |
|
} luckm" style="margin-left: 10px; color: #49ff3e;">(1 / ${ |
|
(1 / __telo_proba_luckm >= 2 && to_pretty_num(round(1 / __telo_proba_luckm))) || |
|
to_pretty_float(1 / __telo_proba_luckm) |
|
})</span>`; |
|
} |
|
|
|
html += `</div></div>`; |
|
} |
|
}); |
|
|
|
replaceInParentFunction("render_drop", TO_REPLACE, REPLACEMENT); |
|
} |
|
|
|
function extendTargetTopLeft() { |
|
const RENDER_CHARACTER_MARKER = ` render_character(ctarget);`; |
|
const REPLACEMENT = `${RENDER_CHARACTER_MARKER}render_monster(otarget, true);`; |
|
|
|
replaceInParentFunction("reset_topleft", RENDER_CHARACTER_MARKER, REPLACEMENT); |
|
} |
|
|
|
/** |
|
* Entrypoint to enable UI extensions. |
|
*/ |
|
export function extendUi() { |
|
// ------ render_item |
|
const SEND_ITEM_MARKER = |
|
' if(args.trade && actual && character.slots.helmet && character.slots.helmet.name.startsWith("ghat"))'; |
|
|
|
injectIntoParent("render_item", SEND_ITEM_MARKER, addSendItemShortcut); |
|
|
|
// Everything that should be a stand |
|
replaceInParentFunction("render_item", `item.type=="stand"`, `item.stand`); |
|
|
|
// ------ render_computer |
|
const RENDER_COMPUTER_STAND_MARKER = " $element.html(html);"; |
|
|
|
injectIntoParent("render_computer", RENDER_COMPUTER_STAND_MARKER, addStandInfoToComputer); |
|
|
|
// ------ render_character_sheet add bottom margin |
|
replaceInParentFunction( |
|
// @ts-ignore |
|
"render_character_sheet", |
|
`var html="<div style='background-color: black;`, |
|
`var html="<div style='margin-bottom: 50px; background-color: black;`, |
|
); |
|
|
|
injectIntoParent("render_item", RENDER_GOLD2_MARKER, addAnotherGoldLineForMonsters, true); |
|
|
|
injectIntoParent("render_item", RENDER_DAMAGE_MARKER, addDamageRange, false, { |
|
inj__calculate_damage_range: calculate_damage_range, |
|
}); |
|
|
|
// Cleaner number format for gold |
|
replaceInParentFunction( |
|
"render_item", |
|
`"Base Gold",G.base_gold[args.monster][mname]+"`, |
|
`"Base Gold",to_pretty_num(G.base_gold[args.monster][mname])+"`, |
|
); |
|
|
|
// Let css do its thing with width. |
|
replaceInParentFunction("render_item", `max-width: 240px;`, `max-width: 326px;`); |
|
replaceInParentFunction("render_monster_info", `wwidth:240,`, `wwidth:326,`); |
|
|
|
// Upgrade and compounds are now right above the inventory |
|
replaceInParentFunction( |
|
"render_upgrade_shrine", |
|
`$("#topleftcornerui").html(html);`, |
|
`document.querySelector('#bottomleftcorner').insertAdjacentHTML('afterbegin', html);`, |
|
); |
|
replaceInParentFunction( |
|
"render_compound_shrine", |
|
`$("#topleftcornerui").html(html);`, |
|
`document.querySelector('#bottomleftcorner').insertAdjacentHTML('afterbegin', html);`, |
|
); |
|
|
|
// Add corner with icon for special items |
|
const ITEM_ADD_SPECIAL_MARKER = " return html;"; |
|
|
|
injectIntoParent("item_container", ITEM_ADD_SPECIAL_MARKER, addSpecialCorner); |
|
|
|
// extendTargetTopLeft(); |
|
|
|
extendDropUi(); |
|
} |