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;
|
2022-06-13 04:08:36 -05:00
|
|
|
import noppes.npcs.*;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.api.IContainer;
|
|
|
|
|
import noppes.npcs.api.entity.IPlayer;
|
|
|
|
|
import noppes.npcs.api.handler.data.IQuest;
|
|
|
|
|
import noppes.npcs.api.handler.data.IQuestCategory;
|
|
|
|
|
import noppes.npcs.api.handler.data.IQuestInterface;
|
|
|
|
|
import noppes.npcs.api.handler.data.IQuestObjective;
|
2023-11-01 00:06:41 -04:00
|
|
|
import noppes.npcs.config.ConfigMain;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.constants.EnumPacketClient;
|
|
|
|
|
import noppes.npcs.constants.EnumQuestCompletion;
|
|
|
|
|
import noppes.npcs.constants.EnumQuestRepeat;
|
|
|
|
|
import noppes.npcs.constants.EnumQuestType;
|
2022-12-20 09:21:39 -06:00
|
|
|
import noppes.npcs.controllers.PlayerDataController;
|
2022-05-24 01:07:50 -05:00
|
|
|
import noppes.npcs.controllers.QuestController;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.quests.*;
|
2022-01-10 15:21:48 -06:00
|
|
|
import noppes.npcs.scripted.CustomNPCsException;
|
2022-05-11 22:08:31 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public class Quest implements ICompatibilty, IQuest {
|
2018-09-13 12:03:28 -04:00
|
|
|
public int version = VersionCompatibility.ModRev;
|
|
|
|
|
public int id = -1;
|
|
|
|
|
public EnumQuestType type = EnumQuestType.Item;
|
|
|
|
|
public EnumQuestRepeat repeat = EnumQuestRepeat.NONE;
|
|
|
|
|
public EnumQuestCompletion completion = EnumQuestCompletion.Npc;
|
|
|
|
|
public String title = "default";
|
|
|
|
|
public QuestCategory category;
|
|
|
|
|
public String logText = "";
|
|
|
|
|
public String completeText = "";
|
|
|
|
|
public String completerNpc = "";
|
|
|
|
|
public int nextQuestid = -1;
|
|
|
|
|
public String nextQuestTitle = "";
|
|
|
|
|
public PlayerMail mail = new PlayerMail();
|
|
|
|
|
public String command = "";
|
2023-10-30 21:06:01 -04:00
|
|
|
|
|
|
|
|
public boolean allowParty = false;
|
|
|
|
|
public byte partyRequirements = 0; // 0 - Only Party Leaders, 1 - Everyone
|
|
|
|
|
public byte rewardControl = 0; // 0 - Only Party Leaders, 1 - Everyone
|
2023-11-01 00:06:41 -04:00
|
|
|
public int maxPartySize = 4;
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
public QuestInterface questInterface = new QuestItem();
|
|
|
|
|
|
|
|
|
|
public int rewardExp = 0;
|
|
|
|
|
public NpcMiscInventory rewardItems = new NpcMiscInventory(9);
|
|
|
|
|
public boolean randomReward = false;
|
|
|
|
|
public FactionOptions factionOptions = new FactionOptions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void readNBT(NBTTagCompound compound) {
|
|
|
|
|
id = compound.getInteger("Id");
|
|
|
|
|
readNBTPartial(compound);
|
|
|
|
|
}
|
|
|
|
|
public void readNBTPartial(NBTTagCompound compound) {
|
|
|
|
|
version = compound.getInteger("ModRev");
|
|
|
|
|
VersionCompatibility.CheckAvailabilityCompatibility(this, compound);
|
|
|
|
|
|
|
|
|
|
setType(EnumQuestType.values()[compound.getInteger("Type")]);
|
|
|
|
|
title = compound.getString("Title");
|
|
|
|
|
logText = compound.getString("Text");
|
|
|
|
|
completeText = compound.getString("CompleteText");
|
|
|
|
|
completerNpc = compound.getString("CompleterNpc");
|
|
|
|
|
command = compound.getString("QuestCommand");
|
|
|
|
|
nextQuestid = compound.getInteger("NextQuestId");
|
|
|
|
|
nextQuestTitle = compound.getString("NextQuestTitle");
|
|
|
|
|
if(hasNewQuest())
|
|
|
|
|
nextQuestTitle = getNextQuest().title;
|
|
|
|
|
else
|
|
|
|
|
nextQuestTitle = "";
|
|
|
|
|
randomReward = compound.getBoolean("RandomReward");
|
|
|
|
|
rewardExp = compound.getInteger("RewardExp");
|
|
|
|
|
rewardItems.setFromNBT(compound.getCompoundTag("Rewards"));
|
|
|
|
|
|
|
|
|
|
completion = EnumQuestCompletion.values()[compound.getInteger("QuestCompletion")];
|
|
|
|
|
repeat = EnumQuestRepeat.values()[compound.getInteger("QuestRepeat")];
|
|
|
|
|
|
|
|
|
|
questInterface.readEntityFromNBT(compound);
|
|
|
|
|
|
|
|
|
|
factionOptions.readFromNBT(compound.getCompoundTag("QuestFactionPoints"));
|
|
|
|
|
|
|
|
|
|
mail.readNBT(compound.getCompoundTag("QuestMail"));
|
2023-11-01 00:06:41 -04:00
|
|
|
|
|
|
|
|
// Party Management
|
|
|
|
|
allowParty = compound.getBoolean("AllowParty");
|
|
|
|
|
if(allowParty){
|
|
|
|
|
partyRequirements = compound.getByte("PartyRequirements");
|
|
|
|
|
rewardControl = compound.getByte("RewardControl");
|
|
|
|
|
maxPartySize = compound.getInteger("MaxPartySize");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(compound.hasKey("PartyRequirements")){
|
|
|
|
|
compound.removeTag("PartyRequirements");
|
|
|
|
|
}
|
|
|
|
|
if(compound.hasKey("RewardControl")){
|
|
|
|
|
compound.removeTag("RewardControl");
|
|
|
|
|
}
|
|
|
|
|
if(compound.hasKey("MaxPartySize")){
|
|
|
|
|
compound.removeTag("MaxPartySize");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partyRequirements = 0;
|
|
|
|
|
rewardControl = 0;
|
|
|
|
|
maxPartySize = ConfigMain.DefaultMaxPartySize;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setType(EnumQuestType questType) {
|
|
|
|
|
type = questType;
|
|
|
|
|
if(type == EnumQuestType.Item)
|
|
|
|
|
questInterface = new QuestItem();
|
|
|
|
|
else if(type == EnumQuestType.Dialog)
|
|
|
|
|
questInterface = new QuestDialog();
|
|
|
|
|
else if(type == EnumQuestType.Kill || type == EnumQuestType.AreaKill)
|
|
|
|
|
questInterface = new QuestKill();
|
|
|
|
|
else if(type == EnumQuestType.Location)
|
|
|
|
|
questInterface = new QuestLocation();
|
|
|
|
|
|
|
|
|
|
if(questInterface != null)
|
|
|
|
|
questInterface.questId = id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
|
|
|
|
compound.setInteger("Id", id);
|
|
|
|
|
return writeToNBTPartial(compound);
|
|
|
|
|
}
|
|
|
|
|
public NBTTagCompound writeToNBTPartial(NBTTagCompound compound) {
|
|
|
|
|
compound.setInteger("ModRev", version);
|
|
|
|
|
compound.setInteger("Type", type.ordinal());
|
|
|
|
|
compound.setString("Title", title);
|
|
|
|
|
compound.setString("Text", logText);
|
|
|
|
|
compound.setString("CompleteText", completeText);
|
|
|
|
|
compound.setString("CompleterNpc", completerNpc);
|
|
|
|
|
compound.setInteger("NextQuestId", nextQuestid);
|
|
|
|
|
compound.setString("NextQuestTitle", nextQuestTitle);
|
|
|
|
|
compound.setInteger("RewardExp", rewardExp);
|
|
|
|
|
compound.setTag("Rewards", rewardItems.getToNBT());
|
|
|
|
|
compound.setString("QuestCommand", command);
|
|
|
|
|
compound.setBoolean("RandomReward", randomReward);
|
|
|
|
|
|
|
|
|
|
compound.setInteger("QuestCompletion", completion.ordinal());
|
|
|
|
|
compound.setInteger("QuestRepeat", repeat.ordinal());
|
|
|
|
|
|
|
|
|
|
this.questInterface.writeEntityToNBT(compound);
|
|
|
|
|
compound.setTag("QuestFactionPoints", factionOptions.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
compound.setTag("QuestMail", mail.writeNBT());
|
2023-11-01 00:06:41 -04:00
|
|
|
|
|
|
|
|
compound.setBoolean("AllowParty", allowParty);
|
|
|
|
|
if(allowParty){
|
|
|
|
|
compound.setByte("PartyRequirements", partyRequirements);
|
|
|
|
|
compound.setByte("RewardControl", rewardControl);
|
|
|
|
|
compound.setInteger("MaxPartySize", maxPartySize);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if(compound.hasKey("PartyRequirements")){
|
|
|
|
|
compound.removeTag("PartyRequirements");
|
|
|
|
|
}
|
|
|
|
|
if(compound.hasKey("RewardControl")){
|
|
|
|
|
compound.removeTag("RewardControl");
|
|
|
|
|
}
|
|
|
|
|
if(compound.hasKey("MaxPartySize")){
|
|
|
|
|
compound.removeTag("MaxPartySize");
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
return compound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasNewQuest()
|
|
|
|
|
{
|
|
|
|
|
return getNextQuest() != null;
|
|
|
|
|
}
|
|
|
|
|
public Quest getNextQuest()
|
|
|
|
|
{
|
2023-06-05 22:12:48 -04:00
|
|
|
return QuestController.Instance == null?null:QuestController.Instance.quests.get(nextQuestid);
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|
|
|
|
|
|
2023-03-16 23:37:57 -05:00
|
|
|
public boolean instantComplete(EntityPlayer player, QuestData data) {
|
|
|
|
|
if(completion == EnumQuestCompletion.Instant && NoppesUtilPlayer.questCompletion((EntityPlayerMP) player, data.quest.id)){
|
2018-09-13 12:03:28 -04:00
|
|
|
Server.sendData((EntityPlayerMP)player, EnumPacketClient.QUEST_COMPLETION, data.quest.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
public Quest copy(){
|
|
|
|
|
Quest quest = new Quest();
|
|
|
|
|
quest.readNBT(this.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
return quest;
|
|
|
|
|
}
|
2022-12-20 09:21:39 -06:00
|
|
|
|
|
|
|
|
public long getTimeUntilRepeat(EntityPlayer player) {
|
2023-06-05 19:35:27 -04:00
|
|
|
long questTime = PlayerDataController.Instance.getPlayerData(player).getQuestData().getLastCompletedTime(this.id);
|
2022-12-20 09:21:39 -06:00
|
|
|
|
|
|
|
|
switch (repeat) {
|
|
|
|
|
case MCDAILY:
|
2023-05-11 16:45:25 -04:00
|
|
|
return Math.max(0, (questTime + 24000 - player.worldObj.getTotalWorldTime()) * 50);
|
2022-12-20 09:21:39 -06:00
|
|
|
case MCWEEKLY:
|
2023-05-11 16:45:25 -04:00
|
|
|
return Math.max(0, (questTime + 168000 - player.worldObj.getTotalWorldTime()) * 50);
|
2022-12-20 09:21:39 -06:00
|
|
|
case RLDAILY:
|
2023-05-11 16:45:25 -04:00
|
|
|
return Math.max(0, questTime + 86400000 - System.currentTimeMillis());
|
2022-12-20 09:21:39 -06:00
|
|
|
case RLWEEKLY:
|
|
|
|
|
return Math.max(0, questTime + 604800000 - System.currentTimeMillis());
|
|
|
|
|
}
|
|
|
|
|
return 0L;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getVersion() {
|
|
|
|
|
return version;
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void setVersion(int version) {
|
|
|
|
|
this.version = version;
|
|
|
|
|
}
|
2022-01-10 15:21:48 -06:00
|
|
|
|
|
|
|
|
public int getId() {
|
|
|
|
|
return this.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
|
return this.title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getType() {
|
|
|
|
|
return this.type.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setType(int questType) {
|
|
|
|
|
if(questType < 0 || questType >= EnumQuestType.values().length)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
EnumQuestType type = EnumQuestType.values()[questType];
|
|
|
|
|
setType(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IQuestCategory getCategory() {
|
|
|
|
|
return this.category;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save() {
|
2023-06-05 22:12:48 -04:00
|
|
|
QuestController.Instance.saveQuest(this.category.id, this);
|
2022-01-10 15:21:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setName(String name) {
|
|
|
|
|
this.title = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLogText() {
|
|
|
|
|
return this.logText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setLogText(String text) {
|
|
|
|
|
this.logText = text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getCompleteText() {
|
|
|
|
|
return this.completeText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setCompleteText(String text) {
|
|
|
|
|
this.completeText = text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNextQuest(IQuest quest) {
|
|
|
|
|
if (quest == null) {
|
|
|
|
|
this.nextQuestid = -1;
|
|
|
|
|
this.nextQuestTitle = "";
|
|
|
|
|
} else {
|
|
|
|
|
if (quest.getId() < 0) {
|
|
|
|
|
throw new CustomNPCsException("Quest id is lower than 0", new Object[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.nextQuestid = quest.getId();
|
|
|
|
|
this.nextQuestTitle = quest.getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getNpcName() {
|
|
|
|
|
return this.completerNpc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNpcName(String name) {
|
|
|
|
|
this.completerNpc = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IQuestObjective[] getObjectives(IPlayer player) {
|
|
|
|
|
if (!player.hasActiveQuest(this.id)) {
|
|
|
|
|
throw new CustomNPCsException("Player doesnt have this quest active.", new Object[0]);
|
|
|
|
|
} else {
|
|
|
|
|
return this.questInterface.getObjectives((EntityPlayer) player.getMCEntity());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean getIsRepeatable() {
|
|
|
|
|
return this.repeat != EnumQuestRepeat.NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-20 09:21:39 -06:00
|
|
|
public long getTimeUntilRepeat(IPlayer player) {
|
|
|
|
|
return this.getTimeUntilRepeat((EntityPlayer) player.getMCEntity());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRepeatType(int type) {
|
|
|
|
|
if (type < 0 || type >= EnumQuestRepeat.values().length) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.repeat = EnumQuestRepeat.values()[type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getRepeatType() {
|
|
|
|
|
return this.repeat.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 15:21:48 -06:00
|
|
|
public IContainer getRewards() {
|
|
|
|
|
return NpcAPI.Instance().getIContainer(this.rewardItems);
|
|
|
|
|
}
|
2022-01-27 05:40:51 -06:00
|
|
|
|
|
|
|
|
public IQuestInterface getQuestInterface(){
|
|
|
|
|
return this.questInterface;
|
|
|
|
|
}
|
2023-10-30 21:06:01 -04:00
|
|
|
|
|
|
|
|
public boolean isAllowParty() {
|
|
|
|
|
return allowParty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setAllowParty(boolean allowParty) {
|
|
|
|
|
this.allowParty = allowParty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte getPartyRequirements() {
|
|
|
|
|
return partyRequirements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setPartyRequirements(byte partyRequirements) {
|
|
|
|
|
this.partyRequirements = partyRequirements;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public byte getRewardControl() {
|
|
|
|
|
return rewardControl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setRewardControl(byte rewardControl) {
|
|
|
|
|
this.rewardControl = rewardControl;
|
|
|
|
|
}
|
2023-11-01 00:06:41 -04:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getMaxPartySize() {
|
|
|
|
|
return maxPartySize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setMaxPartySize(int newSize) {
|
|
|
|
|
maxPartySize = newSize;
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|