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;
|
2024-03-03 17:37:52 -05:00
|
|
|
import noppes.npcs.constants.*;
|
|
|
|
|
import noppes.npcs.controllers.PartyController;
|
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;
|
2023-05-11 20:17:16 -05:00
|
|
|
private IQuest trackedQuest = null;
|
2022-05-27 14:32:24 -05:00
|
|
|
|
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");
|
2024-03-03 17:37:52 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
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;
|
|
|
|
|
}
|
2024-03-03 17:37:52 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
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");
|
2023-06-05 22:12:48 -04:00
|
|
|
Quest quest = QuestController.Instance.quests.get(id);
|
2018-09-13 12:03:28 -04:00
|
|
|
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
|
|
|
|
2023-06-05 22:12:48 -04: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);
|
|
|
|
|
}
|
2024-03-03 17:37:52 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
compound.setTag("CompletedQuests", list);
|
2024-03-03 17:37:52 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
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);
|
|
|
|
|
}
|
2024-03-03 17:37:52 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
compound.setTag("ActiveQuests", list2);
|
2024-03-03 17:37:52 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
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) {
|
2023-06-05 19:35:27 -04: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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 01:04:15 -05:00
|
|
|
public Party getPartyQuestCompletion(EntityPlayer player,EntityNPCInterface npc) {
|
|
|
|
|
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
|
|
|
|
if(playerData != null){
|
|
|
|
|
Party party = playerData.getPlayerParty();
|
|
|
|
|
if(party != null){
|
|
|
|
|
QuestData data = party.getQuestData();
|
|
|
|
|
if(data != null){
|
|
|
|
|
Quest quest = data.quest;
|
|
|
|
|
if(quest != null && quest.completion == EnumQuestCompletion.Npc && quest.completerNpc.equals(npc.getCommandSenderName()) && quest.questInterface.isPartyCompleted(party)){
|
|
|
|
|
return party;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-03-03 17:37:52 -05:00
|
|
|
int partyQuestID = -1;
|
|
|
|
|
if(playerData.partyUUID != null){
|
|
|
|
|
Party party = PartyController.Instance().getParty(playerData.partyUUID);
|
|
|
|
|
if(party != null){
|
|
|
|
|
IQuest quest = party.getQuest();
|
|
|
|
|
if(quest != null){
|
|
|
|
|
partyQuestID = quest.getId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
2024-03-03 17:37:52 -05:00
|
|
|
// Check if Active Quest = Party Quest
|
|
|
|
|
if(partyQuestID != -1 && data.quest.id == partyQuestID && data.quest.partyOptions.isAllowParty()){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-29 04:45:38 -05:00
|
|
|
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)){
|
2018-09-13 12:03:28 -04:00
|
|
|
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
|
|
|
}
|
2023-05-14 19:14:43 -05:00
|
|
|
|
|
|
|
|
if (this.trackedQuest != null && data.quest.getId() == this.trackedQuest.getId()) {
|
|
|
|
|
NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) player);
|
|
|
|
|
}
|
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
|
|
|
|
2023-05-11 20:17:16 -05:00
|
|
|
public void trackQuest(IQuest quest) {
|
2023-05-11 20:27:00 -05:00
|
|
|
if (this.trackedQuest == null || quest.getId() != this.trackedQuest.getId()) {
|
2023-05-11 20:17:16 -05:00
|
|
|
this.trackedQuest = quest;
|
2023-05-14 19:14:43 -05:00
|
|
|
NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) this.parent.player);
|
2023-05-11 20:17:16 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void untrackQuest() {
|
2023-05-14 19:14:43 -05:00
|
|
|
if (this.trackedQuest != null) {
|
|
|
|
|
this.trackedQuest = null;
|
|
|
|
|
Server.sendData((EntityPlayerMP) this.parent.player, EnumPacketClient.OVERLAY_QUEST_TRACKING);
|
|
|
|
|
}
|
2023-05-11 20:17:16 -05:00
|
|
|
}
|
|
|
|
|
|
2022-06-12 01:26:23 -05:00
|
|
|
public IQuest getTrackedQuest() {
|
2023-05-11 20:17:16 -05:00
|
|
|
return this.trackedQuest;
|
2022-06-12 01:26:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startQuest(int id) {
|
2023-06-05 22:12:48 -04:00
|
|
|
Quest quest = QuestController.Instance.quests.get(id);
|
2022-06-12 01:26:23 -05:00
|
|
|
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) {
|
2023-06-05 22:12:48 -04:00
|
|
|
Quest quest = QuestController.Instance.quests.get(id);
|
2022-06-12 01:26:23 -05:00
|
|
|
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) {
|
2023-06-05 22:12:48 -04:00
|
|
|
Quest quest = QuestController.Instance.quests.get(id);
|
2022-06-12 01:26:23 -05:00
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
|
|
|
|
activeQuests.remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeQuest(int id) {
|
2023-06-05 22:12:48 -04:00
|
|
|
Quest quest = QuestController.Instance.quests.get(id);
|
2022-06-12 01:26:23 -05:00
|
|
|
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()) {
|
2023-06-05 22:12:48 -04:00
|
|
|
IQuest quest = (IQuest) QuestController.Instance.quests.get(id);
|
2022-06-12 01:26:23 -05:00
|
|
|
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()) {
|
2023-06-05 22:12:48 -04:00
|
|
|
IQuest quest = (IQuest) QuestController.Instance.quests.get(id);
|
2022-06-12 01:26:23 -05:00
|
|
|
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) {
|
2023-06-05 22:12:48 -04:00
|
|
|
Quest quest = QuestController.Instance.quests.get(id);
|
2022-12-20 09:21:39 -06:00
|
|
|
if (quest == null)
|
|
|
|
|
return;
|
|
|
|
|
this.finishedQuests.put(id,time);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|