Whitespace & other formatting fixes for Combat.java

This commit is contained in:
GJ 2012-03-06 22:50:36 -05:00
parent 6733eb93f2
commit b86cfb595c
2 changed files with 315 additions and 295 deletions

View File

@ -41,12 +41,18 @@ import com.gmail.nossr50.skills.Swords;
import com.gmail.nossr50.skills.Taming; import com.gmail.nossr50.skills.Taming;
import com.gmail.nossr50.skills.Unarmed; import com.gmail.nossr50.skills.Unarmed;
public class Combat public class Combat {
{
public static void combatChecks(EntityDamageByEntityEvent event, mcMMO pluginx) /**
{ * Apply combat modifiers and process and XP gain.
if (event.getDamage() == 0 || event.getEntity().isDead()) *
* @param event The event to run the combat checks on.
* @param pluginx mcMMO plugin instance
*/
public static void combatChecks(EntityDamageByEntityEvent event, mcMMO pluginx) {
if (event.getDamage() == 0 || event.getEntity().isDead()) {
return; return;
}
Entity damager = event.getDamager(); Entity damager = event.getDamager();
LivingEntity target = (LivingEntity) event.getEntity(); LivingEntity target = (LivingEntity) event.getEntity();
@ -54,199 +60,192 @@ public class Combat
EntityType damagerType = damager.getType(); EntityType damagerType = damager.getType();
EntityType targetType = target.getType(); EntityType targetType = target.getType();
switch (damagerType) switch (damagerType) {
{
case PLAYER: case PLAYER:
Player attacker = (Player) event.getDamager(); Player attacker = (Player) event.getDamager();
ItemStack itemInHand = attacker.getItemInHand(); ItemStack itemInHand = attacker.getItemInHand();
PlayerProfile PPa = Users.getProfile(attacker); PlayerProfile PPa = Users.getProfile(attacker);
combatAbilityChecks(attacker, PPa); combatAbilityChecks(attacker);
if (m.isSwords(itemInHand) && mcPermissions.getInstance().swords(attacker)) if (m.isSwords(itemInHand) && mcPermissions.getInstance().swords(attacker)) {
{ if (!pluginx.misc.bleedTracker.contains(target)) {
if (!pluginx.misc.bleedTracker.contains(target))
Swords.bleedCheck(attacker, target, pluginx); Swords.bleedCheck(attacker, target, pluginx);
}
if (PPa.getSerratedStrikesMode()) if (PPa.getSerratedStrikesMode()) {
Swords.applySerratedStrikes(attacker, event, pluginx); Swords.applySerratedStrikes(attacker, event, pluginx);
}
if (targetType.equals(EntityType.PLAYER)) if (targetType.equals(EntityType.PLAYER)) {
PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS); PvPExperienceGain(attacker, PPa, (Player) target, damage, SkillType.SWORDS);
else if (!pluginx.misc.mobSpawnerList.contains(target.getEntityId())) }
else if (!pluginx.misc.mobSpawnerList.contains(target.getEntityId())){
PvEExperienceGain(attacker, PPa, target, damage, SkillType.SWORDS); PvEExperienceGain(attacker, PPa, target, damage, SkillType.SWORDS);
} }
else if (m.isAxes(itemInHand) && mcPermissions.getInstance().axes(attacker)) }
{ else if (m.isAxes(itemInHand) && mcPermissions.getInstance().axes(attacker)) {
Axes.axesBonus(attacker, event); Axes.axesBonus(attacker, event);
Axes.axeCriticalCheck(attacker, event, pluginx); Axes.axeCriticalCheck(attacker, event, pluginx);
Axes.impact(attacker, target, event); Axes.impact(attacker, target, event);
if (PPa.getSkullSplitterMode()) if (PPa.getSkullSplitterMode()) {
Axes.applyAoeDamage(attacker, event, pluginx); Axes.applyAoeDamage(attacker, event, pluginx);
}
if (targetType.equals(EntityType.PLAYER)) if (targetType.equals(EntityType.PLAYER)) {
PvPExperienceGain(attacker, PPa, (Player) target, event.getDamage(), SkillType.AXES); //use getDamage because damage is modified in earlier functions 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())) }
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 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);
if (PPa.getBerserkMode()) if (PPa.getBerserkMode()) {
event.setDamage(damage + (damage / 2)); event.setDamage(damage + (damage / 2));
}
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 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())) 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 PvEExperienceGain(attacker, PPa, target, event.getDamage(), SkillType.UNARMED); //use getDamage because damage is modified in earlier functions
} }
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;
String message = "Combat.BeastLore" + " "; String message = "Combat.BeastLore" + " ";
int health = wolf.getHealth(); int health = wolf.getHealth();
event.setCancelled(true); event.setCancelled(true);
if (wolf.isTamed()) if (wolf.isTamed()) {
{
message.concat(mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)}) + " "); message.concat(mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)}) + " ");
message.concat(mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {health})); message.concat(mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {health}));
} }
else else {
message.concat(mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {health})); message.concat(mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {health}));
}
attacker.sendMessage(message); attacker.sendMessage(message);
} }
break;
case WOLF: case WOLF:
{
Wolf wolf = (Wolf) damager; Wolf wolf = (Wolf) damager;
if (wolf.isTamed() && wolf.getOwner() instanceof Player) if (wolf.isTamed() && wolf.getOwner() instanceof Player) {
{
Player master = (Player) wolf.getOwner(); Player master = (Player) wolf.getOwner();
PlayerProfile PPo = Users.getProfile(master); PlayerProfile PPo = Users.getProfile(master);
if (mcPermissions.getInstance().taming(master)) if (mcPermissions.getInstance().taming(master)) {
{
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); Taming.rewardXp(event, pluginx, master);
} }
} }
} break;
case ARROW: case ARROW:
archeryCheck((EntityDamageByEntityEvent)event, pluginx); archeryCheck((EntityDamageByEntityEvent)event, pluginx);
break;
default:
break;
} }
if (targetType.equals(EntityType.PLAYER)) if (targetType.equals(EntityType.PLAYER)) {
{
Swords.counterAttackChecks(event); Swords.counterAttackChecks(event);
Acrobatics.dodgeChecks(event); Acrobatics.dodgeChecks(event);
} }
} }
public static void combatAbilityChecks(Player attacker, PlayerProfile PPa) /**
{ * Process combat abilities based on weapon preparation modes.
//Check to see if any abilities need to be activated *
if(PPa.getAxePreparationMode()) * @param attacker The player attacking
*/
public static void combatAbilityChecks(Player attacker) {
PlayerProfile PPa = Users.getProfile(attacker);
if (PPa.getAxePreparationMode()) {
Skills.abilityCheck(attacker, SkillType.AXES); Skills.abilityCheck(attacker, SkillType.AXES);
if(PPa.getSwordsPreparationMode()) }
else if (PPa.getSwordsPreparationMode()) {
Skills.abilityCheck(attacker, SkillType.SWORDS); Skills.abilityCheck(attacker, SkillType.SWORDS);
if(PPa.getFistsPreparationMode()) }
else if (PPa.getFistsPreparationMode()) {
Skills.abilityCheck(attacker, SkillType.UNARMED); Skills.abilityCheck(attacker, SkillType.UNARMED);
} }
}
public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) /**
{ * Process archery abilities.
Arrow arrow = (Arrow)event.getDamager(); *
Entity y = arrow.getShooter(); * @param event The event to run the archery checks on.
Entity x = event.getEntity(); * @param pluginx mcMMO plugin instance
if(x instanceof Player)
{
Player defender = (Player)x;
PlayerProfile PPd = Users.getProfile(defender);
if(PPd == null)
Users.addUser(defender);
if(mcPermissions.getInstance().unarmed(defender) && defender.getItemInHand().getTypeId() == 0)
{
if(defender != null && PPd.getSkillLevel(SkillType.UNARMED) >= 1000)
{
if(Math.random() * 1000 <= 500)
{
event.setCancelled(true);
defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect")); //$NON-NLS-1$
return;
}
} else if(defender != null && Math.random() * 1000 <= (PPd.getSkillLevel(SkillType.UNARMED) / 2))
{
event.setCancelled(true);
defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect")); //$NON-NLS-1$
return;
}
}
}
/*
* If attacker is player
*/ */
if(y instanceof Player) public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) {
{ Arrow arrow = (Arrow) event.getDamager();
Player attacker = (Player)y; LivingEntity shooter = arrow.getShooter();
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player defender = (Player) entity;
PlayerProfile PPd = Users.getProfile(defender);
boolean deflect = false;
if (mcPermissions.getInstance().unarmed(defender) && defender.getItemInHand().getType().equals(Material.AIR)) {
if (PPd.getSkillLevel(SkillType.UNARMED) >= 1000 && (Math.random() * 1000 <= 500)) {
deflect = true;
}
else if (Math.random() * 1000 <= (PPd.getSkillLevel(SkillType.UNARMED) / 2)) {
deflect = true;
}
if (deflect) {
event.setCancelled(true);
defender.sendMessage(mcLocale.getString("Combat.ArrowDeflect"));
return;
}
}
}
if (shooter instanceof Player) {
Player attacker = (Player) shooter;
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)
{
Archery.trackArrows(pluginx, x, PPa);
/* if (mcPermissions.getInstance().archery(attacker) && damage > 0) {
* IGNITION Archery.trackArrows(pluginx, entity, PPa);
*/ Archery.ignitionCheck(entity, attacker);
Archery.ignitionCheck(x, attacker);
/* if (!pluginx.misc.mobSpawnerList.contains(entity.getEntityId())) {
* Defender is Monster int xp = getXp((LivingEntity) entity, damage);
*/
if(!pluginx.misc.mobSpawnerList.contains(x.getEntityId()))
{
int xp = getXp(x, damage);
PPa.addXP(SkillType.ARCHERY, xp*10, attacker); PPa.addXP(SkillType.ARCHERY, xp*10, attacker);
} }
/*
* Attacker is Player if (entity instanceof Player) {
*/ Player defender = (Player) entity;
if(x instanceof Player){
Player defender = (Player)x;
PlayerProfile PPd = Users.getProfile(defender); PlayerProfile PPd = Users.getProfile(defender);
/*
* Stuff for the daze proc if (PPa.inParty() && PPd.inParty() && Party.getInstance().inSameParty(defender, attacker)) {
*/
if(PPa.inParty() && PPd.inParty())
{
if(Party.getInstance().inSameParty(defender, attacker))
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
}
/* if (LoadProperties.pvpxp && (((PPd.getLastLogin() + 5) * 1000) < System.currentTimeMillis()) && !attacker.getName().equals(defender.getName())) {
* PVP XP int xp = (damage * 2) * 10; //What's the 2 for? Should this be a multiplier from file instead?
*/
if(LoadProperties.pvpxp && ((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis() && !attacker.getName().equals(defender.getName()))
{
int xp = (int) ((damage * 2) * 10);
PPa.addXP(SkillType.ARCHERY, xp, attacker); PPa.addXP(SkillType.ARCHERY, xp, attacker);
} }
/*
* DAZE PROC
*/
Archery.dazeCheck(defender, attacker); Archery.dazeCheck(defender, attacker);
} }
} }
Skills.XpCheckSkill(SkillType.ARCHERY, attacker); Skills.XpCheckSkill(SkillType.ARCHERY, attacker);
} }
} }
@ -271,11 +270,16 @@ public class Combat
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 = (EntityDamageEvent) new FakeEntityDamageEvent(target, cause, dmg); EntityDamageEvent ede = (EntityDamageEvent) new FakeEntityDamageEvent(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); target.damage(dmg);
} }
} }
@ -290,117 +294,133 @@ public class Combat
public static void dealDamage(LivingEntity target, int dmg, Player attacker) { public static void dealDamage(LivingEntity target, int dmg, Player attacker) {
if (LoadProperties.eventCallback) { if (LoadProperties.eventCallback) {
EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg); EntityDamageEvent ede = (EntityDamageByEntityEvent) new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, 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); target.damage(dmg);
} }
} }
private static void PvPExperienceGain(Player attacker, PlayerProfile PPa, Player defender, int damage, SkillType skillType) private static void PvPExperienceGain(Player attacker, PlayerProfile PPa, Player defender, int damage, SkillType skillType) {
{ if (!LoadProperties.pvpxp) {
if (!LoadProperties.pvpxp)
return; return;
}
PlayerProfile PPd = Users.getProfile(defender); PlayerProfile PPd = Users.getProfile(defender);
int health = defender.getHealth();
if(System.currentTimeMillis() >= (PPd.getRespawnATS()*1000) + 5000 if ((System.currentTimeMillis() >= (PPd.getRespawnATS()*1000) + 5000) && (((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis()) && health >= 1) {
&& ((PPd.getLastLogin()+5)*1000) < System.currentTimeMillis() int xp = capXP(health, damage);
&& 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) xp = (int) (xp * 2 * LoadProperties.pvpxprewardmodifier);
{
if(hpLeft > 0)
xpinc = hpLeft;
else
xpinc = 0;
} else
xpinc = damage;
int xp = (int) (xpinc * 2 * LoadProperties.pvpxprewardmodifier);
PPa.addXP(skillType, xp * 10, attacker); PPa.addXP(skillType, xp * 10, attacker);
Skills.XpCheckSkill(skillType, attacker); Skills.XpCheckSkill(skillType, attacker);
} }
} }
private static void PvEExperienceGain(Player attacker, PlayerProfile PPa, LivingEntity target, int damage, SkillType skillType) private static void PvEExperienceGain(Player attacker, PlayerProfile PPa, LivingEntity target, int damage, SkillType skillType) {
{
int xp = getXp(target, damage); int xp = getXp(target, damage);
PPa.addXP(skillType, xp * 10, attacker); PPa.addXP(skillType, xp * 10, attacker);
Skills.XpCheckSkill(skillType, attacker); Skills.XpCheckSkill(skillType, attacker);
} }
public static int getXp(Entity entity, int damage) private static int capXP(int hpLeft, int damage) {
{ int xp;
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 < damage) {
{ if (hpLeft > 0) {
if(hpLeft > 0) xp = hpLeft;
xpinc = hpLeft; }
else else {
xpinc = 0; xp = 0;
}
}
else {
xp = damage;
} }
else
xpinc = damage;
if(entity instanceof Animals) return xp;
xp = (int) (xpinc * LoadProperties.animalXP); }
else
{ /**
* 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(); EntityType type = entity.getType();
switch (type) { switch (type) {
case BLAZE: case BLAZE:
xp = (int) (xpinc * LoadProperties.blazeXP); xp = (int) (xp * LoadProperties.blazeXP);
break; break;
case CAVE_SPIDER: case CAVE_SPIDER:
xp = (int) (xpinc * LoadProperties.cavespiderXP); xp = (int) (xp * LoadProperties.cavespiderXP);
break; break;
case CREEPER: case CREEPER:
xp = (int) (xpinc * LoadProperties.creeperXP); xp = (int) (xp * LoadProperties.creeperXP);
break; break;
case ENDER_DRAGON: case ENDER_DRAGON:
xp = (int) (xpinc * LoadProperties.enderdragonXP); xp = (int) (xp * LoadProperties.enderdragonXP);
break; break;
case ENDERMAN: case ENDERMAN:
xp = (int) (xpinc * LoadProperties.endermanXP); xp = (int) (xp * LoadProperties.endermanXP);
break; break;
case GHAST: case GHAST:
xp = (int) (xpinc * LoadProperties.ghastXP); xp = (int) (xp * LoadProperties.ghastXP);
break; break;
case MAGMA_CUBE: case MAGMA_CUBE:
xp = (int) (xpinc * LoadProperties.magmacubeXP); xp = (int) (xp * LoadProperties.magmacubeXP);
break; break;
case PIG_ZOMBIE: case PIG_ZOMBIE:
xp = (int) (xpinc * LoadProperties.pigzombieXP); xp = (int) (xp * LoadProperties.pigzombieXP);
break; break;
case SILVERFISH: case SILVERFISH:
xp = (int) (xpinc * LoadProperties.silverfishXP); xp = (int) (xp * LoadProperties.silverfishXP);
break; break;
case SKELETON: case SKELETON:
xp = (int) (xpinc * LoadProperties.skeletonXP); xp = (int) (xp * LoadProperties.skeletonXP);
break; break;
case SLIME: case SLIME:
xp = (int) (xpinc * LoadProperties.slimeXP); xp = (int) (xp * LoadProperties.slimeXP);
break; break;
case SPIDER: case SPIDER:
xp = (int) (xpinc * LoadProperties.spiderXP); xp = (int) (xp * LoadProperties.spiderXP);
break; break;
case ZOMBIE: case ZOMBIE:
xp = (int) (xpinc * LoadProperties.zombieXP); xp = (int) (xp * LoadProperties.zombieXP);
break;
default:
break; break;
}
} }
} }
return xp; return xp;

View File

@ -42,7 +42,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.getDamage()); int xp = Combat.getXp((LivingEntity) 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)