mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 17:23:07 +00:00
Trader System + Stocks Implemented
- Removed Auction System Temporarily for Full Rebase
This commit is contained in:
1 parent
692b985237
commit
d0dc8a4578
61 files changed
+2595
-6897
No files matched your search
@@ -49,14 +49,11 @@ import noppes.npcs.compat.PixelmonHelper;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.constants.EnumQuestType;
|
||||
import noppes.npcs.containers.ContainerCustomGui;
|
||||
import noppes.npcs.controllers.AuctionController;
|
||||
import noppes.npcs.controllers.CurrencyController;
|
||||
import noppes.npcs.controllers.CustomGuiController;
|
||||
import noppes.npcs.controllers.DialogController;
|
||||
import noppes.npcs.controllers.PartyController;
|
||||
import noppes.npcs.controllers.PlayerQuestController;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.VaultHelper;
|
||||
import noppes.npcs.controllers.data.Dialog;
|
||||
import noppes.npcs.controllers.data.Party;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
@@ -899,185 +896,42 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
return (IPlayer[]) list.toArray(new IPlayer[list.size()]);
|
||||
}
|
||||
|
||||
// ==================== CURRENCY METHODS ====================
|
||||
// =========================================
|
||||
// Currency Methods
|
||||
// =========================================
|
||||
|
||||
/**
|
||||
* Get the player's current currency balance.
|
||||
* Uses Vault if available, otherwise uses internal currency system.
|
||||
* @return The player's currency balance
|
||||
* @since 1.11
|
||||
*/
|
||||
@Override
|
||||
public long getCurrencyBalance() {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return CurrencyController.Instance.getBalance(player);
|
||||
return getData().currencyData.getBalance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add currency to the player's balance.
|
||||
* @param amount The amount to add (must be positive)
|
||||
* @return true if successful, false if failed (e.g., would exceed max balance)
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean addCurrency(long amount) {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return false;
|
||||
}
|
||||
return CurrencyController.Instance.deposit(player, amount);
|
||||
@Override
|
||||
public void setCurrencyBalance(long amount) {
|
||||
getData().currencyData.setBalance(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove currency from the player's balance.
|
||||
* @param amount The amount to remove (must be positive)
|
||||
* @return true if successful, false if insufficient funds
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean removeCurrency(long amount) {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return false;
|
||||
}
|
||||
return CurrencyController.Instance.withdraw(player, amount);
|
||||
@Override
|
||||
public boolean depositCurrency(long amount) {
|
||||
return getData().currencyData.deposit(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player can afford a specific amount.
|
||||
* @param amount The amount to check
|
||||
* @return true if player has sufficient balance
|
||||
* @since 1.11
|
||||
*/
|
||||
@Override
|
||||
public boolean withdrawCurrency(long amount) {
|
||||
return getData().currencyData.withdraw(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAffordCurrency(long amount) {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return false;
|
||||
}
|
||||
return CurrencyController.Instance.canAfford(player, amount);
|
||||
return getData().currencyData.canAfford(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the configured currency name (e.g., "Gold").
|
||||
* @return The currency name
|
||||
* @since 1.11
|
||||
*/
|
||||
public String getCurrencyName() {
|
||||
if (VaultHelper.Instance == null) {
|
||||
return "Currency";
|
||||
}
|
||||
return VaultHelper.Instance.getCurrencyName();
|
||||
@Override
|
||||
public boolean isUsingVaultCurrency() {
|
||||
return getData().currencyData.isUsingVault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a currency amount for display (e.g., "1,000 Gold").
|
||||
* @param amount The amount to format
|
||||
* @return Formatted string
|
||||
* @since 1.11
|
||||
*/
|
||||
public String formatCurrency(long amount) {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return String.valueOf(amount);
|
||||
}
|
||||
return CurrencyController.Instance.formatAmount(amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has pending currency claims.
|
||||
* Claims are created by auction refunds, NPC payments, etc.
|
||||
* @return true if there are pending claims
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean hasPendingClaims() {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return false;
|
||||
}
|
||||
return CurrencyController.Instance.hasPendingClaims(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total amount of pending currency claims.
|
||||
* @return Total pending claim amount
|
||||
* @since 1.11
|
||||
*/
|
||||
public long getPendingClaimsTotal() {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return CurrencyController.Instance.getTotalPendingClaims(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Claim all pending currency claims and add them to balance.
|
||||
* @return The total amount claimed
|
||||
* @since 1.11
|
||||
*/
|
||||
public long claimAllCurrency() {
|
||||
if (CurrencyController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return CurrencyController.Instance.claimAll(player);
|
||||
}
|
||||
|
||||
// ==================== AUCTION METHODS ====================
|
||||
|
||||
/**
|
||||
* Get the number of active auction listings the player has.
|
||||
* @return Number of active listings
|
||||
* @since 1.11
|
||||
*/
|
||||
public int getAuctionListingCount() {
|
||||
if (AuctionController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return AuctionController.Instance.getActiveListingsCount(player.getUniqueID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum number of auction listings the player is allowed.
|
||||
* @return Maximum listing count
|
||||
* @since 1.11
|
||||
*/
|
||||
public int getMaxAuctionListings() {
|
||||
if (AuctionController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return AuctionController.Instance.getMaxListings(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the player has auction items waiting to be claimed.
|
||||
* This includes won items, expired listings, and sale proceeds.
|
||||
* @return true if there are claimable items
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean hasAuctionClaims() {
|
||||
if (AuctionController.Instance == null) {
|
||||
return false;
|
||||
}
|
||||
return !AuctionController.Instance.getClaimableListings(player.getUniqueID()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of auction items waiting to be claimed.
|
||||
* @return Number of claimable items/listings
|
||||
* @since 1.11
|
||||
*/
|
||||
public int getAuctionClaimCount() {
|
||||
if (AuctionController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return AuctionController.Instance.getClaimableListings(player.getUniqueID()).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of auctions where the player is the current high bidder.
|
||||
* @return Number of active bids
|
||||
* @since 1.11
|
||||
*/
|
||||
public int getActiveAuctionBidCount() {
|
||||
if (AuctionController.Instance == null) {
|
||||
return 0;
|
||||
}
|
||||
return (int) AuctionController.Instance.getListingsAsBidder(player.getUniqueID())
|
||||
.stream()
|
||||
.filter(l -> l.isActive())
|
||||
.count();
|
||||
@Override
|
||||
public String getFormattedCurrencyBalance() {
|
||||
return getData().currencyData.formatBalance();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package noppes.npcs.scripted.item;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import kamkeel.npcs.controllers.data.attribute.ItemTradeAttribute;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.IRequirementChecker;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
|
||||
import kamkeel.npcs.util.AttributeItemUtil;
|
||||
@@ -593,117 +592,4 @@ public class ScriptItemStack implements IItemStack {
|
||||
Set<String> keys = reqTag.func_150296_c();
|
||||
return keys.toArray(new String[keys.size()]);
|
||||
}
|
||||
|
||||
// ==================== Trade Restriction Methods ====================
|
||||
|
||||
/**
|
||||
* Check if this item can be traded or auctioned.
|
||||
* An item cannot be traded if it is:
|
||||
* - Marked as untradeable
|
||||
* - Bound to a profile slot
|
||||
* - Soulbound to a player
|
||||
* @return true if the item can be traded
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean canTrade() {
|
||||
return ItemTradeAttribute.canTrade(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reason why this item cannot be traded.
|
||||
* @return Localization key for the block reason, or null if tradeable
|
||||
* @since 1.11
|
||||
*/
|
||||
public String getTradeBlockReason() {
|
||||
return ItemTradeAttribute.getTradeBlockReason(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this item is marked as untradeable
|
||||
* @return true if untradeable
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean isUntradeable() {
|
||||
return ItemTradeAttribute.isUntradeable(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this item is untradeable
|
||||
* @param untradeable true to mark as untradeable
|
||||
* @since 1.11
|
||||
*/
|
||||
public void setUntradeable(boolean untradeable) {
|
||||
ItemTradeAttribute.setUntradeable(item, untradeable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this item is bound to a profile slot
|
||||
* @return true if profile slot bound
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean isProfileSlotBound() {
|
||||
return ItemTradeAttribute.isProfileSlotBound(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the profile slot this item is bound to
|
||||
* @return Profile slot ID, or -1 if not bound
|
||||
* @since 1.11
|
||||
*/
|
||||
public int getProfileSlot() {
|
||||
return ItemTradeAttribute.getProfileSlot(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind this item to a specific profile slot
|
||||
* @param slot The profile slot ID, or -1 to unbind
|
||||
* @since 1.11
|
||||
*/
|
||||
public void setProfileSlotBound(int slot) {
|
||||
ItemTradeAttribute.setProfileSlotBound(item, slot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this item is soulbound to any player
|
||||
* @return true if soulbound
|
||||
* @since 1.11
|
||||
*/
|
||||
public boolean isSoulbound() {
|
||||
return ItemTradeAttribute.isSoulbound(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UUID of the player this item is soulbound to
|
||||
* @return UUID string, or null if not soulbound
|
||||
* @since 1.11
|
||||
*/
|
||||
public String getSoulbindOwner() {
|
||||
return ItemTradeAttribute.getSoulbindOwner(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the soulbind from this item
|
||||
* @since 1.11
|
||||
*/
|
||||
public void removeSoulbind() {
|
||||
ItemTradeAttribute.removeSoulbind(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all trade restrictions from this item
|
||||
* (untradeable, profile slot bound, soulbound)
|
||||
* @since 1.11
|
||||
*/
|
||||
public void clearTradeRestrictions() {
|
||||
ItemTradeAttribute.clearAllRestrictions(item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a summary of all trade restrictions on this item
|
||||
* @return Human-readable string of restrictions, or empty if none
|
||||
* @since 1.11
|
||||
*/
|
||||
public String getRestrictionSummary() {
|
||||
return ItemTradeAttribute.getRestrictionSummary(item);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader
|
||||
public IItemStack getSellOption(int slot) {
|
||||
if (slot >= 18 || slot < 0) return null;
|
||||
if (role.inventorySold.items.get(slot) == null) return null;
|
||||
return NpcAPI.Instance().getIItemStack(role.inventoryCurrency.items.get(slot));
|
||||
return NpcAPI.Instance().getIItemStack(role.inventorySold.items.get(slot));
|
||||
}
|
||||
|
||||
public IItemStack[] getCurrency(int slot) {
|
||||
@@ -100,7 +100,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader
|
||||
|
||||
public boolean isSlotEnabled(int slot) {
|
||||
if (slot >= 18 || slot < 0) return false;
|
||||
return role.disableSlot[slot] > 0;
|
||||
return role.disableSlot[slot] <= 0; // enabled when NOT disabled
|
||||
}
|
||||
|
||||
public boolean isSlotEnabled(int slot, IPlayer player) {
|
||||
@@ -128,6 +128,132 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader
|
||||
role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 0;
|
||||
}
|
||||
|
||||
// ==================== Stock System ====================
|
||||
|
||||
public boolean isStockEnabled() {
|
||||
return role.stock.enableStock;
|
||||
}
|
||||
|
||||
public void setStockEnabled(boolean enabled) {
|
||||
role.stock.enableStock = enabled;
|
||||
}
|
||||
|
||||
public boolean isPerPlayerStock() {
|
||||
return role.stock.perPlayer;
|
||||
}
|
||||
|
||||
public void setPerPlayerStock(boolean perPlayer) {
|
||||
role.stock.perPlayer = perPlayer;
|
||||
}
|
||||
|
||||
public int getStockResetType() {
|
||||
return role.stock.resetType.ordinal();
|
||||
}
|
||||
|
||||
public void setStockResetType(int type) {
|
||||
noppes.npcs.constants.EnumStockReset[] values = noppes.npcs.constants.EnumStockReset.values();
|
||||
if (type >= 0 && type < values.length) {
|
||||
role.stock.resetType = values[type];
|
||||
}
|
||||
}
|
||||
|
||||
public long getCustomResetTime() {
|
||||
return role.stock.customResetTime;
|
||||
}
|
||||
|
||||
public void setCustomResetTime(long time) {
|
||||
role.stock.customResetTime = Math.max(0, time);
|
||||
}
|
||||
|
||||
public int getMaxStock(int slot) {
|
||||
if (slot < 0 || slot >= 18) return -1;
|
||||
return role.stock.maxStock[slot];
|
||||
}
|
||||
|
||||
public void setMaxStock(int slot, int amount) {
|
||||
if (slot >= 0 && slot < 18) {
|
||||
role.stock.setMaxStock(slot, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public int getAvailableStock(int slot) {
|
||||
if (slot < 0 || slot >= 18) return 0;
|
||||
return role.stock.getAvailableStock(slot, "");
|
||||
}
|
||||
|
||||
public int getAvailableStock(int slot, IPlayer player) {
|
||||
if (slot < 0 || slot >= 18) return 0;
|
||||
return role.stock.getAvailableStock(slot, player.getDisplayName());
|
||||
}
|
||||
|
||||
public void resetStock() {
|
||||
long currentTime = role.stock.resetType.isRealTime()
|
||||
? System.currentTimeMillis()
|
||||
: (npc.worldObj != null ? npc.worldObj.getTotalWorldTime() : 0);
|
||||
role.stock.resetStock(currentTime);
|
||||
}
|
||||
|
||||
public void resetCooldown() {
|
||||
long currentTime = role.stock.resetType.isRealTime()
|
||||
? System.currentTimeMillis()
|
||||
: (npc.worldObj != null ? npc.worldObj.getTotalWorldTime() : 0);
|
||||
role.stock.lastResetTime = currentTime;
|
||||
}
|
||||
|
||||
public int getCurrentStock(int slot) {
|
||||
if (slot < 0 || slot >= 18) return -1;
|
||||
return role.stock.currentStock[slot];
|
||||
}
|
||||
|
||||
public void setCurrentStock(int slot, int amount) {
|
||||
if (slot >= 0 && slot < 18) {
|
||||
role.stock.currentStock[slot] = amount;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPlayerPurchased(int slot, IPlayer player) {
|
||||
if (slot < 0 || slot >= 18) return 0;
|
||||
noppes.npcs.controllers.data.TraderStock.PlayerTraderStock pStock =
|
||||
role.stock.playerStock.get(player.getDisplayName());
|
||||
if (pStock == null) return 0;
|
||||
return pStock.purchasedAmounts[slot];
|
||||
}
|
||||
|
||||
public void setPlayerPurchased(int slot, IPlayer player, int amount) {
|
||||
if (slot < 0 || slot >= 18) return;
|
||||
noppes.npcs.controllers.data.TraderStock.PlayerTraderStock pStock =
|
||||
role.stock.playerStock.computeIfAbsent(
|
||||
player.getDisplayName(),
|
||||
k -> new noppes.npcs.controllers.data.TraderStock.PlayerTraderStock()
|
||||
);
|
||||
pStock.purchasedAmounts[slot] = Math.max(0, amount);
|
||||
}
|
||||
|
||||
public long getLastResetTime() {
|
||||
return role.stock.lastResetTime;
|
||||
}
|
||||
|
||||
public long getTimeUntilReset() {
|
||||
long currentTime = role.stock.resetType.isRealTime()
|
||||
? System.currentTimeMillis()
|
||||
: (npc.worldObj != null ? npc.worldObj.getTotalWorldTime() : 0);
|
||||
return role.stock.getTimeUntilReset(currentTime);
|
||||
}
|
||||
|
||||
// ==================== Currency Cost System ====================
|
||||
|
||||
public long getCurrencyCost(int slot) {
|
||||
return role.getCurrencyCost(slot);
|
||||
}
|
||||
|
||||
public void setCurrencyCost(int slot, long cost) {
|
||||
role.setCurrencyCost(slot, cost);
|
||||
}
|
||||
|
||||
public boolean hasCurrencyCost(int slot) {
|
||||
return role.hasCurrencyCost(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return RoleType.TRADER;
|
||||
|
||||
Reference in new issue
Block a user