Jump to content
Sign in to follow this  
Sakon

Experience rates system

Recommended Posts

[code]
package armadyl.model.content;

import java.util.HashMap;

/**
* Enumeration containing the experience rates for each mode which the player
* will choose from.
*
* @author Sakon
*/
public enum Rates {
ROOKIE(500, 9178), MEDIUM(200, 9179), HARD(50, 9180), EXTREME(10, 9181);

/**
* Experience rate the player will be choosing.
*/
private int rate;

/**
* The buttons in the dialogue.
*/
private int button;

/**
* Constructs the enumeration.
*
* [MENTION=75098]Para[/MENTION]m xp
* the experience rates the player can choose from.
*/
private Rates(int rate, int button) {
this.rate = rate;
this.button = button;
}

/**
* Gets the experience rates the players can choose from.
*
* [MENTION=184045]return[/MENTION] the experience.
*/
public int getRate() {
return rate;
}

/**
* Gets the button on the initialization dialogue
*
* [MENTION=184045]return[/MENTION] The button id
*/
public int getButton() {
return button;
}

/**
* Sets the experience rate.
*
* [MENTION=75098]Para[/MENTION]m xp
* the experience.
* [MENTION=184045]return[/MENTION]
*/
public int setRate(int rate) {
return this.rate = rate;
}

/**
* Constructs the hashmap.
*/
public static HashMap<Integer, Rates> type = new HashMap<Integer, Rates>();

/**
* Populates the hashmap.
*/
static {
for (final Rates b : values()) {
Rates.type.put(b.getButton(), b);
}
}

/**
* Gets the rates value for the button pressed
*
* [MENTION=75098]Para[/MENTION]m button
* The button id
*/
public static Rates forId(int button) {
return type.get(button);
}

}
[/code]

Add the getter and the setter in the player/client class.

[code]
/**
* Gets the experience rate.
*
* [MENTION=184045]return[/MENTION] the rate.
*/
public Rates getRates() {
return rate;
}
[/code]
[code]
/**
* Sets the experience rate for the player
*
* [MENTION=75098]Para[/MENTION]m rate
* The experience rate
*/
public void setRate(Rates rate) {
this.rate = rate;
}
[/code]

Also add these in that class.

[code]
/**
* Toggles the player's state of rate configuration
*/
public void toggleRateConfig() {
this.configuringRates = !configuringRates;
}

/**
* Checks if the player is configuring their exp rates
*
* [MENTION=184045]return[/MENTION]
* True if so, else false
*/
public boolean isConfiguringRates() {
return configuringRates;
}
[/code]

Playersave class

[code]
} else if (token.equals("exp-rate")) {
p.setRate(Rates.valueOf(token2));
[/code]

[code]
characterfile.write("exp-rate = ", 0, 11);
characterfile.write(p.getRates().toString(), 0, p
.getRates().toString().length());
characterfile.newLine();
[/code]

addSkillXp method

[code]
amount = (int) ((double) amount * 1.0D) * c.getRates().getRate();
[/code]

In your client class, wherever it calls out the addStarter method, put your dialogue there and call out the toggleRateConfig() method.

Dialogue, though you'll have to convert it to the way you handle it.

[code]
package armadyl.model.content.dialogue.impl;

import armadyl.model.content.dialogue.Dialogue;
import armadyl.model.npcs.NPC;
import armadyl.model.players.Client;

/**
* The experience dialogue.
*
* @author Sakon
*
*/
public class RateDialogue extends Dialogue {

/**
* Handles the dialogue for choosing the experience rates.
*/
[MENTION=15855]Over[/MENTION]ride
public void handleDialogue(Client player, NPC npc) throws Exception {
player.setDialogueHook(this);
player.setDialogueNpc(npc);

switch (getCurrentStage()) {
case 0:
sendOption4(player, "Rookie", "Medium", "Hard", "Extreme");
setOptionSets(2, 3, 4, 5);
setOptionDialogue(true);
break;
}
}

}

[/code]

Clicking buttons;

[code]
/* Check if the player is configuring their exp rates */
if (c.isConfiguringRates()) {
Rates rates = Rates.forId(actionButtonId);
if (rates != null) {
c.setRate(rates);
c.getPA().closeAllWindows();
c.toggleRateConfig();
c.sendMessage("You set your experience rate to: "
+ Misc.formatPlayerName(rates.toString()
.toLowerCase()));
}
}
[/code]

Share this post


Link to post
Share on other sites
Sign in to follow this  

×