mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-23 10:44:36 +01:00
Implement enabling rogue talents
This commit is contained in:
@@ -38,6 +38,7 @@ import emu.lunarcore.game.scene.triggers.PropTriggerType;
|
||||
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
||||
import emu.lunarcore.proto.RogueVirtualItemInfoOuterClass.RogueVirtualItemInfo;
|
||||
import emu.lunarcore.server.game.GameServer;
|
||||
import emu.lunarcore.server.game.GameSession;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
@@ -45,6 +46,7 @@ import emu.lunarcore.server.packet.SessionState;
|
||||
import emu.lunarcore.server.packet.send.PacketEnterSceneByServerScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketPlayerSyncScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketSceneEntityMoveScNotify;
|
||||
import emu.lunarcore.server.packet.send.PacketSyncRogueVirtualItemInfoScNotify;
|
||||
import emu.lunarcore.util.Position;
|
||||
|
||||
import lombok.Getter;
|
||||
@@ -303,6 +305,7 @@ public class Player {
|
||||
|
||||
public void addTalentPoints(int amount) {
|
||||
this.talentPoints += amount;
|
||||
this.sendPacket(new PacketSyncRogueVirtualItemInfoScNotify(this));
|
||||
}
|
||||
|
||||
public void addStamina(int amount) {
|
||||
@@ -548,7 +551,8 @@ public class Player {
|
||||
this.getInventory().loadFromDatabase();
|
||||
this.getMailbox().loadFromDatabase();
|
||||
this.getChallengeManager().loadFromDatabase();
|
||||
|
||||
this.getRogueManager().loadFromDatabase();
|
||||
|
||||
// Load Etc
|
||||
this.getLineupManager().validate(this);
|
||||
this.getAvatars().setupHeroPaths();
|
||||
@@ -588,4 +592,11 @@ public class Player {
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
public RogueVirtualItemInfo toRogueVirtualItemsProto() {
|
||||
var proto = RogueVirtualItemInfo.newInstance()
|
||||
.setRogueTalentPoints(this.getTalentPoints());
|
||||
|
||||
return proto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import emu.lunarcore.GameConstants;
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.GameDepot;
|
||||
import emu.lunarcore.data.excel.RogueTalentExcel;
|
||||
import emu.lunarcore.game.player.BasePlayerManager;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.game.player.PlayerLineup;
|
||||
@@ -17,15 +19,53 @@ import emu.lunarcore.proto.RogueInfoDataOuterClass.RogueInfoData;
|
||||
import emu.lunarcore.proto.RogueInfoOuterClass.RogueInfo;
|
||||
import emu.lunarcore.proto.RogueScoreRewardInfoOuterClass.RogueScoreRewardInfo;
|
||||
import emu.lunarcore.proto.RogueSeasonInfoOuterClass.RogueSeasonInfo;
|
||||
import emu.lunarcore.proto.RogueTalentInfoOuterClass.RogueTalentInfo;
|
||||
import emu.lunarcore.proto.RogueTalentOuterClass.RogueTalent;
|
||||
import emu.lunarcore.proto.RogueTalentStatusOuterClass.RogueTalentStatus;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
import emu.lunarcore.server.packet.send.PacketStartRogueScRsp;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import lombok.Getter;
|
||||
import us.hebi.quickbuf.RepeatedInt;
|
||||
|
||||
@Getter
|
||||
public class RogueManager extends BasePlayerManager {
|
||||
private IntSet talents;
|
||||
|
||||
public RogueManager(Player player) {
|
||||
super(player);
|
||||
this.talents = new IntOpenHashSet();
|
||||
}
|
||||
|
||||
public boolean hasTalent(int talentId) {
|
||||
return this.getTalents().contains(talentId);
|
||||
}
|
||||
|
||||
public boolean enableTalent(int talentId) {
|
||||
// Sanity check so we dont enable the same talent
|
||||
if (this.getTalents().contains(talentId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get talent excel
|
||||
RogueTalentExcel excel = GameData.getRogueTalentExcelMap().get(talentId);
|
||||
if (excel == null) return false;
|
||||
|
||||
// Verify items
|
||||
if (!getPlayer().getInventory().verifyItems(excel.getCost())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pay items
|
||||
getPlayer().getInventory().removeItemsByParams(excel.getCost());
|
||||
|
||||
// Add talent
|
||||
RogueTalentData talent = new RogueTalentData(getPlayer(), excel.getTalentID());
|
||||
talent.save();
|
||||
|
||||
return getTalents().add(talentId);
|
||||
}
|
||||
|
||||
public void startRogue(int areaId, int aeonId, RepeatedInt avatarIdList) {
|
||||
@@ -133,26 +173,24 @@ public class RogueManager extends BasePlayerManager {
|
||||
.setRogueScoreInfo(score)
|
||||
.setRogueAeonInfo(aeonInfo)
|
||||
.setRogueData(data)
|
||||
.setRogueVirtualItemInfo(getPlayer().toRogueVirtualItemsProto())
|
||||
.setTalentPoints(getPlayer().getTalentPoints())
|
||||
.setSeasonId(seasonId)
|
||||
.setBeginTime(beginTime)
|
||||
.setEndTime(endTime);
|
||||
|
||||
proto.getMutableRogueVirtualItems()
|
||||
.setRogueTalentPoints(getPlayer().getTalentPoints());
|
||||
|
||||
// Rogue data
|
||||
RogueInstance curRogue = this.getPlayer().getRogueInstance();
|
||||
if (curRogue != null) {
|
||||
proto.setStatus(curRogue.getStatus());
|
||||
RogueInstance instance = this.getPlayer().getRogueInstance();
|
||||
if (instance != null) {
|
||||
proto.setStatus(instance.getStatus());
|
||||
proto.setRogueProgress(this.getPlayer().getRogueInstance().toProto());
|
||||
proto.setRoomMap(proto.getRogueProgress().getRoomMap());
|
||||
|
||||
for (int id : curRogue.getBaseAvatarIds()) {
|
||||
for (int id : instance.getBaseAvatarIds()) {
|
||||
proto.addBaseAvatarIdList(id);
|
||||
}
|
||||
|
||||
aeonInfo.setSelectedAeonId(curRogue.getAeonId());
|
||||
aeonInfo.setSelectedAeonId(instance.getAeonId());
|
||||
}
|
||||
|
||||
// Add areas
|
||||
@@ -165,10 +203,10 @@ public class RogueManager extends BasePlayerManager {
|
||||
.setAreaId(excel.getRogueAreaID())
|
||||
.setRogueAreaStatus(RogueAreaStatus.ROGUE_AREA_STATUS_FIRST_PASS);
|
||||
|
||||
if (curRogue != null && excel == curRogue.getExcel()) {
|
||||
area.setMapId(curRogue.getExcel().getMapId());
|
||||
area.setCurReachRoomNum(curRogue.getCurrentRoomProgress());
|
||||
area.setRogueStatus(curRogue.getStatus());
|
||||
if (instance != null && excel == instance.getExcel()) {
|
||||
area.setMapId(instance.getExcel().getMapId());
|
||||
area.setCurReachRoomNum(instance.getCurrentRoomProgress());
|
||||
area.setRogueStatus(instance.getStatus());
|
||||
}
|
||||
|
||||
proto.addRogueAreaList(area);
|
||||
@@ -177,4 +215,34 @@ public class RogueManager extends BasePlayerManager {
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
public RogueTalentInfo toTalentInfoProto() {
|
||||
var proto = RogueTalentInfo.newInstance();
|
||||
|
||||
for (RogueTalentExcel excel : GameData.getRogueTalentExcelMap().values()) {
|
||||
var talent = RogueTalent.newInstance()
|
||||
.setTalentId(excel.getTalentID());
|
||||
|
||||
if (this.hasTalent(excel.getTalentID())) {
|
||||
talent.setStatus(RogueTalentStatus.ROGUE_TALENT_STATUS_ENABLE);
|
||||
} else {
|
||||
talent.setStatus(RogueTalentStatus.ROGUE_TALENT_STATUS_UNLOCK);
|
||||
}
|
||||
|
||||
proto.addRogueTalent(talent);
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
// Database
|
||||
|
||||
public void loadFromDatabase() {
|
||||
// Load talent data
|
||||
var stream = LunarCore.getGameDatabase().getObjects(RogueTalentData.class, "ownerUid", this.getPlayer().getUid());
|
||||
|
||||
stream.forEach(talent -> {
|
||||
this.getTalents().add(talent.getTalentId());
|
||||
});
|
||||
}
|
||||
}
|
||||
33
src/main/java/emu/lunarcore/game/rogue/RogueTalentData.java
Normal file
33
src/main/java/emu/lunarcore/game/rogue/RogueTalentData.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package emu.lunarcore.game.rogue;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import emu.lunarcore.LunarCore;
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Entity(value = "rogueTalents", useDiscriminator = false)
|
||||
public class RogueTalentData {
|
||||
@Id
|
||||
private ObjectId id;
|
||||
|
||||
@Indexed
|
||||
private int ownerUid;
|
||||
private int talentId;
|
||||
|
||||
@Deprecated // Morphia only
|
||||
public RogueTalentData() {}
|
||||
|
||||
public RogueTalentData(Player player, int talentId) {
|
||||
this.ownerUid = player.getUid();
|
||||
this.talentId = talentId;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
LunarCore.getGameDatabase().save(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package emu.lunarcore.server.packet.recv;
|
||||
|
||||
import emu.lunarcore.proto.EnableRogueTalentCsReqOuterClass.EnableRogueTalentCsReq;
|
||||
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.PacketEnableRogueTalentScRsp;
|
||||
|
||||
@Opcodes(CmdId.EnableRogueTalentCsReq)
|
||||
public class HandlerEnableRogueTalentCsReq extends PacketHandler {
|
||||
|
||||
@Override
|
||||
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||
var req = EnableRogueTalentCsReq.parseFrom(data);
|
||||
|
||||
if (session.getPlayer().getRogueManager().enableTalent(req.getTalentId())) {
|
||||
session.send(new PacketEnableRogueTalentScRsp(session.getPlayer().getRogueManager()));
|
||||
} else {
|
||||
session.send(new PacketEnableRogueTalentScRsp());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.rogue.RogueManager;
|
||||
import emu.lunarcore.proto.EnableRogueTalentScRspOuterClass.EnableRogueTalentScRsp;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketEnableRogueTalentScRsp extends BasePacket {
|
||||
|
||||
public PacketEnableRogueTalentScRsp() {
|
||||
super(CmdId.EnableRogueTalentScRsp);
|
||||
|
||||
var data = EnableRogueTalentScRsp.newInstance()
|
||||
.setRetcode(1);
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
public PacketEnableRogueTalentScRsp(RogueManager rogueManager) {
|
||||
super(CmdId.EnableRogueTalentScRsp);
|
||||
|
||||
var data = EnableRogueTalentScRsp.newInstance()
|
||||
.setTalentInfo(rogueManager.toTalentInfoProto());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,7 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.data.GameData;
|
||||
import emu.lunarcore.data.excel.RogueTalentExcel;
|
||||
import emu.lunarcore.game.rogue.RogueManager;
|
||||
import emu.lunarcore.proto.GetRogueTalentInfoScRspOuterClass.GetRogueTalentInfoScRsp;
|
||||
import emu.lunarcore.proto.RogueTalentOuterClass.RogueTalent;
|
||||
import emu.lunarcore.proto.RogueTalentStatusOuterClass.RogueTalentStatus;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
@@ -14,15 +10,8 @@ public class PacketGetRogueTalentInfoScRsp extends BasePacket {
|
||||
public PacketGetRogueTalentInfoScRsp(RogueManager rogueManager) {
|
||||
super(CmdId.GetRogueTalentInfoScRsp);
|
||||
|
||||
var data = GetRogueTalentInfoScRsp.newInstance();
|
||||
|
||||
for (RogueTalentExcel excel : GameData.getRogueTalentExcelMap().values()) {
|
||||
var talent = RogueTalent.newInstance()
|
||||
.setTalentId(excel.getTalentID())
|
||||
.setStatus(RogueTalentStatus.ROGUE_TALENT_STATUS_UNLOCK);
|
||||
|
||||
data.getMutableTalentInfo().addRogueTalent(talent);
|
||||
}
|
||||
var data = GetRogueTalentInfoScRsp.newInstance()
|
||||
.setTalentInfo(rogueManager.toTalentInfoProto());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package emu.lunarcore.server.packet.send;
|
||||
|
||||
import emu.lunarcore.game.player.Player;
|
||||
import emu.lunarcore.proto.SyncRogueVirtualItemInfoScNotifyOuterClass.SyncRogueVirtualItemInfoScNotify;
|
||||
import emu.lunarcore.server.packet.BasePacket;
|
||||
import emu.lunarcore.server.packet.CmdId;
|
||||
|
||||
public class PacketSyncRogueVirtualItemInfoScNotify extends BasePacket {
|
||||
|
||||
public PacketSyncRogueVirtualItemInfoScNotify(Player player) {
|
||||
super(CmdId.SyncRogueVirtualItemInfoScNotify);
|
||||
|
||||
var data = SyncRogueVirtualItemInfoScNotify.newInstance()
|
||||
.setRogueVirtualItemInfo(player.toRogueVirtualItemsProto());
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user