Add new ExperienceAPI method to specify if XP can be shared

This commit is contained in:
TfT_02
2014-08-22 11:49:16 -07:00
parent 087a0b079f
commit b61c65636b
2 changed files with 71 additions and 0 deletions

View File

@ -86,6 +86,29 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason) {
addRawXP(player, skillType, XP, xpGainReason, false);
}
/**
* Adds raw XP to the player.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addRawXP(Player player, String skillType, float XP, String xpGainReason, boolean isUnshared) {
if (isUnshared) {
UserManager.getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
return;
}
UserManager.getPlayer(player).applyXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
}
@ -218,8 +241,31 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason) {
addModifiedXP(player, skillType, XP, xpGainReason, false);
}
/**
* Adds XP to the player, calculates for XP Rate and skill modifier.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addModifiedXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
SkillType skill = getSkillType(skillType);
if (isUnshared) {
UserManager.getPlayer(player).beginUnsharedXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
return;
}
UserManager.getPlayer(player).applyXpGain(skill, (int) (XP / skill.getXpModifier() * ExperienceConfig.getInstance().getExperienceGainsGlobalMultiplier()), getXPGainReason(xpGainReason));
}
@ -274,6 +320,30 @@ public final class ExperienceAPI {
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addXP(Player player, String skillType, int XP, String xpGainReason) {
addXP(player, skillType, XP, xpGainReason, false);
}
/**
* Adds XP to the player, calculates for XP Rate, skill modifiers, perks, child skills,
* and party sharing.
* </br>
* This function is designed for API usage.
*
* @param player The player to add XP to
* @param skillType The skill to add XP to
* @param XP The amount of XP to add
* @param xpGainReason The reason to gain XP
* @param isUnshared true if the XP cannot be shared with party members
*
* @throws InvalidSkillException if the given skill is not valid
* @throws InvalidXPGainReasonException if the given xpGainReason is not valid
*/
public static void addXP(Player player, String skillType, int XP, String xpGainReason, boolean isUnshared) {
if (isUnshared) {
UserManager.getPlayer(player).beginUnsharedXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
return;
}
UserManager.getPlayer(player).beginXpGain(getSkillType(skillType), XP, getXPGainReason(xpGainReason));
}