Added custom kill types

This commit is contained in:
luisc committed 2022-02-02 22:11:49 -06:00
1 parent 7e0ff3c836
commit 47f41ff5b7
3 files changed
+26 -6

No files matched your search

@@ -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();
@@ -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(){
@@ -20,12 +20,14 @@ import noppes.npcs.scripted.handler.data.IQuestObjective;
public class QuestKill extends QuestInterface implements IQuestKill {
public HashMap<String,Integer> targets = new HashMap<String,Integer>();
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;
}