mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-13 04:45:02 +01:00
Handle more achievements
This commit is contained in:
@@ -20,8 +20,8 @@ public class AchievementDef extends BaseDef {
|
|||||||
private int Qty1;
|
private int Qty1;
|
||||||
|
|
||||||
// Custom params
|
// Custom params
|
||||||
private transient int param1;
|
private transient int param1; // -1 == any, 0 = no param, 1+ = param required
|
||||||
private transient int param2;
|
private transient int param2; // -1 == any, 0 = no param, 1+ = param required
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
@@ -33,12 +33,30 @@ public class AchievementDef extends BaseDef {
|
|||||||
this.param2 = param2;
|
this.param2 = param2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasParam1() {
|
/**
|
||||||
return this.param1 > 0;
|
* Checks if this achievement requires params to match
|
||||||
|
*/
|
||||||
|
public boolean hasParam1(int param) {
|
||||||
|
if (this.param1 < 0) {
|
||||||
|
return false;
|
||||||
|
} else if (this.param1 == 0) {
|
||||||
|
return param != 0;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasParam2() {
|
/**
|
||||||
return this.param2 > 0;
|
* Checks if this achievement requires params to match
|
||||||
|
*/
|
||||||
|
public boolean hasParam2(int param) {
|
||||||
|
if (this.param2 < 0) {
|
||||||
|
return false;
|
||||||
|
} else if (this.param2 == 0) {
|
||||||
|
return param != 0;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import lombok.Getter;
|
|||||||
// Because achievements in the data files do not have params, we will hardcode them here
|
// Because achievements in the data files do not have params, we will hardcode them here
|
||||||
public class AchievementHelper {
|
public class AchievementHelper {
|
||||||
// Cache
|
// Cache
|
||||||
private static IntSet isTotalAchievementSet = new IntOpenHashSet();
|
private static IntSet incrementalAchievementSet = new IntOpenHashSet();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private static Int2ObjectMap<List<AchievementDef>> cache = new Int2ObjectOpenHashMap<>();
|
private static Int2ObjectMap<List<AchievementDef>> cache = new Int2ObjectOpenHashMap<>();
|
||||||
@@ -25,8 +25,8 @@ public class AchievementHelper {
|
|||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
public static boolean isTotalAchievement(int condition) {
|
public static boolean isIncrementalAchievement(int condition) {
|
||||||
return isTotalAchievementSet.contains(condition);
|
return incrementalAchievementSet.contains(condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix params
|
// Fix params
|
||||||
@@ -35,12 +35,14 @@ public class AchievementHelper {
|
|||||||
// Cache total achievements
|
// Cache total achievements
|
||||||
for (var condition : AchievementCondition.values()) {
|
for (var condition : AchievementCondition.values()) {
|
||||||
if (condition.name().endsWith("Total")) {
|
if (condition.name().endsWith("Total")) {
|
||||||
isTotalAchievementSet.add(condition.getValue());
|
incrementalAchievementSet.add(condition.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isTotalAchievementSet.add(AchievementCondition.ItemsAdd.getValue());
|
incrementalAchievementSet.remove(AchievementCondition.AchievementTotal.getValue());
|
||||||
isTotalAchievementSet.add(AchievementCondition.ItemsDeplete.getValue());
|
|
||||||
|
incrementalAchievementSet.add(AchievementCondition.ItemsAdd.getValue());
|
||||||
|
incrementalAchievementSet.add(AchievementCondition.ItemsDeplete.getValue());
|
||||||
|
|
||||||
// Fix params
|
// Fix params
|
||||||
fixParams();
|
fixParams();
|
||||||
@@ -58,6 +60,33 @@ public class AchievementHelper {
|
|||||||
addParam(27, GameConstants.GOLD_ITEM_ID, 0);
|
addParam(27, GameConstants.GOLD_ITEM_ID, 0);
|
||||||
addParam(28, GameConstants.GOLD_ITEM_ID, 0);
|
addParam(28, GameConstants.GOLD_ITEM_ID, 0);
|
||||||
addParam(29, GameConstants.GOLD_ITEM_ID, 0);
|
addParam(29, GameConstants.GOLD_ITEM_ID, 0);
|
||||||
|
|
||||||
|
// Ininfite tower
|
||||||
|
for (int diff = 10, id = 270; diff <= 60; diff += 10) {
|
||||||
|
addParam(id++, 11000 + diff, 0); // Infinite Arena
|
||||||
|
addParam(id++, 51000 + diff, 0); // Shake the Floor
|
||||||
|
addParam(id++, 41000 + diff, 0); // Elegance and Flow
|
||||||
|
addParam(id++, 71000 + diff, 0); // Upbeat Party
|
||||||
|
addParam(id++, 31000 + diff, 0); // Thrilling Beat
|
||||||
|
addParam(id++, 21000 + diff, 0); // Flames and Beats
|
||||||
|
addParam(id++, 61000 + diff, 0); // Sinister Ritual
|
||||||
|
}
|
||||||
|
|
||||||
|
// Character count
|
||||||
|
addParam(393, 1, 0);
|
||||||
|
addParam(394, 1, 0);
|
||||||
|
addParam(395, 1, 0);
|
||||||
|
addParam(396, 1, 0);
|
||||||
|
addParam(397, 1, 0);
|
||||||
|
addParam(398, 1, 0);
|
||||||
|
|
||||||
|
// Disc count
|
||||||
|
addParam(382, 1, 0);
|
||||||
|
addParam(383, 1, 0);
|
||||||
|
addParam(384, 1, 0);
|
||||||
|
addParam(385, 1, 0);
|
||||||
|
addParam(386, 1, 0);
|
||||||
|
addParam(387, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addParam(int achievementId, int param1, int param2) {
|
private static void addParam(int achievementId, int param1, int param2) {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class AchievementManager extends PlayerManager implements GameDatabaseObj
|
|||||||
// Parse events
|
// Parse events
|
||||||
for (var event : events.getList()) {
|
for (var event : events.getList()) {
|
||||||
// Check id
|
// Check id
|
||||||
if (event.getId() != 200) {
|
if (event.getId() != AchievementCondition.ClientReport.getValue()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,7 +157,7 @@ public class AchievementManager extends PlayerManager implements GameDatabaseObj
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check what type of achievement condition this is
|
// Check what type of achievement condition this is
|
||||||
boolean isTotal = AchievementHelper.isTotalAchievement(condition);
|
boolean isTotal = AchievementHelper.isIncrementalAchievement(condition);
|
||||||
boolean hasCompleted = false;
|
boolean hasCompleted = false;
|
||||||
|
|
||||||
// Parse achievements
|
// Parse achievements
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ public class GameAchievement {
|
|||||||
var data = this.getData();
|
var data = this.getData();
|
||||||
if (data == null) return false;
|
if (data == null) return false;
|
||||||
|
|
||||||
if ((data.hasParam1() || param1 != 0) && data.getParam1() != param1) {
|
if (data.hasParam1(param1) && data.getParam1() != param1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((data.hasParam2() || param2 != 0) && data.getParam2() != param2) {
|
if (data.hasParam2(param2) && data.getParam2() != param2) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import emu.nebula.data.GameData;
|
|||||||
import emu.nebula.data.resources.CharacterDef;
|
import emu.nebula.data.resources.CharacterDef;
|
||||||
import emu.nebula.data.resources.DiscDef;
|
import emu.nebula.data.resources.DiscDef;
|
||||||
import emu.nebula.game.player.PlayerManager;
|
import emu.nebula.game.player.PlayerManager;
|
||||||
|
import emu.nebula.net.NetMsgId;
|
||||||
import emu.nebula.proto.Public.HandbookInfo;
|
import emu.nebula.proto.Public.HandbookInfo;
|
||||||
import emu.nebula.util.Bitset;
|
import emu.nebula.util.Bitset;
|
||||||
|
import emu.nebula.game.achievement.AchievementCondition;
|
||||||
import emu.nebula.game.player.Player;
|
import emu.nebula.game.player.Player;
|
||||||
import emu.nebula.game.player.PlayerChangeInfo;
|
import emu.nebula.game.player.PlayerChangeInfo;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
@@ -22,6 +24,10 @@ public class CharacterStorage extends PlayerManager {
|
|||||||
private final Int2ObjectMap<GameCharacter> characters;
|
private final Int2ObjectMap<GameCharacter> characters;
|
||||||
private final Int2ObjectMap<GameDisc> discs;
|
private final Int2ObjectMap<GameDisc> discs;
|
||||||
|
|
||||||
|
// Flags
|
||||||
|
@Setter private boolean hasAddedChar;
|
||||||
|
@Setter private boolean hasAddedDisc;
|
||||||
|
|
||||||
@Setter private boolean updateCharHandbook;
|
@Setter private boolean updateCharHandbook;
|
||||||
@Setter private boolean updateDiscHandbook;
|
@Setter private boolean updateDiscHandbook;
|
||||||
|
|
||||||
@@ -67,11 +73,14 @@ public class CharacterStorage extends PlayerManager {
|
|||||||
// Save to database
|
// Save to database
|
||||||
character.save();
|
character.save();
|
||||||
|
|
||||||
// Set flag for player to update character skins in their handbook
|
|
||||||
this.setUpdateCharHandbook(true);
|
|
||||||
|
|
||||||
// Add to characters
|
// Add to characters
|
||||||
this.characters.put(character.getCharId(), character);
|
this.characters.put(character.getCharId(), character);
|
||||||
|
|
||||||
|
// Set flags for player to update character skins in their handbook
|
||||||
|
this.setUpdateCharHandbook(true);
|
||||||
|
this.setHasAddedChar(true);
|
||||||
|
|
||||||
|
// Return character
|
||||||
return character;
|
return character;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,18 +88,6 @@ public class CharacterStorage extends PlayerManager {
|
|||||||
return this.getCharacters().values();
|
return this.getCharacters().values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNewPhoneMessageCount() {
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
for (var character : this.getCharacterCollection()) {
|
|
||||||
if (character.getContact().hasNew()) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HandbookInfo getCharacterHandbook() {
|
public HandbookInfo getCharacterHandbook() {
|
||||||
var bitset = new Bitset();
|
var bitset = new Bitset();
|
||||||
|
|
||||||
@@ -145,11 +142,14 @@ public class CharacterStorage extends PlayerManager {
|
|||||||
// Save to database
|
// Save to database
|
||||||
disc.save();
|
disc.save();
|
||||||
|
|
||||||
// Set flag for player to update discs in their handbook
|
|
||||||
this.setUpdateDiscHandbook(true);
|
|
||||||
|
|
||||||
// Add to discs
|
// Add to discs
|
||||||
this.discs.put(disc.getDiscId(), disc);
|
this.discs.put(disc.getDiscId(), disc);
|
||||||
|
|
||||||
|
// Set flags for player to update discs in their handbook
|
||||||
|
this.setUpdateDiscHandbook(true);
|
||||||
|
this.setHasAddedDisc(true);
|
||||||
|
|
||||||
|
// Return disc
|
||||||
return disc;
|
return disc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +215,73 @@ public class CharacterStorage extends PlayerManager {
|
|||||||
return change.setExtraData(modifiedDiscs);
|
return change.setExtraData(modifiedDiscs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Contacts
|
||||||
|
|
||||||
|
public int getNewPhoneMessageCount() {
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (var character : this.getCharacterCollection()) {
|
||||||
|
if (character.getContact().hasNew()) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if we should add next packages for player
|
||||||
|
*/
|
||||||
|
public void checkPlayerState() {
|
||||||
|
// Check if we need to trigger character achievements
|
||||||
|
if (this.hasAddedChar) {
|
||||||
|
this.hasAddedChar = false;
|
||||||
|
this.getPlayer().trigger(
|
||||||
|
AchievementCondition.CharactersWithSpecificQuantityAndRarity,
|
||||||
|
getCharacters().size()
|
||||||
|
);
|
||||||
|
this.getPlayer().trigger(
|
||||||
|
AchievementCondition.CharactersWithSpecificQuantityAndRarity,
|
||||||
|
(int) getCharacters().values().stream().filter(GameCharacter::isMaster).count(),
|
||||||
|
1,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we need to send handbook update to player
|
||||||
|
if (this.updateCharHandbook) {
|
||||||
|
this.updateCharHandbook = false;
|
||||||
|
this.getPlayer().addNextPackage(
|
||||||
|
NetMsgId.handbook_change_notify,
|
||||||
|
this.getPlayer().getCharacters().getCharacterHandbook());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we need to trigger disc achievements
|
||||||
|
if (this.hasAddedChar) {
|
||||||
|
this.hasAddedChar = false;
|
||||||
|
this.getPlayer().trigger(
|
||||||
|
AchievementCondition.DiscAcquireSpecificQuantityAndRarity,
|
||||||
|
this.getDiscs().size()
|
||||||
|
);
|
||||||
|
this.getPlayer().trigger(
|
||||||
|
AchievementCondition.DiscAcquireSpecificQuantityAndRarity,
|
||||||
|
(int) getDiscs().values().stream().filter(GameDisc::isMaster).count(),
|
||||||
|
1,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we need to send handbook update to player
|
||||||
|
if (this.updateDiscHandbook) {
|
||||||
|
this.updateDiscHandbook = false;
|
||||||
|
this.getPlayer().addNextPackage(
|
||||||
|
NetMsgId.handbook_change_notify,
|
||||||
|
this.getPlayer().getCharacters().getDiscHandbook());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
|
|
||||||
public void loadFromDatabase() {
|
public void loadFromDatabase() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import emu.nebula.data.GameData;
|
|||||||
import emu.nebula.data.resources.CharacterDef;
|
import emu.nebula.data.resources.CharacterDef;
|
||||||
import emu.nebula.data.resources.TalentGroupDef;
|
import emu.nebula.data.resources.TalentGroupDef;
|
||||||
import emu.nebula.database.GameDatabaseObject;
|
import emu.nebula.database.GameDatabaseObject;
|
||||||
|
import emu.nebula.game.achievement.AchievementCondition;
|
||||||
import emu.nebula.game.inventory.ItemParamMap;
|
import emu.nebula.game.inventory.ItemParamMap;
|
||||||
import emu.nebula.game.player.Player;
|
import emu.nebula.game.player.Player;
|
||||||
import emu.nebula.game.player.PlayerChangeInfo;
|
import emu.nebula.game.player.PlayerChangeInfo;
|
||||||
@@ -117,6 +118,10 @@ public class GameCharacter implements GameDatabaseObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMaster() {
|
||||||
|
return this.getData().getGrade() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
public void setLevel(int level) {
|
public void setLevel(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
@@ -272,6 +277,9 @@ public class GameCharacter implements GameDatabaseObject {
|
|||||||
// Save to database
|
// Save to database
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
|
// Trigger quest/achievement
|
||||||
|
this.getPlayer().trigger(AchievementCondition.CharacterAdvanceTotal, 1);
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
return changes.setSuccess(true);
|
return changes.setSuccess(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import emu.nebula.data.GameData;
|
|||||||
import emu.nebula.data.resources.DiscDef;
|
import emu.nebula.data.resources.DiscDef;
|
||||||
import emu.nebula.data.resources.SubNoteSkillPromoteGroupDef;
|
import emu.nebula.data.resources.SubNoteSkillPromoteGroupDef;
|
||||||
import emu.nebula.database.GameDatabaseObject;
|
import emu.nebula.database.GameDatabaseObject;
|
||||||
|
import emu.nebula.game.achievement.AchievementCondition;
|
||||||
import emu.nebula.game.inventory.ItemParamMap;
|
import emu.nebula.game.inventory.ItemParamMap;
|
||||||
import emu.nebula.game.player.Player;
|
import emu.nebula.game.player.Player;
|
||||||
import emu.nebula.game.player.PlayerChangeInfo;
|
import emu.nebula.game.player.PlayerChangeInfo;
|
||||||
@@ -70,6 +71,10 @@ public class GameDisc implements GameDatabaseObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMaster() {
|
||||||
|
return GameData.getItemDataTable().get(this.getDiscId()).getRarity() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
public void setLevel(int level) {
|
public void setLevel(int level) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
}
|
}
|
||||||
@@ -215,6 +220,9 @@ public class GameDisc implements GameDatabaseObject {
|
|||||||
// Save to database
|
// Save to database
|
||||||
this.save();
|
this.save();
|
||||||
|
|
||||||
|
// Trigger quest/achievement
|
||||||
|
this.getPlayer().trigger(AchievementCondition.DiscPromoteTotal, 1);
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
return change.setSuccess(true);
|
return change.setSuccess(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package emu.nebula.game.infinitytower;
|
|||||||
|
|
||||||
import emu.nebula.data.GameData;
|
import emu.nebula.data.GameData;
|
||||||
import emu.nebula.data.resources.InfinityTowerLevelDef;
|
import emu.nebula.data.resources.InfinityTowerLevelDef;
|
||||||
|
import emu.nebula.game.achievement.AchievementCondition;
|
||||||
import emu.nebula.game.player.Player;
|
import emu.nebula.game.player.Player;
|
||||||
import emu.nebula.game.player.PlayerChangeInfo;
|
import emu.nebula.game.player.PlayerChangeInfo;
|
||||||
import emu.nebula.game.player.PlayerManager;
|
import emu.nebula.game.player.PlayerManager;
|
||||||
@@ -75,6 +76,9 @@ public class InfinityTowerManager extends PlayerManager {
|
|||||||
// Log in player progress
|
// Log in player progress
|
||||||
this.getPlayer().getProgress().addInfinityArenaLog(this.getLevelId());
|
this.getPlayer().getProgress().addInfinityArenaLog(this.getLevelId());
|
||||||
|
|
||||||
|
// Trigger achievement
|
||||||
|
this.getPlayer().trigger(AchievementCondition.InfinityTowerClearSpecificFloor, 10, this.getLevelId(), 0);
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
return change.setSuccess(true);
|
return change.setSuccess(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,18 +193,7 @@ public class GameSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check handbook states
|
// Check handbook states
|
||||||
if (this.getPlayer().getCharacters().isUpdateCharHandbook()) {
|
this.getPlayer().getCharacters().checkPlayerState();
|
||||||
getPlayer().getCharacters().setUpdateCharHandbook(false);
|
|
||||||
getPlayer().addNextPackage(
|
|
||||||
NetMsgId.handbook_change_notify,
|
|
||||||
this.getPlayer().getCharacters().getCharacterHandbook());
|
|
||||||
}
|
|
||||||
if (this.getPlayer().getCharacters().isUpdateDiscHandbook()) {
|
|
||||||
getPlayer().getCharacters().setUpdateDiscHandbook(false);
|
|
||||||
getPlayer().addNextPackage(
|
|
||||||
NetMsgId.handbook_change_notify,
|
|
||||||
this.getPlayer().getCharacters().getDiscHandbook());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProtoMessage<?> addNextPackages(ProtoMessage<?> proto) {
|
private ProtoMessage<?> addNextPackages(ProtoMessage<?> proto) {
|
||||||
|
|||||||
Reference in New Issue
Block a user