First Working Version of Party Kill Quest Completion

This commit is contained in:
Kam committed 2024-03-02 21:06:42 -05:00
1 parent 607b3f54d8
commit 2328b0dadf
16 files changed
+508 -104

No files matched your search

@@ -1,13 +1,17 @@
package noppes.npcs.quests;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NoppesUtilPlayer;
import noppes.npcs.NoppesUtilServer;
import noppes.npcs.NpcMiscInventory;
import noppes.npcs.Server;
import noppes.npcs.api.handler.data.IQuestItem;
import noppes.npcs.api.handler.data.IQuestObjective;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.data.Party;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.scripted.CustomNPCsException;
@@ -145,6 +149,20 @@ public class QuestItem extends QuestInterface implements IQuestItem {
return list.toArray(new IQuestObjective[0]);
}
@Override
public IQuestObjective[] getPartyObjectives(Party party) {
List<IQuestObjective> list = new ArrayList<>();
List<ItemStack> questItems = NoppesUtilPlayer.countStacks(this.items, this.ignoreDamage, this.ignoreNBT);
for (ItemStack stack : questItems) {
if (stack.stackSize > 0) {
list.add(new QuestItemObjective(this, party, stack));
}
}
return list.toArray(new IQuestObjective[0]);
}
@Override
public Vector<String> getPartyQuestLogStatus(Party party) {
Vector<String> vec = new Vector<String>();
@@ -214,13 +232,21 @@ public class QuestItem extends QuestInterface implements IQuestItem {
class QuestItemObjective implements IQuestObjective {
private final QuestItem parent;
private final EntityPlayer player;
private final Party party;
private final ItemStack questItem;
public QuestItemObjective(QuestItem this$0, EntityPlayer player, ItemStack item) {
this.parent = this$0;
this.player = player;
this.questItem = item;
this.party = null;
}
public QuestItemObjective(QuestItem this$0, Party party, ItemStack item) {
this.parent = this$0;
this.player = null;
this.questItem = item;
this.party = party;
}
public int getProgress() {
int count = 0;
@@ -230,12 +256,27 @@ public class QuestItem extends QuestInterface implements IQuestItem {
count += item.stackSize;
}
for(int i = 0; i < this.player.inventory.getSizeInventory(); ++i) {
item = this.player.inventory.getStackInSlot(i);
if (!NoppesUtilServer.IsItemStackNull(item) && NoppesUtilPlayer.compareItems(this.questItem, item, this.parent.ignoreDamage, this.parent.ignoreNBT)) {
count += item.stackSize;
}
}
if(player != null){
for(int i = 0; i < this.player.inventory.getSizeInventory(); ++i) {
item = this.player.inventory.getStackInSlot(i);
if (!NoppesUtilServer.IsItemStackNull(item) && NoppesUtilPlayer.compareItems(this.questItem, item, this.parent.ignoreDamage, this.parent.ignoreNBT)) {
count += item.stackSize;
}
}
} else if (party != null){
for(String name : party.getPlayerNames()){
EntityPlayer playerMP = NoppesUtilServer.getPlayerByName(name);
if(playerMP == null)
continue;
for(int i = 0; i < playerMP.inventory.getSizeInventory(); ++i) {
item = playerMP.inventory.getStackInSlot(i);
if (!NoppesUtilServer.IsItemStackNull(item) && NoppesUtilPlayer.compareItems(this.questItem, item, this.parent.ignoreDamage, this.parent.ignoreNBT)) {
count += item.stackSize;
}
}
}
}
return ValueUtil.clamp(count, 0, this.questItem.stackSize);
}
@@ -249,9 +290,28 @@ public class QuestItem extends QuestInterface implements IQuestItem {
}
public boolean isCompleted() {
return NoppesUtilPlayer.compareItems(this.player, this.questItem, this.parent.ignoreDamage, this.parent.ignoreNBT);
if(player != null)
return NoppesUtilPlayer.compareItems(this.player, this.questItem, this.parent.ignoreDamage, this.parent.ignoreNBT);
else if(party != null)
return comparePartyItems(this.party, this.questItem, this.parent.ignoreDamage, this.parent.ignoreNBT);
return false;
}
public boolean comparePartyItems(Party party, ItemStack item, boolean ignoreDamage, boolean ignoreNBT){
int size = 0;
for(String name : party.getPlayerNames()){
EntityPlayer playerMP = NoppesUtilServer.getPlayerByName(name);
if(playerMP == null)
continue;
for(ItemStack is : playerMP.inventory.mainInventory){
if(is != null && NoppesUtilPlayer.compareItems(item, is, ignoreDamage, ignoreNBT))
size += is.stackSize;
}
}
return size >= item.stackSize;
}
public String getText() {
return this.questItem.getDisplayName() + ": " + this.getProgress() + "/" + this.getMaxProgress();
}