Skip to content

Commit

Permalink
some improvements, and a new skill
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Jul 15, 2017
1 parent 1bbb080 commit d5869a6
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 36 deletions.
4 changes: 3 additions & 1 deletion Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class EffectBase<Value> implements IEffect<Value> {
private boolean stackable = false;
private String name;
private int level;
private Set<PotionEffect> potions = new HashSet<>();
private Set<PotionEffect> potions;
private IEffectConsumer consumer;
private long duration = -1;
private long period = -1;
Expand Down Expand Up @@ -124,6 +124,8 @@ public void setConsumer(IEffectConsumer consumer) {

@Override
public Set<PotionEffect> getPotions() {
if (potions == null)
potions = new HashSet<>();
return potions;
}

Expand Down
2 changes: 1 addition & 1 deletion Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static GlobalScope getGlobalScope() {

default void reApplyPotions() {
for (PotionEffect e : getPotions()) {
getConsumer().addPotionEffect(e.getType(), e.getAmplifier(), e.getDuration());
getConsumer().addPotionEffect(e.getType(), e.getAmplifier(), e.getDuration());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cz.neumimto.rpg.gui;

import org.spongepowered.api.effect.particle.ParticleEffect;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
* Created by NeumimTo on 9.7.2017.
Expand All @@ -16,6 +18,5 @@ public interface IActionDecorator {

void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer<Task, Entity> e);



void circle(Location location, int count, double radius, Consumer<Location> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ public void setDamageType(DamageType type) {
/* Skills are singletons */
@Override
public boolean equals(Object o) {
if (this == o) return true;
return false;
return this == o;
}

@Override
Expand Down
4 changes: 4 additions & 0 deletions Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ default double getDoubleNodeValue(ExtendedSkillInfo extendedSkillInfo, String no
return extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel());
}

default double getDoubleNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode node) {
return getDoubleNodeValue(extendedSkillInfo, node.value());
}

@Override
default IEffectSource getType() {
return EffectSourceType.SKILL;
Expand Down
34 changes: 27 additions & 7 deletions Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,35 @@ public static boolean isNumeric(String str) {
return str.matches("-?\\d+(\\.\\d+)?");
}

public static Set<Entity> getNearbyEntities(Location l, int radius) {
double s = Math.pow(radius, 2);
HashSet<Entity> ee = new HashSet<>();
for (Entity e : l.getExtent().getEntities()) {
if (e.getLocation().getPosition().distanceSquared(l.getX(), l.getY(), l.getZ()) <= s) {
ee.add(e);
public static Set<Entity> getNearbyEntities(Location l, int radius){
int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16))/16;
HashSet<Entity> set = new HashSet<>();
double pow = Math.pow(radius, 2);
for (int chX = 0 -chunkRadius; chX <= chunkRadius; chX ++){
for (int chZ = 0 -chunkRadius; chZ <= chunkRadius; chZ++){
Location chunkLoc = new Location(l.getExtent(),l.getBlockX()+(chX*16),l.getBlockY(),l.getBlockZ()+(chZ*16));
for (Entity e : chunkLoc.getExtent().getEntities()){
if (e.getLocation().getPosition().distanceSquared(l.getPosition()) <= pow)
set.add(e);
}
}
}
return set;
}

public static Set<Entity> getNearbyEntitiesPrecise(Location l, int radius){
int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16))/16;
HashSet<Entity> set = new HashSet<>();
for (int chX = 0 -chunkRadius; chX <= chunkRadius; chX ++){
for (int chZ = 0 -chunkRadius; chZ <= chunkRadius; chZ++){
Location chunkLoc = new Location(l.getExtent(),l.getBlockX()+(chX*16),l.getBlockY(),l.getBlockZ()+(chZ*16));
for (Entity e : chunkLoc.getExtent().getEntities()){
if (e.getLocation().getPosition().distance(l.getPosition()) <= radius)
set.add(e);
}
}
}
return ee;
return set;
}


Expand Down
12 changes: 12 additions & 0 deletions Skills/src/main/java/cz/neumimto/Decorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import cz.neumimto.core.ioc.IoC;
import cz.neumimto.effects.decoration.ParticleDecorator;
import org.spongepowered.api.effect.particle.ParticleEffect;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
* Created by NeumimTo on 6.2.2016.
Expand All @@ -32,4 +34,14 @@ public static void strikeLightning(Location<World> location) {
public static void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer<Task, Entity> e) {
decorator.createTrajectory(entity, interval, maxticks, e);
}

public static void circle(Location location, int count, double radius, Consumer<Location> callback) {
decorator.circle(location, count, radius, callback);
}

public static void particleExplosion(Location location, int size) {

}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.neumimto.effects.decoration;

import com.flowpowered.math.TrigMath;
import cz.neumimto.Decorator;
import cz.neumimto.core.ioc.Inject;
import cz.neumimto.core.ioc.Singleton;
Expand All @@ -15,9 +16,13 @@
import org.spongepowered.api.scheduler.Task;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.Extent;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
* Created by NeumimTo on 9.7.2017.
Expand All @@ -36,31 +41,28 @@ public void strikeLightning(Location<World> location) {

@Override
public void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer<Task, Entity> e) {
Task submit = Sponge.getScheduler()
.createTaskBuilder()
.delay(1L, TimeUnit.MILLISECONDS)
.interval(interval, TimeUnit.MILLISECONDS)
.execute((task -> {
if (!entity.isRemoved()) {
e.accept(task, entity);
} else {
task.cancel();
}
})).submit(plugin);
Sponge.getScheduler()
.createTaskBuilder()
.delay(1L, TimeUnit.MILLISECONDS)
.interval(interval, TimeUnit.MILLISECONDS)
.execute((task -> {
if (!entity.isRemoved()) {
e.accept(task, entity);
} else {
task.cancel();
}
})).submit(plugin);
}

public static class SIMPLE_TRAJECTORY implements BiConsumer<Task, Entity> {

private ParticleEffect eff;

public SIMPLE_TRAJECTORY(ParticleEffect eff) {
this.eff = eff;
}

@Override
public void accept(Task task, Entity entity) {
entity.getWorld().spawnParticles(eff, entity.getLocation().getPosition());
@Override
public void circle(Location location, int count, double radius, Consumer<Location> callback) {
Extent e = location.getExtent();
double increment = TrigMath.TWO_PI/count;
for (int i = 0; i < count; i++) {
double angle = i * increment;
double x = location.getX() + radius * TrigMath.cos(angle);
double z = location.getZ() + radius * TrigMath.sin(angle);
callback.accept(new Location(e, x, location.getY(), z));
}
}

}
59 changes: 59 additions & 0 deletions Skills/src/main/java/cz/neumimto/effects/negative/Blindness.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cz.neumimto.effects.negative;

import cz.neumimto.rpg.ClassGenerator;
import cz.neumimto.rpg.effects.*;
import org.spongepowered.api.effect.potion.PotionEffect;
import org.spongepowered.api.effect.potion.PotionEffectTypes;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
* Created by NeumimTo on 9.7.2017.
*/
@ClassGenerator.Generate(id = "name")
public class Blindness extends EffectBase<Long> implements IEffectContainer<Long, Blindness> {

public static final String name = "Blindness";

public Blindness(IEffectConsumer consumer, long duration, String value) {
this(consumer, duration);
setValue(duration);
setDuration(duration);
getPotions().add(getEffect());
}

public Blindness(IEffectConsumer consumer, long duration) {
super(name, consumer);
}


@Override
public Set<Blindness> getEffects() {
return new HashSet<>(Arrays.asList(this));
}

@Override
public Long getStackedValue() {
return getDuration();
}

@Override
public void setStackedValue(Long aLong) {
setDuration(aLong);
}

@Override
public void stackEffect(Blindness blindness, IEffectSourceProvider effectSourceProvider) {
setStackedValue(getStackedValue() + blindness.getStackedValue());
}

private PotionEffect getEffect() {
return PotionEffect.builder()
.potionType(PotionEffectTypes.BLINDNESS)
.particles(false)
.duration((int) (20 * getStackedValue() / 1000))
.build(); //miliseconds to minecraft ticks
}
}
92 changes: 92 additions & 0 deletions Skills/src/main/java/cz/neumimto/skills/active/Despair.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package cz.neumimto.skills.active;

import com.flowpowered.math.vector.Vector3d;
import cz.neumimto.Decorator;
import cz.neumimto.ParticleUtils;
import cz.neumimto.core.ioc.Inject;
import cz.neumimto.effects.negative.Blindness;
import cz.neumimto.rpg.IEntity;
import cz.neumimto.rpg.ResourceLoader;
import cz.neumimto.rpg.damage.SkillDamageSource;
import cz.neumimto.rpg.damage.SkillDamageSourceBuilder;
import cz.neumimto.rpg.effects.EffectService;
import cz.neumimto.rpg.entities.EntityService;
import cz.neumimto.rpg.players.IActiveCharacter;
import cz.neumimto.rpg.skills.*;
import cz.neumimto.rpg.utils.Utils;
import org.spongepowered.api.effect.particle.ParticleEffect;
import org.spongepowered.api.effect.particle.ParticleOptions;
import org.spongepowered.api.effect.particle.ParticleTypes;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.Living;
import org.spongepowered.api.event.cause.entity.damage.DamageTypes;
import org.spongepowered.api.util.Color;
import org.spongepowered.api.util.Direction;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.ArrayList;
import java.util.Set;

/**
* Created by NeumimTo on 15.7.2017.
*/
@ResourceLoader.Skill
public class Despair extends ActiveSkill {

@Inject
private EntityService entityService;

@Inject
private EffectService effectService;

public Despair() {
setName("Despair");
setDamageType(DamageTypes.MAGIC);
SkillSettings settings = new SkillSettings();
settings.addNode(SkillNodes.DURATION, 1000L, 500);
settings.addNode(SkillNodes.DAMAGE, 10L, 1.5f);
settings.addNode(SkillNodes.RADIUS, 7L, 2);
super.settings = settings;
}

@Override
public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, SkillModifier modifier) {
int k = getIntNodeValue(info, SkillNodes.RADIUS);
Set<Entity> nearbyEntities = Utils.getNearbyEntities(character.getEntity().getLocation(), k);
double damage = getDoubleNodeValue(info, SkillNodes.DAMAGE);
long duration = getLongNodeValue(info, SkillNodes.DURATION);

for (Entity nearbyEntity : nearbyEntities) {
if (Utils.isLivingEntity(nearbyEntity)) {
Living l = (Living) nearbyEntity;
if (Utils.canDamage(character, l)) {
IEntity iEntity = entityService.get(l);
SkillDamageSource build = new SkillDamageSourceBuilder()
.fromSkill(this)
.setTarget(iEntity)
.setCaster(character).build();
l.damage(damage, build);
Blindness blindness = new Blindness(iEntity, duration);
effectService.addEffect(blindness, character, this);
}
}
}

Vector3d vec = new Vector3d(0,1,0);
Decorator.circle(character.getEntity().getLocation(), 36, k, location -> {
ParticleEffect build = ParticleEffect.builder()
.type(ParticleTypes.SPELL)
.option(ParticleOptions.COLOR, Color.GRAY)
.build();
character.getEntity().getLocation().getExtent().spawnParticles(build, location.getPosition().add(vec));
build = ParticleEffect.builder()
.type(ParticleTypes.MOB_SPELL)
.option(ParticleOptions.COLOR, Color.GRAY)
.build();
character.getEntity().getLocation().getExtent().spawnParticles(build, location.getPosition().add(vec));
});

return SkillResult.OK;
}
}

0 comments on commit d5869a6

Please sign in to comment.