Пример #1
0
  public void restore() {
    _listByIndex.clear();
    _listByClassId.clear();
    List<SubClass> subclasses = CharacterSubclassDAO.getInstance().restore(_owner);
    int lastFreeIndex = 2;
    for (SubClass sub : subclasses) {
      if (sub == null) // Невозможно, но хай будет.
      continue;

      if (size() >= MAX_SUB_COUNT) {
        _log.warn(
            "SubClassList:restore: Limit is subclass! Player: "
                + _owner.getName()
                + "("
                + _owner.getObjectId()
                + ")");
        break;
      }

      if (sub.isActive()) {
        _activeSubClass = sub;
      }

      if (sub.isBase()) {
        _baseSubClass = sub;
        sub.setIndex(1);
      } else {
        sub.setIndex(lastFreeIndex);
        lastFreeIndex++;
      }

      if (_listByIndex.containsKey(sub.getIndex()))
        _log.warn(
            "SubClassList:restore: Duplicate index in player subclasses! Player: "
                + _owner.getName()
                + "("
                + _owner.getObjectId()
                + ")");
      _listByIndex.put(sub.getIndex(), sub);

      if (_listByClassId.containsKey(sub.getClassId()))
        _log.warn(
            "SubClassList:restore: Duplicate class_id in player subclasses! Player: "
                + _owner.getName()
                + "("
                + _owner.getObjectId()
                + ")");
      _listByClassId.put(sub.getClassId(), sub);
    }

    _lastFreeIndex = lastFreeIndex;

    if (_listByIndex.size() != _listByClassId.size()) // Невозможно, но хай будет.
    _log.warn(
          "SubClassList:restore: The size of the lists do not match! Player: "
              + _owner.getName()
              + "("
              + _owner.getObjectId()
              + ")");
  }
Пример #2
0
  public boolean changeSubClassId(int oldClassId, int newClassId) {
    if (!_listByClassId.containsKey(oldClassId)) return false;

    if (_listByClassId.containsKey(newClassId)) return false;

    SubClass sub = _listByClassId.get(oldClassId);
    sub.setClassId(newClassId);
    _listByClassId.remove(oldClassId);
    _listByClassId.put(sub.getClassId(), sub);
    return true;
  }
Пример #3
0
  public SubClass changeActiveSubClass(int classId) {
    if (!_listByClassId.containsKey(classId)) return null;

    if (_activeSubClass == null) return null;

    _activeSubClass.setActive(false);

    SubClass sub = _listByClassId.get(classId);
    sub.setActive(true);

    _activeSubClass = sub;
    return sub;
  }
Пример #4
0
  public boolean add(SubClass sub) {
    if (sub == null) return false;

    if (size() >= MAX_SUB_COUNT) return false;

    if (_listByClassId.containsKey(sub.getClassId())) return false;

    sub.setIndex(_lastFreeIndex);

    _lastFreeIndex++;
    _listByIndex.put(sub.getIndex(), sub);
    _listByClassId.put(sub.getClassId(), sub);
    return true;
  }