mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 21:09:40 +00:00
Added handler support to NPC API.
This commit is contained in:
1 parent
69f96519dc
commit
d50f51e208
40 files changed
+1471
-56
No files matched your search
@@ -1,14 +1,20 @@
|
||||
package noppes.npcs.quests;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.controllers.Dialog;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.PlayerData;
|
||||
import noppes.npcs.controllers.PlayerDataController;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.handler.data.IQuestObjective;
|
||||
|
||||
public class QuestDialog extends QuestInterface{
|
||||
|
||||
@@ -55,4 +61,69 @@ public class QuestDialog extends QuestInterface{
|
||||
return vec;
|
||||
}
|
||||
|
||||
public IQuestObjective[] getObjectives(EntityPlayer player) {
|
||||
List<IQuestObjective> list = new ArrayList();
|
||||
|
||||
for(int i = 0; i < 3; ++i) {
|
||||
if (this.dialogs.containsKey(i)) {
|
||||
Dialog dialog = (Dialog)DialogController.instance.dialogs.get(this.dialogs.get(i));
|
||||
if (dialog != null) {
|
||||
list.add(new noppes.npcs.quests.QuestDialog.QuestDialogObjective(this, player, dialog));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]);
|
||||
}
|
||||
|
||||
class QuestDialogObjective implements IQuestObjective {
|
||||
private final QuestDialog parent;
|
||||
private final EntityPlayer player;
|
||||
private final Dialog dialog;
|
||||
|
||||
public QuestDialogObjective(QuestDialog this$0, EntityPlayer player, Dialog dialog) {
|
||||
this.parent = this$0;
|
||||
this.player = player;
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
public int getProgress() {
|
||||
return this.isCompleted() ? 1 : 0;
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
if (progress >= 0 && progress <= 1) {
|
||||
PlayerData data = PlayerData.get(this.player);
|
||||
boolean completed = data.dialogData.dialogsRead.contains(this.dialog.id);
|
||||
if (progress == 0 && completed) {
|
||||
data.dialogData.dialogsRead.remove(this.dialog.id);
|
||||
data.questData.checkQuestCompletion(this.player, EnumQuestType.values()[1]);
|
||||
data.saveNBTData(data.getNBT());
|
||||
}
|
||||
|
||||
if (progress == 1 && !completed) {
|
||||
data.dialogData.dialogsRead.add(this.dialog.id);
|
||||
data.questData.checkQuestCompletion(this.player, EnumQuestType.values()[1]);
|
||||
data.saveNBTData(data.getNBT());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new CustomNPCsException("Progress has to be 0 or 1", new Object[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public int getMaxProgress() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean isCompleted() {
|
||||
PlayerData data = PlayerData.get(this.player);
|
||||
return data.dialogData.dialogsRead.contains(this.dialog.id);
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return this.dialog.title + (this.isCompleted() ? " (read)" : " (unread)");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user