mirror of
https://github.com/SimplexDevelopment/ArcanumOcculta.git
synced 2024-12-22 04:07:37 +00:00
Backend Finalization
TODO: - Listener implementations - Spell tome, book, and wand items - Persistent data storage - Configurable values - Custom spells
This commit is contained in:
parent
f7089a110c
commit
a84bbeea94
@ -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);
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package app.simplexdev.arcanumocculta.api.effect;
|
||||
|
||||
public interface EffectProvider<T extends Effect> {
|
||||
T getEffect(Class<T> type);
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package app.simplexdev.arcanumocculta.api.effect;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
public interface SpecialEffect extends Effect
|
||||
{
|
||||
void applyEffect(final Player player);
|
||||
public interface SpecialEffect extends Effect {
|
||||
void applyEffect(final LivingEntity target);
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package app.simplexdev.arcanumocculta.api.effect;
|
||||
|
||||
import java.time.Duration;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public interface SpellEffect extends Effect
|
||||
{
|
||||
public interface SpellEffect extends Effect {
|
||||
PotionEffectType getEffectType();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package app.simplexdev.arcanumocculta.api.player;
|
||||
|
||||
import app.simplexdev.arcanumocculta.api.book.SpellBook;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -16,6 +17,11 @@ public interface Caster {
|
||||
*/
|
||||
String getDisplayName();
|
||||
|
||||
/**
|
||||
* @return The {@link Player} associated with this caster.
|
||||
*/
|
||||
Player bukkit();
|
||||
|
||||
/**
|
||||
* @return The amount of maximum mana the caster is allowed to have.
|
||||
*/
|
||||
|
@ -1,8 +0,0 @@
|
||||
package app.simplexdev.arcanumocculta.api.spell;
|
||||
|
||||
import app.simplexdev.arcanumocculta.api.effect.CompoundEffect;
|
||||
|
||||
public interface CompoundSpell extends Spell
|
||||
{
|
||||
CompoundEffect getEffect();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package app.simplexdev.arcanumocculta.api.spell;
|
||||
|
||||
import app.simplexdev.arcanumocculta.api.effect.SpecialEffect;
|
||||
|
||||
public interface SpecialSpell extends Spell
|
||||
{
|
||||
SpecialEffect getSpecialEffect();
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
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 java.time.Duration;
|
||||
|
||||
public interface Spell
|
||||
{
|
||||
public interface Spell<T extends Effect> {
|
||||
String getSpellName();
|
||||
|
||||
String getSpellDescription();
|
||||
@ -17,7 +17,7 @@ public interface Spell
|
||||
|
||||
int getSpellLevel();
|
||||
|
||||
boolean isOnCoolDown();
|
||||
|
||||
SpellProjectile<? extends Projectile> getSpellProjectile();
|
||||
|
||||
T getEffect();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import org.bukkit.entity.Projectile;
|
||||
import java.util.List;
|
||||
|
||||
public interface SpellProjectile<T extends Projectile> {
|
||||
T getProjectile();
|
||||
Class<T> getProjectileType();
|
||||
|
||||
List<Particle> getParticles();
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
package app.simplexdev.arcanumocculta.api.spell;
|
||||
|
||||
import app.simplexdev.arcanumocculta.api.effect.SpellEffect;
|
||||
|
||||
public interface StandardSpell extends Spell
|
||||
{
|
||||
SpellEffect getSpellEffect();
|
||||
}
|
@ -11,7 +11,7 @@ public abstract class AbstractPassiveEffect extends AbstractEffect implements Pa
|
||||
private final Caster wandHolder;
|
||||
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);
|
||||
this.wandHolder = wandHolder;
|
||||
this.passiveEffect = passiveEffect;
|
||||
@ -23,19 +23,19 @@ public abstract class AbstractPassiveEffect extends AbstractEffect implements Pa
|
||||
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);
|
||||
this.wandHolder = wandHolder;
|
||||
this.passiveEffect = passiveEffect;
|
||||
}
|
||||
|
||||
public AbstractPassiveEffect(Duration duration, Caster wandHolder, PassiveEffects passiveEffect) {
|
||||
protected AbstractPassiveEffect(Duration duration, Caster wandHolder, PassiveEffects passiveEffect) {
|
||||
super(duration);
|
||||
this.wandHolder = wandHolder;
|
||||
this.passiveEffect = passiveEffect;
|
||||
}
|
||||
|
||||
public AbstractPassiveEffect(Caster wandHolder, PassiveEffects passiveEffect) {
|
||||
protected AbstractPassiveEffect(Caster wandHolder, PassiveEffects passiveEffect) {
|
||||
super();
|
||||
this.wandHolder = wandHolder;
|
||||
this.passiveEffect = passiveEffect;
|
||||
@ -43,11 +43,11 @@ public abstract class AbstractPassiveEffect extends AbstractEffect implements Pa
|
||||
|
||||
@Override
|
||||
public Caster getWandHolder() {
|
||||
return null;
|
||||
return wandHolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PassiveEffects getPassiveEffect() {
|
||||
return null;
|
||||
return passiveEffect;
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,68 @@
|
||||
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.SpellProjectile;
|
||||
import org.bukkit.entity.Projectile;
|
||||
|
||||
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
|
||||
public String getSpellName() {
|
||||
return null;
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpellDescription() {
|
||||
return null;
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getManaCost() {
|
||||
return 0;
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Duration getCoolDown() {
|
||||
return null;
|
||||
return coolDown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSpellLevel() {
|
||||
return 0;
|
||||
return spellLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCoolDown() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpellProjectile<? extends Projectile> getSpellProjectile() {
|
||||
return null;
|
||||
public T getEffect() {
|
||||
return spellEffect;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user