import React, { useState } from "react"; import { ActionTypes } from "../data/ActionTypes"; import { createProgressBarText } from "../../../utils/helpers/createProgressBarText"; import { formatNumber, convertTimeMsToTimeElapsedString, } from "../../../utils/StringHelperFunctions"; import { stealthIcon, killIcon } from "../data/Icons"; import { BladeburnerConstants } from "../data/Constants"; import { IBladeburner } from "../IBladeburner"; import { IPlayer } from "../../PersonObjects/IPlayer"; interface IProps { bladeburner: IBladeburner; player: IPlayer; action: any; } export function ContractElem(props: IProps): React.ReactElement { const setRerender = useState(false)[1]; const isActive = props.bladeburner.action.type === ActionTypes["Contract"] && props.action.name === props.bladeburner.action.name; const estimatedSuccessChance = props.action.getSuccessChance(props.bladeburner, {est:true}); const computedActionTimeCurrent = Math.min(props.bladeburner.actionTimeCurrent+props.bladeburner.actionTimeOverflow, props.bladeburner.actionTimeToComplete); const maxLevel = (props.action.level >= props.action.maxLevel); const actionTime = props.action.getActionTime(props.bladeburner); const autolevelCheckboxId = `bladeburner-${props.action.name}-autolevel-checkbox`; function onStart() { props.bladeburner.action.type = ActionTypes.Contract; props.bladeburner.action.name = props.action.name; props.bladeburner.startAction(props.player, props.bladeburner.action); setRerender(old => !old); } function increaseLevel() { ++props.action.level; if (isActive) props.bladeburner.startAction(props.player, props.bladeburner.action); setRerender(old => !old); } function decreaseLevel() { --props.action.level; if (isActive) props.bladeburner.startAction(props.player, props.bladeburner.action); setRerender(old => !old); } function onAutolevel(event: React.ChangeEvent) { props.action.autoLevel = event.target.checked; setRerender(old => !old); } return (<>

{isActive ? <>{props.action.name} (IN PROGRESS - {formatNumber(computedActionTimeCurrent, 0)} / {formatNumber(props.bladeburner.actionTimeToComplete, 0)}) : <>{props.action.name} }

{isActive ?

{createProgressBarText({progress:computedActionTimeCurrent / props.bladeburner.actionTimeToComplete})}

: <> Start }

            
                {props.action.getSuccessesNeededForNextLevel(BladeburnerConstants.ContractSuccessesPerLevel)} successes needed for next level
            
            Level: {props.action.level} / {props.action.maxLevel}
        
{isActive && (WARNING: changing the level will restart the Operation)} ↑ {isActive && (WARNING: changing the level will restart the Operation)} ↓




Estimated success chance: {formatNumber(estimatedSuccessChance*100, 1)}% {props.action.isStealth?stealthIcon:<>}${props.action.isKill?killIcon:<>}
Time Required: {convertTimeMsToTimeElapsedString(actionTime*1000)}
Contracts remaining: {Math.floor(props.action.count)}
Successes: {props.action.successes}
Failures: {props.action.failures}

); } /* // Autolevel Checkbox el.appendChild(createElement("br")); var autolevelCheckboxId = "bladeburner-" + action.name + "-autolevel-checkbox"; el.appendChild(createElement("label", { for:autolevelCheckboxId, innerText:"Autolevel: ",color:"white", tooltip:"Automatically increase contract level when possible", })); const checkboxInput = createElement("input", { type:"checkbox", id: autolevelCheckboxId, checked: action.autoLevel, changeListener: () => { action.autoLevel = checkboxInput.checked; }, }); el.appendChild(checkboxInput); */