mirror of
https://github.com/Melledy/LunarCore.git
synced 2026-02-04 06:55:05 +01:00
Implement head icons
This commit is contained in:
@@ -118,6 +118,7 @@ public class Inventory extends BasePlayerManager {
|
|||||||
|
|
||||||
// Add item to inventory store
|
// Add item to inventory store
|
||||||
ItemMainType type = item.getExcel().getItemMainType();
|
ItemMainType type = item.getExcel().getItemMainType();
|
||||||
|
ItemSubType subType = item.getExcel().getItemSubType();
|
||||||
InventoryTab tab = getInventoryTab(type);
|
InventoryTab tab = getInventoryTab(type);
|
||||||
|
|
||||||
// Add
|
// Add
|
||||||
@@ -145,6 +146,12 @@ public class Inventory extends BasePlayerManager {
|
|||||||
getPlayer().addAvatar(new GameAvatar(avatarExcel));
|
getPlayer().addAvatar(new GameAvatar(avatarExcel));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
case Usable:
|
||||||
|
if (subType == ItemSubType.HeadIcon) {
|
||||||
|
getPlayer().addHeadIcon(item.getItemId());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
case Material:
|
case Material:
|
||||||
switch (item.getExcel().getItemSubType()) {
|
switch (item.getExcel().getItemSubType()) {
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package emu.lunarcore.game.player;
|
package emu.lunarcore.game.player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
import dev.morphia.annotations.Id;
|
import dev.morphia.annotations.Id;
|
||||||
import dev.morphia.annotations.Indexed;
|
import dev.morphia.annotations.Indexed;
|
||||||
@@ -20,6 +23,8 @@ import emu.lunarcore.game.battle.Battle;
|
|||||||
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
import emu.lunarcore.game.gacha.PlayerGachaInfo;
|
||||||
import emu.lunarcore.game.inventory.Inventory;
|
import emu.lunarcore.game.inventory.Inventory;
|
||||||
import emu.lunarcore.game.scene.Scene;
|
import emu.lunarcore.game.scene.Scene;
|
||||||
|
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||||
|
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||||
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
import emu.lunarcore.proto.PlayerBasicInfoOuterClass.PlayerBasicInfo;
|
||||||
import emu.lunarcore.server.game.GameServer;
|
import emu.lunarcore.server.game.GameServer;
|
||||||
import emu.lunarcore.server.game.GameSession;
|
import emu.lunarcore.server.game.GameSession;
|
||||||
@@ -42,8 +47,9 @@ public class Player {
|
|||||||
@Indexed private String accountUid;
|
@Indexed private String accountUid;
|
||||||
private String name;
|
private String name;
|
||||||
private String signature;
|
private String signature;
|
||||||
private PlayerGender gender;
|
private int headIcon;
|
||||||
private int birthday;
|
private int birthday;
|
||||||
|
private PlayerGender gender;
|
||||||
private int curBasicType;
|
private int curBasicType;
|
||||||
|
|
||||||
private int level;
|
private int level;
|
||||||
@@ -61,6 +67,8 @@ public class Player {
|
|||||||
private int floorId;
|
private int floorId;
|
||||||
private int entryId;
|
private int entryId;
|
||||||
|
|
||||||
|
private Set<Integer> unlockedHeadIcons;
|
||||||
|
|
||||||
// Etc
|
// Etc
|
||||||
@Setter private transient boolean paused;
|
@Setter private transient boolean paused;
|
||||||
private transient int nextBattleId;
|
private transient int nextBattleId;
|
||||||
@@ -75,7 +83,7 @@ public class Player {
|
|||||||
|
|
||||||
@Deprecated // Morphia only
|
@Deprecated // Morphia only
|
||||||
public Player() {
|
public Player() {
|
||||||
this.curBasicType = 8001;
|
this.curBasicType = GameConstants.TRAILBLAZER_AVATAR_ID;
|
||||||
this.gender = PlayerGender.GENDER_MAN;
|
this.gender = PlayerGender.GENDER_MAN;
|
||||||
this.avatars = new AvatarStorage(this);
|
this.avatars = new AvatarStorage(this);
|
||||||
this.inventory = new Inventory(this);
|
this.inventory = new Inventory(this);
|
||||||
@@ -87,6 +95,8 @@ public class Player {
|
|||||||
this.session = session;
|
this.session = session;
|
||||||
this.accountUid = getAccount().getUid();
|
this.accountUid = getAccount().getUid();
|
||||||
this.name = GameConstants.DEFAULT_NAME;
|
this.name = GameConstants.DEFAULT_NAME;
|
||||||
|
this.signature = "";
|
||||||
|
this.headIcon = 200001;
|
||||||
this.level = 1;
|
this.level = 1;
|
||||||
this.stamina = GameConstants.MAX_STAMINA;
|
this.stamina = GameConstants.MAX_STAMINA;
|
||||||
|
|
||||||
@@ -95,6 +105,7 @@ public class Player {
|
|||||||
this.floorId = 20001001;
|
this.floorId = 20001001;
|
||||||
this.entryId = 2000101;
|
this.entryId = 2000101;
|
||||||
|
|
||||||
|
this.unlockedHeadIcons = new HashSet<>();
|
||||||
this.lineupManager = new LineupManager(this);
|
this.lineupManager = new LineupManager(this);
|
||||||
this.gachaInfo = new PlayerGachaInfo();
|
this.gachaInfo = new PlayerGachaInfo();
|
||||||
|
|
||||||
@@ -157,6 +168,27 @@ public class Player {
|
|||||||
this.sendPacket(new PacketPlayerSyncScNotify(this));
|
this.sendPacket(new PacketPlayerSyncScNotify(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Integer> getUnlockedHeadIcons() {
|
||||||
|
if (this.unlockedHeadIcons == null) {
|
||||||
|
this.unlockedHeadIcons = new HashSet<>();
|
||||||
|
}
|
||||||
|
return this.unlockedHeadIcons;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addHeadIcon(int headIconId) {
|
||||||
|
this.getUnlockedHeadIcons().add(headIconId);
|
||||||
|
this.sendPacket(new PacketPlayerSyncScNotify(this.toBoardData()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setHeadIcon(int id) {
|
||||||
|
if (this.getUnlockedHeadIcons().contains(id)) {
|
||||||
|
this.headIcon = id;
|
||||||
|
this.save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasLoggedIn() {
|
public boolean hasLoggedIn() {
|
||||||
return this.getSession() != null && this.getSession().getState() != SessionState.WAITING_FOR_TOKEN;
|
return this.getSession() != null && this.getSession().getState() != SessionState.WAITING_FOR_TOKEN;
|
||||||
}
|
}
|
||||||
@@ -363,6 +395,8 @@ public class Player {
|
|||||||
this.loadScene(planeId, floorId, entryId, this.getPos());
|
this.loadScene(planeId, floorId, entryId, this.getPos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Proto
|
||||||
|
|
||||||
public PlayerBasicInfo toProto() {
|
public PlayerBasicInfo toProto() {
|
||||||
var proto = PlayerBasicInfo.newInstance()
|
var proto = PlayerBasicInfo.newInstance()
|
||||||
.setNickname(this.getName())
|
.setNickname(this.getName())
|
||||||
@@ -376,4 +410,15 @@ public class Player {
|
|||||||
|
|
||||||
return proto;
|
return proto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BoardDataSync toBoardData() {
|
||||||
|
var proto = BoardDataSync.newInstance()
|
||||||
|
.setSignature(this.getSignature());
|
||||||
|
|
||||||
|
for (int id : this.getUnlockedHeadIcons()) {
|
||||||
|
proto.addUnlockedHeadIconList(HeadIcon.newInstance().setId(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package emu.lunarcore.server.packet.recv;
|
||||||
|
|
||||||
|
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.PacketGetPlayerBoardDataScRsp;
|
||||||
|
|
||||||
|
@Opcodes(CmdId.GetPlayerBoardDataCsReq)
|
||||||
|
public class HandlerGetPlayerBoardDataCsReq extends PacketHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||||
|
session.send(new PacketGetPlayerBoardDataScRsp(session.getPlayer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package emu.lunarcore.server.packet.recv;
|
||||||
|
|
||||||
|
import emu.lunarcore.proto.SetHeadIconCsReqOuterClass.SetHeadIconCsReq;
|
||||||
|
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.PacketSetHeadIconScRsp;
|
||||||
|
|
||||||
|
@Opcodes(CmdId.SetHeadIconCsReq)
|
||||||
|
public class HandlerSetHeadIconCsReq extends PacketHandler {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(GameSession session, byte[] header, byte[] data) throws Exception {
|
||||||
|
var req = SetHeadIconCsReq.parseFrom(data);
|
||||||
|
|
||||||
|
if (session.getPlayer().setHeadIcon(req.getId())) {
|
||||||
|
// Success
|
||||||
|
session.send(new PacketSetHeadIconScRsp(req.getId()));
|
||||||
|
} else {
|
||||||
|
// Failure (player probably didnt have the head icon)
|
||||||
|
session.send(new PacketSetHeadIconScRsp());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package emu.lunarcore.server.packet.send;
|
||||||
|
|
||||||
|
import emu.lunarcore.game.player.Player;
|
||||||
|
import emu.lunarcore.proto.GetPlayerBoardDataScRspOuterClass.GetPlayerBoardDataScRsp;
|
||||||
|
import emu.lunarcore.proto.HeadIconOuterClass.HeadIcon;
|
||||||
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
|
|
||||||
|
public class PacketGetPlayerBoardDataScRsp extends BasePacket {
|
||||||
|
|
||||||
|
public PacketGetPlayerBoardDataScRsp(Player player) {
|
||||||
|
super(CmdId.GetPlayerBoardDataScRsp);
|
||||||
|
|
||||||
|
var data = GetPlayerBoardDataScRsp.newInstance()
|
||||||
|
.setCurrentHeadIconId(player.getHeadIcon())
|
||||||
|
.setSignature(player.getSignature());
|
||||||
|
|
||||||
|
for (int id : player.getUnlockedHeadIcons()) {
|
||||||
|
data.addUnlockedHeadIconList(HeadIcon.newInstance().setId(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setData(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import emu.lunarcore.game.avatar.HeroPath;
|
|||||||
import emu.lunarcore.game.inventory.GameItem;
|
import emu.lunarcore.game.inventory.GameItem;
|
||||||
import emu.lunarcore.game.player.Player;
|
import emu.lunarcore.game.player.Player;
|
||||||
import emu.lunarcore.proto.AvatarSyncOuterClass.AvatarSync;
|
import emu.lunarcore.proto.AvatarSyncOuterClass.AvatarSync;
|
||||||
|
import emu.lunarcore.proto.BoardDataSyncOuterClass.BoardDataSync;
|
||||||
import emu.lunarcore.proto.PlayerSyncScNotifyOuterClass.PlayerSyncScNotify;
|
import emu.lunarcore.proto.PlayerSyncScNotifyOuterClass.PlayerSyncScNotify;
|
||||||
import emu.lunarcore.server.packet.BasePacket;
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
import emu.lunarcore.server.packet.CmdId;
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
@@ -27,6 +28,15 @@ public class PacketPlayerSyncScNotify extends BasePacket {
|
|||||||
this.setData(data);
|
this.setData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PacketPlayerSyncScNotify(BoardDataSync boardData) {
|
||||||
|
this();
|
||||||
|
|
||||||
|
var data = PlayerSyncScNotify.newInstance()
|
||||||
|
.setBoardDataSync(boardData);
|
||||||
|
|
||||||
|
this.setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
public PacketPlayerSyncScNotify(GameAvatar avatar) {
|
public PacketPlayerSyncScNotify(GameAvatar avatar) {
|
||||||
this();
|
this();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package emu.lunarcore.server.packet.send;
|
||||||
|
|
||||||
|
import emu.lunarcore.proto.SetHeadIconScRspOuterClass.SetHeadIconScRsp;
|
||||||
|
import emu.lunarcore.server.packet.BasePacket;
|
||||||
|
import emu.lunarcore.server.packet.CmdId;
|
||||||
|
|
||||||
|
public class PacketSetHeadIconScRsp extends BasePacket {
|
||||||
|
|
||||||
|
public PacketSetHeadIconScRsp() {
|
||||||
|
super(CmdId.SetHeadIconScRsp);
|
||||||
|
|
||||||
|
var data = SetHeadIconScRsp.newInstance()
|
||||||
|
.setRetcode(1);
|
||||||
|
|
||||||
|
this.setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketSetHeadIconScRsp(int headIconId) {
|
||||||
|
super(CmdId.SetHeadIconScRsp);
|
||||||
|
|
||||||
|
var data = SetHeadIconScRsp.newInstance()
|
||||||
|
.setId(headIconId);
|
||||||
|
|
||||||
|
this.setData(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user