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