Fix mob using attack with no diseaseSkill causing errors

This commit is contained in:
P0nk
2022-09-12 20:31:38 +02:00
parent 0c6548a36d
commit d31f4806fc
14 changed files with 71 additions and 45 deletions

View File

@@ -7326,7 +7326,8 @@ public class Character extends AbstractCharacterObject {
final int skilllv = rs.getInt("mobskilllv");
final long length = rs.getInt("length");
MobSkill ms = MobSkillFactory.getMobSkill(MobSkillType.from(skillid), skilllv);
MobSkillType type = MobSkillType.from(skillid).orElseThrow();
MobSkill ms = MobSkillFactory.getMobSkillOrThrow(type, skilllv);
loadedDiseases.put(disease, new Pair<>(length, ms));
}
}

View File

@@ -8,6 +8,7 @@ import server.life.MobSkillFactory;
import server.life.MobSkillType;
import java.util.Collections;
import java.util.Optional;
public class MobSkillCommand extends Command {
{
@@ -22,13 +23,18 @@ public class MobSkillCommand extends Command {
String skillId = params[0];
String skillLevel = params[1];
MobSkillType type = MobSkillType.from(Integer.parseInt(skillId));
MobSkill mobSkill = MobSkillFactory.getMobSkill(type, Integer.parseInt(skillLevel));
if (mobSkill == null) {
throw new IllegalArgumentException("Mob skill not found. Id: %s, level: %s".formatted(skillId, skillLevel));
Optional<MobSkillType> possibleType = MobSkillType.from(Integer.parseInt(skillId));
Optional<MobSkill> possibleSkill = possibleType.map(
type -> MobSkillFactory.getMobSkillOrThrow(type, Integer.parseInt(skillLevel))
);
if (possibleSkill.isEmpty()) {
return;
}
Character chr = client.getPlayer();
chr.getMap().getAllMonsters().forEach(monster -> mobSkill.applyEffect(chr, monster, false, Collections.emptyList()));
MobSkill mobSkill = possibleSkill.get();
chr.getMap().getAllMonsters().forEach(
monster -> mobSkill.applyEffect(chr, monster, false, Collections.emptyList())
);
}
}

View File

@@ -34,6 +34,7 @@ import server.maps.MapObject;
import server.maps.MapObjectType;
import java.util.Arrays;
import java.util.Optional;
public class DebuffCommand extends Command {
{
@@ -49,7 +50,7 @@ public class DebuffCommand extends Command {
}
Disease disease = null;
MobSkill skill = null;
Optional<MobSkill> skill = Optional.empty();
switch (params[0].toUpperCase()) {
case "SLOW" -> {
@@ -94,7 +95,7 @@ public class DebuffCommand extends Command {
}
}
if (disease == null) {
if (disease == null || skill.isEmpty()) {
player.yellowMessage("Syntax: !debuff SLOW|SEDUCE|ZOMBIFY|CONFUSE|STUN|POISON|SEAL|DARKNESS|WEAKEN|CURSE");
return;
}
@@ -103,7 +104,7 @@ public class DebuffCommand extends Command {
Character chr = (Character) mmo;
if (chr.getId() != player.getId()) {
chr.giveDebuff(disease, skill);
chr.giveDebuff(disease, skill.get());
}
}
}