Commit 8c32438b authored by Yazawazi's avatar Yazawazi Committed by Melledy
Browse files

feature(widget): simple implementation of widget

Simple implementation of a part of the gadget support, very rough, hard code variables, I am very sorry for that. It can now handle part of the gadget rig. More features and better support await PRs from others. if no one else does, I'll give it a try.
parent f45e106b
......@@ -82,6 +82,8 @@ public class Player {
private Set<Integer> flyCloakList;
private Set<Integer> costumeList;
private Integer widgetId;
@Transient private long nextGuid = 0;
@Transient private int peerId;
@Transient private World world;
......@@ -297,6 +299,14 @@ public class Player {
this.updateProfile();
}
public Integer getWidgetId() {
return widgetId;
}
public void setWidgetId(Integer widgetId) {
this.widgetId = widgetId;
}
public Position getPos() {
return pos;
}
......@@ -1141,6 +1151,9 @@ public class Player {
session.send(new PacketPlayerStoreNotify(this));
session.send(new PacketAvatarDataNotify(this));
session.send(new PacketAllWidgetDataNotify(this));
session.send(new PacketWidgetGadgetAllDataNotify());
getTodayMoonCard(); // The timer works at 0:0, some users log in after that, use this method to check if they have received a reward today or not. If not, send the reward.
session.send(new PacketPlayerEnterSceneNotify(this)); // Enter game world
......
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketGetShopRsp;
import emu.grasscutter.server.packet.send.PacketGetWidgetSlotRsp;
@Opcodes(PacketOpcodes.GetWidgetSlotReq)
public class HandlerGetWidgetSlotReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
// Unhandled
Player player = session.getPlayer();
session.send(new PacketGetWidgetSlotRsp(player));
}
}
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetWidgetSlotReqOuterClass;
import emu.grasscutter.net.proto.WidgetSlotOpOuterClass;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSetWidgetSlotRsp;
import emu.grasscutter.server.packet.send.PacketWidgetSlotChangeNotify;
@Opcodes(PacketOpcodes.SetWidgetSlotReq)
public class HandlerSetWidgetSlotReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SetWidgetSlotReqOuterClass.SetWidgetSlotReq req = SetWidgetSlotReqOuterClass.SetWidgetSlotReq.parseFrom(payload);
Player player = session.getPlayer();
player.setWidgetId(req.getMaterialId());
// WidgetSlotChangeNotify op & slot key
session.send(new PacketWidgetSlotChangeNotify(WidgetSlotOpOuterClass.WidgetSlotOp.DETACH));
// WidgetSlotChangeNotify slot
session.send(new PacketWidgetSlotChangeNotify(req.getMaterialId()));
// SetWidgetSlotRsp
session.send(new PacketSetWidgetSlotRsp(req.getMaterialId()));
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.AllWidgetDataNotifyOuterClass.AllWidgetDataNotify;
import emu.grasscutter.net.proto.LunchBoxDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotTagOuterClass;
import java.util.List;
import java.util.Map;
public class PacketAllWidgetDataNotify extends BasePacket {
public PacketAllWidgetDataNotify(Player player) {
super(PacketOpcodes.AllWidgetDataNotify);
// TODO: Implement this
AllWidgetDataNotify.Builder proto = AllWidgetDataNotify.newBuilder()
// If you want to implement this, feel free to do so. :)
.setLunchBoxData(
LunchBoxDataOuterClass.LunchBoxData.newBuilder().build()
)
// Maybe it's a little difficult, or it makes you upset :(
.addAllOneoffGatherPointDetectorDataList(List.of())
// So, goodbye, and hopefully sometime in the future o(* ̄▽ ̄*)ブ
.addAllCoolDownGroupDataList(List.of())
// I'll see your PR with a title that says (・∀・(・∀・(・∀・*)
.addAllAnchorPointList(List.of())
// "Complete implementation of widget functionality" b( ̄▽ ̄)d 
.addAllClientCollectorDataList(List.of())
// Good luck, my boy.
.addAllNormalCoolDownDataList(List.of());
if (player.getWidgetId() == null) {
proto.addAllSlotList(List.of());
} else {
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.setMaterialId(player.getWidgetId())
.build()
);
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_ATTACH_AVATAR)
.build()
);
}
AllWidgetDataNotify protoData = proto.build();
this.setData(protoData);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.GetWidgetSlotRspOuterClass;
import emu.grasscutter.net.proto.WidgetSlotDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotTagOuterClass;
import java.util.List;
public class PacketGetWidgetSlotRsp extends BasePacket {
public PacketGetWidgetSlotRsp(Player player) {
super(PacketOpcodes.GetWidgetSlotRsp);
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.Builder proto =
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp.newBuilder();
if (player.getWidgetId() == null) {
proto.addAllSlotList(List.of());
} else {
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.setMaterialId(player.getWidgetId())
.build()
);
proto.addSlotList(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setTag(WidgetSlotTagOuterClass.WidgetSlotTag.WIDGET_SLOT_ATTACH_AVATAR)
.build()
);
}
GetWidgetSlotRspOuterClass.GetWidgetSlotRsp protoData = proto.build();
this.setData(protoData);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SetWidgetSlotRspOuterClass;
public class PacketSetWidgetSlotRsp extends BasePacket {
public PacketSetWidgetSlotRsp(int materialId) {
super(PacketOpcodes.SetWidgetSlotRsp);
SetWidgetSlotRspOuterClass.SetWidgetSlotRsp proto = SetWidgetSlotRspOuterClass.SetWidgetSlotRsp.newBuilder()
.setMaterialId(materialId)
.build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WidgetGadgetAllDataNotifyOuterClass.WidgetGadgetAllDataNotify;
public class PacketWidgetGadgetAllDataNotify extends BasePacket {
public PacketWidgetGadgetAllDataNotify() {
super(PacketOpcodes.AllWidgetDataNotify);
WidgetGadgetAllDataNotify proto = WidgetGadgetAllDataNotify.newBuilder().build();
this.setData(proto);
}
}
package emu.grasscutter.server.packet.send;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.WidgetSlotChangeNotifyOuterClass;
import emu.grasscutter.net.proto.WidgetSlotDataOuterClass;
import emu.grasscutter.net.proto.WidgetSlotOpOuterClass;
public class PacketWidgetSlotChangeNotify extends BasePacket {
public PacketWidgetSlotChangeNotify(WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto) {
super(PacketOpcodes.WidgetSlotChangeNotify);
this.setData(proto);
}
public PacketWidgetSlotChangeNotify(WidgetSlotOpOuterClass.WidgetSlotOp op) {
super(PacketOpcodes.WidgetSlotChangeNotify);
WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder()
.setOp(op)
.setSlot(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.build()
)
.build();
this.setData(proto);
}
public PacketWidgetSlotChangeNotify(int materialId) {
super(PacketOpcodes.WidgetSlotChangeNotify);
WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify proto = WidgetSlotChangeNotifyOuterClass.WidgetSlotChangeNotify.newBuilder()
.setSlot(
WidgetSlotDataOuterClass.WidgetSlotData.newBuilder()
.setIsActive(true)
.setMaterialId(materialId)
.build()
)
.build();
this.setData(proto);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment