Merge pull request #184 from bm01/master

Optimization in combatChecks()
This commit is contained in:
nossr50 2012-02-26 04:07:58 -08:00
commit bf38fc9819
2 changed files with 403 additions and 429 deletions

View File

@ -1,18 +1,18 @@
/* /*
This file is part of mcMMO. This file is part of mcMMO.
mcMMO is free software: you can redistribute it and/or modify mcMMO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
mcMMO is distributed in the hope that it will be useful, mcMMO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mcMMO. If not, see <http://www.gnu.org/licenses/>. along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.gmail.nossr50; package com.gmail.nossr50;
@ -21,6 +21,7 @@ import org.bukkit.entity.*;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; 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.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.config.LoadProperties;
@ -46,200 +47,139 @@ public class Combat
if(event instanceof EntityDamageByEntityEvent) if(event instanceof EntityDamageByEntityEvent)
{ {
//Declare Things
EntityDamageByEntityEvent eEvent = (EntityDamageByEntityEvent) event;
Entity damager = eEvent.getDamager();
LivingEntity target = (LivingEntity) eEvent.getEntity();
int damage = eEvent.getDamage();
/* /*
* OFFENSIVE CHECKS FOR PLAYERS VERSUS ENTITIES * PLAYER VERSUS ENTITIES
*/ */
if(((EntityDamageByEntityEvent) event).getDamager() instanceof Player) if(damager instanceof Player)
{ {
//Declare Things Player attacker = (Player) eEvent.getDamager();
EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event; ItemStack itemInHand = attacker.getItemInHand();
Player attacker = (Player)((EntityDamageByEntityEvent) event).getDamager();
PlayerProfile PPa = Users.getProfile(attacker); PlayerProfile PPa = Users.getProfile(attacker);
//Damage modifiers
if(mcPermissions.getInstance().unarmed(attacker) && attacker.getItemInHand().getTypeId() == 0) //Unarmed
Unarmed.unarmedBonus(attacker, eventb);
if(m.isAxes(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker) && Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500)
{
int damage = event.getDamage()+4;
event.setDamage(damage);
}
//If there are any abilities to activate //If there are any abilities to activate
combatAbilityChecks(attacker, PPa, pluginx); combatAbilityChecks(attacker, PPa, pluginx);
//Check for offensive procs //Damage modifiers and proc checks
if(!(((EntityDamageByEntityEvent) event).getDamager() instanceof Arrow)) if(m.isSwords(itemInHand) && mcPermissions.getInstance().swords(attacker))
{
if(mcPermissions.getInstance().axes(attacker))
Axes.axeCriticalCheck(attacker, eventb, pluginx); //Axe Critical Checks
if(!pluginx.misc.bleedTracker.contains((LivingEntity) event.getEntity())) //Swords Bleed
Swords.bleedCheck(attacker, (LivingEntity)event.getEntity(), pluginx);
if(event.getEntity() instanceof Player && mcPermissions.getInstance().unarmed(attacker))
{
Player defender = (Player)event.getEntity();
Unarmed.disarmProcCheck(attacker, defender);
}
//Modify the event damage if Attacker is Berserk
if(PPa.getBerserkMode())
event.setDamage(event.getDamage() + (event.getDamage() / 2));
//Handle Ability Interactions
if(!(event instanceof FakeEntityDamageByEntityEvent)) {
if(PPa.getSkullSplitterMode() && m.isAxes(attacker.getItemInHand()))
Axes.applyAoeDamage(attacker, eventb, pluginx);
if(PPa.getSerratedStrikesMode() && m.isSwords(attacker.getItemInHand()))
Swords.applySerratedStrikes(attacker, eventb, pluginx);
}
//Experience
if(event.getEntity() instanceof Player)
{
Player defender = (Player)event.getEntity();
PlayerProfile PPd = Users.getProfile(defender);
if(attacker != null && defender != null && LoadProperties.pvpxp)
{
if(System.currentTimeMillis() >= (PPd.getRespawnATS()*1000) + 5000
&& ((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis()
&& defender.getHealth() >= 1)
{
//Prevent a ridiculous amount of XP being granted by capping it at the remaining health of the mob
int hpLeft = defender.getHealth(), xpinc = 0;
if(hpLeft < event.getDamage())
{
if(hpLeft > 0)
xpinc = hpLeft;
else
xpinc = 0;
} else
xpinc = event.getDamage();
int xp = (int) (xpinc * 2 * LoadProperties.pvpxprewardmodifier);
if(m.isAxes(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker))
PPa.addXP(SkillType.AXES, xp*10, attacker);
if(m.isSwords(attacker.getItemInHand()) && mcPermissions.getInstance().swords(attacker))
PPa.addXP(SkillType.SWORDS, xp*10, attacker);
if(attacker.getItemInHand().getTypeId() == 0 && mcPermissions.getInstance().unarmed(attacker))
PPa.addXP(SkillType.UNARMED, xp*10, attacker);
}
}
}
if(!pluginx.misc.mobSpawnerList.contains(event.getEntity().getEntityId()))
{
int xp = getXp(event.getEntity(), event);
if(m.isSwords(attacker.getItemInHand()) && mcPermissions.getInstance().swords(attacker))
PPa.addXP(SkillType.SWORDS, xp*10, attacker);
else if(m.isAxes(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker))
PPa.addXP(SkillType.AXES, xp*10, attacker);
else if(attacker.getItemInHand().getTypeId() == 0 && mcPermissions.getInstance().unarmed(attacker))
PPa.addXP(SkillType.UNARMED, xp*10, attacker);
}
Skills.XpCheckAll(attacker);
if(event.getEntity() instanceof Wolf)
{
Wolf theWolf = (Wolf)event.getEntity();
if(attacker.getItemInHand().getTypeId() == 352 && mcPermissions.getInstance().taming(attacker))
{
event.setCancelled(true);
if(theWolf.isTamed())
{
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(theWolf)})+" "+
mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {theWolf.getHealth()}));
}
else
{
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {theWolf.getHealth()}));
}
}
}
}
}
}
/*
* TAMING (WOLVES VERSUS ENTITIES)
*/
if(event instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) event).getDamager() instanceof Wolf)
{
EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event;
Wolf theWolf = (Wolf) eventb.getDamager();
if(theWolf.isTamed() && Taming.ownerOnline(theWolf, pluginx))
{
if(Taming.getOwner(theWolf, pluginx) == null)
return;
Player master = Taming.getOwner(theWolf, pluginx);
PlayerProfile PPo = Users.getProfile(master);
if(mcPermissions.getInstance().taming(master))
{ {
//Fast Food Service if(!pluginx.misc.bleedTracker.contains(target)) //Bleed
Taming.fastFoodService(PPo, theWolf, event); Swords.bleedCheck(attacker, target, pluginx);
//Sharpened Claws if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSerratedStrikesMode())
Taming.sharpenedClaws(PPo, event); Swords.applySerratedStrikes(attacker, eEvent, pluginx);
//Gore if(target instanceof Player)
Taming.gore(PPo, event, master, pluginx); PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS);
else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId()))
//Reward XP PvEExperienceGain(attacker, PPa, target, damage, SkillType.SWORDS);
Taming.rewardXp(event, pluginx, master);
} }
} else if(m.isAxes(itemInHand) && mcPermissions.getInstance().axes(attacker))
}
//Another offensive check for Archery
if(event instanceof EntityDamageByEntityEvent && event.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) event).getDamager() instanceof Arrow)
archeryCheck((EntityDamageByEntityEvent)event, pluginx);
/*
* DEFENSIVE CHECKS
*/
if(event instanceof EntityDamageByEntityEvent && event.getEntity() instanceof Player)
{
Swords.counterAttackChecks((EntityDamageByEntityEvent)event);
Acrobatics.dodgeChecks((EntityDamageByEntityEvent)event);
}
/*
* DEFENSIVE CHECKS FOR WOLVES
*/
if(event.getEntity() instanceof Wolf)
{
Wolf theWolf = (Wolf) event.getEntity();
if(theWolf.isTamed() && Taming.ownerOnline(theWolf, pluginx))
{
if(Taming.getOwner(theWolf, pluginx) == null)
return;
Player master = Taming.getOwner(theWolf, pluginx);
PlayerProfile PPo = Users.getProfile(master);
if(mcPermissions.getInstance().taming(master))
{ {
//Shock-Proof if(Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500)
if((event.getCause() == DamageCause.ENTITY_EXPLOSION || event.getCause() == DamageCause.BLOCK_EXPLOSION) && PPo.getSkillLevel(SkillType.TAMING) >= 500) event.setDamage(damage + 4);
Axes.axeCriticalCheck(attacker, eEvent, pluginx); //Critical hit
if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSkullSplitterMode())
Axes.applyAoeDamage(attacker, eEvent, pluginx);
if(target instanceof Player)
PvPExperienceGain(attacker, PPa, (Player) target, eEvent.getDamage(), SkillType.AXES);
else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId()))
PvEExperienceGain(attacker, PPa, target, eEvent.getDamage(), SkillType.AXES);
}
else if(itemInHand.getTypeId() == 0 && mcPermissions.getInstance().unarmed(attacker)) //Unarmed
{
Unarmed.unarmedBonus(attacker, eEvent);
if(PPa.getBerserkMode())
event.setDamage(eEvent.getDamage() + (eEvent.getDamage() / 2));
if(target instanceof Player)
Unarmed.disarmProcCheck(attacker, (Player) target); //Disarm
if(target instanceof Player)
PvPExperienceGain(attacker, PPa, (Player) target, eEvent.getDamage(), SkillType.UNARMED);
else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId()))
PvEExperienceGain(attacker, PPa, target, eEvent.getDamage(), SkillType.UNARMED);
}
//Player use bone on wolf.
else if(target instanceof Wolf)
{
Wolf wolf = (Wolf) target;
if(itemInHand.getTypeId() == 352 && mcPermissions.getInstance().taming(attacker))
{ {
event.setDamage(2); event.setCancelled(true);
if(wolf.isTamed())
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)})+" "+
mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {wolf.getHealth()}));
else
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {wolf.getHealth()}));
} }
//Thick Fur
if(PPo.getSkillLevel(SkillType.TAMING) >= 250)
event.setDamage(event.getDamage() / 2);
} }
} }
/*
* TAMING (WOLVES VERSUS ENTITIES)
*/
else if(damager instanceof Wolf)
{
Wolf wolf = (Wolf) damager;
if (wolf.isTamed() && Taming.ownerOnline(wolf, pluginx))
{
Player master = Taming.getOwner(wolf, pluginx);
if (master == null) //Can it really happen?
return;
PlayerProfile PPo = Users.getProfile(master);
if(mcPermissions.getInstance().taming(master))
{
//Fast Food Service
Taming.fastFoodService(PPo, wolf, event);
//Sharpened Claws
Taming.sharpenedClaws(PPo, event);
//Gore
Taming.gore(PPo, event, master, pluginx);
//Reward XP
Taming.rewardXp(event, pluginx, master);
}
}
}
//Another offensive check for Archery
else if(damager instanceof Arrow)
archeryCheck((EntityDamageByEntityEvent)event, pluginx);
/*
* DEFENSIVE CHECKS
*/
if(target instanceof Player)
{
Swords.counterAttackChecks(eEvent);
Acrobatics.dodgeChecks(eEvent);
}
/*
* DEFENSIVE CHECKS FOR WOLVES
*/
else if(target instanceof Wolf)
{
Wolf wolf = (Wolf) target;
if(wolf.isTamed() && Taming.ownerOnline(wolf, pluginx))
Taming.preventDamage(eEvent, pluginx);
}
} }
} }
@ -257,192 +197,226 @@ 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();
Entity y = arrow.getShooter(); Entity y = arrow.getShooter();
Entity x = event.getEntity(); Entity x = event.getEntity();
if(x instanceof Player) if(x instanceof Player)
{ {
Player defender = (Player)x; Player defender = (Player)x;
PlayerProfile PPd = Users.getProfile(defender); PlayerProfile PPd = Users.getProfile(defender);
if(PPd == null) if(PPd == null)
Users.addUser(defender); Users.addUser(defender);
if(mcPermissions.getInstance().unarmed(defender) && defender.getItemInHand().getTypeId() == 0) if(mcPermissions.getInstance().unarmed(defender) && defender.getItemInHand().getTypeId() == 0)
{ {
if(defender != null && PPd.getSkillLevel(SkillType.UNARMED) >= 1000) if(defender != null && PPd.getSkillLevel(SkillType.UNARMED) >= 1000)
{ {
if(Math.random() * 1000 <= 500) if(Math.random() * 1000 <= 500)
{ {
event.setCancelled(true); event.setCancelled(true);
defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect")); //$NON-NLS-1$ defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect")); //$NON-NLS-1$
return; return;
} }
} else if(defender != null && Math.random() * 1000 <= (PPd.getSkillLevel(SkillType.UNARMED) / 2)) } else if(defender != null && Math.random() * 1000 <= (PPd.getSkillLevel(SkillType.UNARMED) / 2))
{ {
event.setCancelled(true); event.setCancelled(true);
defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect")); //$NON-NLS-1$ defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect")); //$NON-NLS-1$
return; return;
} }
} }
} }
/* /*
* If attacker is player * If attacker is player
*/ */
if(y instanceof Player) if(y instanceof Player)
{ {
Player attacker = (Player)y; Player attacker = (Player)y;
PlayerProfile PPa = Users.getProfile(attacker); PlayerProfile PPa = Users.getProfile(attacker);
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, x, PPa); Archery.trackArrows(pluginx, x, PPa);
/* /*
* IGNITION * IGNITION
*/ */
Archery.ignitionCheck(x, attacker); Archery.ignitionCheck(x, attacker);
/* /*
* Defender is Monster * Defender is Monster
*/ */
if(!pluginx.misc.mobSpawnerList.contains(x.getEntityId())) if(!pluginx.misc.mobSpawnerList.contains(x.getEntityId()))
{ {
int xp = getXp(x, event); int xp = getXp(x, damage);
PPa.addXP(SkillType.ARCHERY, xp*10, attacker); PPa.addXP(SkillType.ARCHERY, xp*10, attacker);
} }
/* /*
* Attacker is Player * Attacker is Player
*/ */
if(x instanceof Player){ if(x instanceof Player){
Player defender = (Player)x; Player defender = (Player)x;
PlayerProfile PPd = Users.getProfile(defender); PlayerProfile PPd = Users.getProfile(defender);
/* /*
* Stuff for the daze proc * Stuff for the daze proc
*/ */
if(PPa.inParty() && PPd.inParty()) if(PPa.inParty() && PPd.inParty())
{ {
if(Party.getInstance().inSameParty(defender, attacker)) if(Party.getInstance().inSameParty(defender, attacker))
{ {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
/* /*
* PVP XP * PVP XP
*/ */
if(LoadProperties.pvpxp && ((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis() && !attacker.getName().equals(defender.getName())) if(LoadProperties.pvpxp && ((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis() && !attacker.getName().equals(defender.getName()))
{ {
int xp = (int) ((damage * 2) * 10); int xp = (int) ((damage * 2) * 10);
PPa.addXP(SkillType.ARCHERY, xp, attacker); PPa.addXP(SkillType.ARCHERY, xp, attacker);
} }
/* /*
* DAZE PROC * DAZE PROC
*/ */
Archery.dazeCheck(defender, attacker); Archery.dazeCheck(defender, attacker);
} }
} }
Skills.XpCheckSkill(SkillType.ARCHERY, attacker); Skills.XpCheckSkill(SkillType.ARCHERY, attacker);
} }
} }
/** /**
* Attempt to damage target for value dmg with reason CUSTOM * Attempt to damage target for value dmg with reason CUSTOM
* *
* @param target LivingEntity which to attempt to damage * @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do * @param dmg Amount of damage to attempt to do
*/ */
public static void dealDamage(LivingEntity target, int dmg){ public static void dealDamage(LivingEntity target, int dmg){
dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM); dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM);
} }
/** /**
* Attempt to damage target for value dmg with reason cause * Attempt to damage target for value dmg with reason cause
* *
* @param target LivingEntity which to attempt to damage * @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do * @param dmg Amount of damage to attempt to do
* @param cause DamageCause to pass to damage event * @param cause DamageCause to pass to damage event
*/ */
public static void dealDamage(LivingEntity target, int dmg, DamageCause cause) { public static void dealDamage(LivingEntity target, int dmg, DamageCause cause) {
if(LoadProperties.eventCallback) { if(LoadProperties.eventCallback) {
EntityDamageEvent ede = new EntityDamageEvent(target, cause, dmg); EntityDamageEvent ede = new EntityDamageEvent(target, cause, dmg);
Bukkit.getPluginManager().callEvent(ede); Bukkit.getPluginManager().callEvent(ede);
if(ede.isCancelled()) return; if(ede.isCancelled()) return;
target.damage(ede.getDamage()); target.damage(ede.getDamage());
} else { } else {
target.damage(dmg);
}
}
/**
* Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
*
* @param target LivingEntity which to attempt to damage
* @param dmg Amount of damage to attempt to do
* @param attacker Player to pass to event as damager
*/
public static void dealDamage(LivingEntity target, int dmg, Player attacker) {
if(LoadProperties.eventCallback) {
EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
Bukkit.getPluginManager().callEvent(ede);
if(ede.isCancelled()) return;
target.damage(ede.getDamage());
} else {
target.damage(dmg); target.damage(dmg);
} }
} }
public static int getXp(Entity entity, EntityDamageEvent event) /**
{ * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker
int xp = 0; *
if(entity instanceof LivingEntity) * @param target LivingEntity which to attempt to damage
{ * @param dmg Amount of damage to attempt to do
LivingEntity le = (LivingEntity) entity; * @param attacker Player to pass to event as damager
//Prevent a ridiculous amount of XP being granted by capping it at the remaining health of the entity */
int hpLeft = le.getHealth(); public static void dealDamage(LivingEntity target, int dmg, Player attacker) {
int xpinc = 0; if(LoadProperties.eventCallback) {
int damage = event.getDamage(); EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg);
Bukkit.getPluginManager().callEvent(ede);
if(ede.isCancelled()) return;
target.damage(ede.getDamage());
} else {
target.damage(dmg);
}
}
private static void PvPExperienceGain(Player attacker, PlayerProfile PPa, Player defender, int damage, SkillType skillType)
{
if (!LoadProperties.pvpxp)
return;
PlayerProfile PPd = Users.getProfile(defender);
if(System.currentTimeMillis() >= (PPd.getRespawnATS()*1000) + 5000
&& ((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis()
&& defender.getHealth() >= 1)
{
//Prevent a ridiculous amount of XP being granted by capping it at the remaining health of the mob
int hpLeft = defender.getHealth(), xpinc = 0;
if(hpLeft < damage) if(hpLeft < damage)
{ {
if(hpLeft > 0) if(hpLeft > 0)
xpinc = hpLeft; xpinc = hpLeft;
else else
xpinc = 0; xpinc = 0;
} } else
else xpinc = damage;
xpinc = damage;
if(entity instanceof Animals) int xp = (int) (xpinc * 2 * LoadProperties.pvpxprewardmodifier);
xp = (int) (xpinc * LoadProperties.animalXP); PPa.addXP(skillType, xp*10, attacker);
else Skills.XpCheckSkill(skillType, attacker);
{ }
if(entity instanceof Enderman) }
xp = (int) (xpinc * LoadProperties.endermanXP);
else if(entity instanceof Creeper) 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);
}
public static int getXp(Entity entity, int damage)
{
int xp = 0;
if(entity instanceof LivingEntity)
{
LivingEntity le = (LivingEntity) entity;
//Prevent a ridiculous amount of XP being granted by capping it at the remaining health of the entity
int hpLeft = le.getHealth();
int xpinc = 0;
if(hpLeft < damage)
{
if(hpLeft > 0)
xpinc = hpLeft;
else
xpinc = 0;
}
else
xpinc = damage;
if(entity instanceof Animals)
xp = (int) (xpinc * LoadProperties.animalXP);
else
{
if(entity instanceof Enderman)
xp = (int) (xpinc * LoadProperties.endermanXP);
else if(entity instanceof Creeper)
xp = (int) (xpinc * LoadProperties.creeperXP); xp = (int) (xpinc * LoadProperties.creeperXP);
else if(entity instanceof Silverfish) else if(entity instanceof Silverfish)
xp = (int) (xpinc * LoadProperties.silverfishXP); xp = (int) (xpinc * LoadProperties.silverfishXP);
else if(entity instanceof CaveSpider) else if(entity instanceof CaveSpider)
xp = (int) (xpinc * LoadProperties.cavespiderXP); xp = (int) (xpinc * LoadProperties.cavespiderXP);
else if(entity instanceof Spider) else if(entity instanceof Spider)
xp = (int) (xpinc * LoadProperties.spiderXP); xp = (int) (xpinc * LoadProperties.spiderXP);
else if(entity instanceof Skeleton) else if(entity instanceof Skeleton)
xp = (int) (xpinc * LoadProperties.skeletonXP); xp = (int) (xpinc * LoadProperties.skeletonXP);
else if(entity instanceof Zombie) else if(entity instanceof Zombie)
xp = (int) (xpinc * LoadProperties.zombieXP); xp = (int) (xpinc * LoadProperties.zombieXP);
else if(entity instanceof PigZombie) else if(entity instanceof PigZombie)
xp = (int) (xpinc * LoadProperties.pigzombieXP); xp = (int) (xpinc * LoadProperties.pigzombieXP);
else if(entity instanceof Slime) else if(entity instanceof Slime)
xp = (int) (xpinc * LoadProperties.slimeXP); xp = (int) (xpinc * LoadProperties.slimeXP);
else if(entity instanceof Ghast) else if(entity instanceof Ghast)
xp = (int) (xpinc * LoadProperties.ghastXP); xp = (int) (xpinc * LoadProperties.ghastXP);
else if(entity instanceof Blaze) else if(entity instanceof Blaze)
xp = (int) (xpinc * LoadProperties.blazeXP); xp = (int) (xpinc * LoadProperties.blazeXP);
else if(entity instanceof EnderDragon) else if(entity instanceof EnderDragon)
xp = (int) (xpinc * LoadProperties.enderdragonXP); xp = (int) (xpinc * LoadProperties.enderdragonXP);
else if(entity instanceof MagmaCube) else if(entity instanceof MagmaCube)
xp = (int) (xpinc * LoadProperties.magmacubeXP); xp = (int) (xpinc * LoadProperties.magmacubeXP);
} }
} }
return xp; return xp;
} }
} }

View File

@ -1,18 +1,18 @@
/* /*
This file is part of mcMMO. This file is part of mcMMO.
mcMMO is free software: you can redistribute it and/or modify mcMMO is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
mcMMO is distributed in the hope that it will be useful, mcMMO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with mcMMO. If not, see <http://www.gnu.org/licenses/>. along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.gmail.nossr50.skills; package com.gmail.nossr50.skills;
@ -34,70 +34,70 @@ import com.gmail.nossr50.locale.mcLocale;
public class Taming public class Taming
{ {
public static void rewardXp(EntityDamageEvent event, mcMMO pluginx, Player master) public static void rewardXp(EntityDamageEvent event, mcMMO pluginx, Player master)
{ {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if(!pluginx.misc.mobSpawnerList.contains(entity.getEntityId())) if(!pluginx.misc.mobSpawnerList.contains(entity.getEntityId()))
{ {
int xp = Combat.getXp(entity, event); int xp = Combat.getXp(entity, event.getDamage());
Users.getProfile(master).addXP(SkillType.TAMING, xp*10, master); Users.getProfile(master).addXP(SkillType.TAMING, xp*10, master);
if(entity instanceof Player) if(entity instanceof Player)
{ {
xp = (event.getDamage() * 2); xp = (event.getDamage() * 2);
Users.getProfile(master).addXP(SkillType.TAMING, (int)((xp*10)*1.5), master); Users.getProfile(master).addXP(SkillType.TAMING, (int)((xp*10)*1.5), master);
} }
Skills.XpCheckSkill(SkillType.TAMING, 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();
int maxHealth = theWolf.getMaxHealth(); int maxHealth = theWolf.getMaxHealth();
int damage = event.getDamage(); int damage = event.getDamage();
if(PPo.getSkillLevel(SkillType.TAMING) >= 50) if(PPo.getSkillLevel(SkillType.TAMING) >= 50)
{ {
if(health < maxHealth) if(health < maxHealth)
{ {
if(Math.random() * 10 > 5) if(Math.random() * 10 > 5)
{ {
if(health + damage <= maxHealth) if(health + damage <= maxHealth)
theWolf.setHealth(health + damage); theWolf.setHealth(health + damage);
else else
theWolf.setHealth(maxHealth); theWolf.setHealth(maxHealth);
} }
} }
} }
} }
public static void sharpenedClaws(PlayerProfile PPo, EntityDamageEvent event) public static void sharpenedClaws(PlayerProfile PPo, EntityDamageEvent event)
{ {
if(PPo.getSkillLevel(SkillType.TAMING) >= 750) if(PPo.getSkillLevel(SkillType.TAMING) >= 750)
{ {
event.setDamage(event.getDamage() + 2); event.setDamage(event.getDamage() + 2);
} }
} }
public static void gore(PlayerProfile PPo, EntityDamageEvent event, Player master, mcMMO pluginx) public static void gore(PlayerProfile PPo, EntityDamageEvent event, Player master, mcMMO pluginx)
{ {
if(Math.random() * 1000 <= PPo.getSkillLevel(SkillType.TAMING)) if(Math.random() * 1000 <= PPo.getSkillLevel(SkillType.TAMING))
{ {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
event.setDamage(event.getDamage() * 2); event.setDamage(event.getDamage() * 2);
if(entity instanceof Player) if(entity instanceof Player)
{ {
Player target = (Player)entity; Player target = (Player)entity;
target.sendMessage(mcLocale.getString("Combat.StruckByGore")); //$NON-NLS-1$ target.sendMessage(mcLocale.getString("Combat.StruckByGore")); //$NON-NLS-1$
Users.getProfile(target).setBleedTicks(2); Users.getProfile(target).setBleedTicks(2);
} }
else else
pluginx.misc.addToBleedQue((LivingEntity)entity); pluginx.misc.addToBleedQue((LivingEntity)entity);
master.sendMessage(mcLocale.getString("Combat.Gore")); //$NON-NLS-1$ master.sendMessage(mcLocale.getString("Combat.Gore")); //$NON-NLS-1$
} }
} }
public static boolean ownerOnline(Wolf theWolf, Plugin pluginx) public static boolean ownerOnline(Wolf theWolf, Plugin pluginx)
{ {