Fix standard banner display and handle gacha ceiling exchange properly

This commit is contained in:
Melledy
2023-11-27 22:19:36 -08:00
parent 94af07d498
commit 29e5b130d3
17 changed files with 1403 additions and 194 deletions

View File

@@ -33,6 +33,9 @@ public class GameConstants {
public static final int MATERIAL_COIN_ID = 2; // Material id for credits. DO NOT CHANGE
public static final int TRAILBLAZER_EXP_ID = 22;
// Gacha
public static final int GACHA_CEILING_MAX = 300; // Yes, I know this is in an excel
// Challenge
public static final int CHALLENGE_ENTRANCE = 100000103;

View File

@@ -1,7 +1,6 @@
package emu.lunarcore.game.gacha;
import emu.lunarcore.proto.GachaCeilingOuterClass.GachaCeiling;
import emu.lunarcore.proto.GachaCeilingAvatarOuterClass.GachaCeilingAvatar;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.GachaInfoOuterClass.GachaInfo;
import lombok.Getter;
@@ -14,53 +13,36 @@ public class GachaBanner {
private int[] rateUpItems5;
private int[] rateUpItems4;
private int eventChance = 50;
private GachaCeiling gachaCeiling;
private GachaCeilingAvatar createCeilingAvatarInfo(int avatarId) {
return GachaCeilingAvatar.newInstance()
.setRepeatedCnt(1)
.setAvatarId(avatarId);
}
public GachaInfo toProto() {
public GachaInfo toProto(GachaService service, Player player) {
var info = GachaInfo.newInstance()
.setGachaId(this.getId())
.setDetailUrl("")
.setHistoryUrl("");
if (this.gachaType == GachaType.Normal) {
// Gacha ceiling
info.setGachaCeiling(GachaCeiling.newInstance());
} else {
if (this.gachaType != GachaType.Normal) {
info.setBeginTime(this.getBeginTime());
info.setEndTime(this.getEndTime());
}
if (this.getRateUpItems4().length > 0) {
for (int id : getRateUpItems4()) {
info.addUpInfo(id);
}
}
if (this.getRateUpItems5().length > 0) {
for (int id : getRateUpItems5()) {
info.addUpInfo(id);
info.addFeatured(id);
}
}
if (this.getId() == 1001) {
GachaCeilingAvatar ceilingavatarinfo1 = createCeilingAvatarInfo(1003);
GachaCeilingAvatar ceilingavatarinfo2 = createCeilingAvatarInfo(1107);
GachaCeilingAvatar ceilingavatarinfo3 = createCeilingAvatarInfo(1211);
info.setGachaCeiling(player.getGachaInfo().toGachaCeiling(player));
info.addAllUpInfo(service.getPurpleAvatars());
info.addAllUpInfo(service.getYellowAvatars());
info.addAllUpInfo(service.getPurpleWeapons());
info.addAllUpInfo(service.getYellowWeapons());
info.addAllFeatured(service.getDefaultFeaturedIds());
} else {
if (this.getRateUpItems4().length > 0) {
info.addAllUpInfo(getRateUpItems4());
}
GachaCeiling ceilinginfo = GachaCeiling.newInstance()
.addAvatarList(ceilingavatarinfo1)
.addAvatarList(ceilingavatarinfo2)
.addAvatarList(ceilingavatarinfo3)
.setCeilingNum(169);
info.setGachaCeiling(ceilinginfo);
if (this.getRateUpItems5().length > 0) {
info.addAllUpInfo(getRateUpItems5());
info.addAllFeatured(getRateUpItems5());
}
}
return info;

View File

@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import emu.lunarcore.GameConstants;
import emu.lunarcore.LunarCore;
import emu.lunarcore.data.GameData;
import emu.lunarcore.data.excel.ItemExcel;
@@ -21,21 +22,25 @@ import emu.lunarcore.server.game.BaseGameService;
import emu.lunarcore.server.game.GameServer;
import emu.lunarcore.server.packet.send.PacketDoGachaScRsp;
import emu.lunarcore.util.JsonUtils;
import emu.lunarcore.util.Utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import lombok.Getter;
@Getter
public class GachaService extends BaseGameService {
private final Int2ObjectMap<GachaBanner> gachaBanners;
private GetGachaInfoScRsp cachedProto;
private int[] yellowAvatars = new int[] {1003, 1004, 1101, 1107, 1104, 1209, 1211};
private int[] yellowWeapons = new int[] {23000, 23002, 23003, 23004, 23005, 23012, 23013};
private int[] purpleAvatars = new int[] {1001, 1002, 1008, 1009, 1013, 1103, 1105, 1106, 1108, 1109, 1111, 1201, 1202, 1206, 1207};
private int[] purpleAvatars = new int[] {1001, 1002, 1008, 1009, 1013, 1103, 1105, 1106, 1108, 1109, 1110, 1111, 1201, 1202, 1206, 1207, 1210};
private int[] purpleWeapons = new int[] {21000, 21001, 21002, 21003, 21004, 21005, 21006, 21007, 21008, 21009, 21010, 21011, 21012, 21013, 21014, 21015, 21016, 21017, 21018, 21019, 21020};
private int[] blueWeapons = new int[] {20000, 20001, 20002, 20003, 20004, 20005, 20006, 20007, 20008, 20009, 20010, 20011, 20012, 20013, 20014, 20015, 20016, 20017, 20018, 20019, 20020};
private int[] defaultFeaturedIds = new int[] {23002, 1003, 1101, 1104, 23000, 23003};
private static int starglightId = 252;
private static int embersId = 251;
@@ -45,10 +50,6 @@ public class GachaService extends BaseGameService {
this.load();
}
public Int2ObjectMap<GachaBanner> getGachaBanners() {
return gachaBanners;
}
public int randomRange(int min, int max) {
return ThreadLocalRandom.current().nextInt(max - min + 1) + min;
}
@@ -69,10 +70,9 @@ public class GachaService extends BaseGameService {
}
public synchronized void doPulls(Player player, int gachaId, int times) {
// Sanity check
if (times != 10 && times != 1) {
return;
}
// Sanity checks
if (times != 10 && times != 1) return;
if (player.getInventory().getInventoryTab(ItemMainType.Equipment).getSize() + times > player.getInventory().getInventoryTab(ItemMainType.Equipment).getMaxCapacity()) {
player.sendPacket(new PacketDoGachaScRsp());
return;
@@ -94,6 +94,12 @@ public class GachaService extends BaseGameService {
player.getInventory().removeItem(costItem, times);
}
// Add gacha ceiling
if (banner.getGachaType() == GachaType.Normal || banner.getGachaType() == GachaType.Newbie) {
player.getGachaInfo().addCeilingNum(times);
player.save();
}
// Roll
PlayerGachaBannerInfo gachaInfo = player.getGachaInfo().getBannerInfo(banner.getGachaType());
@@ -255,24 +261,44 @@ public class GachaService extends BaseGameService {
}
// Packets
player.sendPacket(new PacketDoGachaScRsp(banner, times, list));
player.sendPacket(new PacketDoGachaScRsp(player, banner, times, list));
}
public List<GameItem> exchangeGachaCeiling(Player player, int avatarId) {
// Sanity check
if (player.getGachaInfo().getCeilingNum() < GameConstants.GACHA_CEILING_MAX || player.getGachaInfo().isCeilingClaimed()) {
return null;
}
// Make sure the player is getting a valid avatar
if (!Utils.arrayContains(this.getYellowAvatars(), avatarId)) {
return null;
}
// Add items
List<GameItem> items = new ArrayList<>();
if (player.getAvatars().hasAvatar(avatarId)) {
// Add eidolon if player already has the avatar
items.add(new GameItem(avatarId + 10000));
} else {
items.add(new GameItem(avatarId));
}
player.getInventory().addItems(items);
player.getGachaInfo().setCeilingClaimed(true);
player.save();
return items;
}
private synchronized GetGachaInfoScRsp createProto() {
public synchronized GetGachaInfoScRsp toProto(Player player) {
var proto = GetGachaInfoScRsp.newInstance();
for (GachaBanner banner : getGachaBanners().values()) {
proto.addGachaInfoList(banner.toProto());
proto.addGachaInfoList(banner.toProto(this, player));
}
return proto;
}
public GetGachaInfoScRsp toProto() {
if (this.cachedProto == null) {
this.cachedProto = createProto();
}
return this.cachedProto;
}
}

View File

@@ -4,16 +4,19 @@ import lombok.Getter;
@Getter
public enum GachaType {
Newbie (101, 1, 2),
Normal (101, 1, 2),
AvatarUp (102, 1, 1),
WeaponUp (102, 2, 2);
Unknown (0, 0, 0, 0),
Newbie (1, 101, 1, 2),
Normal (2, 101, 1, 2),
AvatarUp (11, 102, 1, 1),
WeaponUp (12, 102, 2, 2);
private int id;
private int costItem;
private int minItemType;
private int maxItemType;
private GachaType(int costItem, int min, int max) {
private GachaType(int id, int costItem, int min, int max) {
this.id = id;
this.costItem = costItem;
this.minItemType = min;
this.maxItemType = max;

View File

@@ -1,29 +1,31 @@
package emu.lunarcore.game.gacha;
import dev.morphia.annotations.Entity;
import emu.lunarcore.GameConstants;
import emu.lunarcore.game.avatar.GameAvatar;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.GachaCeilingAvatarOuterClass.GachaCeilingAvatar;
import emu.lunarcore.proto.GachaCeilingOuterClass.GachaCeiling;
import lombok.Getter;
import lombok.Setter;
@Entity(useDiscriminator = false)
@Getter @Entity(useDiscriminator = false)
public class PlayerGachaInfo {
private PlayerGachaBannerInfo standardBanner;
private PlayerGachaBannerInfo eventCharacterBanner;
private PlayerGachaBannerInfo eventWeaponBanner;
private int ceilingNum;
@Setter private boolean ceilingClaimed;
public PlayerGachaInfo() {
this.standardBanner = new PlayerGachaBannerInfo();
this.eventCharacterBanner = new PlayerGachaBannerInfo();
this.eventWeaponBanner = new PlayerGachaBannerInfo();
}
public PlayerGachaBannerInfo getStandardBanner() {
return standardBanner;
}
public PlayerGachaBannerInfo getEventCharacterBanner() {
return eventCharacterBanner;
}
public PlayerGachaBannerInfo getEventWeaponBanner() {
return eventWeaponBanner;
public void addCeilingNum(int amount) {
this.ceilingNum = Math.min(ceilingNum + amount, GameConstants.GACHA_CEILING_MAX);
}
public PlayerGachaBannerInfo getBannerInfo(GachaType type) {
@@ -35,4 +37,30 @@ public class PlayerGachaInfo {
return this.standardBanner;
}
public GachaCeiling toGachaCeiling(Player player) {
var proto = GachaCeiling.newInstance()
.setIsClaimed(this.isCeilingClaimed())
.setCeilingNum(this.getCeilingNum());
// Gacha ceiling avatars are the avatars that we can pick
var ceilingAvatars = player.getServer().getGachaService().getYellowAvatars();
for (int i = 0; i < ceilingAvatars.length; i++) {
int avatarId = ceilingAvatars[i];
int repeatedCount = 0; // Eidolon count
GameAvatar avatar = player.getAvatarById(avatarId);
if (avatar != null) {
repeatedCount = avatar.getRank();
}
var ceilingAvatar = GachaCeilingAvatar.newInstance()
.setRepeatedCnt(repeatedCount)
.setAvatarId(avatarId);
proto.addAvatarList(ceilingAvatar);
}
return proto;
}
}

View File

@@ -0,0 +1,21 @@
package emu.lunarcore.server.packet.recv;
import emu.lunarcore.proto.ExchangeGachaCeilingCsReqOuterClass.ExchangeGachaCeilingCsReq;
import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.CmdId;
import emu.lunarcore.server.packet.Opcodes;
import emu.lunarcore.server.packet.PacketHandler;
import emu.lunarcore.server.packet.send.PacketExchangeGachaCeilingScRsp;
@Opcodes(CmdId.ExchangeGachaCeilingCsReq)
public class HandlerExchangeGachaCeilingCsReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] data) throws Exception {
var req = ExchangeGachaCeilingCsReq.parseFrom(data);
var items = session.getServer().getGachaService().exchangeGachaCeiling(session.getPlayer(), req.getAvatarId());
session.send(new PacketExchangeGachaCeilingScRsp(session.getPlayer(), req.getGachaType(), req.getAvatarId(), items));
}
}

View File

@@ -5,15 +5,13 @@ import emu.lunarcore.server.packet.CmdId;
import emu.lunarcore.server.packet.Opcodes;
import emu.lunarcore.server.packet.PacketHandler;
import emu.lunarcore.server.packet.send.PacketGetGachaCeilingScRsp;
import emu.lunarcore.proto.GetGachaCeilingCsReqOuterClass.GetGachaCeilingCsReq;
@Opcodes(CmdId.GetGachaCeilingCsReq)
public class HandlerGetGachaCeilingCsReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] data) throws Exception {
var req = GetGachaCeilingCsReq.parseFrom(data);
session.send(new PacketGetGachaCeilingScRsp(req.getUnkfield()));
session.send(new PacketGetGachaCeilingScRsp(session.getPlayer()));
}
}

View File

@@ -3,6 +3,7 @@ package emu.lunarcore.server.packet.send;
import java.util.List;
import emu.lunarcore.game.gacha.GachaBanner;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.DoGachaScRspOuterClass.DoGachaScRsp;
import emu.lunarcore.proto.GachaItemOuterClass.GachaItem;
import emu.lunarcore.server.packet.BasePacket;
@@ -16,11 +17,12 @@ public class PacketDoGachaScRsp extends BasePacket {
this.setData(DoGachaScRsp.newInstance().setRetcode(1));
}
public PacketDoGachaScRsp(GachaBanner banner, int num, List<GachaItem> items) {
public PacketDoGachaScRsp(Player player, GachaBanner banner, int num, List<GachaItem> items) {
super(CmdId.DoGachaScRsp);
var data = DoGachaScRsp.newInstance()
.setGachaNum(num)
.setCeilingNum(player.getGachaInfo().getCeilingNum())
.setGachaId(banner.getId());
for (GachaItem item : items) {

View File

@@ -0,0 +1,32 @@
package emu.lunarcore.server.packet.send;
import java.util.Collection;
import emu.lunarcore.game.inventory.GameItem;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.ExchangeGachaCeilingScRspOuterClass.ExchangeGachaCeilingScRsp;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId;
public class PacketExchangeGachaCeilingScRsp extends BasePacket {
public PacketExchangeGachaCeilingScRsp(Player player, int gachaType, int avatarId, Collection<GameItem> items) {
super(CmdId.ExchangeGachaCeilingScRsp);
var data = ExchangeGachaCeilingScRsp.newInstance();
if (items == null) {
data.setRetcode(1);
} else {
data.setGachaCeiling(player.getGachaInfo().toGachaCeiling(player));
data.setGachaType(gachaType);
data.setAvatarId(avatarId);
for (var item : items) {
data.getMutableTransferItemList().addItemList(item.toProto());
}
}
this.setData(data);
}
}

View File

@@ -1,37 +1,20 @@
package emu.lunarcore.server.packet.send;
import emu.lunarcore.server.packet.CmdId;
import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.proto.GachaCeilingOuterClass.GachaCeiling;
import emu.lunarcore.proto.GachaCeilingAvatarOuterClass.GachaCeilingAvatar;
import emu.lunarcore.game.gacha.GachaType;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.GetGachaCeilingScRspOuterClass.GetGachaCeilingScRsp;
public class PacketGetGachaCeilingScRsp extends BasePacket {
private GachaCeilingAvatar createCeilingAvatarInfo(int avatarId) {
return GachaCeilingAvatar.newInstance()
.setRepeatedCnt(1)
.setAvatarId(avatarId);
}
public PacketGetGachaCeilingScRsp(int unkfield) {
public PacketGetGachaCeilingScRsp(Player player) {
super(CmdId.GetGachaCeilingScRsp);
GachaCeilingAvatar ceilingavatarinfo1 = createCeilingAvatarInfo(1003);
GachaCeilingAvatar ceilingavatarinfo2 = createCeilingAvatarInfo(1107);
GachaCeilingAvatar ceilingavatarinfo3 = createCeilingAvatarInfo(1211);
GachaCeiling gachaceiling = GachaCeiling.newInstance()
.addAvatarList(ceilingavatarinfo1)
.addAvatarList(ceilingavatarinfo2)
.addAvatarList(ceilingavatarinfo3)
.setCeilingNum(169);
var proto = GetGachaCeilingScRsp.newInstance()
.setGachaCeiling(gachaceiling)
.setUnkfield(unkfield);
.setGachaType(GachaType.Normal.getId())
.setGachaCeiling(player.getGachaInfo().toGachaCeiling(player));
this.setData(proto);
}
}

View File

@@ -9,6 +9,6 @@ public class PacketGetGachaInfoScRsp extends BasePacket {
public PacketGetGachaInfoScRsp(GameSession session) {
super(CmdId.GetGachaInfoScRsp);
this.setData(session.getServer().getGachaService().toProto());
this.setData(session.getServer().getGachaService().toProto(session.getPlayer()));
}
}