Fix path changing for the trailblazer

This commit is contained in:
Melledy
2024-07-31 01:26:29 -07:00
parent 3ad4ca201b
commit 17e3bf0f20
5 changed files with 237 additions and 14 deletions

View File

@@ -0,0 +1,54 @@
package emu.lunarcore.command.commands;
import emu.lunarcore.GameConstants;
import emu.lunarcore.command.Command;
import emu.lunarcore.command.CommandArgs;
import emu.lunarcore.command.CommandHandler;
import emu.lunarcore.data.GameData;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.game.player.PlayerGender;
import emu.lunarcore.server.packet.send.PacketGetBasicInfoScRsp;
@Command(label = "gender", permission = "player.gender", requireTarget = true, desc = "/gender {male | female}. Sets the player gender.")
public class GenderCommand implements CommandHandler {
@Override
public void execute(CommandArgs args) {
// Set world level
Player target = args.getTarget();
// Get new gender
String gender = args.get(0).toLowerCase();
PlayerGender playerGender = switch (gender) {
case "m", "male", "boy", "man", "1" -> PlayerGender.GENDER_MAN;
case "f", "female", "girl", "woman", "2" -> PlayerGender.GENDER_WOMAN;
default -> null;
};
// Change gender
if (playerGender != null && playerGender != target.getGender()) {
// Get first hero excel that matches our new player gender
var excel = GameData.getMultiplePathAvatarExcelMap().values().stream()
.filter(path -> path.getBaseAvatarID() == GameConstants.TRAILBLAZER_AVATAR_ID && path.getGender() == playerGender)
.findFirst()
.orElse(null);
// Sanity check. Should never happen
if (excel == null) {
args.sendMessage("Error: No avatar path was found for this gender");
return;
}
// Set our main character's path
target.setAvatarPath(excel.getId());
// Send packet to update our gender
target.sendPacket(new PacketGetBasicInfoScRsp(target));
// Send response message
args.sendMessage("Gender for " + target.getName() + " set successfully");
} else {
args.sendMessage("Error: Invalid input");
}
}
}

View File

@@ -479,13 +479,19 @@ public class Player implements Tickable {
// Set new avatar path
avatar.setMultiPath(path);
// Set current avatar path
this.getCurAvatarPaths().put(excel.getBaseAvatarID(), pathId);
// Set gender if we are changing the main character
if (excel.getBaseAvatarID() == GameConstants.TRAILBLAZER_AVATAR_ID && excel.getGender() != null) {
this.gender = excel.getGender();
}
// Set current avatar path and save to database
this.getCurAvatarPaths().put(excel.getBaseAvatarID(), pathId);
this.save();
// Sync with client
this.sendPacket(new PacketAvatarPathChangedNotify(avatar, path));
this.sendPacket(new PacketPlayerSyncScNotify(avatar));
// Success
return pathId;
}

View File

@@ -11,7 +11,7 @@ public class HandlerGetBasicInfoCsReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] data) throws Exception {
session.send(new PacketGetBasicInfoScRsp(session));
session.send(new PacketGetBasicInfoScRsp(session.getPlayer()));
}
}

View File

@@ -1,20 +1,22 @@
package emu.lunarcore.server.packet.send;
import emu.lunarcore.game.player.Player;
import emu.lunarcore.proto.GetBasicInfoScRspOuterClass.GetBasicInfoScRsp;
import emu.lunarcore.proto.PlayerSettingInfoOuterClass.PlayerSettingInfo;
import emu.lunarcore.server.game.GameSession;
import emu.lunarcore.server.packet.BasePacket;
import emu.lunarcore.server.packet.CmdId;
public class PacketGetBasicInfoScRsp extends BasePacket {
public PacketGetBasicInfoScRsp(GameSession session) {
public PacketGetBasicInfoScRsp(Player player) {
super(CmdId.GetBasicInfoScRsp);
var data = GetBasicInfoScRsp.newInstance()
.setCurDay(1)
.setNextRecoverTime(session.getPlayer().getNextStaminaRecover() / 1000)
.setGameplayBirthday(session.getPlayer().getBirthday())
.setIsGenderSet(true)
.setGender(player.getGender().getVal())
.setNextRecoverTime(player.getNextStaminaRecover() / 1000)
.setGameplayBirthday(player.getBirthday())
.setPlayerSettingInfo(PlayerSettingInfo.newInstance());
this.setData(data);