Fix multiple challenges

This commit is contained in:
Sam 2017-11-16 16:35:57 +00:00 committed by Alexander Meech
parent c0d530404e
commit 9e8d30f86c
7 changed files with 253 additions and 65 deletions

View File

@ -10,6 +10,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity;
@ -58,7 +59,7 @@ public class ChristmasCommon extends SoloGame
DEBUG_COMMANDS
}
private static final int BARRIER_BREAK_SQUARED = 600;
private static final int BARRIER_BREAK_SQUARED = 1000;
private static final int MIN_Y = 40;
protected final List<Section> _sections;
@ -173,6 +174,11 @@ public class ChristmasCommon extends SoloGame
return;
}
for (Player player : GetPlayers(true))
{
player.setGameMode(GameMode.ADVENTURE);
}
_badGuys = new GameTeam(this, "Christmas Thieves", ChatColor.RED, new ArrayList<>());
AddTeam(_badGuys);
}
@ -289,9 +295,17 @@ public class ChristmasCommon extends SoloGame
_sleigh.onDamage(event);
}
if (event.GetCause() == DamageCause.FALL)
if (event.GetDamageePlayer() != null)
{
event.SetCancelled("Fall Damage");
switch (event.GetCause())
{
case FALL:
event.SetCancelled("Fall Damage");
break;
case SUFFOCATION:
event.GetDamageeEntity().teleport(getSleigh().GetLocation());
break;
}
}
}

View File

@ -16,7 +16,6 @@ import nautilus.game.arcade.game.games.christmas.kits.KitPlayer;
import nautilus.game.arcade.game.games.christmasnew.section.five.Section5;
import nautilus.game.arcade.game.games.christmasnew.section.four.Section4;
import nautilus.game.arcade.game.games.christmasnew.section.one.Section1;
import nautilus.game.arcade.game.games.christmasnew.section.six.Section6;
import nautilus.game.arcade.game.games.christmasnew.section.three.Section3;
import nautilus.game.arcade.game.games.christmasnew.section.two.Section2;
import nautilus.game.arcade.kit.Kit;

View File

@ -1,6 +1,25 @@
package nautilus.game.arcade.game.games.christmasnew.section.five;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowman;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.game.games.christmasnew.ChristmasNew;
import nautilus.game.arcade.game.games.christmasnew.section.Section;
@ -9,21 +28,34 @@ import nautilus.game.arcade.game.games.christmasnew.section.SectionChallenge;
class SnowmenKong extends SectionChallenge
{
private static final int SEARCH_DISTANCE_SQUARED = 100;
private static final int MIN_TICKS_BEFORE_HIT = 8;
private static final Vector HIT_VELOCITY = new Vector(-1.5, 0.7, 0);
private final List<SnowmanWave> _waves;
private boolean _spawn;
SnowmenKong(ChristmasNew host, Location present, Section section)
{
super(host, present, section);
_waves = new ArrayList<>(3);
createWaves(_worldData.GetCustomLocs(String.valueOf(Material.QUARTZ_ORE.getId())), false);
createWaves(_worldData.GetCustomLocs(String.valueOf(Material.MELON_BLOCK.getId())), true);
}
@Override
public void onPresentCollect()
{
_spawn = false;
}
@Override
public void onRegister()
{
_host.getArcadeManager().runSyncLater(() -> _spawn = true, 400);
}
@Override
@ -31,4 +63,119 @@ class SnowmenKong extends SectionChallenge
{
}
private void createWaves(List<Location> locations, boolean positiveZ)
{
locations.forEach(location -> MapUtil.QuickChangeBlockAt(location, Material.AIR));
locations = new ArrayList<>(locations);
while (!locations.isEmpty())
{
SnowmanWave wave = new SnowmanWave(positiveZ);
Location start = locations.get(0);
locations.removeIf(location ->
{
if (UtilMath.offsetSquared(start, location) < SEARCH_DISTANCE_SQUARED)
{
location.setYaw(positiveZ ? 0 : 180);
wave.Spawns.add(location);
return true;
}
return false;
});
_waves.add(wave);
}
}
@EventHandler
public void updateWaveSpawn(UpdateEvent event)
{
if (event.getType() != UpdateType.TWOSEC || !_spawn)
{
return;
}
for (SnowmanWave wave : _waves)
{
int index = UtilMath.r(wave.Spawns.size() - 1) + 1;
boolean upShift = Math.random() > 0.5;
for (int i = 0; i < wave.Spawns.size(); i++)
{
if (i == index || i == (index + (upShift ? 1 : -1)))
{
continue;
}
Location location = wave.Spawns.get(i);
Snowman snowman = spawn(location, Snowman.class);
UtilEnt.vegetate(snowman);
UtilEnt.ghost(snowman, true, false);
UtilEnt.setFakeHead(snowman, true);
wave.Entities.add(snowman);
}
}
}
@EventHandler
public void updateCollide(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
for (SnowmanWave wave : _waves)
{
for (Snowman entity : wave.Entities)
{
if (!entity.isValid() || entity.getTicksLived() < MIN_TICKS_BEFORE_HIT)
{
continue;
}
Location target = entity.getLocation().add(0, -1, (wave.PositiveZ ? 2 : -2));
UtilEnt.CreatureMove(entity, target, 1.5F);
for (Player player : UtilEnt.getPlayersInsideEntity(entity))
{
if (UtilPlayer.isSpectator(player) || !Recharge.Instance.use(player, "Snowman Hit", 1000, false, false))
{
continue;
}
_host.getArcadeManager().GetDamage().NewDamageEvent(player, entity, null, DamageCause.CUSTOM, 4, false, true, true, entity.getName(), entity.getName());
UtilAction.velocity(player, HIT_VELOCITY);
}
Location location = entity.getLocation();
if (UtilBlock.solid(location.add(location.getDirection()).getBlock()))
{
entity.remove();
}
}
}
}
private class SnowmanWave
{
private final List<Location> Spawns;
private final List<Snowman> Entities;
private final boolean PositiveZ;
SnowmanWave(boolean positiveZ)
{
Spawns = new ArrayList<>();
Entities = new ArrayList<>();
PositiveZ = positiveZ;
}
}
}

View File

@ -22,6 +22,7 @@ import nautilus.game.arcade.game.games.christmasnew.section.SectionChallenge;
public class CaveMaze extends SectionChallenge
{
private static final int STARTING_MOBS = 12;
private static final int MAX_MOBS = 25;
private static final int HEALTH = 5;
private static final ItemStack[] IN_HAND =
@ -33,7 +34,6 @@ public class CaveMaze extends SectionChallenge
};
private final List<Location> _mobSpawns;
private final List<Location> _quickOutStone;
private final List<Location> _quickOutAir;
CaveMaze(ChristmasNew host, Location present, Section section)
@ -41,25 +41,14 @@ public class CaveMaze extends SectionChallenge
super(host, present, section);
_mobSpawns = _worldData.GetDataLocs("BROWN");
_quickOutStone = _worldData.GetCustomLocs(String.valueOf(Material.NETHERRACK.getId()));
_quickOutAir = _worldData.GetCustomLocs(String.valueOf(Material.SOUL_SAND.getId()));
_quickOutStone.forEach(location -> MapUtil.QuickChangeBlockAt(location, Material.STATIONARY_LAVA));
_quickOutAir.forEach(location -> MapUtil.QuickChangeBlockAt(location, Material.IRON_FENCE));
}
@Override
public void onPresentCollect()
{
_quickOutStone.forEach(location ->
{
if (Math.random() > 0.95)
{
location.getWorld().playEffect(location, Effect.STEP_SOUND, Material.COBBLESTONE);
}
MapUtil.QuickChangeBlockAt(location, Material.COBBLESTONE);
});
_quickOutAir.forEach(location ->
{
if (Math.random() > 0.95)
@ -74,7 +63,10 @@ public class CaveMaze extends SectionChallenge
@Override
public void onRegister()
{
for (int i = 0; i < STARTING_MOBS; i++)
{
spawn();
}
}
@Override
@ -91,10 +83,16 @@ public class CaveMaze extends SectionChallenge
return;
}
spawn();
}
private void spawn()
{
Skeleton skeleton = spawn(UtilAlg.Random(_mobSpawns), Skeleton.class);
skeleton.setHealth(HEALTH);
skeleton.setMaxHealth(HEALTH);
skeleton.getEquipment().setItemInHand(UtilMath.randomElement(IN_HAND));
skeleton.setRemoveWhenFarAway(false);
}
}

View File

@ -2,17 +2,21 @@ package nautilus.game.arcade.game.games.christmasnew.section.three;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.entity.Spider;
import org.bukkit.event.EventHandler;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -24,11 +28,13 @@ class CaveIn extends SectionChallenge
{
private static final Material ALLOW_BREAK = Material.COBBLESTONE;
private static final int MAX_MOBS = 25;
private final int _triggerZ;
private final List<Location> _blocksToExplode;
private final List<Location> _blocksToFall;
private final List<Location> _blocksToClear;
private final List<Location> _mobSpawns;
private boolean _exploded;
@ -40,6 +46,7 @@ class CaveIn extends SectionChallenge
_blocksToExplode = _worldData.GetCustomLocs(String.valueOf(Material.GOLD_ORE.getId()));
_blocksToFall = _worldData.GetCustomLocs(String.valueOf(Material.MYCEL.getId()));
_blocksToClear = _worldData.GetCustomLocs(String.valueOf(Material.RED_SANDSTONE.getId()));
_mobSpawns = _worldData.GetDataLocs("MAGENTA");
_blocksToExplode.forEach(location -> MapUtil.QuickChangeBlockAt(location, Material.AIR));
_blocksToFall.forEach(location -> MapUtil.QuickChangeBlockAt(location, Material.COBBLESTONE));
@ -56,12 +63,30 @@ class CaveIn extends SectionChallenge
public void onRegister()
{
_host.BlockBreakAllow.add(ALLOW_BREAK.getId());
for (Player player : _host.GetPlayers(true))
{
player.setGameMode(GameMode.SURVIVAL);
}
}
@Override
public void onUnregister()
{
_host.BlockBreakAllow.remove(ALLOW_BREAK.getId());
for (Player player : _host.GetPlayers(true))
{
player.setGameMode(GameMode.ADVENTURE);
}
_blocksToClear.forEach(location ->
{
if (location.getBlock().getType() != Material.AIR)
{
MapUtil.QuickChangeBlockAt(location, Material.AIR);
}
});
}
public boolean isCleared()
@ -114,4 +139,28 @@ class CaveIn extends SectionChallenge
fallingBlock.setDropItem(false);
});
}
@EventHandler
public void updateMobs(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !_exploded || _entities.size() > MAX_MOBS)
{
return;
}
spawn(UtilAlg.Random(_mobSpawns), Spider.class);
_entities.forEach(entity ->
{
if (entity instanceof Spider)
{
Spider spider = (Spider) entity;
if (spider.getTarget() == null)
{
spider.setTarget(UtilPlayer.getClosest(entity.getLocation()));
}
}
});
}
}

View File

@ -45,16 +45,18 @@ class IceMaze extends SectionChallenge
mazeOne.forEach(location -> MapUtil.QuickChangeBlockAt(location, state ? Material.ICE : Material.AIR));
mazeTwo.forEach(location -> MapUtil.QuickChangeBlockAt(location, state ? Material.AIR : Material.ICE));
_mazeBlocks = new ArrayList<>(1000);
_mazeBlocks = new ArrayList<>(5000);
List<Location> corners = _worldData.GetDataLocs("LIGHT_BLUE");
for (Block block : UtilBlock.getInBoundingBox(corners.get(0), corners.get(1)))
{
if (block.getType() == Material.ICE)
if (block.getType() != Material.ICE)
{
_mazeBlocks.add(block.getLocation());
continue;
}
_mazeBlocks.add(block.getLocation());
}
_mazeBlocks.sort(HEIGHT_COMPATATOR);
@ -65,36 +67,10 @@ class IceMaze extends SectionChallenge
{
int sleighHeight = _host.getSleigh().GetLocation().getBlockY();
removeMaze(sleighHeight);
fillMaze(sleighHeight);
removeMaze(sleighHeight - 1);
}
private void removeMaze(int sleighHeight)
{
_host.getArcadeManager().runSyncTimer(new BukkitRunnable()
{
@Override
public void run()
{
for (int i = 0; i < 30; i++)
{
Location location = _mazeBlocks.remove(0);
if (location.getY() < sleighHeight)
{
cancel();
return;
}
else
{
MapUtil.QuickChangeBlockAt(location, Material.AIR);
}
}
}
}, 0, 1);
}
private void fillMaze(int sleighHeight)
{
_host.getArcadeManager().runSyncTimer(new BukkitRunnable()
{
@ -109,16 +85,16 @@ class IceMaze extends SectionChallenge
return;
}
Location location = _mazeBlocks.remove(_mazeBlocks.size() - 1);
Location location = _mazeBlocks.remove(0);
if (location.getY() > sleighHeight)
if (location.getY() < sleighHeight)
{
cancel();
return;
}
else
{
MapUtil.QuickChangeBlockAt(location, Material.ICE);
MapUtil.QuickChangeBlockAt(location, Material.AIR);
}
}
}

View File

@ -4,7 +4,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
@ -21,6 +20,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
@ -56,8 +56,8 @@ class SnowTurrets extends SectionChallenge
private static final int MAX_DIST = 40;
private static final int HIT_RADIUS = 4;
private static final String HIT_CAUSE = "Snow Witch";
private static final Vector HIT_VELOCITY = new Vector(0, 0.7, 1.2);
private static final Vector HIT_BLOCK_VELOCITY = new Vector(0, 1.2, 0);
private static final Vector HIT_VELOCITY = new Vector(0, 0.8, 1.2);
private static final Vector HIT_BLOCK_VELOCITY = new Vector(0, 0.6, 0);
private final List<Location> _turretSpawns;
private final Set<FallingBlock> _bullets;
@ -89,15 +89,13 @@ class SnowTurrets extends SectionChallenge
Witch witch = spawn(location, Witch.class);
witch.setCustomName(C.cAquaB + "Snow Witch");
witch.setCustomName(C.cAquaB + HIT_CAUSE);
witch.setCustomNameVisible(true);
witch.setRemoveWhenFarAway(false);
UtilEnt.vegetate(witch);
UtilEnt.ghost(witch, true, false);
UtilEnt.setFakeHead(witch, true);
Bukkit.broadcastMessage("Test");
});
}
@ -131,15 +129,15 @@ class SnowTurrets extends SectionChallenge
return;
}
FallingBlock fallingBlock = location.getWorld().spawnFallingBlock(location, Material.PUMPKIN, (byte) 0);
FallingBlock fallingBlock = location.getWorld().spawnFallingBlock(location, Material.SNOW_BLOCK, (byte) 0);
fallingBlock.setDropItem(false);
Vector velocity = UtilAlg.getTrajectory2d(location, player.getLocation());
velocity.multiply(2 * scale);
velocity.multiply(1.5 * scale);
velocity.setY(0.4);
UtilAction.velocity(entity, velocity);
UtilAction.velocity(fallingBlock, velocity);
_bullets.add(fallingBlock);
});
@ -158,11 +156,18 @@ class SnowTurrets extends SectionChallenge
{
if (UtilEnt.isGrounded(block))
{
explodeBlock(block.getLocation());
Location location = block.getLocation();
block.remove();
MapUtil.QuickChangeBlockAt(location, Material.AIR);
explodeBlock(location);
return true;
}
UtilFirework.playFirework(block.getLocation(), BULLET_EFFECT);
if (block.getTicksLived() % 8 == 0)
{
UtilFirework.playFirework(block.getLocation(), BULLET_EFFECT);
}
return false;
});
}
@ -176,13 +181,13 @@ class SnowTurrets extends SectionChallenge
UtilPlayer.getInRadius(location, HIT_RADIUS).forEach((player, scale) ->
{
damageManager.NewDamageEvent(player, null, null, DamageCause.CUSTOM, 2, false, true, true, HIT_CAUSE, HIT_CAUSE);
damageManager.NewDamageEvent(player, null, null, DamageCause.CUSTOM, 6, false, true, true, HIT_CAUSE, HIT_CAUSE);
UtilAction.velocity(player, HIT_VELOCITY.clone().multiply(scale + 0.3));
});
for (Block block : UtilBlock.getInRadius(location.getBlock(), HIT_RADIUS).keySet())
{
if (Math.random() > 0.3 || UtilBlock.airFoliage(block) || !UtilBlock.airFoliage(block.getRelative(BlockFace.UP)))
if (Math.random() > 0.1 || UtilBlock.airFoliage(block) || !UtilBlock.airFoliage(block.getRelative(BlockFace.UP)))
{
continue;
}