Select the target skill based on the supplied criteria. Uses the id in the details object to either retrieve a skill by name or by position in the skill list. @param pc The character being processed. @param details The parsed details of the token. @param eh The ExportHandler @return The matching sk
(PlayerCharacter pc, SkillDetails details, ExportHandler eh)
| 85 | * @return The matching skill, or null if none match. |
| 86 | */ |
| 87 | private Object getSkill(PlayerCharacter pc, SkillDetails details, ExportHandler eh) |
| 88 | { |
| 89 | Object skill = null; |
| 90 | try |
| 91 | { |
| 92 | int i = Integer.parseInt(details.getSkillId()); |
| 93 | final List<Skill> pcSkills = new ArrayList<>(getSkillList(pc)); |
| 94 | |
| 95 | SkillFilter filter = details.getSkillFilter(); |
| 96 | if (filter == null || filter == SkillFilter.Selected) |
| 97 | { |
| 98 | filter = pc.getSkillFilter(); |
| 99 | } |
| 100 | |
| 101 | Iterator<Skill> iter = pcSkills.iterator(); |
| 102 | while (iter.hasNext()) |
| 103 | { |
| 104 | Skill sk = iter.next(); |
| 105 | if (!pc.includeSkill(sk, filter) || !sk.qualifies(pc, null)) |
| 106 | { |
| 107 | iter.remove(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if ((i >= (pcSkills.size() - 1)) && eh != null && eh.getExistsOnly()) |
| 112 | { |
| 113 | eh.setNoMoreItems(true); |
| 114 | } |
| 115 | |
| 116 | for (iter = pcSkills.iterator(); i >= 0;) |
| 117 | { |
| 118 | Skill sk = iter.next(); |
| 119 | |
| 120 | if (i == 0) |
| 121 | { |
| 122 | return sk; |
| 123 | } |
| 124 | i--; //wasn't the base skill |
| 125 | List<String> situations = new ArrayList<>(sk.getUniqueListFor(ListKey.SITUATION)); |
| 126 | int numSits = situations.size(); |
| 127 | if (i < numSits) |
| 128 | { |
| 129 | Collections.sort(situations); |
| 130 | } |
| 131 | for (String situation : situations) |
| 132 | { |
| 133 | double bonus = pc.getTotalBonusTo("SITUATION", sk.getKeyName() + '=' + situation); |
| 134 | if (bonus > 0.01 || bonus < -0.01) |
| 135 | { |
| 136 | if (i == 0) |
| 137 | { |
| 138 | return new SkillSituation(sk, situation, bonus); |
| 139 | } |
| 140 | i--; //Wasn't this situation |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
no test coverage detected