mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 12:24:35 +01:00
Implement random npc event chance in Monoliths
This commit is contained in:
@@ -518,7 +518,7 @@ public class StarTowerGame {
|
|||||||
cases.add(this.createExit());
|
cases.add(this.createExit());
|
||||||
|
|
||||||
// Create shop npc if this is the last room
|
// Create shop npc if this is the last room
|
||||||
if (this.isOnFinalFloor()) {
|
if (this.getRoom().getType() == RoomType.FinalBossRoom) {
|
||||||
// Create hawker case (shop)
|
// Create hawker case (shop)
|
||||||
cases.add(new StarTowerHawkerCase());
|
cases.add(new StarTowerHawkerCase());
|
||||||
// Create strengthen machine
|
// Create strengthen machine
|
||||||
@@ -526,8 +526,13 @@ public class StarTowerGame {
|
|||||||
cases.add(new StarTowerStrengthenMachineCase());
|
cases.add(new StarTowerStrengthenMachineCase());
|
||||||
}
|
}
|
||||||
} else if (this.getRoom() instanceof StarTowerBattleRoom) {
|
} else if (this.getRoom() instanceof StarTowerBattleRoom) {
|
||||||
// Create recovery npc
|
if (this.getRoom().getType() == RoomType.BattleRoom && Utils.randomChance(this.getModifiers().getBattleNpcEventChance())) {
|
||||||
cases.add(new StarTowerNpcRecoveryHPCase());
|
// Create npc event
|
||||||
|
cases.add(this.getRoom().createNpcEvent());
|
||||||
|
} else {
|
||||||
|
// Create recovery npc
|
||||||
|
cases.add(new StarTowerNpcRecoveryHPCase());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Complete
|
// Complete
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ public class StarTowerModifiers {
|
|||||||
private double bonusCoinChance;
|
private double bonusCoinChance;
|
||||||
private int bonusCoinCount;
|
private int bonusCoinCount;
|
||||||
|
|
||||||
|
// Random npc event
|
||||||
|
private double battleNpcEventChance;
|
||||||
|
|
||||||
public StarTowerModifiers(StarTowerGame game) {
|
public StarTowerModifiers(StarTowerGame game) {
|
||||||
this.game = game;
|
this.game = game;
|
||||||
|
|
||||||
@@ -184,6 +187,13 @@ public class StarTowerModifiers {
|
|||||||
this.bonusCoinChance = 0.1;
|
this.bonusCoinChance = 0.1;
|
||||||
this.bonusCoinCount = 10;
|
this.bonusCoinCount = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Battle npc event chance (Destiny's Choice)
|
||||||
|
if (game.getDifficulty() >= 4 && this.hasGrowthNode(20503)) {
|
||||||
|
this.battleNpcEventChance = 0.3;
|
||||||
|
} else if (game.getDifficulty() >= 3 && this.hasGrowthNode(10901)) {
|
||||||
|
this.battleNpcEventChance = 0.2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasGrowthNode(int nodeId) {
|
public boolean hasGrowthNode(int nodeId) {
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
package emu.nebula.game.tower.room;
|
package emu.nebula.game.tower.room;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import emu.nebula.GameConstants;
|
||||||
|
import emu.nebula.data.GameData;
|
||||||
|
import emu.nebula.data.resources.StarTowerEventDef;
|
||||||
import emu.nebula.data.resources.StarTowerStageDef;
|
import emu.nebula.data.resources.StarTowerStageDef;
|
||||||
import emu.nebula.game.tower.StarTowerGame;
|
import emu.nebula.game.tower.StarTowerGame;
|
||||||
import emu.nebula.game.tower.StarTowerModifiers;
|
import emu.nebula.game.tower.StarTowerModifiers;
|
||||||
import emu.nebula.game.tower.cases.CaseType;
|
import emu.nebula.game.tower.cases.CaseType;
|
||||||
import emu.nebula.game.tower.cases.StarTowerBaseCase;
|
import emu.nebula.game.tower.cases.StarTowerBaseCase;
|
||||||
|
import emu.nebula.game.tower.cases.StarTowerNpcEventCase;
|
||||||
import emu.nebula.game.tower.cases.StarTowerSyncHPCase;
|
import emu.nebula.game.tower.cases.StarTowerSyncHPCase;
|
||||||
import emu.nebula.proto.PublicStarTower.InteractEnterReq;
|
import emu.nebula.proto.PublicStarTower.InteractEnterReq;
|
||||||
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
|
import emu.nebula.proto.PublicStarTower.StarTowerRoomCase;
|
||||||
import emu.nebula.proto.PublicStarTower.StarTowerRoomData;
|
import emu.nebula.proto.PublicStarTower.StarTowerRoomData;
|
||||||
import emu.nebula.proto.StarTowerApply.StarTowerApplyReq;
|
import emu.nebula.proto.StarTowerApply.StarTowerApplyReq;
|
||||||
|
import emu.nebula.util.Utils;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
|
||||||
@@ -75,6 +82,43 @@ public class StarTowerBaseRoom {
|
|||||||
this.paramId = req.getParamId();
|
this.paramId = req.getParamId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NPC events
|
||||||
|
|
||||||
|
private StarTowerEventDef getRandomEvent() {
|
||||||
|
/*
|
||||||
|
var list = GameData.getStarTowerEventDataTable()
|
||||||
|
.values()
|
||||||
|
.stream()
|
||||||
|
.toList();
|
||||||
|
*/
|
||||||
|
|
||||||
|
var list = Arrays.stream(GameConstants.TOWER_EVENTS_IDS)
|
||||||
|
.mapToObj(GameData.getStarTowerEventDataTable()::get)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Utils.randomElement(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StarTowerBaseCase createNpcEvent() {
|
||||||
|
// Get random event
|
||||||
|
var event = this.getRandomEvent();
|
||||||
|
|
||||||
|
if (event == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get random npc
|
||||||
|
int npcId = Utils.randomElement(event.getRelatedNPCs());
|
||||||
|
|
||||||
|
// Create case with event
|
||||||
|
return new StarTowerNpcEventCase(npcId, event);
|
||||||
|
}
|
||||||
|
|
||||||
// Cases
|
// Cases
|
||||||
|
|
||||||
public int getNextCaseId() {
|
public int getNextCaseId() {
|
||||||
|
|||||||
@@ -1,17 +1,8 @@
|
|||||||
package emu.nebula.game.tower.room;
|
package emu.nebula.game.tower.room;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import emu.nebula.GameConstants;
|
|
||||||
import emu.nebula.data.GameData;
|
|
||||||
import emu.nebula.data.resources.StarTowerEventDef;
|
|
||||||
import emu.nebula.data.resources.StarTowerStageDef;
|
import emu.nebula.data.resources.StarTowerStageDef;
|
||||||
import emu.nebula.game.tower.StarTowerGame;
|
import emu.nebula.game.tower.StarTowerGame;
|
||||||
import emu.nebula.game.tower.cases.StarTowerBaseCase;
|
|
||||||
import emu.nebula.game.tower.cases.StarTowerNpcEventCase;
|
|
||||||
import emu.nebula.game.tower.cases.StarTowerSyncHPCase;
|
import emu.nebula.game.tower.cases.StarTowerSyncHPCase;
|
||||||
import emu.nebula.util.Utils;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@@ -21,41 +12,6 @@ public class StarTowerEventRoom extends StarTowerBaseRoom {
|
|||||||
public StarTowerEventRoom(StarTowerGame game, StarTowerStageDef stage) {
|
public StarTowerEventRoom(StarTowerGame game, StarTowerStageDef stage) {
|
||||||
super(game, stage);
|
super(game, stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StarTowerEventDef getRandomEvent() {
|
|
||||||
/*
|
|
||||||
var list = GameData.getStarTowerEventDataTable()
|
|
||||||
.values()
|
|
||||||
.stream()
|
|
||||||
.toList();
|
|
||||||
*/
|
|
||||||
|
|
||||||
var list = Arrays.stream(GameConstants.TOWER_EVENTS_IDS)
|
|
||||||
.mapToObj(GameData.getStarTowerEventDataTable()::get)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Utils.randomElement(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public StarTowerBaseCase createNpcEvent() {
|
|
||||||
// Get random event
|
|
||||||
var event = this.getRandomEvent();
|
|
||||||
|
|
||||||
if (event == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get random npc
|
|
||||||
int npcId = Utils.randomElement(event.getRelatedNPCs());
|
|
||||||
|
|
||||||
// Create case with event
|
|
||||||
return new StarTowerNpcEventCase(npcId, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnter() {
|
public void onEnter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user