Skip to content

Commit

Permalink
Update & format
Browse files Browse the repository at this point in the history
  • Loading branch information
NotThorny committed Oct 21, 2023
1 parent 6f3341c commit 58cdafa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>xyz.grasscutters</groupId> <!-- Versions below 1.0.3-dev are on 'tech.xigam' -->
<artifactId>grasscutter</artifactId>
<version>1.7.1</version> <!-- Replace with the latest version of the API. -->
<version>1.7.2</version> <!-- Replace with the latest version of the API. -->
</dependency>
</dependencies>
</project>
72 changes: 26 additions & 46 deletions src/main/java/thorny/grasscutters/MobWave/MobSpawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MobSpawner {
public static List<Integer> commonMob = monsterLists.getCommonMobs(); // Common mobs
public static List<Integer> eliteMob = monsterLists.getEliteMobs(); // Elite mobs
public static List<Integer> bossMob = monsterLists.getBossMobs(); // Boss mobs

public static int generatedCount = 0; // Spawned mob counter
static int alive = 0; // Number of mobs alive
public static int n = 0; // Wave counter
Expand All @@ -52,20 +52,20 @@ public static boolean checkWave(int waves) {
public static MonsterData setMonsterData(int imn) {
Random pRandom = new Random();
int randomMob;

// Sanity check
if (MobWaveCommand.waveType.equals(null)) {
MobWaveCommand.waveType = "common";
} // if

// Scale elite spawns
if (imn > 0 && imn % 4 == 0) {
imn = 4;
}
if (imn > 0 && imn % 3 == 0) {
imn = 3;
}

// Boss wave
if (MobSpawner.n > 0 && (MobSpawner.n + 1) % 5 == 0) {
switch (imn) {
Expand All @@ -75,7 +75,7 @@ public static MonsterData setMonsterData(int imn) {
default -> MobWaveCommand.waveType = "common";
} // switch
} // if

// Normal wave
else {
switch (imn) {
Expand All @@ -85,22 +85,22 @@ public static MonsterData setMonsterData(int imn) {
default -> MobWaveCommand.waveType = "common";
} // switch
} // else

// Custom user wave type
if(!MobWaveCommand.userWaveReq.equals("none")){
if (!MobWaveCommand.userWaveReq.equals("none")) {
Grasscutter.getLogger().info("Set custom wave: " + MobWaveCommand.userWaveReq);
MobWaveCommand.waveType = MobWaveCommand.userWaveReq;
}

// Get random mob from type
switch (MobWaveCommand.waveType) {
case "common" -> randomMob = commonMob.get(pRandom.nextInt(commonMob.size()));
case "common" -> randomMob = commonMob.get(pRandom.nextInt(commonMob.size()));
case "elite" -> randomMob = eliteMob.get(pRandom.nextInt(eliteMob.size()));
case "boss" -> randomMob = bossMob.get(pRandom.nextInt(bossMob.size()));
// Use common mob when no match
default -> randomMob = commonMob.get(pRandom.nextInt(commonMob.size()));
} // switch

// Set mob
MonsterData monsterData = GameData.getMonsterDataMap().get(randomMob);
return monsterData;
Expand All @@ -117,38 +117,29 @@ public static void setMonsters(List<EntityMonster> monsters) {

// Spawn the monsters
public static void spawnMobEntity(int uid, Player targetPlayer, List<String> args, int nuMobs, int nuWaves,
int mLevel, int step, List<Integer> paramList, int time, String waveType) {
int mLevel, int step, List<Integer> paramList, int time, String waveType) {
// Defaults
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
List<EntityMonster> newMonsters = new ArrayList<>();
MobSpawner.generatedCount = 0;
int goal = nuMobs;
MobWaveCommand.isWaves = true;

// Repeat once per second
executor.scheduleAtFixedRate(() -> {
// Get current location
Scene scene = targetPlayer.getScene();
Position pos = targetPlayer.getPosition();
Position rot = targetPlayer.getRotation();
newMonsters.clear(); // Clean list
exceedTime(targetPlayer); // Check for time

if(!(targetPlayer.getServer().getPlayerByUid(uid, true).isOnline())){

if (!(targetPlayer.getServer().getPlayerByUid(uid, true).isOnline())) {
Grasscutter.getLogger().info("[MobWave] Player logged out so challenge ended.");
MobWaveCommand.mobWaveChallenge.fail();
endChallenge(executor);
MobWaveCommand.playerExited = false;
}

// When timer runs out
if (exceedTime(targetPlayer)) {
CommandHandler.sendMessage(targetPlayer, "Ran out of time!");
MobWaveCommand.mobWaveChallenge.fail();
endChallenge(executor);
return;
} // if


// Check to spawn
if (MobSpawner.getAliveMonstersCount() <= 0) {
// Check if waves are completed and shutdown if so
Expand All @@ -157,7 +148,7 @@ public static void spawnMobEntity(int uid, Player targetPlayer, List<String> arg
endChallenge(executor);
return;
} // if

// Spawns mobs if waves remain and challenge is active
if (MobSpawner.generatedCount < goal && MobWaveCommand.isWaves) {
for (int i = 0; i < goal; i++) {
Expand All @@ -170,28 +161,28 @@ public static void spawnMobEntity(int uid, Player targetPlayer, List<String> arg
} // for
setMonsters(newMonsters);
incrementWaves();

// Alert if next wave is boss wave
if((MobSpawner.n+1)%5==0){
if ((MobSpawner.n + 1) % 5 == 0) {
CommandHandler.sendMessage(targetPlayer, "Boss incoming next wave!");
} // if

// Stop waves if only one exists
if (nuWaves == 1) {
MobWaveCommand.isWaves = false;
} // if

} // if
newMonsters.clear();

// Start next wave is previous finished and waves remain
if (nuWaves > 1) {
if (MobWaveCommand.mobWaveChallenge.isSuccess()) {
MobSpawner.generatedCount = 0;
executor.shutdown();
MobWaveCommand.mobSG.setId(80085);
MobWaveCommand.mobWaveChallenge = new WorldChallenge(targetPlayer.getScene(), MobWaveCommand.mobSG, 180, 180, paramList, time,
nuMobs, MobWaveCommand.cTrigger);
MobWaveCommand.mobWaveChallenge = new WorldChallenge(targetPlayer.getScene(),
MobWaveCommand.mobSG, 180, 180, paramList, time, nuMobs, MobWaveCommand.cTrigger);
MobWaveCommand.mobWaveChallenge.start();
spawnMobEntity(uid, targetPlayer, args, nuMobs, nuWaves, mLevel, step, paramList,
time, waveType);
Expand All @@ -209,21 +200,10 @@ public static void endChallenge(ScheduledExecutorService executor) {
resetWaves();
}

// Check if wave has exceeded time limit
private static boolean exceedTime(Player targetPlayer) {
var current = System.currentTimeMillis();
// If time is exceeded
if (current - MobWaveCommand.mobWaveChallenge.getStartedAt() > MobWaveCommand.mobWaveChallenge
.getTimeLimit() * 1000L) {
return true;
} else {
return false;
} // else
} // exceedTime

// Remove currently alive monsters
public static void removeAliveMobs() {
MobWaveCommand.mobWaveChallenge.getScene().removeEntities(MobSpawner.activeMonsters, VisionType.VISION_TYPE_REMOVE);
MobWaveCommand.mobWaveChallenge.getScene().removeEntities(MobSpawner.activeMonsters,
VisionType.VISION_TYPE_REMOVE);
MobSpawner.activeMonsters.clear();
} // removeAliveMobs

Expand All @@ -239,5 +219,5 @@ public static int getAliveMonstersCount() {
} // if
} // for
return count;
} // getAliveMonstersCount
} // getAliveMonstersCount
}
4 changes: 2 additions & 2 deletions src/main/java/thorny/grasscutters/MobWave/monsterLists.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class monsterLists {
25030101, 25030201, 25030301, 25040101, 25050101, 25050201, 25050301, 25050401,
25050501, 25060101, 25070101, 25070202, 25080101, 25080201, 25080301, 25080401,
26030101, 26051001, 26051101, 26060101, 26060201, 26060301, 26090101, 25210204,
25210105, 25210306, 25210504, 22110101, 22110102, 22110201, 22110202, 22110301,
22110302, 22110402, 22110403, 20051001, 20051002, 20051003, 20051401);
25210105, 25210306, 25210504, 22110101, 22110201, 22110301, 22110402, 20051001,
20051002, 20051003, 20051401);

public static List<Integer> eliteMobs = List.of(20020101, 21010301, 21020101, 21020201,
21020301, 21020401, 21020501, 21020601, 21020701, 21020801, 22010101, 22010201, 22010301,
Expand Down

0 comments on commit 58cdafa

Please sign in to comment.