Profile set birthday feature

This commit is contained in:
Miyucchi 2022-04-23 03:22:32 +02:00
parent 0c89c2dd73
commit 7fd0b371d0
4 changed files with 143 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import emu.grasscutter.game.friends.PlayerProfile;
import emu.grasscutter.game.gacha.PlayerGachaInfo;
import emu.grasscutter.game.inventory.GenshinItem;
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.player.PlayerBirthday;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.net.packet.GenshinPacket;
@ -73,6 +74,7 @@ public class GenshinPlayer {
private int nameCardId = 210001;
private Position pos;
private Position rotation;
private PlayerBirthday birthday;
private Map<Integer, Integer> properties;
private Set<Integer> nameCardList;
@ -139,6 +141,8 @@ public class GenshinPlayer {
this.combatInvokeHandler = new InvokeHandler(PacketCombatInvocationsNotify.class);
this.abilityInvokeHandler = new InvokeHandler(PacketAbilityInvocationsNotify.class);
this.clientAbilityInitFinishHandler = new InvokeHandler(PacketClientAbilityInitFinishNotify.class);
this.birthday = new PlayerBirthday();
}
// On player creation
@ -150,6 +154,7 @@ public class GenshinPlayer {
this.nickname = "Traveler";
this.signature = "";
this.teamManager = new TeamManager(this);
this.birthday = new PlayerBirthday();
this.setProperty(PlayerProperty.PROP_PLAYER_LEVEL, 1);
this.setProperty(PlayerProperty.PROP_IS_SPRING_AUTO_USE, 1);
this.setProperty(PlayerProperty.PROP_SPRING_AUTO_USE_PERCENT, 50);
@ -642,6 +647,15 @@ public class GenshinPlayer {
return onlineInfo.build();
}
public PlayerBirthday getBirthday(){
return this.birthday;
}
public void setBirthday(int d, int m) {
this.birthday = new PlayerBirthday(d, m);
this.updateProfile();
}
public SocialDetail.Builder getSocialDetail() {
SocialDetail.Builder social = SocialDetail.newBuilder()
.setUid(this.getUid())
@ -649,7 +663,7 @@ public class GenshinPlayer {
.setNickname(this.getNickname())
.setSignature(this.getSignature())
.setLevel(this.getLevel())
.setBirthday(Birthday.newBuilder())
.setBirthday(this.getBirthday().getFilledProtoWhenNotEmpty())
.setWorldLevel(this.getWorldLevel())
.setUnk1(1)
.setUnk3(1)

View File

@ -0,0 +1,68 @@
package emu.grasscutter.game.player;
import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday;
public class PlayerBirthday {
private int day;
private int month;
public PlayerBirthday(){
this.day = 0;
this.month = 0;
}
public PlayerBirthday(int day, int month){
this.day = day;
this.month = month;
}
public PlayerBirthday set(PlayerBirthday birth){
this.day = birth.day;
this.month = birth.month;
return this;
}
public PlayerBirthday set(int d, int m){
this.day = d;
this.month = m;
return this;
}
public PlayerBirthday setDay(int value){
this.day = value;
return this;
}
public PlayerBirthday setMonth(int value){
this.month = value;
return this;
}
public int getDay(){
return this.day;
}
public int getMonth(){
return this.month;
}
public Birthday toProto(){
return Birthday.newBuilder()
.setDay(this.getDay())
.setMonth(this.getMonth())
.build();
}
public Birthday.Builder getFilledProtoWhenNotEmpty(){
if(this.getDay() > 0)
{
return Birthday.newBuilder()
.setDay(this.getDay())
.setMonth(this.getMonth());
}
return Birthday.newBuilder();
}
}

View File

@ -0,0 +1,38 @@
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetPlayerSocialDetailRsp;
import emu.grasscutter.server.packet.send.PacketSetPlayerBirthdayRsp;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail;
import emu.grasscutter.net.proto.SetPlayerBirthdayReqOuterClass.SetPlayerBirthdayReq;
import com.google.gson.Gson;
@Opcodes(PacketOpcodes.SetPlayerBirthdayReq)
public class HandlerSetPlayerBirthdayReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SetPlayerBirthdayReq req = SetPlayerBirthdayReq.parseFrom(payload);
if(req.getBirth() != null && req.getBirth().getDay() > 0 && req.getBirth().getMonth() > 0)
{
int day = req.getBirth().getDay();
int month = req.getBirth().getMonth();
// Update birthday value
session.getPlayer().setBirthday(day, month);
// Save birthday month and day
session.getPlayer().save();
SocialDetail.Builder detail = session.getPlayer().getSocialDetail();
session.send(new PacketSetPlayerBirthdayRsp(session.getPlayer()));
session.send(new PacketGetPlayerSocialDetailRsp(detail));
}
}
}

View File

@ -0,0 +1,22 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.net.packet.GenshinPacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetPlayerBirthdayRspOuterClass.SetPlayerBirthdayRsp;
import emu.grasscutter.net.proto.BirthdayOuterClass.Birthday;
public class PacketSetPlayerBirthdayRsp extends GenshinPacket {
public PacketSetPlayerBirthdayRsp(GenshinPlayer player) {
super(PacketOpcodes.SetPlayerBirthdayRsp);
SetPlayerBirthdayRsp proto = SetPlayerBirthdayRsp.newBuilder()
.setBirth(player.getBirthday().toProto())
.build();
this.setData(proto);
if(Grasscutter.getConfig().DebugMode == true) Grasscutter.getLogger().info("Sending packet");
}
}