studio.magemonkey.fabled.dynamic.mechanic.particle.ParticleMechanic Maven / Gradle / Ivy
Show all versions of fabled Show documentation
/**
* Fabled
* studio.magemonkey.fabled.dynamic.mechanic.particle.ParticleMechanic
*
* The MIT License (MIT)
*
* Copyright (c) 2024 MageMonkeyStudio
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software") to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package studio.magemonkey.fabled.dynamic.mechanic.particle;
import studio.magemonkey.fabled.api.Settings;
import studio.magemonkey.fabled.api.particle.ParticleHelper;
import studio.magemonkey.fabled.dynamic.mechanic.MechanicComponent;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
import java.util.List;
/**
* Plays a particle effect
*/
public class ParticleMechanic extends MechanicComponent {
private static final Vector UP = new Vector(0, 1, 0);
private static final String FORWARD = "forward";
private static final String UPWARD = "upward";
private static final String RIGHT = "right";
@Override
public String getKey() {
return "particle";
}
/**
* Executes the component
*
* @param caster caster of the skill
* @param level level of the skill
* @param targets targets to apply to
* @param force
* @return true if applied to something, false otherwise
*/
@Override
public boolean execute(LivingEntity caster, int level, List targets, boolean force) {
if (targets.size() == 0) {
return false;
}
double forward = settings.getDouble(FORWARD, 0);
double upward = settings.getDouble(UPWARD, 0);
double right = settings.getDouble(RIGHT, 0);
final Settings copy = new Settings(settings);
copy.set(ParticleHelper.POINTS_KEY, parseValues(caster, ParticleHelper.POINTS_KEY, level, 1), 0);
copy.set(ParticleHelper.RADIUS_KEY, parseValues(caster, ParticleHelper.RADIUS_KEY, level, 0), 0);
copy.set("level", level);
for (LivingEntity target : targets) {
Location loc = target.getLocation();
Vector dir = loc.getDirection().setY(0).normalize();
Vector side = dir.clone().crossProduct(UP);
loc.add(dir.multiply(forward)).add(0, upward, 0).add(side.multiply(right));
ParticleHelper.play(loc, copy);
}
return targets.size() > 0;
}
}