2013-01-30 17:53:51 +01:00
|
|
|
package com.gmail.nossr50.skills.runnables;
|
2012-03-14 07:10:16 +01:00
|
|
|
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2012-03-14 07:10:16 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
public class CombatXpGiver implements Runnable {
|
|
|
|
private McMMOPlayer mcMMOPlayer;
|
2013-01-26 23:01:55 +01:00
|
|
|
private double baseXp;
|
|
|
|
private SkillType skillType;
|
|
|
|
private LivingEntity target;
|
|
|
|
private int baseHealth;
|
2012-03-14 07:10:16 +01:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
public CombatXpGiver(McMMOPlayer mcMMOPlayer, SkillType skillType, double baseXp, LivingEntity target) {
|
|
|
|
this.mcMMOPlayer = mcMMOPlayer;
|
2012-03-14 07:10:16 +01:00
|
|
|
this.skillType = skillType;
|
|
|
|
this.baseXp = baseXp;
|
|
|
|
this.target = target;
|
|
|
|
baseHealth = target.getHealth();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
int health = target.getHealth();
|
2012-06-06 01:19:39 +02:00
|
|
|
int damage = baseHealth - health;
|
2012-03-14 07:10:16 +01:00
|
|
|
|
|
|
|
//May avoid negative xp, we don't know what other plugins do with the entity health
|
|
|
|
if (damage <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Don't reward the player for overkills
|
|
|
|
if (health < 0) {
|
|
|
|
damage += health;
|
|
|
|
}
|
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
mcMMOPlayer.addXp(skillType, (int) (damage * baseXp));
|
2012-03-14 07:10:16 +01:00
|
|
|
}
|
|
|
|
}
|