WIP on Archery rework.

This commit is contained in:
GJ 2012-06-12 21:36:01 -04:00
parent 050b794b42
commit 29c629eb22
7 changed files with 241 additions and 104 deletions

View File

@ -34,7 +34,7 @@ import com.gmail.nossr50.events.fake.FakeEntityDamageEvent;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.combat.Archery;
import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.gathering.BlastMining;
import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.Combat;

View File

@ -0,0 +1,60 @@
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;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.util.Misc;
public class Archery {
private static Random random = new Random();
private static Map<LivingEntity, Integer> arrowTracker = new HashMap<LivingEntity, Integer>();
public static final int ARROW_TRACKING_MAX_BONUS_LEVEL = 1000;
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);
}
protected static void incrementTrackerValue(LivingEntity livingEntity) {
arrowTracker.put(livingEntity, arrowTracker.get(livingEntity) + 1);
}
protected static void addToTracker(LivingEntity livingEntity) {
arrowTracker.put(livingEntity, 1);
}
/**
* Check for arrow retrieval.
*
* @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();
if (entry.getKey() == entity) { //Shouldn't we be using .equals() here?
Misc.dropItems(entity.getLocation(), new ItemStack(Material.ARROW), entry.getValue());
it.remove();
return;
}
}
}
protected static Random getRandom() {
return random;
}
}

View File

@ -0,0 +1,94 @@
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;
public class ArcheryManager {
private Player player;
private PlayerProfile profile;
private int skillLevel;
private Permissions permissionsInstance;
public ArcheryManager (Player player) {
this.player = player;
this.profile = Users.getProfile(player);
this.skillLevel = profile.getSkillLevel(SkillType.TAMING);
this.permissionsInstance = Permissions.getInstance();
}
/**
* Track arrows fired for later retrieval.
*
* @param livingEntity Entity damaged by the arrow
*/
public void trackArrows(LivingEntity livingEntity) {
if (!permissionsInstance.trackArrows(player)) {
return;
}
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
if (Archery.getRandom().nextInt(1000) <= eventHandler.skillModifier) {
eventHandler.addToTracker();
}
}
/**
* Check for Daze.
*
* @param defender Defending player
* @param event The event to modify
*/
public void dazeCheck(Player defender, EntityDamageEvent event) {
if (!permissionsInstance.daze(player)) {
return;
}
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
if (Archery.getRandom().nextInt(2000) <= eventHandler.skillModifier) {
eventHandler.handleDazeEffect();
eventHandler.sendAbilityMessages();
}
}
// 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;
// }
// }
// }
protected int getSkillLevel() {
return skillLevel;
}
protected Player getPlayer() {
return player;
}
}

View File

@ -0,0 +1,32 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.entity.LivingEntity;
import com.gmail.nossr50.util.Misc;
public class ArrowTrackingEventHandler {
private ArcheryManager manager;
private LivingEntity entity;
protected int skillModifier;
protected ArrowTrackingEventHandler (ArcheryManager manager, LivingEntity entity) {
this.manager = manager;
this.entity = entity;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Archery.ARROW_TRACKING_MAX_BONUS_LEVEL);
}
protected void addToTracker() {
if (Archery.arrowTrackerContains(entity)) {
Archery.incrementTrackerValue(entity);
}
else {
Archery.addToTracker(entity);
}
}
}

View File

@ -0,0 +1,47 @@
package com.gmail.nossr50.skills.archery;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
public class DazeEventHandler {
private ArcheryManager manager;
private EntityDamageEvent event;
private Player defender;
protected int skillModifier;
protected DazeEventHandler (ArcheryManager manager, EntityDamageEvent event, Player defender) {
this.manager = manager;
this.event = event;
this.defender = defender;
calculateSkillModifier();
}
protected void calculateSkillModifier() {
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Archery.DAZE_MAX_BONUS_LEVEL);
}
protected void handleDazeEffect() {
Location location = defender.getLocation();
if (Archery.getRandom().nextInt(10) > 5) {
location.setPitch(90);
}
else {
location.setPitch(-90);
}
defender.teleport(location);
event.setDamage(event.getDamage() + Archery.DAZE_MODIFIER);
}
protected void sendAbilityMessages() {
defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy"));
manager.getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
}

View File

@ -1,95 +0,0 @@
package com.gmail.nossr50.skills.combat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Users;
public class Archery {
private static Random random = new Random();
public static Map<Entity, Integer> arrowTracker = new HashMap<Entity, Integer>();
/**
* Track arrows fired for later retrieval.
*
* @param entity Entity damaged by the arrow
* @param PPa PlayerProfile of the player firing the arrow
*/
public static void trackArrows(Entity entity, PlayerProfile PPa) {
final int MAX_BONUS_LEVEL = 1000;
int skillLevel = PPa.getSkillLevel(SkillType.ARCHERY);
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (random.nextInt(1000) <= skillCheck) {
for (Entry<Entity, Integer> entry : arrowTracker.entrySet()) {
if (entry.getKey() == entity) { //Shouldn't we be using .equals() here?
entry.setValue(entry.getValue() + 1);
return;
}
}
arrowTracker.put(entity, 1);
}
}
/**
* Check for Daze.
*
* @param defender Defending player
* @param attacker Attacking player
* @param event The event to modify
*/
public static void dazeCheck(Player defender, Player attacker, EntityDamageByEntityEvent event) {
final int MAX_BONUS_LEVEL = 1000;
int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.ARCHERY);
Location location = defender.getLocation();
int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
if (random.nextInt(10) > 5) {
location.setPitch(90);
}
else {
location.setPitch(-90);
}
if (random.nextInt(2000) <= skillCheck) {
defender.teleport(location);
event.setDamage(event.getDamage() + 4);
defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy"));
attacker.sendMessage(LocaleLoader.getString("Combat.TargetDazed"));
}
}
/**
* Check for arrow retrieval.
*
* @param entity The entity hit by the arrows
*/
public static void arrowRetrievalCheck(Entity entity) {
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;
}
}
}
}

View File

@ -30,7 +30,7 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.GainXp;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.combat.Archery;
import com.gmail.nossr50.skills.archery.ArcheryManager;
import com.gmail.nossr50.skills.combat.Axes;
import com.gmail.nossr50.skills.combat.Swords;
import com.gmail.nossr50.skills.combat.Unarmed;
@ -274,17 +274,16 @@ public class Combat {
event.setDamage(damage + archeryBonus);
}
if (target instanceof Player && permInstance.daze(shooter)) {
Archery.dazeCheck((Player) target, shooter, event);
ArcheryManager archeryManager = new ArcheryManager(shooter);
if (target instanceof Player) {
archeryManager.dazeCheck((Player) target, event);
}
PlayerProfile PP = Users.getProfile(shooter);
if (permInstance.trackArrows(shooter)) {
Archery.trackArrows(target, PP);
}
archeryManager.trackArrows(target);
if (target != shooter) {
PlayerProfile PP = Users.getProfile(shooter);
startGainXp(shooter, PP, target, SkillType.ARCHERY);
}
}