*CLEANUP* - Swords.java

This commit is contained in:
GJ 2012-03-13 15:55:42 -04:00
parent dc6a2b654e
commit 5a54d6e0c5

View File

@ -1,13 +1,16 @@
package com.gmail.nossr50.skills; package com.gmail.nossr50.skills;
import org.bukkit.entity.AnimalTamer;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import com.gmail.nossr50.Combat; import com.gmail.nossr50.Combat;
import com.gmail.nossr50.ItemChecks; import com.gmail.nossr50.ItemChecks;
import com.gmail.nossr50.Users; import com.gmail.nossr50.Users;
import com.gmail.nossr50.m;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.mcPermissions;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
@ -15,125 +18,130 @@ import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.Party;
public class Swords public class Swords {
{
public static void bleedCheck(Player attacker, LivingEntity x, mcMMO pluginx) /**
{ * Check for Bleed effect.
*
* @param attacker The attacking player
* @param entity The defending entity
* @param plugin mcMMO plugin instance
*/
public static void bleedCheck(Player attacker, LivingEntity entity, mcMMO plugin) {
if (entity instanceof Wolf) {
Wolf wolf = (Wolf) entity;
if (wolf.isTamed()) {
AnimalTamer tamer = wolf.getOwner();
if (tamer instanceof Player) {
Player owner = (Player) tamer;
if (owner == attacker || Party.getInstance().inSameParty(attacker, owner)) {
return;
}
}
}
}
final int MAX_BONUS_LEVEL = 750;
PlayerProfile PPa = Users.getProfile(attacker); PlayerProfile PPa = Users.getProfile(attacker);
int skillLevel = PPa.getSkillLevel(SkillType.SWORDS);
int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if(x instanceof Wolf) if (Math.random() * 1000 <= skillCheck && !entity.isDead()) {
{ if (entity instanceof Player) {
Wolf wolf = (Wolf)x; Player target = (Player) entity;
if(wolf.getOwner() instanceof Player) int bleedTicks;
{
Player owner = (Player) wolf.getOwner(); if (skillLevel >= 750) {
if(owner == attacker) bleedTicks = 3;
return;
if(Party.getInstance().inSameParty(attacker, owner))
return;
} }
else {
bleedTicks = 2;
} }
if(mcPermissions.getInstance().swords(attacker) && ItemChecks.isSword(attacker.getItemInHand())){
if(PPa.getSkillLevel(SkillType.SWORDS) >= 750) Users.getProfile(target).addBleedTicks(bleedTicks);
{ }
if(Math.random() * 1000 <= 750) else {
{ plugin.misc.addToBleedQue(entity);
if(!(x instanceof Player))
pluginx.misc.addToBleedQue(x);
if(x instanceof Player)
{
Player target = (Player)x;
Users.getProfile(target).addBleedTicks(3);
} }
attacker.sendMessage(mcLocale.getString("Swords.EnemyBleeding")); attacker.sendMessage(mcLocale.getString("Swords.EnemyBleeding"));
} }
} }
else if (Math.random() * 1000 <= PPa.getSkillLevel(SkillType.SWORDS))
{
if(!(x instanceof Player))
pluginx.misc.addToBleedQue(x);
if(x instanceof Player)
{
Player target = (Player)x;
Users.getProfile(target).addBleedTicks(2);
}
attacker.sendMessage(mcLocale.getString("Swords.EnemyBleeding"));
}
}
}
public static void counterAttackChecks(EntityDamageByEntityEvent event) /**
{ * Counter-attack entities.
//Don't want to counter attack stuff not alive *
* @param event The event to modify
*/
public static void counterAttackChecks(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager();
if(!(event.getDamager() instanceof LivingEntity)) if (!(attacker instanceof LivingEntity)) {
return; return;
}
if(event instanceof EntityDamageByEntityEvent) Entity target = event.getEntity();
{
Entity f = ((EntityDamageByEntityEvent) event).getDamager(); if (target instanceof Player) {
if(event.getEntity() instanceof Player) Player defender = (Player) target;
{
Player defender = (Player)event.getEntity();
PlayerProfile PPd = Users.getProfile(defender); PlayerProfile PPd = Users.getProfile(defender);
if(ItemChecks.isSword(defender.getItemInHand()) && mcPermissions.getInstance().swords(defender))
{ if (ItemChecks.isSword(defender.getItemInHand()) && mcPermissions.getInstance().swords(defender)) {
if(PPd.getSkillLevel(SkillType.SWORDS) >= 600) final int MAX_BONUS_LEVEL = 600;
{ final int COUNTER_ATTACK_MODIFIER = 2;
if(Math.random() * 2000 <= 600)
{ int skillLevel = PPd.getSkillLevel(SkillType.SWORDS);
Combat.dealDamage((LivingEntity) f, event.getDamage() / 2); int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (Math.random() * 2000 <= skillCheck) {
Combat.dealDamage((LivingEntity) attacker, event.getDamage() / COUNTER_ATTACK_MODIFIER);
defender.sendMessage(mcLocale.getString("Swords.CounterAttacked")); defender.sendMessage(mcLocale.getString("Swords.CounterAttacked"));
if(f instanceof Player)
((Player) f).sendMessage(mcLocale.getString("Swords.HitByCounterAttack")); if (attacker instanceof Player) {
} ((Player) attacker).sendMessage(mcLocale.getString("Swords.HitByCounterAttack"));
}
else if (Math.random() * 2000 <= PPd.getSkillLevel(SkillType.SWORDS))
{
Combat.dealDamage((LivingEntity) f, event.getDamage() / 2);
defender.sendMessage(mcLocale.getString("Swords.CounterAttacked"));
if(f instanceof Player)
((Player) f).sendMessage(mcLocale.getString("Swords.HitByCounterAttack"));
} }
} }
} }
} }
} }
public static void bleedSimulate(mcMMO plugin) /**
{ * Simulate a bleed.
//Add items from Que list to BleedTrack list *
* @param plugin mcMMO plugin instance
*/
public static void bleedSimulate(mcMMO plugin) {
for(LivingEntity x : plugin.misc.bleedQue) /* Add items from Que list to BleedTrack list */
{ for (LivingEntity entity : plugin.misc.bleedQue) {
plugin.misc.bleedTracker.add(x); plugin.misc.bleedTracker.add(entity);
} }
//Clear list /* Clear the BleedQue list */
plugin.misc.bleedQue = new LivingEntity[plugin.misc.bleedQue.length]; plugin.misc.bleedQue = new LivingEntity[plugin.misc.bleedQue.length];
plugin.misc.bleedQuePos = 0; plugin.misc.bleedQuePos = 0;
//Cleanup any dead entities from the list /* Cleanup any dead entities from the list */
for(LivingEntity x : plugin.misc.bleedRemovalQue) for(LivingEntity entity : plugin.misc.bleedRemovalQue) {
{ plugin.misc.bleedTracker.remove(entity);
plugin.misc.bleedTracker.remove(x);
} }
//Clear bleed removal list /* Clear bleed removal list */
plugin.misc.bleedRemovalQue = new LivingEntity[plugin.misc.bleedRemovalQue.length]; plugin.misc.bleedRemovalQue = new LivingEntity[plugin.misc.bleedRemovalQue.length];
plugin.misc.bleedRemovalQuePos = 0; plugin.misc.bleedRemovalQuePos = 0;
//Bleed monsters/animals /* Bleed monsters/animals */
for(LivingEntity x : plugin.misc.bleedTracker) for (LivingEntity entity : plugin.misc.bleedTracker) {
{ if (entity == null || entity.isDead()) {
if(x == null || x.isDead()) plugin.misc.addToBleedRemovalQue(entity);
{
plugin.misc.addToBleedRemovalQue(x);
continue; continue;
} }
else else {
{ Combat.dealDamage(entity, 2);
Combat.dealDamage(x, 2);
} }
} }
} }