mcMMO/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java

116 lines
3.4 KiB
Java
Raw Normal View History

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;
public ArcheryManager (Player player) {
this.player = player;
this.profile = Users.getProfile(player);
2012-12-24 22:56:25 +01: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
}
/**
* Track arrows fired for later retrieval.
*
* @param livingEntity Entity damaged by the arrow
*/
public void trackArrows(LivingEntity livingEntity) {
if(player == null)
return;
2013-01-07 02:52:31 +01:00
if (!Permissions.trackArrows(player)) {
2012-06-13 03:36:01 +02:00
return;
}
ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
2012-11-21 21:49:54 +01:00
int randomChance = 100;
2013-01-07 02:52:31 +01:00
if (Permissions.luckyArchery(player)) {
randomChance = (int) (randomChance * 0.75);
}
float chance = (float) (((double) Archery.ARROW_TRACKING_MAX_BONUS / (double) Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * skillLevel);
if (chance > Archery.ARROW_TRACKING_MAX_BONUS) chance = Archery.ARROW_TRACKING_MAX_BONUS;
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) {
if(player == null)
return;
2013-01-07 02:52:31 +01:00
if (!Permissions.daze(player)) {
2012-06-13 03:36:01 +02:00
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
2013-01-07 02:52:31 +01:00
if (Permissions.luckyArchery(player)) {
randomChance = (int) (randomChance * 0.75);
}
2012-12-24 22:56:25 +01:00
float chance = (float) (((double) Archery.DAZE_MAX_BONUS / (double) Archery.DAZE_MAX_BONUS_LEVEL) * skillLevel);
if (chance > Archery.DAZE_MAX_BONUS) chance = Archery.DAZE_MAX_BONUS;
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) {
if(player == null)
return;
2013-01-07 02:52:31 +01:00
if (!Permissions.archeryBonus(player)) {
2012-06-13 14:53:18 +02:00
return;
}
if (skillLevel >= Archery.BONUS_DAMAGE_INCREASE_LEVEL) {
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;
}
}