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

130 lines
4.0 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-11-21 21:49:54 +01:00
import com.gmail.nossr50.config.AdvancedConfig;
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 {
2012-11-26 01:40:42 +01:00
AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
2012-06-13 03:36:01 +02:00
private Player player;
private PlayerProfile profile;
private int skillLevel;
private Permissions permissionsInstance;
2012-11-26 01:40:42 +01:00
private float dazeBonusMax = advancedConfig.getDazeBonusMax();
private float dazeMaxBonusLevel = advancedConfig.getDazeMaxBonusLevel();
private float retrieveBonusMax = advancedConfig.getRetrieveBonusMax();
private float retrieveMaxBonusLevel = advancedConfig.getRetrieveMaxBonusLevel();
2012-06-13 03:36:01 +02:00
public ArcheryManager (Player player) {
this.player = player;
this.profile = Users.getProfile(player);
//Compatibility with Citizens, Citizens NPCs won't create a profile so we'll check for it here
if(this.profile == null)
return;
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) {
if(player == null)
return;
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;
if (player.hasPermission("mcmmo.perks.lucky.archery")) {
randomChance = (int) (randomChance * 0.75);
}
2012-11-26 01:40:42 +01:00
final float chance = (float) (((double) retrieveBonusMax / (double) retrieveMaxBonusLevel) * (double) 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) {
if(player == null)
return;
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-11-21 21:49:54 +01:00
int randomChance = 100;
if (player.hasPermission("mcmmo.perks.lucky.archery")) {
randomChance = (int) (randomChance * 0.75);
}
2012-11-21 21:49:54 +01:00
2012-11-26 01:40:42 +01:00
final float chance = (float) (((double) dazeBonusMax / (double) dazeMaxBonusLevel) * (double) 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) {
if(player == null)
return;
if(permissionsInstance == null)
return;
2012-06-13 14:53:18 +02:00
if (!permissionsInstance.archeryBonus(player)) {
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;
}
}