mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-23 13:46:46 +01:00
Archery cleanup.
This commit is contained in:
parent
08b46e1a7c
commit
f3c89fe48b
@ -6,6 +6,7 @@ import org.bukkit.event.entity.EntityDamageEvent;
|
|||||||
|
|
||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||||
import com.gmail.nossr50.datatypes.SkillType;
|
import com.gmail.nossr50.datatypes.SkillType;
|
||||||
|
import com.gmail.nossr50.util.Misc;
|
||||||
import com.gmail.nossr50.util.Permissions;
|
import com.gmail.nossr50.util.Permissions;
|
||||||
import com.gmail.nossr50.util.Users;
|
import com.gmail.nossr50.util.Users;
|
||||||
|
|
||||||
@ -17,11 +18,6 @@ public class ArcheryManager {
|
|||||||
public ArcheryManager (Player player) {
|
public ArcheryManager (Player player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.profile = Users.getProfile(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;
|
|
||||||
|
|
||||||
this.skillLevel = profile.getSkillLevel(SkillType.ARCHERY);
|
this.skillLevel = profile.getSkillLevel(SkillType.ARCHERY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +27,7 @@ public class ArcheryManager {
|
|||||||
* @param livingEntity Entity damaged by the arrow
|
* @param livingEntity Entity damaged by the arrow
|
||||||
*/
|
*/
|
||||||
public void trackArrows(LivingEntity livingEntity) {
|
public void trackArrows(LivingEntity livingEntity) {
|
||||||
if(player == null)
|
if (Misc.isCitizensNPC(player) || !Permissions.trackArrows(player)) {
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Permissions.trackArrows(player)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +38,7 @@ public class ArcheryManager {
|
|||||||
randomChance = (int) (randomChance * 0.75);
|
randomChance = (int) (randomChance * 0.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
float chance = (float) (((double) Archery.ARROW_TRACKING_MAX_BONUS / (double) Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * skillLevel);
|
float chance = ((float) Archery.ARROW_TRACKING_MAX_BONUS / Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
||||||
if (chance > Archery.ARROW_TRACKING_MAX_BONUS) chance = Archery.ARROW_TRACKING_MAX_BONUS;
|
|
||||||
|
|
||||||
if (chance > Archery.getRandom().nextInt(randomChance)) {
|
if (chance > Archery.getRandom().nextInt(randomChance)) {
|
||||||
eventHandler.addToTracker();
|
eventHandler.addToTracker();
|
||||||
@ -60,23 +52,18 @@ public class ArcheryManager {
|
|||||||
* @param event The event to modify
|
* @param event The event to modify
|
||||||
*/
|
*/
|
||||||
public void dazeCheck(Player defender, EntityDamageEvent event) {
|
public void dazeCheck(Player defender, EntityDamageEvent event) {
|
||||||
if(player == null)
|
if (Misc.isCitizensNPC(player) || !Permissions.daze(player)) {
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Permissions.daze(player)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
|
DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
|
||||||
|
|
||||||
int randomChance = 100;
|
int randomChance = 100;
|
||||||
|
|
||||||
if (Permissions.luckyArchery(player)) {
|
if (Permissions.luckyArchery(player)) {
|
||||||
randomChance = (int) (randomChance * 0.75);
|
randomChance = (int) (randomChance * 0.75);
|
||||||
}
|
}
|
||||||
|
|
||||||
float chance = (float) (((double) Archery.DAZE_MAX_BONUS / (double) Archery.DAZE_MAX_BONUS_LEVEL) * skillLevel);
|
float chance = ((float) Archery.DAZE_MAX_BONUS / Archery.DAZE_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
|
||||||
if (chance > Archery.DAZE_MAX_BONUS) chance = Archery.DAZE_MAX_BONUS;
|
|
||||||
|
|
||||||
if (chance > Archery.getRandom().nextInt(randomChance)) {
|
if (chance > Archery.getRandom().nextInt(randomChance)) {
|
||||||
eventHandler.handleDazeEffect();
|
eventHandler.handleDazeEffect();
|
||||||
@ -90,10 +77,7 @@ public class ArcheryManager {
|
|||||||
* @param event The event to modify.
|
* @param event The event to modify.
|
||||||
*/
|
*/
|
||||||
public void bonusDamage(EntityDamageEvent event) {
|
public void bonusDamage(EntityDamageEvent event) {
|
||||||
if(player == null)
|
if (Misc.isCitizensNPC(player) || !Permissions.archeryBonus(player)) {
|
||||||
return;
|
|
||||||
|
|
||||||
if (!Permissions.archeryBonus(player)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ public class DazeEventHandler {
|
|||||||
private EntityDamageEvent event;
|
private EntityDamageEvent event;
|
||||||
private Player defender;
|
private Player defender;
|
||||||
|
|
||||||
|
private final static int DAZE_CHANCE = 50;
|
||||||
|
|
||||||
protected int skillModifier;
|
protected int skillModifier;
|
||||||
|
|
||||||
protected DazeEventHandler (ArcheryManager manager, EntityDamageEvent event, Player defender) {
|
protected DazeEventHandler (ArcheryManager manager, EntityDamageEvent event, Player defender) {
|
||||||
@ -29,7 +31,7 @@ public class DazeEventHandler {
|
|||||||
protected void handleDazeEffect() {
|
protected void handleDazeEffect() {
|
||||||
Location location = defender.getLocation();
|
Location location = defender.getLocation();
|
||||||
|
|
||||||
if (Archery.getRandom().nextInt(10) > 5) {
|
if (Archery.getRandom().nextInt(100) > DAZE_CHANCE) {
|
||||||
location.setPitch(90);
|
location.setPitch(90);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -11,14 +11,14 @@ public class TrackedEntity implements Runnable {
|
|||||||
private int previousTicksLived;
|
private int previousTicksLived;
|
||||||
private int taskId;
|
private int taskId;
|
||||||
|
|
||||||
public TrackedEntity(LivingEntity livingEntity) {
|
protected TrackedEntity(LivingEntity livingEntity) {
|
||||||
this.livingEntity = livingEntity;
|
this.livingEntity = livingEntity;
|
||||||
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
|
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(mcMMO.p, this, 12000, 12000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//LivingEntity.isDead() isn't a reliable way to know if an entity is still active
|
//LivingEntity.isDead() isn't a reliable way to know if an entity is still active
|
||||||
//This method must not be called more than once per server tick
|
//This method must not be called more than once per server tick
|
||||||
public boolean isActive() {
|
private boolean isActive() {
|
||||||
int currentTicksLived = livingEntity.getTicksLived();
|
int currentTicksLived = livingEntity.getTicksLived();
|
||||||
|
|
||||||
if (currentTicksLived == previousTicksLived) {
|
if (currentTicksLived == previousTicksLived) {
|
||||||
@ -29,15 +29,15 @@ public class TrackedEntity implements Runnable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LivingEntity getLivingEntity() {
|
protected LivingEntity getLivingEntity() {
|
||||||
return livingEntity;
|
return livingEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getArrowCount() {
|
protected int getArrowCount() {
|
||||||
return arrowCount;
|
return arrowCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementArrowCount() {
|
protected void incrementArrowCount() {
|
||||||
arrowCount++;
|
arrowCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user