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) {
|
if (entries < 3) {
|
||||||
this.getInventory().addItem(GameConstants.WEEKLY_ENTRY_ITEM_ID, 3 - entries);
|
this.getInventory().addItem(GameConstants.WEEKLY_ENTRY_ITEM_ID, 3 - entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset weekly tower tickets
|
||||||
|
this.getProgress().clearWeeklyTowerTicketLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to reset monthly
|
// Check if we need to reset monthly
|
||||||
@@ -819,6 +822,7 @@ public class Player implements GameDatabaseObject {
|
|||||||
PlayerInfo proto = PlayerInfo.newInstance()
|
PlayerInfo proto = PlayerInfo.newInstance()
|
||||||
.setServerTs(Nebula.getCurrentTime())
|
.setServerTs(Nebula.getCurrentTime())
|
||||||
.setSigninIndex(this.getSignInIndex())
|
.setSigninIndex(this.getSignInIndex())
|
||||||
|
.setTowerTicket(this.getProgress().getTowerTickets())
|
||||||
.setDailyShopRewardStatus(this.getQuestManager().hasDailyReward())
|
.setDailyShopRewardStatus(this.getQuestManager().hasDailyReward())
|
||||||
.setAchievements(new byte[64]);
|
.setAchievements(new byte[64]);
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
|||||||
// Star Tower
|
// Star Tower
|
||||||
private IntSet starTowerLog;
|
private IntSet starTowerLog;
|
||||||
private int[] starTowerGrowth;
|
private int[] starTowerGrowth;
|
||||||
|
private int towerTickets;
|
||||||
|
|
||||||
// Instances
|
// Instances
|
||||||
private Int2IntMap dailyInstanceLog;
|
private Int2IntMap dailyInstanceLog;
|
||||||
@@ -122,6 +123,39 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
|||||||
return true;
|
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) {
|
public void addInfinityArenaLog(int levelId) {
|
||||||
// Calculate arena id
|
// Calculate arena id
|
||||||
int id = (int) Math.floor(levelId / 10000D);
|
int id = (int) Math.floor(levelId / 10000D);
|
||||||
|
|||||||
@@ -856,12 +856,12 @@ public class StarTowerGame {
|
|||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StarTowerInteractResp settle(StarTowerInteractResp rsp, boolean isWin) {
|
public StarTowerInteractResp settle(StarTowerInteractResp rsp, boolean victory) {
|
||||||
// Set completed flag
|
// Set completed flag
|
||||||
this.completed = true;
|
this.completed = true;
|
||||||
|
|
||||||
// End game
|
// End game
|
||||||
this.getManager().settleGame(isWin);
|
this.getManager().settleGame(victory);
|
||||||
|
|
||||||
// Settle info
|
// Settle info
|
||||||
var settle = rsp.getMutableSettle()
|
var settle = rsp.getMutableSettle()
|
||||||
@@ -871,6 +871,30 @@ public class StarTowerGame {
|
|||||||
// Set empty change info
|
// Set empty change info
|
||||||
settle.getMutableChange();
|
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
|
// Complete
|
||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +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.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
@@ -233,6 +233,9 @@ public class StarTowerManager extends PlayerManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear game
|
||||||
|
this.game = null;
|
||||||
|
|
||||||
// Set last build
|
// Set last build
|
||||||
this.lastBuild = game.getBuild();
|
this.lastBuild = game.getBuild();
|
||||||
|
|
||||||
@@ -265,33 +268,6 @@ public class StarTowerManager extends PlayerManager {
|
|||||||
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
|
|
||||||
this.game = null;
|
|
||||||
|
|
||||||
// Return change info
|
|
||||||
return change;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Achievements
|
// Achievements
|
||||||
|
|
||||||
private void updateTowerGroupAchievements(StarTowerGame game) {
|
private void updateTowerGroupAchievements(StarTowerGame game) {
|
||||||
@@ -327,9 +303,16 @@ public class StarTowerManager extends PlayerManager {
|
|||||||
// Calculate quanity of tickets from record score
|
// Calculate quanity of tickets from record score
|
||||||
int count = (int) Math.floor(build.getScore() / 100);
|
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
|
// Add journey tickets
|
||||||
this.getPlayer().getInventory().addItem(12, count, change);
|
this.getPlayer().getInventory().addItem(12, count, change);
|
||||||
|
|
||||||
|
// Add to weekly ticket log
|
||||||
|
this.getPlayer().getProgress().addWeeklyTowerTicketLog(count);
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public class HandlerStarTowerBuildDeleteReq extends NetHandler {
|
|||||||
|
|
||||||
// Build response
|
// Build response
|
||||||
var rsp = StarTowerBuildDeleteResp.newInstance()
|
var rsp = StarTowerBuildDeleteResp.newInstance()
|
||||||
|
.setTicket(session.getPlayer().getProgress().getTowerTickets())
|
||||||
.setChange(change.toProto());
|
.setChange(change.toProto());
|
||||||
|
|
||||||
// Encode packet
|
// Encode packet
|
||||||
|
|||||||
@@ -26,11 +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()
|
||||||
|
.setTicket(session.getPlayer().getProgress().getTowerTickets())
|
||||||
.setChange(change.toProto());
|
.setChange(change.toProto());
|
||||||
|
|
||||||
return session.encodeMsg(NetMsgId.star_tower_build_whether_save_succeed_ack, rsp);
|
return session.encodeMsg(NetMsgId.star_tower_build_whether_save_succeed_ack, rsp);
|
||||||
|
|||||||
Reference in New Issue
Block a user