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

📄 xmlstreamparser.java

📁 MegaMek is a networked Java clone of BattleTech, a turn-based sci-fi boardgame for 2+ players. Fight
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            } // End ready-for-location        } else if (name.equals(TURRETLOCK)) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found turret lock outside of an Entity.\n" );            } else if (!(this.entity instanceof Tank)) {                this.warning.append                    ( "Turret crit record found outside a Tank.\n" );            }            String value = (String) attr.get( DIRECTION );            try {                int turDir = Integer.parseInt(value);                ((Tank)this.entity).setSecondaryFacing(turDir);                ((Tank)this.entity).lockTurret();            } catch (Exception e) {                System.err.println(e);                e.printStackTrace();                this.warning.append                    ( "Invalid turret lock direction value in movement tag.\n" );            }        } else if (name.equals(MOVEMENT)) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found movement crit outside of an Entity.\n" );            } else if (!(this.entity instanceof Tank)) {                this.warning.append                    ( "Movement crit record found outside a Tank.\n" );            }            String value = (String) attr.get( SPEED );            if (value.equals("immobile")) {                ((Tank)(this.entity)).immobilize();            } else {                try {                    int newSpeed = Integer.parseInt(value);                    this.entity.setOriginalWalkMP(newSpeed);                } catch (Exception e) {                    this.warning.append                        ( "Invalid speed value in movement tag.\n" );                }            }        } else if ( name.equals( ARMOR ) ) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found armor outside of an Entity.\n" );            }            // Are we in the outside of parsing an Entity's location?            else if ( this.loc == Entity.LOC_NONE ) {                this.warning.append                    ( "Found armor while outside of a location.\n" );            }            // Handle the location.            else {                // Look for the element's attributes.                String points = (String) attr.get( POINTS );                String type = (String) attr.get( TYPE );                // Did we find required attributes?                if ( points == null || points.length() == 0 ) {                    this.warning.append                        ( "Could not find points for armor.\n" );                }                else {                    // Try to get a good points value.                    int pointsVal = -1;                    try {                        pointsVal = Integer.parseInt( points );                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( points.equals( NA ) ) {                        pointsVal = IArmorState.ARMOR_NA;                    }                    else if ( points.equals( DESTROYED ) ) {                        pointsVal = IArmorState.ARMOR_DESTROYED;                    }                    else if ( pointsVal < 0 || pointsVal > 100 ) {                        this.warning.append( "Found invalid points value: " )                            .append( points )                            .append( ".\n" );                        return;                    }                    // Assign the points to the correct location.                    // Sanity check the armor value before setting it.                    if ( type == null || type.equals( FRONT ) ) {                        if ( this.entity.getOArmor(this.loc) < pointsVal ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " does not start with " )                                .append( pointsVal )                                .append( " points of armor for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else {                            this.entity.setArmor( pointsVal, this.loc );                        }                    }                    else if ( type.equals( INTERNAL ) ) {                        if ( this.entity.getOInternal(this.loc) < pointsVal ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " does not start with " )                                .append( pointsVal )                                .append( " points of internal structure for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else {                            this.entity.setInternal( pointsVal, this.loc );                        }                    }                    else if ( type.equals( REAR ) ) {                        if ( !this.entity.hasRearArmor( this.loc ) ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " has no rear armor for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else if ( this.entity.getOArmor(this.loc, true) <                                    pointsVal ) {                            this.warning.append( "The entity, " )                                .append( this.entity.getShortName() )                                .append( " does not start with " )                                .append( pointsVal )                                .append( " points of rear armor for location: " )                                .append( this.loc )                                .append( ".\n" );                        } else {                            this.entity.setArmor( pointsVal, this.loc, true );                        }                    }                } // End have-required-fields            } // End ready-for-armor        }        else if ( name.equals( SLOT ) ) {            // Are we in the outside of an Entity?            if ( this.entity == null ) {                this.warning.append                    ( "Found a slot outside of an Entity.\n" );            }            // Are we in the outside of parsing an Entity's location?            else if ( this.loc == Entity.LOC_NONE ) {                this.warning.append                    ( "Found a slot while outside of a location.\n" );            }            // Handle the location.            else {                // Look for the element's attributes.                String index = (String) attr.get( INDEX );                String type = (String) attr.get( TYPE );                String rear = (String) attr.get( IS_REAR );                String shots = (String) attr.get( SHOTS );                String hit = (String) attr.get( IS_HIT );                String destroyed = (String) attr.get( IS_DESTROYED );                String munition = (String) attr.get( MUNITION );                // Did we find required attributes?                if ( index == null || index.length() == 0 ) {                    this.warning.append                        ( "Could not find index for slot.\n" );                }                else if ( type == null || type.length() == 0 ) {                    this.warning.append                        ( "Could not find type for slot.\n" );                }                else {                    // Try to get a good index value.                    // Remember, slot index starts at 1.                    int indexVal = -1;                    try {                        indexVal = Integer.parseInt( index );                        indexVal -= 1;                    } catch ( NumberFormatException excep ) {                        // Handled by the next if test.                    }                    if ( index.equals( NA ) ) {                        indexVal = IArmorState.ARMOR_NA;                        // Tanks don't have slots, and Protomechs only have                        // system slots, so we have to handle the ammo specially.                        if ( entity instanceof Tank ||                             entity instanceof Protomech ) {                            // Get the saved ammo load.                            EquipmentType newLoad =                                 EquipmentType.get( type );                            if ( newLoad instanceof AmmoType ) {                                int counter = -1;                                Iterator<Mounted> ammo = entity.getAmmo().iterator();                                while ( ammo.hasNext() &&                                        counter < this.locAmmoCount ) {                                    // Is this mounted in the current location?                                    Mounted mounted = ammo.next();                                    if ( mounted.getLocation() == loc ) {                                        // Increment the loop counter.                                        counter++;                                        // Is this the one we want to handle?                                        if ( counter == this.locAmmoCount ) {                                            // Increment the counter of ammo                                            // handled for this location.                                            this.locAmmoCount++;                                            // Reset transient values.                                            mounted.restore();                                            // Try to get a good shots value.                                            int shotsVal = -1;                                            try {                                                shotsVal = Integer.parseInt                                                    ( shots );                                            } catch ( NumberFormatException                                                      excep ) {                                                // Handled by the next if test.                                            }                                            if ( shots.equals( NA ) ) {                                                shotsVal = IArmorState.ARMOR_NA;                                                this.warning.append( "Expected to find number of shots for " )                                                    .append( type )                                                    .append( ", but found " )                                                    .append( shots )                                                    .append( " instead.\n" );                                            }                                            else if ( shotsVal < 0 || shotsVal > 200 ) {                                                this.warning.append( "Found invalid shots value for slot: " )                                                    .append( shots )                                                    .append( ".\n" );                                            } else {                                                // Change to the saved                                                // ammo type and shots.                                                mounted.changeAmmoType                                                    ( (AmmoType) newLoad );                                                mounted.setShotsLeft                                                    ( shotsVal );                                            } // End have-good-shots-value                                            // Stop looking for a match.                                            break;                                        } // End found-match-for-slot                                    } // End ammo-in-this-loc                                } // Check the next ammo.                                                        } else {                                // Bad XML equipment.                                this.warning.append( "XML file lists " )                                    .append( type )                                    .append( " equipment at location " )                                    .append( this.loc )                                    .append( ".  XML parser expected ammo.\n" );                            } // End not-ammo-type                        } // End is-tank                        // TODO: handle slotless equipment.                        return;                    }                    else if ( indexVal < 0 || indexVal > 12 ) {                        this.warning.append( "Found invalid index value for slot: " )                            .append( index )                            .append( ".\n" );                        return;                    }                    // Is this index valid for this entity?                    if ( indexVal > entity.getNumberOfCriticals(this.loc) ) {                        this.warning.append( "The entity, " )                            .append( this.entity.getShortName() )                            .append( " does not have " )                            .append( index )                            .append( " slots in location " )                            .append( this.loc )                            .append( ".\n" );                        return;                    }                    // Try to get a good isHit value.                    boolean hitFlag = false;                    try {                        if ( hit != null ) {                            hitFlag = hit.equals( "true" );                        }                    } catch ( Throwable excep ) {

⌨️ 快捷键说明

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