Added handler support to NPC API.

This commit is contained in:
luisc committed 2022-01-10 15:21:48 -06:00
1 parent 69f96519dc
commit d50f51e208
40 files changed
+1471 -56

No files matched your search

@@ -1,16 +1,20 @@
package noppes.npcs.quests;
import java.util.HashMap;
import java.util.Vector;
import java.util.*;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NBTTags;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.controllers.PlayerData;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.PlayerQuestData;
import noppes.npcs.controllers.QuestData;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.handler.data.IQuestObjective;
public class QuestKill extends QuestInterface{
public HashMap<String,Integer> targets = new HashMap<String,Integer>();
@@ -74,4 +78,67 @@ public class QuestKill extends QuestInterface{
data.extraData.setTag("Killed", NBTTags.nbtStringIntegerMap(killed));
}
public IQuestObjective[] getObjectives(EntityPlayer player) {
List<IQuestObjective> list = new ArrayList();
Iterator var3 = this.targets.entrySet().iterator();
while(var3.hasNext()) {
Map.Entry<String, Integer> entry = (Map.Entry)var3.next();
list.add(new noppes.npcs.quests.QuestKill.QuestKillObjective(this, player, (String)entry.getKey(), (Integer)entry.getValue()));
}
return (IQuestObjective[])list.toArray(new IQuestObjective[list.size()]);
}
class QuestKillObjective implements IQuestObjective {
private final QuestKill parent;
private final EntityPlayer player;
private final String entity;
private final int amount;
public QuestKillObjective(QuestKill parent, EntityPlayer player, String entity, int amount) {
this.parent = parent;
this.player = player;
this.entity = entity;
this.amount = amount;
}
public int getProgress() {
PlayerData data = PlayerData.get(this.player);
PlayerQuestData playerdata = data.questData;
QuestData questdata = (QuestData)playerdata.activeQuests.get(this.parent.questId);
HashMap<String, Integer> killed = this.parent.getKilled(questdata);
return !killed.containsKey(this.entity) ? 0 : (Integer)killed.get(this.entity);
}
public void setProgress(int progress) {
if (progress >= 0 && progress <= this.amount) {
PlayerData data = PlayerData.get(this.player);
PlayerQuestData playerdata = data.questData;
QuestData questdata = (QuestData)playerdata.activeQuests.get(this.parent.questId);
HashMap<String, Integer> killed = this.parent.getKilled(questdata);
if (!killed.containsKey(this.entity) || (Integer)killed.get(this.entity) != progress) {
killed.put(this.entity, progress);
this.parent.setKilled(questdata, killed);
data.questData.checkQuestCompletion(this.player, EnumQuestType.values()[2]);
data.questData.checkQuestCompletion(this.player, EnumQuestType.values()[4]);
data.saveNBTData(data.getNBT());
}
} else {
throw new CustomNPCsException("Progress has to be between 0 and " + this.amount, new Object[0]);
}
}
public int getMaxProgress() {
return this.amount;
}
public boolean isCompleted() {
return this.getProgress() >= this.amount;
}
public String getText() {
return this.entity + ": " + this.getProgress() + "/" + this.getMaxProgress();
}
}
}