Code:
package com.osrsunity.game.items.exchanges;
import com.osrsunity.game.character.player.Player;
import com.osrsunity.game.character.player.content.dialogue.Dialogue;
import com.osrsunity.game.character.player.content.dialogue.Expression;
import com.osrsunity.game.character.player.content.dialogue.Type;
import com.osrsunity.game.items.ItemAssistant;
/**
* GodCape Exchange to bring the new godcapes in to the game.
*
* @author Durky
*
*/
public class GodcapeExchange {
public enum GodCapes {
Saradomin(2412, 21791, 13331, 13332, 21776, 21778),
Guthix(2413, 21793, 13335, 13336, 21784,21786),
Zamorak(2414, 21795, 13333, 13334, 21780, 21782);
private int regularCape;
private int imbuedRegularCape;
private int maxCape;
private int maxHood;
private int imbuedMaxCape;
private int imbuedMaxHood;
GodCapes(int regularCape, int imbuedRegularCape, int maxCape, int maxHood, int imbuedCape, int imbuedHood) {
this.regularCape = regularCape;
this.imbuedRegularCape = imbuedRegularCape;
this.maxCape = maxCape;
this.maxHood = maxHood;
this.imbuedMaxCape = imbuedCape;
this.imbuedMaxHood = imbuedHood;
}
// small static iteration hurts nothing, No point in a set with such a
// small use feature.
public static GodCapes forId(int cape, boolean lookForMax) {
for (GodCapes godcape : GodCapes.values()) {
if(lookForMax ? godcape.maxCape == cape: godcape.regularCape == cape)
return godcape;
}
return null;
}
}
private static int COST = 25_000_000; // cost of the upgrade.
/*
* Call me with item on NPC or how ever you want to handle it.
*/
public static void exchangeCape(Player player, int cape) {
boolean maxCape = false;
// look for regular first
GodCapes godcape = GodCapes.forId(cape, maxCape);
// if null look for max
if (godcape == null) {
maxCape = true;
godcape = GodCapes.forId(cape, maxCape);
}
// Yes we got a cape, so lets continue on.
if (godcape != null) {
if (player.getItems().playerHasItem(995, COST)) { //
// ALWAYS check to make sure the player has the item, when ever
// you write code.
// prevents dupes, and spamm clicks abuse.
if (player.getItems().playerHasItem(maxCape ? godcape.maxCape : godcape.regularCape, 1)) {
if (maxCape && !player.getItems().playerHasItem(godcape.maxHood, 1)) {
player.sendMessage("You need to have the max hood aswell to upgrade.");
return;
}
player.getItems().deleteItem(995, COST);
// Don't need to check for room when we are swapping items,
// Just delete first.
player.getItems().deleteItem(maxCape ? godcape.maxCape : godcape.regularCape, 1);
player.getItems().addItem(maxCape ? godcape.imbuedMaxCape : godcape.imbuedRegularCape, 1);
// tell the player
player.sendMessage("You exchange your " + ItemAssistant.getItemName(cape) + " for a "
+ ItemAssistant.getItemName((maxCape ? godcape.imbuedMaxCape : godcape.imbuedRegularCape))
+ "");
if (maxCape) {
// Don't forget about the hood!
player.getItems().deleteItem(godcape.maxHood, 1);
player.getItems().addItem(godcape.imbuedMaxHood, 1);
}
}
} else
// sorry this cost money
player.dialogue().start(new Dialogue() {
@Override
protected void start(Object... parameters) {
send(Type.NPC, 1603, Expression.CALM_TALK1, "To upgrade a god cape it cost 25m ");
}
});
} else {
// remind the player
player.dialogue().start(new Dialogue() {
@Override
protected void start(Object... parameters) {
send(Type.NPC, 1603, Expression.CALM_TALK1, "Please use a Saradomin, Guthix, or Zamorak ",
"max or regular cape on me to upgrade");
}
});
}
}
}
i'm not a professional developer, I'm a self taught programmer and if you have suggestions to any code i've written please post below.