Attributes, AirScooter fixes, Config fixes (#720)

* Attributes, AirScooter fixes, Config fixes

* AirScooter fixes

* AirScooter fixes part two
This commit is contained in:
Simplicitee 2017-02-03 22:21:20 -05:00 committed by Christopher Martin
parent 3539389e1a
commit 697db0236d
10 changed files with 289 additions and 74 deletions

View file

@ -28,6 +28,7 @@ import com.projectkorra.projectkorra.util.MetricsLite;
import com.projectkorra.projectkorra.util.RevertChecker; import com.projectkorra.projectkorra.util.RevertChecker;
import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.util.TempBlock;
import com.projectkorra.projectkorra.util.Updater; import com.projectkorra.projectkorra.util.Updater;
import com.projectkorra.projectkorra.util.attributes.AttributeModifiers;
import com.projectkorra.projectkorra.util.logging.PKLogHandler; import com.projectkorra.projectkorra.util.logging.PKLogHandler;
import com.projectkorra.projectkorra.waterbending.util.WaterbendingManager; import com.projectkorra.projectkorra.waterbending.util.WaterbendingManager;
@ -68,6 +69,7 @@ public class ProjectKorra extends JavaPlugin {
CoreAbility.registerAbilities(); CoreAbility.registerAbilities();
collisionInitializer.initializeDefaultCollisions(); // must be called after abilities have been registered collisionInitializer.initializeDefaultCollisions(); // must be called after abilities have been registered
collisionManager.startCollisionDetection(); collisionManager.startCollisionDetection();
new AttributeModifiers();
Preset.loadExternalPresets(); Preset.loadExternalPresets();

View file

@ -40,6 +40,7 @@ import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.event.AbilityEndEvent; import com.projectkorra.projectkorra.event.AbilityEndEvent;
import com.projectkorra.projectkorra.event.AbilityProgressEvent; import com.projectkorra.projectkorra.event.AbilityProgressEvent;
import com.projectkorra.projectkorra.event.AbilityStartEvent; import com.projectkorra.projectkorra.event.AbilityStartEvent;
import com.projectkorra.projectkorra.util.Attribute.Attributable;
import sun.reflect.ReflectionFactory; import sun.reflect.ReflectionFactory;
@ -491,6 +492,11 @@ public abstract class CoreAbility implements Ability {
AddonAbility addon = (AddonAbility) ability; AddonAbility addon = (AddonAbility) ability;
addon.load(); addon.load();
} }
if (ability instanceof Attributable) {
Attributable att = (Attributable) ability;
att.registerAttributes();
}
} }
catch (Exception e) { catch (Exception e) {
} }
@ -564,6 +570,12 @@ public abstract class CoreAbility implements Ability {
PassiveManager.getPassivesByElement().get(((SubElement) coreAbil.getElement()).getParentElement()).add(name); PassiveManager.getPassivesByElement().get(((SubElement) coreAbil.getElement()).getParentElement()).add(name);
} }
} }
if (coreAbil instanceof Attributable) {
Attributable att = (Attributable) coreAbil;
att.registerAttributes();
}
} }
catch (Exception | Error e) { catch (Exception | Error e) {
plugin.getLogger().warning("The ability " + coreAbil.getName() + " was not able to load, if this message shows again please remove it!"); plugin.getLogger().warning("The ability " + coreAbil.getName() + " was not able to load, if this message shows again please remove it!");

View file

@ -29,10 +29,12 @@ import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.ability.util.Collision;
import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.command.Commands;
import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; import com.projectkorra.projectkorra.object.HorizontalVelocityTracker;
import com.projectkorra.projectkorra.util.Attribute;
import com.projectkorra.projectkorra.util.Attribute.Attributable;
import com.projectkorra.projectkorra.util.DamageHandler; import com.projectkorra.projectkorra.util.DamageHandler;
import com.projectkorra.projectkorra.util.Flight; import com.projectkorra.projectkorra.util.Flight;
public class AirBlast extends AirAbility { public class AirBlast extends AirAbility implements Attributable{
private static final int MAX_TICKS = 10000; private static final int MAX_TICKS = 10000;
private static final Map<Player, Location> ORIGINS = new ConcurrentHashMap<>(); private static final Map<Player, Location> ORIGINS = new ConcurrentHashMap<>();
@ -44,15 +46,9 @@ public class AirBlast extends AirAbility {
private boolean isFromOtherOrigin; private boolean isFromOtherOrigin;
private boolean showParticles; private boolean showParticles;
private int ticks; private int ticks;
private int particles; int particles;
private long cooldown; long cooldown;
private double speedFactor; double speedFactor, range, pushFactor, pushFactorForOthers, damage, speed, radius;
private double range;
private double pushFactor;
private double pushFactorForOthers;
private double damage;
private double speed;
private double radius;
private Location location; private Location location;
private Location origin; private Location origin;
private Vector direction; private Vector direction;
@ -60,6 +56,14 @@ public class AirBlast extends AirAbility {
private Random random; private Random random;
private ArrayList<Block> affectedLevers; private ArrayList<Block> affectedLevers;
private ArrayList<Entity> affectedEntities; private ArrayList<Entity> affectedEntities;
private static Attribute<Integer> particlesA;
private static Attribute<Long> cooldownA;
private static Attribute<Double> rangeA;
private static Attribute<Double> pushFactorA;
private static Attribute<Double> pushFactorForOthersA;
private static Attribute<Double> damageA;
private static Attribute<Double> speedA;
private static Attribute<Double> radiusA;
public AirBlast(Player player) { public AirBlast(Player player) {
super(player); super(player);
@ -111,23 +115,18 @@ public class AirBlast extends AirAbility {
this.canPressButtons = false; this.canPressButtons = false;
this.canFlickLevers = false; this.canFlickLevers = false;
if (bPlayer.isAvatarState()) {
this.pushFactor = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Entities");
this.pushFactorForOthers = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Self");
}
start(); start();
} }
private void setFields() { private void setFields() {
this.particles = getConfig().getInt("Abilities.Air.AirBlast.Particles"); this.particles = particlesA.getModified(bPlayer);
this.cooldown = getConfig().getLong("Abilities.Air.AirBlast.Cooldown"); this.cooldown = cooldownA.getModified(bPlayer);
this.range = getConfig().getDouble("Abilities.Air.AirBlast.Range"); this.range = rangeA.getModified(bPlayer);
this.speed = getConfig().getDouble("Abilities.Air.AirBlast.Speed"); this.damage = damageA.getModified(bPlayer);
this.range = getConfig().getDouble("Abilities.Air.AirBlast.Range"); this.speed = speedA.getModified(bPlayer);
this.radius = getConfig().getDouble("Abilities.Air.AirBlast.Radius"); this.radius = radiusA.getModified(bPlayer);
this.pushFactor = getConfig().getDouble("Abilities.Air.AirBlast.Push.Entities"); this.pushFactor = pushFactorA.getModified(bPlayer);
this.pushFactorForOthers = getConfig().getDouble("Abilities.Air.AirBlast.Push.Self"); this.pushFactorForOthers = pushFactorForOthersA.getModified(bPlayer);
this.canFlickLevers = getConfig().getBoolean("Abilities.Air.AirBlast.CanFlickLevers"); this.canFlickLevers = getConfig().getBoolean("Abilities.Air.AirBlast.CanFlickLevers");
this.canOpenDoors = getConfig().getBoolean("Abilities.Air.AirBlast.CanOpenDoors"); this.canOpenDoors = getConfig().getBoolean("Abilities.Air.AirBlast.CanOpenDoors");
this.canPressButtons = getConfig().getBoolean("Abilities.Air.AirBlast.CanPressButtons"); this.canPressButtons = getConfig().getBoolean("Abilities.Air.AirBlast.CanPressButtons");
@ -639,4 +638,16 @@ public class AirBlast extends AirAbility {
return getConfig().getInt("Abilities.Air.AirBlast.SelectRange"); return getConfig().getInt("Abilities.Air.AirBlast.SelectRange");
} }
@Override
public void registerAttributes() {
particlesA = new Attribute<Integer>(this, "particles", getConfig().getInt("Abilities.Air.AirBlast.Particles"));
cooldownA = new Attribute<Long>(this, "cooldown", getConfig().getLong("Abilities.Air.AirBlast.Cooldown"));
rangeA = new Attribute<Double>(this, "range", getConfig().getDouble("Abilities.Air.AirBlast.Range"));
pushFactorA = new Attribute<Double>(this, "pushFactor", getConfig().getDouble("Abilities.Air.AirBlast.Push.Self"));
pushFactorForOthersA = new Attribute<Double>(this, "pushFactorForOthers", getConfig().getDouble("Abilities.Air.AirBlast.Push.Entities"));
damageA = new Attribute<Double>(this, "damage", getConfig().getDouble("Abilities.Air.AirBlast.Damage"));
speedA = new Attribute<Double>(this, "speed", getConfig().getDouble("Abilities.Air.AirBlast.Speed"));
radiusA = new Attribute<Double>(this, "radius", getConfig().getDouble("Abilities.Air.AirBlast.Radius"));
}
} }

View file

@ -14,22 +14,26 @@ import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.Element;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.AirAbility;
import com.projectkorra.projectkorra.util.Attribute;
import com.projectkorra.projectkorra.util.Attribute.Attributable;
import com.projectkorra.projectkorra.waterbending.WaterManipulation; import com.projectkorra.projectkorra.waterbending.WaterManipulation;
public class AirBubble extends AirAbility { public class AirBubble extends AirAbility implements Attributable{
private boolean waterBubble; private boolean waterBubble;
private double radius; private double radius;
private double airRadius; private double airRadius;
private double waterRadius; private double waterRadius;
private Map<Block, BlockState> waterOrigins; private Map<Block, BlockState> waterOrigins;
private static Attribute<Double> airRadiusA;
private static Attribute<Double> waterRadiusA;
public AirBubble(Player player) { public AirBubble(Player player) {
super(player); super(player);
this.radius = 0; this.radius = 0;
this.airRadius = getConfig().getDouble("Abilities.Air.AirBubble.Radius"); this.airRadius = airRadiusA.getModified(bPlayer);
this.waterRadius = getConfig().getDouble("Abilities.Water.WaterBubble.Radius"); this.waterRadius = waterRadiusA.getModified(bPlayer);
this.waterOrigins = new ConcurrentHashMap<>(); this.waterOrigins = new ConcurrentHashMap<>();
start(); start();
} }
@ -206,4 +210,10 @@ public class AirBubble extends AirAbility {
return waterOrigins; return waterOrigins;
} }
@Override
public void registerAttributes() {
airRadiusA = new Attribute<Double>(this, "airRadius", getConfig().getDouble("Abilities.Air.AirBubble.Radius"));
waterRadiusA = new Attribute<Double>(this, "waterRadius", getConfig().getDouble("Abilities.Water.WaterBubble.Radius"));
}
} }

View file

@ -11,8 +11,10 @@ import org.bukkit.util.Vector;
import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.AirAbility;
import com.projectkorra.projectkorra.util.Attribute;
import com.projectkorra.projectkorra.util.Attribute.Attributable;
public class AirBurst extends AirAbility { public class AirBurst extends AirAbility implements Attributable{
private boolean isCharged; private boolean isCharged;
private boolean isFallBurst; private boolean isFallBurst;
@ -27,6 +29,12 @@ public class AirBurst extends AirAbility {
private double particlePercentage; private double particlePercentage;
private ArrayList<AirBlast> blasts; private ArrayList<AirBlast> blasts;
private ArrayList<Entity> affectedEntities; private ArrayList<Entity> affectedEntities;
private static Attribute<Long> chargeTimeA;
private static Attribute<Double> fallThresholdA;
private static Attribute<Double> pushFactorA;
private static Attribute<Double> damageA;
private static Attribute<Double> blastAngleThetaA;
private static Attribute<Double> blastAnglePhiA;
public AirBurst(Player player, boolean isFallBurst) { public AirBurst(Player player, boolean isFallBurst) {
super(player); super(player);
@ -43,21 +51,17 @@ public class AirBurst extends AirAbility {
this.isFallBurst = isFallBurst; this.isFallBurst = isFallBurst;
this.isCharged = false; this.isCharged = false;
this.playerFallDistance = player.getFallDistance(); this.playerFallDistance = player.getFallDistance();
this.chargeTime = getConfig().getLong("Abilities.Air.AirBurst.ChargeTime"); this.chargeTime = chargeTimeA.getModified(bPlayer);
this.fallThreshold = getConfig().getDouble("Abilities.Air.AirBurst.FallThreshold"); this.fallThreshold = fallThresholdA.getModified(bPlayer);
this.pushFactor = getConfig().getDouble("Abilities.Air.AirBurst.PushFactor"); this.pushFactor = pushFactorA.getModified(bPlayer);
this.damage = getConfig().getDouble("Abilities.Air.AirBurst.Damage"); this.damage = damageA.getModified(bPlayer);
this.blastAnglePhi = getConfig().getDouble("Abilities.Air.AirBurst.AnglePhi"); this.blastAnglePhi = blastAnglePhiA.getModified(bPlayer);
this.blastAngleTheta = getConfig().getDouble("Abilities.Air.AirBurst.AngleTheta"); this.blastAngleTheta = blastAngleThetaA.getModified(bPlayer);
this.sneakParticles = getConfig().getInt("Abilities.Air.AirBurst.SneakParticles"); this.sneakParticles = getConfig().getInt("Abilities.Air.AirBurst.SneakParticles");
this.particlePercentage = getConfig().getDouble("Abilities.Air.AirBurst.ParticlePercentage"); this.particlePercentage = getConfig().getDouble("Abilities.Air.AirBurst.ParticlePercentage");
this.blasts = new ArrayList<>(); this.blasts = new ArrayList<>();
this.affectedEntities = new ArrayList<>(); this.affectedEntities = new ArrayList<>();
if (bPlayer.isAvatarState()) {
this.chargeTime = getConfig().getLong("Abilities.Avatar.AvatarState.Air.AirBurst.ChargeTime");
this.damage = getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirBurst.Damage");
}
start(); start();
} }
@ -315,4 +319,14 @@ public class AirBurst extends AirAbility {
public ArrayList<Entity> getAffectedEntities() { public ArrayList<Entity> getAffectedEntities() {
return affectedEntities; return affectedEntities;
} }
@Override
public void registerAttributes() {
chargeTimeA = new Attribute<Long>(this, "chargeTime", getConfig().getLong("Abilities.Air.AirBurst.ChargeTime"));
fallThresholdA = new Attribute<Double>(this, "fallThreshold", getConfig().getDouble("Abilities.Air.AirBurst.FallThreshold"));
pushFactorA = new Attribute<Double>(this, "pushFactor", getConfig().getDouble("Abilities.Air.AirBurst.PushFactor"));
damageA = new Attribute<Double>(this, "damage", getConfig().getDouble("Abilities.Air.AirBurst.Damage"));
blastAngleThetaA = new Attribute<Double>(this, "blastAngleTheta", getConfig().getDouble("Abilities.Air.AirBlast.AngleTheta"));
blastAnglePhiA = new Attribute<Double>(this, "blastAnglePhi", getConfig().getDouble("Abilities.Air.AirBlast.AnglePhi"));
}
} }

View file

@ -1,6 +1,5 @@
package com.projectkorra.projectkorra.airbending; package com.projectkorra.projectkorra.airbending;
import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import org.bukkit.Location; import org.bukkit.Location;
@ -13,22 +12,28 @@ import org.bukkit.util.Vector;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.AirAbility; import com.projectkorra.projectkorra.ability.AirAbility;
import com.projectkorra.projectkorra.ability.WaterAbility; import com.projectkorra.projectkorra.ability.WaterAbility;
import com.projectkorra.projectkorra.util.Attribute;
import com.projectkorra.projectkorra.util.Attribute.Attributable;
import com.projectkorra.projectkorra.util.Flight; import com.projectkorra.projectkorra.util.Flight;
public class AirScooter extends AirAbility { public class AirScooter extends AirAbility implements Attributable{
private double speed; private double speed;
private double interval; private double interval;
private double radius; private double radius;
private long cooldown; private long cooldown;
private double maxHeightFromGround; private double maxHeightFromGround;
private static Attribute<Double> speedA;
private static Attribute<Double> intervalA;
private static Attribute<Double> radiusA;
private static Attribute<Long> cooldownA;
private static Attribute<Double> heightA;
private Block floorblock; private Block floorblock;
private Random random; private Random random;
private ArrayList<Double> angles; private double phi = 0;
private boolean canFly; private boolean canFly;
private boolean hadFly; private boolean hadFly;
private double phi = 0;
public AirScooter(Player player) { public AirScooter(Player player) {
super(player); super(player);
@ -42,13 +47,12 @@ public class AirScooter extends AirAbility {
else if (bPlayer.isOnCooldown(this)) else if (bPlayer.isOnCooldown(this))
return; return;
this.speed = getConfig().getDouble("Abilities.Air.AirScooter.Speed"); this.speed = speedA.getModified(bPlayer);
this.interval = getConfig().getDouble("Abilities.Air.AirScooter.Interval"); this.interval = intervalA.getModified(bPlayer);
this.radius = getConfig().getDouble("Abilities.Air.AirScooter.Radius"); this.radius = radiusA.getModified(bPlayer);
this.cooldown = getConfig().getLong("Abilities.Air.AirScooter.Cooldown"); this.cooldown = cooldownA.getModified(bPlayer);
this.maxHeightFromGround = getConfig().getDouble("Abilities.Air.AirScooter.MaxHeightFromGround"); this.maxHeightFromGround = heightA.getModified(bPlayer);
this.random = new Random(); this.random = new Random();
this.angles = new ArrayList<>();
canFly = player.getAllowFlight(); canFly = player.getAllowFlight();
hadFly = player.isFlying(); hadFly = player.isFlying();
@ -59,10 +63,6 @@ public class AirScooter extends AirAbility {
player.setSprinting(false); player.setSprinting(false);
player.setSneaking(false); player.setSneaking(false);
for (int i = 0; i < 5; i++) {
angles.add((double) (60 * i));
}
start(); start();
} }
@ -109,7 +109,7 @@ public class AirScooter extends AirAbility {
} }
Vector velocity = player.getEyeLocation().getDirection().clone().normalize(); Vector velocity = player.getEyeLocation().getDirection().clone().normalize();
velocity = velocity.clone().normalize().multiply(speed); velocity = velocity.multiply(speed);
/* /*
* checks the players speed and ends the move if they are going too slow * checks the players speed and ends the move if they are going too slow
*/ */
@ -125,26 +125,30 @@ public class AirScooter extends AirAbility {
* lowers the player based on their distance from the ground. * lowers the player based on their distance from the ground.
*/ */
double distance = player.getLocation().getY() - (double) floorblock.getY(); double distance = player.getLocation().getY() - (double) floorblock.getY();
double dx = Math.abs(distance - 2.4); if (distance > 2.355) {
if (distance > 2.75) { velocity.setY(-0.15);
velocity.setY(-.40 * dx * dx); } else if (distance < 1.9) {
} else if (distance < 2) { velocity.setY(0.15);
velocity.setY(.40 * dx * dx);
} else { } else {
velocity.setY(0); velocity.setY(0);
} }
Location loc = player.getLocation(); Vector v = velocity.clone().setY(0);
if (!WaterAbility.isWater(player.getLocation().add(0, 2, 0).getBlock())) { Block b = floorblock.getLocation().clone().add(v.multiply(1.2)).getBlock();
loc.setY((double) floorblock.getY() + 1.5); if (!GeneralMethods.isSolid(b) && !b.isLiquid()) {
} else { velocity.add(new Vector(0, -0.6, 0));
} else if (GeneralMethods.isSolid(b.getRelative(BlockFace.UP)) || b.getRelative(BlockFace.UP).isLiquid()) {
velocity.add(new Vector(0, 0.6, 0));
}
if (WaterAbility.isWater(player.getLocation().getBlock())) {
remove();
return; return;
} }
player.setSprinting(false); player.setSprinting(false);
player.removePotionEffect(PotionEffectType.SPEED); player.removePotionEffect(PotionEffectType.SPEED);
player.setVelocity(velocity); player.setVelocity(velocity);
if (random.nextInt(4) == 0) { if (random.nextInt(4) == 0) {
playAirbendingSound(player.getLocation()); playAirbendingSound(player.getLocation());
} }
@ -161,13 +165,9 @@ public class AirScooter extends AirAbility {
bPlayer.addCooldown(this); bPlayer.addCooldown(this);
} }
/*
* The particles used for AirScooter phi = how many rings of particles the
* sphere has. theta = how dense the rings are. r = Radius of the sphere
*/
private void spinScooter() { private void spinScooter() {
Location origin = player.getLocation(); Location origin = player.getLocation().clone();
Location origin2 = player.getLocation(); Location origin2 = player.getLocation().clone();
phi += Math.PI / 10 * 4; phi += Math.PI / 10 * 4;
for (double theta = 0; theta <= 2 * Math.PI; theta += Math.PI / 10) { for (double theta = 0; theta <= 2 * Math.PI; theta += Math.PI / 10) {
double r = 0.6; double r = 0.6;
@ -186,7 +186,7 @@ public class AirScooter extends AirAbility {
origin2.subtract(x, y, z); origin2.subtract(x, y, z);
playAirbendingParticles(origin2, 1, 0F, 0F, 0F); playAirbendingParticles(origin2, 1, 0F, 0F, 0F);
origin2.add(x, y, z); origin2.add(x, y, z);
} }
} }
@Override @Override
@ -262,4 +262,13 @@ public class AirScooter extends AirAbility {
public void setCooldown(long cooldown) { public void setCooldown(long cooldown) {
this.cooldown = cooldown; this.cooldown = cooldown;
} }
@Override
public void registerAttributes() {
speedA = new Attribute<Double>(this, "speed", getConfig().getDouble("Abilities.Air.AirScooter.Speed"));
intervalA = new Attribute<Double>(this, "interval", getConfig().getDouble("Abilities.Air.AirScooter.Interval"));
radiusA = new Attribute<Double>(this, "radius", getConfig().getDouble("Abilities.Air.AirScooter.Radius"));
heightA = new Attribute<Double>(this, "height", getConfig().getDouble("Abilities.Air.AirScooter.MaxHeightFromGround"));
cooldownA = new Attribute<Long>(this, "cooldown", getConfig().getLong("Abilities.Air.AirScooter.Cooldown"));
}
} }

View file

@ -535,8 +535,8 @@ public class ConfigManager {
config.addDefault("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Entities", 4.5); config.addDefault("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Entities", 4.5);
config.addDefault("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Self", 4.0); config.addDefault("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Self", 4.0);
config.addDefault("Abilities.Avatar.AvatarState.AirSpout.Height", 26); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSpout.Height", 26);
config.addDefault("Abilities.Avatar.AvatarState.AirSuction.Push", 3.5); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSuction.Push", 3.5);
config.addDefault("Abilities.Avatar.AvatarState.Air.AirSwipe.Cooldown", 1000); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSwipe.Cooldown", 1000);
config.addDefault("Abilities.Avatar.AvatarState.Air.AirSwipe.Damage", 4.5); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSwipe.Damage", 4.5);
config.addDefault("Abilities.Avatar.AvatarState.Air.AirSwipe.Push", 1.0); config.addDefault("Abilities.Avatar.AvatarState.Air.AirSwipe.Push", 1.0);

View file

@ -0,0 +1,90 @@
package com.projectkorra.projectkorra.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.ability.CoreAbility;
public class Attribute<TYPE> {
private static Map<CoreAbility, Map<String, Attribute<? extends Object>>> attributes = new HashMap<>();
public List<AttributeModifier<TYPE>> modifiers;
public CoreAbility ability;
public String name;
public TYPE value;
public Attribute(CoreAbility ability, String name, TYPE value) {
this(ability, name, value, new ArrayList<AttributeModifier<TYPE>>());
}
public Attribute(CoreAbility ability, String name, TYPE value, List<AttributeModifier<TYPE>> modifiers) {
this.ability = ability;
this.name = name;
this.value = value;
if (!attributes.containsKey(ability)) {
attributes.put(ability, new HashMap<String, Attribute<? extends Object>>());
}
attributes.get(ability).put(name.toLowerCase(), this);
this.modifiers = new ArrayList<AttributeModifier<TYPE>>(modifiers);
}
public List<AttributeModifier<TYPE>> getModifiers() {
return modifiers;
}
public void addModifier(AttributeModifier<TYPE> modifier) {
modifiers.add(modifier);
}
public CoreAbility getAbility() {
return ability;
}
public String getName() {
return name;
}
public TYPE getDefault() {
return value;
}
public TYPE getModified(BendingPlayer bPlayer) {
TYPE modified = value;
for (AttributeModifier<TYPE> modifier : modifiers) {
if (!modifier.canModify(bPlayer)) {
continue;
}
value = modifier.newValue(value);
}
return modified;
}
public static Attribute<? extends Object> get(CoreAbility ability, String name) {
Map<String, Attribute<? extends Object>> map = attributes.containsKey(ability) ? attributes.get(ability) : new HashMap<String, Attribute<? extends Object>>();
if (map.isEmpty()) {
return null;
}
if (map.containsKey(name.toLowerCase())) {
return map.get(name.toLowerCase());
}
return null;
}
public interface AttributeModifier<TYPE> {
public boolean canModify(BendingPlayer bPlayer);
public TYPE newValue(TYPE value);
}
public interface Attributable {
/**
* Registers the {@link Attribute} objects the ability has
*/
public void registerAttributes();
}
}

View file

@ -0,0 +1,49 @@
package com.projectkorra.projectkorra.util.attributes;
import com.projectkorra.projectkorra.ability.CoreAbility;
import com.projectkorra.projectkorra.airbending.AirBlast;
import com.projectkorra.projectkorra.airbending.AirBurst;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.util.Attribute;
public class AttributeModifiers {
public AttributeModifiers() {
load();
}
@SuppressWarnings("unchecked")
public void load() {
Attribute<Double> airBlastPushSelf = (Attribute<Double>) Attribute.get(CoreAbility.getAbility(AirBlast.class), "pushFactor");
airBlastPushSelf.addModifier(new AvatarStateModifier<Double>() {
@Override
public Double newValue(Double value) {
return ConfigManager.getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Self");
}
});
Attribute<Double> airBlastPushOthers = (Attribute<Double>) Attribute.get(CoreAbility.getAbility(AirBlast.class), "pushFactorForOthers");
airBlastPushOthers.addModifier(new AvatarStateModifier<Double>() {
@Override
public Double newValue(Double value) {
return ConfigManager.getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirBlast.Push.Entities");
}
});
Attribute<Double> airBurstDamage = (Attribute<Double>) Attribute.get(CoreAbility.getAbility(AirBurst.class), "damage");
airBurstDamage.addModifier(new AvatarStateModifier<Double>() {
@Override
public Double newValue(Double value) {
return ConfigManager.getConfig().getDouble("Abilities.Avatar.AvatarState.Air.AirBurst.Damage");
}
});
Attribute<Long> airBurstChargetime = (Attribute<Long>) Attribute.get(CoreAbility.getAbility(AirBurst.class), "chargeTime");
airBurstChargetime.addModifier(new AvatarStateModifier<Long>() {
@Override
public Long newValue(Long value) {
return ConfigManager.getConfig().getLong("Abilities.Avatar.AvatarState.Air.AirBurst.ChargeTime");
}
});
}
}

View file

@ -0,0 +1,18 @@
package com.projectkorra.projectkorra.util.attributes;
import com.projectkorra.projectkorra.BendingPlayer;
import com.projectkorra.projectkorra.util.Attribute.AttributeModifier;
public class AvatarStateModifier<TYPE> implements AttributeModifier<TYPE>{
@Override
public boolean canModify(BendingPlayer bPlayer) {
return bPlayer.isAvatarState();
}
@Override
public TYPE newValue(TYPE value) {
return value;
}
}