Implement gacha banners (not newbie)

This commit is contained in:
Melledy
2025-11-01 04:17:44 -07:00
parent e9f991355a
commit 37b74c9b35
20 changed files with 697 additions and 40 deletions

View File

@@ -2,6 +2,7 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.GachaInformation.GachaInfo;
import emu.nebula.proto.GachaInformation.GachaInformationResp;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@@ -11,10 +12,23 @@ public class HandlerGachaInformationReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Build response
var rsp = GachaInformationResp.newInstance();
// TODO
for (var bannerInfo : session.getPlayer().getGachaManager().getBannerInfos()) {
var info = GachaInfo.newInstance()
.setId(bannerInfo.getBannerId())
.setGachaTotalTimes(bannerInfo.getTotal())
.setTotalTimes(bannerInfo.getTotal())
.setAupMissTimes(bannerInfo.getMissTimesA())
.setAMissTimes(bannerInfo.getMissTimesA())
.setReveFirstTenReward(true)
.setRecvGuaranteeReward(bannerInfo.isUsedGuarantee());
rsp.addInformation(info);
}
// Encode and send
return session.encodeMsg(NetMsgId.gacha_information_succeed_ack, rsp);
}

View File

@@ -2,7 +2,8 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.proto.GachaInformation.GachaInformationResp;
import emu.nebula.proto.GachaNewbieInfoOuterClass.GachaNewbieInfo;
import emu.nebula.proto.GachaNewbieInfoOuterClass.GachaNewbieInfoResp;
import emu.nebula.net.HandlerId;
import emu.nebula.net.GameSession;
@@ -11,7 +12,12 @@ public class HandlerGachaNewbieInfoReq extends NetHandler {
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
var rsp = GachaInformationResp.newInstance();
var rsp = GachaNewbieInfoResp.newInstance();
var info = GachaNewbieInfo.newInstance()
.setId(5)
.setReceive(true);
rsp.addList(info);
return session.encodeMsg(NetMsgId.gacha_newbie_info_succeed_ack, rsp);
}

View File

@@ -2,50 +2,51 @@ package emu.nebula.server.handlers;
import emu.nebula.net.NetHandler;
import emu.nebula.net.NetMsgId;
import emu.nebula.net.HandlerId;
import emu.nebula.Nebula;
import emu.nebula.net.GameSession;
import emu.nebula.proto.GachaSpin.GachaCard;
import emu.nebula.proto.GachaSpin.GachaSpinReq;
import emu.nebula.proto.GachaSpin.GachaSpinResp;
import emu.nebula.proto.Public.ItemTpl;
import emu.nebula.util.Utils;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import emu.nebula.net.HandlerId;
import emu.nebula.Nebula;
import emu.nebula.data.GameData;
import emu.nebula.net.GameSession;
@HandlerId(NetMsgId.gacha_spin_req)
public class HandlerGachaSpinReq extends NetHandler {
@SuppressWarnings("unused")
@Override
public byte[] handle(GameSession session, byte[] message) throws Exception {
// Parse request
var req = GachaSpinReq.parseFrom(message);
// Temp
var list = new IntArrayList();
// Do gacha
var result = Nebula.getGameContext().getGachaModule().spin(
session.getPlayer(),
req.getId(),
req.getMode()
);
for (var def : GameData.getCharacterDataTable()) {
if (def.getGrade() == 1 && def.isAvailable()) {
list.add(def.getId());
}
if (result == null) {
return session.encodeMsg(NetMsgId.gacha_spin_failed_ack);
}
// Build response
var rsp = GachaSpinResp.newInstance()
.setTime(Nebula.getCurrentTime());
.setTime(Nebula.getCurrentTime())
.setAMissTimes(result.getInfo().getMissTimesA())
.setAupMissTimes(result.getInfo().getMissTimesA())
.setTotalTimes(result.getInfo().getTotal())
.setGachaTotalTimes(result.getInfo().getTotal())
.setAupGuaranteeTimes(result.getInfo().isUsedGuarantee() ? 0 : 1)
.setChange(result.getChange().toProto());
rsp.getMutableChange();
rsp.getMutableNextPackage();
for (int i = 0; i < 10; i++) {
int id = Utils.randomElement(list);
for (int id : result.getCards()) {
var card = GachaCard.newInstance()
.setCard(ItemTpl.newInstance().setTid(id).setQty(1));
rsp.addCards(card);
}
// Encode and send response
return session.encodeMsg(NetMsgId.gacha_spin_succeed_ack, rsp);
}