2013-01-30 15:17:50 +01:00
|
|
|
package com.gmail.nossr50.party;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-02-02 05:00:39 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2013-01-30 15:17:50 +01:00
|
|
|
import com.gmail.nossr50.util.Users;
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
public final class ShareHandler {
|
|
|
|
public enum XpShareMode {
|
|
|
|
NONE,
|
|
|
|
EQUAL;
|
|
|
|
|
|
|
|
public static XpShareMode getFromString(String string) {
|
|
|
|
try {
|
|
|
|
return valueOf(string);
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException exception) {
|
|
|
|
return NONE;
|
2013-02-01 13:57:00 +01:00
|
|
|
}
|
|
|
|
catch (NullPointerException exception) {
|
|
|
|
return NONE;
|
2013-02-01 06:38:25 +01:00
|
|
|
}
|
2013-01-30 15:17:50 +01:00
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
};
|
2013-01-30 17:25:44 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
private ShareHandler() {}
|
2013-01-30 15:17:50 +01:00
|
|
|
|
|
|
|
/**
|
2013-02-02 05:00:39 +01:00
|
|
|
* Distribute Xp amongst party members.
|
2013-01-30 15:17:50 +01:00
|
|
|
*
|
2013-02-02 05:00:39 +01:00
|
|
|
* @param xp Xp without party sharing
|
|
|
|
* @param mcMMOPlayer Player initiating the Xp gain
|
|
|
|
* @param skillType Skill being used
|
2013-02-02 05:06:47 +01:00
|
|
|
* @return True is the xp has been shared
|
2013-01-30 15:17:50 +01:00
|
|
|
*/
|
2013-02-03 12:45:19 +01:00
|
|
|
public static boolean handleXpShare(int xp, McMMOPlayer mcMMOPlayer, SkillType skillType) {
|
2013-02-02 05:00:39 +01:00
|
|
|
Party party = mcMMOPlayer.getParty();
|
2013-02-01 06:38:25 +01:00
|
|
|
|
2013-02-03 05:25:02 +01:00
|
|
|
switch (party.getXpShareMode()) {
|
|
|
|
case EQUAL:
|
2013-02-02 05:00:39 +01:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2013-02-01 06:38:25 +01:00
|
|
|
List<Player> nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange());
|
2013-01-30 15:17:50 +01:00
|
|
|
|
2013-02-02 04:42:24 +01:00
|
|
|
if (nearMembers.isEmpty()) {
|
2013-02-02 05:06:47 +01:00
|
|
|
return false;
|
2013-02-01 06:38:25 +01:00
|
|
|
}
|
2013-01-30 15:17:50 +01:00
|
|
|
|
2013-02-02 04:33:26 +01:00
|
|
|
double partySize = nearMembers.size() + 1;
|
2013-02-04 17:20:45 +01:00
|
|
|
double shareBonus = Config.getInstance().getPartyShareBonusBase() + partySize * Config.getInstance().getPartyShareBonusIncrease();
|
|
|
|
if (shareBonus > Config.getInstance().getPartyShareBonusCap()) {
|
|
|
|
shareBonus = Config.getInstance().getPartyShareBonusCap();
|
|
|
|
}
|
|
|
|
double splitXp = xp / partySize * shareBonus;
|
2013-02-02 05:00:39 +01:00
|
|
|
int roundedXp = (int) Math.ceil(splitXp);
|
2013-02-02 04:33:26 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
for (Player member : nearMembers) {
|
2013-02-03 12:45:19 +01:00
|
|
|
Users.getPlayer(member).beginUnsharedXpGain(skillType, roundedXp);
|
2013-01-30 15:17:50 +01:00
|
|
|
}
|
2013-02-02 05:00:39 +01:00
|
|
|
|
2013-02-03 12:45:19 +01:00
|
|
|
mcMMOPlayer.beginUnsharedXpGain(skillType, roundedXp);
|
2013-02-01 06:38:25 +01:00
|
|
|
|
2013-02-03 05:25:02 +01:00
|
|
|
return true;
|
|
|
|
case NONE:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
}
|
2013-02-03 12:45:19 +01:00
|
|
|
}
|
2013-02-01 06:38:25 +01:00
|
|
|
|