2022-05-24 01:07:50 -05:00
|
|
|
package noppes.npcs.controllers.data;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2022-01-12 20:12:16 -06:00
|
|
|
import noppes.npcs.EventHooks;
|
2022-05-29 04:45:38 -05:00
|
|
|
import noppes.npcs.NoppesUtilPlayer;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.Server;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.api.handler.IPlayerQuestData;
|
|
|
|
|
import noppes.npcs.api.handler.data.IQuest;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.constants.EnumPacketClient;
|
|
|
|
|
import noppes.npcs.constants.EnumQuestCompletion;
|
2023-05-11 11:57:39 -04:00
|
|
|
import noppes.npcs.constants.EnumQuestRepeat;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.constants.EnumQuestType;
|
2022-05-24 01:07:50 -05:00
|
|
|
import noppes.npcs.controllers.PlayerDataController;
|
|
|
|
|
import noppes.npcs.controllers.QuestController;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
import noppes.npcs.quests.QuestInterface;
|
2022-06-13 04:08:36 -05:00
|
|
|
import noppes.npcs.quests.QuestItem;
|
2023-01-12 21:33:06 -05:00
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2022-06-12 01:26:23 -05:00
|
|
|
public class PlayerQuestData implements IPlayerQuestData {
|
|
|
|
|
private final PlayerData parent;
|
2022-05-27 14:32:24 -05:00
|
|
|
public IQuest trackedQuest = null;
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public HashMap<Integer,QuestData> activeQuests = new HashMap<Integer,QuestData>();
|
|
|
|
|
public HashMap<Integer,Long> finishedQuests = new HashMap<Integer,Long>();
|
2022-06-12 01:26:23 -05:00
|
|
|
|
|
|
|
|
public PlayerQuestData(PlayerData parent) {
|
|
|
|
|
this.parent = parent;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public void loadNBTData(NBTTagCompound mainCompound) {
|
|
|
|
|
if(mainCompound == null)
|
|
|
|
|
return;
|
|
|
|
|
NBTTagCompound compound = mainCompound.getCompoundTag("QuestData");
|
|
|
|
|
|
|
|
|
|
NBTTagList list = compound.getTagList("CompletedQuests", 10);
|
|
|
|
|
if(list != null){
|
|
|
|
|
HashMap<Integer,Long> finishedQuests = new HashMap<Integer,Long>();
|
|
|
|
|
for(int i = 0; i < list.tagCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound nbttagcompound = list.getCompoundTagAt(i);
|
|
|
|
|
finishedQuests.put(nbttagcompound.getInteger("Quest"),nbttagcompound.getLong("Date"));
|
|
|
|
|
}
|
|
|
|
|
this.finishedQuests = finishedQuests;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NBTTagList list2 = compound.getTagList("ActiveQuests", 10);
|
|
|
|
|
if(list2 != null){
|
|
|
|
|
HashMap<Integer,QuestData> activeQuests = new HashMap<Integer,QuestData>();
|
|
|
|
|
for(int i = 0; i < list2.tagCount(); i++)
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound nbttagcompound = list2.getCompoundTagAt(i);
|
|
|
|
|
int id = nbttagcompound.getInteger("Quest");
|
|
|
|
|
Quest quest = QuestController.instance.quests.get(id);
|
|
|
|
|
if(quest == null)
|
|
|
|
|
continue;
|
|
|
|
|
QuestData data = new QuestData(quest);
|
|
|
|
|
data.readEntityFromNBT(nbttagcompound);
|
|
|
|
|
activeQuests.put(id,data);
|
|
|
|
|
}
|
|
|
|
|
this.activeQuests = activeQuests;
|
|
|
|
|
}
|
2022-05-27 14:32:24 -05:00
|
|
|
|
|
|
|
|
this.trackedQuest = QuestController.instance.get(mainCompound.getInteger("TrackedQuestID"));
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void saveNBTData(NBTTagCompound maincompound) {
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
NBTTagList list = new NBTTagList();
|
|
|
|
|
for(int quest : finishedQuests.keySet()){
|
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
|
nbttagcompound.setInteger("Quest", quest);
|
|
|
|
|
nbttagcompound.setLong("Date", finishedQuests.get(quest));
|
|
|
|
|
list.appendTag(nbttagcompound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
compound.setTag("CompletedQuests", list);
|
|
|
|
|
|
|
|
|
|
NBTTagList list2 = new NBTTagList();
|
|
|
|
|
for(int quest : activeQuests.keySet()){
|
|
|
|
|
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
|
|
|
|
nbttagcompound.setInteger("Quest", quest);
|
|
|
|
|
activeQuests.get(quest).writeEntityToNBT(nbttagcompound);
|
|
|
|
|
list2.appendTag(nbttagcompound);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
compound.setTag("ActiveQuests", list2);
|
|
|
|
|
|
|
|
|
|
maincompound.setTag("QuestData", compound);
|
2022-05-27 14:32:24 -05:00
|
|
|
|
|
|
|
|
if (this.trackedQuest != null) {
|
|
|
|
|
maincompound.setInteger("TrackedQuestID", this.trackedQuest.getId());
|
|
|
|
|
} else {
|
|
|
|
|
maincompound.setInteger("TrackedQuestID", -1);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public QuestData getQuestCompletion(EntityPlayer player,EntityNPCInterface npc) {
|
2022-02-02 07:18:33 -06:00
|
|
|
PlayerData playerData = PlayerDataController.instance.getPlayerData(player);
|
2018-09-13 12:03:28 -04:00
|
|
|
for(QuestData data : activeQuests.values()){
|
|
|
|
|
Quest quest = data.quest;
|
2022-02-02 07:18:33 -06:00
|
|
|
if(quest != null && quest.completion == EnumQuestCompletion.Npc && quest.completerNpc.equals(npc.getCommandSenderName()) && quest.questInterface.isCompleted(playerData)){
|
2018-09-13 12:03:28 -04:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 07:18:33 -06:00
|
|
|
public boolean checkQuestCompletion(PlayerData playerData,EnumQuestType type) {
|
2018-09-13 12:03:28 -04:00
|
|
|
boolean bo = false;
|
2022-02-02 07:18:33 -06:00
|
|
|
EntityPlayer player = playerData.player;
|
2022-07-20 16:26:09 -05:00
|
|
|
|
|
|
|
|
ArrayList<QuestData> activeQuestValues = new ArrayList<>(this.activeQuests.values());
|
|
|
|
|
for(QuestData data : activeQuestValues){
|
2018-09-13 12:03:28 -04:00
|
|
|
if(data.quest.type != type && type != null)
|
|
|
|
|
continue;
|
2022-02-02 07:18:33 -06:00
|
|
|
|
2022-05-29 04:45:38 -05:00
|
|
|
NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) player,data.quest);
|
|
|
|
|
|
|
|
|
|
QuestInterface inter = data.quest.questInterface;
|
2022-02-02 07:18:33 -06:00
|
|
|
if(inter.isCompleted(playerData)){
|
2023-03-16 23:37:57 -05:00
|
|
|
if((!data.isCompleted && data.quest.completion == EnumQuestCompletion.Npc) || data.quest.instantComplete(player,data)){
|
|
|
|
|
if (data.quest.completeText.isEmpty() && data.sendAlerts) {
|
2018-09-13 12:03:28 -04:00
|
|
|
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.completed", data.quest.title);
|
|
|
|
|
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.completed",": ",data.quest.title);
|
|
|
|
|
}
|
|
|
|
|
data.isCompleted = true;
|
2023-03-16 23:37:57 -05:00
|
|
|
if (data.quest.completion == EnumQuestCompletion.Npc) {
|
|
|
|
|
EventHooks.onQuestFinished(player, data.quest);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
bo = true;
|
|
|
|
|
}
|
2023-03-16 23:37:57 -05:00
|
|
|
} else {
|
2018-09-13 12:03:28 -04:00
|
|
|
data.isCompleted = false;
|
2023-03-16 23:37:57 -05:00
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
2022-06-13 04:08:36 -05:00
|
|
|
QuestItem.pickedUp = null;
|
2018-09-13 12:03:28 -04:00
|
|
|
return bo;
|
|
|
|
|
|
|
|
|
|
}
|
2022-06-12 01:26:23 -05:00
|
|
|
|
|
|
|
|
public IQuest getTrackedQuest() {
|
|
|
|
|
return trackedQuest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startQuest(int id) {
|
|
|
|
|
Quest quest = QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
|
|
|
|
if(activeQuests.containsKey(id))
|
|
|
|
|
return;
|
|
|
|
|
QuestData questdata = new QuestData(quest);
|
|
|
|
|
activeQuests.put(id, questdata);
|
|
|
|
|
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
|
|
|
|
|
Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void finishQuest(int id) {
|
|
|
|
|
Quest quest = QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
2023-05-11 11:57:39 -04:00
|
|
|
|
|
|
|
|
if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY)
|
|
|
|
|
finishedQuests.put(quest.id, System.currentTimeMillis());
|
|
|
|
|
else
|
|
|
|
|
finishedQuests.put(quest.id, parent.player.worldObj.getTotalWorldTime());
|
2022-06-12 01:26:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void stopQuest(int id) {
|
|
|
|
|
Quest quest = QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
|
|
|
|
activeQuests.remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeQuest(int id) {
|
|
|
|
|
Quest quest = QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
|
|
|
|
activeQuests.remove(id);
|
|
|
|
|
finishedQuests.remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasFinishedQuest(int id){
|
|
|
|
|
return finishedQuests.containsKey(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasActiveQuest(int id){
|
|
|
|
|
return activeQuests.containsKey(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IQuest[] getActiveQuests() {
|
|
|
|
|
List<IQuest> quests = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int id : activeQuests.keySet()) {
|
|
|
|
|
IQuest quest = (IQuest) QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest != null) {
|
|
|
|
|
quests.add(quest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (IQuest[])quests.toArray(new IQuest[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IQuest[] getFinishedQuests() {
|
|
|
|
|
List<IQuest> quests = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int id : finishedQuests.keySet()) {
|
|
|
|
|
IQuest quest = (IQuest) QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest != null) {
|
|
|
|
|
quests.add(quest);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (IQuest[])quests.toArray(new IQuest[0]);
|
|
|
|
|
}
|
2022-12-20 09:21:39 -06:00
|
|
|
|
|
|
|
|
public long getLastCompletedTime(int id) {
|
|
|
|
|
if (this.hasFinishedQuest(id)) {
|
|
|
|
|
return this.finishedQuests.get(id);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLastCompletedTime(int id,long time) {
|
|
|
|
|
Quest quest = QuestController.instance.quests.get(id);
|
|
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
|
|
|
|
this.finishedQuests.put(id,time);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|