Fix mob using attack with no diseaseSkill causing errors
This commit is contained in:
@@ -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())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user