Add journey tickets after finishing a tower run

This commit is contained in:
Melledy
2025-12-06 19:40:15 -08:00
parent 2a7817df95
commit 467b7443f3
5 changed files with 79 additions and 23 deletions

View File

@@ -76,6 +76,7 @@ public class StarTowerGame {
private int pendingPotentialCases = 0; private int pendingPotentialCases = 0;
private int pendingSubNotes = 0; private int pendingSubNotes = 0;
private boolean completed;
// Bag // Bag
private ItemParamMap items; private ItemParamMap items;
@@ -807,29 +808,20 @@ public class StarTowerGame {
} }
public StarTowerInteractResp settle(StarTowerInteractResp rsp, boolean isWin) { public StarTowerInteractResp settle(StarTowerInteractResp rsp, boolean isWin) {
// Set completed flag
this.completed = true;
// End game // End game
this.getManager().endGame(isWin); this.getManager().settleGame(isWin);
// Settle info // Settle info
var settle = rsp.getMutableSettle() var settle = rsp.getMutableSettle()
.setTotalTime(this.getBattleTime()) .setTotalTime(this.getBattleTime())
.setBuild(this.getBuild().toProto()); .setBuild(this.getBuild().toProto());
// Mark change info // Set empty change info
settle.getMutableChange(); settle.getMutableChange();
// Log victory
if (isWin) {
// Add star tower history
this.getManager().getPlayer().getProgress().addStarTowerLog(this.getId());
// Trigger achievement
var elementType = this.getTeamElement();
if (elementType != null) {
this.getAchievementManager().trigger(AchievementCondition.TowerClearSpecificCharacterTypeWithTotal, 1, elementType.getValue(), 0);
}
}
// Complete // Complete
return rsp; return rsp;
} }

View File

@@ -10,6 +10,7 @@ import emu.nebula.game.player.PlayerManager;
import emu.nebula.game.player.PlayerProgress; import emu.nebula.game.player.PlayerProgress;
import emu.nebula.game.quest.QuestCondition; import emu.nebula.game.quest.QuestCondition;
import emu.nebula.proto.StarTowerApply.StarTowerApplyReq; import emu.nebula.proto.StarTowerApply.StarTowerApplyReq;
import emu.nebula.util.Utils;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@@ -219,7 +220,7 @@ public class StarTowerManager extends PlayerManager {
return change.setExtraData(this.game); return change.setExtraData(this.game);
} }
public StarTowerGame endGame(boolean victory) { public StarTowerGame settleGame(boolean victory) {
// Cache instance // Cache instance
var game = this.game; var game = this.game;
@@ -232,27 +233,61 @@ public class StarTowerManager extends PlayerManager {
// Handle victory events // Handle victory events
if (victory) { if (victory) {
// Trigger achievements // Add star tower history
this.getPlayer().trigger(AchievementCondition.TowerClearTotal, 1); this.getPlayer().getProgress().addStarTowerLog(game.getId());
this.getPlayer().trigger(
// Achievement conditions
var achievements = this.getPlayer().getAchievementManager();
achievements.trigger(AchievementCondition.TowerClearTotal, 1);
achievements.trigger(
AchievementCondition.TowerClearSpecificGroupIdAndDifficulty, AchievementCondition.TowerClearSpecificGroupIdAndDifficulty,
1, 1,
game.getData().getGroupId(), game.getData().getGroupId(),
game.getData().getDifficulty() game.getData().getDifficulty()
); );
this.getPlayer().trigger( achievements.trigger(
AchievementCondition.TowerClearSpecificLevelWithDifficultyAndTotal, AchievementCondition.TowerClearSpecificLevelWithDifficultyAndTotal,
1, 1,
game.getData().getId(), game.getData().getId(),
game.getData().getDifficulty() game.getData().getDifficulty()
); );
var elementType = game.getTeamElement();
if (elementType != null) {
achievements.trigger(AchievementCondition.TowerClearSpecificCharacterTypeWithTotal, 1, elementType.getValue(), 0);
}
} }
// Return game
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 // Clear game instance
this.game = null; this.game = null;
// Return game // Return change info
return game; return change;
} }
// Build // Build
@@ -277,8 +312,10 @@ public class StarTowerManager extends PlayerManager {
// Create player change info // Create player change info
var change = new PlayerChangeInfo(); var change = new PlayerChangeInfo();
// Cache build and clear reference // Cache build
var build = this.lastBuild; var build = this.lastBuild;
// Clear reference to build
this.lastBuild = null; this.lastBuild = null;
// Check if the player wants this build or not // Check if the player wants this build or not

View File

@@ -1,6 +1,7 @@
package emu.nebula.game.tower; package emu.nebula.game.tower;
import emu.nebula.GameConstants; import emu.nebula.GameConstants;
import emu.nebula.util.Utils;
import lombok.Getter; import lombok.Getter;
/** /**
@@ -178,4 +179,27 @@ public class StarTowerModifiers {
public void consumeShopReroll() { public void consumeShopReroll() {
this.shopRerollCount = Math.max(this.shopRerollCount - 1, 0); this.shopRerollCount = Math.max(this.shopRerollCount - 1, 0);
} }
/**
* Returns the amount of tickets we earn from completing this monolith
*/
public int calculateTickets() {
// Get base amount
int tickets = 50;
// Add tickets based on difficulty
tickets += Utils.randomRange(game.getDifficulty() * 50, game.getDifficulty() * 100);
// Apply talent modifiers
if (this.hasGrowthNode(20403)) {
tickets *= 2; // +100%
} else if (this.hasGrowthNode(20102)) {
tickets *= 1.6; // +60%
} else if (this.hasGrowthNode(10501)) {
tickets *= 1.3; // +30%
}
// Complete
return tickets;
}
} }

View File

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

View File

@@ -11,7 +11,7 @@ public class HandlerStarTowerGiveUpReq extends NetHandler {
@Override @Override
public byte[] handle(GameSession session, byte[] message) throws Exception { public byte[] handle(GameSession session, byte[] message) throws Exception {
var game = session.getPlayer().getStarTowerManager().endGame(false); var game = session.getPlayer().getStarTowerManager().settleGame(false);
if (game == null) { if (game == null) {
return session.encodeMsg(NetMsgId.star_tower_give_up_failed_ack); return session.encodeMsg(NetMsgId.star_tower_give_up_failed_ack);