6 Commits

Author SHA1 Message Date
Melledy
6483e8a5a7 Implement weekly journey ticket limit 2025-12-09 23:49:48 -08:00
Melledy
5d797fb9d3 Fix weekly boss entry tickets resetting every day 2025-12-09 23:28:24 -08:00
Melledy
0ad87dd751 Improve random potential selector generator 2025-12-09 22:37:04 -08:00
Melledy
5b7adc8fa4 Separate custom data defs into their own category 2025-12-09 21:57:35 -08:00
Melledy
6f832bcdfe Fix potential count calculations when creating a record 2025-12-09 21:33:34 -08:00
Melledy
bf5fe3912f Fix discs surging to max crescendo regardless of materials used 2025-12-09 21:28:53 -08:00
15 changed files with 215 additions and 63 deletions

View File

@@ -11,7 +11,7 @@ import java.util.stream.Collectors;
import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import emu.nebula.data.custom.CharGemAttrGroupDef;
import emu.nebula.data.resources.*;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package emu.nebula.data.resources;
package emu.nebula.data.custom;
import java.util.List;
import java.util.Map;
@@ -6,6 +6,7 @@ import java.util.Map;
import emu.nebula.data.BaseDef;
import emu.nebula.data.GameData;
import emu.nebula.data.ResourceType;
import emu.nebula.data.resources.CharGemAttrValueDef;
import emu.nebula.util.WeightedList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
@@ -97,7 +98,7 @@ public class CharGemAttrGroupDef extends BaseDef {
this.values = new WeightedList<>();
}
protected void addValue(CharGemAttrValueDef value) {
public void addValue(CharGemAttrValueDef value) {
this.values.add(value.getRarity(), value);
}

View File

@@ -3,6 +3,7 @@ package emu.nebula.data.resources;
import emu.nebula.data.BaseDef;
import emu.nebula.data.GameData;
import emu.nebula.data.ResourceType;
import emu.nebula.data.custom.CharGemAttrGroupDef;
import emu.nebula.util.CustomIntArray;
import emu.nebula.util.Utils;
import emu.nebula.util.WeightedList;

View File

@@ -21,6 +21,10 @@ public class PotentialDef extends BaseDef {
public int getId() {
return Id;
}
public boolean isRare() {
return this.BranchType != 3;
}
public int getMaxLevel() {
// Check if regular potential

View File

@@ -245,9 +245,11 @@ public class GameDisc implements GameDatabaseObject {
// Remove items
var change = this.getPlayer().getInventory().removeItems(materials, null);
// Add star
// Cache old star value
int old = this.star;
this.star = Math.max(this.star + count, 5);
// Add star
this.star = Math.min(this.star + count, 5);
// Save to database if star count changed
if (this.star != old) {

View File

@@ -633,13 +633,7 @@ public class Player implements GameDatabaseObject {
// Trigger quest/achievement login
this.trigger(QuestCondition.LoginTotal, 1);
// Add weekly boss entry item
int entries = this.getInventory().getResourceCount(GameConstants.WEEKLY_ENTRY_ITEM_ID);
if (entries < 3) {
this.getInventory().addItem(GameConstants.WEEKLY_ENTRY_ITEM_ID, 3 - entries);
}
// Give sign-in rewards
this.getSignInRewards(hasMonthChanged);
@@ -685,8 +679,21 @@ public class Player implements GameDatabaseObject {
this.getQuestManager().resetDailyQuests();
this.getBattlePassManager().getBattlePass().resetDailyQuests(resetWeekly);
// Reset monthly shop purchases
// Check to reset weeklies
if (resetWeekly) {
// Add weekly boss entry item
int entries = this.getInventory().getResourceCount(GameConstants.WEEKLY_ENTRY_ITEM_ID);
if (entries < 3) {
this.getInventory().addItem(GameConstants.WEEKLY_ENTRY_ITEM_ID, 3 - entries);
}
// Reset weekly tower tickets
this.getProgress().clearWeeklyTowerTicketLog();
}
// Check if we need to reset monthly
if (resetMonthly) {
// Reset monthly shop purchases
this.getInventory().resetShopPurchases();
}
}
@@ -815,6 +822,7 @@ public class Player implements GameDatabaseObject {
PlayerInfo proto = PlayerInfo.newInstance()
.setServerTs(Nebula.getCurrentTime())
.setSigninIndex(this.getSignInIndex())
.setTowerTicket(this.getProgress().getTowerTickets())
.setDailyShopRewardStatus(this.getQuestManager().hasDailyReward())
.setAchievements(new byte[64]);

View File

@@ -34,6 +34,7 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
// Star Tower
private IntSet starTowerLog;
private int[] starTowerGrowth;
private int towerTickets;
// Instances
private Int2IntMap dailyInstanceLog;
@@ -122,6 +123,39 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
return true;
}
/**
* Returns the maximum amount of weekly tickets that a player can receive without hitting the limit
*/
public int getMaxEarnableWeeklyTowerTickets() {
return Math.max(this.getWeeklyTowerTicketLimit() - this.getTowerTickets(), 0);
}
public int getWeeklyTowerTicketLimit() {
int limit = 2000;
if (this.getPlayer().getStarTowerManager().hasGrowthNode(10502)) {
limit += 1000;
} else if (this.getPlayer().getStarTowerManager().hasGrowthNode(10201)) {
limit += 500;
}
return limit;
}
public void addWeeklyTowerTicketLog(int count) {
this.towerTickets += count;
Nebula.getGameDatabase().update(this, this.getUid(), "towerTickets", this.towerTickets);
}
public void clearWeeklyTowerTicketLog() {
if (this.towerTickets == 0) {
return;
}
this.towerTickets = 0;
Nebula.getGameDatabase().update(this, this.getUid(), "towerTickets", this.towerTickets);
}
public void addInfinityArenaLog(int levelId) {
// Calculate arena id
int id = (int) Math.floor(levelId / 10000D);

View File

@@ -70,7 +70,7 @@ public class StarTowerBuild implements GameDatabaseObject {
// Add potentials
for (var entry : game.getPotentials()) {
//
// Get potential data
int id = entry.getIntKey();
int level = entry.getIntValue();
@@ -81,13 +81,13 @@ public class StarTowerBuild implements GameDatabaseObject {
var potentialData = GameData.getPotentialDataTable().get(id);
if (potentialData != null) {
int charId = potentialData.getCharId();
this.getCharPots().put(charId, this.getCharPots().get(charId) + 1);
this.getCharPots().add(charId, level);
}
}
// Add sub note skills
for (var entry : game.getItems()) {
this.getSubNoteSkills().put(entry.getIntKey(), entry.getIntValue());
this.getSubNoteSkills().add(entry.getIntKey(), entry.getIntValue());
}
// Set secondary skills

View File

@@ -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();
@@ -786,12 +856,12 @@ public class StarTowerGame {
return rsp;
}
public StarTowerInteractResp settle(StarTowerInteractResp rsp, boolean isWin) {
public StarTowerInteractResp settle(StarTowerInteractResp rsp, boolean victory) {
// Set completed flag
this.completed = true;
// End game
this.getManager().settleGame(isWin);
this.getManager().settleGame(victory);
// Settle info
var settle = rsp.getMutableSettle()
@@ -801,6 +871,30 @@ public class StarTowerGame {
// Set empty change info
settle.getMutableChange();
// Calculate rewards
if (victory) {
// Init rewards
var rewards = new ItemParamMap();
// Add journey tickets
int tickets = this.getModifiers().calculateTickets();
rewards.add(12, tickets);
// (Custom) Add research materials since tower quests are not implemented yet
int research = 50 + (Utils.randomRange(this.getDifficulty() - 1, this.getDifficulty() * 2) * 10);
rewards.add(51, research);
// Add to inventory
var change = this.getPlayer().getInventory().addItem(51, research);
// Set proto data
settle.setChange(change.toProto());
rewards.toItemTemplateStream().forEach(settle::addTowerRewards);
// Save tower tickets
this.getPlayer().getProgress().addWeeklyTowerTicketLog(tickets);
}
// Complete
return rsp;
}

View File

@@ -10,7 +10,7 @@ import emu.nebula.game.player.PlayerManager;
import emu.nebula.game.player.PlayerProgress;
import emu.nebula.game.quest.QuestCondition;
import emu.nebula.proto.StarTowerApply.StarTowerApplyReq;
import emu.nebula.util.Utils;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
@@ -233,6 +233,9 @@ public class StarTowerManager extends PlayerManager {
return null;
}
// Clear game
this.game = null;
// Set last build
this.lastBuild = game.getBuild();
@@ -265,33 +268,6 @@ public class StarTowerManager extends PlayerManager {
return game;
}
public PlayerChangeInfo addRewards(PlayerChangeInfo change) {
// Create change info
if (change == null) {
change = new PlayerChangeInfo();
}
// Get game
var game = this.getGame();
if (game == null || !game.isCompleted()) {
return change;
}
// Add journey tickets
this.getPlayer().getInventory().addItem(12, game.getModifiers().calculateTickets(), change);
// (Custom) Add research materials since tower quests are not implemented yet
int amount = 50 + (Utils.randomRange(game.getDifficulty() - 1, game.getDifficulty() * 2) * 10);
this.getPlayer().getInventory().addItem(51, amount, change);
// Clear game instance
this.game = null;
// Return change info
return change;
}
// Achievements
private void updateTowerGroupAchievements(StarTowerGame game) {
@@ -327,9 +303,16 @@ public class StarTowerManager extends PlayerManager {
// Calculate quanity of tickets from record score
int count = (int) Math.floor(build.getScore() / 100);
// Check weekly tickets
int maxAmount = this.getPlayer().getProgress().getMaxEarnableWeeklyTowerTickets();
count = Math.min(maxAmount, count);
// Add journey tickets
this.getPlayer().getInventory().addItem(12, count, change);
// Add to weekly ticket log
this.getPlayer().getProgress().addWeeklyTowerTicketLog(count);
// Success
return change;
}

View File

@@ -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)

View File

@@ -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());

View File

@@ -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) {

View File

@@ -26,6 +26,7 @@ public class HandlerStarTowerBuildDeleteReq extends NetHandler {
// Build response
var rsp = StarTowerBuildDeleteResp.newInstance()
.setTicket(session.getPlayer().getProgress().getTowerTickets())
.setChange(change.toProto());
// Encode packet

View File

@@ -26,11 +26,9 @@ public class HandlerStarTowerBuildWhetherSaveReq extends NetHandler {
return session.encodeMsg(NetMsgId.star_tower_build_whether_save_failed_ack);
}
// Add rewards from game
session.getPlayer().getStarTowerManager().addRewards(change);
// Build response
var rsp = StarTowerBuildWhetherSaveResp.newInstance()
.setTicket(session.getPlayer().getProgress().getTowerTickets())
.setChange(change.toProto());
return session.encodeMsg(NetMsgId.star_tower_build_whether_save_succeed_ack, rsp);