use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project Skree by Skelril.
the class PatientXManager method setupBossManager.
private void setupBossManager() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Zombie.class));
List<Instruction<BindCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Zombie> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Zombie bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Patient X"));
setMaxHealth(bossEnt, config.bossHealth, true);
}
return Optional.empty();
});
bindProcessor.add((condition, boss) -> {
Optional<Zombie> optBoss = boss.getTargetEntity();
if (optBoss.isPresent()) {
optBoss.get().offer(Keys.PERSISTS, true);
}
return Optional.empty();
});
bindProcessor.add((condition, boss) -> {
boss.getDetail().getZone().getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.GOLD, "Ice to meet you again!"));
return Optional.empty();
});
List<Instruction<UnbindCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> unbindProcessor = bossManager.getUnbindProcessor();
unbindProcessor.add((condition, boss) -> {
PatientXInstance inst = boss.getDetail().getZone();
Location<World> target = inst.getCenter();
for (Player player : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
player.setLocation(target);
boolean useX = Probability.getChance(2);
int accel = Probability.getChance(2) ? 1 : -1;
Vector3d v = new Vector3d(useX ? accel : 0, 0, !useX ? accel : 0);
player.setVelocity(v);
}
inst.freezeBlocks(100, false);
// Reset respawn mechanics
inst.bossDied();
return Optional.empty();
});
List<Instruction<DamageCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> damageProcessor = bossManager.getDamageProcessor();
damageProcessor.add((condition, boss) -> {
PatientXInstance inst = boss.getDetail().getZone();
DamageEntityEvent event = condition.getEvent();
// Nullify all modifiers
for (DamageFunction modifier : event.getModifiers()) {
event.setDamage(modifier.getModifier(), (a) -> a);
}
event.setBaseDamage(inst.getDifficulty() * config.baseBossHit);
return Optional.empty();
});
List<Instruction<DamagedCondition, Boss<Zombie, ZoneBossDetail<PatientXInstance>>>> damagedProcessor = bossManager.getDamagedProcessor();
damagedProcessor.add((condition, boss) -> {
DamageEntityEvent event = condition.getEvent();
Optional<DamageSource> optDamageSource = condition.getDamageSource();
if (optDamageSource.isPresent() && blockedDamage.contains(optDamageSource.get().getType())) {
event.setCancelled(true);
return Optional.empty();
}
return Optional.of((damagedCondition, zombieZoneBossDetailBoss) -> {
PatientXInstance inst = boss.getDetail().getZone();
if (optDamageSource.isPresent() && optDamageSource.get() instanceof EntityDamageSource) {
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
Task.builder().execute(() -> {
VelocityEntitySpawner.sendRadial(EntityTypes.SNOWBALL, inst.getBoss().get(), Cause.source(SpawnCause.builder().type(SpawnTypes.PROJECTILE).build()).build());
}).delayTicks(1).submit(SkreePlugin.inst());
} else {
Entity srcEntity = ((EntityDamageSource) optDamageSource.get()).getSource();
if (srcEntity instanceof Player) {
Optional<ItemStack> optHeld = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
if (optHeld.isPresent() && optHeld.get().getItem() == ItemTypes.BLAZE_ROD) {
inst.modifyDifficulty(2);
}
}
}
}
inst.modifyDifficulty(.5);
inst.teleportRandom(true);
return Optional.empty();
});
});
}
use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeAPI by SpongePowered.
the class SpongeAbstractDamageEntityEventTest method testAddModifier.
@Test
public void testAddModifier() {
Entity targetEntity = mockParam(Entity.class);
final int originalDamage = 1;
final int originalFinalDamage = 18;
final int firstModifierDamage = 2;
final int secondModifierDamage = 15;
final int modifiedFinalDamage = 36;
final int thirdDamage = 18;
DamageModifier firstModifer = mockParam(DamageModifier.class);
DamageModifier secondModifier = mockParam(DamageModifier.class);
DamageModifier thirdModifier = mockParam(DamageModifier.class);
DoubleUnaryOperator thirdFunction = p -> p;
List<DamageFunction> originalFunctions = Lists.newArrayList(DamageFunction.of(firstModifer, p -> p * 2), DamageFunction.of(secondModifier, p -> p * 5));
List<DamageFunction> newFunctions = Lists.newArrayList(originalFunctions);
newFunctions.add(DamageFunction.of(thirdModifier, thirdFunction));
DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), originalFunctions, targetEntity, originalDamage);
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
assertThat(event.isModifierApplicable(thirdModifier), is(false));
event.setDamage(thirdModifier, thirdFunction);
assertThat(event.getDamage(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(event.getDamage(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getDamage(thirdModifier), is(closeTo(thirdDamage, ERROR)));
assertThat(event.getOriginalModifierDamage(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(event.getOriginalModifierDamage(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getOriginalDamage(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalDamage(), is(closeTo(originalFinalDamage, ERROR)));
assertThat(event.getFinalDamage(), is(closeTo(modifiedFinalDamage, ERROR)));
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
assertThat(event.getModifiers(), is(Matchers.equalTo(newFunctions)));
}
use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeAPI by SpongePowered.
the class SpongeAbstractDamageEntityEventTest method testSetModifiers.
@Test
public void testSetModifiers() {
Entity targetEntity = mockParam(Entity.class);
final int originalDamage = 1;
final int originalFinalDamage = 18;
final int firstModifierDamage = 2;
final int secondModifierDamage = 15;
final int firstChangedDamage = 1;
final int secondChangedDamage = 10;
final int modifiedFinalDamage = 12;
DamageModifier firstModifer = mockParam(DamageModifier.class);
DamageModifier secondModifier = mockParam(DamageModifier.class);
List<DamageFunction> originalFunctions = Lists.newArrayList(DamageFunction.of(firstModifer, p -> p * 2), DamageFunction.of(secondModifier, p -> p * 5));
DamageEntityEvent event = SpongeEventFactory.createDamageEntityEvent(Cause.of(EventContext.empty(), "none"), originalFunctions, targetEntity, originalDamage);
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
DoubleUnaryOperator newFunction = p -> p;
event.setDamage(firstModifer, newFunction);
assertThat(event.getDamage(firstModifer), is(closeTo(firstChangedDamage, ERROR)));
assertThat(event.getDamage(secondModifier), is(closeTo(secondChangedDamage, ERROR)));
assertThat(event.getOriginalModifierDamage(firstModifer), is(closeTo(firstModifierDamage, ERROR)));
assertThat(event.getOriginalModifierDamage(secondModifier), is(closeTo(secondModifierDamage, ERROR)));
assertThat(event.getOriginalDamage(), is(closeTo(originalDamage, ERROR)));
assertThat(event.getOriginalFinalDamage(), is(closeTo(originalFinalDamage, ERROR)));
assertThat(event.getFinalDamage(), is(closeTo(modifiedFinalDamage, ERROR)));
assertThat(event.getOriginalFunctions(), is(Matchers.equalTo(originalFunctions)));
assertThat(event.getModifiers(), is(Matchers.equalTo(Lists.newArrayList(DamageFunction.of(firstModifer, newFunction), originalFunctions.get(1)))));
}
use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeAPI by SpongePowered.
the class AbstractDamageEntityEvent method addModifierAfter.
@Override
public void addModifierAfter(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> after) {
checkNotNull(damageModifier, "Damage modifier was null!");
checkNotNull(function, "Function was null!");
int indexToAddAfter = -1;
int index = 0;
for (ModifierFunction<DamageModifier> tuple : this.modifierFunctions) {
checkArgument(!tuple.getModifier().equals(damageModifier), "Cannot add a duplicate modifier!");
if (after.contains(tuple.getModifier().getType())) {
indexToAddAfter = index;
}
index++;
}
if (indexToAddAfter == -1) {
this.modifierFunctions.add(new DamageFunction(damageModifier, function));
} else {
this.modifierFunctions.add(indexToAddAfter + 1, new DamageFunction(damageModifier, function));
}
this.recalculateDamages(this.baseDamage);
}
use of org.spongepowered.api.event.cause.entity.damage.DamageFunction in project SpongeAPI by SpongePowered.
the class AbstractAttackEntityEvent method addDamageModifierBefore.
@Override
public void addDamageModifierBefore(DamageModifier damageModifier, DoubleUnaryOperator function, Set<DamageModifierType> before) {
checkNotNull(damageModifier, "Damage modifier was null!");
checkNotNull(function, "Function was null!");
int indexToAddBefore = -1;
int index = 0;
for (ModifierFunction<DamageModifier> tuple : this.modifierFunctions) {
checkArgument(!tuple.getModifier().equals(damageModifier), "Cannot add a duplicate modifier!");
if (before.contains(tuple.getModifier().getType())) {
indexToAddBefore = index;
}
index++;
}
if (indexToAddBefore == -1) {
this.modifierFunctions.add(new DamageFunction(damageModifier, function));
} else {
this.modifierFunctions.add(indexToAddBefore, new DamageFunction(damageModifier, function));
}
this.recalculateDamages(this.baseDamage);
}
Aggregations