import React from "react"; import {IWeapon, IWeaponPiercing} from "../types/IUnit"; import { Accordion, AccordionDetails, AccordionSummary, Grid2, Paper, styled, Table, TableBody, TableCell, tableCellClasses, TableContainer, TableHead, TableRow, ToggleButton, ToggleButtonGroup } from "@mui/material"; import ArmorType from "./ArmorType"; import ArmorTypeNames from "../types/ArmorTypeValues"; import {IconUrl} from "../core/api"; import {ExpandMore} from "@mui/icons-material"; import Sergeant from "./Sergeant"; interface IWeaponProps { weapon: IWeapon, isDefault: Boolean, } interface IWeaponState { currentTable: "dps" | "one hit", } class Weapon extends React.Component { public static defaultProps = { isDefault: false }; humanReadableName(unit: string) { const firstUpper = String(unit).charAt(0).toUpperCase() + String(unit).slice(1); return firstUpper.replaceAll('_', ' ').replace('.rgd', ''); } constructor(props: any) { super(props); this.state = ({ currentTable: 'dps' }); } getPiercingK(armorType: string): number { const weaponPiercing = this.props.weapon.weaponArmorPiercing.find((p) => p.armorType.name === armorType) return (typeof weaponPiercing !== "undefined" ? weaponPiercing.piercingValue : 10) / 100 } handleChange = (e: React.MouseEvent, selectedDamageTable: String | null) => { this.setState({ currentTable: selectedDamageTable }); } render() { const weapon = this.props.weapon const dpsK = (this.state.currentTable == "dps") ? weapon.accuracy * (1 / (weapon.reloadTime - (weapon.reloadTime % 0.125))) : 1 const infLowPiercing = this.getPiercingK(ArmorTypeNames.InfantryLow) const infMedPiercing = this.getPiercingK(ArmorTypeNames.InfantryMedium) const infHighPiercing = this.getPiercingK(ArmorTypeNames.InfantryHigh) const infHeavyMedPiercing = this.getPiercingK(ArmorTypeNames.InfantryHeavyMedium) const infHeavyHighPiercing = this.getPiercingK(ArmorTypeNames.InfantryHeavyMedium) const demonPiercing = this.getPiercingK(ArmorTypeNames.DemonMedium) const demonHighPiercing = this.getPiercingK(ArmorTypeNames.DemonHigh) const commanderPiercing = this.getPiercingK(ArmorTypeNames.Commander) const airPiercing = this.getPiercingK(ArmorTypeNames.Air) const vehLowPiercing = this.getPiercingK(ArmorTypeNames.VehicleLow) const vehMedPiercing = this.getPiercingK(ArmorTypeNames.VehicleMedium) const vehHighPiercing = this.getPiercingK(ArmorTypeNames.VehicleHigh) const buildingLowPiercing = this.getPiercingK(ArmorTypeNames.BuildingLow) const buildingMedPiercing = this.getPiercingK(ArmorTypeNames.BuildingMedium) const buildingHighPiercing = this.getPiercingK(ArmorTypeNames.BuildingHigh) const getTotalDamage = (damagePiercing: number, isAir: boolean = false) => { if (!isAir && !weapon.canAttackGround && !weapon.isMeleeWeapon) return "" if (isAir && !weapon.canAttackAir) return "" var minDamage = damagePiercing * weapon.minDamage var maxDamage = damagePiercing * weapon.maxDamage if (minDamage < weapon.minDamageValue) { minDamage = weapon.minDamageValue } if (maxDamage < weapon.minDamageValue) { maxDamage = weapon.minDamageValue } const averageDmg = (minDamage + maxDamage) / 2 return (averageDmg * dpsK).toFixed(2) } const getMoraleDamage = () => { return (weapon.moraleDamage * dpsK / 2).toFixed(2) } const StyledTableCell = styled(TableCell)(({theme}) => ({ [`&.${tableCellClasses.head}`]: { backgroundColor: "rgb(234, 234, 234)", color: theme.palette.common.white, paddingLeft: 10 }, [`&.${tableCellClasses.body}`]: { fontSize: 13, paddingLeft: 10, }, })); return (
} aria-controls="panel1-content" id="panel1-header" > {!this.props.isDefault && weapon.icon && weapon.haveEquipButton ? : ( weapon.isMeleeWeapon ? : )} {weapon.name ? weapon.name : this.humanReadableName(weapon.filename)}
{this.props.isDefault ? "Default weapon" : weapon.description}
{/*Damage*/} Base damage {weapon.minDamage} {weapon.maxDamage !== weapon.minDamage && -weapon.maxDamage} Accuracy {weapon.accuracy.toFixed(3).replace(/[,.]?0+$/, '')} Accuracy moving {weapon.setupTime === 0 && weapon.accuracy - weapon.accuracyReductionMoving > 0 ? (weapon.accuracy - weapon.accuracyReductionMoving).toFixed(3).replace(/[,.]?0+$/, '') : "-"}
Reload time {weapon.reloadTime} Range {weapon.maxRange ? (weapon.maxRange) : "-"} {weapon.minRange ? "(min " + (weapon.minRange) + ")" : ""} Damage radius {weapon.damageRadius ? (weapon.damageRadius) : "-"}
Cost {(weapon.costRequisition > 0 || weapon.costPower > 0) ? {weapon.costRequisition > 0 &&    {weapon.costRequisition.toFixed(0)}} {weapon.costPower > 0 &&    {weapon.costPower.toFixed(0)}} : - } Setup time {weapon.setupTime != 0 ? (weapon.setupTime).toFixed(3).replace(/[,.]?0+$/, '') : "-"} Throw force {weapon.throwForceMin != 0 ? weapon.throwForceMin + " - " + weapon.throwForceMax : "-"}
Dps One hit average damage {getTotalDamage(infLowPiercing)} {getTotalDamage(infMedPiercing)} {getTotalDamage(infHighPiercing)} {getTotalDamage(infHeavyMedPiercing)} {getTotalDamage(infHeavyHighPiercing)} {getTotalDamage(commanderPiercing)} {getTotalDamage(demonPiercing)} {getTotalDamage(demonHighPiercing)} {getTotalDamage(airPiercing, true)} {getTotalDamage(vehLowPiercing)} {getTotalDamage(vehMedPiercing)} {getTotalDamage(vehHighPiercing)} {getTotalDamage(buildingLowPiercing)} {getTotalDamage(buildingMedPiercing)} {getTotalDamage(buildingHighPiercing)} {getMoraleDamage()}
{weapon.filename}
); } } export default Weapon;