Files
CustomNPC-Plus/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java
T

134 lines
3.9 KiB
Java
Raw Normal View History

2018-09-13 12:03:28 -04:00
package noppes.npcs.scripted.roles;
2022-05-26 01:43:17 -05:00
import foxz.utils.Market;
2018-09-13 12:03:28 -04:00
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.RoleTrader;
2022-05-27 15:54:12 -05:00
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.interfaces.item.IItemStack;
2018-09-13 12:03:28 -04:00
import noppes.npcs.scripted.constants.RoleType;
2022-05-27 15:54:12 -05:00
import noppes.npcs.scripted.interfaces.entity.IPlayer;
2022-06-12 01:26:23 -05:00
import noppes.npcs.scripted.interfaces.roles.IRoleTrader;
2018-09-13 12:03:28 -04:00
2022-06-12 01:26:23 -05:00
public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader {
2018-09-13 12:03:28 -04:00
private RoleTrader role;
public ScriptRoleTrader(EntityNPCInterface npc) {
super(npc);
role = (RoleTrader) npc.roleInterface;
}
2022-06-12 01:26:23 -05:00
public void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold){
2018-09-13 12:03:28 -04:00
if(sold == null || slot >= 18 || slot < 0)
return;
if(currency == null)
currency = currency2;
if(currency != null)
role.inventoryCurrency.items.put(slot, currency.getMCItemStack());
else
role.inventoryCurrency.items.remove(slot);
if(currency2 != null)
role.inventoryCurrency.items.put(slot + 18, currency2.getMCItemStack());
else
role.inventoryCurrency.items.remove(slot + 18);
role.inventorySold.items.put(slot, sold.getMCItemStack());
}
public void setSellOption(int slot, IItemStack currency, IItemStack sold){
2018-09-13 12:03:28 -04:00
setSellOption(slot, currency, null, sold);
}
2022-06-12 01:26:23 -05:00
public IItemStack getSellOption(int slot) {
if (slot >= 18 || slot < 0) return null;
if (role.inventorySold.items.get(slot) == null) return null;
2022-05-27 15:54:12 -05:00
return NpcAPI.Instance().getIItemStack(role.inventoryCurrency.items.get(slot));
}
2022-06-12 01:26:23 -05:00
public IItemStack[] getCurrency(int slot) {
if (slot >= 18 || slot < 0) return null;
2022-05-27 15:54:12 -05:00
IItemStack[] currency = new IItemStack[2];
if (role.inventoryCurrency.items.get(slot) != null) {
2022-05-27 15:54:12 -05:00
currency[0] = NpcAPI.Instance().getIItemStack(role.inventoryCurrency.items.get(slot));
}
if (role.inventoryCurrency.items.get(slot + 18) != null) {
2022-05-27 15:54:12 -05:00
currency[1] = NpcAPI.Instance().getIItemStack(role.inventoryCurrency.items.get(slot + 18));
}
return currency;
}
2022-06-12 01:26:23 -05:00
2018-09-13 12:03:28 -04:00
public void removeSellOption(int slot){
if(slot >= 18 || slot < 0) return;
2018-09-13 12:03:28 -04:00
role.inventoryCurrency.items.remove(slot);
role.inventoryCurrency.items.remove(slot + 18);
role.inventorySold.items.remove(slot);
}
2022-06-12 01:26:23 -05:00
2018-09-13 12:03:28 -04:00
public void setMarket(String name){
role.marketName = name;
Market.load(role, name);
}
2022-06-12 01:26:23 -05:00
2018-09-13 12:03:28 -04:00
public String getMarket(){
return role.marketName;
}
2022-06-12 01:26:23 -05:00
public int getPurchaseNum(int slot) {
if(slot >= 18 || slot < 0) return -1;
return role.purchases[slot];
}
2022-06-12 01:26:23 -05:00
2022-05-26 01:43:17 -05:00
public int getPurchaseNum(int slot, IPlayer player) {
if(slot >= 18 || slot < 0) return -1;
return role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot];
2022-05-26 01:43:17 -05:00
}
2022-06-12 01:26:23 -05:00
public void resetPurchaseNum() {
for (int i = 0; i < role.purchases.length; ++i) role.purchases[i] = 0;
}
2022-06-12 01:26:23 -05:00
2022-05-25 18:38:54 -05:00
public void resetPurchaseNum(int slot) {
if(slot >= 18 || slot < 0) return;
2022-05-25 18:38:54 -05:00
role.purchases[slot] = 0;
}
2022-06-12 01:26:23 -05:00
public void resetPurchaseNum(int slot, IPlayer player) {
if(slot >= 18 || slot < 0) return;
role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot] = 0;
}
2022-06-12 01:26:23 -05:00
public boolean isSlotEnabled(int slot) {
if(slot >= 18 || slot < 0) return false;
return role.disableSlot[slot] > 0;
}
2022-06-12 01:26:23 -05:00
public boolean isSlotEnabled(int slot, IPlayer player) {
if(slot >= 18 || slot < 0) return false;
return role.isSlotEnabled(slot, player.getDisplayName());
}
2022-06-12 01:26:23 -05:00
public void disableSlot(int slot) {
if(slot >= 18 || slot < 0) return;
role.disableSlot[slot] = 1;
}
2022-06-12 01:26:23 -05:00
public void disableSlot(int slot, IPlayer player) {
if(slot >= 18 || slot < 0) return;
role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 1;
}
2022-06-12 01:26:23 -05:00
public void enableSlot(int slot) {
if(slot >= 18 || slot < 0) return;
role.disableSlot[slot] = 0;
}
2022-06-12 01:26:23 -05:00
public void enableSlot(int slot, IPlayer player) {
if(slot >= 18 || slot < 0) return;
role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 0;
}
2018-09-13 12:03:28 -04:00
@Override
public int getType(){
return RoleType.TRADER;
}
}