⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 entityencoder.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     *          was passed.     */    private static String formatEquipment( int index, Mounted mount,                                           Entity entity ) {        StringBuffer output = new StringBuffer();        // null in, null out.        if ( null == mount ) return null;        // Format this piece of equipment.        output.append( "<equipment index=\"" );        output.append( String.valueOf(index) );        output.append( "\" type=\"" );        output.append( mount.getType().getInternalName() );        output.append( "\" location=\"" );        output.append( String.valueOf(mount.getLocation()) );        output.append( "\" isRear=\"" );        output.append( mount.isRearMounted() ? "true" : "false" );        if ( mount.getType() instanceof AmmoType ) {            output.append( "\" shots=\"" );            output.append( String.valueOf(mount.getShotsLeft()) );        }        output.append( "\" curMode=\"" );        output.append( mount.curMode().getName() );        output.append( "\" pendingMode=\"" );        output.append( mount.pendingMode().getName() );        output.append( "\" linkedRef=\"" );        if ( null == mount.getLinked() ) {            output.append( "N/A" );        } else {            output.append( String.valueOf( entity.getEquipmentNum                                           (mount.getLinked()) ) );        }        output.append( "\" foundCrits=\"" );        output.append( String.valueOf(mount.getFoundCrits()) );        output.append( "\" isUsedThisRound=\"" );        output.append( mount.isUsedThisRound() ? "true" : "false" );        output.append( "\" isBreached=\"" );        output.append( mount.isBreached() ? "true" : "false" );        output.append( "\" isHit=\"" );        output.append( mount.isHit() ? "true" : "false" );        output.append( "\" isDestroyed=\"" );        output.append( mount.isDestroyed() ? "true" : "false" );        output.append( "\" isMissing=\"" );        output.append( mount.isMissing() ? "true" : "false" );        output.append( "\" isJammed=\"" );        output.append( mount.isJammed() ? "true" : "false" );        output.append( "\" isPendingDump=\"" );        output.append( mount.isPendingDump() ? "true" : "false" );        output.append( "\" isDumping=\"" );        output.append( mount.isDumping() ? "true" : "false" );        output.append( "\" isSplit=\"" );        output.append( mount.isSplit() ? "true" : "false" );        output.append( "\" isFired=\"" );        output.append( mount.isFired() ? "true" : "false" );        output.append( "\"/>" );        // Return a String.        return output.toString();    }    /**     * Produce a string describing the equipment in a critical slot.     *     * @param   slot - the <code>CriticalSlot</code> being encoded.     * @param   mount - the <code>Mounted</code> object of the equipment.     *          This value should be <code>null</code> for a slot with     *          system equipment.     * @return  a <code>String</code> describing the slot.     */    private static String formatSlot( CriticalSlot slot, Mounted mount ) {        StringBuffer output = new StringBuffer();        // Don't forget... slots start at index 1.        output.append( "<slot index=\"" );        output.append( String.valueOf(slot.getIndex()+1) );        output.append( "\" type=\"" );        if ( mount == null ) {            output.append( "System" );        } else {            output.append( mount.getType().getInternalName() );            if ( mount.isRearMounted() ) {                output.append( "\" isRear=\"true" );            }            if ( mount.getType() instanceof AmmoType ) {                output.append( "\" shots=\"" );                output.append( String.valueOf                                (mount.getShotsLeft()) );            }        }        output.append( "\" isHit=\"" );        output.append( slot.isHit() ? "true" : "false" );        output.append( "\" isDestroyed=\"" );        output.append( slot.isDestroyed() ? "true" : "false" );        output.append( "\" isMissing=\"" );        output.append( slot.isMissing() ? "true" : "false" );        output.append( "\" isBreached=\"" );        output.append( slot.isBreached() ? "true" : "false" );        output.append( "\" isHittable=\"" );        output.append( slot.isEverHittable() ? "true" : "false" );        output.append( "\"/>" );        // Return a String.        return output.toString();    }    /**     * Helper function that generates a string identifying the state of     * the locations for an entity.     *     * @param   entity - the <code>Entity</code> whose location state is needed     */    private static String getLocString( Entity entity ) {        boolean isMech = entity instanceof Mech;        StringBuffer output = new StringBuffer();        // Walk through the locations for the entity,        // and only record damage and ammo.        for ( int loc = 0; loc < entity.locations(); loc++ ) {            // Add this location to the output string.            output.append( "<location index=\"" );            output.append( String.valueOf(loc) );            output.append( "\"> " );            // Record values of armor and internal structure,            // unless the section never has armor.            if ( entity.getOInternal(loc) != IArmorState.ARMOR_NA ) {                output.append( "<armor points=\"" );                output.append( String.valueOf(entity.getArmor(loc)) );                output.append( "\"/>" );                output.append( "<armor points=\"" );                output.append( String.valueOf(entity.getInternal(loc)) );                output.append( "\" type=\"Internal\"/>" );                if ( entity.hasRearArmor(loc) ) {                    output.append( "<armor points=\"" );                    output.append(String.valueOf(entity.getArmor(loc, true)));                    output.append( "\" type=\"Rear\"/>" );                }            }            // Walk through the slots in this location.            for ( int loop = 0; loop < entity.getNumberOfCriticals(loc);                  loop++ ) {                // Get this slot.                CriticalSlot slot = entity.getCritical( loc, loop );                // Did we get a slot?                if ( null == slot ) {                    // Nope.  Record missing actuators on Biped Mechs.                    if ( isMech && !entity.entityIsQuad() &&                         ( loc == Mech.LOC_RARM || loc == Mech.LOC_LARM ) &&                         ( loop == 2 || loop == 3 ) ) {                        output.append( "<slot index=\"" );                        output.append( String.valueOf(loop+1) );                        output.append( "\" type=\"Empty\"/>" );                    }                } else {                    // Yup.  If the equipment isn't a system, get it.                    Mounted mount = null;                    if ( CriticalSlot.TYPE_EQUIPMENT == slot.getType() ) {                        mount = entity.getEquipment( slot.getIndex() );                    }                    // Format the slot.                    output.append( formatSlot( slot, mount ) );                } // End have-slot            } // Check the next slot in this location            // Tanks don't have slots, and Protomechs only have            // system slots, so we have to handle their ammo specially.            if ( entity instanceof Tank ||                 entity instanceof Protomech ) {                for (Mounted mount : entity.getAmmo()) {                    // Is this ammo in the current location?                    if ( mount.getLocation() == loc ) {                        output.append( "<slot index=\"N/A\" type=\"" );                        output.append( mount.getType().getInternalName() );                        output.append( "\" shots=\"" );                        output.append( String.valueOf(mount.getShotsLeft()) );                        output.append( "\"/>" );                    }                } // Check the next ammo.            } // End is-tank-or-proto            // Finish off the location            output.append( "</location>" );        } // Handle the next location        // Convert the output into a String and return it.        return output.toString();    } // End private static String getLocString( Entity )    /**     * Helper function to decode the pilot (crew) of an <code>Entity</code>     * object from the passed node.     *     * @param   node - the <code>ParsedXML</code> node for this object.     *          This value must not be <code>null</code>.     * @param   entity - the <code>Entity</code> the decoded object belongs to.     * @throws  IllegalArgumentException if the node is     *          <code>null</code>.     * @throws  IllegalStateException if the node does not     *          contain a valid <code>Entity</code>.     */    private static void decodePilot( ParsedXML node, Entity entity ) {        // TODO : implement me    }    /**     * Helper function to decode the equipment of an <code>Entity</code>     * object from the passed node.     *     * @param   node - the <code>ParsedXML</code> node for this object.     *          This value must not be <code>null</code>.     * @param   entity - the <code>Entity</code> the decoded object belongs to.     * @throws  IllegalArgumentException if the node is     *          <code>null</code>.     * @throws  IllegalStateException if the node does not     *          contain a valid <code>Entity</code>.     */    private static void decodeEntityEquipment( ParsedXML node, Entity entity ) {        // TODO : implement me    }    /**     * Helper function to decode a location of an <code>Entity</code>     * object from the passed node.     *     * @param   node - the <code>ParsedXML</code> node for this object.     *          This value must not be <code>null</code>.     * @param   entity - the <code>Entity</code> the decoded object belongs to.     * @throws  IllegalArgumentException if the node is     *          <code>null</code>.     * @throws  IllegalStateException if the node does not     *          contain a valid <code>Entity</code>.     */    private static void decodeLocation( ParsedXML node, Entity entity ) {        // TODO : implement me    }    /**     * Helper function to decode the inferno rounds on an <code>Entity</code>     * object from the passed node.     *     * @param   node - the <code>ParsedXML</code> node for this object.     *          This value must not be <code>null</code>.     * @param   entity - the <code>Entity</code> the decoded object belongs to.     * @throws  IllegalArgumentException if the node is     *          <code>null</code>.     * @throws  IllegalStateException if the node does not     *          contain a valid <code>Entity</code>.     */    private static void decodeInferno( ParsedXML node, Entity entity ) {        String attrStr = null;        int attrVal = 0;        // Did we get a null node?        if ( null == node ) {            throw new IllegalArgumentException( "The inferno is null." );        }        // Make sure that the node is for a EntityData object.        if ( !node.getName().equals( "inferno" ) ) {            throw new IllegalStateException( "Not passed a inferno node." );        }        // Try to find the inferno detail nodes.        Enumeration details = node.elements();        while ( details.hasMoreElements() ) {            ParsedXML detail = (ParsedXML)                 details.nextElement();            // Have we found the Arrow IV inferno detail?            if ( detail.getName().equals("arrowiv") ) {                // Get the burn turns attribute.                attrStr = detail.getAttribute( "turns" );                if ( null == attrStr ) {                    throw new IllegalStateException                        ( "Couldn't decode the burn turns for an Arrow IV inferno round." );                }                // Try to pull the value from the string                try {                    attrVal = Integer.parseInt( attrStr );                }                catch ( NumberFormatException exp ) {                    throw new IllegalStateException                        ( "Couldn't get an integer from " + attrStr );                }                // Add the number of Arrow IV burn turns.                entity.infernos.add( InfernoTracker.INFERNO_IV_TURN,                                     attrVal );            } // End found-arrowiv-detail            // Have we found the standard inferno entry?            else if ( detail.getName().equals("standard") ) {                // Get the burn turns attribute.                attrStr = detail.getAttribute( "turns" );                if ( null == attrStr ) {                    throw new IllegalStateException                        ( "Couldn't decode the burn turns for a standard inferno round." );                }                // Try to pull the value from the string                try {                    attrVal = Integer.parseInt( attrStr );                }                catch ( NumberFormatException exp ) {                    throw new IllegalStateException                        ( "Couldn't get an integer from " + attrStr );                }                // Add the number of standard burn turns.                entity.infernos.add( InfernoTracker.STANDARD_TURN,                                     attrVal );            } // End found-standard-detail        } // Handle the next detail node.    }    /**     * Helper function to decode a <code>Entity</code> object from the     * passed node.     *     * @param   node - the <code>ParsedXML</code> node for this object.     *          This value must not be <code>null</code>.     * @param   game - the <code>IGame</code> the decoded object belongs to.     * @return  the <code>Entity</code> object based on the node.     * @throws  IllegalArgumentException if the node is     *          <code>null</code>.     * @throws  IllegalStateException if the node does not     *          contain a valid <code>Entity</code>.     */    private static Entity decodeEntityData( ParsedXML node, IGame game ) {        String attrStr = null;        int attrVal = 0;        boolean attrTrue = false;        Entity entity = null;        Coords coords = null;        ParsedXML actionNode = null;        ParsedXML narcNode = null;        ParsedXML infernoNode = null;        ParsedXML loadedUnitsNode = null;        // Did we get a null node?        if ( null == node ) {            throw new IllegalArgumentException( "The entityData is null." );        }        // Make sure that the node is for a EntityData object.        if ( !node.getName().equals( "entityData" ) ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -