Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
9bf94f95
Commit
9bf94f95
authored
Apr 25, 2022
by
Benjamin Elsdon
Browse files
Receiving items in mail
parent
a548fe6c
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
GM_Handbook.txt
0 → 100644
View file @
9bf94f95
This diff is collapsed.
Click to expand it.
src/main/java/emu/grasscutter/command/commands/SendMailCommand.java
View file @
9bf94f95
...
@@ -24,7 +24,7 @@ public class SendMailCommand implements CommandHandler {
...
@@ -24,7 +24,7 @@ public class SendMailCommand implements CommandHandler {
sender
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
7006
);
sender
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
7006
);
}
}
sender
.
sendMail
(
new
Mail
(
new
Mail
.
MailContent
(
"Test"
,
"This is a test"
),
sender
.
sendMail
(
new
Mail
(
new
Mail
.
MailContent
(
"Test"
,
"This is a test"
),
new
ArrayList
<
Mail
.
MailItem
>(){{
add
(
new
Mail
.
MailItem
(
1062
));}},
new
ArrayList
<
Mail
.
MailItem
>(){{
add
(
new
Mail
.
MailItem
(
23411
));}},
Instant
.
now
().
getEpochSecond
()
+
4000
));
Instant
.
now
().
getEpochSecond
()
+
4000
));
sender
.
dropMessage
(
"Check your inbox"
);
sender
.
dropMessage
(
"Check your inbox"
);
...
...
src/main/java/emu/grasscutter/game/GenshinPlayer.java
View file @
9bf94f95
...
@@ -573,16 +573,46 @@ public class GenshinPlayer {
...
@@ -573,16 +573,46 @@ public class GenshinPlayer {
this
.
sendPacket
(
new
PacketPrivateChatNotify
(
sender
.
getUid
(),
this
.
getUid
(),
message
.
toString
()));
this
.
sendPacket
(
new
PacketPrivateChatNotify
(
sender
.
getUid
(),
this
.
getUid
(),
message
.
toString
()));
}
}
public
List
<
Mail
>
getMail
()
{
return
mail
;
}
// ---------------------MAIL------------------------
public
void
sendMail
(
Mail
message
)
{
public
List
<
Mail
>
getAllMail
()
{
return
this
.
mail
;
}
public
void
sendMail
(
Mail
message
)
{
this
.
mail
.
add
(
message
);
this
.
mail
.
add
(
message
);
message
.
_id
=
this
.
mail
.
size
()
+
1
;
message
.
_id
=
this
.
mail
.
size
()
+
1
;
this
.
save
();
this
.
save
();
this
.
sendPacket
(
new
PacketMailChangeNotify
(
this
,
message
));
this
.
sendPacket
(
new
PacketMailChangeNotify
(
this
,
message
));
}
}
public
boolean
deleteMail
(
int
mailId
)
{
Mail
message
=
getMailById
(
mailId
);
if
(
message
!=
null
)
{
this
.
mail
.
remove
(
message
);
this
.
save
();
return
true
;
}
return
false
;
}
public
Mail
getMailById
(
int
mailId
)
{
return
this
.
mail
.
stream
().
filter
(
message
->
message
.
_id
==
mailId
).
findFirst
().
orElse
(
null
);
}
public
int
getMailIndex
(
Mail
message
)
{
return
this
.
mail
.
indexOf
(
message
);
}
public
boolean
replaceMailByIndex
(
int
mailId
,
Mail
message
)
{
if
(
getMailById
(
mailId
)
!=
null
)
{
this
.
mail
.
set
(
mailId
,
message
);
return
true
;
}
else
{
return
false
;
}
}
public
void
interactWith
(
int
gadgetEntityId
)
{
public
void
interactWith
(
int
gadgetEntityId
)
{
GenshinEntity
entity
=
getScene
().
getEntityById
(
gadgetEntityId
);
GenshinEntity
entity
=
getScene
().
getEntityById
(
gadgetEntityId
);
...
...
src/main/java/emu/grasscutter/game/Mail.java
View file @
9bf94f95
...
@@ -55,6 +55,10 @@ public class Mail {
...
@@ -55,6 +55,10 @@ public class Mail {
this
.
stateValue
=
state
;
this
.
stateValue
=
state
;
}
}
public
int
getId
()
{
return
this
.
_id
;
}
@Entity
@Entity
public
static
class
MailContent
{
public
static
class
MailContent
{
public
String
title
;
public
String
title
;
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllMailReq.java
View file @
9bf94f95
...
@@ -15,7 +15,6 @@ public class HandlerGetAllMailReq extends PacketHandler {
...
@@ -15,7 +15,6 @@ public class HandlerGetAllMailReq 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
{
Grasscutter
.
getLogger
().
info
(
"Mail Req"
);
GetAllMailReqOuterClass
.
GetAllMailReq
req
=
GetAllMailReqOuterClass
.
GetAllMailReq
.
parseFrom
(
payload
);
GetAllMailReqOuterClass
.
GetAllMailReq
req
=
GetAllMailReqOuterClass
.
GetAllMailReq
.
parseFrom
(
payload
);
session
.
send
(
new
PacketGetAllMailRsp
(
session
.
getPlayer
(),
req
.
getIsGiftMail
()));
session
.
send
(
new
PacketGetAllMailRsp
(
session
.
getPlayer
(),
req
.
getIsGiftMail
()));
}
}
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java
View file @
9bf94f95
...
@@ -6,7 +6,6 @@ import emu.grasscutter.net.packet.PacketHandler;
...
@@ -6,7 +6,6 @@ import emu.grasscutter.net.packet.PacketHandler;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.GetMailItemReqOuterClass
;
import
emu.grasscutter.net.proto.GetMailItemReqOuterClass
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketGetAllMailRsp
;
import
emu.grasscutter.server.packet.send.PacketGetMailItemRsp
;
import
emu.grasscutter.server.packet.send.PacketGetMailItemRsp
;
@Opcodes
(
PacketOpcodes
.
GetMailItemReq
)
@Opcodes
(
PacketOpcodes
.
GetMailItemReq
)
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java
View file @
9bf94f95
package
emu.grasscutter.server.packet.send
;
package
emu.grasscutter.server.packet.send
;
import
com.google.gson.Gson
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.*
;
import
emu.grasscutter.net.proto.GetAllMailRspOuterClass.GetAllMailRsp
;
import
emu.grasscutter.net.proto.GetAllMailRspOuterClass.GetAllMailRsp
;
import
emu.grasscutter.net.proto.ItemParamOuterClass
;
import
emu.grasscutter.net.proto.MailDataOuterClass
;
import
emu.grasscutter.net.proto.MailDataOuterClass.MailData
;
import
emu.grasscutter.net.proto.MailDataOuterClass.MailData
;
import
emu.grasscutter.net.proto.MailItemOuterClass
;
import
emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent
;
import
emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent
;
import
javax.swing.*
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.Base64
;
import
java.util.List
;
import
java.util.List
;
...
@@ -20,7 +20,6 @@ public class PacketGetAllMailRsp extends GenshinPacket {
...
@@ -20,7 +20,6 @@ public class PacketGetAllMailRsp extends GenshinPacket {
public
PacketGetAllMailRsp
(
GenshinPlayer
player
,
boolean
isGiftMail
)
{
public
PacketGetAllMailRsp
(
GenshinPlayer
player
,
boolean
isGiftMail
)
{
super
(
PacketOpcodes
.
GetAllMailRsp
);
super
(
PacketOpcodes
.
GetAllMailRsp
);
Grasscutter
.
getLogger
().
info
(
String
.
valueOf
(
isGiftMail
));
if
(
isGiftMail
)
{
if
(
isGiftMail
)
{
// TODO: Gift Mail
// TODO: Gift Mail
...
@@ -34,11 +33,11 @@ public class PacketGetAllMailRsp extends GenshinPacket {
...
@@ -34,11 +33,11 @@ public class PacketGetAllMailRsp extends GenshinPacket {
}
}
}
else
{
}
else
{
if
(
player
.
getMail
().
size
()
!=
0
)
{
// Make sure the player has mail
if
(
player
.
get
All
Mail
().
size
()
!=
0
)
{
// Make sure the player has mail
GetAllMailRsp
.
Builder
proto
=
GetAllMailRsp
.
newBuilder
();
GetAllMailRsp
.
Builder
proto
=
GetAllMailRsp
.
newBuilder
();
List
<
MailData
>
mailDataList
=
new
ArrayList
<
MailData
>();
List
<
MailData
>
mailDataList
=
new
ArrayList
<
MailData
>();
for
(
Mail
message
:
player
.
getMail
())
{
for
(
Mail
message
:
player
.
get
All
Mail
())
{
if
(
message
.
stateValue
==
1
)
{
//Make sure it isn't a gift
if
(
message
.
stateValue
==
1
)
{
//Make sure it isn't a gift
MailTextContent
.
Builder
mailTextContent
=
MailTextContent
.
newBuilder
();
MailTextContent
.
Builder
mailTextContent
=
MailTextContent
.
newBuilder
();
mailTextContent
.
setTitle
(
message
.
mailContent
.
title
);
mailTextContent
.
setTitle
(
message
.
mailContent
.
title
);
...
@@ -73,7 +72,7 @@ public class PacketGetAllMailRsp extends GenshinPacket {
...
@@ -73,7 +72,7 @@ public class PacketGetAllMailRsp extends GenshinPacket {
}
}
proto
.
addAllMailList
(
mailDataList
);
proto
.
addAllMailList
(
mailDataList
);
proto
.
setIsTruncated
(
true
);
proto
.
setIsTruncated
(
false
);
// When enabled this will send a notification to the user that their inbox is full when opening the mailbox.
this
.
setData
(
proto
.
build
());
this
.
setData
(
proto
.
build
());
}
else
{
}
else
{
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java
View file @
9bf94f95
package
emu.grasscutter.server.packet.send
;
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.EquipParamOuterClass
;
import
emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp
;
import
emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp
;
import
emu.grasscutter.net.proto.ItemParamOuterClass
;
import
emu.grasscutter.net.proto.ItemParamOuterClass
;
import
emu.grasscutter.net.proto.MailItemOuterClass
;
import
emu.grasscutter.net.proto.MailItemOuterClass
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
PacketGetMailItemRsp
extends
GenshinPacket
{
public
class
PacketGetMailItemRsp
extends
GenshinPacket
{
...
@@ -17,15 +25,40 @@ public class PacketGetMailItemRsp extends GenshinPacket {
...
@@ -17,15 +25,40 @@ public class PacketGetMailItemRsp extends GenshinPacket {
//I'm assuming that this is to receive the attachments on the message.
//I'm assuming that this is to receive the attachments on the message.
// TODO: This.
// TODO: This.
//GetMailItemRsp.Builder proto = GetMailItemRsp.newBuilder();
List
<
Mail
>
claimedMessages
=
new
ArrayList
<>();
List
<
EquipParamOuterClass
.
EquipParam
>
claimedItems
=
new
ArrayList
<>();
//MailItemOuterClass.
MailItem.Builder
mailItem = MailItemOuterClass.
MailItem.newBuilder();
Get
MailItem
Rsp
.
Builder
proto
=
Get
MailItem
Rsp
.
newBuilder
();
//ItemParamOuterClass.ItemParam.Builder itemParam = ItemParamOuterClass.ItemParam.newBuilder();
for
(
int
mailId
:
mailList
)
{
Mail
message
=
player
.
getMailById
(
mailId
);
int
messageIndex
=
player
.
getMailIndex
(
message
);
//mailItem.setItemParam(itemParam);
message
.
isAttachmentGot
=
true
;
claimedMessages
.
add
(
message
);
//proto.addAllMailIdList(mailList);
player
.
replaceMailByIndex
(
messageIndex
,
message
);
//proto.addItemList();
for
(
Mail
.
MailItem
mailItem
:
message
.
itemList
)
{
//TODO: Actually give the item
EquipParamOuterClass
.
EquipParam
.
Builder
item
=
EquipParamOuterClass
.
EquipParam
.
newBuilder
();
item
.
setItemId
(
mailItem
.
itemId
);
item
.
setItemNum
(
mailItem
.
itemCount
);
claimedItems
.
add
(
item
.
build
());
GenshinItem
genshinItem
=
new
GenshinItem
(
GenshinData
.
getItemDataMap
().
get
(
mailItem
.
itemId
));
genshinItem
.
setCount
(
mailItem
.
itemCount
);
player
.
getInventory
().
addItem
(
genshinItem
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
genshinItem
,
ActionReason
.
MailAttachment
));
}
}
proto
.
addAllMailIdList
(
claimedMessages
.
stream
().
map
(
Mail:
:
getId
).
collect
(
Collectors
.
toList
()));
proto
.
addAllItemList
(
claimedItems
);
player
.
save
();
Grasscutter
.
getLogger
().
info
(
Grasscutter
.
getDispatchServer
().
getGsonFactory
().
toJson
(
proto
.
build
()));
this
.
setData
(
proto
.
build
());
player
.
getSession
().
send
(
new
PacketMailChangeNotify
(
player
,
claimedMessages
));
}
}
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketMailChangeNotify.java
View file @
9bf94f95
package
emu.grasscutter.server.packet.send
;
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.GenshinPacket
;
...
@@ -13,10 +14,15 @@ import java.util.List;
...
@@ -13,10 +14,15 @@ import java.util.List;
public
class
PacketMailChangeNotify
extends
GenshinPacket
{
public
class
PacketMailChangeNotify
extends
GenshinPacket
{
public
PacketMailChangeNotify
(
GenshinPlayer
player
,
Mail
message
)
{
public
PacketMailChangeNotify
(
GenshinPlayer
player
,
Mail
message
)
{
this
(
player
,
new
ArrayList
<
Mail
>(){{
add
(
message
);}});
}
public
PacketMailChangeNotify
(
GenshinPlayer
player
,
List
<
Mail
>
mailList
)
{
super
(
PacketOpcodes
.
MailChangeNotify
);
super
(
PacketOpcodes
.
MailChangeNotify
);
MailChangeNotifyOuterClass
.
MailChangeNotify
.
Builder
proto
=
MailChangeNotifyOuterClass
.
MailChangeNotify
.
newBuilder
();
MailChangeNotifyOuterClass
.
MailChangeNotify
.
Builder
proto
=
MailChangeNotifyOuterClass
.
MailChangeNotify
.
newBuilder
();
for
(
Mail
message
:
mailList
)
{
MailTextContentOuterClass
.
MailTextContent
.
Builder
mailTextContent
=
MailTextContentOuterClass
.
MailTextContent
.
newBuilder
();
MailTextContentOuterClass
.
MailTextContent
.
Builder
mailTextContent
=
MailTextContentOuterClass
.
MailTextContent
.
newBuilder
();
mailTextContent
.
setTitle
(
message
.
mailContent
.
title
);
mailTextContent
.
setTitle
(
message
.
mailContent
.
title
);
mailTextContent
.
setContent
(
message
.
mailContent
.
content
);
mailTextContent
.
setContent
(
message
.
mailContent
.
content
);
...
@@ -41,12 +47,15 @@ public class PacketMailChangeNotify extends GenshinPacket {
...
@@ -41,12 +47,15 @@ public class PacketMailChangeNotify extends GenshinPacket {
mailData
.
setSendTime
((
int
)
message
.
sendTime
);
mailData
.
setSendTime
((
int
)
message
.
sendTime
);
mailData
.
setExpireTime
((
int
)
message
.
expireTime
);
mailData
.
setExpireTime
((
int
)
message
.
expireTime
);
mailData
.
setImportance
(
message
.
importance
);
mailData
.
setImportance
(
message
.
importance
);
mailData
.
setIsRead
(
false
);
mailData
.
setIsRead
(
message
.
isRead
);
mailData
.
setIsAttachmentGot
(
false
);
mailData
.
setIsAttachmentGot
(
message
.
isAttachmentGot
);
mailData
.
setStateValue
(
message
.
stateValue
);
mailData
.
setStateValue
(
message
.
stateValue
);
proto
.
addMailList
(
mailData
.
build
());
proto
.
addMailList
(
mailData
.
build
());
Grasscutter
.
getLogger
().
info
(
Grasscutter
.
getDispatchServer
().
getGsonFactory
().
toJson
(
proto
.
build
()));
this
.
setData
(
proto
.
build
());
this
.
setData
(
proto
.
build
());
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment