Search in sources :

Example 1 with NorsemenRaidEvent

use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenRaidEvent in project minecolonies by Minecolonies.

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()) {
            MessageUtils.format(new StringTextComponent("Horde Spawn Point: " + targetSpawnPoint)).sendTo(colony).forAllPlayers();
        }
        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();
}
Also used : Horde(com.minecolonies.coremod.colony.colonyEvents.raidEvents.barbarianEvent.Horde) EgyptianRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.egyptianevent.EgyptianRaidEvent) HordeRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent) BarbarianRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.barbarianEvent.BarbarianRaidEvent) PirateGroundRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.pirateEvent.PirateGroundRaidEvent) AmazonRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.amazonevent.AmazonRaidEvent) NorsemenShipRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenShipRaidEvent) NorsemenRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenRaidEvent) PirateRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.pirateEvent.PirateRaidEvent) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 2 with NorsemenRaidEvent

use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenRaidEvent 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();
}
Also used : Horde(com.minecolonies.coremod.colony.colonyEvents.raidEvents.barbarianEvent.Horde) EgyptianRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.egyptianevent.EgyptianRaidEvent) HordeRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent) BarbarianRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.barbarianEvent.BarbarianRaidEvent) PirateGroundRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.pirateEvent.PirateGroundRaidEvent) AmazonRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.amazonevent.AmazonRaidEvent) NorsemenShipRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenShipRaidEvent) NorsemenRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenRaidEvent) PirateRaidEvent(com.minecolonies.coremod.colony.colonyEvents.raidEvents.pirateEvent.PirateRaidEvent) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

HordeRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent)2 AmazonRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.amazonevent.AmazonRaidEvent)2 BarbarianRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.barbarianEvent.BarbarianRaidEvent)2 Horde (com.minecolonies.coremod.colony.colonyEvents.raidEvents.barbarianEvent.Horde)2 EgyptianRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.egyptianevent.EgyptianRaidEvent)2 NorsemenRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenRaidEvent)2 NorsemenShipRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.norsemenevent.NorsemenShipRaidEvent)2 PirateGroundRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.pirateEvent.PirateGroundRaidEvent)2 PirateRaidEvent (com.minecolonies.coremod.colony.colonyEvents.raidEvents.pirateEvent.PirateRaidEvent)2 BlockPos (net.minecraft.util.math.BlockPos)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)1