RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
TradingPostListing.java
1package com.osroyale.content.tradingpost;
2
3import com.osroyale.game.world.entity.mob.player.Player;
4import com.osroyale.net.packet.out.SendMessage;
5
37
38public class TradingPostListing {
39 private final int itemId;
40 private final String seller;
41 private int amountSold = 0;
42 private int price;
43 private int initialQuantity = 1;
44
45 public TradingPostListing(int itemId, String seller) {
46 this.itemId = itemId;
47 this.seller = seller;
48 }
49
50 public int getItemId() {
51 return itemId;
52 }
53
54 public int getInitialQuantity() {
55 return initialQuantity;
56 }
57
58 public void setQuantity(Player player, int quantity) {
59 this.initialQuantity = quantity;
60 if (this.initialQuantity == 0) {
61 this.initialQuantity = 1;
62 }
63 checkAndUpdate(player);
64 }
65
66 public int getPrice() {
67 return price;
68 }
69
70 public void setPrice(Player player, int price) {
71 if ((long) price * initialQuantity > Integer.MAX_VALUE) {
72 player.send(new SendMessage("Unable to set this price to this quantity. reason: above max integer value."));
73 return;
74 }
75 this.price = price;
76 player.tradingPost.updatePriceStrings();
77 }
78
79 public String getSeller() {
80 return seller;
81 }
82
83 public void removeQuantity(Player player, int amount) {
84 initialQuantity -= amount;
85 if (initialQuantity <= 0) {
86 initialQuantity = 1;
87 }
88 player.tradingPost.updateQuantityString();
89 player.tradingPost.updatePriceStrings();
90 }
91
92 public void addQuantity(Player player, int amount) {
93 initialQuantity += amount;
94 checkAndUpdate(player);
95 }
96
97 public void checkAndUpdate(Player player) {
98 int playerAmount = player.inventory.computeAmountForId(itemId);
99 if (initialQuantity > playerAmount) {
100 initialQuantity = playerAmount;
101 }
102 player.tradingPost.updateQuantityString();
103 player.tradingPost.updatePriceStrings();
104 }
105
106 public int getAmountLeft() {
107 return initialQuantity - amountSold;
108 }
109
110 public int getAmountSold() {
111 return amountSold;
112 }
113
114 public void addToAmountSold(int amountSold) {
115 this.amountSold += amountSold;
116 }
117
118 public void setAmountSold(int amountSold) {
119 this.amountSold = amountSold;
120 }
121
122 public void setPrice(int price) {
123 this.price = price;
124 }
125
126 public void setInitialQuantity(int initialQuantity) {
127 this.initialQuantity = initialQuantity;
128 }
129}