Search in sources :

Example 1 with ProtomechArmor

use of megamek.common.verifier.TestProtomech.ProtomechArmor in project megameklab by MegaMek.

the class PMStructureTab method createArmorMountsAndSetArmorType.

private void createArmorMountsAndSetArmorType(EquipmentType armor) {
    ProtomechArmor pmArmor = ProtomechArmor.getArmor(EquipmentType.getArmorType(armor));
    List<Mounted> armorMounts = getProtomech().getMisc().stream().filter(m -> EquipmentType.getArmorType(m.getType()) != EquipmentType.T_ARMOR_UNKNOWN).collect(Collectors.toList());
    for (Mounted m : armorMounts) {
        UnitUtil.removeMounted(getProtomech(), m);
    }
    if (pmArmor == null) {
        getProtomech().setArmorType(EquipmentType.T_ARMOR_STANDARD);
        getProtomech().setArmorTechLevel(TechConstants.T_ALL_CLAN);
        return;
    } else {
        getProtomech().setArmorType(pmArmor.getType());
        getProtomech().setArmorTechLevel(pmArmor.getArmorTech());
    }
    if (pmArmor.getTorsoSlots() > 0) {
        if (freeUpSpace(Protomech.LOC_TORSO, pmArmor.getTorsoSlots())) {
            try {
                Mounted mount = new Mounted(getProtomech(), pmArmor.getArmorEqType());
                getProtomech().addEquipment(mount, Protomech.LOC_TORSO, false);
                return;
            } catch (LocationFullException ignored) {
            // fall through
            }
        }
        JOptionPane.showMessageDialog(null, "Requires free torso slot. Resetting to Standard Armor", "Location Full", JOptionPane.INFORMATION_MESSAGE);
        getProtomech().setArmorType(EquipmentType.T_ARMOR_STANDARD);
        getProtomech().setArmorTechLevel(TechConstants.T_ALL_CLAN);
        panArmor.setFromEntity(getProtomech());
    }
}
Also used : IArmorState(megamek.common.IArmorState) ProtomekBuildListener(megameklab.ui.listeners.ProtomekBuildListener) RefreshListener(megameklab.ui.util.RefreshListener) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) TestEntity(megamek.common.verifier.TestEntity) EquipmentType(megamek.common.EquipmentType) EntitySource(megameklab.ui.EntitySource) Mounted(megamek.common.Mounted) ITab(megameklab.ui.util.ITab) BorderLayout(java.awt.BorderLayout) ITechManager(megamek.common.ITechManager) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) ArmorAllocationView(megameklab.ui.generalUnit.ArmorAllocationView) TechConstants(megamek.common.TechConstants) LocationFullException(megamek.common.LocationFullException) BAProtoArmorView(megameklab.ui.generalUnit.BAProtoArmorView) Engine(megamek.common.Engine) BorderFactory(javax.swing.BorderFactory) EntityMovementMode(megamek.common.EntityMovementMode) ProtomechArmor(megamek.common.verifier.TestProtomech.ProtomechArmor) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) Collectors(java.util.stream.Collectors) BasicInfoView(megameklab.ui.generalUnit.BasicInfoView) Box(javax.swing.Box) ArmorAllocationListener(megameklab.ui.listeners.ArmorAllocationListener) UnitUtil(megameklab.util.UnitUtil) Protomech(megamek.common.Protomech) Dimension(java.awt.Dimension) List(java.util.List) TestProtomech(megamek.common.verifier.TestProtomech) JLabel(javax.swing.JLabel) SimpleTechLevel(megamek.common.SimpleTechLevel) MiscType(megamek.common.MiscType) Optional(java.util.Optional) MovementView(megameklab.ui.generalUnit.MovementView) GridBagLayout(java.awt.GridBagLayout) Entity(megamek.common.Entity) JPanel(javax.swing.JPanel) ProtomechArmor(megamek.common.verifier.TestProtomech.ProtomechArmor) LocationFullException(megamek.common.LocationFullException) Mounted(megamek.common.Mounted)

Aggregations

BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 BorderFactory (javax.swing.BorderFactory)1 Box (javax.swing.Box)1 BoxLayout (javax.swing.BoxLayout)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JOptionPane (javax.swing.JOptionPane)1 JPanel (javax.swing.JPanel)1 SwingConstants (javax.swing.SwingConstants)1 Engine (megamek.common.Engine)1 Entity (megamek.common.Entity)1 EntityMovementMode (megamek.common.EntityMovementMode)1 EquipmentType (megamek.common.EquipmentType)1