mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
add get reset disable purchase num by slot number and IPlayer
needed to add get/setStringIntegerArrayMap to NBTTags so save the player purchases and disabled slots with a String int[] hashmap
This commit is contained in:
1 parent
e7250158ac
commit
3cf780d9a2
4 files changed
+141
-13
No files matched your search
@@ -1,10 +1,12 @@
|
||||
package noppes.npcs.scripted.roles;
|
||||
|
||||
import foxz.utils.Market;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.roles.RoleTrader;
|
||||
import noppes.npcs.scripted.ScriptItemStack;
|
||||
import noppes.npcs.scripted.constants.RoleType;
|
||||
import noppes.npcs.scripted.interfaces.IItemStack;
|
||||
import noppes.npcs.scripted.interfaces.IPlayer;
|
||||
|
||||
public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
@@ -20,7 +22,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
* @param currency2 Currency item number two
|
||||
* @param sold Item to be sold by this npc
|
||||
*/
|
||||
public void setSellOption(int slot, ScriptItemStack currency, ScriptItemStack currency2, ScriptItemStack sold){
|
||||
public void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold){
|
||||
if(sold == null || slot >= 18 || slot < 0)
|
||||
return;
|
||||
if(currency == null)
|
||||
@@ -43,7 +45,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
* @param currency Currency item
|
||||
* @param sold Item to be sold by this npc
|
||||
*/
|
||||
public void setSellOption(int slot, ScriptItemStack currency, ScriptItemStack sold){
|
||||
public void setSellOption(int slot, IItemStack currency, IItemStack sold){
|
||||
setSellOption(slot, currency, null, sold);
|
||||
}
|
||||
|
||||
@@ -51,7 +53,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
* @param slot
|
||||
* @return The item being sold in this slot.
|
||||
*/
|
||||
public ScriptItemStack getSellOption(int slot) {
|
||||
public IItemStack getSellOption(int slot) {
|
||||
if (slot >= 18 || slot < 0) return null;
|
||||
if (role.inventorySold.items.get(slot) == null) return null;
|
||||
return new ScriptItemStack(role.inventorySold.items.get(slot));
|
||||
@@ -61,7 +63,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
* @param slot
|
||||
* @return a ScriptItemStack array of size 2 which contains the currency of this trade
|
||||
*/
|
||||
public ScriptItemStack[] getCurrency(int slot) {
|
||||
public IItemStack[] getCurrency(int slot) {
|
||||
if (slot >= 18 || slot < 0) return null;
|
||||
ScriptItemStack[] currency = new ScriptItemStack[2];
|
||||
if (role.inventoryCurrency.items.get(slot) != null) {
|
||||
@@ -77,8 +79,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
* @param slot Slot number 0-17
|
||||
*/
|
||||
public void removeSellOption(int slot){
|
||||
if(slot >= 18 || slot < 0)
|
||||
return;
|
||||
if(slot >= 18 || slot < 0) return;
|
||||
role.inventoryCurrency.items.remove(slot);
|
||||
role.inventoryCurrency.items.remove(slot + 18);
|
||||
role.inventorySold.items.remove(slot);
|
||||
@@ -107,9 +108,14 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
return role.purchases[slot];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param slot
|
||||
* @param player
|
||||
* @return the number of times this player has purchased from this trader
|
||||
*/
|
||||
public int getPurchaseNum(int slot, IPlayer player) {
|
||||
// TODO get purchase num by player
|
||||
return -1;
|
||||
if(slot >= 18 || slot < 0) return -1;
|
||||
return role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,9 +130,39 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
* @param slot
|
||||
*/
|
||||
public void resetPurchaseNum(int slot) {
|
||||
if(slot >= 18 || slot < 0) return;
|
||||
role.purchases[slot] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the purchase num for that slot and player to 0
|
||||
* @param slot
|
||||
* @param player
|
||||
*/
|
||||
public void resetPurchaseNum(int slot, IPlayer player) {
|
||||
if(slot >= 18 || slot < 0) return;
|
||||
role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param slot
|
||||
* @return if this slot is enabled
|
||||
*/
|
||||
public boolean isSlotEnabled(int slot) {
|
||||
if(slot >= 18 || slot < 0) return false;
|
||||
return role.disableSlot[slot] > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param slot
|
||||
* @param player
|
||||
* @return if this slot is enabled for this player
|
||||
*/
|
||||
public boolean isSlotEnabled(int slot, IPlayer player) {
|
||||
if(slot >= 18 || slot < 0) return false;
|
||||
return role.isSlotEnabled(slot, (EntityPlayer)player.getMCEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
* prevent an item from being sold on that slot
|
||||
* @param slot
|
||||
@@ -136,6 +172,16 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
role.disableSlot[slot] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* disables the slot for this player
|
||||
* @param slot
|
||||
* @param player
|
||||
*/
|
||||
public void disableSlot(int slot, IPlayer player) {
|
||||
if(slot >= 18 || slot < 0) return;
|
||||
role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* allow an item to be sold on that slot
|
||||
* @param slot
|
||||
@@ -144,6 +190,16 @@ public class ScriptRoleTrader extends ScriptRoleInterface{
|
||||
if(slot >= 18 || slot < 0) return;
|
||||
role.disableSlot[slot] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* enables the slot for this player
|
||||
* @param slot
|
||||
* @param player
|
||||
*/
|
||||
public void enableSlot(int slot, IPlayer player) {
|
||||
if(slot >= 18 || slot < 0) return;
|
||||
role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType(){
|
||||
|
||||
Reference in new issue
Block a user