mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-26 18:22:54 +08:00
Call Player#onPlayerBorn
when the player is created
This commit is contained in:
parent
41be058509
commit
d6efaaea86
@ -1,89 +1,90 @@
|
|||||||
package emu.grasscutter.server.packet.recv;
|
package emu.grasscutter.server.packet.recv;
|
||||||
|
|
||||||
import static emu.grasscutter.config.Configuration.GAME_INFO;
|
import static emu.grasscutter.config.Configuration.GAME_INFO;
|
||||||
|
|
||||||
import emu.grasscutter.GameConstants;
|
import emu.grasscutter.GameConstants;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.command.commands.SendMailCommand.MailBuilder;
|
import emu.grasscutter.command.commands.SendMailCommand.MailBuilder;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.game.avatar.Avatar;
|
import emu.grasscutter.game.avatar.Avatar;
|
||||||
import emu.grasscutter.game.mail.Mail;
|
import emu.grasscutter.game.mail.Mail;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.net.packet.BasePacket;
|
import emu.grasscutter.net.packet.BasePacket;
|
||||||
import emu.grasscutter.net.packet.Opcodes;
|
import emu.grasscutter.net.packet.Opcodes;
|
||||||
import emu.grasscutter.net.packet.PacketHandler;
|
import emu.grasscutter.net.packet.PacketHandler;
|
||||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
import emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq;
|
import emu.grasscutter.net.proto.SetPlayerBornDataReqOuterClass.SetPlayerBornDataReq;
|
||||||
import emu.grasscutter.server.game.GameSession;
|
import emu.grasscutter.server.game.GameSession;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@Opcodes(PacketOpcodes.SetPlayerBornDataReq)
|
@Opcodes(PacketOpcodes.SetPlayerBornDataReq)
|
||||||
public class HandlerSetPlayerBornDataReq extends PacketHandler {
|
public class HandlerSetPlayerBornDataReq extends PacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||||
SetPlayerBornDataReq req = SetPlayerBornDataReq.parseFrom(payload);
|
SetPlayerBornDataReq req = SetPlayerBornDataReq.parseFrom(payload);
|
||||||
|
|
||||||
// Sanity checks
|
// Sanity checks
|
||||||
int avatarId = req.getAvatarId();
|
int avatarId = req.getAvatarId();
|
||||||
int startingSkillDepot;
|
int startingSkillDepot;
|
||||||
if (avatarId == GameConstants.MAIN_CHARACTER_MALE) {
|
if (avatarId == GameConstants.MAIN_CHARACTER_MALE) {
|
||||||
startingSkillDepot = 504;
|
startingSkillDepot = 504;
|
||||||
} else if (avatarId == GameConstants.MAIN_CHARACTER_FEMALE) {
|
} else if (avatarId == GameConstants.MAIN_CHARACTER_FEMALE) {
|
||||||
startingSkillDepot = 704;
|
startingSkillDepot = 704;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure resources folder is set
|
// Make sure resources folder is set
|
||||||
if (!GameData.getAvatarDataMap().containsKey(avatarId)) {
|
if (!GameData.getAvatarDataMap().containsKey(avatarId)) {
|
||||||
Grasscutter.getLogger()
|
Grasscutter.getLogger()
|
||||||
.error("No avatar data found! Please check your ExcelBinOutput folder.");
|
.error("No avatar data found! Please check your ExcelBinOutput folder.");
|
||||||
session.close();
|
session.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get player object
|
// Get player object
|
||||||
Player player = session.getPlayer();
|
Player player = session.getPlayer();
|
||||||
player.setNickname(req.getNickName());
|
player.setNickname(req.getNickName());
|
||||||
|
|
||||||
// Create avatar
|
// Create avatar
|
||||||
if (player.getAvatars().getAvatarCount() == 0) {
|
if (player.getAvatars().getAvatarCount() == 0) {
|
||||||
Avatar mainCharacter = new Avatar(avatarId);
|
Avatar mainCharacter = new Avatar(avatarId);
|
||||||
mainCharacter.setSkillDepotData(
|
mainCharacter.setSkillDepotData(
|
||||||
GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot));
|
GameData.getAvatarSkillDepotDataMap().get(startingSkillDepot));
|
||||||
// Manually handle adding to team
|
// Manually handle adding to team
|
||||||
player.addAvatar(mainCharacter, false);
|
player.addAvatar(mainCharacter, false);
|
||||||
player.setMainCharacterId(avatarId);
|
player.setMainCharacterId(avatarId);
|
||||||
player.setHeadImage(avatarId);
|
player.setHeadImage(avatarId);
|
||||||
player
|
player
|
||||||
.getTeamManager()
|
.getTeamManager()
|
||||||
.getCurrentSinglePlayerTeamInfo()
|
.getCurrentSinglePlayerTeamInfo()
|
||||||
.getAvatars()
|
.getAvatars()
|
||||||
.add(mainCharacter.getAvatarId());
|
.add(mainCharacter.getAvatarId());
|
||||||
player.save(); // TODO save player team in different object
|
player.save(); // TODO save player team in different object
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login done
|
// Login done
|
||||||
session.getPlayer().onLogin();
|
session.getPlayer().onLogin();
|
||||||
|
session.getPlayer().onPlayerBorn();
|
||||||
// Born resp packet
|
|
||||||
session.send(new BasePacket(PacketOpcodes.SetPlayerBornDataRsp));
|
// Born resp packet
|
||||||
|
session.send(new BasePacket(PacketOpcodes.SetPlayerBornDataRsp));
|
||||||
// Default mail
|
|
||||||
var welcomeMail = GAME_INFO.joinOptions.welcomeMail;
|
// Default mail
|
||||||
MailBuilder mailBuilder = new MailBuilder(player.getUid(), new Mail());
|
var welcomeMail = GAME_INFO.joinOptions.welcomeMail;
|
||||||
mailBuilder.mail.mailContent.title = welcomeMail.title;
|
MailBuilder mailBuilder = new MailBuilder(player.getUid(), new Mail());
|
||||||
mailBuilder.mail.mailContent.sender = welcomeMail.sender;
|
mailBuilder.mail.mailContent.title = welcomeMail.title;
|
||||||
// Please credit Grasscutter if changing something here. We don't condone commercial use of the
|
mailBuilder.mail.mailContent.sender = welcomeMail.sender;
|
||||||
// project.
|
// Please credit Grasscutter if changing something here. We don't condone commercial use of the
|
||||||
mailBuilder.mail.mailContent.content =
|
// project.
|
||||||
welcomeMail.content
|
mailBuilder.mail.mailContent.content =
|
||||||
+ "\n<type=\"browser\" text=\"GitHub\" href=\"https://github.com/Grasscutters/Grasscutter\"/>";
|
welcomeMail.content
|
||||||
mailBuilder.mail.itemList.addAll(Arrays.asList(welcomeMail.items));
|
+ "\n<type=\"browser\" text=\"GitHub\" href=\"https://github.com/Grasscutters/Grasscutter\"/>";
|
||||||
mailBuilder.mail.importance = 1;
|
mailBuilder.mail.itemList.addAll(Arrays.asList(welcomeMail.items));
|
||||||
player.sendMail(mailBuilder.mail);
|
mailBuilder.mail.importance = 1;
|
||||||
}
|
player.sendMail(mailBuilder.mail);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user