From cdb34f4624c6d110e7750b55a1ee4326b85eff68 Mon Sep 17 00:00:00 2001 From: luisc Date: Tue, 13 Feb 2024 14:14:21 -0600 Subject: [PATCH] Moved quest party options to a party options class. Added a blank subgui for editing a quest's party options. --- src/api | 2 +- .../java/noppes/npcs/PacketHandlerServer.java | 2 +- src/main/java/noppes/npcs/QuestLogData.java | 2 +- .../client/gui/SubGuiNpcPartyOptions.java | 44 ++++++ .../npcs/client/gui/SubGuiNpcQuest.java | 8 +- .../noppes/npcs/controllers/data/Party.java | 6 +- .../npcs/controllers/data/PartyOptions.java | 129 ++++++++++++++++++ .../noppes/npcs/controllers/data/Quest.java | 114 +--------------- 8 files changed, 192 insertions(+), 115 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java create mode 100644 src/main/java/noppes/npcs/controllers/data/PartyOptions.java diff --git a/src/api b/src/api index a6c43f2e9..a55f9b010 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit a6c43f2e9124404c541f182bb1b1c9b79ad2ed7e +Subproject commit a55f9b0109e4437dc41b0d8ebcd1fe473ec0b927 diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index f645ec166..ede6f768e 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -193,7 +193,7 @@ public class PacketHandlerServer{ String questName = Server.readString(buffer); party.setQuest(null); for (Quest quest : QuestController.Instance.quests.values()) { - if (quest.allowParty && quest.getCategory().getName().equals(questCategory) && quest.getName().equals(questName)) { + if (quest.partyOptions.allowParty && quest.getCategory().getName().equals(questCategory) && quest.getName().equals(questName)) { party.setQuest(quest); break; } diff --git a/src/main/java/noppes/npcs/QuestLogData.java b/src/main/java/noppes/npcs/QuestLogData.java index 508fe03b1..a0c084f73 100644 --- a/src/main/java/noppes/npcs/QuestLogData.java +++ b/src/main/java/noppes/npcs/QuestLogData.java @@ -67,7 +67,7 @@ public class QuestLogData { } } - if (quest.allowParty) { + if (quest.partyOptions.allowParty) { partyAbleQuests.add(category + ":" + quest.title); } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java new file mode 100644 index 000000000..51f1a1063 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcPartyOptions.java @@ -0,0 +1,44 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.StatCollector; +import noppes.npcs.client.Client; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.FactionOptions; +import noppes.npcs.controllers.data.PartyOptions; + +import java.util.HashMap; +import java.util.Vector; + +public class SubGuiNpcPartyOptions extends SubGuiInterface +{ + private final PartyOptions options; + private HashMap data = new HashMap<>(); + + public SubGuiNpcPartyOptions(PartyOptions options) + { + this.options = options; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + + addButton(new GuiNpcButton(66, guiLeft + 20, guiTop + 192, 90, 20, "gui.done")); + } + + protected void actionPerformed(GuiButton guibutton) + { + int id = guibutton.id; + + if(id == 66) + { + close(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java index 51f510e72..af9d2169a 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcQuest.java @@ -12,7 +12,6 @@ import noppes.npcs.client.gui.util.*; import noppes.npcs.constants.*; import noppes.npcs.controllers.data.PlayerMail; import noppes.npcs.controllers.data.Quest; -import noppes.npcs.controllers.data.QuestCategory; public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, GuiSelectionListener,ITextfieldListener { @@ -64,6 +63,9 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, addButton(new GuiNpcButton(6, guiLeft + 240, guiTop + 76, 60, 20, new String[]{"quest.item","quest.dialog","quest.kill","quest.location","quest.areakill"},quest.type.ordinal())); addButton(new GuiNpcButton(7, guiLeft + 303, guiTop + 76,50, 20, "selectServer.edit")); + addLabel(new GuiNpcLabel(17, "party.options", guiLeft + 180, guiTop + 105)); + addButton(new GuiNpcButton(18, guiLeft + 303, guiTop + 100, 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; @@ -156,6 +158,10 @@ public class SubGuiNpcQuest extends SubGuiInterface implements ISubGuiListener, questSelection.listener = this; NoppesUtil.openGUI(player, questSelection); } + if(button.id == 18) + { + setSubGui(new SubGuiNpcPartyOptions(quest.partyOptions)); + } if(button.id == 16){ close(); } diff --git a/src/main/java/noppes/npcs/controllers/data/Party.java b/src/main/java/noppes/npcs/controllers/data/Party.java index 91a60e7c8..68358b01d 100644 --- a/src/main/java/noppes/npcs/controllers/data/Party.java +++ b/src/main/java/noppes/npcs/controllers/data/Party.java @@ -194,14 +194,14 @@ public class Party { return false; } - int partyReq = quest.getPartyRequirements(); + int partyReq = quest.getPartyOptions().getPartyRequirements(); if (partyReq < 0 || partyReq >= EnumPartyRequirements.values().length) { sendInfoMessage(leader, "Error in quest party requirements"); return false; } - if (partyMembers.size() > quest.getMaxPartySize()) { - sendInfoMessage(leader, String.format("Party too large. Max %d members", quest.getMaxPartySize())); + if (partyMembers.size() > quest.getPartyOptions().getMaxPartySize()) { + sendInfoMessage(leader, String.format("Party too large. Max %d members", quest.getPartyOptions().getMaxPartySize())); return false; } diff --git a/src/main/java/noppes/npcs/controllers/data/PartyOptions.java b/src/main/java/noppes/npcs/controllers/data/PartyOptions.java new file mode 100644 index 000000000..f6e413764 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/PartyOptions.java @@ -0,0 +1,129 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentTranslation; +import noppes.npcs.api.handler.data.IPartyOptions; +import noppes.npcs.config.ConfigMain; +import noppes.npcs.constants.EnumPartyExchange; +import noppes.npcs.constants.EnumPartyRequirements; +import noppes.npcs.controllers.FactionController; +import noppes.npcs.controllers.PlayerDataController; + +public class PartyOptions implements IPartyOptions { + + public boolean allowParty = false; + public EnumPartyRequirements partyRequirements = EnumPartyRequirements.Leader; + public EnumPartyExchange rewardControl = EnumPartyExchange.Leader; + public EnumPartyExchange completeFor = EnumPartyExchange.Leader; + public int maxPartySize = ConfigMain.DefaultMaxPartySize; + + public void readFromNBT(NBTTagCompound compound) + { + // Party Management + allowParty = compound.getBoolean("AllowParty"); + if(allowParty){ + partyRequirements = EnumPartyRequirements.values()[compound.getInteger("PartyRequirements")]; + rewardControl = EnumPartyExchange.values()[compound.getInteger("RewardControl")]; + completeFor = EnumPartyExchange.values()[compound.getInteger("CompleteFor")]; + maxPartySize = compound.getInteger("MaxPartySize"); + } + else { + if(compound.hasKey("PartyRequirements")){ + compound.removeTag("PartyRequirements"); + } + if(compound.hasKey("RewardControl")){ + compound.removeTag("RewardControl"); + } + if(compound.hasKey("CompleteFor")){ + compound.removeTag("CompleteFor"); + } + if(compound.hasKey("MaxPartySize")){ + compound.removeTag("MaxPartySize"); + } + + partyRequirements = EnumPartyRequirements.Leader; + rewardControl = EnumPartyExchange.Leader; + completeFor = EnumPartyExchange.Leader; + maxPartySize = ConfigMain.DefaultMaxPartySize; + } + } + public NBTTagCompound writeToNBT() + { + NBTTagCompound compound = new NBTTagCompound(); + compound.setBoolean("AllowParty", allowParty); + if(allowParty){ + compound.setInteger("PartyRequirements", partyRequirements.ordinal()); + compound.setInteger("RewardControl", rewardControl.ordinal()); + compound.setInteger("CompleteFor", completeFor.ordinal()); + compound.setInteger("MaxPartySize", maxPartySize); + } + else { + if(compound.hasKey("PartyRequirements")){ + compound.removeTag("PartyRequirements"); + } + if(compound.hasKey("RewardControl")){ + compound.removeTag("RewardControl"); + } + if(compound.hasKey("CompleteFor")){ + compound.removeTag("CompleteFor"); + } + if(compound.hasKey("MaxPartySize")){ + compound.removeTag("MaxPartySize"); + } + } + + return compound; + } + + public boolean isAllowParty() { + return allowParty; + } + + public void setAllowParty(boolean allowParty) { + this.allowParty = allowParty; + } + + public int getPartyRequirements() { + return partyRequirements.ordinal(); + } + + public void setPartyRequirements(int partyReq) { + if (partyReq < 0 || partyReq >= EnumPartyRequirements.values().length) { + return; + } + this.partyRequirements = EnumPartyRequirements.values()[partyReq]; + } + + public int getRewardControl() { + return rewardControl.ordinal(); + } + + public void setRewardControl(int rewardCon) { + if (rewardCon < 0 || rewardCon >= EnumPartyExchange.values().length) { + return; + } + this.rewardControl = EnumPartyExchange.values()[rewardCon]; + } + + public int getCompleteFor() { + return completeFor.ordinal(); + } + + public void setCompleteFor(int compFor) { + if (compFor < 0 || compFor >= EnumPartyExchange.values().length) { + return; + } + this.completeFor = EnumPartyExchange.values()[compFor]; + } + + @Override + public int getMaxPartySize() { + return maxPartySize; + } + + @Override + public void setMaxPartySize(int newSize) { + maxPartySize = newSize; + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/Quest.java b/src/main/java/noppes/npcs/controllers/data/Quest.java index a136d042b..cb8544f11 100644 --- a/src/main/java/noppes/npcs/controllers/data/Quest.java +++ b/src/main/java/noppes/npcs/controllers/data/Quest.java @@ -6,10 +6,7 @@ import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.*; 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; +import noppes.npcs.api.handler.data.*; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.*; import noppes.npcs.controllers.PlayerDataController; @@ -33,12 +30,6 @@ public class Quest implements ICompatibilty, IQuest { public String nextQuestTitle = ""; public PlayerMail mail = new PlayerMail(); public String command = ""; - - public boolean allowParty = false; - public EnumPartyRequirements partyRequirements = EnumPartyRequirements.Leader; - public EnumPartyExchange rewardControl = EnumPartyExchange.Leader; - public EnumPartyExchange completeFor = EnumPartyExchange.Leader; - public int maxPartySize = ConfigMain.DefaultMaxPartySize; public QuestInterface questInterface = new QuestItem(); @@ -46,6 +37,7 @@ public class Quest implements ICompatibilty, IQuest { public NpcMiscInventory rewardItems = new NpcMiscInventory(9); public boolean randomReward = false; public FactionOptions factionOptions = new FactionOptions(); + public PartyOptions partyOptions = new PartyOptions(); public void readNBT(NBTTagCompound compound) { @@ -78,36 +70,9 @@ public class Quest implements ICompatibilty, IQuest { questInterface.readEntityFromNBT(compound); factionOptions.readFromNBT(compound.getCompoundTag("QuestFactionPoints")); + partyOptions.readFromNBT(compound.getCompoundTag("PartyOptions")); mail.readNBT(compound.getCompoundTag("QuestMail")); - - // Party Management - allowParty = compound.getBoolean("AllowParty"); - if(allowParty){ - partyRequirements = EnumPartyRequirements.values()[compound.getInteger("PartyRequirements")]; - rewardControl = EnumPartyExchange.values()[compound.getInteger("RewardControl")]; - completeFor = EnumPartyExchange.values()[compound.getInteger("CompleteFor")]; - maxPartySize = compound.getInteger("MaxPartySize"); - } - else { - if(compound.hasKey("PartyRequirements")){ - compound.removeTag("PartyRequirements"); - } - if(compound.hasKey("RewardControl")){ - compound.removeTag("RewardControl"); - } - if(compound.hasKey("CompleteFor")){ - compound.removeTag("CompleteFor"); - } - if(compound.hasKey("MaxPartySize")){ - compound.removeTag("MaxPartySize"); - } - - partyRequirements = EnumPartyRequirements.Leader; - rewardControl = EnumPartyExchange.Leader; - completeFor = EnumPartyExchange.Leader; - maxPartySize = ConfigMain.DefaultMaxPartySize; - } } public void setType(EnumQuestType questType) { @@ -148,29 +113,9 @@ public class Quest implements ICompatibilty, IQuest { this.questInterface.writeEntityToNBT(compound); compound.setTag("QuestFactionPoints", factionOptions.writeToNBT(new NBTTagCompound())); + compound.setTag("PartyOptions", partyOptions.writeToNBT()); compound.setTag("QuestMail", mail.writeNBT()); - compound.setBoolean("AllowParty", allowParty); - if(allowParty){ - compound.setInteger("PartyRequirements", partyRequirements.ordinal()); - compound.setInteger("RewardControl", rewardControl.ordinal()); - compound.setInteger("CompleteFor", completeFor.ordinal()); - compound.setInteger("MaxPartySize", maxPartySize); - } - else { - if(compound.hasKey("PartyRequirements")){ - compound.removeTag("PartyRequirements"); - } - if(compound.hasKey("RewardControl")){ - compound.removeTag("RewardControl"); - } - if(compound.hasKey("CompleteFor")){ - compound.removeTag("CompleteFor"); - } - if(compound.hasKey("MaxPartySize")){ - compound.removeTag("MaxPartySize"); - } - } return compound; } @@ -327,54 +272,7 @@ public class Quest implements ICompatibilty, IQuest { return this.questInterface; } - public boolean isAllowParty() { - return allowParty; - } - - public void setAllowParty(boolean allowParty) { - this.allowParty = allowParty; - } - - public int getPartyRequirements() { - return partyRequirements.ordinal(); - } - - public void setPartyRequirements(int partyReq) { - if (partyReq < 0 || partyReq >= EnumPartyRequirements.values().length) { - return; - } - this.partyRequirements = EnumPartyRequirements.values()[partyReq]; - } - - public int getRewardControl() { - return rewardControl.ordinal(); - } - - public void setRewardControl(int rewardCon) { - if (rewardCon < 0 || rewardCon >= EnumPartyExchange.values().length) { - return; - } - this.rewardControl = EnumPartyExchange.values()[rewardCon]; - } - - public int getCompleteFor() { - return completeFor.ordinal(); - } - - public void setCompleteFor(int compFor) { - if (compFor < 0 || compFor >= EnumPartyExchange.values().length) { - return; - } - this.completeFor = EnumPartyExchange.values()[compFor]; - } - - @Override - public int getMaxPartySize() { - return maxPartySize; - } - - @Override - public void setMaxPartySize(int newSize) { - maxPartySize = newSize; + public IPartyOptions getPartyOptions() { + return this.partyOptions; } }