use of org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource in project TotalEconomy by Erigitic.
the class TEJobManager method onPlayerKillEntity.
/**
* Used for the break option in jobs. Will check if the job has the break node and if it does it will check if the
* block that was broken is present in the config of the player's job. If it is, it will grab the job exp reward as
* well as the pay.
*
* @param event DestructEntityEvent.Death
*/
@Listener
public void onPlayerKillEntity(DestructEntityEvent.Death event) {
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
EntityDamageSource damageSource = optDamageSource.get();
Entity killer = damageSource.getSource();
Entity victim = event.getTargetEntity();
if (!(killer instanceof Player)) {
// If a projectile was shot to kill an entity, this will grab the player who shot it
Optional<UUID> damageCreator = damageSource.getSource().getCreator();
if (damageCreator.isPresent())
killer = Sponge.getServer().getPlayer(damageCreator.get()).get();
}
if (killer instanceof Player) {
Player player = (Player) killer;
UUID playerUUID = player.getUniqueId();
String victimName = victim.getType().getName();
String playerJob = getPlayerJob(player);
Optional<TEJob> optPlayerJob = getJob(playerJob, true);
if (optPlayerJob.isPresent()) {
Optional<TEActionReward> reward = Optional.empty();
List<String> sets = optPlayerJob.get().getSets();
for (String s : sets) {
Optional<TEJobSet> optSet = getJobSet(s);
if (!optSet.isPresent()) {
logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
continue;
}
reward = optSet.get().getRewardFor("kill", victimName);
}
if (reward.isPresent()) {
int expAmount = reward.get().getExpReward();
BigDecimal payAmount = reward.get().getMoneyReward();
boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
if (notify) {
notifyPlayer(player, payAmount);
}
addExp(player, expAmount);
playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
checkForLevel(player);
}
}
}
}
}
use of org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource in project SpongeCommon by SpongePowered.
the class MixinEntityPlayer method attackTargetEntityWithCurrentItem.
/**
* @author gabizou - April 8th, 2016
* @author gabizou - April 11th, 2016 - Update for 1.9 - This enitre method was rewritten
*
* @reason Rewrites the attackTargetEntityWithCurrentItem to throw an {@link AttackEntityEvent} prior
* to the ensuing {@link DamageEntityEvent}. This should cover all cases where players are
* attacking entities and those entities override {@link EntityLivingBase#attackEntityFrom(DamageSource, float)}
* and effectively bypass our damage event hooks.
*
* LVT Rename Table:
* float f | damage |
* float f1 | enchantmentDamage |
* float f2 | attackStrength |
* boolean flag | isStrongAttack |
* boolean flag1 | isSprintingAttack |
* boolean flag2 | isCriticalAttack | Whether critical particles will spawn and of course, multiply the output damage
* boolean flag3 | isSweapingAttack | Whether the player is sweaping an attack and will deal AoE damage
* int i | knockbackModifier | The knockback modifier, must be set from the event after it has been thrown
* float f4 | targetOriginalHealth | This is initially set as the entity original health
* boolean flag4 | litEntityOnFire | This is an internal flag to where if the attack failed, the entity is no longer set on fire
* int j | fireAspectModifier | Literally just to check that the weapon used has fire aspect enchantments
* double d0 | distanceWalkedDelta | This checks that the distance walked delta is more than the normal walking speed to evaluate if you're making a sweaping attack
* double d1 | targetMotionX | Current target entity motion x vector
* double d2 | targetMotionY | Current target entity motion y vector
* double d3 | targetMotionZ | Current target entity motion z vector
* boolean flag5 | attackSucceeded | Whether the attack event succeeded
*
* @param targetEntity The target entity
*/
@Overwrite
public void attackTargetEntityWithCurrentItem(Entity targetEntity) {
// Sponge Start - Add SpongeImpl hook to override in forge as necessary
if (!SpongeImplHooks.checkAttackEntity((EntityPlayer) (Object) this, targetEntity)) {
return;
}
// Sponge End
if (targetEntity.canBeAttackedWithItem()) {
if (!targetEntity.hitByEntity((EntityPlayer) (Object) this)) {
// Sponge Start - Prepare our event values
// float damage = (float) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
final double originalBaseDamage = this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
float damage = (float) originalBaseDamage;
// Sponge End
float enchantmentDamage = 0.0F;
// Spogne Start - Redirect getting enchantments for our damage event handlers
// if (targetEntity instanceof EntityLivingBase) {
// enchantmentDamage = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((EntityLivingBase) targetEntity).getCreatureAttribute());
// } else {
// enchantmentDamage = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), EnumCreatureAttribute.UNDEFINED);
// }
float attackStrength = this.getCooledAttackStrength(0.5F);
final List<ModifierFunction<DamageModifier>> originalFunctions = new ArrayList<>();
final EnumCreatureAttribute creatureAttribute = targetEntity instanceof EntityLivingBase ? ((EntityLivingBase) targetEntity).getCreatureAttribute() : EnumCreatureAttribute.UNDEFINED;
final List<DamageFunction> enchantmentModifierFunctions = DamageEventHandler.createAttackEnchantmentFunction(this.getHeldItemMainhand(), creatureAttribute, attackStrength);
// This is kept for the post-damage event handling
final List<DamageModifier> enchantmentModifiers = enchantmentModifierFunctions.stream().map(ModifierFunction::getModifier).collect(Collectors.toList());
enchantmentDamage = (float) enchantmentModifierFunctions.stream().map(ModifierFunction::getFunction).mapToDouble(function -> function.applyAsDouble(originalBaseDamage)).sum();
originalFunctions.addAll(enchantmentModifierFunctions);
// Sponge End
originalFunctions.add(DamageEventHandler.provideCooldownAttackStrengthFunction((EntityPlayer) (Object) this, attackStrength));
damage = damage * (0.2F + attackStrength * attackStrength * 0.8F);
enchantmentDamage = enchantmentDamage * attackStrength;
this.resetCooldown();
if (damage > 0.0F || enchantmentDamage > 0.0F) {
boolean isStrongAttack = attackStrength > 0.9F;
boolean isSprintingAttack = false;
boolean isCriticalAttack = false;
boolean isSweapingAttack = false;
int knockbackModifier = 0;
knockbackModifier = knockbackModifier + EnchantmentHelper.getKnockbackModifier((EntityPlayer) (Object) this);
if (this.isSprinting() && isStrongAttack) {
// Sponge - Only play sound after the event has be thrown and not cancelled.
// this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.entity_player_attack_knockback, this.getSoundCategory(), 1.0F, 1.0F);
++knockbackModifier;
isSprintingAttack = true;
}
isCriticalAttack = isStrongAttack && this.fallDistance > 0.0F && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(MobEffects.BLINDNESS) && !this.isRiding() && targetEntity instanceof EntityLivingBase;
isCriticalAttack = isCriticalAttack && !this.isSprinting();
if (isCriticalAttack) {
// Sponge Start - add critical attack tuple
// damage *= 1.5F; // Sponge - This is handled in the event
originalFunctions.add(DamageEventHandler.provideCriticalAttackTuple((EntityPlayer) (Object) this));
// Sponge End
}
// damage = damage + enchantmentDamage; // Sponge - We don't need this since our event will re-assign the damage to deal
double distanceWalkedDelta = (double) (this.distanceWalkedModified - this.prevDistanceWalkedModified);
final ItemStack heldItem = this.getHeldItem(EnumHand.MAIN_HAND);
if (isStrongAttack && !isCriticalAttack && !isSprintingAttack && this.onGround && distanceWalkedDelta < (double) this.getAIMoveSpeed()) {
ItemStack itemstack = heldItem;
if (itemstack.getItem() instanceof ItemSword) {
isSweapingAttack = true;
}
}
// Sponge Start - Create the event and throw it
final DamageSource damageSource = DamageSource.causePlayerDamage((EntityPlayer) (Object) this);
final boolean isMainthread = !this.world.isRemote;
if (isMainthread) {
Sponge.getCauseStackManager().pushCause(damageSource);
}
final Cause currentCause = isMainthread ? Sponge.getCauseStackManager().getCurrentCause() : Cause.of(EventContext.empty(), damageSource);
final AttackEntityEvent event = SpongeEventFactory.createAttackEntityEvent(currentCause, originalFunctions, EntityUtil.fromNative(targetEntity), knockbackModifier, originalBaseDamage);
SpongeImpl.postEvent(event);
if (isMainthread) {
Sponge.getCauseStackManager().popCause();
}
if (event.isCancelled()) {
return;
}
damage = (float) event.getFinalOutputDamage();
// sponge - need final for later events
final double attackDamage = damage;
knockbackModifier = event.getKnockbackModifier();
enchantmentDamage = (float) enchantmentModifiers.stream().mapToDouble(event::getOutputDamage).sum();
// Sponge End
float targetOriginalHealth = 0.0F;
boolean litEntityOnFire = false;
int fireAspectModifier = EnchantmentHelper.getFireAspectModifier((EntityPlayer) (Object) this);
if (targetEntity instanceof EntityLivingBase) {
targetOriginalHealth = ((EntityLivingBase) targetEntity).getHealth();
if (fireAspectModifier > 0 && !targetEntity.isBurning()) {
litEntityOnFire = true;
targetEntity.setFire(1);
}
}
double targetMotionX = targetEntity.motionX;
double targetMotionY = targetEntity.motionY;
double targetMotionZ = targetEntity.motionZ;
boolean attackSucceeded = targetEntity.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) (Object) this), damage);
if (attackSucceeded) {
if (knockbackModifier > 0) {
if (targetEntity instanceof EntityLivingBase) {
((EntityLivingBase) targetEntity).knockBack((EntityPlayer) (Object) this, (float) knockbackModifier * 0.5F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
} else {
targetEntity.addVelocity((double) (-MathHelper.sin(this.rotationYaw * 0.017453292F) * (float) knockbackModifier * 0.5F), 0.1D, (double) (MathHelper.cos(this.rotationYaw * 0.017453292F) * (float) knockbackModifier * 0.5F));
}
this.motionX *= 0.6D;
this.motionZ *= 0.6D;
this.setSprinting(false);
}
if (isSweapingAttack) {
for (EntityLivingBase entitylivingbase : this.world.getEntitiesWithinAABB(EntityLivingBase.class, targetEntity.getEntityBoundingBox().grow(1.0D, 0.25D, 1.0D))) {
if (entitylivingbase != (EntityPlayer) (Object) this && entitylivingbase != targetEntity && !this.isOnSameTeam(entitylivingbase) && this.getDistanceSq(entitylivingbase) < 9.0D) {
// Sponge Start - Do a small event for these entities
// entitylivingbase.knockBack(this, 0.4F, (double)MathHelper.sin(this.rotationYaw * 0.017453292F), (double)(-MathHelper.cos(this.rotationYaw * 0.017453292F)));
// entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage(this), 1.0F);
final EntityDamageSource sweepingAttackSource = EntityDamageSource.builder().entity(this).type(DamageTypes.SWEEPING_ATTACK).build();
try (final StackFrame frame = isMainthread ? Sponge.getCauseStackManager().pushCauseFrame() : null) {
if (isMainthread) {
Sponge.getCauseStackManager().pushCause(sweepingAttackSource);
}
final ItemStackSnapshot heldSnapshot = ItemStackUtil.snapshotOf(heldItem);
if (isMainthread) {
Sponge.getCauseStackManager().addContext(EventContextKeys.WEAPON, heldSnapshot);
}
final DamageFunction sweapingFunction = DamageFunction.of(DamageModifier.builder().cause(Cause.of(EventContext.empty(), heldSnapshot)).item(heldSnapshot).type(DamageModifierTypes.SWEEPING).build(), (incoming) -> EnchantmentHelper.getSweepingDamageRatio((EntityPlayer) (Object) this) * attackDamage);
final List<DamageFunction> sweapingFunctions = new ArrayList<>();
sweapingFunctions.add(sweapingFunction);
AttackEntityEvent sweepingAttackEvent = SpongeEventFactory.createAttackEntityEvent(currentCause, sweapingFunctions, EntityUtil.fromNative(entitylivingbase), 1, 1.0D);
SpongeImpl.postEvent(sweepingAttackEvent);
if (!sweepingAttackEvent.isCancelled()) {
entitylivingbase.knockBack((EntityPlayer) (Object) this, sweepingAttackEvent.getKnockbackModifier() * 0.4F, (double) MathHelper.sin(this.rotationYaw * 0.017453292F), (double) (-MathHelper.cos(this.rotationYaw * 0.017453292F)));
entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) (Object) this), (float) sweepingAttackEvent.getFinalOutputDamage());
}
}
// Sponge End
}
}
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0F, 1.0F);
this.spawnSweepParticles();
}
if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
((EntityPlayerMP) targetEntity).connection.sendPacket(new SPacketEntityVelocity(targetEntity));
targetEntity.velocityChanged = false;
targetEntity.motionX = targetMotionX;
targetEntity.motionY = targetMotionY;
targetEntity.motionZ = targetMotionZ;
}
if (isCriticalAttack) {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0F, 1.0F);
this.onCriticalHit(targetEntity);
}
if (!isCriticalAttack && !isSweapingAttack) {
if (isStrongAttack) {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0F, 1.0F);
} else {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0F, 1.0F);
}
}
if (enchantmentDamage > 0.0F) {
this.onEnchantmentCritical(targetEntity);
}
this.setLastAttackedEntity(targetEntity);
if (targetEntity instanceof EntityLivingBase) {
EnchantmentHelper.applyThornEnchantments((EntityLivingBase) targetEntity, (EntityPlayer) (Object) this);
}
EnchantmentHelper.applyArthropodEnchantments((EntityPlayer) (Object) this, targetEntity);
ItemStack itemstack1 = this.getHeldItemMainhand();
Entity entity = targetEntity;
if (targetEntity instanceof MultiPartEntityPart) {
IEntityMultiPart ientitymultipart = ((MultiPartEntityPart) targetEntity).parent;
if (ientitymultipart instanceof EntityLivingBase) {
entity = (EntityLivingBase) ientitymultipart;
}
}
if (!itemstack1.isEmpty() && targetEntity instanceof EntityLivingBase) {
itemstack1.hitEntity((EntityLivingBase) targetEntity, (EntityPlayer) (Object) this);
if (itemstack1.isEmpty()) {
this.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
}
}
if (targetEntity instanceof EntityLivingBase) {
float f5 = targetOriginalHealth - ((EntityLivingBase) targetEntity).getHealth();
this.addStat(StatList.DAMAGE_DEALT, Math.round(f5 * 10.0F));
if (fireAspectModifier > 0) {
targetEntity.setFire(fireAspectModifier * 4);
}
if (this.world instanceof WorldServer && f5 > 2.0F) {
int k = (int) ((double) f5 * 0.5D);
((WorldServer) this.world).spawnParticle(EnumParticleTypes.DAMAGE_INDICATOR, targetEntity.posX, targetEntity.posY + (double) (targetEntity.height * 0.5F), targetEntity.posZ, k, 0.1D, 0.0D, 0.1D, 0.2D, new int[0]);
}
}
this.addExhaustion(0.3F);
} else {
this.world.playSound((EntityPlayer) null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0F, 1.0F);
if (litEntityOnFire) {
targetEntity.extinguish();
}
}
}
}
}
}
use of org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource 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.source.EntityDamageSource in project Skree by Skelril.
the class ShnugglesPrimeInstance method runAttack.
public void runAttack(ShnugglesPrimeAttack attackCase) {
Optional<Giant> optBoss = getBoss();
if (!optBoss.isPresent()) {
return;
}
Giant boss = optBoss.get();
double bossHealth = getHealth(boss);
double maxBossHealth = getMaxHealth(boss);
double delay = 15000;
if (lastAttackTime != 0 && System.currentTimeMillis() - lastAttackTime <= delay) {
return;
}
Collection<Player> contained = getPlayers(PARTICIPANT);
if (contained.isEmpty()) {
return;
}
// AI-ish system
if ((attackCase == ShnugglesPrimeAttack.EVERLASTING || attackCase == ShnugglesPrimeAttack.MINION_LEECH) && bossHealth > maxBossHealth * .9) {
attackCase = Probability.getChance(2) ? ShnugglesPrimeAttack.DARK_POTIONS : ShnugglesPrimeAttack.CORRUPTION;
}
for (Player player : contained) {
if (player.get(Keys.HEALTH).get() < 4) {
attackCase = ShnugglesPrimeAttack.CORRUPTION;
break;
}
}
Collection<Zombie> zombies = getContained(Zombie.class);
if (zombies.size() > 200) {
attackCase = ShnugglesPrimeAttack.BASK_IN_MY_GLORY;
}
if (bossHealth < maxBossHealth * .4 && Probability.getChance(5)) {
if (zombies.size() < 100 && bossHealth > 200) {
attackCase = ShnugglesPrimeAttack.EVERLASTING;
} else {
attackCase = ShnugglesPrimeAttack.MINION_LEECH;
}
}
if ((attackCase == ShnugglesPrimeAttack.BLINDNESS || attackCase == ShnugglesPrimeAttack.FIRE) && bossHealth < maxBossHealth * .15) {
runRandomAttack();
return;
}
switch(attackCase) {
case WRATH:
sendAttackBroadcast("Taste my wrath!", AttackSeverity.NORMAL);
for (Player player : contained) {
player.offer(Keys.VELOCITY, new Vector3d(random.nextDouble() * 3 - 1.5, random.nextDouble() * 1 + .5, random.nextDouble() * 3 - 1.5));
player.offer(Keys.FIRE_TICKS, 20 * 3);
}
break;
case CORRUPTION:
sendAttackBroadcast("Embrace my corruption!", AttackSeverity.NORMAL);
PotionEffect witherEffect = PotionEffect.of(PotionEffectTypes.WITHER, 1, 20 * 3);
for (Player player : contained) {
List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
potionEffects.add(witherEffect);
player.offer(Keys.POTION_EFFECTS, potionEffects);
}
break;
case BLINDNESS:
sendAttackBroadcast("Are you BLIND? Mwhahahaha!", AttackSeverity.NORMAL);
PotionEffect blindnessEffect = PotionEffect.of(PotionEffectTypes.BLINDNESS, 0, 20 * 4);
for (Player player : contained) {
List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
potionEffects.add(blindnessEffect);
player.offer(Keys.POTION_EFFECTS, potionEffects);
}
break;
case TANGO_TIME:
sendAttackBroadcast("Tango time!", AttackSeverity.ULTIMATE);
activeAttacks.add(ShnugglesPrimeAttack.TANGO_TIME);
Task.builder().delay(7, TimeUnit.SECONDS).execute(() -> {
if (!isBossSpawned()) {
return;
}
for (Player player : getPlayers(PARTICIPANT)) {
// TODO Convert to Sponge
if (((EntityGiantZombie) boss).canEntityBeSeen(tf(player))) {
player.sendMessage(Text.of(TextColors.YELLOW, "Come closer..."));
player.setLocation(boss.getLocation());
EntityDamageSource source = EntityDamageSource.builder().entity(boss).type(DamageTypes.ATTACK).build();
player.damage(100, source, Cause.source(boss).build());
player.offer(Keys.VELOCITY, new Vector3d(random.nextDouble() * 1.7 - 1.5, random.nextDouble() * 2, random.nextDouble() * 1.7 - 1.5));
} else {
player.sendMessage(Text.of(TextColors.YELLOW, "Fine... No tango this time..."));
}
}
sendAttackBroadcast("Now wasn't that fun?", AttackSeverity.INFO);
activeAttacks.remove(ShnugglesPrimeAttack.TANGO_TIME);
}).submit(SkreePlugin.inst());
break;
case EVERLASTING:
if (!damageHeals) {
activeAttacks.add(ShnugglesPrimeAttack.EVERLASTING);
sendAttackBroadcast("I am everlasting!", AttackSeverity.NORMAL);
damageHeals = true;
Task.builder().delay(12, TimeUnit.SECONDS).execute(() -> {
if (damageHeals) {
damageHeals = false;
if (!isBossSpawned()) {
return;
}
sendAttackBroadcast("Thank you for your assistance.", AttackSeverity.INFO);
}
activeAttacks.remove(ShnugglesPrimeAttack.EVERLASTING);
}).submit(SkreePlugin.inst());
break;
}
runRandomAttack();
return;
case FIRE:
sendAttackBroadcast("Fire is your friend...", AttackSeverity.NORMAL);
for (Player player : contained) {
player.offer(Keys.FIRE_TICKS, 20 * 5);
}
break;
case BASK_IN_MY_GLORY:
if (!damageHeals) {
sendAttackBroadcast("Bask in my glory!", AttackSeverity.ULTIMATE);
activeAttacks.add(ShnugglesPrimeAttack.BASK_IN_MY_GLORY);
Task.builder().delay(7, TimeUnit.SECONDS).execute(() -> {
if (!isBossSpawned()) {
return;
}
boolean baskInGlory = false;
for (Player player : getContained(Player.class)) {
// TODO Convert to Sponge
if (((EntityGiantZombie) boss).canEntityBeSeen(tf(player))) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You!"));
baskInGlory = true;
}
}
// Attack
if (baskInGlory) {
damageHeals = true;
spawnPts.stream().filter(pt -> Probability.getChance(12)).forEach(pt -> {
Explosion explosion = Explosion.builder().shouldDamageEntities(true).location(pt).radius(10).build();
getRegion().getExtent().triggerExplosion(explosion, Cause.source(SkreePlugin.container()).owner(boss).build());
});
// Schedule Reset
Task.builder().delay(500, TimeUnit.MILLISECONDS).execute(() -> {
damageHeals = false;
}).submit(SkreePlugin.inst());
return;
}
// Notify if avoided
sendAttackBroadcast("Gah... Afraid are you friends?", AttackSeverity.INFO);
activeAttacks.remove(ShnugglesPrimeAttack.BASK_IN_MY_GLORY);
}).submit(SkreePlugin.inst());
break;
}
runRandomAttack();
break;
case DARK_POTIONS:
sendAttackBroadcast("Unleash the inner darkness!", AttackSeverity.NORMAL);
PotionEffect instantDamageEffect = PotionEffect.of(PotionEffectTypes.INSTANT_DAMAGE, 0, 1);
for (Living entity : getContained(Zombie.class)) {
if (!Probability.getChance(5)) {
continue;
}
entity.offer(Keys.HEALTH, 0D);
Location targetLoc = entity.getLocation();
Entity potion = getRegion().getExtent().createEntity(EntityTypes.SPLASH_POTION, targetLoc.getPosition());
potion.offer(Keys.POTION_EFFECTS, Lists.newArrayList(instantDamageEffect));
getRegion().getExtent().spawnEntity(potion, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
}
return;
case MINION_LEECH:
sendAttackBroadcast("My minions our time is now!", AttackSeverity.ULTIMATE);
activeAttacks.add(ShnugglesPrimeAttack.MINION_LEECH);
IntegratedRunnable minionEater = new IntegratedRunnable() {
@Override
public boolean run(int times) {
if (!isBossSpawned()) {
return true;
}
for (Living entity : getContained(Living.class)) {
// TODO convert to Sponge
if (entity instanceof Giant || !Probability.getChance(5) || !((EntityGiantZombie) boss).canEntityBeSeen((EntityLivingBase) entity)) {
continue;
}
double realDamage = entity.get(Keys.HEALTH).get();
// TODO convert to Sponge
if (entity instanceof Zombie && ((EntityZombie) entity).isChild()) {
entity.offer(Keys.HEALTH, 0D);
} else {
DamageSource source = DamageSource.builder().type(DamageTypes.ATTACK).build();
entity.damage(realDamage, source, Cause.source(boss).build());
}
toHeal += Math.min(1, realDamage / 3);
}
if (new TimeFilter(-1, 2).matchesFilter(times + 1)) {
getPlayerMessageChannel(SPECTATOR).send(Text.of(TextColors.DARK_AQUA, "The boss has drawn in: " + (int) toHeal + " health."));
}
return true;
}
@Override
public void end() {
if (!isBossSpawned()) {
return;
}
heal(boss, toHeal);
toHeal = 0;
sendAttackBroadcast("Thank you my minions!", AttackSeverity.INFO);
printBossHealth();
activeAttacks.remove(ShnugglesPrimeAttack.MINION_LEECH);
}
};
TimedRunnable<IntegratedRunnable> minonEatingTask = new TimedRunnable<>(minionEater, 20);
Task minionEatingTaskExecutor = Task.builder().interval(500, TimeUnit.MILLISECONDS).execute(minonEatingTask).submit(SkreePlugin.inst());
minonEatingTask.setTask(minionEatingTaskExecutor);
break;
}
lastAttackTime = System.currentTimeMillis();
lastAttack = attackCase;
}
use of org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource in project Skree by Skelril.
the class ShnugglesPrimeManager method setupBossManager.
private void setupBossManager() {
Sponge.getEventManager().registerListeners(SkreePlugin.inst(), new BossListener<>(bossManager, Giant.class));
List<Instruction<BindCondition, Boss<Giant, ZoneBossDetail<ShnugglesPrimeInstance>>>> bindProcessor = bossManager.getBindProcessor();
bindProcessor.add((condition, boss) -> {
Optional<Giant> optBossEnt = boss.getTargetEntity();
if (optBossEnt.isPresent()) {
Giant bossEnt = optBossEnt.get();
bossEnt.offer(Keys.DISPLAY_NAME, Text.of("Shnuggles Prime"));
setMaxHealth(bossEnt, 750, true);
}
return Optional.empty();
});
bindProcessor.add((condition, boss) -> {
Optional<Giant> 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, "I live again!"));
return Optional.empty();
});
List<Instruction<UnbindCondition, Boss<Giant, ZoneBossDetail<ShnugglesPrimeInstance>>>> unbindProcessor = bossManager.getUnbindProcessor();
unbindProcessor.add((condition, boss) -> {
ShnugglesPrimeInstance inst = boss.getDetail().getZone();
// Reset respawn mechanics
inst.bossDied();
// Buff babies
inst.buffBabies();
return Optional.empty();
});
unbindProcessor.add((condition, boss) -> {
ShnugglesPrimeInstance inst = boss.getDetail().getZone();
int playerCount = inst.getPlayers(PlayerClassifier.PARTICIPANT).size();
Collection<ItemStack> drops = DROP_TABLE.getDrops(Math.min(7000, playerCount * 1500));
Optional<Giant> optEnt = boss.getTargetEntity();
if (optEnt.isPresent()) {
Task.builder().execute(() -> {
new ItemDropper(optEnt.get().getLocation()).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}).delayTicks(1).submit(SkreePlugin.inst());
}
return Optional.empty();
});
List<Instruction<DamagedCondition, Boss<Giant, ZoneBossDetail<ShnugglesPrimeInstance>>>> damagedProcessor = bossManager.getDamagedProcessor();
damagedProcessor.add((condition, boss) -> {
ShnugglesPrimeInstance inst = boss.getDetail().getZone();
DamageEntityEvent event = condition.getEvent();
// Schedule a task to change the display name to show HP
Task.builder().execute(inst::printBossHealth).delayTicks(1).submit(SkreePlugin.inst());
if (inst.damageHeals()) {
if (inst.isActiveAttack(ShnugglesPrimeAttack.BASK_IN_MY_GLORY)) {
if (boss.getTargetEntity().isPresent()) {
toFullHealth(boss.getTargetEntity().get());
}
} else {
double healedDamage = event.getFinalDamage() * 2;
if (boss.getTargetEntity().isPresent()) {
heal(boss.getTargetEntity().get(), healedDamage);
}
}
event.setBaseDamage(0);
if (Probability.getChance(3) && event.getCause().first(Player.class).isPresent()) {
int affected = 0;
if (boss.getTargetEntity().isPresent()) {
for (Entity e : boss.getTargetEntity().get().getNearbyEntities(8)) {
if (e.isLoaded() && !e.isRemoved() && e instanceof Player && inst.contains(e)) {
e.setVelocity(new Vector3d(Math.random() * 3 - 1.5, Math.random() * 4, Math.random() * 3 - 1.5));
e.offer(Keys.FIRE_TICKS, Probability.getRandom(20 * 60));
++affected;
}
}
}
if (affected > 0) {
inst.sendAttackBroadcast("Feel my power!", AttackSeverity.INFO);
}
}
}
Optional<DamageSource> optDmgSource = condition.getDamageSource();
if (optDmgSource.isPresent()) {
DamageSource dmgSource = optDmgSource.get();
Entity attacker = null;
if (dmgSource instanceof IndirectEntityDamageSource) {
attacker = ((IndirectEntityDamageSource) dmgSource).getIndirectSource();
} else if (dmgSource instanceof EntityDamageSource) {
attacker = ((EntityDamageSource) dmgSource).getSource();
if (attacker instanceof Player) {
/* TODO Convert to Sponge
if (ItemUtil.hasForgeBook((Player) attacker)) {
boss.setHealth(0);
final Player finalAttacker = (Player) attacker;
if (!finalAttacker.getGameMode().equals(GameMode.CREATIVE)) {
server().getScheduler().runTaskLater(inst(), () -> (finalAttacker).setItemInHand(null), 1);
}
}*/
}
}
if (Probability.getChance(3) && attacker instanceof Player) {
inst.spawnMinions((Player) attacker);
}
}
event.setBaseDamage(Math.min(35, event.getBaseDamage()));
return Optional.empty();
});
}
Aggregations