mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 20:34:36 +01:00
Mark new vampire survivor cards
This commit is contained in:
@@ -218,7 +218,7 @@ public final class DatabaseManager {
|
||||
.update(opt, UpdateOperators.set(field, item));
|
||||
}
|
||||
|
||||
public void addToList(Object obj, int uid, String field, Object item) {
|
||||
public void addToSet(Object obj, int uid, String field, Object item) {
|
||||
var opt = new UpdateOptions().upsert(false);
|
||||
|
||||
getDatastore().find(obj.getClass())
|
||||
|
||||
@@ -146,7 +146,7 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
this.getExtraSkins().add(id);
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().addToList(this, this.getUid(), "extraSkins", id);
|
||||
Nebula.getGameDatabase().addToSet(this, this.getUid(), "extraSkins", id);
|
||||
|
||||
// Send packet
|
||||
this.getPlayer().addNextPackage(
|
||||
@@ -212,7 +212,7 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
this.getHeadIcons().add(id);
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().addToList(this, this.getUid(), "headIcons", id);
|
||||
Nebula.getGameDatabase().addToSet(this, this.getUid(), "headIcons", id);
|
||||
|
||||
// Success
|
||||
return true;
|
||||
@@ -228,7 +228,7 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
this.getTitles().add(id);
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().addToList(this, this.getUid(), "titles", id);
|
||||
Nebula.getGameDatabase().addToSet(this, this.getUid(), "titles", id);
|
||||
|
||||
// Success
|
||||
return true;
|
||||
@@ -244,7 +244,7 @@ public class Inventory extends PlayerManager implements GameDatabaseObject {
|
||||
this.getHonorList().add(id);
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().addToList(this, this.getUid(), "honorList", id);
|
||||
Nebula.getGameDatabase().addToSet(this, this.getUid(), "honorList", id);
|
||||
|
||||
// Success
|
||||
return true;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Mailbox extends PlayerManager implements GameDatabaseObject, Iterab
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().update(this, getUid(), "lastMailId", this.getLastMailId());
|
||||
Nebula.getGameDatabase().addToList(this, getUid(), "list", mail);
|
||||
Nebula.getGameDatabase().addToSet(this, getUid(), "list", mail);
|
||||
}
|
||||
|
||||
public boolean readMail(int id, long flag) {
|
||||
|
||||
@@ -86,7 +86,7 @@ public class PlayerProgress extends PlayerManager implements GameDatabaseObject
|
||||
|
||||
// Add & Save to database
|
||||
this.getStarTowerLog().add(id);
|
||||
Nebula.getGameDatabase().addToList(this, this.getUid(), "starTowerLog", id);
|
||||
Nebula.getGameDatabase().addToSet(this, this.getUid(), "starTowerLog", id);
|
||||
}
|
||||
|
||||
public void addInfinityArenaLog(int levelId) {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class StoryManager extends PlayerManager implements GameDatabaseObject {
|
||||
this.getPlayer().getInventory().addItems(data.getRewards(), changes);
|
||||
|
||||
// Save to db
|
||||
Nebula.getGameDatabase().addToList(this, this.getPlayerUid(), "completedStories", id);
|
||||
Nebula.getGameDatabase().addToSet(this, this.getPlayerUid(), "completedStories", id);
|
||||
}
|
||||
|
||||
return changes;
|
||||
|
||||
@@ -48,7 +48,11 @@ public class VampireSurvivorGame {
|
||||
public int getId() {
|
||||
return this.getData().getId();
|
||||
}
|
||||
|
||||
|
||||
public boolean isNewCard(int id) {
|
||||
return !this.getManager().getProgress().getVampireCards().contains(id);
|
||||
}
|
||||
|
||||
private void cacheRandomCards() {
|
||||
this.randomCards = new ObjectOpenHashSet<>();
|
||||
|
||||
@@ -88,6 +92,11 @@ public class VampireSurvivorGame {
|
||||
// Get random selector
|
||||
var random = this.getRandom();
|
||||
|
||||
// Sanity check
|
||||
if (random.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add 2 rewards
|
||||
this.getRewards().add(random.next().intValue());
|
||||
this.getRewards().add(random.next().intValue());
|
||||
@@ -148,12 +157,12 @@ public class VampireSurvivorGame {
|
||||
|
||||
for (int id : this.getRewards()) {
|
||||
var card = CardInfo.newInstance()
|
||||
.setId(id);
|
||||
.setId(id)
|
||||
.setNew(this.isNewCard(id));
|
||||
|
||||
pkg.addCards(card);
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package emu.nebula.game.vampire;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import emu.nebula.Nebula;
|
||||
import emu.nebula.data.GameData;
|
||||
import emu.nebula.game.player.Player;
|
||||
import emu.nebula.game.player.PlayerManager;
|
||||
import emu.nebula.game.player.PlayerProgress;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.proto.VampireTalentDetail.VampireTalentDetailResp;
|
||||
import emu.nebula.util.Bitset;
|
||||
import lombok.Getter;
|
||||
import us.hebi.quickbuf.RepeatedLong;
|
||||
@@ -68,6 +73,9 @@ public class VampireSurvivorManager extends PlayerManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save earned cards to the database
|
||||
this.updateSavedCards();
|
||||
|
||||
// Skip if we didn't win
|
||||
if (!isWin) {
|
||||
return;
|
||||
@@ -99,4 +107,33 @@ public class VampireSurvivorManager extends PlayerManager {
|
||||
this.game = null;
|
||||
}
|
||||
|
||||
private void updateSavedCards() {
|
||||
// Get new cards
|
||||
List<Integer> newCards = new ArrayList<>();
|
||||
|
||||
for (int card : game.getCards()) {
|
||||
if (this.getProgress().getVampireCards().contains(card)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.getProgress().getVampireCards().add(card);
|
||||
newCards.add(card);
|
||||
}
|
||||
|
||||
if (newCards.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Save to database
|
||||
Nebula.getGameDatabase().addToSet(this.getProgress(), this.getPlayerUid(), "vampireCards", newCards);
|
||||
|
||||
// Notify player
|
||||
this.getPlayer().addNextPackage(
|
||||
NetMsgId.vampire_survivor_talent_node_notify,
|
||||
VampireTalentDetailResp.newInstance()
|
||||
.setNodes(this.getTalents().toByteArray())
|
||||
.setActiveCount(this.getProgress().getVampireCards().size())
|
||||
.setObtainCount(newCards.size())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class HandlerVampireSurvivorRewardChestReq extends NetHandler {
|
||||
for (int cardId : chest) {
|
||||
var card = CardInfo.newInstance()
|
||||
.setId(cardId)
|
||||
.setNew(true);
|
||||
.setNew(game.isNewCard(cardId));
|
||||
|
||||
rsp.addChestCards(card);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public class HandlerVampireTalentDetailReq extends NetHandler {
|
||||
// Build response
|
||||
var rsp = VampireTalentDetailResp.newInstance()
|
||||
.setNodes(manager.getTalents().toByteArray())
|
||||
.setActiveCount(manager.getTalentPoints());
|
||||
.setActiveCount(manager.getProgress().getVampireCards().size());
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.vampire_talent_detail_succeed_ack, rsp);
|
||||
|
||||
Reference in New Issue
Block a user