mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 15:45:10 +00:00
Map Party Quests to Quest ID for better Packet Handling
Prevents Loop from being run every time Party Quest is set
This commit is contained in:
1 parent
faf9e61258
commit
1c29fd66c4
5 files changed
+40
-37
No files matched your search
@@ -211,22 +211,20 @@ public class PacketHandlerServer{
|
||||
return;
|
||||
}
|
||||
|
||||
String questCategory = Server.readString(buffer);
|
||||
String questName = Server.readString(buffer);
|
||||
int questID = buffer.readInt();
|
||||
party.setQuest(null);
|
||||
for (Quest quest : QuestController.Instance.quests.values()) {
|
||||
if (quest.partyOptions.allowParty && quest.getCategory().getName().equals(questCategory) && quest.getName().equals(questName)) {
|
||||
|
||||
if(playerData.questData.hasActiveQuest(quest.getId())){
|
||||
QuestData questdata = new QuestData(quest);
|
||||
playerData.questData.activeQuests.put(quest.getId(), questdata);
|
||||
if(questID != -1){
|
||||
Quest foundQuest = QuestController.Instance.quests.get(questID);
|
||||
if(foundQuest != null){
|
||||
if (foundQuest.partyOptions.allowParty) {
|
||||
if(playerData.questData.hasActiveQuest(questID)){
|
||||
QuestData questdata = new QuestData(foundQuest);
|
||||
playerData.questData.activeQuests.put(questID, questdata);
|
||||
}
|
||||
party.setQuest(foundQuest);
|
||||
}
|
||||
|
||||
party.setQuest(quest);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Server.sendData(player, EnumPacketClient.PARTY_DATA, party.writeToNBT());
|
||||
PartyController.Instance().pingPartyUpdate(party);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class QuestLogData {
|
||||
public HashMap<String,String> questAlerts = new HashMap<>();
|
||||
public HashMap<String,Vector<String>> questStatus = new HashMap<>();
|
||||
public HashMap<String,String> finish = new HashMap<>();
|
||||
public HashSet<String> partyQuests = new HashSet<>();
|
||||
public HashMap<String, Integer> partyQuests = new HashMap<>();
|
||||
|
||||
public NBTTagCompound writeNBT(){
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
@@ -31,7 +31,7 @@ public class QuestLogData {
|
||||
compound.setTag("Status", NBTTags.nbtVectorMap(questStatus));
|
||||
compound.setTag("QuestFinisher", NBTTags.nbtStringStringMap(finish));
|
||||
compound.setString("TrackedQuestID", trackedQuestKey);
|
||||
compound.setTag("PartyQuests", NBTTags.nbtStringSet(partyQuests));
|
||||
compound.setTag("PartyQuests", NBTTags.nbtStringIntegerMap(partyQuests));
|
||||
return compound;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class QuestLogData {
|
||||
questStatus = NBTTags.getVectorMap(compound.getTagList("Status", 10));
|
||||
finish = NBTTags.getStringStringMap(compound.getTagList("QuestFinisher", 10));
|
||||
trackedQuestKey = compound.getString("TrackedQuestID");
|
||||
partyQuests = NBTTags.getStringSet(compound.getTagList("PartyQuests", 10));
|
||||
partyQuests = NBTTags.getStringIntegerMap(compound.getTagList("PartyQuests", 10));
|
||||
}
|
||||
public void setData(EntityPlayer player){
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
@@ -55,20 +55,21 @@ public class QuestLogData {
|
||||
Vector<String> list = categories.get(category);
|
||||
list.add(quest.title);
|
||||
|
||||
questText.put(category + ":" + quest.title, quest.logText);
|
||||
questAlerts.put(category + ":" + quest.title, String.valueOf(playerData.questData.activeQuests.get(quest.id).sendAlerts));
|
||||
questStatus.put(category + ":" + quest.title, quest.questInterface.getQuestLogStatus(player));
|
||||
String key = category + ":" + quest.title;
|
||||
questText.put(key, quest.logText);
|
||||
questAlerts.put(key, String.valueOf(playerData.questData.activeQuests.get(quest.id).sendAlerts));
|
||||
questStatus.put(key, quest.questInterface.getQuestLogStatus(player));
|
||||
if(quest.completion == EnumQuestCompletion.Npc && quest.questInterface.isCompleted(playerData))
|
||||
finish.put(category + ":" + quest.title, quest.completerNpc);
|
||||
finish.put(key, quest.completerNpc);
|
||||
|
||||
if (playerData.questData.getTrackedQuest() != null) {
|
||||
if (quest.id == playerData.questData.getTrackedQuest().getId()) {
|
||||
trackedQuestKey = category + ":" + quest.title;
|
||||
trackedQuestKey = key;
|
||||
}
|
||||
}
|
||||
|
||||
if (quest.partyOptions.allowParty) {
|
||||
partyQuests.add(category + ":" + quest.title);
|
||||
partyQuests.put(key, quest.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ public class GuiParty extends GuiCNPCInventory implements ITextfieldListener, IT
|
||||
break;
|
||||
case 4:
|
||||
// Drop Party Quest
|
||||
Client.sendData(EnumPacketServer.SetPartyQuest, "", "");
|
||||
Client.sendData(EnumPacketServer.SetPartyQuest, -1);
|
||||
break;
|
||||
}
|
||||
receivedData = false;
|
||||
|
||||
@@ -90,7 +90,7 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,
|
||||
addButton(new GuiButtonNextPage(1, guiLeft + 286, guiTop + 176, true));
|
||||
addButton(new GuiButtonNextPage(2, guiLeft + 144, guiTop + 176, false));
|
||||
|
||||
if (data.partyQuests.contains(data.selectedCategory + ":" + data.selectedQuest)) {
|
||||
if (data.partyQuests.containsKey(data.selectedCategory + ":" + data.selectedQuest)) {
|
||||
String questName = ClientCacheHandler.party != null ? ClientCacheHandler.party.getCurrentQuestName() : null;
|
||||
GuiNpcButton partyButton = new GuiNpcButton(3, guiLeft + 150, guiTop + 151, 50, 20, new String[]{"party.party", "party.partying"}, Objects.equals(questName, data.selectedQuest) ? 1 : 0);
|
||||
addButton(partyButton);
|
||||
@@ -124,7 +124,11 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,
|
||||
public void confirmClicked(boolean flag, int i) {
|
||||
if (flag) {
|
||||
if (i == 0) {
|
||||
Client.sendData(EnumPacketServer.SetPartyQuest, data.selectedCategory, data.selectedQuest);
|
||||
String key = data.selectedCategory + ":" + data.selectedQuest;
|
||||
if(data.partyQuests.containsKey(key)){
|
||||
int questID = data.partyQuests.get(key);
|
||||
Client.sendData(EnumPacketServer.SetPartyQuest, questID);
|
||||
}
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
@@ -142,7 +146,7 @@ public class GuiQuestLog extends GuiCNPCInventory implements ITopButtonListener,
|
||||
if (guibutton.id == 3)
|
||||
{
|
||||
if (Objects.equals(ClientCacheHandler.party.getCurrentQuestName(), data.selectedQuest)) {
|
||||
Client.sendData(EnumPacketServer.SetPartyQuest, "", "");
|
||||
Client.sendData(EnumPacketServer.SetPartyQuest, -1);
|
||||
} else {
|
||||
GuiYesNo yesnoDisband = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("party.setQuestConfirm"), 0);
|
||||
displayGuiScreen(yesnoDisband);
|
||||
|
||||
@@ -25,18 +25,18 @@ public class QuestController implements IQuestHandler {
|
||||
|
||||
private int lastUsedCatID = 0;
|
||||
private int lastUsedQuestID = 0;
|
||||
|
||||
|
||||
public QuestController(){
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
|
||||
public void load(){
|
||||
categories.clear();
|
||||
quests.clear();
|
||||
|
||||
lastUsedCatID = 0;
|
||||
lastUsedQuestID = 0;
|
||||
|
||||
|
||||
try {
|
||||
File file = new File(CustomNpcs.getWorldSaveDirectory(), "quests.dat");
|
||||
if(file.exists()){
|
||||
@@ -48,9 +48,9 @@ public class QuestController implements IQuestHandler {
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
File dir = getDir();
|
||||
if(!dir.exists()){
|
||||
dir.mkdir();
|
||||
@@ -103,7 +103,7 @@ public class QuestController implements IQuestHandler {
|
||||
File dir = getDir();
|
||||
if(!dir.exists()){
|
||||
dir.mkdir();
|
||||
}
|
||||
}
|
||||
NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file));
|
||||
lastUsedCatID = nbttagcompound1.getInteger("lastID");
|
||||
lastUsedQuestID = nbttagcompound1.getInteger("lastQuestID");
|
||||
@@ -143,7 +143,7 @@ public class QuestController implements IQuestHandler {
|
||||
quests.remove(dia);
|
||||
categories.remove(category);
|
||||
}
|
||||
|
||||
|
||||
public void saveCategory(QuestCategory category){
|
||||
category.title = NoppesStringUtils.cleanFileName(category.title);
|
||||
if(categories.containsKey(category.id)){
|
||||
@@ -181,7 +181,7 @@ public class QuestController implements IQuestHandler {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean containsQuestName(QuestCategory category, Quest quest) {
|
||||
for(Quest q : category.quests.values()){
|
||||
if(q.id != quest.id && q.title.equalsIgnoreCase(quest.title))
|
||||
@@ -189,7 +189,7 @@ public class QuestController implements IQuestHandler {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void saveQuest(int categoryID, Quest quest){
|
||||
QuestCategory category = categories.get(categoryID);
|
||||
if(category == null)
|
||||
@@ -199,21 +199,21 @@ public class QuestController implements IQuestHandler {
|
||||
while(containsQuestName(quest.category, quest)){
|
||||
quest.title = quest.title + "_";
|
||||
}
|
||||
|
||||
|
||||
if(quest.id < 0){
|
||||
lastUsedQuestID++;
|
||||
quest.id = lastUsedQuestID;
|
||||
}
|
||||
quests.put(quest.id, quest);
|
||||
category.quests.put(quest.id, quest);
|
||||
|
||||
|
||||
File dir = new File(getDir(), category.title);
|
||||
if(!dir.exists())
|
||||
dir.mkdirs();
|
||||
|
||||
File file = new File(dir, quest.id + ".json_new");
|
||||
File file2 = new File(dir, quest.id + ".json");
|
||||
|
||||
|
||||
try {
|
||||
NBTJsonUtil.SaveFile(file, quest.writeToNBTPartial(new NBTTagCompound()));
|
||||
if(file2.exists())
|
||||
|
||||
Reference in new issue
Block a user