Rewrote how Arrow Retrieval subskill is handled

This commit is contained in:
nossr50 2019-06-07 01:18:14 -07:00
parent 39b5719e12
commit 80beb92a06
12 changed files with 63 additions and 139 deletions

View File

@ -32,6 +32,7 @@ Version 2.2.0
Acrobatic's Dodge XP increased from 120 -> 480
Fishing's always catch fish setting now defaults to true instead of false
Optimized code related to Fishing
Tracking arrows for Arrow Retrieval with Archery has been rewritten to a much more efficient system
Added a new command 'mcmmoreload' to reload config values
Added new locale string 'Commands.Reload.Start'
Added new locale string 'Commands.Reload.Finished'

View File

@ -6,7 +6,8 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable
public class ConfigExperienceArchery {
public static final double DISTANCE_MULTIPLIER_DEFAULT = 0.025;
private static final double DISTANCE_MULTIPLIER_DEFAULT = 0.025;
private static final double ARROW_FORCE_XP_MULTIPLIER = 2.0D;
@Setting(value = "Distance-Multiplier", comment = "The distance multiplier is multiplied against the distance an " +
"arrow travels before hitting its target to determine final XP values awarded." +
@ -16,6 +17,14 @@ public class ConfigExperienceArchery {
"\nDefault value: " + DISTANCE_MULTIPLIER_DEFAULT)
private double distanceMultiplier = DISTANCE_MULTIPLIER_DEFAULT;
@Setting(value = "Arrow-Force-XP-Multiplier", comment = "How much velocity the arrow has after leaving the players bow is used in the XP formula for handing out Archery XP." +
"\nDefault value: "+ARROW_FORCE_XP_MULTIPLIER)
private double forceMultiplier = ARROW_FORCE_XP_MULTIPLIER;
public double getForceMultiplier() {
return forceMultiplier;
}
public double getDistanceMultiplier() {
return distanceMultiplier;
}

View File

@ -7,17 +7,6 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ConfigSerializable
public class ConfigArchery {
/* ARCHERY */
//
// public double getDazeBonusDamage() {
// return getDoubleValue(SKILLS, ARCHERY, DAZE, BONUS_DAMAGE);
// }
//
// public double getForceMultiplier() {
// return getDoubleValue(SKILLS, ARCHERY, FORCE_MULTIPLIER);
// }
@Setting(value = "Daze")
private ConfigArcheryDaze daze = new ConfigArcheryDaze();
@ -49,6 +38,6 @@ public class ConfigArchery {
}
public double getBonusDamage() {
return daze.getBonusDamage();
return daze.getDazeBonusDamage();
}
}

View File

@ -30,7 +30,7 @@ public class ConfigArcheryDaze {
return maxBonusLevel;
}
public double getBonusDamage() {
public double getDazeBonusDamage() {
return bonusDamage;
}
}

View File

@ -22,6 +22,7 @@ public class MetadataConstants {
public final static String INFINITE_ARROW_METAKEY = "mcMMO: Infinite Arrow";
public final static String BOW_FORCE_METAKEY = "mcMMO: Bow Force";
public final static String ARROW_DISTANCE_METAKEY = "mcMMO: Arrow Distance";
public final static String ARROW_TRACKER_METAKEY = "mcMMO: Arrow Tracker";
public final static String BONUS_DROPS_METAKEY = "mcMMO: Bonus Drops";
public final static String DISARMED_ITEM_METAKEY = "mcMMO: Disarmed Item";
public final static String PLAYER_DATA_METAKEY = "mcMMO: Player Data";

View File

@ -0,0 +1,18 @@
package com.gmail.nossr50.datatypes.meta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class TrackedArrowMeta extends FixedMetadataValue {
/**
* Initializes a FixedMetadataValue with an Object
*
* @param owningPlugin the {@link Plugin} that created this metadata value
* @param value the value assigned to this metadata value
*/
public TrackedArrowMeta(@NotNull Plugin owningPlugin, @Nullable Integer value) {
super(owningPlugin, value);
}
}

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.listeners;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.WorldBlacklist;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
@ -103,7 +102,10 @@ public class EntityListener implements Listener {
projectile.setMetadata(MetadataConstants.INFINITE_ARROW_METAKEY, MetadataConstants.metadataValue);
}
projectile.setMetadata(MetadataConstants.BOW_FORCE_METAKEY, new FixedMetadataValue(plugin, Math.min(event.getForce() * AdvancedConfig.getInstance().getForceMultiplier(), 1.0)));
projectile.setMetadata(MetadataConstants.BOW_FORCE_METAKEY,
new FixedMetadataValue(plugin,
Math.min(event.getForce()
* mcMMO.getConfigManager().getConfigExperience().getExperienceArchery().getForceMultiplier(), 1.0)));
projectile.setMetadata(MetadataConstants.ARROW_DISTANCE_METAKEY, new FixedMetadataValue(plugin, projectile.getLocation()));
}

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.skills.archery;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.core.MetadataConstants;
import com.gmail.nossr50.datatypes.meta.TrackedArrowMeta;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Misc;
@ -9,101 +10,48 @@ import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.metadata.FixedMetadataValue;
public class Archery {
private static List<TrackedEntity> trackedEntities;
private static double skillShotDamageCap;
private static double dazeBonusDamage;
private static double distanceXpMultiplier;
private static Archery archery;
public Archery() {
List<TrackedEntity> trackedEntities = new ArrayList<>();
skillShotDamageCap = AdvancedConfig.getInstance().getSkillShotDamageMax();
dazeBonusDamage = AdvancedConfig.getInstance().getDazeBonusDamage();
distanceXpMultiplier = mcMMO.getConfigManager().getConfigExperience().getDistanceMultiplier();
}
public static Archery getInstance() {
if (archery == null)
archery = new Archery();
return archery;
}
protected static void incrementTrackerValue(LivingEntity livingEntity) {
for (TrackedEntity trackedEntity : trackedEntities) {
if (trackedEntity.getLivingEntity().getEntityId() == livingEntity.getEntityId()) {
trackedEntity.incrementArrowCount();
return;
}
}
addToTracker(livingEntity); // If the entity isn't tracked yet
}
protected static void addToTracker(LivingEntity livingEntity) {
TrackedEntity trackedEntity = new TrackedEntity(livingEntity);
trackedEntity.incrementArrowCount();
trackedEntities.add(trackedEntity);
}
protected static void removeFromTracker(TrackedEntity trackedEntity) {
trackedEntities.remove(trackedEntity);
}
/**
* Check for arrow retrieval.
*
* @param livingEntity The entity hit by the arrows
*/
public static void arrowRetrievalCheck(LivingEntity livingEntity) {
for (Iterator<TrackedEntity> entityIterator = trackedEntities.iterator(); entityIterator.hasNext(); ) {
TrackedEntity trackedEntity = entityIterator.next();
if (trackedEntity.getID() == livingEntity.getUniqueId()) {
Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), trackedEntity.getArrowCount());
entityIterator.remove();
return;
if(livingEntity.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) {
Misc.dropItems(livingEntity.getLocation(), new ItemStack(Material.ARROW), livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).get(0).asInt());
}
}
public static void incrementArrowCount(LivingEntity livingEntity) {
if(livingEntity.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) {
int arrowCount = livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).get(0).asInt();
livingEntity.getMetadata(MetadataConstants.ARROW_TRACKER_METAKEY).set(0, new FixedMetadataValue(mcMMO.p, arrowCount + 1));
} else {
livingEntity.setMetadata(MetadataConstants.ARROW_TRACKER_METAKEY, new TrackedArrowMeta(mcMMO.p, 1));
}
}
public static double getSkillShotBonusDamage(Player player, double oldDamage) {
double damageBonusPercent = getDamageBonusPercent(player);
double newDamage = oldDamage + (oldDamage * damageBonusPercent);
return Math.min(newDamage, Archery.skillShotDamageCap);
return Math.min(newDamage, getSkillShotDamageCap());
}
public static double getDamageBonusPercent(Player player) {
return ((RankUtils.getRank(player, SubSkillType.ARCHERY_SKILL_SHOT)) * AdvancedConfig.getInstance().getSkillShotRankDamageMultiplier()) / 100.0D;
return ((RankUtils.getRank(player, SubSkillType.ARCHERY_SKILL_SHOT)) * mcMMO.getConfigManager().getConfigArchery().getSkillShotDamageMultiplier()) / 100.0D;
}
public List<TrackedEntity> getTrackedEntities() {
return trackedEntities;
public static double getSkillShotDamageCap() {
return mcMMO.getConfigManager().getConfigArchery().getSkillShotDamageCeiling();
}
public double getSkillShotDamageCap() {
return skillShotDamageCap;
public static double getDazeBonusDamage() {
return mcMMO.getConfigManager().getConfigArchery().getDaze().getDazeBonusDamage();
}
public double getDazeBonusDamage() {
return dazeBonusDamage;
}
public double getDistanceXpMultiplier() {
return distanceXpMultiplier;
public static double getDistanceXpMultiplier() {
return mcMMO.getConfigManager().getConfigExperience().getExperienceArchery().getDistanceMultiplier();
}
}

View File

@ -59,7 +59,7 @@ public class ArcheryManager extends SkillManager {
return 1;
}
return 1 + Math.min(firedLocation.distance(targetLocation), 50) * Archery.getInstance().getDistanceXpMultiplier();
return 1 + Math.min(firedLocation.distance(targetLocation), 50) * Archery.getDistanceXpMultiplier();
}
/**
@ -67,9 +67,9 @@ public class ArcheryManager extends SkillManager {
*
* @param target The {@link LivingEntity} damaged by the arrow
*/
public void retrieveArrows(LivingEntity target) {
public void processArrowRetrievalActivation(LivingEntity target) {
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_ARROW_RETRIEVAL, getPlayer())) {
Archery.incrementTrackerValue(target);
Archery.incrementArrowCount(target);
}
}
@ -98,7 +98,7 @@ public class ArcheryManager extends SkillManager {
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Combat.TargetDazed");
}
return Archery.getInstance().getDazeBonusDamage();
return Archery.getDazeBonusDamage();
}
/**

View File

@ -1,44 +0,0 @@
package com.gmail.nossr50.skills.archery;
import com.gmail.nossr50.mcMMO;
import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.UUID;
public class TrackedEntity extends BukkitRunnable {
private LivingEntity livingEntity;
private UUID id;
private int arrowCount;
protected TrackedEntity(LivingEntity livingEntity) {
this.livingEntity = livingEntity;
this.id = livingEntity.getUniqueId();
this.runTaskTimer(mcMMO.p, 12000, 12000);
}
@Override
public void run() {
if (!livingEntity.isValid()) {
Archery.removeFromTracker(this);
this.cancel();
}
}
protected LivingEntity getLivingEntity() {
return livingEntity;
}
protected UUID getID() {
return id;
}
protected int getArrowCount() {
return arrowCount;
}
protected void incrementArrowCount() {
arrowCount++;
}
}

View File

@ -105,7 +105,7 @@ public final class Misc {
return null;
}
return location.getWorld().dropItem(location, itemStack);
return location.getWorld().dropItemNaturally(location, itemStack);
}
public static void profileCleanup(String playerName) {

View File

@ -218,7 +218,7 @@ public final class CombatUtils {
}
if (!arrow.hasMetadata(MetadataConstants.INFINITE_ARROW_METAKEY) && archeryManager.canRetrieveArrows()) {
archeryManager.retrieveArrows(target);
archeryManager.processArrowRetrievalActivation(target);
}
if (canUseLimitBreak(player, SubSkillType.ARCHERY_ARCHERY_LIMIT_BREAK)) {