Skip to content

Commit

Permalink
wave survival fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SoLegendary committed Nov 16, 2024
1 parent 3cbbd89 commit 738a818
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
3 changes: 3 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Features
- can't be the same faction twice in a row
- as days pass, waves get larger (balanced by population value)

[❌] Disallow messing with time of day during survival



[🟡] Bloodlust ability
- Unlockable active ability for Brutes and Headhunters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ public static void resetRTS() {
BuildingClientEvents.getBuildings().clear();
ResourcesClientEvents.resourcesList.clear();
ClientGameModeHelper.gameMode = GameMode.STANDARD;
ClientGameModeHelper.gameModeLocked = false;
if (!ClientGameModeHelper.disallowSurvival)
ClientGameModeHelper.gameModeLocked = false;
}

public static void setRTSLock(boolean lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public static void playSoundForAction(SoundAction soundAction, BlockPos bp) {

public static void playSoundForPlayer(SoundAction soundAction) {
Minecraft MC = Minecraft.getInstance();
if (MC.player != null)
if (MC.player != null) {
System.out.println("Playing sound: " + getSoundEvent(soundAction).getLocation().getNamespace());
MC.player.playSound(getSoundEvent(soundAction), 1.2f, 1.0f);
}
}

private static SoundEvent getSoundEvent(SoundAction soundAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.solegendary.reignofnether.sounds.SoundAction;
import com.solegendary.reignofnether.sounds.SoundClientboundPacket;
import com.solegendary.reignofnether.time.TimeUtils;
import com.solegendary.reignofnether.unit.UnitAction;
import com.solegendary.reignofnether.unit.UnitServerEvents;
import com.solegendary.reignofnether.unit.interfaces.Unit;
import com.solegendary.reignofnether.util.MiscUtil;
Expand All @@ -33,6 +34,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class SurvivalServerEvents {

Expand Down Expand Up @@ -77,8 +80,7 @@ public static void onLevelTick(TickEvent.LevelTickEvent evt) {
}

// TODO: add or subtract penalty time based on how fast the wave was cleared
if (bonusDayTicks > 0) {
((ServerLevel) evt.level).setDayTime(TimeUtils.DAWN + 100);
if (bonusDayTicks > 0 && TimeUtils.isDay(evt.level.getDayTime())) {
bonusDayTicks -= 4;
}

Expand All @@ -93,6 +95,10 @@ public static void onLevelTick(TickEvent.LevelTickEvent evt) {
if (lastTime <= TimeUtils.DUSK + 100 && normTime > TimeUtils.DUSK + 100) {
startNextWave((ServerLevel) evt.level);
}
if (lastTime <= TimeUtils.DAWN && normTime > TimeUtils.DAWN) {
PlayerServerEvents.sendMessageToAllPlayers(I18n.get("survival.reignofnether.dawn"), true);
}

else if (!TimeUtils.isDay(normTime) && isWaveInProgress()) {
((ServerLevel) evt.level).setDayTime(TimeUtils.DUSK + 6000);
ticksToClearLastWave += 4;
Expand All @@ -101,9 +107,9 @@ else if (!TimeUtils.isDay(normTime) && isWaveInProgress()) {
int enemyCount = getCurrentEnemies().size();
if (enemyCount < lastEnemyCount && enemyCount <= 3) {
if (enemyCount == 0)
PlayerServerEvents.sendMessageToAllPlayers(enemyCount + " enemies remain.");
else
endCurrentWave((ServerLevel) evt.level);
else
PlayerServerEvents.sendMessageToAllPlayers(enemyCount + " enemies remain.");
}
lastTime = time;
lastEnemyCount = enemyCount;
Expand Down Expand Up @@ -188,7 +194,7 @@ public static long getDifficultyTimeModifier() {
}

public static long getDayLength() {
return 24000 - getDifficultyTimeModifier();
return 12000 - getDifficultyTimeModifier();
}

public static void setToStartingTime() {
Expand Down Expand Up @@ -220,34 +226,42 @@ public static void startNextWave(ServerLevel level) {
// triggered when last enemy is killed
public static void endCurrentWave(ServerLevel level) {
nextWave = Wave.getWave(nextWave.number + 1);
PlayerServerEvents.sendMessageToAllPlayers("Your enemies have been defeated... for now.", true);
PlayerServerEvents.sendMessageToAllPlayers("Your enemies have been defeated... for now.", false);

// set bonusDayTicks to pause daytime based on ticksToClearLastWave - up to a maximum of getDayLength()
// fast-forward day time if the player took too long (to a max of 35s before the next night)
long ticksToClearInv = Math.max(-getDayLength()/2 + 700, 24000 - ticksToClearLastWave);
// fast-forward day time if the player took too long (to a max of 30s before the next night)

if (ticksToClearInv > 0) {
bonusDayTicks = ticksToClearInv;
PlayerServerEvents.sendMessageToAllPlayers(I18n.get("survival.reignofnether.dawn"), true);
PlayerServerEvents.sendMessageToAllPlayers("Their swift defeat gives you more time to prepare (+" +
TimeUtils.getTimeStrFromTicks(ticksToClearInv) + ")", true);
level.setDayTime(TimeUtils.DAWN + 10);
if (ticksToClearLastWave < getDayLength()) {
bonusDayTicks = getDayLength() - ticksToClearLastWave;
level.setDayTime(TimeUtils.DAWN - 200);

CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS).execute(() -> {
if (bonusDayTicks >= 200) {
PlayerServerEvents.sendMessageToAllPlayers("Their swift defeat gives you more time to prepare today (+" +
TimeUtils.getTimeStrFromTicks(bonusDayTicks) + ")", true);
}
});
} else {
PlayerServerEvents.sendMessageToAllPlayers("The prolonged battle means the next night comes sooner (-" +
TimeUtils.getTimeStrFromTicks(Math.abs(ticksToClearInv)) + ")", true);
level.setDayTime(TimeUtils.DAWN - ticksToClearInv);
long penaltyTicks = Math.min(-getDayLength() + 600, getDayLength() - ticksToClearLastWave) ;

CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS).execute(() -> {
if (penaltyTicks >= 200) {
PlayerServerEvents.sendMessageToAllPlayers("The prolonged battle means the next night comes sooner (" +
TimeUtils.getTimeStrFromTicks(Math.abs(penaltyTicks)) + ")", true);
}
});
level.setDayTime(TimeUtils.DAWN - penaltyTicks);
}
ticksToClearLastWave = 0;
}

private static final int MONSTER_MAX_SPAWN_RANGE = 60;
private static final int MONSTER_MIN_SPAWN_RANGE = 40;
private static final int MONSTER_MAX_SPAWN_RANGE = 120;
private static final int MONSTER_MIN_SPAWN_RANGE = 90;

public static void spawnMonsterWave(ServerLevel level) {
Random random = new Random();
List<Building> buildings = BuildingServerEvents.getBuildings();
int remainingPop = 1;//nextWave.population;
int remainingPop = nextWave.population;
if (buildings.isEmpty())
return;

Expand Down Expand Up @@ -311,10 +325,10 @@ public static void spawnMonsterWave(ServerLevel level) {
}
BotControls.startingCommand(entity, MONSTER_OWNER_NAME);
if (entity instanceof Unit unit)
nextWave.population -= unit.getPopCost();
remainingPop -= unit.getPopCost();
}

} while (nextWave.population > 0);
} while (remainingPop > 0);

}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/solegendary/reignofnether/survival/Wave.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static EntityType<? extends Mob> getRandomUnitOfTier(int tier) {
}

private static final List<EntityType<? extends Mob>> TIER_1_UNITS = List.of(
EntityRegistrar.SPIDER_UNIT.get(),
EntityRegistrar.POISON_SPIDER_UNIT.get()
EntityRegistrar.ZOMBIE_PIGLIN_UNIT.get(),
EntityRegistrar.ZOMBIE_UNIT.get()
);
private static final List<EntityType<? extends Mob>> TIER_2_UNITS = List.of(
EntityRegistrar.HUSK_UNIT.get(),
Expand Down Expand Up @@ -75,6 +75,12 @@ public static EntityType<? extends Mob> getRandomUnitOfTier(int tier) {
new Wave(12, 60, 4),
new Wave(13, 65, 5),
new Wave(14, 70, 5),
new Wave(15, 75, 5)
new Wave(15, 75, 5),

new Wave(16, 85, 5),
new Wave(17, 100, 5),
new Wave(18, 120, 5),
new Wave(19, 145, 5),
new Wave(20, 175, 5)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,11 @@ public static ArrayList<Entity> spawnMobs(
Entity entity = entityType.create(level);
if (entity != null) {
entity.moveTo(pos.getX() + i, pos.getY(), pos.getZ());
level.addFreshEntity(entity);
entities.add(entity);
if (entity instanceof Unit unit) {
unit.setOwnerName(ownerName);
}
level.addFreshEntity(entity);
}
}
}
Expand Down

0 comments on commit 738a818

Please sign in to comment.