667/718 making a shop use an internally stored currency
Hey everyone, so, basically I've declared the Loyalty point int insidde of the player.java, everything in terms of accumulating the points works fine, But I seem to be struggling to get the shop to accept the currency rather than GP, I've used 3 seperate methods for it, similar to the way the dung token and vote points are handled.
The three methods I declared in Shop.java are:
[SPOIL] public void buyLoyalty(Player player, int clickSlot, int quantity) {
int slotId = getSlotId(clickSlot);
if (slotId >= getStoreSize())
return;
Item item = slotId >= mainStock.length ? generalStock[slotId
- mainStock.length] : mainStock[slotId];
if (item == null)
return;
if (item.getAmount() == 0) {
player.getPackets().sendGameMessage(
"There is no stock of that item at the moment.");
return;
}
int dq = slotId >= mainStock.length ? 0 : defaultQuantity[slotId];
int price = getLoyaltyPrice(item, dq);
int amountCoins = player.Loyaltypoints;
int maxQuantity = amountCoins / price;
int buyQ = item.getAmount() > quantity ? quantity : item.getAmount();
boolean enoughCoins = maxQuantity >= buyQ;
if (!enoughCoins) {
player.getPackets().sendGameMessage("You don't have enough points, you have "+player.Loyaltypoints+" points.");
buyQ = maxQuantity;
} else if (quantity > buyQ)
player.getPackets().sendGameMessage(
"The shop has run out of stock.");
if (item.getDefinitions().isStackable()) {
if (player.getInventory().getFreeSlots() < 1) {
player.getPackets().sendGameMessage(
"Not enough space in your inventory.");
return;
}
} else {
int freeSlots = player.getInventory().getFreeSlots();
if (buyQ > freeSlots) {
buyQ = freeSlots;
player.getPackets().sendGameMessage(
"Not enough space in your inventory.");
}
}
if (buyQ != 0) {
int totalPrice = price * buyQ;
player.Loyaltypoints -= totalPrice;
player.getInventory().addItem(item.getId(), buyQ);
refreshShop();
sendInventory(player);
}
}[/SPOIL]
[SPOIL] public void sendLoyaltyInfo(Player player, int clickSlot) {
int slotId = getSlotId(clickSlot);
if (slotId >= getStoreSize())
return;
Item item = slotId >= mainStock.length ? generalStock[slotId
- mainStock.length] : mainStock[slotId];
if (item == null)
return;
player.getTemporaryAttributtes().put("ShopSelected Slot", clickSlot);
int dq = slotId >= mainStock.length ? 0 : defaultQuantity[slotId];
int price = getLoyaltyPrice(item, dq);
player.getPackets().sendGameMessage(
item.getDefinitions().getName()
+ ": current costs "
+ price
+ " Loyalty Points.");
player.getInterfaceManager().sendInventoryInterfac e(449);
player.getPackets().sendGlobalConfig(741, item.getId());
player.getPackets().sendGlobalConfig(743, money);
player.getPackets().sendUnlockIComponentOptionSlot s(449, 15, -1, 0, 0,
1, 2, 3, 4); // unlocks buy
player.getPackets().sendGlobalConfig(744, price);
player.getPackets().sendGlobalConfig(745, 0);
player.getPackets().sendGlobalConfig(746, -1);
player.getPackets().sendGlobalConfig(168, 98);
player.getPackets().sendGlobalString(25, ItemExamines.getExamine(item));
player.getPackets().sendGlobalString(34, ""); // quest id for some items
int[] bonuses = ItemBonuses.getItemBonuses(item.getId());
if (bonuses != null) {
HashMap<Integer, Integer> requiriments = item.getDefinitions()
.getWearingSkillRequiriments();
if (requiriments != null && !requiriments.isEmpty()) {
String reqsText = "";
for (int skillId : requiriments.keySet()) {
if (skillId > 24 || skillId < 0)
continue;
int level = requiriments.get(skillId);
if (level < 0 || level > 120)
continue;
boolean hasReq = player.getSkills().getLevelForXp(skillId) >= level;
reqsText += "<br>"
+ (hasReq ? "<col=00ff00>" : "<col=ff0000>")
+ "Level " + level + " "
+ Skills.SKILL_NAME[skillId];
}
player.getPackets().sendGlobalString(26,
"<br>Worn on yourself, requiring: " + reqsText);
} else
player.getPackets()
.sendGlobalString(26, "<br>Worn on yourself");
player.getPackets().sendGlobalString(
35,
"<br>Attack<br><col=ffff00>+"
+ bonuses[CombatDefinitions.STAB_ATTACK]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.SLASH_ATTACK]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.CRUSH_ATTACK]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.MAGIC_ATTACK]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.RANGE_ATTACK]
+ "<br><col=ffff00>---" + "<br>Strength"
+ "<br>Ranged Strength" + "<br>Magic Damage"
+ "<br>Absorve Melee" + "<br>Absorve Magic"
+ "<br>Absorve Ranged" + "<br>Prayer Bonus");
player.getPackets()
.sendGlobalString(36,
"<br><br>Stab<br>Slash<br>Crush<br>Magic<br>Ranged <br>Summoning");
player.getPackets().sendGlobalString(
52,
"<<br>Defence<br><col=ffff00>+"
+ bonuses[CombatDefinitions.STAB_DEF]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.SLASH_DEF]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.CRUSH_DEF]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.MAGIC_DEF]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.RANGE_DEF]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.SUMMONING_DEF]
+ "<br><col=ffff00>+"
+ bonuses[CombatDefinitions.STRENGTH_BONUS]
+ "<br><col=ffff00>"
+ bonuses[CombatDefinitions.RANGED_STR_BONUS]
+ "<br><col=ffff00>"
+ bonuses[CombatDefinitions.MAGIC_DAMAGE]
+ "%<br><col=ffff00>"
+ bonuses[CombatDefinitions.ABSORVE_MELEE_BONUS]
+ "%<br><col=ffff00>"
+ bonuses[CombatDefinitions.ABSORVE_MAGE_BONUS]
+ "%<br><col=ffff00>"
+ bonuses[CombatDefinitions.ABSORVE_RANGE_BONUS]
+ "%<br><col=ffff00>"
+ bonuses[CombatDefinitions.PRAYER_BONUS]);
} else
player.getPackets().sendGlobalString(26, "");
}[/SPOIL]
[SPOIL] public int getLoyaltyPrice(Item item, int dq) {
switch(item.getId()) {
/*Chaotic*/
case 18349:
return 20000;
case 18351:
return 20000;
case 18353:
return 20000;
case 18355:
return 20000;
case 18357:
return 20000;
case 18359:
return 20000;
case 18361:
return 20000;
case 18363:
return 20000;
/*Chaotic*/
/*Nex Sets*/
case 20135:
return 50000;
case 20139:
return 50000;
case 20143:
return 50000;
case 20147:
return 50000;
case 20151:
return 50000;
case 20155:
return 50000;
case 20159:
return 50000;
case 20163:
return 50000;
case 20167:
return 50000;
}
return -1;
}[/SPOIL]
Any help in regards to this would be appreciated, and I would like to thank you for taking your time to read this.
EDIT: Checked NPCHandler.java for where the vote point and toks methods are used, only saw the sm line showing how many points/tokens they have, andyone have any idea of where the NPC ID is assigned the points as the main currency?