use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent in project minecolonies by ldtteam.
the class RaidManager method raiderEvent.
@Override
public void raiderEvent(String raidType) {
if (colony.getWorld() == null || !canRaid() || raidType == null) {
return;
}
final int raidLevel = getColonyRaidLevel();
int amount = calculateRaiderAmount(raidLevel);
if (amount <= 0 || raidLevel < MIN_REQUIRED_RAIDLEVEL) {
return;
}
// Splits into multiple raids if too large
final int raidCount = Math.max(1, amount / BIG_HORDE_SIZE);
final Set<BlockPos> spawnPoints = new HashSet<>();
for (int i = 0; i < raidCount; i++) {
final BlockPos targetSpawnPoint = calculateSpawnLocation();
if (targetSpawnPoint == null || targetSpawnPoint.equals(colony.getCenter()) || targetSpawnPoint.getY() > MineColonies.getConfig().getServer().maxYForBarbarians.get() || !colony.getWorld().getWorldBorder().isWithinBounds(targetSpawnPoint)) {
continue;
}
spawnPoints.add(targetSpawnPoint);
}
if (spawnPoints.isEmpty()) {
return;
}
nightsSinceLastRaid = 0;
raidTonight = false;
amount = (int) Math.ceil((float) amount / spawnPoints.size());
for (final BlockPos targetSpawnPoint : spawnPoints) {
if (MineColonies.getConfig().getServer().enableInDevelopmentFeatures.get()) {
LanguageHandler.sendPlayersMessage(colony.getMessagePlayerEntities(), "Horde Spawn Point: " + targetSpawnPoint);
}
if (colony.getWorld().getBlockState(targetSpawnPoint).getMaterial() == Material.AIR && colony.getWorld().getBlockState(targetSpawnPoint.below()).getMaterial() == Material.AIR) {
raidType = PirateRaidEvent.PIRATE_RAID_EVENT_TYPE_ID.getPath();
}
// No rotation till spawners are moved into schematics
final int shipRotation = new Random().nextInt(3);
final String homeBiomePath = colony.getWorld().getBiome(colony.getCenter()).getBiomeCategory().getName();
final int rand = colony.getWorld().random.nextInt(100);
if ((raidType.isEmpty() && (homeBiomePath.contains(TAIGA_BIOME_ID) || rand < IGNORE_BIOME_CHANCE) || raidType.equals(NorsemenRaidEvent.NORSEMEN_RAID_EVENT_TYPE_ID.getPath())) && ShipBasedRaiderUtils.canSpawnShipAt(colony, targetSpawnPoint, amount, shipRotation, NorsemenShipRaidEvent.SHIP_NAME)) {
final NorsemenShipRaidEvent event = new NorsemenShipRaidEvent(colony);
event.setSpawnPoint(targetSpawnPoint);
event.setShipSize(ShipSize.getShipForRaiderAmount(amount));
event.setShipRotation(shipRotation);
event.setSpawnPath(createSpawnPath(targetSpawnPoint));
colony.getEventManager().addEvent(event);
} else if (ShipBasedRaiderUtils.canSpawnShipAt(colony, targetSpawnPoint, amount, shipRotation, PirateRaidEvent.SHIP_NAME) && (raidType.isEmpty() || raidType.equals(PirateRaidEvent.PIRATE_RAID_EVENT_TYPE_ID.getPath()))) {
final PirateRaidEvent event = new PirateRaidEvent(colony);
event.setSpawnPoint(targetSpawnPoint);
event.setShipSize(ShipSize.getShipForRaiderAmount(amount));
event.setShipRotation(shipRotation);
event.setSpawnPath(createSpawnPath(targetSpawnPoint));
colony.getEventManager().addEvent(event);
} else {
final String biomePath = colony.getWorld().getBiome(targetSpawnPoint).getBiomeCategory().getName().toLowerCase();
final HordeRaidEvent event;
if (((biomePath.contains(DESERT_BIOME_ID) || (rand > IGNORE_BIOME_CHANCE && rand < IGNORE_BIOME_CHANCE * 2)) && raidType.isEmpty()) || raidType.equals(EgyptianRaidEvent.EGYPTIAN_RAID_EVENT_TYPE_ID.getPath())) {
event = new EgyptianRaidEvent(colony);
} else if (((biomePath.contains(JUNGLE_BIOME_ID) || (rand > IGNORE_BIOME_CHANCE * 2 && rand < IGNORE_BIOME_CHANCE * 3) && raidType.isEmpty())) || (raidType.equals(AmazonRaidEvent.AMAZON_RAID_EVENT_TYPE_ID.getPath()))) {
event = new AmazonRaidEvent(colony);
} else if (((biomePath.contains(TAIGA_BIOME_ID) || (rand > IGNORE_BIOME_CHANCE * 3 && rand < IGNORE_BIOME_CHANCE * 4)) && raidType.isEmpty()) || raidType.equals(NorsemenRaidEvent.NORSEMEN_RAID_EVENT_TYPE_ID.getPath())) {
event = new NorsemenRaidEvent(colony);
} else if (raidType.equals(PirateRaidEvent.PIRATE_RAID_EVENT_TYPE_ID.getPath())) {
event = new PirateGroundRaidEvent(colony);
} else {
event = new BarbarianRaidEvent(colony);
}
event.setSpawnPoint(targetSpawnPoint);
event.setHorde(new Horde(amount));
event.setSpawnPath(createSpawnPath(targetSpawnPoint));
colony.getEventManager().addEvent(event);
}
addRaiderSpawnPoint(targetSpawnPoint);
}
colony.markDirty();
}
Aggregations