use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent in project minecolonies by ldtteam.
the class RaiderWalkAI method walkToCampFire.
/**
* Chooses and walks to a random campfire
*/
private void walkToCampFire() {
if (raider.level.getGameTime() - nextCampfireTime < 0) {
return;
}
final BlockPos campFire = ((HordeRaidEvent) raider.getColony().getEventManager().getEventByID(raider.getEventID())).getRandomCampfire();
if (campFire == null) {
return;
}
nextCampfireTime = raider.level.getGameTime() + raider.level.random.nextInt(1000);
targetBlock = BlockPosUtil.getRandomPosition(raider.level, campFire, BlockPos.ZERO, 3, 6);
if (targetBlock != null && targetBlock != BlockPos.ZERO) {
raider.getNavigation().moveToXYZ(targetBlock.getX(), targetBlock.getY(), targetBlock.getZ(), 1.0);
}
}
use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent in project minecolonies by ldtteam.
the class RaiderWalkAI method walk.
/**
* Walk raider towards the colony or campfires
*
* @return
*/
private boolean walk() {
if (raider.getColony() != null) {
final IColonyEvent event = raider.getColony().getEventManager().getEventByID(raider.getEventID());
if (event == null) {
return false;
}
if (event.getStatus() == EventStatus.PREPARING && event instanceof HordeRaidEvent) {
walkToCampFire();
return false;
}
if (targetBlock == null || raider.getNavigation().isDone() || (targetBlock != null && raider.blockPosition().distSqr(targetBlock) < 25)) {
targetBlock = raider.getColony().getRaiderManager().getRandomBuilding();
final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(((IColonyRaidEvent) event).getWayPoints(), raider.blockPosition(), targetBlock);
raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 1.1);
}
}
return false;
}
use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent in project minecolonies by Minecolonies.
the class RaiderWalkAI method walk.
/**
* Walk raider towards the colony or campfires
*
* @return
*/
private boolean walk() {
if (raider.getColony() != null) {
final IColonyEvent event = raider.getColony().getEventManager().getEventByID(raider.getEventID());
if (event == null) {
return false;
}
if (event.getStatus() == EventStatus.PREPARING && event instanceof HordeRaidEvent) {
walkToCampFire();
return false;
}
if (targetBlock == null || raider.blockPosition().distSqr(targetBlock) < 25 || raider.level.getGameTime() > walkTimer) {
targetBlock = raider.getColony().getRaiderManager().getRandomBuilding();
walkTimer = raider.level.getGameTime() + TICKS_SECOND * 240;
final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(((IColonyRaidEvent) event).getWayPoints(), raider.blockPosition(), targetBlock);
raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 1.1);
} else if (raider.getNavigation().isDone() || raider.getNavigation().getDesiredPos() == null) {
final BlockPos moveToPos = ShipBasedRaiderUtils.chooseWaypointFor(((IColonyRaidEvent) event).getWayPoints(), raider.blockPosition(), targetBlock);
raider.getNavigation().moveToXYZ(moveToPos.getX(), moveToPos.getY(), moveToPos.getZ(), 1.1);
}
}
return false;
}
use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent 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();
}
use of com.minecolonies.coremod.colony.colonyEvents.raidEvents.HordeRaidEvent in project minecolonies by Minecolonies.
the class RaiderWalkAI method walkToCampFire.
/**
* Chooses and walks to a random campfire
*/
private void walkToCampFire() {
if (raider.level.getGameTime() - walkTimer < 0) {
return;
}
final BlockPos campFire = ((HordeRaidEvent) raider.getColony().getEventManager().getEventByID(raider.getEventID())).getRandomCampfire();
if (campFire == null) {
return;
}
walkTimer = raider.level.getGameTime() + raider.level.random.nextInt(1000);
targetBlock = BlockPosUtil.getRandomPosition(raider.level, campFire, BlockPos.ZERO, 3, 6);
if (targetBlock != null && targetBlock != BlockPos.ZERO) {
raider.getNavigation().moveToXYZ(targetBlock.getX(), targetBlock.getY(), targetBlock.getZ(), 1.0);
}
}
Aggregations