Make MCSkill immutable with record

This commit is contained in:
P0nk
2022-09-03 14:44:14 +02:00
parent 9e0479fe9f
commit 15c4188d48
4 changed files with 13 additions and 28 deletions

View File

@@ -95,14 +95,14 @@ public final class MonsterCarnivalHandler extends AbstractPacketHandler {
return;
}
final MCSkill skill = CarnivalFactory.getInstance().getSkill(skillid.get(num)); //ugh wtf
if (skill == null || c.getPlayer().getCP() < skill.cpLoss) {
if (skill == null || c.getPlayer().getCP() < skill.cpLoss()) {
c.sendPacket(PacketCreator.CPQMessage((byte) 1));
c.sendPacket(PacketCreator.enableActions());
return;
}
final Disease dis = skill.getDisease();
Party enemies = c.getPlayer().getParty().getEnemy();
if (skill.targetsAll) {
if (skill.targetsAll()) {
int hitChance = rollHitChance(dis.getMobSkillType());
if (hitChance <= 80) {
for (PartyCharacter mpc : enemies.getPartyMembers()) {
@@ -128,11 +128,11 @@ public final class MonsterCarnivalHandler extends AbstractPacketHandler {
}
}
}
neededCP = skill.cpLoss;
neededCP = skill.cpLoss();
c.sendPacket(PacketCreator.enableActions());
} else if (tab == 2) { //protectors
final MCSkill skill = CarnivalFactory.getInstance().getGuardian(num);
if (skill == null || c.getPlayer().getCP() < skill.cpLoss) {
if (skill == null || c.getPlayer().getCP() < skill.cpLoss()) {
c.sendPacket(PacketCreator.CPQMessage((byte) 1));
c.sendPacket(PacketCreator.enableActions());
return;
@@ -163,7 +163,7 @@ public final class MonsterCarnivalHandler extends AbstractPacketHandler {
c.sendPacket(PacketCreator.enableActions());
return;
} else {
neededCP = skill.cpLoss;
neededCP = skill.cpLoss();
}
}
}

View File

@@ -1039,14 +1039,15 @@ public class StatEffect {
if (skill != null) {
final Disease dis = skill.getDisease();
Party opposition = applyfrom.getParty().getEnemy();
if (skill.targetsAll) {
if (skill.targetsAll()) {
for (PartyCharacter enemyChrs : opposition.getPartyMembers()) {
Character chrApp = enemyChrs.getPlayer();
if (chrApp != null && chrApp.getMap().isCPQMap()) {
if (dis == null) {
chrApp.dispel();
} else {
chrApp.giveDebuff(dis, MCSkill.getMobSkill(dis.getMobSkillType(), skill.level));
MobSkill mobSkill = MobSkillFactory.getMobSkill(dis.getMobSkillType(), skill.level());
chrApp.giveDebuff(dis, mobSkill);
}
}
}
@@ -1058,7 +1059,8 @@ public class StatEffect {
if (dis == null) {
chrApp.dispel();
} else {
chrApp.giveDebuff(dis, MCSkill.getMobSkill(dis.getMobSkillType(), skill.level));
MobSkill mobSkill = MobSkillFactory.getMobSkill(dis.getMobSkillType(), skill.level());
chrApp.giveDebuff(dis, mobSkill);
}
}
}

View File

@@ -47,7 +47,7 @@ public class MobSkillFactory {
private static final Lock readLock = readWriteLock.readLock();
private static final Lock writeLock = readWriteLock.writeLock();
public static MobSkill getMobSkill(final MobSkillType type, final int level) { // TODO: return Optional
public static MobSkill getMobSkill(final MobSkillType type, final int level) {
readLock.lock();
try {
MobSkill ms = mobSkills.get(createKey(type, level));

View File

@@ -90,26 +90,9 @@ public class CarnivalFactory {
return guardians.get(id);
}
public static class MCSkill {
public int cpLoss;
public MobSkillType mobSkillType;
public int level;
public boolean targetsAll;
public MCSkill(int _cpLoss, MobSkillType mobSkillType, int _level, boolean _targetsAll) {
cpLoss = _cpLoss;
mobSkillType = mobSkillType;
level = _level;
targetsAll = _targetsAll;
}
public record MCSkill(int cpLoss, MobSkillType mobSkillType, int level, boolean targetsAll) {
public MobSkill getSkill() {
return getMobSkill(mobSkillType, level);
}
public static MobSkill getMobSkill(MobSkillType type, int level) {
return MobSkillFactory.getMobSkill(type, level);
return MobSkillFactory.getMobSkill(mobSkillType, level);
}
public Disease getDisease() {