From 47f41ff5b7475314b625ece697627973a865f158 Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 2 Feb 2022 22:11:49 -0600 Subject: [PATCH] Added custom kill types --- src/main/java/noppes/npcs/ServerEventsHandler.java | 11 ++++++++++- .../client/gui/questtypes/GuiNpcQuestTypeKill.java | 14 +++++++++++--- src/main/java/noppes/npcs/quests/QuestKill.java | 7 +++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 09049d05e..5d996b6c7 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -308,7 +308,16 @@ public class ServerEventsHandler { } String name = entityName; QuestKill quest = (QuestKill) data.quest.questInterface; - if(quest.targetType == 1 && !(entity instanceof EntityNPCInterface)) + + Class entityType = EntityNPCInterface.class; + if(quest.targetType == 2) { + try { + entityType = Class.forName(quest.customTargetType); + } catch (ClassNotFoundException notFoundException) { + continue; + } + } + if(quest.targetType > 0 && !(entityType.isInstance(entity))) continue; if(quest.targets.containsKey(entity.getCommandSenderName())) name = entity.getCommandSenderName(); diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java index 40a5cc9ae..0e1dc39e1 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeKill.java @@ -88,8 +88,12 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi addScroll(scroll); guiTop += 50; - this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 300, 98, 20, "gui.back")); - this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + 260, 98, 20, new String[]{"Any", "NPCs"}, quest.targetType)); + this.addButton(new GuiNpcButton(0, guiLeft + 4, guiTop + 310, 98, 20, "gui.back")); + this.addButton(new GuiNpcButton(1, guiLeft + 4, guiTop + 260, 98, 20, new String[]{"Any", "NPCs", "Custom"}, quest.targetType)); + + this.addTextField(new GuiNpcTextField(36, this, fontRendererObj, guiLeft + 4, guiTop + 282, 180, 20, quest.customTargetType)); + this.getTextField(36).setVisible(this.getButton(1).getValue() == 2); + guiTop -= 50; scroll.visible = GuiNpcTextField.isFieldActive(); @@ -101,7 +105,8 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi close(); } if (guibutton.id == 1) { - quest.targetType = guibutton.displayString.equals("NPCs") ? 1 : 0; + quest.targetType = this.getButton(1).getValue(); + this.getTextField(36).setVisible(this.getButton(1).getValue() == 2); } } public void mouseClicked(int i, int j, int k) @@ -117,6 +122,9 @@ public class GuiNpcQuestTypeKill extends SubGuiInterface implements ITextfieldLi if(guiNpcTextField.id < 12) lastSelected = guiNpcTextField; + if(guiNpcTextField.id == 36) + quest.customTargetType = guiNpcTextField.getText(); + saveTargets(); } private void saveTargets(){ diff --git a/src/main/java/noppes/npcs/quests/QuestKill.java b/src/main/java/noppes/npcs/quests/QuestKill.java index d4568c1eb..79206dffd 100644 --- a/src/main/java/noppes/npcs/quests/QuestKill.java +++ b/src/main/java/noppes/npcs/quests/QuestKill.java @@ -20,12 +20,14 @@ import noppes.npcs.scripted.handler.data.IQuestObjective; public class QuestKill extends QuestInterface implements IQuestKill { public HashMap targets = new HashMap(); public int targetType = 0; + public String customTargetType = "noppes.npcs.entity.EntityCustomNpc"; @Override public void writeEntityToNBT(NBTTagCompound compound) { compound.setTag("QuestKills", NBTTags.nbtStringIntegerMap(targets)); //compound.setTag("QuestDialogs", NBTTags.nbtStringIntegerMap(targets)); compound.setInteger("TargetType",targetType); + compound.setString("CustomTargetType",customTargetType); } @Override @@ -40,6 +42,7 @@ public class QuestKill extends QuestInterface implements IQuestKill { //targets = NBTTags.getStringIntegerMap(compound.getTagList("QuestDialogs", 10)); targetType = compound.getInteger("TargetType"); + customTargetType = compound.getString("CustomTargetType"); } @Override @@ -106,8 +109,8 @@ public class QuestKill extends QuestInterface implements IQuestKill { public void setTargetType(int type) { if(type < 0) type = 0; - if(type > 1) - type = 1; + if(type > 2) + type = 2; this.targetType = type; }