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() + ")"); }
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; }
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; }
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; }