mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 12:24:35 +01:00
Implement weekly journey ticket limit
This commit is contained in:
@@ -686,6 +686,9 @@ public class Player implements GameDatabaseObject {
|
||||
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
|
||||
@@ -819,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]);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -856,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()
|
||||
@@ -871,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user