mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-20 11:09:42 +00:00
First Working Version of Party Kill Quest Completion
This commit is contained in:
1 parent
607b3f54d8
commit
2328b0dadf
16 files changed
+508
-104
No files matched your search
@@ -39,12 +39,12 @@ public class NoppesUtilPlayer {
|
||||
public static void changeFollowerState(EntityPlayerMP player, EntityNPCInterface npc) {
|
||||
if(npc.advanced.role != EnumRoleType.Follower)
|
||||
return;
|
||||
|
||||
|
||||
RoleFollower role = (RoleFollower) npc.roleInterface;
|
||||
EntityPlayer owner = role.owner;
|
||||
if(owner == null || !owner.getCommandSenderName().equals(player.getCommandSenderName()))
|
||||
return;
|
||||
|
||||
|
||||
role.isFollowing = !role.isFollowing;
|
||||
}
|
||||
public static void hireFollower(EntityPlayerMP player, EntityNPCInterface npc) {
|
||||
@@ -53,7 +53,7 @@ public class NoppesUtilPlayer {
|
||||
Container con = player.openContainer;
|
||||
if(con == null || !(con instanceof ContainerNPCFollowerHire))
|
||||
return;
|
||||
|
||||
|
||||
ContainerNPCFollowerHire container = (ContainerNPCFollowerHire) con;
|
||||
RoleFollower role = (RoleFollower) npc.roleInterface;
|
||||
followerBuy(role, container.currencyMatrix, player, npc);
|
||||
@@ -64,7 +64,7 @@ public class NoppesUtilPlayer {
|
||||
Container con = player.openContainer;
|
||||
if(con == null || !(con instanceof ContainerNPCFollower))
|
||||
return;
|
||||
|
||||
|
||||
ContainerNPCFollower container = (ContainerNPCFollower) con;
|
||||
RoleFollower role = (RoleFollower) npc.roleInterface;
|
||||
followerBuy(role, container.currencyMatrix, player, npc);
|
||||
@@ -75,10 +75,10 @@ public class NoppesUtilPlayer {
|
||||
|
||||
if(loc == null || !loc.isDefault() && !playerdata.transports.contains(loc.id))
|
||||
return;
|
||||
|
||||
|
||||
teleportPlayer(player, loc.posX, loc.posY, loc.posZ, loc.dimension);
|
||||
}
|
||||
|
||||
|
||||
public static void teleportPlayer(EntityPlayerMP player, double posX, double posY, double posZ, int dimension){
|
||||
if(player.dimension != dimension){
|
||||
int dim = player.dimension;
|
||||
@@ -138,7 +138,7 @@ public class NoppesUtilPlayer {
|
||||
public static void swingPlayerArm(EntityPlayerMP player){
|
||||
Server.sendData(player, EnumPacketClient.SWING_PLAYER_ARM);
|
||||
}
|
||||
|
||||
|
||||
private static void followerBuy(RoleFollower role,IInventory currencyInv,EntityPlayerMP player, EntityNPCInterface npc){
|
||||
ItemStack currency = currencyInv.getStackInSlot(0);
|
||||
if(currency == null)
|
||||
@@ -151,14 +151,14 @@ public class NoppesUtilPlayer {
|
||||
int days = 1;
|
||||
if(role.rates.containsKey(i))
|
||||
days = role.rates.get(i);
|
||||
|
||||
|
||||
cd.put(is,days);
|
||||
}
|
||||
if(cd.size() == 0)
|
||||
return;
|
||||
int stackSize = currency.stackSize;
|
||||
int days = 0;
|
||||
|
||||
|
||||
int possibleDays = 0;
|
||||
int possibleSize = stackSize;
|
||||
while(true){
|
||||
@@ -187,7 +187,7 @@ public class NoppesUtilPlayer {
|
||||
currencyInv.setInventorySlotContents(0, null);
|
||||
else
|
||||
currency = currency.splitStack(stackSize);
|
||||
|
||||
|
||||
npc.say(player, new Line(NoppesStringUtils.formatText(role.dialogHire.replace("{days}", days+""), player, npc)));
|
||||
role.setOwner(player);
|
||||
role.addDays(days);
|
||||
@@ -199,7 +199,7 @@ public class NoppesUtilPlayer {
|
||||
Container con = player.openContainer;
|
||||
if(con == null || !(con instanceof ContainerNPCBankInterface))
|
||||
return;
|
||||
|
||||
|
||||
ContainerNPCBankInterface container = (ContainerNPCBankInterface) con;
|
||||
Bank bank = BankController.getInstance().getBank(container.bankid);
|
||||
ItemStack item = bank.upgradeInventory.getStackInSlot(container.slot);
|
||||
@@ -229,11 +229,11 @@ public class NoppesUtilPlayer {
|
||||
return;
|
||||
ContainerNPCBankInterface container = (ContainerNPCBankInterface) con;
|
||||
Bank bank = BankController.getInstance().getBank(container.bankid);
|
||||
|
||||
|
||||
ItemStack item = bank.currencyInventory.getStackInSlot(container.slot);
|
||||
if(item == null)
|
||||
return;
|
||||
|
||||
|
||||
int price = item.stackSize;
|
||||
ItemStack currency = container.currencyMatrix.getStackInSlot(0);
|
||||
if(currency == null || price > currency.stackSize)
|
||||
@@ -247,7 +247,7 @@ public class NoppesUtilPlayer {
|
||||
BankData bankData = data.getBank(bank.id);
|
||||
if(bankData.unlockedSlots + 1 <= bank.maxSlots)
|
||||
bankData.unlockedSlots++;
|
||||
|
||||
|
||||
bankData.openBankGui(player, npc, bank.id, container.slot);
|
||||
}
|
||||
public static void sendData(EnumPlayerPacket enu, Object... obs) {
|
||||
@@ -450,7 +450,133 @@ public class NoppesUtilPlayer {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean questPartyCompletion(Party party) {
|
||||
if(party == null)
|
||||
return false;
|
||||
|
||||
QuestData data = party.getQuestData();
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
if (!data.quest.questInterface.isPartyCompleted(party))
|
||||
return false;
|
||||
|
||||
|
||||
Quest quest = data.quest;
|
||||
if(quest == null)
|
||||
return false;
|
||||
|
||||
PartyOptions partyOptions = quest.partyOptions;
|
||||
EnumPartyExchange complete = partyOptions.completeFor;
|
||||
EnumPartyExchange reward = partyOptions.rewardControl;
|
||||
for(String name : party.getPlayerNames()){
|
||||
EntityPlayer player = NoppesUtilServer.getPlayerByName(name);
|
||||
if(player == null)
|
||||
continue;
|
||||
|
||||
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
|
||||
if(playerData == null)
|
||||
continue;
|
||||
|
||||
|
||||
boolean isLeader = party.getLeaderUUID().equals(player.getUniqueID());
|
||||
boolean hasActiveQuest = playerData.questData.hasActiveQuest(quest.getId());
|
||||
boolean hasFinishedQuest = playerData.questData.hasFinishedQuest(quest.getId());
|
||||
|
||||
boolean meetsComplete = meetsPartyExchange(complete, hasActiveQuest, hasFinishedQuest, isLeader);
|
||||
boolean meetsReward = meetsPartyExchange(reward, hasActiveQuest, hasFinishedQuest, isLeader);
|
||||
|
||||
if(meetsComplete){
|
||||
if (data.quest.completion == EnumQuestCompletion.Instant) {
|
||||
EventHooks.onQuestFinished(player, data.quest);
|
||||
}
|
||||
}
|
||||
|
||||
if(meetsReward){
|
||||
QuestEvent.QuestTurnedInEvent event = new QuestEvent.QuestTurnedInEvent((IPlayer) NpcAPI.Instance().getIEntity(player), data.quest);
|
||||
|
||||
event.expReward = data.quest.rewardExp;
|
||||
List<IItemStack> list = new ArrayList();
|
||||
Iterator var8 = data.quest.rewardItems.items.values().iterator();
|
||||
|
||||
while(var8.hasNext()) {
|
||||
ItemStack item = (ItemStack)var8.next();
|
||||
if (item != null && item.stackSize > 0) {
|
||||
IItemStack iStack = NpcAPI.Instance().getIItemStack(item);
|
||||
if (iStack != null){
|
||||
list.add(iStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!data.quest.randomReward) {
|
||||
event.itemRewards = (IItemStack[])list.toArray(new IItemStack[list.size()]);
|
||||
} else if (!list.isEmpty()) {
|
||||
event.itemRewards = new IItemStack[]{(IItemStack)list.get(player.getRNG().nextInt(list.size()))};
|
||||
}
|
||||
|
||||
EventHooks.onQuestTurnedIn(event);
|
||||
if (event.isCancelled())
|
||||
return false;
|
||||
|
||||
IItemStack[] var12 = event.itemRewards;
|
||||
int var14 = var12.length;
|
||||
for(int var10 = 0; var10 < var14; ++var10) {
|
||||
IItemStack item = var12[var10];
|
||||
if (item != null) {
|
||||
NoppesUtilServer.GivePlayerItem(player, player, item.getMCItemStack());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(meetsComplete){
|
||||
data.quest.questInterface.handleComplete(player);
|
||||
}
|
||||
|
||||
if(meetsReward){
|
||||
if(data.quest.rewardExp > 0){
|
||||
player.worldObj.playSoundAtEntity(player, "random.orb", 0.1F, 0.5F * ((player.worldObj.rand.nextFloat() - player.worldObj.rand.nextFloat()) * 0.7F + 1.8F));
|
||||
player.addExperience(data.quest.rewardExp);
|
||||
}
|
||||
|
||||
data.quest.factionOptions.addPoints(player);
|
||||
if(data.quest.mail.isValid()){
|
||||
PlayerDataController.Instance.addPlayerMessage(player.getCommandSenderName(), data.quest.mail);
|
||||
}
|
||||
}
|
||||
|
||||
if(meetsComplete){
|
||||
if(!data.quest.command.isEmpty()){
|
||||
NoppesUtilServer.runCommand(player, "QuestCompletion", data.quest.command);
|
||||
}
|
||||
PlayerQuestController.setQuestPartyFinished(data.quest, player, data);
|
||||
}
|
||||
|
||||
if (data.quest.hasNewQuest()) {
|
||||
QuestData nextQuest = new QuestData(data.quest.getNextQuest());
|
||||
nextQuest.sendAlerts = data.quest.id != data.quest.getNextQuest().id || data.sendAlerts;
|
||||
PlayerQuestController.addActiveQuest(nextQuest, player);
|
||||
// questData.trackQuest(nextQuest.quest);
|
||||
}
|
||||
playerData.save();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean meetsPartyExchange(EnumPartyExchange exchange, boolean hasActive, boolean hasFinished, boolean isLeader){
|
||||
if(exchange == EnumPartyExchange.All){
|
||||
return true;
|
||||
} else if (isLeader){
|
||||
return true;
|
||||
} else if(exchange == EnumPartyExchange.Enrolled && hasActive){
|
||||
return true;
|
||||
} else return exchange == EnumPartyExchange.Valid && (hasActive || hasFinished);
|
||||
}
|
||||
|
||||
|
||||
public static boolean compareItems(ItemStack item, ItemStack item2, boolean ignoreDamage, boolean ignoreNBT){
|
||||
if (item2 == null || item == null){
|
||||
return false;
|
||||
@@ -493,7 +619,7 @@ public class NoppesUtilPlayer {
|
||||
public static boolean compareItems(EntityPlayer player, ItemStack item, boolean ignoreDamage, boolean ignoreNBT){
|
||||
int size = 0;
|
||||
for(ItemStack is : player.inventory.mainInventory){
|
||||
if(is != null && compareItems(item, is, ignoreDamage, ignoreNBT))
|
||||
if(is != null && compareItems(item, is, ignoreDamage, ignoreNBT))
|
||||
size += is.stackSize;
|
||||
}
|
||||
return size >= item.stackSize;
|
||||
|
||||
Reference in new issue
Block a user