mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 12:24:35 +01:00
Improve random potential selector generator
This commit is contained in:
@@ -22,6 +22,10 @@ public class PotentialDef extends BaseDef {
|
||||
return Id;
|
||||
}
|
||||
|
||||
public boolean isRare() {
|
||||
return this.BranchType != 3;
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
// Check if regular potential
|
||||
if (this.BranchType == 3) {
|
||||
|
||||
@@ -75,6 +75,7 @@ public class StarTowerGame {
|
||||
private int[] discIds;
|
||||
|
||||
private int pendingPotentialCases = 0;
|
||||
private int pendingRarePotentialCases = 0;
|
||||
private boolean completed;
|
||||
|
||||
// Bag
|
||||
@@ -89,9 +90,10 @@ public class StarTowerGame {
|
||||
// Modifiers
|
||||
private StarTowerModifiers modifiers;
|
||||
|
||||
// Cached build
|
||||
// Cached info
|
||||
private transient StarTowerBuild build;
|
||||
private transient ItemParamMap newInfos;
|
||||
private transient ItemParamMap rarePotentialCount;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public StarTowerGame() {
|
||||
@@ -173,6 +175,9 @@ public class StarTowerGame {
|
||||
this.charIds = charList.toIntArray();
|
||||
this.discIds = discList.toIntArray();
|
||||
|
||||
// Temp data to cache for rare potential count
|
||||
this.rarePotentialCount = new ItemParamMap();
|
||||
|
||||
// Finish setting up droppable sub note skills
|
||||
for (int id : GameConstants.TOWER_COMMON_SUB_NOTE_SKILLS) {
|
||||
this.subNoteDropList.add(id);
|
||||
@@ -206,6 +211,10 @@ public class StarTowerGame {
|
||||
return this.getData().getDifficulty();
|
||||
}
|
||||
|
||||
public int getRarePotentialCount(int charId) {
|
||||
return this.getRarePotentialCount().get(charId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the team element, if the team has 2+ or more elements, then returns null
|
||||
*/
|
||||
@@ -424,6 +433,11 @@ public class StarTowerGame {
|
||||
// Add potential
|
||||
this.getPotentials().put(id, nextLevel);
|
||||
|
||||
// Add to rare potential count
|
||||
if (potentialData.isRare()) {
|
||||
this.getRarePotentialCount().add(potentialData.getCharId(), 1);
|
||||
}
|
||||
|
||||
// Add to change info
|
||||
var info = PotentialInfo.newInstance()
|
||||
.setTid(id)
|
||||
@@ -491,14 +505,34 @@ public class StarTowerGame {
|
||||
* Adds random potential selector cases for the client
|
||||
*/
|
||||
public void addPotentialSelectors(int amount) {
|
||||
if (amount <= 0) return;
|
||||
this.pendingPotentialCases += amount;
|
||||
}
|
||||
|
||||
public void addRarePotentialSelectors(int amount) {
|
||||
if (amount <= 0) return;
|
||||
this.pendingRarePotentialCases += amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a potential selectors for the client if there are any potential selectors avaliable.
|
||||
* If there are none, then create the door case so the player can exit
|
||||
*/
|
||||
public List<StarTowerBaseCase> handlePendingPotentialSelectors() {
|
||||
// Create rare potential selectors if any characters can recieve a rare potential
|
||||
if (this.pendingRarePotentialCases > 0) {
|
||||
this.pendingRarePotentialCases--;
|
||||
|
||||
// Create a rare selector, if no selector can be created, then create a regular one instead
|
||||
var selector = this.createRarePotentialSelector();
|
||||
|
||||
if (selector != null) {
|
||||
return List.of(selector);
|
||||
} else {
|
||||
this.pendingPotentialCases += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Create potential selectors if any are avaliable
|
||||
if (this.pendingPotentialCases > 0) {
|
||||
this.pendingPotentialCases--;
|
||||
@@ -553,12 +587,17 @@ public class StarTowerGame {
|
||||
/**
|
||||
* Creates a potential selector for the specified character
|
||||
*/
|
||||
public StarTowerPotentialCase createPotentialSelector(int charId, boolean rareOnly) {
|
||||
public StarTowerPotentialCase createPotentialSelector(int charId, boolean rare) {
|
||||
// Check character id
|
||||
if (charId <= 0) {
|
||||
charId = this.getRandomCharId();
|
||||
}
|
||||
|
||||
// Make sure character can't have more than 2 rare potentials
|
||||
if (rare && this.getRarePotentialCount(charId) >= 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get character potentials
|
||||
var data = GameData.getCharPotentialDataTable().get(charId);
|
||||
if (data == null) {
|
||||
@@ -572,20 +611,20 @@ public class StarTowerGame {
|
||||
boolean isMainCharacter = this.getCharIds()[0] == charId;
|
||||
|
||||
if (isMainCharacter) {
|
||||
list.addElements(0, data.getMasterSpecificPotentialIds());
|
||||
|
||||
if (!rareOnly) {
|
||||
if (rare) {
|
||||
list.addElements(0, data.getMasterSpecificPotentialIds());
|
||||
} else {
|
||||
list.addElements(0, data.getMasterNormalPotentialIds());
|
||||
}
|
||||
} else {
|
||||
list.addElements(0, data.getAssistSpecificPotentialIds());
|
||||
|
||||
if (!rareOnly) {
|
||||
if (rare) {
|
||||
list.addElements(0, data.getAssistSpecificPotentialIds());
|
||||
} else {
|
||||
list.addElements(0, data.getAssistNormalPotentialIds());
|
||||
}
|
||||
}
|
||||
|
||||
if (!rareOnly) {
|
||||
if (!rare) {
|
||||
list.addElements(0, data.getCommonPotentialIds());
|
||||
}
|
||||
|
||||
@@ -648,13 +687,44 @@ public class StarTowerGame {
|
||||
}
|
||||
|
||||
// Creator potential selector case
|
||||
if (rareOnly) {
|
||||
if (rare) {
|
||||
return new StarTowerSelectSpecialPotentialCase(this, charId, selector);
|
||||
} else {
|
||||
return new StarTowerPotentialCase(this, charId, selector);
|
||||
}
|
||||
}
|
||||
|
||||
public int getRandomCharIdForRarePotential() {
|
||||
// Create list of avaliable characters
|
||||
IntList list = new IntArrayList();
|
||||
|
||||
for (int id : this.getCharIds()) {
|
||||
int rareCount = this.getRarePotentialCount().get(id);
|
||||
if (rareCount < 2) {
|
||||
list.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
// Sanity check
|
||||
if (list.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Utils.randomElement(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a random rare potential selector
|
||||
*/
|
||||
public StarTowerPotentialCase createRarePotentialSelector() {
|
||||
// Get random character from list
|
||||
int charId = this.getRandomCharIdForRarePotential();
|
||||
if (charId == 0) return null;
|
||||
|
||||
// Create rare selector
|
||||
return this.createPotentialSelector(charId, true);
|
||||
}
|
||||
|
||||
public StarTowerPotentialCase createStrengthenSelector() {
|
||||
// Random potentials list
|
||||
var potentials = new IntArrayList();
|
||||
|
||||
@@ -72,9 +72,9 @@ public class StarTowerModifiers {
|
||||
|
||||
// Bonus potential max level (Ocean of Souls)
|
||||
if (this.hasGrowthNode(30301)) {
|
||||
this.bonusMaxPotentialLevel = 6;
|
||||
this.bonusMaxPotentialLevel = 3; // 6 total
|
||||
} else if (this.hasGrowthNode(20601)) {
|
||||
this.bonusMaxPotentialLevel = 4;
|
||||
this.bonusMaxPotentialLevel = 1; // 4 total
|
||||
}
|
||||
|
||||
// Shop extra goods (Monolith Premium)
|
||||
|
||||
@@ -21,6 +21,10 @@ public class StarTowerBattleCase extends StarTowerBaseCase {
|
||||
return CaseType.Battle;
|
||||
}
|
||||
|
||||
public RoomType getRoomType() {
|
||||
return this.getRoom().getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegister() {
|
||||
// Get relevant floor exp data
|
||||
@@ -70,7 +74,28 @@ public class StarTowerBattleCase extends StarTowerBaseCase {
|
||||
if (proto.hasVictory()) {
|
||||
// Level up
|
||||
this.getGame().addExp(this.expReward);
|
||||
this.getGame().addPotentialSelectors(this.getGame().levelUp());
|
||||
int picks = this.getGame().levelUp();
|
||||
|
||||
// Handle potential picks
|
||||
if (picks > 0) {
|
||||
// Check special cases
|
||||
if (this.getGame().getFloorCount() == 1) {
|
||||
// First floor potential selector is always special
|
||||
this.getGame().addRarePotentialSelectors(1);
|
||||
picks--;
|
||||
} else if (this.getRoomType() == RoomType.BossRoom || this.getRoomType() == RoomType.FinalBossRoom) {
|
||||
// First selector after a boss fight is also rare
|
||||
this.getGame().addRarePotentialSelectors(1);
|
||||
picks--;
|
||||
} else if (Utils.randomChance(0.125D)) {
|
||||
// Random 1/8th chance for a rare potential
|
||||
this.getGame().addRarePotentialSelectors(1);
|
||||
picks--;
|
||||
}
|
||||
}
|
||||
|
||||
// Add remaining picks
|
||||
this.getGame().addPotentialSelectors(picks);
|
||||
|
||||
// Add clear time
|
||||
this.getGame().addBattleTime(proto.getVictory().getTime());
|
||||
|
||||
@@ -297,7 +297,8 @@ public class StarTowerNpcEventCase extends StarTowerBaseCase {
|
||||
}
|
||||
|
||||
private void addRarePotentialSelector(StarTowerInteractResp rsp) {
|
||||
this.addRarePotentialSelector(rsp, 0);
|
||||
int charId = this.getGame().getRandomCharIdForRarePotential();
|
||||
this.addRarePotentialSelector(rsp, charId);
|
||||
}
|
||||
|
||||
private void addRarePotentialSelector(StarTowerInteractResp rsp, int charId) {
|
||||
|
||||
Reference in New Issue
Block a user