From 40154f9c53b7d58c91fb57c5f932c890af71a2ec Mon Sep 17 00:00:00 2001 From: Kam Date: Fri, 21 Feb 2025 06:19:24 -0500 Subject: [PATCH] Quest Profile Options --- src/api | 2 +- .../npcs/command/QuestCategoryCommand.java | 7 +- .../npcs/controllers/ProfileController.java | 109 +++++++++++++--- .../controllers/data/IProfileController.java | 2 + .../request/profile/ProfileCreatePacket.java | 2 - .../client/gui/SubGuiNpcProfileOptions.java | 65 ++++++++++ .../npcs/client/gui/SubGuiNpcQuest.java | 33 +++-- .../gui/util/SubGuiNpcCooldownPicker.java | 118 ++++++++++++++++++ .../npcs/constants/EnumProfileSync.java | 21 ++++ .../controllers/PlayerQuestController.java | 23 +++- .../npcs/controllers/data/ProfileOptions.java | 88 +++++++++++++ .../noppes/npcs/controllers/data/Quest.java | 20 +-- .../npcs/scripted/entity/ScriptPlayer.java | 8 +- .../assets/customnpcs/lang/en_US.lang | 16 ++- 14 files changed, 454 insertions(+), 60 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java create mode 100644 src/main/java/noppes/npcs/constants/EnumProfileSync.java create mode 100644 src/main/java/noppes/npcs/controllers/data/ProfileOptions.java diff --git a/src/api b/src/api index 7b9e091a3..30ba1bafa 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 7b9e091a309eef2be8a202dd0abcc3eb017df27c +Subproject commit 30ba1bafac147bc34cab98fadb38cff0dbab7b90 diff --git a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java index d29ded081..7d57851ba 100644 --- a/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java +++ b/src/main/java/kamkeel/npcs/command/QuestCategoryCommand.java @@ -7,6 +7,7 @@ import net.minecraft.command.ICommandSender; import net.minecraft.entity.player.EntityPlayerMP; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.PlayerQuestController; import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.controllers.data.Quest; @@ -85,11 +86,9 @@ public class QuestCategoryCommand extends CommandKamkeelBase { int count = 0; for(PlayerData playerdata : data){ + count = 0; for(Quest quest : questCategory.quests.values()){ - if(playerdata.questData.activeQuests.containsKey(quest.id)){ - playerdata.questData.activeQuests.remove(quest.id); - } - + playerdata.questData.activeQuests.remove(quest.id); if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) playerdata.questData.finishedQuests.put(quest.id, System.currentTimeMillis()); else diff --git a/src/main/java/kamkeel/npcs/controllers/ProfileController.java b/src/main/java/kamkeel/npcs/controllers/ProfileController.java index 09526352e..152b81222 100644 --- a/src/main/java/kamkeel/npcs/controllers/ProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/ProfileController.java @@ -11,8 +11,13 @@ import noppes.npcs.CustomNpcsPermissions; import noppes.npcs.LogWriter; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.handler.IPlayerData; +import noppes.npcs.api.handler.data.IQuest; import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; +import noppes.npcs.controllers.QuestController; import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerQuestData; +import noppes.npcs.controllers.data.Quest; import noppes.npcs.util.CustomNPCsThreader; import noppes.npcs.util.NBTJsonUtil; @@ -92,8 +97,7 @@ public class ProfileController implements IProfileController { Profile profile; if (activeProfiles.containsKey(player.getUniqueID())) { profile = activeProfiles.get(player.getUniqueID()); - // Update the player reference if needed. - profile = new Profile(player, profile.writeToNBT()); + profile.player = player; } else { NBTTagCompound compound = load(player); profile = new Profile(player, compound); @@ -103,9 +107,10 @@ public class ProfileController implements IProfileController { profile.getSlots().put(0, defaultSlot); profile.currentSlotId = 0; saveSlotData(player); - save(player, profile); } + profile.player = player; activeProfiles.put(player.getUniqueID(), profile); + verifySlotQuests(profile.player); } } @@ -382,6 +387,9 @@ public class ProfileController implements IProfileController { } Slot newSlot = new Slot(newSlotId, "Slot " + newSlotId); newSlot.setLastLoaded(System.currentTimeMillis()); + if(profile.player != null) + verifySlotQuests(profile.player); + profile.getSlots().put(newSlotId, newSlot); return ProfileOperation.success(MSG_NEW_SLOT_CREATED); } @@ -680,21 +688,10 @@ public class ProfileController implements IProfileController { Profile profile = getProfile(entityPlayer); if(profile == null) return null; - - if(profile.currentSlotId == slotID){ - playerData = PlayerData.get(entityPlayer); - } else { - Slot slot = (Slot) profile.getSlots().get(slotID); - if(slot == null) - return null; - - playerData = new PlayerData(); - playerData.player = entityPlayer; - playerData.setNBT(slot.getComponentData(new CNPCData().getTagName())); - } - return playerData; + return getSlotPlayerData(entityPlayer, slotID); } + @Override public void saveSlotData(IPlayer player) { if(player == null || player.getMCEntity() == null) return; @@ -702,4 +699,84 @@ public class ProfileController implements IProfileController { EntityPlayer entityPlayer = (EntityPlayer) player.getMCEntity(); saveSlotData(entityPlayer); } + + public IPlayerData getSlotPlayerData(EntityPlayer player, int slotID) { + PlayerData playerData; + Profile profile = getProfile(player); + if(profile == null) + return null; + + if(profile.currentSlotId == slotID){ + playerData = PlayerData.get(player); + } else { + Slot slot = (Slot) profile.getSlots().get(slotID); + return getSlotPlayerData(player, slot); + } + return playerData; + } + + public PlayerData getSlotPlayerData(EntityPlayer player, Slot slot) { + if(slot == null) + return null; + + PlayerData playerData = new PlayerData(); + playerData.player = player; + playerData.setNBT(slot.getComponentData(new CNPCData().getTagName())); + return playerData; + } + + public void verifySlotQuests(EntityPlayer player) { + Profile profile = getProfile(player); + if(profile == null) + return; + + HashMap universalFinished = new HashMap<>(); + for(ISlot profileSlot : profile.getSlots().values()){ + IPlayerData playerData = getSlotPlayerData(player, profileSlot.getId()); + if(playerData != null){ + PlayerQuestData playerQuestData = (PlayerQuestData) playerData.getQuestData(); + for(int id : playerQuestData.finishedQuests.keySet()){ + IQuest quest = QuestController.Instance.get(id); + if(quest != null){ + Quest quest1 = (Quest) quest; + if(quest1.profileOptions.enableOptions && quest1.profileOptions.completeControl == EnumProfileSync.Shared){ + long complete = playerQuestData.finishedQuests.get(id); + if(universalFinished.containsKey(id)){ + complete = Math.max(universalFinished.get(id), complete); + } + universalFinished.put(id, complete); + } + } + } + } + } + for(ISlot profileSlot : profile.getSlots().values()){ + IPlayerData playerData = getSlotPlayerData(player, profileSlot.getId()); + if(playerData != null){ + PlayerQuestData playerQuestData = (PlayerQuestData) playerData.getQuestData(); + playerQuestData.finishedQuests.putAll(universalFinished); + } + } + ProfileController.Instance.save(player, profile); + } + + public void shareQuestCompletion(EntityPlayer player, int questId, long completeTime) { + Profile profile = getProfile(player); + if (profile == null) { + return; + } + for (ISlot slot : profile.getSlots().values()) { + IPlayerData playerData = getSlotPlayerData(player, slot.getId()); + if (playerData != null) { + PlayerQuestData questData = (PlayerQuestData) playerData.getQuestData(); + Long existing = questData.finishedQuests.get(questId); + // Only update if this completion time is newer. + if (existing == null || completeTime > existing) { + questData.finishedQuests.put(questId, completeTime); + } + } + } + // Optionally, immediately persist the updated profile. + save(player, profile); + } } diff --git a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java index 4d28291f9..960662ff8 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java +++ b/src/main/java/kamkeel/npcs/controllers/data/IProfileController.java @@ -14,4 +14,6 @@ public interface IProfileController { boolean removeSlot(IPlayer player, int slotID); IPlayerData getSlotPlayerData(IPlayer player, int slotID); + + void saveSlotData(IPlayer player); } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java index 60560ec79..56023b5af 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileCreatePacket.java @@ -47,8 +47,6 @@ public final class ProfileCreatePacket extends AbstractPacket { Profile profile = ProfileController.Instance.getProfile(player); ProfileOperation operation = ProfileController.Instance.createSlotInternal(profile); - // TODO: Check Operation and Send Message - ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java new file mode 100644 index 000000000..5177eb95a --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcProfileOptions.java @@ -0,0 +1,65 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumProfileSync; +import noppes.npcs.controllers.data.ProfileOptions; + +public class SubGuiNpcProfileOptions extends SubGuiInterface +{ + private final ProfileOptions options; + + public SubGuiNpcProfileOptions(ProfileOptions options) + { + this.options = options; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + + int y = 0; + //Allow party - T/F button + addButton(new GuiNpcButton(0, guiLeft + 130, guiTop + 10 + y, 60, 20, + new String[]{"gui.no", "gui.yes"}, options.enableOptions ? 1 : 0)); + addLabel(new GuiNpcLabel(1, "party.allowParty", guiLeft + 10, guiTop + 17 + y)); + + if (options.enableOptions) { + y += 23; + addButton(new GuiNpcButton(5, guiLeft + 130, guiTop + 10 + y, 60, 20, + EnumProfileSync.values(), options.completeControl.ordinal())); + addLabel(new GuiNpcLabel(5, "party.partyRequirements", guiLeft + 10, guiTop + 17 + y)); + + y += 23; + addButton(new GuiNpcButton(18, guiLeft + 130, guiTop + 10 + y, 60, 20, + EnumProfileSync.values(), options.cooldownControl.ordinal())); + addLabel(new GuiNpcLabel(18, "quest.objectives", guiLeft + 10, guiTop + 17 + y)); + } + + addButton(new GuiNpcButton(66, guiLeft + 200, guiTop + 192, 50, 20, "gui.done")); + } + + protected void actionPerformed(GuiButton guibutton) + { + int id = guibutton.id; + switch (id) { + case 0: + options.enableOptions = !options.enableOptions; + break; + case 5: + options.completeControl = EnumProfileSync.valueOf(guibutton.displayString); + break; + case 18: + options.cooldownControl = EnumProfileSync.valueOf(guibutton.displayString); + break; + case 66: + close(); + break; + } + initGui(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java index 192dfc4ca..bd8e559c8 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java @@ -69,7 +69,10 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, addLabel(new GuiNpcLabel(17, "party.options", guiLeft + 180, guiTop + 135)); addButton(new GuiNpcButton(18, guiLeft + 303, guiTop + 130, 50, 20, "selectServer.edit")); - this.addButton(new GuiNpcButton(9, guiLeft + 7, guiTop + 102,90, 20, new String[]{"quest.npc","quest.instant"},quest.completion.ordinal())); + addLabel(new GuiNpcLabel(33, "quest.profile", guiLeft + 180, guiTop + 159)); + addButton(new GuiNpcButton(33, guiLeft + 303, guiTop + 154, 50, 20, "selectServer.edit")); + + this.addButton(new GuiNpcButton(9, guiLeft + 7, guiTop + 102,90, 20, new String[]{"quest.npc","quest.instant"},quest.completion.ordinal())); if(quest.completerNpc.isEmpty() && npc != null) quest.completerNpc = npc.display.name; this.addTextField(new GuiNpcTextField(2,this, this.fontRendererObj, guiLeft + 104, guiTop + 102, 154, 20, quest.completerNpc)); @@ -85,9 +88,12 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, if(!quest.mail.subject.isEmpty()) getButton(13).setDisplayText(quest.mail.subject); - addLabel(new GuiNpcLabel(8, "quest.repeatable", guiLeft + 7, guiTop + 178 + 5)); - this.addButton(new GuiNpcButton(8, guiLeft + 100, guiTop + 178,70, 20, new String[]{"gui.no","gui.yes","quest.mcdaily","quest.mcweekly","quest.rldaily","quest.rlweekly"}, quest.repeat.ordinal())); - + addLabel(new GuiNpcLabel(8, "quest.repeatable", guiLeft + 7, guiTop + 178 + 5)); + this.addButton(new GuiNpcButton(8, guiLeft + 100, guiTop + 178, 70, 20, + new String[]{"gui.no", "gui.yes", "quest.mcdaily", "quest.mcweekly", "quest.rldaily", "quest.rlweekly", "quest.mccustom", "quest.rlcustom"}, quest.repeat.ordinal())); + if(quest.repeat == EnumQuestRepeat.MCCUSTOM || quest.repeat == EnumQuestRepeat.RLCUSTOM) { + addButton(new GuiNpcButton(19, guiLeft + 175, guiTop + 178, 90, 20, "Set Cooldown")); + } addButton(new GuiNpcButton(16, guiLeft + 303, guiTop + 192, 50, 20, "gui.done")); if(!quest.mail.subject.isEmpty()) @@ -134,6 +140,7 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, if(button.id == 8) { quest.repeat = EnumQuestRepeat.values()[button.getValue()]; + initGui(); } if(button.id == 9) { @@ -161,14 +168,18 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, } if(button.id == 15 && quest.id >= 0){ setSubGui(new GuiQuestSelection(quest.nextQuestid)); -// questSelection = new GuiNPCQuestSelection(npc, getParent(), quest.nextQuestid); -// questSelection.listener = this; -// NoppesUtil.openGUI(player, questSelection); } if(button.id == 18) { setSubGui(new SubGuiNpcPartyOptions(quest.partyOptions)); } + if(button.id == 19) { + boolean isMCCustom = (quest.repeat == EnumQuestRepeat.MCCUSTOM); + setSubGui(new SubGuiNpcCooldownPicker(isMCCustom, quest.customCooldown)); + } + if(button.id == 33){ + setSubGui(new SubGuiNpcProfileOptions(quest.profileOptions)); + } if(button.id == 16){ close(); } @@ -211,7 +222,13 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, else if(subgui instanceof SubGuiNpcCommand){ SubGuiNpcCommand sub = (SubGuiNpcCommand) subgui; quest.command = sub.command; - } + initGui(); + + } else if(subgui instanceof SubGuiNpcCooldownPicker){ + SubGuiNpcCooldownPicker cooldownGui = (SubGuiNpcCooldownPicker) subgui; + quest.customCooldown = cooldownGui.cooldownValue; + initGui(); + } else { initGui(); } diff --git a/src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java b/src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java new file mode 100644 index 000000000..35df31263 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/SubGuiNpcCooldownPicker.java @@ -0,0 +1,118 @@ +package noppes.npcs.client.gui.util; + +import net.minecraft.client.gui.GuiButton; + +public class SubGuiNpcCooldownPicker extends SubGuiInterface implements ITextfieldListener { + + private final boolean isMCCustom; + public long cooldownValue; + + private GuiNpcTextField daysField; + private GuiNpcTextField hoursField; + private GuiNpcTextField minutesField; + private GuiNpcTextField secondsField; + + public SubGuiNpcCooldownPicker(boolean isMCCustom, long currentCooldown) { + this.isMCCustom = isMCCustom; + this.cooldownValue = currentCooldown; + setBackground("smallbg.png"); + xSize = 220; + ySize = 222; + closeOnEsc = true; + } + + @Override + public void initGui() { + super.initGui(); + + int days = 0, hours = 0, minutes = 0, seconds = 0; + if(isMCCustom) { + long currentMillis = cooldownValue * 50; + days = (int)(currentMillis / 86400000L); + long remainder = currentMillis % 86400000L; + hours = (int)(remainder / 3600000L); + remainder %= 3600000L; + minutes = (int)(remainder / 60000L); + remainder %= 60000L; + seconds = (int)(remainder / 1000L); + } else { + // For RL custom cooldown, currentCooldown is stored in milliseconds. + days = (int)(cooldownValue / 86400000L); + long remainder = cooldownValue % 86400000L; + hours = (int)(remainder / 3600000L); + remainder %= 3600000L; + minutes = (int)(remainder / 60000L); + remainder %= 60000L; + seconds = (int)(remainder / 1000L); + } + + int y = guiTop + 20; + addLabel(new GuiNpcLabel(1, "mailbox.days", guiLeft + 10, y)); + daysField = new GuiNpcTextField(1, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + days); + daysField.setIntegersOnly(); + daysField.setMinMaxDefault(0, Integer.MAX_VALUE, 0); + addTextField(daysField); + + y += 30; + + addLabel(new GuiNpcLabel(2, "mailbox.hours", guiLeft + 10, y)); + hoursField = new GuiNpcTextField(2, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + hours); + hoursField.setIntegersOnly(); + hoursField.setMinMaxDefault(0, 24, 0); + addTextField(hoursField); + + y += 30; + + addLabel(new GuiNpcLabel(3, "mailbox.minutes", guiLeft + 10, y)); + minutesField = new GuiNpcTextField(3, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + minutes); + minutesField.setIntegersOnly(); + minutesField.setMinMaxDefault(0, 60, 0); + addTextField(minutesField); + + y += 30; + + addLabel(new GuiNpcLabel(4, "mailbox.seconds", guiLeft + 10, y)); + secondsField = new GuiNpcTextField(4, this, fontRendererObj, guiLeft + xSize - 110, y - 5, 40, 20, "" + seconds); + secondsField.setIntegersOnly(); + secondsField.setMinMaxDefault(0, 60, 0); + addTextField(secondsField); + + addButton(new GuiNpcButton(0, guiLeft + 10, guiTop + ySize - 30, 80, 20, "gui.done")); + } + + @Override + public void buttonEvent(GuiButton button) { + if(button.id == 0) { + close(); + } + } + + public void close(){ + int inputDays = parseInt(daysField.getText()); + int inputHours = parseInt(hoursField.getText()); + int inputMinutes = parseInt(minutesField.getText()); + int inputSeconds = parseInt(secondsField.getText()); + // Calculate total time in milliseconds. + long totalMillis = inputDays * 86400000L + inputHours * 3600000L + inputMinutes * 60000L + inputSeconds * 1000L; + if(isMCCustom) { + // Convert real milliseconds to ticks. + cooldownValue = totalMillis / 50; + } else { + cooldownValue = totalMillis; + } + super.close(); + } + + @Override + public void unFocused(GuiNpcTextField textField) { + // No immediate action needed on unfocus. + } + + private int parseInt(String text) { + try { + return Integer.parseInt(text); + } catch(Exception e) { + return 0; + } + } +} diff --git a/src/main/java/noppes/npcs/constants/EnumProfileSync.java b/src/main/java/noppes/npcs/constants/EnumProfileSync.java new file mode 100644 index 000000000..f20e3e208 --- /dev/null +++ b/src/main/java/noppes/npcs/constants/EnumProfileSync.java @@ -0,0 +1,21 @@ +package noppes.npcs.constants; + +import java.util.ArrayList; + +public enum EnumProfileSync { + Individual("profile.individual"), + Shared("profile.shared"); + + public final String name; + + EnumProfileSync(String name){ + this.name = name; + } + public static String[] names(){ + ArrayList list = new ArrayList(); + for(EnumProfileSync e : values()) + list.add(e.name); + + return list.toArray(new String[list.size()]); + } +} diff --git a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java index 20d6236e3..c994aec34 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerQuestController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerQuestController.java @@ -1,5 +1,6 @@ package noppes.npcs.controllers; +import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; import net.minecraft.entity.player.EntityPlayer; @@ -8,6 +9,8 @@ import net.minecraft.util.ChatComponentTranslation; import noppes.npcs.EventHooks; import noppes.npcs.NoppesStringUtils; import noppes.npcs.NoppesUtilServer; +import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.data.PlayerData; @@ -64,11 +67,7 @@ public class PlayerQuestController { PlayerQuestData data = playerdata.questData; QuestData questData = data.activeQuests.get(quest.id); data.activeQuests.remove(quest.id); - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - data.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - data.finishedQuests.put(quest.id,player.worldObj.getTotalWorldTime()); - + setQuestFinishedUtil(player, quest, data); if(quest.repeat != EnumQuestRepeat.NONE && quest.type == EnumQuestType.Dialog){ QuestDialog questdialog = (QuestDialog) quest.questInterface; for(int dialog : questdialog.dialogs.values()){ @@ -82,6 +81,20 @@ public class PlayerQuestController { playerdata.updateClient = true; } + public static void setQuestFinishedUtil(EntityPlayer player, Quest quest, PlayerQuestData questData){ + long completeTime; + if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY || quest.repeat == EnumQuestRepeat.RLCUSTOM){ + completeTime = System.currentTimeMillis(); + questData.finishedQuests.put(quest.id, completeTime); + } else { + completeTime = player.worldObj.getTotalWorldTime(); + questData.finishedQuests.put(quest.id, completeTime); + } + + if(ConfigMain.ProfilesEnabled && quest.profileOptions.enableOptions && quest.profileOptions.completeControl == EnumProfileSync.Shared) + ProfileController.Instance.shareQuestCompletion(player, quest.id, completeTime); + } + public static void setQuestPartyFinished(Quest quest, EntityPlayer player, QuestData questData ){ PlayerData playerdata = PlayerData.get(player); PlayerQuestData data = playerdata.questData; diff --git a/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java b/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java new file mode 100644 index 000000000..5605f1b63 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java @@ -0,0 +1,88 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.api.handler.data.IProfileOptions; +import noppes.npcs.constants.EnumProfileSync; + +public class ProfileOptions implements IProfileOptions { + public boolean enableOptions = false; + + public EnumProfileSync cooldownControl = EnumProfileSync.Individual; + public EnumProfileSync completeControl = EnumProfileSync.Individual; + + public void readFromNBT(NBTTagCompound compound) + { + // Party Management + enableOptions = compound.getBoolean("EnableProfiles"); + if(enableOptions){ + cooldownControl = EnumProfileSync.values()[compound.getInteger("CooldownControl")]; + completeControl = EnumProfileSync.values()[compound.getInteger("CompleteControl")]; + } + else { + if(compound.hasKey("CooldownControl")){ + compound.removeTag("CooldownControl"); + } + if(compound.hasKey("CompleteControl")){ + compound.removeTag("CompleteControl"); + } + + cooldownControl = EnumProfileSync.Individual; + completeControl = EnumProfileSync.Individual; + } + } + public NBTTagCompound writeToNBT() + { + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("EnableProfiles", enableOptions); + if(enableOptions){ + compound.setInteger("CooldownControl", cooldownControl.ordinal()); + compound.setInteger("CompleteControl", completeControl.ordinal()); + } + else { + if(compound.hasKey("CooldownControl")){ + compound.removeTag("CooldownControl"); + } + if(compound.hasKey("CompleteControl")){ + compound.removeTag("CompleteControl"); + } + } + + return compound; + } + + @Override + public boolean hasProfileOptions() { + return enableOptions; + } + + @Override + public void setProfileOptions(boolean enable) { + this.enableOptions = enable; + } + + @Override + public void setCooldownControl(int profileType) { + if (profileType < 0 || profileType >= EnumProfileSync.values().length) { + return; + } + this.cooldownControl = EnumProfileSync.values()[profileType]; + } + + @Override + public int getCooldownControl(){ + return this.cooldownControl.ordinal(); + } + + @Override + public void setCompleteControl(int profileType) { + if (profileType < 0 || profileType >= EnumProfileSync.values().length) { + return; + } + this.completeControl = EnumProfileSync.values()[profileType]; + } + + @Override + public int getCompleteControl(){ + return this.completeControl.ordinal(); + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 7b0dad77b..83205ca28 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -41,8 +41,6 @@ public class Quest implements ICompatibilty, IQuest { public String command = ""; public QuestInterface questInterface = new QuestItem(); - - public boolean profileShared = false; public long customCooldown = 0; public int rewardExp = 0; @@ -50,7 +48,7 @@ public class Quest implements ICompatibilty, IQuest { public boolean randomReward = false; public FactionOptions factionOptions = new FactionOptions(); public PartyOptions partyOptions = new PartyOptions(); - + public ProfileOptions profileOptions = new ProfileOptions(); public void readNBT(NBTTagCompound compound) { id = compound.getInteger("Id"); @@ -78,14 +76,12 @@ public class Quest implements ICompatibilty, IQuest { completion = EnumQuestCompletion.values()[compound.getInteger("QuestCompletion")]; repeat = EnumQuestRepeat.values()[compound.getInteger("QuestRepeat")]; - customCooldown = compound.getLong("CustomCooldown"); - profileShared = compound.getBoolean("ProfileShared"); - questInterface.readEntityFromNBT(compound); factionOptions.readFromNBT(compound.getCompoundTag("QuestFactionPoints")); partyOptions.readFromNBT(compound.getCompoundTag("PartyOptions")); + profileOptions.readFromNBT(compound.getCompoundTag("ProfileOptions")); mail.readNBT(compound.getCompoundTag("QuestMail")); } @@ -124,7 +120,6 @@ public class Quest implements ICompatibilty, IQuest { compound.setTag("Rewards", rewardItems.getToNBT()); compound.setString("QuestCommand", command); compound.setBoolean("RandomReward", randomReward); - compound.setBoolean("ProfileShared", profileShared); compound.setLong("CustomCooldown", customCooldown); compound.setInteger("QuestCompletion", completion.ordinal()); @@ -133,6 +128,7 @@ public class Quest implements ICompatibilty, IQuest { this.questInterface.writeEntityToNBT(compound); compound.setTag("QuestFactionPoints", factionOptions.writeToNBT(new NBTTagCompound())); compound.setTag("PartyOptions", partyOptions.writeToNBT()); + compound.setTag("ProfileOptions", profileOptions.writeToNBT()); compound.setTag("QuestMail", mail.writeNBT()); return compound; @@ -166,7 +162,7 @@ public class Quest implements ICompatibilty, IQuest { } public long getTimeUntilRepeat(EntityPlayer player) { - if(profileShared && ConfigMain.ProfilesEnabled){ + if(profileOptions.enableOptions && ConfigMain.ProfilesEnabled){ Profile profile = ProfileController.Instance.getProfile(player); IPlayer iPlayer = NoppesUtilServer.getIPlayer(player); long timeRemaining = 0L; @@ -373,12 +369,8 @@ public class Quest implements ICompatibilty, IQuest { return this.partyOptions; } - public boolean isProfileShared() { - return this.profileShared; - } - - public void setProfileShared(boolean value) { - this.profileShared = value; + public IProfileOptions getProfileOptions() { + return this.profileOptions; } public long getCustomCooldown() { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 0ce931c0e..485e9cc21 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -1,5 +1,6 @@ package noppes.npcs.scripted.entity; +import kamkeel.npcs.controllers.ProfileController; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.packets.data.AchievementPacket; import kamkeel.npcs.network.packets.data.ChatAlertPacket; @@ -34,7 +35,9 @@ import noppes.npcs.api.handler.data.ISound; import noppes.npcs.api.item.IItemStack; import noppes.npcs.api.overlay.ICustomOverlay; import noppes.npcs.compat.PixelmonHelper; +import noppes.npcs.config.ConfigMain; import noppes.npcs.config.ConfigScript; +import noppes.npcs.constants.EnumProfileSync; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.containers.ContainerCustomGui; @@ -284,10 +287,7 @@ public class ScriptPlayer extends ScriptLivingBase if (quest == null) return; PlayerData data = PlayerData.get(player); - if(quest.repeat == EnumQuestRepeat.RLDAILY || quest.repeat == EnumQuestRepeat.RLWEEKLY) - data.questData.finishedQuests.put(quest.id, System.currentTimeMillis()); - else - data.questData.finishedQuests.put(quest.id, player.worldObj.getTotalWorldTime()); + PlayerQuestController.setQuestFinishedUtil(player, quest, data.questData); data.updateClient = true; } diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 5b5d71dc4..6997383b3 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -254,12 +254,13 @@ mailbox.name=Mailbox mailbox.sender=Sender mailbox.read=Read mailbox.timesend=%s ago -mailbox.day=day -mailbox.days=days -mailbox.hour=hour -mailbox.hours=hours -mailbox.minute=minute -mailbox.minutes=minutes +mailbox.day=Day +mailbox.days=Days +mailbox.hour=Hour +mailbox.hours=Hours +mailbox.minute=Minute +mailbox.minutes=Minutes +mailbox.seconds=Seconds mailbox.username=Username mailbox.subject=Subject mailbox.send=Send @@ -662,6 +663,9 @@ quest.mcdaily=MC Daily quest.mcweekly=MC Weekly quest.rldaily=RL Daily quest.rlweekly=RL Weekly +quest.rlcustom=RL Custom +quest.mccustom=MC Custom +quest.profile=Profile Options quest.instant=Instant Complete quest.npc=Complete by npc quest.next=Next Quest