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;
|
2022-11-15 15:25:53 -05:00
|
|
|
import noppes.npcs.api.item.IItemStack;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.scripted.constants.RoleType;
|
2022-11-15 15:25:53 -05:00
|
|
|
import noppes.npcs.api.entity.IPlayer;
|
|
|
|
|
import noppes.npcs.api.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
|
|
|
|
2022-05-26 15:57:24 -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());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-26 15:57:24 -05:00
|
|
|
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
|
|
|
|
2022-05-26 15:57:24 -05:00
|
|
|
public IItemStack getSellOption(int slot) {
|
2022-05-24 03:06:16 -05:00
|
|
|
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-05-24 03:06:16 -05:00
|
|
|
}
|
2022-06-12 01:26:23 -05:00
|
|
|
|
2022-05-26 15:57:24 -05:00
|
|
|
public IItemStack[] getCurrency(int slot) {
|
2022-05-24 03:06:16 -05:00
|
|
|
if (slot >= 18 || slot < 0) return null;
|
2022-05-27 15:54:12 -05:00
|
|
|
IItemStack[] currency = new IItemStack[2];
|
2022-05-24 03:06:16 -05:00
|
|
|
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));
|
2022-05-24 03:06:16 -05:00
|
|
|
}
|
|
|
|
|
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));
|
2022-05-24 03:06:16 -05:00
|
|
|
}
|
|
|
|
|
return currency;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-12 01:26:23 -05:00
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public void removeSellOption(int slot){
|
2022-05-26 15:57:24 -05:00
|
|
|
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
|
|
|
|
2022-05-24 03:06:16 -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) {
|
2022-05-26 15:57:24 -05:00
|
|
|
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
|
|
|
|
2022-05-24 03:06:16 -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) {
|
2022-05-26 15:57:24 -05:00
|
|
|
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
|
|
|
|
2022-05-26 15:57:24 -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
|
|
|
|
2022-05-26 15:57:24 -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
|
|
|
|
2022-05-26 15:57:24 -05:00
|
|
|
public boolean isSlotEnabled(int slot, IPlayer player) {
|
|
|
|
|
if(slot >= 18 || slot < 0) return false;
|
2022-06-06 14:38:33 -05:00
|
|
|
return role.isSlotEnabled(slot, player.getDisplayName());
|
2022-05-26 15:57:24 -05:00
|
|
|
}
|
2022-06-12 01:26:23 -05:00
|
|
|
|
2022-05-24 03:06:16 -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
|
|
|
|
2022-05-26 15:57:24 -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
|
|
|
|
2022-05-24 03:06:16 -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
|
|
|
|
2022-05-26 15:57:24 -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;
|
|
|
|
|
}
|
|
|
|
|
}
|