From 1fe259eb7aca08c7286fdf7bc7f2fd0ae98696d7 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 23 Feb 2012 21:13:06 -0500 Subject: [PATCH] Archery optimizations. --- Changelog.txt | 2 +- src/main/java/com/gmail/nossr50/Combat.java | 23 +++---- .../com/gmail/nossr50/skills/Archery.java | 69 ++++++++----------- 3 files changed, 37 insertions(+), 57 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 92b67404b..2eedd80f4 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -24,7 +24,7 @@ Version 1.3.00-dev = Fixed memory leak with mob spawner tracking = Fixed /mcability not respecting permissions = Prettied up new config files - = Optimized repair functions + = Various skill function optimizations ! Changed mcMMO user information to be stored for 2 minutes after log out to reduce lag on rejoins ! Changed the name of Unarmed Apprentice/Mastery to Iron Arm Style ! Changed Unarmed to start with a +3 DMG bonus from Iron Arm Style to make leveling it more viable diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 505a3c3fb..19cd316d7 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -17,7 +17,6 @@ package com.gmail.nossr50; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.*; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; @@ -254,6 +253,7 @@ public class Combat if(PPa.getFistsPreparationMode()) Unarmed.berserkActivationCheck(attacker); } + public static void archeryCheck(EntityDamageByEntityEvent event, mcMMO pluginx) { Arrow arrow = (Arrow)event.getDamager(); @@ -290,20 +290,21 @@ public class Combat { Player attacker = (Player)y; PlayerProfile PPa = Users.getProfile(attacker); - if(mcPermissions.getInstance().archery(attacker)) + int damage = event.getDamage(); + if(mcPermissions.getInstance().archery(attacker) && damage > 0) { - Archery.trackArrows(pluginx, x, event, attacker); + Archery.trackArrows(pluginx, x, PPa); /* * IGNITION */ - Archery.ignitionCheck(x, event, attacker); + Archery.ignitionCheck(x, attacker); /* * Defender is Monster */ if(!pluginx.misc.mobSpawnerList.contains(x.getEntityId())) { - int xp = getXp(event.getEntity(), event); + int xp = getXp(x, event); PPa.addXP(SkillType.ARCHERY, xp*10, attacker); } /* @@ -326,10 +327,9 @@ public class Combat /* * PVP XP */ - if(LoadProperties.pvpxp && !Party.getInstance().inSameParty(attacker, defender) - && ((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) ((event.getDamage() * 2) * 10); + int xp = (int) ((damage * 2) * 10); PPa.addXP(SkillType.ARCHERY, xp, attacker); } /* @@ -390,13 +390,6 @@ public class Combat } } - public static boolean pvpAllowed(EntityDamageByEntityEvent event, World world) - { - if(!event.getEntity().getWorld().getPVP()) - return false; - //If it made it this far, pvp is enabled - return true; - } public static int getXp(Entity entity, EntityDamageEvent event) { int xp = 0; diff --git a/src/main/java/com/gmail/nossr50/skills/Archery.java b/src/main/java/com/gmail/nossr50/skills/Archery.java index 4b7a2bd0e..6f03d4a9e 100644 --- a/src/main/java/com/gmail/nossr50/skills/Archery.java +++ b/src/main/java/com/gmail/nossr50/skills/Archery.java @@ -19,7 +19,6 @@ package com.gmail.nossr50.skills; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.PlayerProfile; @@ -29,34 +28,16 @@ import com.gmail.nossr50.party.Party; public class Archery { - public static void trackArrows(mcMMO pluginx, Entity x, EntityDamageByEntityEvent event, Player attacker) + public static void trackArrows(mcMMO pluginx, Entity x, PlayerProfile PPa) { - PlayerProfile PPa = Users.getProfile(attacker); - if(!pluginx.misc.arrowTracker.containsKey(x) && event.getDamage() > 0) - { + int skillLevel = PPa.getSkillLevel(SkillType.ARCHERY); + if(!pluginx.misc.arrowTracker.containsKey(x)) pluginx.misc.arrowTracker.put(x, 0); - if(attacker != null) - { - if(PPa.getSkillLevel(SkillType.ARCHERY) > 1000 || (Math.random() * 1000 <= PPa.getSkillLevel(SkillType.ARCHERY))) - { - pluginx.misc.arrowTracker.put(x, 1); - } - } - } else - { - if(event.getDamage() > 0) - { - if(attacker != null) - { - if(PPa.getSkillLevel(SkillType.ARCHERY) > 1000 || (Math.random() * 1000 <= PPa.getSkillLevel(SkillType.ARCHERY))) - { - pluginx.misc.arrowTracker.put(x, 1); - } - } - } - } + if(skillLevel > 1000 || (Math.random() * 1000 <= skillLevel)) + pluginx.misc.arrowTracker.put(x, 1); } - public static void ignitionCheck(Entity x, EntityDamageByEntityEvent event, Player attacker) + + public static void ignitionCheck(Entity x, Player attacker) { //Check to see if PVP for this world is disabled before executing if(!x.getWorld().getPVP()) @@ -73,37 +54,43 @@ public class Archery if(x instanceof Player) { - Player Defender = (Player)x; - if(!Party.getInstance().inSameParty(attacker, Defender)) + Player defender = (Player)x; + if(!Party.getInstance().inSameParty(attacker, defender)) { - event.getEntity().setFireTicks(ignition); + defender.setFireTicks(ignition); attacker.sendMessage(mcLocale.getString("Combat.Ignition")); //$NON-NLS-1$ - Defender.sendMessage(mcLocale.getString("Combat.BurningArrowHit")); //$NON-NLS-1$ + defender.sendMessage(mcLocale.getString("Combat.BurningArrowHit")); //$NON-NLS-1$ } - } else { - event.getEntity().setFireTicks(ignition); - attacker.sendMessage(mcLocale.getString("Combat.Ignition")); //$NON-NLS-1$ + } + else + { + x.setFireTicks(ignition); + attacker.sendMessage(mcLocale.getString("Combat.Ignition")); //$NON-NLS-1$ } } } + public static void dazeCheck(Player defender, Player attacker) { - PlayerProfile PPa = Users.getProfile(attacker); + int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.ARCHERY); Location loc = defender.getLocation(); if(Math.random() * 10 > 5) - { - loc.setPitch(90); - } else { + loc.setPitch(90); + else loc.setPitch(-90); - } - if(PPa.getSkillLevel(SkillType.ARCHERY) >= 1000){ - if(Math.random() * 1000 <= 500){ + + if(skillLevel >= 1000) + { + if(Math.random() * 1000 <= 500) + { defender.teleport(loc); defender.sendMessage(mcLocale.getString("Combat.TouchedFuzzy")); //$NON-NLS-1$ attacker.sendMessage(mcLocale.getString("Combat.TargetDazed")); //$NON-NLS-1$ //$NON-NLS-2$ } - } else if(Math.random() * 2000 <= PPa.getSkillLevel(SkillType.ARCHERY)){ + } + else if(Math.random() * 2000 <= skillLevel) + { defender.teleport(loc); defender.sendMessage(mcLocale.getString("Combat.TouchedFuzzy")); //$NON-NLS-1$ attacker.sendMessage(mcLocale.getString("Combat.TargetDazed")); //$NON-NLS-1$ //$NON-NLS-2$