mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 13:46:46 +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.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;
|
||||||
@ -45,124 +46,83 @@ public class Combat
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if(event instanceof EntityDamageByEntityEvent)
|
if(event instanceof EntityDamageByEntityEvent)
|
||||||
{
|
|
||||||
/*
|
|
||||||
* OFFENSIVE CHECKS FOR PLAYERS VERSUS ENTITIES
|
|
||||||
*/
|
|
||||||
if(((EntityDamageByEntityEvent) event).getDamager() instanceof Player)
|
|
||||||
{
|
{
|
||||||
//Declare Things
|
//Declare Things
|
||||||
EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event;
|
EntityDamageByEntityEvent eEvent = (EntityDamageByEntityEvent) event;
|
||||||
Player attacker = (Player)((EntityDamageByEntityEvent) event).getDamager();
|
Entity damager = eEvent.getDamager();
|
||||||
PlayerProfile PPa = Users.getProfile(attacker);
|
LivingEntity target = (LivingEntity) eEvent.getEntity();
|
||||||
|
int damage = eEvent.getDamage();
|
||||||
|
|
||||||
//Damage modifiers
|
/*
|
||||||
if(mcPermissions.getInstance().unarmed(attacker) && attacker.getItemInHand().getTypeId() == 0) //Unarmed
|
* PLAYER VERSUS ENTITIES
|
||||||
Unarmed.unarmedBonus(attacker, eventb);
|
*/
|
||||||
if(m.isAxes(attacker.getItemInHand()) && mcPermissions.getInstance().axes(attacker) && Users.getProfile(attacker).getSkillLevel(SkillType.AXES) >= 500)
|
if(damager instanceof Player)
|
||||||
{
|
{
|
||||||
int damage = event.getDamage()+4;
|
Player attacker = (Player) eEvent.getDamager();
|
||||||
event.setDamage(damage);
|
ItemStack itemInHand = attacker.getItemInHand();
|
||||||
}
|
PlayerProfile PPa = Users.getProfile(attacker);
|
||||||
|
|
||||||
//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))
|
if(!pluginx.misc.bleedTracker.contains(target)) //Bleed
|
||||||
Axes.axeCriticalCheck(attacker, eventb, pluginx); //Axe Critical Checks
|
Swords.bleedCheck(attacker, target, pluginx);
|
||||||
|
|
||||||
if(!pluginx.misc.bleedTracker.contains((LivingEntity) event.getEntity())) //Swords Bleed
|
if (!(event instanceof FakeEntityDamageByEntityEvent) && PPa.getSerratedStrikesMode())
|
||||||
Swords.bleedCheck(attacker, (LivingEntity)event.getEntity(), pluginx);
|
Swords.applySerratedStrikes(attacker, eEvent, pluginx);
|
||||||
|
|
||||||
if(event.getEntity() instanceof Player && mcPermissions.getInstance().unarmed(attacker))
|
if(target instanceof Player)
|
||||||
{
|
PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS);
|
||||||
Player defender = (Player)event.getEntity();
|
else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId()))
|
||||||
Unarmed.disarmProcCheck(attacker, defender);
|
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())
|
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(target instanceof Player)
|
||||||
if(!(event instanceof FakeEntityDamageByEntityEvent)) {
|
PvPExperienceGain(attacker, PPa, (Player) target, eEvent.getDamage(), SkillType.UNARMED);
|
||||||
if(PPa.getSkullSplitterMode() && m.isAxes(attacker.getItemInHand()))
|
else if(!pluginx.misc.mobSpawnerList.contains(target.getEntityId()))
|
||||||
Axes.applyAoeDamage(attacker, eventb, pluginx);
|
PvEExperienceGain(attacker, PPa, target, eEvent.getDamage(), SkillType.UNARMED);
|
||||||
if(PPa.getSerratedStrikesMode() && m.isSwords(attacker.getItemInHand()))
|
|
||||||
Swords.applySerratedStrikes(attacker, eventb, pluginx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Experience
|
//Player use bone on wolf.
|
||||||
if(event.getEntity() instanceof Player)
|
else if(target instanceof Wolf)
|
||||||
{
|
{
|
||||||
Player defender = (Player)event.getEntity();
|
Wolf wolf = (Wolf) target;
|
||||||
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(itemInHand.getTypeId() == 352 && mcPermissions.getInstance().taming(attacker))
|
||||||
{
|
|
||||||
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);
|
event.setCancelled(true);
|
||||||
if(theWolf.isTamed())
|
if(wolf.isTamed())
|
||||||
{
|
|
||||||
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
|
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
|
||||||
mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(theWolf)})+" "+
|
mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)})+" "+
|
||||||
mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {theWolf.getHealth()}));
|
mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {wolf.getHealth()}));
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
attacker.sendMessage(mcLocale.getString("Combat.BeastLore")+" "+
|
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)
|
* TAMING (WOLVES VERSUS ENTITIES)
|
||||||
*/
|
*/
|
||||||
if(event instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) event).getDamager() instanceof Wolf)
|
else if(damager instanceof Wolf)
|
||||||
{
|
{
|
||||||
EntityDamageByEntityEvent eventb = (EntityDamageByEntityEvent) event;
|
Wolf wolf = (Wolf) damager;
|
||||||
Wolf theWolf = (Wolf) eventb.getDamager();
|
|
||||||
|
|
||||||
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;
|
return;
|
||||||
|
|
||||||
Player master = Taming.getOwner(theWolf, pluginx);
|
|
||||||
PlayerProfile PPo = Users.getProfile(master);
|
PlayerProfile PPo = Users.getProfile(master);
|
||||||
|
|
||||||
if(mcPermissions.getInstance().taming(master))
|
if(mcPermissions.getInstance().taming(master))
|
||||||
{
|
{
|
||||||
//Fast Food Service
|
//Fast Food Service
|
||||||
Taming.fastFoodService(PPo, theWolf, event);
|
Taming.fastFoodService(PPo, wolf, event);
|
||||||
|
|
||||||
//Sharpened Claws
|
//Sharpened Claws
|
||||||
Taming.sharpenedClaws(PPo, event);
|
Taming.sharpenedClaws(PPo, event);
|
||||||
@ -201,44 +159,26 @@ public class Combat
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Another offensive check for Archery
|
//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);
|
archeryCheck((EntityDamageByEntityEvent)event, pluginx);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DEFENSIVE CHECKS
|
* DEFENSIVE CHECKS
|
||||||
*/
|
*/
|
||||||
if(event instanceof EntityDamageByEntityEvent && event.getEntity() instanceof Player)
|
if(target instanceof Player)
|
||||||
{
|
{
|
||||||
Swords.counterAttackChecks((EntityDamageByEntityEvent)event);
|
Swords.counterAttackChecks(eEvent);
|
||||||
Acrobatics.dodgeChecks((EntityDamageByEntityEvent)event);
|
Acrobatics.dodgeChecks(eEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DEFENSIVE CHECKS FOR WOLVES
|
* DEFENSIVE CHECKS FOR WOLVES
|
||||||
*/
|
*/
|
||||||
|
else if(target instanceof Wolf)
|
||||||
if(event.getEntity() instanceof Wolf)
|
|
||||||
{
|
{
|
||||||
Wolf theWolf = (Wolf) event.getEntity();
|
Wolf wolf = (Wolf) target;
|
||||||
|
if(wolf.isTamed() && Taming.ownerOnline(wolf, pluginx))
|
||||||
if(theWolf.isTamed() && Taming.ownerOnline(theWolf, pluginx))
|
Taming.preventDamage(eEvent, 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,7 +244,7 @@ public class Combat
|
|||||||
*/
|
*/
|
||||||
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);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -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;
|
int xp = 0;
|
||||||
if(entity instanceof LivingEntity)
|
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
|
//Prevent a ridiculous amount of XP being granted by capping it at the remaining health of the entity
|
||||||
int hpLeft = le.getHealth();
|
int hpLeft = le.getHealth();
|
||||||
int xpinc = 0;
|
int xpinc = 0;
|
||||||
int damage = event.getDamage();
|
|
||||||
|
|
||||||
if(hpLeft < damage)
|
if(hpLeft < damage)
|
||||||
{
|
{
|
||||||
|
@ -39,7 +39,7 @@ public class Taming
|
|||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user