/** Method refreshStats. */
  @Override
  protected void refreshStats() {
    _maxCp = set(SEND_STATUS_INFO, _maxCp, _activeChar.getMaxCp());
    super.refreshStats();
    _maxLoad = set(SEND_CHAR_INFO | SEND_MAX_LOAD, _maxLoad, _activeChar.getMaxLoad());
    _curLoad = set(SEND_CUR_LOAD, _curLoad, _activeChar.getCurrentLoad());

    for (Element e : Element.VALUES) {
      _attackElement[e.getId()] =
          set(SEND_CHAR_INFO, _attackElement[e.getId()], _activeChar.getAttack(e));
      _defenceElement[e.getId()] =
          set(SEND_CHAR_INFO, _defenceElement[e.getId()], _activeChar.getDefence(e));
    }

    _exp = set(SEND_CHAR_INFO, _exp, _activeChar.getExp());
    _sp = set(SEND_CHAR_INFO, _sp, _activeChar.getIntSp());
    _pk = set(SEND_CHAR_INFO, _pk, _activeChar.getPkKills());
    _pvp = set(SEND_CHAR_INFO, _pvp, _activeChar.getPvpKills());
    _fame = set(SEND_CHAR_INFO, _fame, _activeChar.getFame());
    _karma = set(BROADCAST_KARMA, _karma, _activeChar.getKarma());
    _inventory = set(SEND_STORAGE_INFO, _inventory, _activeChar.getInventoryLimit());
    _warehouse = set(SEND_STORAGE_INFO, _warehouse, _activeChar.getWarehouseLimit());
    _clan = set(SEND_STORAGE_INFO, _clan, Config.WAREHOUSE_SLOTS_CLAN);
    _trade = set(SEND_STORAGE_INFO, _trade, _activeChar.getTradeLimit());
    _recipeDwarven = set(SEND_STORAGE_INFO, _recipeDwarven, _activeChar.getDwarvenRecipeLimit());
    _recipeCommon = set(SEND_STORAGE_INFO, _recipeCommon, _activeChar.getCommonRecipeLimit());
    _cubicsHash =
        set(BROADCAST_CHAR_INFO, _cubicsHash, CollectionUtils.hashCode(_activeChar.getCubics()));
    _partyRoom =
        set(
            BROADCAST_CHAR_INFO,
            _partyRoom,
            (_activeChar.getMatchingRoom() != null)
                    && (_activeChar.getMatchingRoom().getType() == MatchingRoom.PARTY_MATCHING)
                    && (_activeChar.getMatchingRoom().getLeader() == _activeChar)
                ? _activeChar.getMatchingRoom().getId()
                : 0);
    _team = set(BROADCAST_CHAR_INFO2, _team, _activeChar.getTeam());
    _title = set(BROADCAST_CHAR_INFO, _title, _activeChar.getTitle());
  }
Example #2
0
 /**
  * Method readData.
  *
  * @param rootElement org.dom4j.Element
  * @throws Exception
  */
 @Override
 protected void readData(org.dom4j.Element rootElement) throws Exception {
   for (Iterator<org.dom4j.Element> itemIterator = rootElement.elementIterator();
       itemIterator.hasNext(); ) {
     org.dom4j.Element itemElement = itemIterator.next();
     StatsSet set = new StatsSet();
     set.set("item_id", itemElement.attributeValue("id"));
     set.set("name", itemElement.attributeValue("name"));
     set.set("add_name", itemElement.attributeValue("add_name", StringUtils.EMPTY));
     int slot = 0;
     for (Iterator<org.dom4j.Element> subIterator = itemElement.elementIterator();
         subIterator.hasNext(); ) {
       org.dom4j.Element subElement = subIterator.next();
       String subName = subElement.getName();
       if (subName.equalsIgnoreCase("set")) {
         set.set(subElement.attributeValue("name"), subElement.attributeValue("value"));
       } else if (subName.equalsIgnoreCase("equip")) {
         for (Iterator<org.dom4j.Element> slotIterator = subElement.elementIterator();
             slotIterator.hasNext(); ) {
           org.dom4j.Element slotElement = slotIterator.next();
           Bodypart bodypart = Bodypart.valueOf(slotElement.attributeValue("id"));
           if (bodypart.getReal() != null) {
             slot = bodypart.mask();
           } else {
             slot |= bodypart.mask();
           }
         }
       }
     }
     set.set("bodypart", slot);
     ItemTemplate template = null;
     try {
       if (itemElement.getName().equalsIgnoreCase("weapon")) {
         if (!set.containsKey("class")) {
           if ((slot & ItemTemplate.SLOT_L_HAND) > 0) {
             set.set("class", ItemTemplate.ItemClass.ARMOR);
           } else {
             set.set("class", ItemTemplate.ItemClass.WEAPON);
           }
         }
         template = new WeaponTemplate(set);
       }
     } catch (Exception e) {
       warn("Fail create item: " + set.get("item_id"), e);
       continue;
     }
     for (Iterator<org.dom4j.Element> subIterator = itemElement.elementIterator();
         subIterator.hasNext(); ) {
       org.dom4j.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<org.dom4j.Element> nextIterator = subElement.elementIterator();
             nextIterator.hasNext(); ) {
           org.dom4j.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.attachSkill(skill);
           } else {
             info(
                 "Skill not found("
                     + id
                     + ","
                     + level
                     + ") for item:"
                     + set.getObject("item_id")
                     + "; file:"
                     + getCurrentFileName());
           }
         }
       } else if (subName.equalsIgnoreCase("enchant4_skill")) {
         int id = Integer.parseInt(subElement.attributeValue("id"));
         int level = Integer.parseInt(subElement.attributeValue("level"));
         Skill skill = SkillTable.getInstance().getInfo(id, level);
         if (skill != null) {
           template.setEnchant4Skill(skill);
         }
       } else if (subName.equalsIgnoreCase("unequip_skill")) {
         int id = Integer.parseInt(subElement.attributeValue("id"));
         int level = Integer.parseInt(subElement.attributeValue("level"));
         Skill skill = SkillTable.getInstance().getInfo(id, level);
         if (skill != null) {
           template.setUnequipeSkill(skill);
         }
       } else if (subName.equalsIgnoreCase("cond")) {
         Condition condition = parseFirstCond(subElement);
         if (condition != null) {
           int msgId = parseNumber(subElement.attributeValue("msgId")).intValue();
           condition.setSystemMsg(msgId);
           template.setCondition(condition);
         }
       } else if (subName.equalsIgnoreCase("attributes")) {
         int[] attributes = new int[6];
         for (Iterator<org.dom4j.Element> nextIterator = subElement.elementIterator();
             nextIterator.hasNext(); ) {
           org.dom4j.Element nextElement = nextIterator.next();
           Element element;
           if (nextElement.getName().equalsIgnoreCase("attribute")) {
             element = Element.getElementByName(nextElement.attributeValue("element"));
             attributes[element.getId()] = Integer.parseInt(nextElement.attributeValue("value"));
           }
         }
         template.setBaseAtributeElements(attributes);
       } else if (subName.equalsIgnoreCase("enchant_options")) {
         for (Iterator<org.dom4j.Element> nextIterator = subElement.elementIterator();
             nextIterator.hasNext(); ) {
           org.dom4j.Element nextElement = nextIterator.next();
           if (nextElement.getName().equalsIgnoreCase("level")) {
             int val = Integer.parseInt(nextElement.attributeValue("val"));
             int i = 0;
             int[] options = new int[3];
             for (org.dom4j.Element optionElement : nextElement.elements()) {
               OptionDataTemplate optionData =
                   OptionDataHolder.getInstance()
                       .getTemplate(Integer.parseInt(optionElement.attributeValue("id")));
               if (optionData == null) {
                 error(
                     "Not found option_data for id: "
                         + optionElement.attributeValue("id")
                         + "; item_id: "
                         + set.get("item_id"));
                 continue;
               }
               options[i++] = optionData.getId();
             }
             template.addEnchantOptions(val, options);
           }
         }
       }
     }
     getHolder().addItem(template);
   }
 }