use of org.spongepowered.api.effect.potion.PotionEffect 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.effect.potion.PotionEffect in project Skree by Skelril.
the class JungleRaidEffectProcessor method titanMode.
private static void titanMode(JungleRaidInstance inst) {
FlagEffectData data = inst.getFlagData();
Collection<Player> players = inst.getPlayers(PlayerClassifier.PARTICIPANT);
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && data.titan == null) {
Player player = Probability.pickOneOf(players);
data.titan = player.getUniqueId();
ItemStack teamHood = newItemStack(ItemTypes.LEATHER_HELMET);
teamHood.offer(Keys.DISPLAY_NAME, Text.of(TextColors.WHITE, "Titan Hood"));
teamHood.offer(Keys.COLOR, Color.BLACK);
// playerEquipment.set(EquipmentTypes.HEADWEAR, teamHood);
tf(player).inventory.armorInventory.set(3, tf(teamHood));
}
for (Player player : players) {
if (inst.isFlagEnabled(JungleRaidFlag.TITAN_MODE) && player.getUniqueId().equals(data.titan)) {
List<PotionEffect> potionEffects = player.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>());
potionEffects.add(PotionEffect.of(PotionEffectTypes.NIGHT_VISION, 1, 20 * 20));
player.offer(Keys.POTION_EFFECTS, potionEffects);
}
}
}
use of org.spongepowered.api.effect.potion.PotionEffect in project guardian by ichorpowered.
the class PotionEffectCapture method update.
@Override
public void update(@Nonnull PlayerEntry entry, @Nonnull CaptureContainer captureContainer) {
if (!entry.getEntity(Player.class).isPresent() || !captureContainer.get(GuardianSequence.INITIAL_LOCATION).isPresent())
return;
final Player player = entry.getEntity(Player.class).get();
captureContainer.offerIfEmpty(GuardianValue.builder(PotionEffectCapture.HORIZONTAL_SPEED_MODIFIER).defaultElement(1d).element(1d).create());
captureContainer.offerIfEmpty(GuardianValue.builder(PotionEffectCapture.VERTICAL_SPEED_MODIFIER).defaultElement(1d).element(1d).create());
final List<PotionEffect> potionEffects = player.get(Keys.POTION_EFFECTS).orElse(Lists.newArrayList());
if (!potionEffects.isEmpty()) {
for (PotionEffect potionEffect : potionEffects) {
final String potionName = potionEffect.getType().getName().toLowerCase();
if (this.effectSpeed.containsKey(potionName)) {
final double effectValue = this.effectSpeed.get(potionName);
captureContainer.getValue(PotionEffectCapture.HORIZONTAL_SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original + ((potionEffect.getAmplifier() + 1) * effectValue)));
}
if (this.effectLift.containsKey(potionName)) {
final double effectValue = this.effectLift.get(potionName);
captureContainer.getValue(PotionEffectCapture.VERTICAL_SPEED_MODIFIER).ifPresent(value -> value.transform(original -> original + ((potionEffect.getAmplifier() + 1) * effectValue)));
}
}
}
}
use of org.spongepowered.api.effect.potion.PotionEffect in project RedProtect by FabioZumbi12.
the class RPEntityListener method onPotionSplash.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPotionSplash(LaunchProjectileEvent event) {
if (event.getTargetEntity() instanceof ThrownPotion) {
ThrownPotion potion = (ThrownPotion) event.getTargetEntity();
ProjectileSource thrower = potion.getShooter();
RedProtect.get().logger.debug("entity", "RPEntityListener - LaunchProjectileEvent entity " + event.getTargetEntity().getType().getName());
List<PotionEffect> pottypes = potion.get(Keys.POTION_EFFECTS).get();
for (PotionEffect t : pottypes) {
if (!t.getType().equals(PotionEffectTypes.BLINDNESS) && !t.equals(PotionEffectTypes.WEAKNESS) && !t.equals(PotionEffectTypes.NAUSEA) && !t.equals(PotionEffectTypes.HUNGER) && !t.equals(PotionEffectTypes.POISON) && !t.equals(PotionEffectTypes.MINING_FATIGUE) && !t.equals(PotionEffectTypes.HASTE) && !t.equals(PotionEffectTypes.SLOWNESS) && !t.equals(PotionEffectTypes.WITHER)) {
return;
}
}
Player shooter;
if (thrower instanceof Player) {
shooter = (Player) thrower;
} else {
return;
}
RedProtect.get().logger.debug("entity", "RPEntityListener - LaunchProjectileEvent shooter " + shooter.getName());
Entity e2 = event.getTargetEntity();
Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
if (e2 instanceof Player) {
if (r != null && r.flagExists("pvp") && !r.canPVP(shooter)) {
event.setCancelled(true);
}
} else {
if (r != null && !r.canInteractPassives(shooter)) {
event.setCancelled(true);
}
}
}
}
use of org.spongepowered.api.effect.potion.PotionEffect in project RedProtect by FabioZumbi12.
the class RPPlayerListener method onPlayerMovement.
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerMovement(MoveEntityEvent e) {
if (RedProtect.get().cfgs.getBool("performance.disable-onPlayerMoveEvent-handler")) {
return;
}
Entity ent = e.getTargetEntity();
Player p = null;
if (ent instanceof Player) {
p = (Player) ent;
} else if (ent.get(Keys.PASSENGERS).isPresent()) {
for (Object uuidEnt : ent.get(Keys.PASSENGERS).get()) {
if (uuidEnt instanceof UUID) {
if (Sponge.getServer().getPlayer((UUID) uuidEnt).isPresent()) {
p = Sponge.getServer().getPlayer((UUID) uuidEnt).get();
}
} else if (uuidEnt instanceof EntitySnapshot) {
if (Sponge.getServer().getPlayer(((EntitySnapshot) uuidEnt).getUniqueId().get()).isPresent()) {
p = Sponge.getServer().getPlayer(((EntitySnapshot) uuidEnt).getUniqueId().get()).get();
}
}
}
} else {
return;
}
if (p == null) {
return;
}
RedProtect.get().logger.debug("player", "PlayerMoveEvent - Entity name: " + ent.getType().getName());
if (e.getFromTransform() != e.getToTransform() && RedProtect.get().tpWait.contains(p.getName())) {
RedProtect.get().tpWait.remove(p.getName());
RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
}
Transform<World> lfromForm = e.getFromTransform();
Transform<World> ltoForm = e.getToTransform();
Location<World> lfrom = e.getFromTransform().getLocation();
Location<World> lto = e.getToTransform().getLocation();
// teleport player to coord/world if playerup 128 y
int NetherY = RedProtect.get().cfgs.getInt("netherProtection.maxYsize");
if (lto.getExtent().getDimension().getType().equals(DimensionTypes.NETHER) && NetherY != -1 && lto.getBlockY() >= NetherY && !p.hasPermission("RedProtect.get().bypass.nether-roof")) {
for (String cmd : RedProtect.get().cfgs.getStringList("netherProtection.execute-cmd")) {
RedProtect.get().game.getCommandManager().process(RedProtect.get().serv.getConsole(), cmd.replace("{player}", p.getName()));
}
RPLang.sendMessage(p, RPLang.get("playerlistener.upnethery").replace("{location}", NetherY + ""));
}
Region r = RedProtect.get().rm.getTopRegion(lto);
/*
//deny enter if no perm doors
String door = lto.getBlock().getType().getName();
if (r != null && (door.contains("DOOR") || door.contains("_GATE")) && !r.canDoor(p)){
if (RPDoor.isDoorClosed(p.getWorld().getBlockAt(lto))){
e.setCancelled(true);
}
}*/
World w = lfrom.getExtent();
if (r != null) {
// enter max players flag
if (r.maxPlayers() != -1) {
if (!checkMaxPlayer(p, r)) {
e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
RPLang.sendMessage(p, RPLang.get("playerlistener.region.maxplayers").replace("{players}", String.valueOf(r.maxPlayers())));
}
}
// remove pots
if (!r.allowEffects(p) && p.get(Keys.POTION_EFFECTS).isPresent()) {
for (PotionEffect pot : p.get(Keys.POTION_EFFECTS).get()) {
if (pot.getDuration() < 36000) {
p.offer(Keys.POTION_EFFECTS, new ArrayList<>());
}
}
}
// Enter flag
if (!r.canEnter(p)) {
e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
RPLang.sendMessage(p, "playerlistener.region.cantregionenter");
}
// Allow enter with items
if (!r.canEnterWithItens(p)) {
e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
RPLang.sendMessage(p, RPLang.get("playerlistener.region.onlyenter.withitems").replace("{items}", r.flags.get("allow-enter-items").toString()));
}
// Deny enter with item
if (!r.denyEnterWithItens(p)) {
e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
RPLang.sendMessage(p, RPLang.get("playerlistener.region.denyenter.withitems").replace("{items}", r.flags.get("deny-enter-items").toString()));
}
// Deny Fly
if (!p.get(Keys.GAME_MODE).get().getName().equalsIgnoreCase("SPECTATOR") && !r.canFly(p) && p.get(Keys.IS_FLYING).get()) {
p.offer(Keys.IS_FLYING, false);
// p.setAllowFlight(false);
RPLang.sendMessage(p, "playerlistener.region.cantfly");
}
// update region admin or leander visit
if (RedProtect.get().cfgs.getString("region-settings.record-player-visit-method").equalsIgnoreCase("ON-REGION-ENTER")) {
if (r.isLeader(p) || r.isAdmin(p)) {
if (r.getDate() == null || (!r.getDate().equals(RPUtil.DateNow()))) {
r.setDate(RPUtil.DateNow());
}
}
}
if (Ownerslist.get(p) != r.getName()) {
Region er = RedProtect.get().rm.getRegion(Ownerslist.get(p), p.getWorld());
Ownerslist.put(p, r.getName());
// Execute listener:
EnterExitRegionEvent event = new EnterExitRegionEvent(er, r, p);
if (Sponge.getEventManager().post(event)) {
return;
}
// --
RegionFlags(r, er, p);
if (!r.getWelcome().equalsIgnoreCase("hide ")) {
EnterExitNotify(r, p);
}
} else {
RegionFlags(r, null, p);
}
} else {
// if (r == null) >>
if (Ownerslist.get(p) != null) {
Region er = RedProtect.get().rm.getRegion(Ownerslist.get(p), p.getWorld());
if (Ownerslist.containsKey(p)) {
Ownerslist.remove(p);
}
// Execute listener:
EnterExitRegionEvent event = new EnterExitRegionEvent(er, null, p);
if (Sponge.getEventManager().post(event)) {
return;
}
// ---
if (er == null) {
// remove all if no regions
List<String> toRemove = new ArrayList<>();
for (String taskId : PlayertaskID.keySet()) {
if (PlayertaskID.get(taskId).equals(p.getName())) {
if (taskId.contains("forcefly")) {
p.offer(Keys.CAN_FLY, false);
p.offer(Keys.IS_FLYING, false);
} else {
p.remove(Keys.POTION_EFFECTS);
}
toRemove.add(taskId);
stopTaskPlayer(taskId);
}
}
for (String key : toRemove) {
PlayertaskID.remove(key);
}
} else {
noRegionFlags(er, p);
if (!er.getWelcome().equalsIgnoreCase("hide ") && RedProtect.get().cfgs.getBool("notify.region-exit")) {
SendNotifyMsg(p, RPLang.get("playerlistener.region.wilderness"));
}
}
}
}
}
Aggregations