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
785effe8
Commit
785effe8
authored
Apr 25, 2022
by
Benjamin Elsdon
Browse files
Receiving items in mail
parent
94a75cf9
Changes
9
Show whitespace changes
Inline
Side-by-side
GM_Handbook.txt
0 → 100644
View file @
785effe8
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/main/java/emu/grasscutter/command/commands/SendMailCommand.java
View file @
785effe8
...
...
@@ -24,7 +24,7 @@ public class SendMailCommand implements CommandHandler {
sender
=
Grasscutter
.
getGameServer
().
getPlayerByUid
(
7006
);
}
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
));
sender
.
dropMessage
(
"Check your inbox"
);
...
...
src/main/java/emu/grasscutter/game/GenshinPlayer.java
View file @
785effe8
...
...
@@ -23,7 +23,6 @@ import emu.grasscutter.game.props.ActionReason;
import
emu.grasscutter.game.props.PlayerProperty
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.proto.AbilityInvokeEntryOuterClass.AbilityInvokeEntry
;
import
emu.grasscutter.net.proto.BirthdayOuterClass.Birthday
;
import
emu.grasscutter.net.proto.CombatInvokeEntryOuterClass.CombatInvokeEntry
;
import
emu.grasscutter.net.proto.HeadImageOuterClass.HeadImage
;
import
emu.grasscutter.net.proto.InteractTypeOuterClass.InteractType
;
...
...
@@ -595,16 +594,46 @@ public class GenshinPlayer {
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
);
message
.
_id
=
this
.
mail
.
size
()
+
1
;
this
.
save
();
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
)
{
GenshinEntity
entity
=
getScene
().
getEntityById
(
gadgetEntityId
);
...
...
src/main/java/emu/grasscutter/game/Mail.java
View file @
785effe8
...
...
@@ -55,6 +55,10 @@ public class Mail {
this
.
stateValue
=
state
;
}
public
int
getId
()
{
return
this
.
_id
;
}
@Entity
public
static
class
MailContent
{
public
String
title
;
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetAllMailReq.java
View file @
785effe8
...
...
@@ -15,7 +15,6 @@ public class HandlerGetAllMailReq extends PacketHandler {
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
Grasscutter
.
getLogger
().
info
(
"Mail Req"
);
GetAllMailReqOuterClass
.
GetAllMailReq
req
=
GetAllMailReqOuterClass
.
GetAllMailReq
.
parseFrom
(
payload
);
session
.
send
(
new
PacketGetAllMailRsp
(
session
.
getPlayer
(),
req
.
getIsGiftMail
()));
}
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerGetMailItemReq.java
View file @
785effe8
...
...
@@ -6,7 +6,6 @@ import emu.grasscutter.net.packet.PacketHandler;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.GetMailItemReqOuterClass
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketGetAllMailRsp
;
import
emu.grasscutter.server.packet.send.PacketGetMailItemRsp
;
@Opcodes
(
PacketOpcodes
.
GetMailItemReq
)
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketGetAllMailRsp.java
View file @
785effe8
package
emu.grasscutter.server.packet.send
;
import
com.google.gson.Gson
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.*
;
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.MailItemOuterClass
;
import
emu.grasscutter.net.proto.MailTextContentOuterClass.MailTextContent
;
import
javax.swing.*
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.List
;
...
...
@@ -20,7 +20,6 @@ public class PacketGetAllMailRsp extends GenshinPacket {
public
PacketGetAllMailRsp
(
GenshinPlayer
player
,
boolean
isGiftMail
)
{
super
(
PacketOpcodes
.
GetAllMailRsp
);
Grasscutter
.
getLogger
().
info
(
String
.
valueOf
(
isGiftMail
));
if
(
isGiftMail
)
{
// TODO: Gift Mail
...
...
@@ -34,11 +33,11 @@ public class PacketGetAllMailRsp extends GenshinPacket {
}
}
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
();
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
MailTextContent
.
Builder
mailTextContent
=
MailTextContent
.
newBuilder
();
mailTextContent
.
setTitle
(
message
.
mailContent
.
title
);
...
...
@@ -73,7 +72,7 @@ public class PacketGetAllMailRsp extends GenshinPacket {
}
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
());
}
else
{
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java
View file @
785effe8
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GenshinData
;
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.PacketOpcodes
;
import
emu.grasscutter.net.proto.EquipParamOuterClass
;
import
emu.grasscutter.net.proto.GetMailItemRspOuterClass.GetMailItemRsp
;
import
emu.grasscutter.net.proto.ItemParamOuterClass
;
import
emu.grasscutter.net.proto.MailItemOuterClass
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
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.
// 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);
//proto.addItemList();
player
.
replaceMailByIndex
(
messageIndex
,
message
);
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 @
785effe8
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.game.GenshinPlayer
;
import
emu.grasscutter.game.Mail
;
import
emu.grasscutter.net.packet.GenshinPacket
;
...
...
@@ -13,10 +14,15 @@ import java.util.List;
public
class
PacketMailChangeNotify
extends
GenshinPacket
{
public
PacketMailChangeNotify
(
GenshinPlayer
player
,
Mail
message
)
{
this
(
player
,
new
ArrayList
<
Mail
>(){{
add
(
message
);}});
}
public
PacketMailChangeNotify
(
GenshinPlayer
player
,
List
<
Mail
>
mailList
)
{
super
(
PacketOpcodes
.
MailChangeNotify
);
MailChangeNotifyOuterClass
.
MailChangeNotify
.
Builder
proto
=
MailChangeNotifyOuterClass
.
MailChangeNotify
.
newBuilder
();
for
(
Mail
message
:
mailList
)
{
MailTextContentOuterClass
.
MailTextContent
.
Builder
mailTextContent
=
MailTextContentOuterClass
.
MailTextContent
.
newBuilder
();
mailTextContent
.
setTitle
(
message
.
mailContent
.
title
);
mailTextContent
.
setContent
(
message
.
mailContent
.
content
);
...
...
@@ -41,12 +47,15 @@ public class PacketMailChangeNotify extends GenshinPacket {
mailData
.
setSendTime
((
int
)
message
.
sendTime
);
mailData
.
setExpireTime
((
int
)
message
.
expireTime
);
mailData
.
setImportance
(
message
.
importance
);
mailData
.
setIsRead
(
false
);
mailData
.
setIsAttachmentGot
(
false
);
mailData
.
setIsRead
(
message
.
isRead
);
mailData
.
setIsAttachmentGot
(
message
.
isAttachmentGot
);
mailData
.
setStateValue
(
message
.
stateValue
);
proto
.
addMailList
(
mailData
.
build
());
Grasscutter
.
getLogger
().
info
(
Grasscutter
.
getDispatchServer
().
getGsonFactory
().
toJson
(
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