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

@@ -188,7 +188,7 @@ public class LifeFactory {
Data monsterSkillInfoData = monsterInfoData.getChildByPath("skill");
if (monsterSkillInfoData != null) {
int i = 0;
List<MobSkillId> skills = new ArrayList<>();
Set<MobSkillId> skills = new HashSet<>();
while (monsterSkillInfoData.getChildByPath(Integer.toString(i)) != null) {
int skillId = DataTool.getInt(i + "/skill", monsterSkillInfoData, 0);
int skillLv = DataTool.getInt(i + "/level", monsterSkillInfoData, 0);

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() {

View File

@@ -41,7 +41,7 @@ public class MonsterStats {
public Map<Element, ElementalEffectiveness> resistance = new HashMap<>();
public List<Integer> revives = Collections.emptyList();
public byte tagColor, tagBgColor;
public List<MobSkillId> skills = new ArrayList<>();
public Set<MobSkillId> skills = new HashSet<>();
public Pair<Integer, Integer> cool = null;
public BanishInfo banish = null;
public List<loseItem> loseItem = null;
@@ -190,17 +190,12 @@ public class MonsterStats {
this.tagBgColor = (byte) tagBgColor;
}
public void setSkills(List<MobSkillId> skills) {
for (int i = this.skills.size(); i < skills.size(); i++) {
this.skills.add(null);
}
for (int i = 0; i < skills.size(); i++) {
this.skills.set(i, skills.get(i));
}
public void setSkills(Set<MobSkillId> skills) {
this.skills = skills;
}
public List<MobSkillId> getSkills() {
return Collections.unmodifiableList(this.skills);
public Set<MobSkillId> getSkills() {
return Collections.unmodifiableSet(this.skills);
}
public int getNoSkills() {