Backend Finalization

TODO:
 - Listener implementations
 - Spell tome, book, and wand items
 - Persistent data storage
 - Configurable values
 - Custom spells
This commit is contained in:
Paul Reilly 2023-06-29 11:26:31 -05:00
parent f7089a110c
commit a84bbeea94
16 changed files with 283 additions and 58 deletions

View File

@ -0,0 +1,24 @@
package app.simplexdev.arcanumocculta.api.display;
import app.simplexdev.arcanumocculta.api.player.Caster;
import app.simplexdev.arcanumocculta.api.spell.Spell;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.entity.Display;
public interface SpellDisplay<T extends Display> {
T getDisplay();
Location getLocation();
World getWorld();
Caster getWhoCast();
Spell getCastSpell();
Particle[] getParticles();
void display(boolean force);
}

View File

@ -0,0 +1,5 @@
package app.simplexdev.arcanumocculta.api.effect;
public interface EffectProvider<T extends Effect> {
T getEffect(Class<T> type);
}

View File

@ -1,8 +1,7 @@
package app.simplexdev.arcanumocculta.api.effect; package app.simplexdev.arcanumocculta.api.effect;
import org.bukkit.entity.Player; import org.bukkit.entity.LivingEntity;
public interface SpecialEffect extends Effect public interface SpecialEffect extends Effect {
{ void applyEffect(final LivingEntity target);
void applyEffect(final Player player);
} }

View File

@ -1,9 +1,7 @@
package app.simplexdev.arcanumocculta.api.effect; package app.simplexdev.arcanumocculta.api.effect;
import java.time.Duration;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
public interface SpellEffect extends Effect public interface SpellEffect extends Effect {
{
PotionEffectType getEffectType(); PotionEffectType getEffectType();
} }

View File

@ -1,6 +1,7 @@
package app.simplexdev.arcanumocculta.api.player; package app.simplexdev.arcanumocculta.api.player;
import app.simplexdev.arcanumocculta.api.book.SpellBook; import app.simplexdev.arcanumocculta.api.book.SpellBook;
import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -16,6 +17,11 @@ public interface Caster {
*/ */
String getDisplayName(); String getDisplayName();
/**
* @return The {@link Player} associated with this caster.
*/
Player bukkit();
/** /**
* @return The amount of maximum mana the caster is allowed to have. * @return The amount of maximum mana the caster is allowed to have.
*/ */

View File

@ -1,8 +0,0 @@
package app.simplexdev.arcanumocculta.api.spell;
import app.simplexdev.arcanumocculta.api.effect.CompoundEffect;
public interface CompoundSpell extends Spell
{
CompoundEffect getEffect();
}

View File

@ -1,8 +0,0 @@
package app.simplexdev.arcanumocculta.api.spell;
import app.simplexdev.arcanumocculta.api.effect.SpecialEffect;
public interface SpecialSpell extends Spell
{
SpecialEffect getSpecialEffect();
}

View File

@ -1,12 +1,12 @@
package app.simplexdev.arcanumocculta.api.spell; package app.simplexdev.arcanumocculta.api.spell;
import app.simplexdev.arcanumocculta.api.effect.SpellEffect; import app.simplexdev.arcanumocculta.api.effect.Effect;
import app.simplexdev.arcanumocculta.api.effect.EffectProvider;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import java.time.Duration; import java.time.Duration;
public interface Spell public interface Spell<T extends Effect> {
{
String getSpellName(); String getSpellName();
String getSpellDescription(); String getSpellDescription();
@ -17,7 +17,7 @@ public interface Spell
int getSpellLevel(); int getSpellLevel();
boolean isOnCoolDown();
SpellProjectile<? extends Projectile> getSpellProjectile(); SpellProjectile<? extends Projectile> getSpellProjectile();
T getEffect();
} }

View File

@ -8,7 +8,7 @@ import org.bukkit.entity.Projectile;
import java.util.List; import java.util.List;
public interface SpellProjectile<T extends Projectile> { public interface SpellProjectile<T extends Projectile> {
T getProjectile(); Class<T> getProjectileType();
List<Particle> getParticles(); List<Particle> getParticles();

View File

@ -1,8 +0,0 @@
package app.simplexdev.arcanumocculta.api.spell;
import app.simplexdev.arcanumocculta.api.effect.SpellEffect;
public interface StandardSpell extends Spell
{
SpellEffect getSpellEffect();
}

View File

@ -11,7 +11,7 @@ public abstract class AbstractPassiveEffect extends AbstractEffect implements Pa
private final Caster wandHolder; private final Caster wandHolder;
private final PassiveEffects passiveEffect; private final PassiveEffects passiveEffect;
public AbstractPassiveEffect(Duration duration, float amplifier, boolean ambient, boolean forceDisplay, Caster wandHolder, PassiveEffects passiveEffect) { protected AbstractPassiveEffect(Duration duration, float amplifier, boolean ambient, boolean forceDisplay, Caster wandHolder, PassiveEffects passiveEffect) {
super(duration, amplifier, ambient, forceDisplay); super(duration, amplifier, ambient, forceDisplay);
this.wandHolder = wandHolder; this.wandHolder = wandHolder;
this.passiveEffect = passiveEffect; this.passiveEffect = passiveEffect;
@ -23,19 +23,19 @@ public abstract class AbstractPassiveEffect extends AbstractEffect implements Pa
this.passiveEffect = passiveEffect; this.passiveEffect = passiveEffect;
} }
public AbstractPassiveEffect(Duration duration, float amplifier, Caster wandHolder, PassiveEffects passiveEffect) { protected AbstractPassiveEffect(Duration duration, float amplifier, Caster wandHolder, PassiveEffects passiveEffect) {
super(duration, amplifier); super(duration, amplifier);
this.wandHolder = wandHolder; this.wandHolder = wandHolder;
this.passiveEffect = passiveEffect; this.passiveEffect = passiveEffect;
} }
public AbstractPassiveEffect(Duration duration, Caster wandHolder, PassiveEffects passiveEffect) { protected AbstractPassiveEffect(Duration duration, Caster wandHolder, PassiveEffects passiveEffect) {
super(duration); super(duration);
this.wandHolder = wandHolder; this.wandHolder = wandHolder;
this.passiveEffect = passiveEffect; this.passiveEffect = passiveEffect;
} }
public AbstractPassiveEffect(Caster wandHolder, PassiveEffects passiveEffect) { protected AbstractPassiveEffect(Caster wandHolder, PassiveEffects passiveEffect) {
super(); super();
this.wandHolder = wandHolder; this.wandHolder = wandHolder;
this.passiveEffect = passiveEffect; this.passiveEffect = passiveEffect;
@ -43,11 +43,11 @@ public abstract class AbstractPassiveEffect extends AbstractEffect implements Pa
@Override @Override
public Caster getWandHolder() { public Caster getWandHolder() {
return null; return wandHolder;
} }
@Override @Override
public PassiveEffects getPassiveEffect() { public PassiveEffects getPassiveEffect() {
return null; return passiveEffect;
} }
} }

View File

@ -1,44 +1,68 @@
package app.simplexdev.arcanumocculta.base.spell; package app.simplexdev.arcanumocculta.base.spell;
import app.simplexdev.arcanumocculta.api.effect.Effect;
import app.simplexdev.arcanumocculta.api.spell.Spell; import app.simplexdev.arcanumocculta.api.spell.Spell;
import app.simplexdev.arcanumocculta.api.spell.SpellProjectile;
import org.bukkit.entity.Projectile;
import java.time.Duration; import java.time.Duration;
public class AbstractSpell implements Spell { public abstract class AbstractSpell<T extends Effect> implements Spell<T> {
private final String name;
private final String description;
private final double manaCost;
private final Duration coolDown;
private final int spellLevel;
private final T spellEffect;
private long coolDownEnd;
protected AbstractSpell(String name, String description, double manaCost, Duration coolDown, int spellLevel, T effect) {
this.name = name;
this.description = description;
this.manaCost = manaCost;
this.coolDown = coolDown;
this.spellLevel = spellLevel;
this.spellEffect = effect;
}
protected AbstractSpell(String name, String description, double manaCost, Duration coolDown, T effect) {
this(name, description, manaCost, coolDown, 1, effect);
}
protected AbstractSpell(String name, String description, double manaCost, T effect) {
this(name, description, manaCost, Duration.ofSeconds(10L), effect);
}
protected AbstractSpell(String name, String description, T effect) {
this(name, description, 5.0, effect);
}
@Override @Override
public String getSpellName() { public String getSpellName() {
return null; return name;
} }
@Override @Override
public String getSpellDescription() { public String getSpellDescription() {
return null; return description;
} }
@Override @Override
public double getManaCost() { public double getManaCost() {
return 0; return manaCost;
} }
@Override @Override
public Duration getCoolDown() { public Duration getCoolDown() {
return null; return coolDown;
} }
@Override @Override
public int getSpellLevel() { public int getSpellLevel() {
return 0; return spellLevel;
} }
@Override @Override
public boolean isOnCoolDown() { public T getEffect() {
return false; return spellEffect;
}
@Override
public SpellProjectile<? extends Projectile> getSpellProjectile() {
return null;
} }
} }

View File

@ -0,0 +1,143 @@
package app.simplexdev.arcanumocculta.base.spell;
import app.simplexdev.arcanumocculta.api.effect.CompoundEffect;
import app.simplexdev.arcanumocculta.api.effect.Effect;
import app.simplexdev.arcanumocculta.api.effect.SpecialEffect;
import app.simplexdev.arcanumocculta.api.effect.SpellEffect;
import app.simplexdev.arcanumocculta.api.player.Caster;
import app.simplexdev.arcanumocculta.api.spell.Spell;
import app.simplexdev.arcanumocculta.api.spell.SpellProjectile;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class AbstractSpellProjectile<T extends Projectile> implements SpellProjectile<T> {
private static final List<EntityType> accepted = List.of(
EntityType.ARROW,
EntityType.SPECTRAL_ARROW,
EntityType.FIREBALL,
EntityType.DRAGON_FIREBALL,
EntityType.SMALL_FIREBALL,
EntityType.WITHER_SKULL,
EntityType.ENDER_PEARL,
EntityType.SNOWBALL,
EntityType.EGG,
EntityType.TRIDENT,
EntityType.FIREWORK,
EntityType.LLAMA_SPIT,
EntityType.SHULKER_BULLET,
EntityType.FISHING_HOOK,
EntityType.SPLASH_POTION,
EntityType.THROWN_EXP_BOTTLE);
private final Class<T> projectile;
private final List<Particle> particles;
private final Caster caster;
private final Spell<?> spell;
protected AbstractSpellProjectile(final Spell<?> spell, final Caster caster, final Class<T> projectile, final Particle... particles) {
this.projectile = projectile;
this.particles = Arrays.asList(particles);
this.caster = caster;
this.spell = spell;
}
@Override
public Class<T> getProjectileType() {
return projectile;
}
@Override
public List<Particle> getParticles() {
return particles;
}
@Override
public void cast(Location target) {
final Vector velocity = caster.bukkit().getEyeLocation().getDirection().multiply(2);
final T launched = caster.bukkit().launchProjectile(getProjectileType(), velocity);
while (!launched.isDead()) {
final double randomXOffset = Math.sin((Math.random() * 10 - 2) % Math.PI) * 5;
final double randomYOffset = ((Math.random() * 10 - 2) % Math.PI) * 5;
final double randomZOffset = Math.cos((Math.random() * 10 - 2) % (2 * Math.PI)) * 5;
particles.forEach(particle -> launched.getWorld().spawnParticle(particle, launched.getLocation(), 1, randomXOffset, randomYOffset, randomZOffset));
if (launched.isOnGround()
|| launched.isDead()
|| launched.getTicksLived() > 100
|| launched.getLocation().clone().equals(target)) {
break;
}
}
final Effect effect = spell.getEffect();
if (effect instanceof SpellEffect sp) {
PotionEffect e = sp.getEffectType().createEffect((int) sp.getDuration().getSeconds(), (int) sp.getAmplifier());
AreaEffectCloud cloud = (AreaEffectCloud) target.getWorld().spawnEntity(target, EntityType.AREA_EFFECT_CLOUD);
cloud.addCustomEffect(e, true);
cloud.setRadius(2.5F);
cloud.setDuration((int) sp.getDuration().getSeconds());
cloud.setSource(caster.bukkit());
} else if (effect instanceof CompoundEffect sp) {
final List<PotionEffect> effects = new ArrayList<>();
for (PotionEffectType type : sp.getEffectTypes()) {
PotionEffect e = type.createEffect((int) sp.getDuration().getSeconds(), (int) sp.getAmplifier());
effects.add(e);
}
AreaEffectCloud cloud = (AreaEffectCloud) target.getWorld().spawnEntity(target, EntityType.AREA_EFFECT_CLOUD);
for (PotionEffect e : effects) {
cloud.addCustomEffect(e, true);
}
cloud.setRadius(2.5F);
cloud.setDuration((int) sp.getDuration().getSeconds());
cloud.setSource(caster.bukkit());
}
}
@Override
public void cast(LivingEntity target) {
final Vector velocity = caster.bukkit().getEyeLocation().getDirection().multiply(2);
final T launched = caster.bukkit().launchProjectile(getProjectileType(), velocity);
while (!launched.isDead()) {
final double randomXOffset = Math.sin((Math.random() * 10 - 2) % Math.PI) * 5;
final double randomYOffset = ((Math.random() * 10 - 2) % Math.PI) * 5;
final double randomZOffset = Math.cos((Math.random() * 10 - 2) % (2 * Math.PI)) * 5;
particles.forEach(particle -> launched.getWorld().spawnParticle(particle, launched.getLocation(), 1, randomXOffset, randomYOffset, randomZOffset));
if (launched.isOnGround()
|| launched.isDead()
|| launched.getTicksLived() > 100
|| launched.getLocation().clone().equals(target)) {
break;
}
}
final Effect effect = spell.getEffect();
if (effect instanceof SpellEffect sp) {
PotionEffect e = sp.getEffectType().createEffect((int) sp.getDuration().getSeconds(), (int) sp.getAmplifier());
target.addPotionEffect(e);
} else if (effect instanceof CompoundEffect sp) {
final List<PotionEffect> effects = new ArrayList<>();
for (PotionEffectType type : sp.getEffectTypes()) {
PotionEffect e = type.createEffect((int) sp.getDuration().getSeconds(), (int) sp.getAmplifier());
effects.add(e);
}
target.addPotionEffects(effects);
} else if (effect instanceof SpecialEffect sp) {
sp.applyEffect(target);
}
}
}

View File

@ -0,0 +1,23 @@
package app.simplexdev.arcanumocculta.spell;
import app.simplexdev.arcanumocculta.api.effect.SpellEffect;
import app.simplexdev.arcanumocculta.api.player.Caster;
import app.simplexdev.arcanumocculta.base.spell.AbstractSpell;
import app.simplexdev.arcanumocculta.spell.effect.FireballEffect;
import app.simplexdev.arcanumocculta.spell.projectile.FireballProjectile;
import java.time.Duration;
public final class FireballSpell extends AbstractSpell<FireballEffect> {
private final Caster caster;
public FireballSpell(final Caster caster) {
super("Fireball", "Fires a fireball in the direction you're facing.", new FireballEffect(Duration.ofSeconds(1), 1));
this.caster = caster;
}
@Override
public FireballProjectile getSpellProjectile() {
return new FireballProjectile(this, this.caster);
}
}

View File

@ -0,0 +1,12 @@
package app.simplexdev.arcanumocculta.spell.effect;
import app.simplexdev.arcanumocculta.base.effect.AbstractSpellEffect;
import org.bukkit.potion.PotionEffectType;
import java.time.Duration;
public class FireballEffect extends AbstractSpellEffect {
public FireballEffect(Duration duration, float amplifier) {
super(duration, amplifier, PotionEffectType.HARM);
}
}

View File

@ -0,0 +1,15 @@
package app.simplexdev.arcanumocculta.spell.projectile;
import app.simplexdev.arcanumocculta.api.player.Caster;
import app.simplexdev.arcanumocculta.api.spell.Spell;
import app.simplexdev.arcanumocculta.base.spell.AbstractSpellProjectile;
import app.simplexdev.arcanumocculta.spell.FireballSpell;
import org.bukkit.Particle;
import org.bukkit.entity.Fireball;
public class FireballProjectile extends AbstractSpellProjectile<Fireball> {
public FireballProjectile(FireballSpell spell,
Caster caster) {
super(spell, caster, Fireball.class, Particle.FLAME, Particle.SMALL_FLAME, Particle.LAVA);
}
}