2012-06-13 03:36:01 +02:00
|
|
|
package com.gmail.nossr50.skills.archery;
|
|
|
|
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
2012-06-13 14:54:02 +02:00
|
|
|
|
2012-06-13 03:36:01 +02:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
|
|
|
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);
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-08-14 23:09:49 +02:00
|
|
|
//Compatibility with Citizens, Citizens NPCs won't create a profile so we'll check for it here
|
|
|
|
if(this.profile == null)
|
|
|
|
return;
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-06-15 02:06:06 +02:00
|
|
|
this.skillLevel = profile.getSkillLevel(SkillType.ARCHERY);
|
2012-06-13 03:36:01 +02:00
|
|
|
this.permissionsInstance = Permissions.getInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Track arrows fired for later retrieval.
|
|
|
|
*
|
|
|
|
* @param livingEntity Entity damaged by the arrow
|
|
|
|
*/
|
|
|
|
public void trackArrows(LivingEntity livingEntity) {
|
2012-10-30 19:46:52 +01:00
|
|
|
if(player == null)
|
|
|
|
return;
|
|
|
|
|
2012-10-30 21:14:22 +01:00
|
|
|
if(permissionsInstance == null)
|
|
|
|
return;
|
|
|
|
|
2012-06-13 03:36:01 +02:00
|
|
|
if (!permissionsInstance.trackArrows(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
|
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
int randomChance = 100;
|
2012-07-02 17:09:55 +02:00
|
|
|
if (player.hasPermission("mcmmo.perks.lucky.archery")) {
|
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
2013-01-01 23:12:15 +01:00
|
|
|
final float chance = (float) (((double) Archery.ARROW_TRACKING_MAX_BONUS / (double) Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * skillLevel);
|
2012-11-21 21:49:54 +01:00
|
|
|
if (chance > Archery.getRandom().nextInt(randomChance)) {
|
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) {
|
2012-10-30 19:46:52 +01:00
|
|
|
if(player == null)
|
|
|
|
return;
|
|
|
|
|
2012-10-30 21:14:22 +01:00
|
|
|
if(permissionsInstance == null)
|
|
|
|
return;
|
|
|
|
|
2012-06-13 03:36:01 +02:00
|
|
|
if (!permissionsInstance.daze(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
int randomChance = 100;
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-07-02 17:09:55 +02:00
|
|
|
if (player.hasPermission("mcmmo.perks.lucky.archery")) {
|
|
|
|
randomChance = (int) (randomChance * 0.75);
|
|
|
|
}
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2013-01-01 23:12:15 +01:00
|
|
|
final float chance = (float) (((double) Archery.DAZE_MAX_BONUS / (double) Archery.DAZE_MAX_BONUS_LEVEL) * skillLevel);
|
2012-11-21 21:49:54 +01:00
|
|
|
if (chance > Archery.getRandom().nextInt(randomChance)) {
|
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.
|
|
|
|
*/
|
|
|
|
public void bonusDamage(EntityDamageEvent event) {
|
2012-10-30 19:46:52 +01:00
|
|
|
if(player == null)
|
|
|
|
return;
|
|
|
|
|
2012-10-30 21:14:22 +01:00
|
|
|
if(permissionsInstance == null)
|
|
|
|
return;
|
|
|
|
|
2012-06-13 14:53:18 +02:00
|
|
|
if (!permissionsInstance.archeryBonus(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skillLevel >= Archery.BONUS_DAMAGE_INCREASE_LEVEL) {
|
2012-06-15 05:29:08 +02:00
|
|
|
ArcheryBonusDamageEventHandler eventHandler = new ArcheryBonusDamageEventHandler(this, event);
|
2012-06-13 14:53:18 +02:00
|
|
|
|
|
|
|
eventHandler.calculateDamageBonus();
|
|
|
|
eventHandler.modifyEventDamage();
|
|
|
|
}
|
|
|
|
}
|
2012-06-13 03:36:01 +02:00
|
|
|
|
|
|
|
protected int getSkillLevel() {
|
|
|
|
return skillLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Player getPlayer() {
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|