Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ruseps.shops.impl;
- import java.sql.ResultSet;
- import java.util.HashMap;
- import com.ruseps.Server;
- import com.ruseps.model.Item;
- import com.ruseps.model.definitions.ItemDefinition;
- import com.ruseps.model.item.Items;
- import com.ruseps.shops.Shop;
- import com.ruseps.util.Misc;
- import com.ruseps.world.content.dialogue.Dialogue;
- import com.ruseps.world.content.dialogue.DialogueExpression;
- import com.ruseps.world.content.dialogue.DialogueManager;
- import com.ruseps.world.content.dialogue.DialogueType;
- import com.ruseps.world.entity.impl.player.Player;
- public class CurrencyShop extends Shop {
- protected int currency;
- private HashMap<Integer, Integer> prices = new HashMap<Integer, Integer>();
- public int getCurrency() {
- return currency;
- }
- /**
- * @param id
- * @param name
- * @param container
- * @param currency
- * @param general
- */
- public CurrencyShop(int id, String name, int currency, boolean general) {
- super(id, name, general);
- this.currency = currency;
- try {
- loadPrices();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public HashMap<Integer, Integer> getPrices() {
- return prices;
- }
- /**
- * Loads the prices for all items
- *
- * @throws Exception
- */
- private void loadPrices() throws Exception {
- if (currency == BLOOD_MONEY_ID) {
- prices.put(4151, 2000); //abyssal whip
- prices.put(15486, 2000); //staff of light
- prices.put(11235, 750); //dark bow
- prices.put(14484, 50000); //dragon claws
- prices.put(19780, 15000); //korasi
- prices.put(51003, 150000); //elder maul
- prices.put(11696, 5000); //bandos godsword
- prices.put(11698, 5000); //saradomin godsword
- prices.put(11700, 5000); //zamorak godsword
- prices.put(11694, 20000); //armadyl godsword
- prices.put(49481, 150000); //ballista
- prices.put(11128, 2000); //berserker necklace
- prices.put(10887, 20000); //barrelchest anchor
- prices.put(11730, 5000); //saradomin sword
- prices.put(4716, 1500); //dh helm
- prices.put(4724, 750); //guthan helm
- prices.put(4745, 750); //torag helm
- prices.put(4753, 750); //verac helm
- prices.put(4708, 1000); //ahrim hood
- prices.put(4732, 750); //karil coif
- prices.put(11554, 15000); //abyssal tentacle
- prices.put(15241, 15000); //hand cannon
- prices.put(51902, 30000); //dragon crossbow
- prices.put(51012, 35000); //dragon hunter crossbow
- prices.put(4720, 1500); //dharok platebody
- prices.put(4728, 1000); //guthan platebody
- prices.put(4749, 1000); //torag platebody
- prices.put(4757, 1000); //verac platebody
- prices.put(4712, 1500); //ahrim robetop
- prices.put(4736, 1000); //karil top
- prices.put(6585, 750); //fury
- prices.put(20000, 25000); //steads
- prices.put(20002, 20000); //ragefires
- prices.put(20001, 25000); //glaivens
- prices.put(4722, 1500); //dharok legs
- prices.put(4730, 1000); //guthan legs
- prices.put(4751, 1000); //torag legs
- prices.put(4759, 1000); //verac legs
- prices.put(4714, 1500); //ahrim bottoms
- prices.put(4738, 1000); //karil skirt
- prices.put(15019, 1500); //archers ring (i)
- prices.put(15018, 1500); //seers ring (i)
- prices.put(15020, 1500); //warrior ring (i)
- prices.put(15220, 3000); //berserker ring (i)
- prices.put(4718, 1500); //dharok axe
- prices.put(4726, 1000); //guthan warspear
- prices.put(4747, 1000); //torag hammer
- prices.put(4755, 1000); //verac's flail
- prices.put(4710, 1000); //ahrim staff
- prices.put(4734, 1000); //karil's crossbow
- prices.put(12601, 45000); //ring of the gods
- prices.put(6914, 500); //master wand
- prices.put(12284, 35000); //toxic staff
- prices.put(4706, 35000); //zaryte bow
- prices.put(11726, 40000); //bandos tassets
- prices.put(11724, 40000); //bandos chestplate
- prices.put(49547, 700000); //aguish neck
- prices.put(11732, 1000); //dragon boots
- prices.put(6920, 1000); //infinity boots
- prices.put(2577, 1000); //ranger boots
- prices.put(11718, 6000); //armadyl helmet
- prices.put(11720, 6000); //armadyl body
- prices.put(11722, 6000); //armadyl legs
- prices.put(12926, 30000); //blowpipe
- prices.put(50214, 10000); //team cape x
- prices.put(50217, 10000); //team cape i
- prices.put(42695, 50); //super combat pot
- prices.put(2581, 5000); //robin hood hat
- prices.put(11848, 6000); //dharok set
- prices.put(11850, 4000); //guthan set
- prices.put(11854, 4000); //torag set
- prices.put(11856, 4000); //verac set
- prices.put(11846, 5500); //ahrim set
- prices.put(11852, 4000); //karil set
- prices.put(4740, 25); //bolt racks
- prices.put(15332, 500); //overloads
- }
- if (currency == STARDUST) {
- prices.put(50014, 6000); //ahrim set
- prices.put(15259, 3500); //karil set
- prices.put(13661, 1700); //bolt racks
- prices.put(6585, 700); //overloads
- prices.put(2581, 650); //ahrim set
- prices.put(2577, 650); //karil set
- prices.put(2417, 500); //bolt racks
- prices.put(2415, 500); //overloads
- prices.put(2416, 500); //overloads
- prices.put(11704, 200); //ahrim set
- prices.put(11706, 200); //karil set
- prices.put(11708, 200); //bolt racks
- prices.put(11710, 200); //overloads
- prices.put(11712, 200); //overloads
- prices.put(11714, 200); //overloads
- prices.put(6918, 300); //overloads
- prices.put(6916, 400); //overloads
- prices.put(6924, 350); //overloads
- }
- if (currency == DUNG_COINS_ID) {
- prices.put(18361, 250000); //ahrim set
- prices.put(18349, 250000); //karil set
- prices.put(18353, 250000); //bolt racks
- prices.put(18357, 250000); //overloads
- prices.put(18355, 250000); //ahrim set
- prices.put(18359, 250000); //karil set
- prices.put(18361, 250000); //bolt racks
- prices.put(18363, 250000); //overloads
- prices.put(16955, 1500000); //overloads
- prices.put(18335, 75000); //ahrim set
- prices.put(16425, 1500000); //karil set
- prices.put(16909, 1500000); //bolt racks
- prices.put(6500, 500000); //overloads
- prices.put(18346, 80000); //overloads
- prices.put(18782, 30000); //overloads
- prices.put(18337, 75000); //overloads
- prices.put(19669, 200000); //overloads
- prices.put(6924, 350); //overloads
- }
- if (currency == AGILITY_TICKET) {
- prices.put(14936, 300); //ahrim set
- prices.put(14938, 250); //karil set
- }
- if (currency == ENERGY_FRAGMENT) {
- prices.put(5509, 75); //ahrim set
- prices.put(5510, 125); //karil set
- prices.put(5512, 200); //ahrim set
- prices.put(13626, 900); //karil set
- prices.put(13624, 1100); //ahrim set
- prices.put(13627, 1100); //karil set
- prices.put(13628, 900); //ahrim set
- }
- if (currency == ZOMBIE_FRAGMENT) {
- prices.put(18337, 200); //ahrim set
- prices.put(10551, 450); //karil set
- prices.put(10548, 500); //ahrim set
- prices.put(10549, 500); //karil set
- prices.put(10550, 1750); //ahrim set
- prices.put(7592, 1750); //karil set
- prices.put(7593, 1700); //ahrim set
- prices.put(7594, 1850); //ahrim set
- prices.put(7595, 1600); //karil set
- prices.put(7596, 1650); //ahrim set
- prices.put(15241, 280); //karil set
- prices.put(15243, 1); //ahrim set
- prices.put(4151, 450); //karil set
- prices.put(6585, 200); //ahrim set
- prices.put(4706, 1000); //karil set
- prices.put(13263, 1500); //ahrim set
- prices.put(11696, 1250); //karil set
- prices.put(11698, 1250); //ahrim set
- prices.put(11700, 1100); //karil set
- }
- if (currency == CASTLE_WARS_TICKET) {
- prices.put(4071, 16); //ahrim set
- prices.put(4069, 24); //karil set
- prices.put(4068, 18); //ahrim set
- prices.put(4072, 18); //karil set
- prices.put(4070, 15); //ahrim set
- prices.put(4506, 32); //karil set
- prices.put(4504, 48); //ahrim set
- prices.put(4503, 36); //ahrim set
- prices.put(4507, 36); //karil set
- prices.put(4505, 30); //ahrim set
- prices.put(4511, 64); //karil set
- prices.put(4509, 96); //ahrim set
- prices.put(4508, 74); //karil set
- prices.put(4512, 74); //ahrim set
- prices.put(4510, 60); //karil set
- prices.put(18782, 5); //ahrim set
- }
- if (currency == CASTLEWARS_TICKET) {
- prices.put(4071, 16); //ahrim set
- prices.put(4069, 24); //karil set
- prices.put(4068, 18); //ahrim set
- prices.put(4072, 18); //karil set
- prices.put(4070, 15); //ahrim set
- prices.put(4506, 32); //karil set
- prices.put(4504, 48); //ahrim set
- prices.put(4503, 36); //ahrim set
- prices.put(4507, 36); //karil set
- prices.put(4505, 30); //ahrim set
- prices.put(4511, 64); //karil set
- prices.put(4509, 96); //ahrim set
- prices.put(4508, 74); //karil set
- prices.put(4512, 74); //ahrim set
- prices.put(4510, 60); //karil set
- prices.put(18782, 5); //ahrim set
- }
- if (currency == TOKKUL_ID) {
- prices.put(11978, 300000); //ahrim set
- prices.put(438, 300); //karil set
- prices.put(436, 300); //ahrim set
- prices.put(440, 600); //karil set
- prices.put(453, 1000); //ahrim set
- prices.put(442, 1500); //karil set
- prices.put(444, 1500); //ahrim set
- prices.put(447, 2000); //ahrim set
- prices.put(449, 2250); //karil set
- prices.put(451, 2500); //ahrim set
- prices.put(1623, 150); //karil set
- prices.put(1621, 200); //ahrim set
- prices.put(1619, 300); //karil set
- prices.put(1617, 600); //ahrim set
- prices.put(1631, 2000); //karil set
- prices.put(6571, 4500); //ahrim set
- prices.put(11128, 10000); //karil set
- prices.put(6524, 10000); //ahrim set
- prices.put(6523, 10000); //karil set
- prices.put(6526, 10000); //ahrim set
- prices.put(6522, 100); //karil set
- prices.put(6528, 20000); //ahrim set
- prices.put(6568, 20000); //karil set
- }
- }
- @Override
- public void sellToShop(Player player, Item item) {
- if (getCurrency() != COINS_ID) {
- player.sendMessage("You can't sell to this shop.");
- return;
- }
- int normalId = item.getNormalId();
- int sellPrice = calculateUnitSellPrice(new Item(normalId));
- long payment = (long) sellPrice * (long) item.getCount();
- if (payment > Integer.MAX_VALUE) {
- item.setAmount(Integer.MAX_VALUE / sellPrice);
- payment = (long) sellPrice * (long) item.getCount();
- }
- if (payment > 0) {
- player.getInventory().delete(item.getId(), item.getAmount());
- addGeneralShop(new Item(normalId, item.getAmount()), getStaticCount());
- player.getInventory().add(currency, (int) payment, "Sell to shop " + item.getId());
- }
- player.getPacketSender().sendItemContainer(player.getInventory(), 3823);
- update();
- }
- @Override
- public void buyFromShop(Player player, Item item) {
- long price = (long) calculateUnitBuyPrice(item) * (long) item.getCount();
- int currencyInInventory = player.getInventory().getAmount(currency);
- long coinsInPouch = player.getMoneyInPouch();
- boolean usePouch = false;
- if(currencyInInventory >= price) {
- } else if(coinsInPouch >= price && currency == COINS_ID) {
- usePouch = true;
- } else {
- item.setAmount((int) (currencyInInventory / calculateUnitBuyPrice(item)));
- price = (long) calculateUnitBuyPrice(item) * (long) item.getCount();
- }
- long available = usePouch ? coinsInPouch : currencyInInventory;
- if (available >= price) {
- if (price < calculateUnitBuyPrice(item) * item.getCount()) {
- return;
- }
- boolean showWarning = currency != COINS_ID && item.getAmount() == 1;
- if(currency == COINS_ID && price > 1_000_000) {
- showWarning = true;
- }
- if(item.getAmount() == 1 && showWarning) {
- final CurrencyShop shop = this;
- long finalPrice = price;
- boolean finalUsePouch = usePouch;
- DialogueManager.start(player, new Dialogue() {
- @Override
- public DialogueType type() {
- return DialogueType.ITEM_STATEMENT;
- }
- @Override
- public String[] item() {
- return new String[] {
- ""+item.getId()+"",
- "180",
- ""+item.getDefinition().getName()+""
- };
- }
- @Override
- public boolean closeInterface() {
- return false;
- }
- @Override
- public String[] dialogue() {
- return new String[] { "Are you sure you want to buy "+item.getAmount()+"x of this item?",
- "Price: "+Misc.formatNumber(finalPrice)+" "+ItemDefinition.forId(currency).getName()};
- }
- @Override
- public Dialogue nextDialogue() {
- return new Dialogue() {
- @Override
- public DialogueType type() {
- return DialogueType.OPTION;
- }
- @Override
- public DialogueExpression animation() {
- return null;
- }
- @Override
- public String[] dialogue() {
- return new String[] { "Yes, purchase item.",
- "No, cancel."};
- }
- @Override
- public boolean closeInterface() {
- return false;
- }
- @Override
- public boolean action(int option) {
- switch(option) {
- case 1:
- shop.buyItem(player, item, finalPrice, finalUsePouch);
- player.getPacketSender().closeDialogueOnly();
- break;
- case 2:
- player.getPacketSender().closeDialogueOnly();
- break;
- }
- return true;
- }
- };
- }
- });
- } else {
- buyItem(player, item, price, usePouch);
- }
- } else {
- if (currency == Items.COINS_1) {
- player.sendMessage("You don't have enough in your pouch to buy this item.");
- } else {
- player.sendMessage("You don't have enough " + ItemDefinition.forId(currency).getName() + " to buy this item.");
- }
- }
- }
- public void buyItem(Player player, Item item, long price, boolean usePouch) {
- int amountCanBuy = this.getCount(item.getId());
- if(item.getAmount() > amountCanBuy && this.isGeneral() && !this.isStaticItem(item.getNormalId())) {
- item.setAmount(amountCanBuy);
- price = (long) amountCanBuy * (long) calculateUnitBuyPrice(item);
- }
- if(this.isGeneral() && !this.isStaticItem(item.getNormalId())) {
- if (!this.contains(item)) {
- player.sendMessage("This shop doesn't seem to carry this anymore.");
- return;
- }
- } else {
- if (!this.contains(item.getId())) {
- player.sendMessage("This shop doesn't seem to carry this anymore.");
- return;
- }
- }
- if (player.getInventory().getAmount(item.getId()) + item.getCount() > Integer.MAX_VALUE || player.getInventory().getAmount(item.getId()) + item.getCount() < 0) {
- player.sendMessage("You already have max amount of this item in your inventory.");
- return;
- }
- if (price < 0 || price > Long.MAX_VALUE) {
- player.sendMessage("You can't afford that");
- player.getLogging().log("DUPE: " + getName() + " tried to buy " + ItemDefinition.forId(item.getId()).getName() + " x " + item.getAmount() + " FOR " + price + " " + ItemDefinition.forId(currency).getName() + ".");
- return;
- }
- long coinsInPouch = player.getMoneyInPouch();
- int currencyAmount = player.getInventory().getAmount(currency);
- if(usePouch) {
- if(coinsInPouch >= price) {
- player.setMoneyInPouch(player.getMoneyInPouch() - price);
- player.getPacketSender().sendString(8135, "" + player.getMoneyInPouch() + "");
- } else {
- player.sendMessage("Error buying this amount - please report to an admin");
- return;
- }
- } else {
- if(player.getInventory().contains(new Item(getCurrency(), (int)price))) {
- player.getInventory().delete(getCurrency(), (int) price);
- } else {
- player.sendMessage("Error buying this amount - please report to an admin");
- return;
- }
- }
- if (this.isGeneral() && !this.isStaticItem(item.getNormalId())) {
- this.remove(item);
- }
- player.getInventory().add(item.getId(), item.getAmount(), "Buy from currency shop");
- player.getPacketSender().sendItemContainer(player.getInventory(), 3823);
- player.getLogging().log("Bought: " + item.getId() + " x " + item.getAmount() + " from " + getName() + " for " + price + " " + ItemDefinition.forId(currency).getName() + ".");
- update();
- }
- @Override
- public void valueSellItem(Player player, Item item) {
- if (getCurrency() != COINS_ID) {
- player.sendMessage("You can't sell to this shop.");
- return;
- }
- int price = calculateUnitSellPrice(item);
- player.sendMessage("The shop will buy a " + item.getDefinition().getName() + " for @dre@" + Misc.insertCommasToNumber(Integer.toString(price)) + "</col> " + ItemDefinition.forId(currency).getName() + ".");
- }
- /**
- * The sell price per unit.
- *
- * @param item
- * @return
- */
- public int calculateUnitSellPrice(Item item) {
- int price = -1;
- if (currency == Shop.COINS_ID) {
- if (getById(item.getId()) != null && getPrices().get(item.getId()) != null) {
- price = (int) (getPrices().get(item.getId()) * 0.9);
- } else {
- price = (int) (item.getDefinition().getValue() * 0.9);
- }
- } else {
- price = (int) (getSpecialPrice(item.getId()) * 0.9);
- }
- return Math.max(1, price);
- }
- public int calculateUnitBuyPrice(Item item) {
- int price = -1;
- if (currency == Shop.COINS_ID) {
- if (prices.get(item.getId()) != null) {
- price = prices.get(item.getId());
- } else {
- price = item.getDefinition().getValue();
- }
- } else {
- price = getSpecialPrice(item.getId());
- }
- return Math.max(1, price);
- }
- private int getSpecialPrice(int itemId) {
- int price = 1;
- if (prices.containsKey(itemId)) {
- price = prices.get(itemId);
- }
- price = currency == Shop.TOKKUL_ID && price == 1 ? 10000 : price;
- return price;
- }
- @Override
- public void process() {
- update();
- }
- @Override
- public int getPrice(int itemId) {
- int price = -1;
- if (currency == Shop.COINS_ID) {
- if (prices.get(itemId) != null) {
- price = prices.get(itemId);
- } else {
- price = ItemDefinition.forId(itemId).getValue();
- }
- } else {
- price = getSpecialPrice(itemId);
- }
- return Math.max(1, price);
- }
- public int getStaticCount() {
- int count = 0;
- for (Item item : this.getStaticItems()) {
- if (item != null)
- count++;
- }
- return count;
- }
- @Override
- public void valueBuyItem(Player player, Item item) {
- int price = calculateUnitBuyPrice(item);
- if (price == 0) {
- price = 1;
- }
- player.sendMessage("The shop will sell a " + item.getDefinition().getName() + " for @dre@" + Misc.insertCommasToNumber(Integer.toString(price)) + "</col> " + ItemDefinition.forId(currency).getName() + ".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement