001package com.fs.starfarer.api.util; 002 003import java.util.ArrayList; 004import java.util.Collections; 005import java.util.Comparator; 006import java.util.HashMap; 007import java.util.List; 008import java.util.Map; 009 010import com.fs.starfarer.api.Global; 011import com.fs.starfarer.api.characters.SkillSpecAPI; 012import com.fs.starfarer.api.impl.campaign.ids.Skills; 013 014public class SkillData { 015 016 public static class SkillTier { 017 public List<SkillSpecAPI> skills = new ArrayList<SkillSpecAPI>(); 018 } 019 public static class SkillsForAptitude { 020 public String aptitudeId; 021 public List<List<SkillSpecAPI>> tiers = new ArrayList<List<SkillSpecAPI>>(); 022 public List<SkillSpecAPI> all = new ArrayList<SkillSpecAPI>(); 023 public SkillsForAptitude(String aptitudeId) { 024 this.aptitudeId = aptitudeId; 025 } 026 027 } 028 029 protected static Map<String, SkillsForAptitude> aptitudes = new HashMap<String, SkillsForAptitude>(); 030 031 public static SkillsForAptitude getSkills(String aptitudeId) { 032 SkillsForAptitude skills = SkillData.getAptitudes().get(aptitudeId); 033 if (skills == null) skills = new SkillsForAptitude(aptitudeId); 034 return skills; 035 } 036 037 public static Map<String, SkillsForAptitude> getAptitudes() { 038 compute(); 039 return aptitudes; 040 } 041 042 043 protected static boolean computed = false; 044 protected static void compute() { 045 if (computed) return; 046 computed = true; 047 048 aptitudes.clear(); 049 050 //List<String> aptitudeIds = new ArrayList<String>(Global.getSettings().getAptitudeIds()); 051 List<String> skillIds = new ArrayList<String>(Global.getSettings().getSkillIds()); 052 053 for (String skillId : skillIds) { 054 SkillSpecAPI skill = Global.getSettings().getSkillSpec(skillId); 055 if (skill.isAptitudeEffect()) continue; 056 if (skill.hasTag(Skills.TAG_NPC_ONLY)) continue; 057 if (skill.hasTag(Skills.TAG_DEPRECATED)) continue; 058 059 String aptitudeId = skill.getGoverningAptitudeId(); 060 if (aptitudeId == null || aptitudeId.isEmpty()) continue; 061 062 SkillsForAptitude skills = aptitudes.get(aptitudeId); 063 if (skills == null) { 064 skills = new SkillsForAptitude(aptitudeId); 065 aptitudes.put(aptitudeId, skills); 066 } 067 068 skills.all.add(skill); 069 } 070 071 for (String aptitudeId : aptitudes.keySet()) { 072 SkillsForAptitude skills = aptitudes.get(aptitudeId); 073 074 Collections.sort(skills.all, new Comparator<SkillSpecAPI>() { 075 public int compare(SkillSpecAPI o1, SkillSpecAPI o2) { 076 int result = o1.getTier() - o2.getTier(); 077 if (result == 0) { 078 result = (int) Math.signum(o1.getOrder() - o2.getOrder()); 079 } 080 return result; 081 } 082 }); 083 084 boolean useTier = true; 085 for (SkillSpecAPI skill : skills.all) { 086 useTier &= skill.getReqPoints() == 0; 087 } 088 089 int currTier = -1; 090 int prevReq = -1; 091 List<SkillSpecAPI> soFar = new ArrayList<SkillSpecAPI>(); 092 for (SkillSpecAPI skill : skills.all) { 093 if (!useTier) { 094 if (skill.getReqPoints() != prevReq) { 095 if (!soFar.isEmpty()) { 096 skills.tiers.add(soFar); 097 } 098 soFar = new ArrayList<SkillSpecAPI>(); 099 prevReq = skill.getReqPoints(); 100 } 101 } else { 102 if (skill.getTier() != currTier) { 103 if (!soFar.isEmpty()) { 104 skills.tiers.add(soFar); 105 } 106 soFar = new ArrayList<SkillSpecAPI>(); 107 currTier = skill.getTier(); 108 } 109 } 110 soFar.add(skill); 111 } 112 if (!soFar.isEmpty()) { 113 skills.tiers.add(soFar); 114 } 115 } 116 } 117 118 119 120 121} 122 123 124 125 126 127 128 129 130 131