mcMMO/src/main/java/com/gmail/nossr50/util/Hardcore.java

83 lines
3.0 KiB
Java
Raw Normal View History

package com.gmail.nossr50.util;
import org.bukkit.entity.Player;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile;
2013-01-16 15:08:45 +01:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillType;
2012-06-14 01:22:35 +02:00
public abstract class Hardcore {
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
public static void invokeStatPenalty(Player player) {
double hardcorePenalty = Config.getInstance().getHardcoreDeathStatPenaltyPercentage();
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
if (hardcorePenalty <= 0 || hardcorePenalty > 100) {
return;
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
PlayerProfile playerProfile = Users.getProfile(player);
int totalLost = 0;
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
for (SkillType skillType : SkillType.values()) {
if (skillType.equals(SkillType.ALL)) {
continue;
2012-06-14 01:22:35 +02:00
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
int playerSkillLevel = playerProfile.getSkillLevel(skillType);
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
//Should we really care about negative skill levels?
if (playerSkillLevel <= 0) {
continue;
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
int levelsLost = (int) (playerSkillLevel * (hardcorePenalty * 0.01D));
totalLost += levelsLost;
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
playerProfile.modifySkill(skillType, playerSkillLevel - levelsLost);
}
2012-06-05 15:57:10 +02:00
2013-01-16 15:08:45 +01:00
player.sendMessage(LocaleLoader.getString("Hardcore.Player.Loss", new Object[] {totalLost}));
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
public static void invokeVampirism(Player killer, Player victim) {
double vampirismLeech = Config.getInstance().getHardcoreVampirismStatLeechPercentage();
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
if (vampirismLeech <= 0 || vampirismLeech > 100) {
return;
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
PlayerProfile killerProfile = Users.getProfile(killer);
PlayerProfile victimProfile = Users.getProfile(victim);
int totalStolen = 0;
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
for (SkillType skillType : SkillType.values()) {
if (skillType.equals(SkillType.ALL)) {
2012-05-22 08:30:16 +02:00
continue;
2012-06-14 01:22:35 +02:00
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
int killerSkillLevel = killerProfile.getSkillLevel(skillType);
int victimSkillLevel = victimProfile.getSkillLevel(skillType);
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
//Should we really care about negative skill levels?
if (victimSkillLevel <= 0 || victimSkillLevel < killerSkillLevel / 2) {
continue;
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
int levelsStolen = (int) (victimSkillLevel * (vampirismLeech * 0.01D));
totalStolen += levelsStolen;
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
killerProfile.modifySkill(skillType, killerSkillLevel + levelsStolen);
victimProfile.modifySkill(skillType, victimSkillLevel - levelsStolen);
}
2012-06-05 15:57:10 +02:00
2012-06-14 01:22:35 +02:00
if (totalStolen > 0) {
2013-01-16 15:08:45 +01:00
killer.sendMessage(LocaleLoader.getString("Vampirism.Killer.Success", new Object[] {totalStolen, victim.getName()} ));
victim.sendMessage(LocaleLoader.getString("Vampirism.Victim.Success", new Object[] {killer.getName(), totalStolen} ));
2012-06-14 01:22:35 +02:00
}
else {
2013-01-16 15:08:45 +01:00
killer.sendMessage(LocaleLoader.getString("Vampirism.Killer.Failure", new Object[] {victim.getName()} ));
victim.sendMessage(LocaleLoader.getString("Vampirism.Victim.Failure", new Object[] {killer.getName()} ));
}
}
}