Skip to content

Commit

Permalink
Raidcommand changes (#10351)
Browse files Browse the repository at this point in the history
Make chased targets turn aware of their pursuer
Raid command now ignores restrictions, like officer online
Raiders now split into slightly bigger grps
Fix barbarians raiders not able to spawn when chosen via command
  • Loading branch information
someaddons authored Oct 22, 2024
1 parent 02b51fb commit 8f54268
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ default RaidSpawnResult raiderEvent(String raidType, final boolean overrideConfi
/**
* Trigger a specific type of raid on a colony.
* @param raidType the type of raid (or empty).
* @param overrideConfig if it should override the config to allow raiders.
* @param forced if it is forced to spawn.
* @param allowShips if ship spawns are allowed.
*/
RaidSpawnResult raiderEvent(String raidType, final boolean overrideConfig, final boolean allowShips);
RaidSpawnResult raiderEvent(String raidType, final boolean forced, final boolean allowShips);

/**
* Calculates the spawn position for raids
Expand Down Expand Up @@ -164,14 +164,6 @@ default RaidSpawnResult raiderEvent(String raidType, final boolean overrideConfi
*/
boolean canRaid();

/**
* Whether the colony can be raided.
*
* @param overrideConfig if the config should be overriden.
* @return true if possible.
*/
boolean canRaid(final boolean overrideConfig);

/**
* calculates the colonies raid level
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public ThreatTableEntry getTarget()
return null;
}

if (current instanceof IThreatTableEntity threatTableEntity && threatTableEntity.getThreatTable().threatList.isEmpty())
{
threatTableEntity.getThreatTable().addThreat(owner, 0);
}

return current;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -260,13 +261,13 @@ public void raiderEvent()
}

@Override
public RaidSpawnResult raiderEvent(String raidType, final boolean overrideConfig, final boolean allowShips)
public RaidSpawnResult raiderEvent(String raidType, final boolean forced, final boolean allowShips)
{
if (colony.getWorld() == null || raidType == null)
{
return RaidSpawnResult.ERROR;
}
else if (!canRaid(overrideConfig))
else if (!forced && !canRaid())
{
return RaidSpawnResult.CANNOT_RAID;
}
Expand Down Expand Up @@ -417,7 +418,7 @@ else if (raidType.equals(PirateRaidEvent.PIRATE_RAID_EVENT_TYPE_ID.getPath()))
{
event = new PirateGroundRaidEvent(colony);
}
else if (raidType.isEmpty() || raidType.equals(BarbarianRaidEvent.BARBARIAN_RAID_EVENT_TYPE_ID))
else if (raidType.isEmpty() || raidType.equals(BarbarianRaidEvent.BARBARIAN_RAID_EVENT_TYPE_ID.getPath()))
{
event = new BarbarianRaidEvent(colony);
}
Expand Down Expand Up @@ -680,10 +681,19 @@ public List<BlockPos> getLastSpawnPoints()
@Override
public int calculateRaiderAmount(final int raidLevel)
{
int nearbyColonyPlayers = 0;
for (final Player player : colony.getMessagePlayerEntities())
{
if (!player.isSpectator())
{
nearbyColonyPlayers++;
}
}

return 1 + Math.min(MineColonies.getConfig().getServer().maxRaiders.get(),
(int) ((raidLevel / SPAWN_MODIFIER)
* getRaidDifficultyModifier()
* (1.0 + colony.getMessagePlayerEntities().size() * INCREASE_PER_PLAYER)
* (1.0 + nearbyColonyPlayers * INCREASE_PER_PLAYER)
* ((ColonyConstants.rand.nextDouble() * 0.5d) + 0.75)));
}

Expand Down Expand Up @@ -763,15 +773,9 @@ public void setNightsSinceLastRaid(final int nightsSinceLastRaid)

@Override
public boolean canRaid()
{
return canRaid(false);
}

@Override
public boolean canRaid(final boolean override)
{
return !WorldUtil.isPeaceful(colony.getWorld())
&& (MineColonies.getConfig().getServer().enableColonyRaids.get() || override)
&& (MineColonies.getConfig().getServer().enableColonyRaids.get())
&& colony.getRaiderManager().canHaveRaiderEvents()
&& !colony.getPackageManager().getImportantColonyPlayers().isEmpty();
}
Expand Down Expand Up @@ -857,7 +861,7 @@ private boolean raidThisNight(final Level world, final IColony colony)
public BlockPos getRandomBuilding()
{
buildingPosUsage++;
if (buildingPosUsage > 6 || lastBuilding == null)
if (buildingPosUsage > Math.max(6, getLastRaid().raiderAmount / 3) || lastBuilding == null)
{
buildingPosUsage = 0;
final Collection<IBuilding> buildingList = colony.getBuildingManager().getBuildings().values();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public int raidExecute(final CommandContext<CommandSourceStack> context, final S
}
else if(StringArgumentType.getString(context, RAID_TIME_ARG).equals(RAID_TONIGHT))
{
if (!colony.getRaiderManager().canRaid(true))
if (!colony.getRaiderManager().canRaid())
{
context.getSource().sendSuccess(() -> Component.translatable(CommandTranslationConstants.COMMAND_RAID_NOW_FAILURE, colony.getName(), IRaiderManager.RaidSpawnResult.CANNOT_RAID), true);
return 1;
Expand Down

0 comments on commit 8f54268

Please sign in to comment.