2012-06-13 03:36:01 +02:00
|
|
|
package com.gmail.nossr50.skills.archery;
|
|
|
|
|
2013-01-29 07:58:03 +01:00
|
|
|
import org.bukkit.Location;
|
2012-06-13 03:36:01 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2012-06-13 14:54:02 +02:00
|
|
|
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2013-01-10 15:26:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2013-01-08 23:44:05 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-06-13 03:36:01 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
|
2013-01-10 15:26:01 +01:00
|
|
|
public class ArcheryManager extends SkillManager {
|
2013-02-01 06:38:25 +01:00
|
|
|
public ArcheryManager (McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.ARCHERY);
|
2012-06-13 03:36:01 +02:00
|
|
|
}
|
|
|
|
|
2013-01-29 07:58:03 +01:00
|
|
|
public void distanceXpBonus(LivingEntity target) {
|
2013-02-01 06:38:25 +01:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2013-02-03 01:07:05 +01:00
|
|
|
Location shooterLocation = player.getLocation();
|
2013-01-29 07:58:03 +01:00
|
|
|
Location targetLocation = target.getLocation();
|
2013-02-03 01:07:05 +01:00
|
|
|
|
|
|
|
if (!shooterLocation.getWorld().equals(targetLocation.getWorld())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-29 16:55:06 +01:00
|
|
|
double squaredDistance = shooterLocation.distanceSquared(targetLocation);
|
2013-01-29 07:58:03 +01:00
|
|
|
|
2013-02-03 01:07:05 +01:00
|
|
|
// Cap distance at 100^2 to prevent teleport exploit.
|
|
|
|
// TODO: Better way to handle this would be great...
|
|
|
|
if (squaredDistance > 10000) {
|
|
|
|
squaredDistance = 10000;
|
|
|
|
}
|
|
|
|
|
2013-01-29 16:55:06 +01:00
|
|
|
int bonusXp = (int) (squaredDistance * Archery.distanceXpModifer);
|
2013-02-01 06:38:25 +01:00
|
|
|
mcMMOPlayer.addXp(SkillType.ARCHERY, bonusXp);
|
2013-01-29 07:58:03 +01:00
|
|
|
}
|
|
|
|
|
2012-06-13 03:36:01 +02:00
|
|
|
/**
|
|
|
|
* Track arrows fired for later retrieval.
|
|
|
|
*
|
|
|
|
* @param livingEntity Entity damaged by the arrow
|
|
|
|
*/
|
|
|
|
public void trackArrows(LivingEntity livingEntity) {
|
|
|
|
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
|
|
|
|
|
2013-01-14 18:41:39 +01:00
|
|
|
double chance = (Archery.retrieveMaxChance / Archery.retrieveMaxBonusLevel) * eventHandler.skillModifier;
|
2013-01-02 00:34:32 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
2012-06-13 03:36:01 +02:00
|
|
|
eventHandler.addToTracker();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for Daze.
|
|
|
|
*
|
|
|
|
* @param defender Defending player
|
|
|
|
* @param event The event to modify
|
|
|
|
*/
|
|
|
|
public void dazeCheck(Player defender, EntityDamageEvent event) {
|
|
|
|
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2013-01-14 18:41:39 +01:00
|
|
|
double chance = (Archery.dazeMaxBonus / Archery.dazeMaxBonusLevel) * eventHandler.skillModifier;
|
2013-01-02 00:34:32 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
2012-11-26 01:40:42 +01:00
|
|
|
eventHandler.handleDazeEffect();
|
|
|
|
eventHandler.sendAbilityMessages();
|
2012-06-13 03:36:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-13 14:53:18 +02:00
|
|
|
/**
|
|
|
|
* Handle archery bonus damage.
|
|
|
|
*
|
|
|
|
* @param event The event to modify.
|
|
|
|
*/
|
2013-01-14 18:41:39 +01:00
|
|
|
public void skillShot(EntityDamageEvent event) {
|
2013-02-01 06:38:25 +01:00
|
|
|
if (skillLevel >= Archery.skillShotIncreaseLevel && Permissions.archeryBonus(mcMMOPlayer.getPlayer())) {
|
2013-01-14 18:41:39 +01:00
|
|
|
SkillShotEventHandler eventHandler = new SkillShotEventHandler(this, event);
|
2012-06-13 14:53:18 +02:00
|
|
|
|
|
|
|
eventHandler.calculateDamageBonus();
|
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
}
|
|
|
|
}
|
2012-06-13 03:36:01 +02:00
|
|
|
}
|