Custom Quest Cooldowns / Shared Profile Cooldowns + Profile Packet Fixes

This commit is contained in:
Kam committed 2025-02-20 22:19:21 -05:00
1 parent 83c16ae419
commit 2141c5c4ca
11 files changed
+135 -34

No files matched your search

@@ -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;
@@ -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);
@@ -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);
@@ -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<InfoEntry> profileInfo = ProfileController.getProfileInfo(player, slot.getId());
List<InfoEntry> profileInfo = ProfileController.Instance.getProfileInfo(player, slot.getId());
for(InfoEntry infoEntry : profileInfo){
infoList.appendTag(infoEntry.writeToNBT());
}
@@ -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);
@@ -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
@@ -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);
@@ -54,7 +54,7 @@ public class ServerTickHandler {
SyncController.syncPlayer(player);
SyncController.syncEffects(player);
ProfileController.login(player);
ProfileController.Instance.login(player);
}
@SubscribeEvent
@@ -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;
}
@@ -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;
}
}