mirror of
https://github.com/Melledy/Nebula.git
synced 2025-12-12 12:24:35 +01:00
Implement daily shop reward
This commit is contained in:
@@ -485,6 +485,7 @@ public class Player implements GameDatabaseObject {
|
||||
public PlayerInfo toProto() {
|
||||
PlayerInfo proto = PlayerInfo.newInstance()
|
||||
.setServerTs(Nebula.getCurrentTime())
|
||||
.setDailyShopRewardStatus(this.getQuestManager().hasDailyReward())
|
||||
.setAchievements(new byte[64]);
|
||||
|
||||
var acc = proto.getMutableAcc()
|
||||
|
||||
@@ -19,6 +19,7 @@ import emu.nebula.util.Bitset;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@@ -37,6 +38,9 @@ public class QuestManager extends PlayerManager implements GameDatabaseObject {
|
||||
// Level rewards
|
||||
private Bitset levelRewards;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private boolean hasDailyReward;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public QuestManager() {
|
||||
|
||||
@@ -48,12 +52,17 @@ public class QuestManager extends PlayerManager implements GameDatabaseObject {
|
||||
this.claimedActiveIds = new IntOpenHashSet();
|
||||
this.quests = new HashMap<>();
|
||||
this.levelRewards = new Bitset();
|
||||
this.hasDailyReward = true;
|
||||
|
||||
this.resetDailyQuests();
|
||||
|
||||
this.save();
|
||||
}
|
||||
|
||||
public boolean hasDailyReward() {
|
||||
return this.hasDailyReward;
|
||||
}
|
||||
|
||||
public void saveLevelRewards() {
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "levelRewards", this.levelRewards);
|
||||
}
|
||||
@@ -75,6 +84,8 @@ public class QuestManager extends PlayerManager implements GameDatabaseObject {
|
||||
this.activity = 0;
|
||||
this.claimedActiveIds.clear();
|
||||
|
||||
this.hasDailyReward = true;
|
||||
|
||||
// Persist to database
|
||||
this.save();
|
||||
}
|
||||
@@ -252,4 +263,27 @@ public class QuestManager extends PlayerManager implements GameDatabaseObject {
|
||||
quest.toProto()
|
||||
);
|
||||
}
|
||||
|
||||
// Daily reward
|
||||
|
||||
public PlayerChangeInfo claimDailyReward() {
|
||||
// Sanity check
|
||||
if (!this.hasDailyReward) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Daily shop reward
|
||||
// TODO randomize
|
||||
var change = this.getPlayer().getInventory().addItem(1, 8888);
|
||||
|
||||
// Set and update in database
|
||||
this.hasDailyReward = false;
|
||||
Nebula.getGameDatabase().update(this, this.getUid(), "hasDailyReward", this.hasDailyReward);
|
||||
|
||||
// Trigger quest
|
||||
this.triggerQuest(QuestCondType.DailyShopReceiveShopTotal, 1);
|
||||
|
||||
// Success
|
||||
return change.setSuccess(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package emu.nebula.server.handlers;
|
||||
|
||||
import emu.nebula.net.NetHandler;
|
||||
import emu.nebula.net.NetMsgId;
|
||||
import emu.nebula.net.HandlerId;
|
||||
import emu.nebula.net.GameSession;
|
||||
|
||||
@HandlerId(NetMsgId.daily_shop_reward_receive_req)
|
||||
public class HandlerDailyShopRewardReceiveReq extends NetHandler {
|
||||
|
||||
@Override
|
||||
public byte[] handle(GameSession session, byte[] message) throws Exception {
|
||||
// Claim daily reward
|
||||
var change = session.getPlayer().getQuestManager().claimDailyReward();
|
||||
|
||||
if (change == null) {
|
||||
return session.encodeMsg(NetMsgId.daily_shop_reward_receive_failed_ack);
|
||||
}
|
||||
|
||||
// Encode and send
|
||||
return session.encodeMsg(NetMsgId.daily_shop_reward_receive_succeed_ack, change.toProto());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user