More work on xbows

This commit is contained in:
nossr50 2020-07-28 18:17:57 -07:00
parent 515d58f04f
commit 3ca06f2518
7 changed files with 111 additions and 36 deletions

View File

@ -113,7 +113,7 @@ public enum SubSkillType {
/* CROSSBOWS */ /* CROSSBOWS */
CROSSBOWS_CONE_OF_DEATH(8), CROSSBOWS_CONE_OF_DEATH(3),
CROSSBOWS_CROSSBOWS_LIMIT_BREAK(10); CROSSBOWS_CROSSBOWS_LIMIT_BREAK(10);

View File

@ -125,12 +125,18 @@ public class EntityListener implements Listener {
projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, projectile.getLocation())); projectile.setMetadata(mcMMO.arrowDistanceKey, new FixedMetadataValue(plugin, projectile.getLocation()));
} }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(ProjectileLaunchEvent event) { public void onProjectileLaunch(ProjectileLaunchEvent event) {
/* WORLD BLACKLIST CHECK */ /* WORLD BLACKLIST CHECK */
if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld())) if(WorldBlacklist.isWorldBlacklisted(event.getEntity().getWorld()))
return; return;
if(mcMMO.getSpawnedProjectileTracker().isSpawnedProjectile(event.getEntity())) {
mcMMO.getSpawnedProjectileTracker().untrackProjectile(event.getEntity());
return;
}
if(event.getEntity().getShooter() instanceof Player) if(event.getEntity().getShooter() instanceof Player)
{ {
Player player = (Player) event.getEntity().getShooter(); Player player = (Player) event.getEntity().getShooter();

View File

@ -80,6 +80,7 @@ public class mcMMO extends JavaPlugin {
private static MaterialMapStore materialMapStore; private static MaterialMapStore materialMapStore;
private static PlayerLevelUtils playerLevelUtils; private static PlayerLevelUtils playerLevelUtils;
private static SmeltingTracker smeltingTracker; private static SmeltingTracker smeltingTracker;
private static SpawnedProjectileTracker spawnedProjectileTracker;
/* Blacklist */ /* Blacklist */
private static WorldBlacklist worldBlacklist; private static WorldBlacklist worldBlacklist;
@ -271,6 +272,9 @@ public class mcMMO extends JavaPlugin {
//Init smelting tracker //Init smelting tracker
smeltingTracker = new SmeltingTracker(); smeltingTracker = new SmeltingTracker();
//Init spawned projectile tracker
spawnedProjectileTracker = new SpawnedProjectileTracker();
} }
public static PlayerLevelUtils getPlayerLevelUtils() { public static PlayerLevelUtils getPlayerLevelUtils() {
@ -679,4 +683,8 @@ public class mcMMO extends JavaPlugin {
public static SmeltingTracker getSmeltingTracker() { public static SmeltingTracker getSmeltingTracker() {
return smeltingTracker; return smeltingTracker;
} }
public static SpawnedProjectileTracker getSpawnedProjectileTracker() {
return spawnedProjectileTracker;
}
} }

View File

@ -7,6 +7,8 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.skills.RankUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -14,11 +16,17 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Random;
public class CrossbowManager extends SkillManager { public class CrossbowManager extends SkillManager {
public CrossbowManager(McMMOPlayer mcMMOPlayer) { public CrossbowManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, PrimarySkillType.CROSSBOWS); super(mcMMOPlayer, PrimarySkillType.CROSSBOWS);
} }
private static final int SPREAD_VALUE = 12;
/** /**
* Calculate bonus XP awarded for Archery when hitting a far-away target. * Calculate bonus XP awarded for Archery when hitting a far-away target.
@ -57,10 +65,47 @@ public class CrossbowManager extends SkillManager {
private void coneOfDeathProcessing(ProjectileLaunchEvent projectileLaunchEvent) { private void coneOfDeathProcessing(ProjectileLaunchEvent projectileLaunchEvent) {
Projectile mainProjectile = projectileLaunchEvent.getEntity(); spawnConeArrows(projectileLaunchEvent.getEntity());
World world = mainProjectile.getWorld(); }
private void spawnConeArrows(@NotNull Projectile originProjectile) {
World world = originProjectile.getWorld();
Vector originVector = originProjectile.getVelocity().clone();
float originProjectileMagnitude = (float) originVector.length();
Vector originUnitVector = originVector.clone().normalize();
for(int i = 0; i < getConeOfDeathProjectileCount(); i++) {
Vector newProjectileVector = byRotateVector(originUnitVector, 0);
spawnTrackedProjectile(originProjectile, world, originProjectileMagnitude, newProjectileVector, getRandomizedSpreadValue());
}
}
private int getConeOfDeathProjectileCount() {
switch(RankUtils.getRank(mcMMOPlayer.getPlayer(), SubSkillType.CROSSBOWS_CONE_OF_DEATH)) {
case 1:
return 9;
case 2:
return 18;
default:
return 27;
}
}
private int getRandomizedSpreadValue() {
return SPREAD_VALUE + 12 + RandomUtils.nextInt(24);
}
private void spawnTrackedProjectile(@NotNull Projectile originProjectile, World world, float originProjectileMagnitude, Vector additionalProjectileVectorA, int spreadValue) {
Projectile spawnedProjectile = world.spawnArrow(originProjectile.getLocation(), additionalProjectileVectorA, originProjectileMagnitude, spreadValue);
spawnedProjectile.setShooter(mcMMOPlayer.getPlayer());
mcMMO.getSpawnedProjectileTracker().trackProjectile(spawnedProjectile);
}
@NotNull
private Vector byRotateVector(Vector originUnitVector, double angle) {
return originUnitVector.clone().rotateAroundAxis(originUnitVector, angle);
} }

View File

@ -62,22 +62,22 @@ public final class ItemUtils {
return mcMMO.getMaterialMapStore().isTrident(itemStack.getType().getKey().getKey()); return mcMMO.getMaterialMapStore().isTrident(itemStack.getType().getKey().getKey());
} }
public static void registerTridentRecipes() { // public static void registerTridentRecipes() {
Material tridentMaterial = Material.getMaterial("trident"); //// Material tridentMaterial = Material.getMaterial("trident");
if(tridentMaterial != null) { //// if(tridentMaterial != null) {
ItemStack weakTridentIS = new ItemStack(tridentMaterial); //// ItemStack weakTridentIS = new ItemStack(tridentMaterial);
NamespacedKey weakTridentNamespacedKey = new NamespacedKey(mcMMO.p, "mcmmo:weak_trident"); //// NamespacedKey weakTridentNamespacedKey = new NamespacedKey(mcMMO.p, "mcmmo:weak_trident");
////
ShapedRecipe weakTridentRecipe = new ShapedRecipe(weakTridentNamespacedKey, weakTridentIS); //// ShapedRecipe weakTridentRecipe = new ShapedRecipe(weakTridentNamespacedKey, weakTridentIS);
////
weakTridentRecipe. //// weakTridentRecipe.
Bukkit.addRecipe(weakTridentRecipe); //// Bukkit.addRecipe(weakTridentRecipe);
} //// }
if(Material.getMaterial("trident") == null) { //// if(Material.getMaterial("trident") == null) {
return; //// return;
} //// }
//
} // }

View File

@ -0,0 +1,26 @@
package com.gmail.nossr50.util;
import org.bukkit.entity.Projectile;
import java.util.HashSet;
import java.util.Set;
public class SpawnedProjectileTracker {
private final Set<Projectile> trackedProjectiles;
public SpawnedProjectileTracker() {
trackedProjectiles = new HashSet<>();
}
public void trackProjectile(Projectile projectile) {
trackedProjectiles.add(projectile);
}
public void untrackProjectile(Projectile projectile) {
trackedProjectiles.remove(projectile);
}
public boolean isSpawnedProjectile(Projectile projectile) {
return trackedProjectiles.contains(projectile);
}
}

View File

@ -732,20 +732,10 @@ Crossbows:
Rank_10: 1000 Rank_10: 1000
ConeOfDeath: ConeOfDeath:
Standard: Standard:
Rank_1: 10 Rank_1: 1
Rank_2: 25 Rank_2: 50
Rank_3: 35 Rank_3: 100
Rank_4: 50
Rank_5: 65
Rank_6: 75
Rank_7: 85
Rank_8: 100
RetroMode: RetroMode:
Rank_1: 100 Rank_1: 10
Rank_2: 250 Rank_2: 500
Rank_3: 350 Rank_3: 1000
Rank_4: 500
Rank_5: 650
Rank_6: 750
Rank_7: 850
Rank_8: 1000