wip super shotgun

This commit is contained in:
nossr50 2024-02-03 16:05:53 -08:00
parent b0c42f8e44
commit 2271bd5236
5 changed files with 92 additions and 22 deletions

View File

@ -25,6 +25,7 @@ import com.gmail.nossr50.party.ShareHandler;
import com.gmail.nossr50.runnables.skills.AbilityCooldownTask;
import com.gmail.nossr50.runnables.skills.AbilityDisableTask;
import com.gmail.nossr50.runnables.skills.ToolLowerTask;
import com.gmail.nossr50.skills.AlternateFiringSuperSkill;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.alchemy.AlchemyManager;
@ -960,20 +961,15 @@ public class McMMOPlayer implements Identified {
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(player, new AbilityDisableTask(this, superAbilityType), (long) ticks * Misc.TICK_CONVERSION_FACTOR);
}
/**
* Check to see if an ability can be activated.
*
* @param isCrossbow true for crossbow, false for bow
*/
public void checkAbilityActivationProjectiles(boolean isCrossbow) {
PrimarySkillType primarySkillType = isCrossbow ? PrimarySkillType.CROSSBOWS : PrimarySkillType.ARCHERY;
public void checkCrossbowAbilityActivation() {
PrimarySkillType primarySkillType = PrimarySkillType.CROSSBOWS;
ToolType tool = ToolType.CROSSBOW;
SuperAbilityType superAbilityType = SuperAbilityType.SUPER_SHOTGUN;
SubSkillType subSkillType = SubSkillType.CROSSBOWS_SUPER_SHOTGUN;
AlternateFiringSuperSkill skillManager = getCrossbowsManager();
// TODO: Refactor this crappy logic
ToolType tool = isCrossbow ? ToolType.CROSSBOW : ToolType.BOW;
SuperAbilityType superAbilityType = isCrossbow ? SuperAbilityType.SUPER_SHOTGUN : SuperAbilityType.EXPLOSIVE_SHOT;
SubSkillType subSkillType = superAbilityType.getSubSkillTypeDefinition();
if (getAbilityMode(superAbilityType) || !superAbilityType.getPermissions(player)) {
// Check permission
if (!superAbilityType.getPermissions(player)) {
return;
}
@ -997,6 +993,11 @@ public class McMMOPlayer implements Identified {
return;
}
// Check if we can fire the ability
if (!skillManager.isReadyToFire()) {
return;
}
if (useChatNotifications()) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUPER_ABILITY, superAbilityType.getAbilityOn());
}
@ -1010,8 +1011,9 @@ public class McMMOPlayer implements Identified {
// TODO: Fire the ability
profile.setAbilityDATS(superAbilityType, System.currentTimeMillis());
setAbilityMode(superAbilityType, true);
setToolPreparationMode(tool, false);
skillManager.resetCharge();
skillManager.fireSuper();
if(!mcMMO.isServerShutdownExecuted()) {
mcMMO.p.getFoliaLib().getImpl().runAtEntityLater(
@ -1021,6 +1023,10 @@ public class McMMOPlayer implements Identified {
}
}
public void chargeCrossbowSuper() {
getCrossbowsManager().chargeSuper();
}
public void processAbilityActivation(@NotNull PrimarySkillType primarySkillType) {
if (!mcMMO.p.getSkillTools().doesPlayerHaveSkillPermission(getPlayer(), primarySkillType)) {
return;

View File

@ -788,6 +788,9 @@ public class PlayerListener implements Listener {
}
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
if (mcMMOPlayer == null)
return;
ItemStack heldItem = player.getInventory().getItemInMainHand();
//Spam Fishing Detection
@ -825,6 +828,11 @@ public class PlayerListener implements Listener {
mcMMOPlayer.processAbilityActivation(PrimarySkillType.HERBALISM);
}
// Projectile Skills
if (ItemUtils.isCrossbow(heldItem) || ItemUtils.isBow(heldItem)) {
CombatUtils.processProjectileSkillSuperAbilityActivation(mcMMOPlayer, heldItem);
}
mcMMOPlayer.processAbilityActivation(PrimarySkillType.AXES);
mcMMOPlayer.processAbilityActivation(PrimarySkillType.EXCAVATION);
mcMMOPlayer.processAbilityActivation(PrimarySkillType.MINING);
@ -896,6 +904,11 @@ public class PlayerListener implements Listener {
mcMMOPlayer.processAbilityActivation(PrimarySkillType.SWORDS);
mcMMOPlayer.processAbilityActivation(PrimarySkillType.UNARMED);
mcMMOPlayer.processAbilityActivation(PrimarySkillType.WOODCUTTING);
// Projectile Skills
if (ItemUtils.isCrossbow(heldItem) || ItemUtils.isBow(heldItem)) {
CombatUtils.processProjectileSkillSuperAbilityActivation(mcMMOPlayer, heldItem);
}
}
/* ITEM CHECKS */
@ -916,10 +929,9 @@ public class PlayerListener implements Listener {
break;
}
// Projectile Skills
// Check if the player is holding a bow or crossbow
if (ItemUtils.isCrossbow(heldItem) || ItemUtils.isBow(heldItem)) {
CombatUtils.processProjectileSkillSuperAbilityActivation(mcMMOPlayer, heldItem);
// Check charge up supers (crossbows, etc...)
if (ItemUtils.isCrossbow(heldItem)) {
mcMMOPlayer.chargeCrossbowSuper();
}
/* CALL OF THE WILD CHECKS */

View File

@ -0,0 +1,13 @@
package com.gmail.nossr50.skills;
public interface AlternateFiringSuperSkill {
int chargeSuper();
void fireSuper();
void resetCharge();
boolean isReadyToFire();
long lastChargeTime();
}

View File

@ -4,6 +4,7 @@ import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.skills.AlternateFiringSuperSkill;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.util.MetadataConstants;
import com.gmail.nossr50.util.Permissions;
@ -22,11 +23,15 @@ import org.jetbrains.annotations.NotNull;
import static com.gmail.nossr50.util.skills.CombatUtils.delayArrowMetaCleanup;
public class CrossbowsManager extends SkillManager {
public class CrossbowsManager extends SkillManager implements AlternateFiringSuperSkill {
public CrossbowsManager(McMMOPlayer mmoPlayer) {
super(mmoPlayer, PrimarySkillType.CROSSBOWS);
}
private long lastChargeTime = 0;
private int crossbowSuperWindupState = 0;
public void handleRicochet(@NotNull Plugin pluginRef, @NotNull Arrow arrow, @NotNull Vector hitBlockNormal) {
if(!arrow.isShotFromCrossbow())
return;
@ -105,4 +110,38 @@ public class CrossbowsManager extends SkillManager {
return oldDamage;
}
}
@Override
public int chargeSuper() {
if (lastChargeTime < System.currentTimeMillis() - 2000) {
crossbowSuperWindupState = 0;
}
if (crossbowSuperWindupState < 3) {
crossbowSuperWindupState++;
}
lastChargeTime = System.currentTimeMillis();
return crossbowSuperWindupState;
}
@Override
public void fireSuper() {
// TODO: Impl
}
@Override
public void resetCharge() {
crossbowSuperWindupState = 0;
}
@Override
public boolean isReadyToFire() {
return crossbowSuperWindupState == 3;
}
@Override
public long lastChargeTime() {
return lastChargeTime;
}
}

View File

@ -51,10 +51,10 @@ public final class CombatUtils {
// TODO: Unit tests
public static void processProjectileSkillSuperAbilityActivation(McMMOPlayer mmoPlayer, ItemStack heldItem) {
// TODO: Support archery super as well
if (heldItem != null && mmoPlayer != null) {
if (ItemUtils.isBowOrCrossbow(heldItem)) {
boolean isCrossbow = ItemUtils.isCrossbow(heldItem);
mmoPlayer.checkAbilityActivationProjectiles(isCrossbow);
if (ItemUtils.isCrossbow(heldItem)) {
mmoPlayer.checkCrossbowAbilityActivation();
}
}
}