Example usage for org.dom4j Element elementIterator

List of usage examples for org.dom4j Element elementIterator

Introduction

In this page you can find the example usage for org.dom4j Element elementIterator.

Prototype

Iterator<Element> elementIterator();

Source Link

Document

Returns an iterator over all this elements child elements.

Usage

From source file:lineage2.gameserver.data.xml.parser.EventParser.java

License:Open Source License

/**
 * Method parseObjects.//from ww w  .ja va 2  s .com
 * @param element Element
 * @return List<Serializable>
 */
private List<Serializable> parseObjects(Element element) {
    if (element == null) {
        return Collections.emptyList();
    }

    List<Serializable> objects = new ArrayList<>(2);

    for (Iterator<?> objectsIterator = element.elementIterator(); objectsIterator.hasNext();) {
        Element objectsElement = (Element) objectsIterator.next();
        final String nodeName = objectsElement.getName();

        if (nodeName.equalsIgnoreCase("boat_point")) {
            objects.add(BoatPoint.parse(objectsElement));
        } else if (nodeName.equalsIgnoreCase("point")) {
            objects.add(Location.parse(objectsElement));
        } else if (nodeName.equalsIgnoreCase("spawn_ex")) {
            objects.add(new SpawnExObject(objectsElement.attributeValue("name")));
        } else if (nodeName.equalsIgnoreCase("door")) {
            objects.add(new DoorObject(Integer.parseInt(objectsElement.attributeValue("id"))));
        } else if (nodeName.equalsIgnoreCase("static_object")) {
            objects.add(new StaticObjectObject(Integer.parseInt(objectsElement.attributeValue("id"))));
        } else if (nodeName.equalsIgnoreCase("combat_flag")) {
            int x = Integer.parseInt(objectsElement.attributeValue("x"));
            int y = Integer.parseInt(objectsElement.attributeValue("y"));
            int z = Integer.parseInt(objectsElement.attributeValue("z"));
            objects.add(new FortressCombatFlagObject(new Location(x, y, z)));
        } else if (nodeName.equalsIgnoreCase("siege_toggle_npc")) {
            int id = Integer.parseInt(objectsElement.attributeValue("id"));
            int fakeId = Integer.parseInt(objectsElement.attributeValue("fake_id"));
            int x = Integer.parseInt(objectsElement.attributeValue("x"));
            int y = Integer.parseInt(objectsElement.attributeValue("y"));
            int z = Integer.parseInt(objectsElement.attributeValue("z"));
            int hp = Integer.parseInt(objectsElement.attributeValue("hp"));
            Set<String> set = Collections.emptySet();

            for (Iterator<?> oIterator = objectsElement.elementIterator(); oIterator.hasNext();) {
                Element sub = (Element) oIterator.next();

                if (set.isEmpty()) {
                    set = new HashSet<>();
                }

                set.add(sub.attributeValue("name"));
            }

            objects.add(new SiegeToggleNpcObject(id, fakeId, new Location(x, y, z), hp, set));
        } else if (nodeName.equalsIgnoreCase("castle_zone")) {
            long price = Long.parseLong(objectsElement.attributeValue("price"));
            objects.add(new CastleDamageZoneObject(objectsElement.attributeValue("name"), price));
        } else if (nodeName.equalsIgnoreCase("zone")) {
            objects.add(new ZoneObject(objectsElement.attributeValue("name")));
        } else if (nodeName.equalsIgnoreCase("ctb_team")) {
            int mobId = Integer.parseInt(objectsElement.attributeValue("mob_id"));
            int flagId = Integer.parseInt(objectsElement.attributeValue("id"));
            Location loc = Location.parse(objectsElement);
            objects.add(new CTBTeamObject(mobId, flagId, loc));
        }
    }

    return objects;
}

From source file:lineage2.gameserver.data.xml.parser.EventParser.java

License:Open Source License

/**
 * Method parseActions.//from  w  w  w.  j av a2s . com
 * @param element Element
 * @param time int
 * @return List<EventAction>
 */
private List<EventAction> parseActions(Element element, int time) {
    if (element == null) {
        return Collections.emptyList();
    }

    IfElseAction lastIf = null;
    List<EventAction> actions = new ArrayList<>(0);

    for (Iterator<?> iterator = element.elementIterator(); iterator.hasNext();) {
        Element actionElement = (Element) iterator.next();

        if (actionElement.getName().equalsIgnoreCase("start")) {
            String name = actionElement.attributeValue("name");
            StartStopAction startStopAction = new StartStopAction(name, true);
            actions.add(startStopAction);
        } else if (actionElement.getName().equalsIgnoreCase("stop")) {
            String name = actionElement.attributeValue("name");
            StartStopAction startStopAction = new StartStopAction(name, false);
            actions.add(startStopAction);
        } else if (actionElement.getName().equalsIgnoreCase("spawn")) {
            String name = actionElement.attributeValue("name");
            SpawnDespawnAction spawnDespawnAction = new SpawnDespawnAction(name, true);
            actions.add(spawnDespawnAction);
        } else if (actionElement.getName().equalsIgnoreCase("despawn")) {
            String name = actionElement.attributeValue("name");
            SpawnDespawnAction spawnDespawnAction = new SpawnDespawnAction(name, false);
            actions.add(spawnDespawnAction);
        } else if (actionElement.getName().equalsIgnoreCase("open")) {
            String name = actionElement.attributeValue("name");
            OpenCloseAction a = new OpenCloseAction(true, name);
            actions.add(a);
        } else if (actionElement.getName().equalsIgnoreCase("close")) {
            String name = actionElement.attributeValue("name");
            OpenCloseAction a = new OpenCloseAction(false, name);
            actions.add(a);
        } else if (actionElement.getName().equalsIgnoreCase("active")) {
            String name = actionElement.attributeValue("name");
            ActiveDeactiveAction a = new ActiveDeactiveAction(true, name);
            actions.add(a);
        } else if (actionElement.getName().equalsIgnoreCase("deactive")) {
            String name = actionElement.attributeValue("name");
            ActiveDeactiveAction a = new ActiveDeactiveAction(false, name);
            actions.add(a);
        } else if (actionElement.getName().equalsIgnoreCase("refresh")) {
            String name = actionElement.attributeValue("name");
            RefreshAction a = new RefreshAction(name);
            actions.add(a);
        } else if (actionElement.getName().equalsIgnoreCase("init")) {
            String name = actionElement.attributeValue("name");
            InitAction a = new InitAction(name);
            actions.add(a);
        } else if (actionElement.getName().equalsIgnoreCase("npc_say")) {
            int npc = Integer.parseInt(actionElement.attributeValue("npc"));
            ChatType chat = ChatType.valueOf(actionElement.attributeValue("chat"));
            int range = Integer.parseInt(actionElement.attributeValue("range"));
            NpcString string = NpcString.valueOf(actionElement.attributeValue("text"));
            NpcSayAction action = new NpcSayAction(npc, range, chat, string);
            actions.add(action);
        } else if (actionElement.getName().equalsIgnoreCase("play_sound")) {
            int range = Integer.parseInt(actionElement.attributeValue("range"));
            String sound = actionElement.attributeValue("sound");
            PlaySound.Type type = PlaySound.Type.valueOf(actionElement.attributeValue("type"));
            PlaySoundAction action = new PlaySoundAction(range, sound, type);
            actions.add(action);
        } else if (actionElement.getName().equalsIgnoreCase("give_item")) {
            int itemId = Integer.parseInt(actionElement.attributeValue("id"));
            long count = Integer.parseInt(actionElement.attributeValue("count"));
            GiveItemAction action = new GiveItemAction(itemId, count);
            actions.add(action);
        } else if (actionElement.getName().equalsIgnoreCase("announce")) {
            String val = actionElement.attributeValue("val");

            if ((val == null) && (time == Integer.MAX_VALUE)) {
                info("Can't get announce time." + getCurrentFileName());
                continue;
            }

            int val2 = val == null ? time : Integer.parseInt(val);
            EventAction action = new AnnounceAction(val2);
            actions.add(action);
        } else if (actionElement.getName().equalsIgnoreCase("if")) {
            String name = actionElement.attributeValue("name");
            IfElseAction action = new IfElseAction(name, false);
            action.setIfList(parseActions(actionElement, time));
            actions.add(action);
            lastIf = action;
        } else if (actionElement.getName().equalsIgnoreCase("ifnot")) {
            String name = actionElement.attributeValue("name");
            IfElseAction action = new IfElseAction(name, true);
            action.setIfList(parseActions(actionElement, time));
            actions.add(action);
            lastIf = action;
        } else if (actionElement.getName().equalsIgnoreCase("else")) {
            if (lastIf == null) {
                info("Not find <if> for <else> tag");
            } else {
                lastIf.setElseList(parseActions(actionElement, time));
            }
        } else if (actionElement.getName().equalsIgnoreCase("say")) {
            ChatType chat = ChatType.valueOf(actionElement.attributeValue("chat"));
            int range = Integer.parseInt(actionElement.attributeValue("range"));
            String how = actionElement.attributeValue("how");
            String text = actionElement.attributeValue("text");
            SysString sysString = SysString.valueOf2(how);
            SayAction sayAction = null;

            if (sysString != null) {
                sayAction = new SayAction(range, chat, sysString, SystemMsg.valueOf(text));
            } else {
                sayAction = new SayAction(range, chat, how, NpcString.valueOf(text));
            }

            actions.add(sayAction);
        } else if (actionElement.getName().equalsIgnoreCase("teleport_players")) {
            String name = actionElement.attributeValue("id");
            TeleportPlayersAction a = new TeleportPlayersAction(name);
            actions.add(a);
        }
    }

    return actions.isEmpty() ? Collections.<EventAction>emptyList() : actions;
}

From source file:lineage2.gameserver.data.xml.parser.FishDataParser.java

License:Open Source License

/**
 * Method readData.//  www . jav a 2 s.c  o  m
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element e = iterator.next();

        if ("fish".equals(e.getName())) {
            MultiValueSet<String> map = new MultiValueSet<>();

            for (Iterator<Attribute> attributeIterator = e.attributeIterator(); attributeIterator.hasNext();) {
                Attribute attribute = attributeIterator.next();
                map.put(attribute.getName(), attribute.getValue());
            }

            getHolder().addFish(new FishTemplate(map));
        } else if ("lure".equals(e.getName())) {
            MultiValueSet<String> map = new MultiValueSet<>();

            for (Iterator<Attribute> attributeIterator = e.attributeIterator(); attributeIterator.hasNext();) {
                Attribute attribute = attributeIterator.next();
                map.put(attribute.getName(), attribute.getValue());
            }

            Map<FishGroup, Integer> chances = new HashMap<>();

            for (Iterator<Element> elementIterator = e.elementIterator(); elementIterator.hasNext();) {
                Element chanceElement = elementIterator.next();
                chances.put(FishGroup.valueOf(chanceElement.attributeValue("type")),
                        Integer.parseInt(chanceElement.attributeValue("value")));
            }

            map.put("chances", chances);
            getHolder().addLure(new LureTemplate(map));
        } else if ("distribution".equals(e.getName())) {
            int id = Integer.parseInt(e.attributeValue("id"));

            for (Iterator<Element> forLureIterator = e.elementIterator(); forLureIterator.hasNext();) {
                Element forLureElement = forLureIterator.next();
                LureType lureType = LureType.valueOf(forLureElement.attributeValue("type"));
                Map<FishGroup, Integer> chances = new HashMap<>();

                for (Iterator<Element> chanceIterator = forLureElement.elementIterator(); chanceIterator
                        .hasNext();) {
                    Element chanceElement = chanceIterator.next();
                    chances.put(FishGroup.valueOf(chanceElement.attributeValue("type")),
                            Integer.parseInt(chanceElement.attributeValue("value")));
                }

                getHolder().addDistribution(id, lureType, chances);
            }
        }
    }
}

From source file:lineage2.gameserver.data.xml.parser.HennaParser.java

License:Open Source License

/**
 * Method readData./*w w  w.  j a va2s  .co m*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element hennaElement = iterator.next();
        int symbolId = Integer.parseInt(hennaElement.attributeValue("symbol_id"));
        int dyeId = Integer.parseInt(hennaElement.attributeValue("dye_id"));
        long price = Integer.parseInt(hennaElement.attributeValue("price"));
        long drawCount = hennaElement.attributeValue("draw_count") == null ? 10
                : Integer.parseInt(hennaElement.attributeValue("draw_count"));
        int wit = Integer.parseInt(hennaElement.attributeValue("wit"));
        int str = Integer.parseInt(hennaElement.attributeValue("str"));
        int _int = Integer.parseInt(hennaElement.attributeValue("int"));
        int con = Integer.parseInt(hennaElement.attributeValue("con"));
        int dex = Integer.parseInt(hennaElement.attributeValue("dex"));
        int men = Integer.parseInt(hennaElement.attributeValue("men"));
        int skillId = hennaElement.attributeValue("skillId") == null ? 0
                : Integer.parseInt(hennaElement.attributeValue("skillId"));
        TIntArrayList list = new TIntArrayList();

        for (Iterator<Element> classIterator = hennaElement.elementIterator("class"); classIterator
                .hasNext();) {
            Element classElement = classIterator.next();
            list.add(Integer.parseInt(classElement.attributeValue("id")));
        }

        Henna henna = new Henna(symbolId, dyeId, price, drawCount, wit, _int, con, str, dex, men, skillId,
                list);
        getHolder().addHenna(henna);
    }
}

From source file:lineage2.gameserver.data.xml.parser.InstantZoneParser.java

License:Open Source License

/**
 * Method readData.// ww w.  jav a 2  s.  c  om
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element element = iterator.next();
        int instanceId;
        String name;
        SchedulingPattern resetReuse = new SchedulingPattern("30 6 * * *");
        int timelimit = -1;
        int timer = 60;
        int mapx = -1;
        int mapy = -1;
        boolean dispelBuffs = false;
        boolean onPartyDismiss = true;
        int mobId, respawn, respawnRnd, count, sharedReuseGroup = 0;
        int collapseIfEmpty = 0;
        int spawnType = 0;
        SpawnInfo spawnDat = null;
        int removedItemId = 0, removedItemCount = 0, giveItemId = 0, givedItemCount = 0, requiredQuestId = 0;
        int maxChannels = 20;
        boolean removedItemNecessity = false;
        boolean setReuseUponEntry = true;
        StatsSet params = new StatsSet();
        List<InstantZone.SpawnInfo> spawns = new ArrayList<>();
        IntObjectMap<InstantZone.DoorInfo> doors = Containers.emptyIntObjectMap();
        Map<String, InstantZone.ZoneInfo> zones = Collections.emptyMap();
        Map<String, InstantZone.SpawnInfo2> spawns2 = Collections.emptyMap();
        instanceId = Integer.parseInt(element.attributeValue("id"));
        name = element.attributeValue("name");
        String n = element.attributeValue("timelimit");

        if (n != null) {
            timelimit = Integer.parseInt(n);
        }

        n = element.attributeValue("collapseIfEmpty");
        collapseIfEmpty = Integer.parseInt(n);
        n = element.attributeValue("maxChannels");
        maxChannels = Integer.parseInt(n);
        n = element.attributeValue("dispelBuffs");
        dispelBuffs = (n != null) && Boolean.parseBoolean(n);
        int minLevel = 0, maxLevel = 0, minParty = 1, maxParty = 7;
        List<Location> teleportLocs = Collections.emptyList();
        Location ret = null;

        for (Iterator<Element> subIterator = element.elementIterator(); subIterator.hasNext();) {
            Element subElement = subIterator.next();

            if ("level".equalsIgnoreCase(subElement.getName())) {
                minLevel = Integer.parseInt(subElement.attributeValue("min"));
                maxLevel = Integer.parseInt(subElement.attributeValue("max"));
            } else if ("collapse".equalsIgnoreCase(subElement.getName())) {
                onPartyDismiss = Boolean.parseBoolean(subElement.attributeValue("on-party-dismiss"));
                timer = Integer.parseInt(subElement.attributeValue("timer"));
            } else if ("party".equalsIgnoreCase(subElement.getName())) {
                minParty = Integer.parseInt(subElement.attributeValue("min"));
                maxParty = Integer.parseInt(subElement.attributeValue("max"));
            } else if ("return".equalsIgnoreCase(subElement.getName())) {
                ret = Location.parseLoc(subElement.attributeValue("loc"));
            } else if ("teleport".equalsIgnoreCase(subElement.getName())) {
                if (teleportLocs.isEmpty()) {
                    teleportLocs = new ArrayList<>(1);
                }

                teleportLocs.add(Location.parseLoc(subElement.attributeValue("loc")));
            } else if ("remove".equalsIgnoreCase(subElement.getName())) {
                removedItemId = Integer.parseInt(subElement.attributeValue("itemId"));
                removedItemCount = Integer.parseInt(subElement.attributeValue("count"));
                removedItemNecessity = Boolean.parseBoolean(subElement.attributeValue("necessary"));
            } else if ("give".equalsIgnoreCase(subElement.getName())) {
                giveItemId = Integer.parseInt(subElement.attributeValue("itemId"));
                givedItemCount = Integer.parseInt(subElement.attributeValue("count"));
            } else if ("quest".equalsIgnoreCase(subElement.getName())) {
                requiredQuestId = Integer.parseInt(subElement.attributeValue("id"));
            } else if ("reuse".equalsIgnoreCase(subElement.getName())) {
                resetReuse = new SchedulingPattern(subElement.attributeValue("resetReuse"));
                sharedReuseGroup = Integer.parseInt(subElement.attributeValue("sharedReuseGroup"));
                setReuseUponEntry = Boolean.parseBoolean(subElement.attributeValue("setUponEntry"));
            } else if ("geodata".equalsIgnoreCase(subElement.getName())) {
                String[] rxy = subElement.attributeValue("map").split("_");
                mapx = Integer.parseInt(rxy[0]);
                mapy = Integer.parseInt(rxy[1]);
            } else if ("doors".equalsIgnoreCase(subElement.getName())) {
                for (Element e : subElement.elements()) {
                    if (doors.isEmpty()) {
                        doors = new HashIntObjectMap<>();
                    }

                    boolean opened = (e.attributeValue("opened") != null)
                            && Boolean.parseBoolean(e.attributeValue("opened"));
                    boolean invul = (e.attributeValue("invul") == null)
                            || Boolean.parseBoolean(e.attributeValue("invul"));
                    DoorTemplate template = DoorHolder.getInstance()
                            .getTemplate(Integer.parseInt(e.attributeValue("id")));
                    doors.put(template.getId(), new InstantZone.DoorInfo(template, opened, invul));
                }
            } else if ("zones".equalsIgnoreCase(subElement.getName())) {
                for (Element e : subElement.elements()) {
                    if (zones.isEmpty()) {
                        zones = new HashMap<>();
                    }

                    boolean active = (e.attributeValue("active") != null)
                            && Boolean.parseBoolean(e.attributeValue("active"));
                    ZoneTemplate template = ZoneHolder.getInstance().getTemplate(e.attributeValue("name"));

                    if (template == null) {
                        error("Zone: " + e.attributeValue("name") + " not found; file: "
                                + getCurrentFileName());
                        continue;
                    }

                    zones.put(template.getName(), new InstantZone.ZoneInfo(template, active));
                }
            } else if ("add_parameters".equalsIgnoreCase(subElement.getName())) {
                for (Element e : subElement.elements()) {
                    if ("param".equalsIgnoreCase(e.getName())) {
                        params.set(e.attributeValue("name"), e.attributeValue("value"));
                    }
                }
            } else if ("spawns".equalsIgnoreCase(subElement.getName())) {
                for (Element e : subElement.elements()) {
                    if ("group".equalsIgnoreCase(e.getName())) {
                        String group = e.attributeValue("name");
                        boolean spawned = (e.attributeValue("spawned") != null)
                                && Boolean.parseBoolean(e.attributeValue("spawned"));
                        List<SpawnTemplate> templates = SpawnHolder.getInstance().getSpawn(group);

                        if (templates == null) {
                            info("not find spawn group: " + group + " in file: " + getCurrentFileName());
                        } else {
                            if (spawns2.isEmpty()) {
                                spawns2 = new Hashtable<>();
                            }

                            spawns2.put(group, new InstantZone.SpawnInfo2(templates, spawned));
                        }
                    } else if ("spawn".equalsIgnoreCase(e.getName())) {
                        String[] mobs = e.attributeValue("mobId").split(" ");
                        String respawnNode = e.attributeValue("respawn");
                        respawn = respawnNode != null ? Integer.parseInt(respawnNode) : 0;
                        String respawnRndNode = e.attributeValue("respawnRnd");
                        respawnRnd = respawnRndNode != null ? Integer.parseInt(respawnRndNode) : 0;
                        String countNode = e.attributeValue("count");
                        count = countNode != null ? Integer.parseInt(countNode) : 1;
                        List<Location> coords = new ArrayList<>();
                        spawnType = 0;
                        String spawnTypeNode = e.attributeValue("type");

                        if ((spawnTypeNode == null) || spawnTypeNode.equalsIgnoreCase("point")) {
                            spawnType = 0;
                        } else if (spawnTypeNode.equalsIgnoreCase("rnd")) {
                            spawnType = 1;
                        } else if (spawnTypeNode.equalsIgnoreCase("loc")) {
                            spawnType = 2;
                        } else {
                            error("Spawn type  '" + spawnTypeNode + "' is unknown!");
                        }

                        for (Element e2 : e.elements()) {
                            if ("coords".equalsIgnoreCase(e2.getName())) {
                                coords.add(Location.parseLoc(e2.attributeValue("loc")));
                            }
                        }

                        Territory territory = null;

                        if (spawnType == 2) {
                            Polygon poly = new Polygon();

                            for (Location loc : coords) {
                                poly.add(loc.getX(), loc.getY()).setZmin(loc.getZ()).setZmax(loc.getZ());
                            }

                            if (!poly.validate()) {
                                error("invalid spawn territory for instance id : " + instanceId + " - " + poly
                                        + "!");
                            }

                            territory = new Territory().add(poly);
                        }

                        for (String mob : mobs) {
                            mobId = Integer.parseInt(mob);
                            spawnDat = new InstantZone.SpawnInfo(spawnType, mobId, count, respawn, respawnRnd,
                                    coords, territory);
                            spawns.add(spawnDat);
                        }
                    }
                }
            }
        }

        InstantZone instancedZone = new InstantZone(instanceId, name, resetReuse, sharedReuseGroup, timelimit,
                dispelBuffs, minLevel, maxLevel, minParty, maxParty, timer, onPartyDismiss, teleportLocs, ret,
                mapx, mapy, doors, zones, spawns2, spawns, collapseIfEmpty, maxChannels, removedItemId,
                removedItemCount, removedItemNecessity, giveItemId, givedItemCount, requiredQuestId,
                setReuseUponEntry, params);
        getHolder().addInstantZone(instancedZone);
    }
}

From source file:lineage2.gameserver.data.xml.parser.JumpTracksParser.java

License:Open Source License

/**
 * Method readData./*w  ww . ja va  2  s  . c  o m*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element trackElement = iterator.next();
        int trackId = Integer.parseInt(trackElement.attributeValue("id"));
        Location startLoc = Location.parse(trackElement);
        JumpTrack jumpTrack = new JumpTrack(trackId, startLoc);

        for (Iterator<?> wayIterator = trackElement.elementIterator("way"); wayIterator.hasNext();) {
            Element wayElement = (Element) wayIterator.next();
            int wayId = Integer.parseInt(wayElement.attributeValue("id"));
            JumpWay jumpWay = new JumpWay(wayId);

            for (Iterator<?> pointIterator = wayElement.elementIterator("point"); pointIterator.hasNext();) {
                Element pointElement = (Element) pointIterator.next();
                Location pointLoc = Location.parse(pointElement);
                int nextWayId = Integer.parseInt(pointElement.attributeValue("next_way_id"));
                jumpWay.addPoint(new JumpPoint(pointLoc, nextWayId));
            }

            jumpTrack.addWay(jumpWay);
        }

        getHolder().addTrack(jumpTrack);
    }
}

From source file:lineage2.gameserver.data.xml.parser.LevelBonusParser.java

License:Open Source License

/**
 * Method readData.//w w  w  .  j  a  v a  2 s . c om
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element element = iterator.next();

        if ("lvl_bonus".equalsIgnoreCase(element.getName())) {
            for (Element e : element.elements()) {
                int lvl = Integer.parseInt(e.attributeValue("lvl"));
                double bonusMod = Double.parseDouble(e.attributeValue("value"));
                (getHolder()).addLevelBonus(lvl, bonusMod);
            }
        }
    }
}

From source file:lineage2.gameserver.data.xml.parser.OptionDataParser.java

License:Open Source License

/**
 * Method readData.//from www  . j  a  v  a  2s .  c o  m
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> itemIterator = rootElement.elementIterator(); itemIterator.hasNext();) {
        Element optionDataElement = itemIterator.next();
        OptionDataTemplate template = new OptionDataTemplate(
                Integer.parseInt(optionDataElement.attributeValue("id")));

        for (Iterator<Element> subIterator = optionDataElement.elementIterator(); subIterator.hasNext();) {
            Element subElement = subIterator.next();
            String subName = subElement.getName();

            if (subName.equalsIgnoreCase("for")) {
                parseFor(subElement, template);
            } else if (subName.equalsIgnoreCase("triggers")) {
                parseTriggers(subElement, template);
            } else if (subName.equalsIgnoreCase("skills")) {
                for (Iterator<Element> nextIterator = subElement.elementIterator(); nextIterator.hasNext();) {
                    Element nextElement = nextIterator.next();
                    int id = Integer.parseInt(nextElement.attributeValue("id"));
                    int level = Integer.parseInt(nextElement.attributeValue("level"));
                    Skill skill = SkillTable.getInstance().getInfo(id, level);

                    if (skill != null) {
                        template.addSkill(skill);
                    } else {
                        info("Skill not found(" + id + "," + level + ") for option data:" + template.getId()
                                + "; file:" + getCurrentFileName());
                    }
                }
            }
        }

        getHolder().addTemplate(template);
    }
}

From source file:lineage2.gameserver.data.xml.parser.PetitionGroupParser.java

License:Open Source License

/**
 * Method readData./*from   w  ww  .j  av  a  2s.  c  o m*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element groupElement = iterator.next();
        PetitionMainGroup group = new PetitionMainGroup(Integer.parseInt(groupElement.attributeValue("id")));
        getHolder().addPetitionGroup(group);

        for (Iterator<Element> subIterator = groupElement.elementIterator(); subIterator.hasNext();) {
            Element subElement = subIterator.next();

            if ("name".equals(subElement.getName())) {
                group.setName(Language.valueOf(subElement.attributeValue("lang")), subElement.getText());
            } else if ("description".equals(subElement.getName())) {
                group.setDescription(Language.valueOf(subElement.attributeValue("lang")), subElement.getText());
            } else if ("sub_group".equals(subElement.getName())) {
                PetitionSubGroup subGroup = new PetitionSubGroup(
                        Integer.parseInt(subElement.attributeValue("id")),
                        subElement.attributeValue("handler"));
                group.addSubGroup(subGroup);

                for (Iterator<Element> sub2Iterator = subElement.elementIterator(); sub2Iterator.hasNext();) {
                    Element sub2Element = sub2Iterator.next();

                    if ("name".equals(sub2Element.getName())) {
                        subGroup.setName(Language.valueOf(sub2Element.attributeValue("lang")),
                                sub2Element.getText());
                    } else if ("description".equals(sub2Element.getName())) {
                        subGroup.setDescription(Language.valueOf(sub2Element.attributeValue("lang")),
                                sub2Element.getText());
                    }
                }
            }
        }
    }
}

From source file:lineage2.gameserver.data.xml.parser.PlayerTemplateParser.java

License:Open Source License

/**
 * Method readData./*from ww w.  j a  v a  2 s.c  o m*/
 * @param rootElement Element
 * @throws Exception
 */
@Override
protected void readData(Element rootElement) throws Exception {
    for (Iterator<Element> iterator = rootElement.elementIterator(); iterator.hasNext();) {
        Element element = iterator.next();
        Race race = Race.valueOf(element.attributeValue("race").toLowerCase());
        Sex sex = Sex.valueOf(element.attributeValue("sex").toUpperCase());
        ClassType classtype = ClassType.valueOf(element.attributeValue("type").toUpperCase());
        StatAttributes min_attr = null;
        StatAttributes max_attr = null;
        StatAttributes base_attr = null;
        BaseArmorDefence arm_defence = null;
        BaseJewelDefence jewl_defence = null;
        StatsSet stats_set = new StatsSet();
        List<StartItem> start_items = new ArrayList<>();
        List<Location> start_locations = new ArrayList<>();
        TIntObjectHashMap<LvlUpData> lvl_up_data = new TIntObjectHashMap<>();

        for (Iterator<Element> subIterator = element.elementIterator(); subIterator.hasNext();) {
            Element subElement = subIterator.next();

            if ("creation_data".equalsIgnoreCase(subElement.getName())) {
                for (Element e : subElement.elements()) {
                    if ("start_equipments".equalsIgnoreCase(e.getName())) {
                        for (Element e2 : e.elements()) {
                            if ("equipment".equalsIgnoreCase(e2.getName())) {
                                int item_id = Integer.parseInt(e2.attributeValue("item_id"));
                                long count = Long.parseLong(e2.attributeValue("count"));
                                boolean equiped = Boolean.parseBoolean(e2.attributeValue("equiped"));
                                start_items.add(new StartItem(item_id, count, equiped));
                            }
                        }
                    } else if ("start_points".equalsIgnoreCase(e.getName())) {
                        for (Element e2 : e.elements()) {
                            if ("point".equalsIgnoreCase(e2.getName())) {
                                start_locations.add(Location.parse(e2));
                            }
                        }
                    }
                }
            } else if ("stats_data".equalsIgnoreCase(subElement.getName())) {
                for (Element e : subElement.elements()) {
                    if (("min_attributes".equalsIgnoreCase(e.getName()))
                            || ("max_attributes".equalsIgnoreCase(e.getName()))
                            || ("base_attributes".equalsIgnoreCase(e.getName()))) {
                        int _int = Integer.parseInt(e.attributeValue("int"));
                        int str = Integer.parseInt(e.attributeValue("str"));
                        int con = Integer.parseInt(e.attributeValue("con"));
                        int men = Integer.parseInt(e.attributeValue("men"));
                        int dex = Integer.parseInt(e.attributeValue("dex"));
                        int wit = Integer.parseInt(e.attributeValue("wit"));
                        StatAttributes attr = new StatAttributes(_int, str, con, men, dex, wit);

                        if ("min_attributes".equalsIgnoreCase(e.getName())) {
                            min_attr = attr;
                        } else if ("max_attributes".equalsIgnoreCase(e.getName())) {
                            max_attr = attr;
                        } else if ("base_attributes".equalsIgnoreCase(e.getName())) {
                            base_attr = attr;
                        }
                    } else if ("armor_defence".equalsIgnoreCase(e.getName())) {
                        int chest = Integer.parseInt(e.attributeValue("chest"));
                        int legs = Integer.parseInt(e.attributeValue("legs"));
                        int helmet = Integer.parseInt(e.attributeValue("helmet"));
                        int boots = Integer.parseInt(e.attributeValue("boots"));
                        int gloves = Integer.parseInt(e.attributeValue("gloves"));
                        int underwear = Integer.parseInt(e.attributeValue("underwear"));
                        int cloak = Integer.parseInt(e.attributeValue("cloak"));
                        arm_defence = new BaseArmorDefence(chest, legs, helmet, boots, gloves, underwear,
                                cloak);
                    } else if ("jewel_defence".equalsIgnoreCase(e.getName())) {
                        int r_earring = Integer.parseInt(e.attributeValue("r_earring"));
                        int l_earring = Integer.parseInt(e.attributeValue("l_earring"));
                        int r_ring = Integer.parseInt(e.attributeValue("r_ring"));
                        int l_ring = Integer.parseInt(e.attributeValue("l_ring"));
                        int necklace = Integer.parseInt(e.attributeValue("necklace"));
                        jewl_defence = new BaseJewelDefence(r_earring, l_earring, r_ring, l_ring, necklace);
                    } else if ("base_stats".equalsIgnoreCase(e.getName())) {
                        for (Element e2 : e.elements()) {
                            if ("stat_set".equalsIgnoreCase(e2.getName())) {
                                stats_set.set(e2.attributeValue("name"), e2.attributeValue("value"));
                            } else if ("regen_lvl_data".equalsIgnoreCase(e2.getName())) {
                                for (Element e3 : e2.elements()) {
                                    if ("lvl_data".equalsIgnoreCase(e3.getName())) {
                                        int lvl = Integer.parseInt(e3.attributeValue("lvl"));
                                        double hp = Double.parseDouble(e3.attributeValue("hp"));
                                        double mp = Double.parseDouble(e3.attributeValue("mp"));
                                        double cp = Double.parseDouble(e3.attributeValue("cp"));
                                        lvl_up_data.put(lvl, new LvlUpData(hp, mp, cp));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        PlayerTemplate template = new PlayerTemplate(stats_set, race, sex, min_attr, max_attr, base_attr,
                arm_defence, jewl_defence, start_locations, start_items, lvl_up_data);
        getHolder().addPlayerTemplate(race, classtype, sex, template);
    }
}