Simplify Monster skills with Set instead of List

Doable now with MobSkillId records
This commit is contained in:
P0nk
2022-09-03 13:30:44 +02:00
parent c47ca4d6a4
commit 7cdaabf6f8
5 changed files with 37 additions and 53 deletions

View File

@@ -1426,7 +1426,7 @@ public class Monster extends AbstractLoadedLife {
return map.getAggroCoordinator();
}
public List<MobSkillId> getSkills() {
public Set<MobSkillId> getSkills() {
return stats.getSkills();
}
@@ -1434,19 +1434,6 @@ public class Monster extends AbstractLoadedLife {
return stats.hasSkill(skillId, level);
}
public int getSkillPos(int skillId, int level) {
int pos = 0;
for (MobSkillId ms : this.getSkills()) {
if (ms.type().getId() == skillId && ms.level() == level) {
return pos;
}
pos++;
}
return -1;
}
public boolean canUseSkill(MobSkill toUse, boolean apply) {
if (toUse == null || isBuffed(MonsterStatus.SEAL_SKILL)) {
return false;
@@ -1600,8 +1587,20 @@ public class Monster extends AbstractLoadedLife {
}
}
public int getNoSkills() {
return this.stats.getNoSkills();
public boolean hasAnySkill() {
return this.stats.getNoSkills() > 0;
}
public MobSkillId getRandomSkill() {
Set<MobSkillId> skills = stats.getSkills();
if (skills.size() == 0) {
return null;
}
// There is no simple way of getting a random element from a Set. Have to make do with this.
return skills.stream()
.skip(Randomizer.nextInt(skills.size()))
.findAny()
.orElse(null);
}
public boolean isFirstAttack() {