Skip to content

Commit

Permalink
Fix: Wrong damage types with skill projectiles
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Apr 29, 2018
1 parent f1caba1 commit 0198a6f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ public void onIndirectEntityDamage(DamageEntityEvent event,
IEntity target = entityService.get(event.getTargetEntity());
ProjectileProperties projectileProperties = ProjectileProperties.cache.get(projectile);
if (projectileProperties != null) {
event.setCancelled(true);
ProjectileProperties.cache.remove(projectile);
projectileProperties.consumer.accept(shooter, target);
projectileProperties.consumer.accept(event, shooter, target);
return;
}

Expand Down Expand Up @@ -326,7 +327,7 @@ public void onSkillDamage(DamageEntityEvent event,
}
}
IEntity targetchar = entityService.get(event.getTargetEntity());
double finalDamage = event.getBaseDamage() * damageService.getEntityBonusDamage(caster, type);
double finalDamage = event.getOriginalDamage() * damageService.getEntityBonusDamage(caster, type);


try (CauseStackManager.StackFrame frame = causeStackManager.pushCauseFrame()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
package cz.neumimto.rpg.skills;

import cz.neumimto.rpg.IEntity;
import cz.neumimto.rpg.utils.TriConsumer;
import org.spongepowered.api.entity.projectile.Projectile;
import org.spongepowered.api.event.entity.DamageEntityEvent;

import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.BiConsumer;

/**
* Created by NeumimTo on 15.1.2015.
Expand All @@ -37,7 +38,7 @@ protected boolean removeEldestEntry(Map.Entry<UUID, ProjectileProperties> entry)
};*/

public static Map<Projectile, ProjectileProperties> cache = new WeakHashMap<>();
public BiConsumer<IEntity, IEntity> consumer;
public TriConsumer<DamageEntityEvent, IEntity, IEntity> consumer;
//protected Projectile t;
private double damage;
// private long lifetime;
Expand All @@ -50,12 +51,12 @@ public ProjectileProperties(Projectile t, IEntity caster) {
this.caster = caster;
}

public void onHit(BiConsumer<IEntity, IEntity> consumer) {
public void onHit(TriConsumer<DamageEntityEvent, IEntity, IEntity> consumer) {
this.consumer = consumer;
}

public void process(IEntity target) {
consumer.accept(caster, target);
public void process(DamageEntityEvent event, IEntity target) {
consumer.accept(event, caster, target);
}

public double getDamage() {
Expand Down
5 changes: 3 additions & 2 deletions Plugin/src/main/java/cz/neumimto/rpg/skills/SkillShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import cz.neumimto.core.ioc.Inject;
import cz.neumimto.rpg.IEntity;
import cz.neumimto.rpg.players.IActiveCharacter;
import cz.neumimto.rpg.utils.TriConsumer;
import org.spongepowered.api.Game;
import org.spongepowered.api.entity.projectile.Projectile;
import org.spongepowered.api.event.entity.DamageEntityEvent;

import java.util.Optional;
import java.util.function.BiConsumer;

/**
* Created by NeumimTo on 12.3.2015.
Expand All @@ -51,6 +52,6 @@ public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, Skil

protected abstract Class<Projectile> getProjectile(IActiveCharacter character, ExtendedSkillInfo info);

protected abstract BiConsumer<IEntity, IEntity> getHitConsumer();
protected abstract TriConsumer<DamageEntityEvent, IEntity, IEntity> getHitConsumer();

}
11 changes: 11 additions & 0 deletions Plugin/src/main/java/cz/neumimto/rpg/utils/TriConsumer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cz.neumimto.rpg.utils;

/**
* Created by NeumimTo on 29.4.2018.
*/
@FunctionalInterface
public interface TriConsumer<K, V, S> {

void accept(K k, V v, S s);

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, Skil
int slowamplf = getIntNodeValue(info, SkillNodes.AMPFLIER);


projectileProperties.onHit((caster, target) -> {
projectileProperties.onHit((event, caster, target) -> {
target.getEntity().damage(projectileProperties.getDamage(), build.build());
effectService.addEffect(new SlowPotion(caster, slowduration, slowamplf), caster, this);
});
Expand Down
17 changes: 12 additions & 5 deletions Skills/src/main/java/cz/neumimto/skills/active/SkillFireball.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package cz.neumimto.skills.active;

import static com.flowpowered.math.TrigMath.cos;
import static com.flowpowered.math.TrigMath.sin;

import com.flowpowered.math.imaginary.Quaterniond;
import com.flowpowered.math.vector.Vector3d;
import cz.neumimto.SkillLocalization;
import cz.neumimto.rpg.ResourceLoader;
import cz.neumimto.rpg.damage.SkillDamageSourceBuilder;
import cz.neumimto.rpg.players.IActiveCharacter;
import cz.neumimto.rpg.skills.*;
import cz.neumimto.rpg.skills.ActiveSkill;
import cz.neumimto.rpg.skills.ExtendedSkillInfo;
import cz.neumimto.rpg.skills.ProjectileProperties;
import cz.neumimto.rpg.skills.SkillModifier;
import cz.neumimto.rpg.skills.SkillNodes;
import cz.neumimto.rpg.skills.SkillResult;
import cz.neumimto.rpg.skills.SkillSettings;
import cz.neumimto.rpg.skills.SkillType;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
Expand All @@ -15,9 +25,6 @@
import org.spongepowered.api.event.cause.entity.damage.DamageTypes;
import org.spongepowered.api.world.World;

import static com.flowpowered.math.TrigMath.cos;
import static com.flowpowered.math.TrigMath.sin;

/**
* Created by NeumimTo on 23.12.2015.
*/
Expand Down Expand Up @@ -58,7 +65,7 @@ public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, Skil
build.fromSkill(this);
build.setCaster(character);
build.type(getDamageType());
projectileProperties.onHit((caster, target) -> {
projectileProperties.onHit((event, caster, target) -> {
target.getEntity().damage(projectileProperties.getDamage(), build.build());
});
return SkillResult.OK;
Expand Down

0 comments on commit 0198a6f

Please sign in to comment.