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
Raycoms committed Nov 12, 2024
1 parent 3cf803e commit 098851d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 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 @@ -41,6 +41,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.Mirror;
Expand Down Expand Up @@ -263,13 +264,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 @@ -683,11 +684,20 @@ 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 + nearbyColonyPlayers * INCREASE_PER_PLAYER)
* ((ColonyConstants.rand.nextDouble() * 0.3) + 0.85)));
* ((ColonyConstants.rand.nextDouble() * 0.3) + 0.85)));
}

@Override
Expand Down Expand Up @@ -766,15 +776,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 @@ -860,7 +864,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 @@ -87,7 +87,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),
Expand Down

0 comments on commit 098851d

Please sign in to comment.