Archery rework.

This commit is contained in:
GJ 2012-06-13 08:53:18 -04:00
parent 29c629eb22
commit 14d13eb4c7
4 changed files with 65 additions and 65 deletions

View File

@ -1,9 +1,7 @@
package com.gmail.nossr50.skills.archery;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
@ -18,13 +16,13 @@ public class Archery {
public static final int ARROW_TRACKING_MAX_BONUS_LEVEL = 1000;
public static final int BONUS_DAMAGE_INCREASE_LEVEL = 50;
public static final double BONUS_DAMAGE_INCREASE_PERCENT = 0.1D;
public static final double BONUS_DAMAGE_MAX_BONUS_PERCENTAGE = 2.0D;
public static final int DAZE_MAX_BONUS_LEVEL = 1000;
public static final int DAZE_MODIFIER = 4;
// protected static Set<Entry<Entity, Integer>> getEntitySet() {
// return arrowTracker.entrySet();
// }
protected static boolean arrowTrackerContains(LivingEntity livingEntity) {
return arrowTracker.containsKey(livingEntity);
}
@ -43,14 +41,10 @@ public class Archery {
* @param entity The entity hit by the arrows
*/
public static void arrowRetrievalCheck(Entity entity) {
for (Iterator<Entry<LivingEntity, Integer>> it = arrowTracker.entrySet().iterator() ; it.hasNext() ; ) { //This is a wee bit confusing...
Entry<LivingEntity, Integer> entry = it.next();
Integer quantity = arrowTracker.remove(entity);
if (entry.getKey() == entity) { //Shouldn't we be using .equals() here?
Misc.dropItems(entity.getLocation(), new ItemStack(Material.ARROW), entry.getValue());
it.remove();
return;
}
if (quantity != null) {
Misc.dropItems(entity.getLocation(), new ItemStack(Material.ARROW), quantity);
}
}

View File

@ -1,19 +1,10 @@
package com.gmail.nossr50.skills.archery;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
@ -67,22 +58,23 @@ public class ArcheryManager {
}
}
// public void retrieveArrows() {
// if (!permissionsInstance.trackArrows(player)) {
// return;
// }
//
// if ()
// for (Iterator<Map.Entry<Entity, Integer>> it = arrowTracker.entrySet().iterator() ; it.hasNext() ; ) { //This is a wee bit confusing...
// Entry<Entity, Integer> entry = it.next();
//
// if (entry.getKey() == entity) { //Shouldn't we be using .equals() here?
// Misc.dropItems(entity.getLocation(), new ItemStack(Material.ARROW), entry.getValue());
// it.remove();
// return;
// }
// }
// }
/**
* Handle archery bonus damage.
*
* @param event The event to modify.
*/
public void bonusDamage(EntityDamageEvent event) {
if (!permissionsInstance.archeryBonus(player)) {
return;
}
if (skillLevel >= Archery.BONUS_DAMAGE_INCREASE_LEVEL) {
BonusDamageEventHandler eventHandler = new BonusDamageEventHandler(this, event);
eventHandler.calculateDamageBonus();
eventHandler.modifyEventDamage();
}
}
protected int getSkillLevel() {
return skillLevel;

View File

@ -0,0 +1,32 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.event.entity.EntityDamageEvent;
public class BonusDamageEventHandler {
private ArcheryManager manager;
private EntityDamageEvent event;
protected double damageBonusPercent;
protected BonusDamageEventHandler(ArcheryManager manager, EntityDamageEvent event) {
this.manager = manager;
this.event = event;
}
protected void calculateDamageBonus() {
double damageBonus = ((manager.getSkillLevel() / Archery.BONUS_DAMAGE_INCREASE_LEVEL) * Archery.BONUS_DAMAGE_INCREASE_PERCENT);
if (damageBonus > Archery.BONUS_DAMAGE_MAX_BONUS_PERCENTAGE) {
damageBonus = Archery.BONUS_DAMAGE_MAX_BONUS_PERCENTAGE;
}
this.damageBonusPercent = damageBonus;
}
protected void modifyEventDamage() {
int damage = event.getDamage();
int archeryBonus = (int) (damage * damageBonusPercent);
event.setDamage(damage + archeryBonus);
}
}

View File

@ -255,37 +255,19 @@ public class Combat {
}
}
if (permInstance.archery(shooter)) {
if (permInstance.archeryBonus(shooter)) {
/*Archery needs a damage bonus to be viable in PVP*/
int skillLvl = Users.getProfile(shooter).getSkillLevel(SkillType.ARCHERY);
double dmgBonusPercent = ((skillLvl / 50) * 0.1D);
ArcheryManager archeryManager = new ArcheryManager(shooter);
/* Cap maximum bonus at 200% */
if (dmgBonusPercent > 2) {
dmgBonusPercent = 2;
}
archeryManager.bonusDamage(event);
/* Every 50 skill levels Archery gains 10% damage bonus, set that here */
//TODO: Work in progress for balancing out Archery, will work on it more later...
int damage = event.getDamage();
int archeryBonus = (int) (damage * dmgBonusPercent);
if (target instanceof Player) {
archeryManager.dazeCheck((Player) target, event);
}
event.setDamage(damage + archeryBonus);
}
archeryManager.trackArrows(target);
ArcheryManager archeryManager = new ArcheryManager(shooter);
if (target instanceof Player) {
archeryManager.dazeCheck((Player) target, event);
}
archeryManager.trackArrows(target);
if (target != shooter) {
PlayerProfile PP = Users.getProfile(shooter);
startGainXp(shooter, PP, target, SkillType.ARCHERY);
}
if (target != shooter) {
PlayerProfile PP = Users.getProfile(shooter);
startGainXp(shooter, PP, target, SkillType.ARCHERY);
}
}