mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
Fix for combat XP gain
This commit is contained in:
parent
c3e1cf8681
commit
7c3b6b9fb3
@ -59,12 +59,7 @@ public class Combat {
|
|||||||
applyAbilityAoE(attacker, target, damage, pluginx, SkillType.SWORDS);
|
applyAbilityAoE(attacker, target, damage, pluginx, SkillType.SWORDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetType.equals(EntityType.PLAYER)) {
|
startGainXp(attacker, PPa, target, SkillType.SWORDS, pluginx);
|
||||||
PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS);
|
|
||||||
}
|
|
||||||
else if (!pluginx.misc.mobSpawnerList.contains(target.getEntityId())){
|
|
||||||
PvEExperienceGain(attacker, PPa, target, damage, SkillType.SWORDS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (ItemChecks.isAxe(itemInHand) && mcPermissions.getInstance().axes(attacker)) {
|
else if (ItemChecks.isAxe(itemInHand) && mcPermissions.getInstance().axes(attacker)) {
|
||||||
Axes.axesBonus(attacker, event);
|
Axes.axesBonus(attacker, event);
|
||||||
@ -75,12 +70,7 @@ public class Combat {
|
|||||||
applyAbilityAoE(attacker, target, damage, pluginx, SkillType.AXES);
|
applyAbilityAoE(attacker, target, damage, pluginx, SkillType.AXES);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetType.equals(EntityType.PLAYER)) {
|
startGainXp(attacker, PPa, target, SkillType.AXES, pluginx);
|
||||||
PvPExperienceGain(attacker, PPa, (Player) target, event.getDamage(), SkillType.AXES); //use getDamage because damage is modified in earlier functions
|
|
||||||
}
|
|
||||||
else if (!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) {
|
|
||||||
PvEExperienceGain(attacker, PPa, target, event.getDamage(), SkillType.AXES); //use getDamage because damage is modified in earlier functions
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (itemInHand.getType().equals(Material.AIR) && mcPermissions.getInstance().unarmed(attacker)) {
|
else if (itemInHand.getType().equals(Material.AIR) && mcPermissions.getInstance().unarmed(attacker)) {
|
||||||
Unarmed.unarmedBonus(attacker, event);
|
Unarmed.unarmedBonus(attacker, event);
|
||||||
@ -91,11 +81,9 @@ public class Combat {
|
|||||||
|
|
||||||
if (targetType.equals(EntityType.PLAYER)) {
|
if (targetType.equals(EntityType.PLAYER)) {
|
||||||
Unarmed.disarmProcCheck(attacker, (Player) target);
|
Unarmed.disarmProcCheck(attacker, (Player) target);
|
||||||
PvPExperienceGain(attacker, PPa, (Player) target, event.getDamage(), SkillType.UNARMED); //use getDamage because damage is modified in earlier functions
|
|
||||||
}
|
|
||||||
else if (!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) {
|
|
||||||
PvEExperienceGain(attacker, PPa, target, event.getDamage(), SkillType.UNARMED); //use getDamage because damage is modified in earlier functions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startGainXp(attacker, PPa, target, SkillType.UNARMED, pluginx);
|
||||||
}
|
}
|
||||||
else if (itemInHand.getType().equals(Material.BONE) && mcPermissions.getInstance().taming(attacker) && targetType.equals(EntityType.WOLF)) {
|
else if (itemInHand.getType().equals(Material.BONE) && mcPermissions.getInstance().taming(attacker) && targetType.equals(EntityType.WOLF)) {
|
||||||
Wolf wolf = (Wolf) target;
|
Wolf wolf = (Wolf) target;
|
||||||
@ -126,7 +114,8 @@ public class Combat {
|
|||||||
Taming.fastFoodService(PPo, wolf, event);
|
Taming.fastFoodService(PPo, wolf, event);
|
||||||
Taming.sharpenedClaws(PPo, event);
|
Taming.sharpenedClaws(PPo, event);
|
||||||
Taming.gore(PPo, event, master, pluginx);
|
Taming.gore(PPo, event, master, pluginx);
|
||||||
Taming.rewardXp(event, pluginx, master);
|
|
||||||
|
startGainXp(master, PPo, target, SkillType.TAMING, pluginx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -173,10 +162,10 @@ public class Combat {
|
|||||||
public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) {
|
public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) {
|
||||||
Arrow arrow = (Arrow) event.getDamager();
|
Arrow arrow = (Arrow) event.getDamager();
|
||||||
LivingEntity shooter = arrow.getShooter();
|
LivingEntity shooter = arrow.getShooter();
|
||||||
Entity entity = event.getEntity();
|
LivingEntity target = (LivingEntity) event.getEntity();
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (target instanceof Player) {
|
||||||
Player defender = (Player) entity;
|
Player defender = (Player) target;
|
||||||
PlayerProfile PPd = Users.getProfile(defender);
|
PlayerProfile PPd = Users.getProfile(defender);
|
||||||
boolean deflect = false;
|
boolean deflect = false;
|
||||||
|
|
||||||
@ -202,16 +191,13 @@ public class Combat {
|
|||||||
int damage = event.getDamage();
|
int damage = event.getDamage();
|
||||||
|
|
||||||
if (mcPermissions.getInstance().archery(attacker) && damage > 0) {
|
if (mcPermissions.getInstance().archery(attacker) && damage > 0) {
|
||||||
Archery.trackArrows(pluginx, entity, PPa);
|
Archery.trackArrows(pluginx, target, PPa);
|
||||||
Archery.ignitionCheck(entity, attacker);
|
Archery.ignitionCheck(target, attacker);
|
||||||
|
|
||||||
if (!pluginx.misc.mobSpawnerList.contains(entity.getEntityId())) {
|
startGainXp(attacker, PPa, target, SkillType.ARCHERY, pluginx);
|
||||||
int xp = getXp((LivingEntity) entity, damage);
|
|
||||||
PPa.addXP(SkillType.ARCHERY, xp*10, attacker);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entity instanceof Player) {
|
if (target instanceof Player) {
|
||||||
Player defender = (Player) entity;
|
Player defender = (Player) target;
|
||||||
PlayerProfile PPd = Users.getProfile(defender);
|
PlayerProfile PPd = Users.getProfile(defender);
|
||||||
|
|
||||||
if (PPa.inParty() && PPd.inParty() && Party.getInstance().inSameParty(defender, attacker)) {
|
if (PPa.inParty() && PPd.inParty() && Party.getInstance().inSameParty(defender, attacker)) {
|
||||||
@ -219,16 +205,9 @@ public class Combat {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LoadProperties.pvpxp && (((PPd.getLastLogin() + 5) * 1000) < System.currentTimeMillis()) && !attacker.getName().equals(defender.getName())) {
|
|
||||||
int xp = (damage * 2) * 10; //What's the 2 for? Should this be a multiplier from file instead?
|
|
||||||
PPa.addXP(SkillType.ARCHERY, xp, attacker);
|
|
||||||
}
|
|
||||||
|
|
||||||
Archery.dazeCheck(defender, attacker);
|
Archery.dazeCheck(defender, attacker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Skills.XpCheckSkill(SkillType.ARCHERY, attacker);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,149 +267,6 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Process PVP experience gain.
|
|
||||||
*
|
|
||||||
* @param attacker The attacking player
|
|
||||||
* @param PPa The profile of the attacking player
|
|
||||||
* @param defender The defending player
|
|
||||||
* @param damage The initial damage amount
|
|
||||||
* @param skillType The skill being used
|
|
||||||
*/
|
|
||||||
private static void PvPExperienceGain(Player attacker, PlayerProfile PPa, Player defender, int damage, SkillType skillType) {
|
|
||||||
if (!LoadProperties.pvpxp) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerProfile PPd = Users.getProfile(defender);
|
|
||||||
int health = defender.getHealth();
|
|
||||||
|
|
||||||
if ((System.currentTimeMillis() >= (PPd.getRespawnATS()*1000) + 5000) && (((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis()) && health >= 1) {
|
|
||||||
int xp = capXP(health, damage);
|
|
||||||
|
|
||||||
xp = (int) (xp * 2 * LoadProperties.pvpxprewardmodifier);
|
|
||||||
PPa.addXP(skillType, xp * 10, attacker);
|
|
||||||
Skills.XpCheckSkill(skillType, attacker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process PVE experience gain.
|
|
||||||
*
|
|
||||||
* @param attacker The attacking player
|
|
||||||
* @param PPa The profile of the attacking player
|
|
||||||
* @param target The defending entity
|
|
||||||
* @param damage The initial damage amount
|
|
||||||
* @param skillType The skill being used
|
|
||||||
*/
|
|
||||||
private static void PvEExperienceGain(Player attacker, PlayerProfile PPa, LivingEntity target, int damage, SkillType skillType) {
|
|
||||||
int xp = getXp(target, damage);
|
|
||||||
|
|
||||||
PPa.addXP(skillType, xp * 10, attacker);
|
|
||||||
Skills.XpCheckSkill(skillType, attacker);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cap the XP based on the remaining health of an entity.
|
|
||||||
*
|
|
||||||
* @param hpLeft Amount of HP remaining
|
|
||||||
* @param damage Amount of damage being dealt
|
|
||||||
* @return the modified XP amount
|
|
||||||
*/
|
|
||||||
private static int capXP(int hpLeft, int damage) {
|
|
||||||
int xp;
|
|
||||||
|
|
||||||
if (hpLeft < damage) {
|
|
||||||
if (hpLeft > 0) {
|
|
||||||
xp = hpLeft;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
xp = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
xp = damage;
|
|
||||||
}
|
|
||||||
|
|
||||||
return xp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the XP gained from damaging a non-player mob
|
|
||||||
*
|
|
||||||
* @param entity Entity being damaged
|
|
||||||
* @param damage Damage to be dealt to the mob
|
|
||||||
* @return XP gained
|
|
||||||
*/
|
|
||||||
public static int getXp(LivingEntity entity, int damage) {
|
|
||||||
int xp = capXP(entity.getHealth(), damage);
|
|
||||||
|
|
||||||
if (entity instanceof Animals) {
|
|
||||||
xp = (int) (xp * LoadProperties.animalXP);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
EntityType type = entity.getType();
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case BLAZE:
|
|
||||||
xp = (int) (xp * LoadProperties.blazeXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CAVE_SPIDER:
|
|
||||||
xp = (int) (xp * LoadProperties.cavespiderXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CREEPER:
|
|
||||||
xp = (int) (xp * LoadProperties.creeperXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ENDER_DRAGON:
|
|
||||||
xp = (int) (xp * LoadProperties.enderdragonXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ENDERMAN:
|
|
||||||
xp = (int) (xp * LoadProperties.endermanXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case GHAST:
|
|
||||||
xp = (int) (xp * LoadProperties.ghastXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case MAGMA_CUBE:
|
|
||||||
xp = (int) (xp * LoadProperties.magmacubeXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PIG_ZOMBIE:
|
|
||||||
xp = (int) (xp * LoadProperties.pigzombieXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SILVERFISH:
|
|
||||||
xp = (int) (xp * LoadProperties.silverfishXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SKELETON:
|
|
||||||
xp = (int) (xp * LoadProperties.skeletonXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SLIME:
|
|
||||||
xp = (int) (xp * LoadProperties.slimeXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SPIDER:
|
|
||||||
xp = (int) (xp * LoadProperties.spiderXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ZOMBIE:
|
|
||||||
xp = (int) (xp * LoadProperties.zombieXP);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return xp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply Area-of-Effect ability actions.
|
* Apply Area-of-Effect ability actions.
|
||||||
*
|
*
|
||||||
@ -532,4 +368,128 @@ public class Combat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the task that gives combat XP.
|
||||||
|
*
|
||||||
|
* @param attacker The attacking player
|
||||||
|
* @param PP The player's PlayerProfile
|
||||||
|
* @param target The defending entity
|
||||||
|
* @param skillType The skill being used
|
||||||
|
* @param plugin mcMMO plugin instance
|
||||||
|
*/
|
||||||
|
public static void startGainXp(Player attacker, PlayerProfile PP, LivingEntity target, SkillType skillType, mcMMO pluginx)
|
||||||
|
{
|
||||||
|
double baseXP = 0;
|
||||||
|
|
||||||
|
if (target instanceof Player) {
|
||||||
|
if (!LoadProperties.pvpxp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player defender = (Player) target;
|
||||||
|
PlayerProfile PPd = Users.getProfile(defender);
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() >= (PPd.getRespawnATS() * 1000) + 5000 &&
|
||||||
|
((PPd.getLastLogin() + 5) * 1000) < System.currentTimeMillis() &&
|
||||||
|
defender.getHealth() >= 1) {
|
||||||
|
baseXP = 20 * LoadProperties.pvpxprewardmodifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) {
|
||||||
|
if (target instanceof Animals) {
|
||||||
|
baseXP = 10 * LoadProperties.animalXP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EntityType type = target.getType();
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case BLAZE:
|
||||||
|
baseXP = LoadProperties.blazeXP;
|
||||||
|
break;
|
||||||
|
case CAVE_SPIDER:
|
||||||
|
baseXP = LoadProperties.cavespiderXP;
|
||||||
|
break;
|
||||||
|
case CREEPER:
|
||||||
|
baseXP = LoadProperties.creeperXP;
|
||||||
|
break;
|
||||||
|
case ENDER_DRAGON:
|
||||||
|
baseXP = LoadProperties.enderdragonXP;
|
||||||
|
break;
|
||||||
|
case ENDERMAN:
|
||||||
|
baseXP = LoadProperties.endermanXP;
|
||||||
|
break;
|
||||||
|
case GHAST:
|
||||||
|
baseXP = LoadProperties.ghastXP;
|
||||||
|
break;
|
||||||
|
case MAGMA_CUBE:
|
||||||
|
baseXP = LoadProperties.magmacubeXP;
|
||||||
|
break;
|
||||||
|
case PIG_ZOMBIE:
|
||||||
|
baseXP = LoadProperties.pigzombieXP;
|
||||||
|
break;
|
||||||
|
case SILVERFISH:
|
||||||
|
baseXP = LoadProperties.silverfishXP;
|
||||||
|
break;
|
||||||
|
case SKELETON:
|
||||||
|
baseXP = LoadProperties.skeletonXP;
|
||||||
|
break;
|
||||||
|
case SLIME:
|
||||||
|
baseXP = LoadProperties.slimeXP;
|
||||||
|
break;
|
||||||
|
case SPIDER:
|
||||||
|
baseXP = LoadProperties.spiderXP;
|
||||||
|
break;
|
||||||
|
case ZOMBIE:
|
||||||
|
baseXP = LoadProperties.zombieXP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
baseXP *= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseXP != 0)
|
||||||
|
Bukkit.getScheduler().scheduleSyncDelayedTask(pluginx, new GainXp(attacker, PP, skillType, baseXP, target), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class GainXp implements Runnable
|
||||||
|
{
|
||||||
|
private Player player = null;
|
||||||
|
private PlayerProfile PP = null;
|
||||||
|
private double baseXp = 0;
|
||||||
|
private SkillType skillType = null;
|
||||||
|
private LivingEntity target = null;
|
||||||
|
private int baseHealth = 0;
|
||||||
|
|
||||||
|
public GainXp(Player player, PlayerProfile PP, SkillType skillType, double baseXp, LivingEntity target)
|
||||||
|
{
|
||||||
|
this.player = player;
|
||||||
|
this.PP = PP;
|
||||||
|
this.skillType = skillType;
|
||||||
|
this.baseXp = baseXp;
|
||||||
|
this.target = target;
|
||||||
|
baseHealth = target.getHealth();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
int health = target.getHealth();
|
||||||
|
int damage = baseHealth - health;
|
||||||
|
|
||||||
|
//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;
|
||||||
|
|
||||||
|
PP.addXP(skillType, (int) (damage * baseXp), player);
|
||||||
|
Skills.XpCheckSkill(skillType, player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
|||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import com.gmail.nossr50.Combat;
|
|
||||||
import com.gmail.nossr50.Users;
|
import com.gmail.nossr50.Users;
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.config.LoadProperties;
|
import com.gmail.nossr50.config.LoadProperties;
|
||||||
@ -21,23 +20,6 @@ import com.gmail.nossr50.locale.mcLocale;
|
|||||||
|
|
||||||
public class Taming
|
public class Taming
|
||||||
{
|
{
|
||||||
public static void rewardXp(EntityDamageEvent event, mcMMO pluginx, Player master)
|
|
||||||
{
|
|
||||||
Entity entity = event.getEntity();
|
|
||||||
if(!pluginx.misc.mobSpawnerList.contains(entity.getEntityId()))
|
|
||||||
{
|
|
||||||
int xp = Combat.getXp((LivingEntity) entity, event.getDamage());
|
|
||||||
Users.getProfile(master).addXP(SkillType.TAMING, xp*10, master);
|
|
||||||
|
|
||||||
if(entity instanceof Player)
|
|
||||||
{
|
|
||||||
xp = (event.getDamage() * 2);
|
|
||||||
Users.getProfile(master).addXP(SkillType.TAMING, (int)((xp*10)*1.5), master);
|
|
||||||
}
|
|
||||||
Skills.XpCheckSkill(SkillType.TAMING, master);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void fastFoodService(PlayerProfile PPo, Wolf theWolf, EntityDamageEvent event)
|
public static void fastFoodService(PlayerProfile PPo, Wolf theWolf, EntityDamageEvent event)
|
||||||
{
|
{
|
||||||
int health = theWolf.getHealth();
|
int health = theWolf.getHealth();
|
||||||
|
Loading…
Reference in New Issue
Block a user