mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
Optimization in Combat.java
This commit is contained in:
parent
a7f259ea3c
commit
aff6b0925f
@ -21,6 +21,7 @@ import org.bukkit.entity.*;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.gmail.nossr50.config.LoadProperties;
|
||||
@ -45,124 +46,83 @@ public class Combat
|
||||
return;
|
||||
|
||||
if(event instanceof EntityDamageByEntityEvent)
|
||||
{
|
||||
/*
|
||||
* OFFENSIVE CHECKS FOR PLAYERS VERSUS ENTITIES
|
||||
*/
|
||||
if(((EntityDamageByEntityEvent) event).getDamager() instanceof Player)
|
||||
{
|
||||
//Declare Things
|
||||
EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event;
|
||||
Player attacker = (Player)((EntityDamageByEntityEvent) event).getDamager();
|
||||
PlayerProfile PPa = Users.getProfile(attacker);
|
||||
EntityDamageByEntityEvent eEvent = (EntityDamageByEntityEvent) event;
|
||||
Entity damager = eEvent.getDamager();
|
||||
LivingEntity target = (LivingEntity) eEvent.getEntity();
|
||||
int damage = eEvent.getDamage();
|
||||
|
||||
//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)
|
||||
/*
|
||||
* PLAYER VERSUS ENTITIES
|
||||
*/
|
||||
if(damager instanceof Player)
|
||||
{
|
||||
int damage = event.getDamage()+4;
|
||||
event.setDamage(damage);
|
||||
}
|
||||
Player attacker = (Player) eEvent.getDamager();
|
||||
ItemStack itemInHand = attacker.getItemInHand();
|
||||
PlayerProfile PPa = Users.getProfile(attacker);
|
||||
|
||||
//If there are any abilities to activate
|
||||
combatAbilityChecks(attacker, PPa, pluginx);
|
||||
|
||||
//Check for offensive procs
|
||||
if(!(((EntityDamageByEntityEvent) event).getDamager() instanceof Arrow))
|
||||
//Damage modifiers and proc checks
|
||||
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(target)) //Bleed
|
||||
Swords.bleedCheck(attacker, target, pluginx);
|
||||
|
||||
if(!pluginx.misc.bleedTracker.contains((LivingEntity) event.getEntity())) //Swords Bleed
|
||||
Swords.bleedCheck(attacker, (LivingEntity)event.getEntity(), pluginx);
|
||||
if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSerratedStrikesMode())
|
||||
Swords.applySerratedStrikes(attacker, eEvent, pluginx);
|
||||
|
||||
if(event.getEntity() instanceof Player && mcPermissions.getInstance().unarmed(attacker))
|
||||
{
|
||||
Player defender = (Player)event.getEntity();
|
||||
Unarmed.disarmProcCheck(attacker, defender);
|
||||
if(target instanceof Player)
|
||||
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(m.isAxes(itemInHand) && mcPermissions.getInstance().axes(attacker))
|
||||
{
|
||||
if(Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500)
|
||||
event.setDamage(damage + 4);
|
||||
|
||||
//Modify the event damage if Attacker is Berserk
|
||||
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(event.getDamage() + (event.getDamage() / 2));
|
||||
event.setDamage(eEvent.getDamage() + (eEvent.getDamage() / 2));
|
||||
if(target instanceof Player)
|
||||
Unarmed.disarmProcCheck(attacker, (Player) target); //Disarm
|
||||
|
||||
//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);
|
||||
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);
|
||||
}
|
||||
|
||||
//Experience
|
||||
if(event.getEntity() instanceof Player)
|
||||
//Player use bone on wolf.
|
||||
else if(target instanceof Wolf)
|
||||
{
|
||||
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;
|
||||
Wolf wolf = (Wolf) target;
|
||||
|
||||
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))
|
||||
if(itemInHand.getTypeId() == 352 && mcPermissions.getInstance().taming(attacker))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if(theWolf.isTamed())
|
||||
{
|
||||
if(wolf.isTamed())
|
||||
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
|
||||
mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(theWolf)})+" "+
|
||||
mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {theWolf.getHealth()}));
|
||||
}
|
||||
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[] {theWolf.getHealth()}));
|
||||
}
|
||||
}
|
||||
}
|
||||
mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {wolf.getHealth()}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -170,23 +130,21 @@ public class Combat
|
||||
/*
|
||||
* TAMING (WOLVES VERSUS ENTITIES)
|
||||
*/
|
||||
if(event instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) event).getDamager() instanceof Wolf)
|
||||
else if(damager instanceof Wolf)
|
||||
{
|
||||
EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event;
|
||||
Wolf theWolf = (Wolf) eventb.getDamager();
|
||||
Wolf wolf = (Wolf) damager;
|
||||
|
||||
if(theWolf.isTamed() && Taming.ownerOnline(theWolf, pluginx))
|
||||
if (wolf.isTamed() && Taming.ownerOnline(wolf, pluginx))
|
||||
{
|
||||
if(Taming.getOwner(theWolf, pluginx) == null)
|
||||
Player master = Taming.getOwner(wolf, pluginx);
|
||||
if (master == null) //Can it really happen?
|
||||
return;
|
||||
|
||||
Player master = Taming.getOwner(theWolf, pluginx);
|
||||
PlayerProfile PPo = Users.getProfile(master);
|
||||
|
||||
if(mcPermissions.getInstance().taming(master))
|
||||
{
|
||||
//Fast Food Service
|
||||
Taming.fastFoodService(PPo, theWolf, event);
|
||||
Taming.fastFoodService(PPo, wolf, event);
|
||||
|
||||
//Sharpened Claws
|
||||
Taming.sharpenedClaws(PPo, event);
|
||||
@ -201,44 +159,26 @@ public class Combat
|
||||
}
|
||||
|
||||
//Another offensive check for Archery
|
||||
if(event instanceof EntityDamageByEntityEvent && event.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) event).getDamager() instanceof Arrow)
|
||||
else if(damager instanceof Arrow)
|
||||
archeryCheck((EntityDamageByEntityEvent)event, pluginx);
|
||||
|
||||
/*
|
||||
* DEFENSIVE CHECKS
|
||||
*/
|
||||
if(event instanceof EntityDamageByEntityEvent && event.getEntity() instanceof Player)
|
||||
if(target instanceof Player)
|
||||
{
|
||||
Swords.counterAttackChecks((EntityDamageByEntityEvent)event);
|
||||
Acrobatics.dodgeChecks((EntityDamageByEntityEvent)event);
|
||||
Swords.counterAttackChecks(eEvent);
|
||||
Acrobatics.dodgeChecks(eEvent);
|
||||
}
|
||||
|
||||
/*
|
||||
* DEFENSIVE CHECKS FOR WOLVES
|
||||
*/
|
||||
|
||||
if(event.getEntity() instanceof Wolf)
|
||||
else if(target 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((event.getCause() == DamageCause.ENTITY_EXPLOSION || event.getCause() == DamageCause.BLOCK_EXPLOSION) && PPo.getSkillLevel(SkillType.TAMING) >= 500)
|
||||
{
|
||||
event.setDamage(2);
|
||||
}
|
||||
|
||||
//Thick Fur
|
||||
if(PPo.getSkillLevel(SkillType.TAMING) >= 250)
|
||||
event.setDamage(event.getDamage() / 2);
|
||||
}
|
||||
Wolf wolf = (Wolf) target;
|
||||
if(wolf.isTamed() && Taming.ownerOnline(wolf, pluginx))
|
||||
Taming.preventDamage(eEvent, pluginx);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -304,7 +244,7 @@ public class Combat
|
||||
*/
|
||||
if(!pluginx.misc.mobSpawnerList.contains(x.getEntityId()))
|
||||
{
|
||||
int xp = getXp(x, event);
|
||||
int xp = getXp(x, damage);
|
||||
PPa.addXP(SkillType.ARCHERY, xp*10, attacker);
|
||||
}
|
||||
/*
|
||||
@ -390,7 +330,42 @@ public class Combat
|
||||
}
|
||||
}
|
||||
|
||||
public static int getXp(Entity entity, EntityDamageEvent event)
|
||||
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 > 0)
|
||||
xpinc = hpLeft;
|
||||
else
|
||||
xpinc = 0;
|
||||
} else
|
||||
xpinc = damage;
|
||||
|
||||
int xp = (int) (xpinc * 2 * LoadProperties.pvpxprewardmodifier);
|
||||
PPa.addXP(skillType, xp*10, attacker);
|
||||
Skills.XpCheckSkill(skillType, attacker);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
@ -399,7 +374,6 @@ public class Combat
|
||||
//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;
|
||||
int damage = event.getDamage();
|
||||
|
||||
if(hpLeft < damage)
|
||||
{
|
||||
|
@ -39,7 +39,7 @@ public class Taming
|
||||
Entity entity = event.getEntity();
|
||||
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);
|
||||
|
||||
if(entity instanceof Player)
|
||||
|
Loading…
Reference in New Issue
Block a user