@Override public void save(PersistanceObject<?, ?> obj) { HumanTreeInfo info = (HumanTreeInfo) obj; IIoOperation _oper = new SaveObjectOperation<TreeInfoEntity, HumanTreeInfo>( info, Globals.getDaoService().getTreeInfoDao()); Globals.getAsyncService().createOperationAndExecuteAtOnce(_oper); }
public FormService() { // 加载阵型模板,按照职业和等级排序 List<FormTemplate> temps = new ArrayList<FormTemplate>(); for (FormTemplate temp : Globals.getTemplateService().getAll(FormTemplate.class).values()) { temps.add(temp); } Collections.sort( temps, new Comparator<FormTemplate>() { @Override public int compare(FormTemplate t1, FormTemplate t2) { // 职业从小到大排列,如果职业相同按照级别从小到大排列 if (t1.getVocation() == t2.getVocation()) { return t1.getLevel() - t2.getLevel(); } else { return t1.getVocation() - t2.getVocation(); } } }); // 将排序后的模板放入map中 for (FormTemplate temp : temps) { VocationType vocation = VocationType.getByCode(temp.getVocation()); if (formMap.containsKey(vocation)) { List<FormTemplate> list = formMap.get(vocation); list.add(temp); } else { List<FormTemplate> list = new ArrayList<FormTemplate>(); list.add(temp); formMap.put(vocation, list); } formMapById.put(temp.getId(), temp); } // 加载阵型位置效果模板 for (FormSnTemplate temp : Globals.getTemplateService().getAll(FormSnTemplate.class).values()) { formSnMap.put(temp.getPosition(), temp); } }
/** * 角色初始化阵型,将自身放入阵法中 * * @param human * @param temp * @return */ private BattleForm initBattleForm(Human human, FormTemplate temp) { // 初始化时将玩家放入阵型配置的第一个开启位置中 String[] positions = new String[BattleForm.TotalPositions]; int initPos = temp.getOpenPositions().get(0); positions[initPos - 1] = human.getUUID(); // 构造阵型对象并保存到数据库中 BattleForm form = new BattleForm(human); form.setFormSn(temp.getId()); form.setOwner(human); form.setPositions(positions); FormEntity entity = form.toEntity(); Globals.getDaoService().getFormDao().save(entity); form.setDbId(entity.getId()); form.setInDb(true); // 设置角色阵型 human.setBattleForm(form); return form; }