diff --git a/src/api b/src/api index 0d9abd56f..7b9e091a3 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit 0d9abd56f6f1ab8bdc7d5ce844a668df86f20bf3 +Subproject commit 7b9e091a309eef2be8a202dd0abcc3eb017df27c diff --git a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java index c66649112..3affe65ad 100644 --- a/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java +++ b/src/main/java/kamkeel/npcs/command/profile/CommandProfileAdmin.java @@ -159,7 +159,7 @@ public class CommandProfileAdmin extends CommandProfileBase { return; } String targetPlayer = args[0]; - Profile profile = ProfileController.getProfile(targetPlayer); + Profile profile = ProfileController.Instance.getProfile(targetPlayer); if(profile == null) { sendError(sender, "Profile not found for player: %s", targetPlayer); return; @@ -203,7 +203,7 @@ public class CommandProfileAdmin extends CommandProfileBase { sendError(sender, "Invalid name. Only alphabetic characters and spaces are allowed."); return; } - Profile profile = ProfileController.getProfile(targetPlayer); + Profile profile = ProfileController.Instance.getProfile(targetPlayer); if(profile == null) { sendError(sender, "Profile not found for player: %s", targetPlayer); return; diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java index 4b6579bd5..c6f88fb77 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileChangePacket.java @@ -53,7 +53,7 @@ public final class ProfileChangePacket extends AbstractPacket { return; int slot = in.readInt(); - ProfileOperation operation = ProfileController.changeSlot(player, slot); + ProfileOperation operation = ProfileController.Instance.changeSlot(player, slot); // TODO: Check Operation and Send Message ProfileGetPacket.sendProfileNBT(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 611546e06..60560ec79 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 @@ -45,8 +45,8 @@ public final class ProfileCreatePacket extends AbstractPacket { if (!(player instanceof EntityPlayerMP)) return; - Profile profile = ProfileController.getProfile(player); - ProfileOperation operation = ProfileController.createSlotInternal(profile); + Profile profile = ProfileController.Instance.getProfile(player); + ProfileOperation operation = ProfileController.Instance.createSlotInternal(profile); // TODO: Check Operation and Send Message ProfileGetPacket.sendProfileNBT(player); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java index 81808afe3..43b2885a6 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetInfoPacket.java @@ -54,13 +54,13 @@ public final class ProfileGetInfoPacket extends AbstractPacket { NBTTagCompound compound = new NBTTagCompound(); compound.setBoolean("PROFILE_INFO", true); NBTTagList slotList = new NBTTagList(); - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); if(profile != null){ for(ISlot slot : profile.getSlots().values()){ NBTTagCompound slotCompound = new NBTTagCompound(); NBTTagList infoList = new NBTTagList(); slotCompound.setInteger("ID", slot.getId()); - List profileInfo = ProfileController.getProfileInfo(player, slot.getId()); + List profileInfo = ProfileController.Instance.getProfileInfo(player, slot.getId()); for(InfoEntry infoEntry : profileInfo){ infoList.appendTag(infoEntry.writeToNBT()); } diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java index d03849b83..a37572db5 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileGetPacket.java @@ -44,7 +44,7 @@ public final class ProfileGetPacket extends AbstractPacket { } public static void sendProfileNBT(EntityPlayer player){ - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); NBTTagCompound compound = profile.writeToNBT(); compound.setBoolean("PROFILE", true); GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound); diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java index d7ae74c8c..6f8ff983c 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRemovePacket.java @@ -53,7 +53,7 @@ public final class ProfileRemovePacket extends AbstractPacket { return; int slot = in.readInt(); - ProfileOperation operation = ProfileController.removeSlot(player, slot); + ProfileOperation operation = ProfileController.Instance.removeSlot(player, slot); // TODO: Check Operation and Send Message diff --git a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java index 945726b49..7322517d4 100644 --- a/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/request/profile/ProfileRenamePacket.java @@ -59,14 +59,14 @@ public final class ProfileRenamePacket extends AbstractPacket { int slot = in.readInt(); String newName = ByteBufUtils.readString(in); - Profile profile = ProfileController.getProfile(player); + Profile profile = ProfileController.Instance.getProfile(player); if(!profile.getSlots().containsKey(slot)) { // TODO: Check Operation and Send Message return; } - ProfileController.getProfile(player).getSlots().get(slot).setName(newName); - ProfileController.save(player, ProfileController.getProfile(player)); + ProfileController.Instance.getProfile(player).getSlots().get(slot).setName(newName); + ProfileController.Instance.save(player, ProfileController.Instance.getProfile(player)); ProfileGetPacket.sendProfileNBT(player); ProfileGetInfoPacket.sendProfileInfo(player); diff --git a/src/main/java/noppes/npcs/ServerTickHandler.java b/src/main/java/noppes/npcs/ServerTickHandler.java index e793e8db0..95d1332ba 100644 --- a/src/main/java/noppes/npcs/ServerTickHandler.java +++ b/src/main/java/noppes/npcs/ServerTickHandler.java @@ -54,7 +54,7 @@ public class ServerTickHandler { SyncController.syncPlayer(player); SyncController.syncEffects(player); - ProfileController.login(player); + ProfileController.Instance.login(player); } @SubscribeEvent diff --git a/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java b/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java index 954e4acd8..7cb4ecac5 100644 --- a/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java +++ b/src/main/java/noppes/npcs/constants/EnumQuestRepeat.java @@ -1,5 +1,5 @@ package noppes.npcs.constants; public enum EnumQuestRepeat { - NONE, REPEATABLE, MCDAILY, MCWEEKLY, RLDAILY, RLWEEKLY; + NONE, REPEATABLE, MCDAILY, MCWEEKLY, RLDAILY, RLWEEKLY, MCCUSTOM, RLCUSTOM; } diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index 4bd22e5ff..7b0dad77b 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -1,16 +1,20 @@ package noppes.npcs.controllers.data; +import kamkeel.npcs.controllers.ProfileController; +import kamkeel.npcs.controllers.data.ISlot; +import kamkeel.npcs.controllers.data.Profile; +import kamkeel.npcs.controllers.data.Slot; import kamkeel.npcs.network.packets.data.QuestCompletionPacket; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.ICompatibilty; -import noppes.npcs.NoppesUtilPlayer; -import noppes.npcs.NpcMiscInventory; -import noppes.npcs.VersionCompatibility; +import noppes.npcs.*; import noppes.npcs.api.IContainer; import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.handler.IPlayerData; +import noppes.npcs.api.handler.IPlayerQuestData; import noppes.npcs.api.handler.data.*; +import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumQuestCompletion; import noppes.npcs.constants.EnumQuestRepeat; import noppes.npcs.constants.EnumQuestType; @@ -38,6 +42,9 @@ public class Quest implements ICompatibilty, IQuest { public QuestInterface questInterface = new QuestItem(); + public boolean profileShared = false; + public long customCooldown = 0; + public int rewardExp = 0; public NpcMiscInventory rewardItems = new NpcMiscInventory(9); public boolean randomReward = false; @@ -72,6 +79,9 @@ 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")); @@ -114,6 +124,8 @@ 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()); compound.setInteger("QuestRepeat", repeat.ordinal()); @@ -153,23 +165,96 @@ public class Quest implements ICompatibilty, IQuest { return quest; } - public long getTimeUntilRepeat(EntityPlayer player) { - long questTime = PlayerDataController.Instance.getPlayerData(player).getQuestData().getLastCompletedTime(this.id); + public long getTimeUntilRepeat(EntityPlayer player) { + if(profileShared && ConfigMain.ProfilesEnabled){ + Profile profile = ProfileController.Instance.getProfile(player); + IPlayer iPlayer = NoppesUtilServer.getIPlayer(player); + long timeRemaining = 0L; + for(ISlot slot : profile.getSlots().values()){ + IPlayerData playerData = ProfileController.Instance.getSlotPlayerData(iPlayer, slot.getId()); + IPlayerQuestData iPlayerQuestData = playerData.getQuestData(); + timeRemaining = Math.max(timeRemaining, getTimeUntilRepeatQuestData(player, iPlayerQuestData)); + } + return timeRemaining; + } + IPlayerQuestData questData = PlayerDataController.Instance.getPlayerData(player).getQuestData(); + return getTimeUntilRepeatQuestData(player, questData); + } - switch (repeat) { - case MCDAILY: - return Math.max(0, (questTime + 24000 - player.worldObj.getTotalWorldTime()) * 50); - case MCWEEKLY: - return Math.max(0, (questTime + 168000 - player.worldObj.getTotalWorldTime()) * 50); - case RLDAILY: - return Math.max(0, questTime + 86400000 - System.currentTimeMillis()); - case RLWEEKLY: - return Math.max(0, questTime + 604800000 - System.currentTimeMillis()); - } - return 0L; - } + public long getTimeUntilRepeatQuestData(EntityPlayer player, IPlayerQuestData questData){ + long questTime = questData.getLastCompletedTime(this.id); - @Override + switch (repeat) { + case MCDAILY: { + long now = player.worldObj.getTotalWorldTime(); + long allowedTicks = 24000; + // If questTime is in the future and the excess is greater than allowed, reset it. + if (questTime > now && (questTime - now) > allowedTicks) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingTicks = questTime + allowedTicks - now; + return Math.max(0, remainingTicks * 50); + } + case MCWEEKLY: { + long now = player.worldObj.getTotalWorldTime(); + long allowedTicks = 168000; + if (questTime > now && (questTime - now) > allowedTicks) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingTicks = questTime + allowedTicks - now; + return Math.max(0, remainingTicks * 50); + } + case RLDAILY: { + long now = System.currentTimeMillis(); + long allowedMillis = 86400000; + if (questTime > now && (questTime - now) > allowedMillis) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingMillis = questTime + allowedMillis - now; + return Math.max(0, remainingMillis); + } + case RLWEEKLY: { + long now = System.currentTimeMillis(); + long allowedMillis = 604800000; + if (questTime > now && (questTime - now) > allowedMillis) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingMillis = questTime + allowedMillis - now; + return Math.max(0, remainingMillis); + } + case MCCUSTOM: { + // For MCCUSTOM, customCooldown is assumed to be defined in ticks. + long now = player.worldObj.getTotalWorldTime(); + long allowedTicks = this.customCooldown; + if (questTime > now && (questTime - now) > allowedTicks) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingTicks = questTime + allowedTicks - now; + return Math.max(0, remainingTicks * 50); + } + case RLCUSTOM: { + // For RLCUSTOM, customCooldown is assumed to be in milliseconds. + long now = System.currentTimeMillis(); + long allowedMillis = this.customCooldown; + if (questTime > now && (questTime - now) > allowedMillis) { + questTime = now; + questData.setLastCompletedTime(this.id, questTime); + } + long remainingMillis = questTime + allowedMillis - now; + return Math.max(0, remainingMillis); + } + default: + return 0L; + } + } + + + @Override public int getVersion() { return version; } @@ -287,4 +372,20 @@ public class Quest implements ICompatibilty, IQuest { public IPartyOptions getPartyOptions() { return this.partyOptions; } + + public boolean isProfileShared() { + return this.profileShared; + } + + public void setProfileShared(boolean value) { + this.profileShared = value; + } + + public long getCustomCooldown() { + return this.customCooldown; + } + + public void setCustomCooldown(long newCooldown) { + this.customCooldown = newCooldown; + } }