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
b2840b17
Commit
b2840b17
authored
Apr 24, 2022
by
Yazawazi
Committed by
GitHub
Apr 24, 2022
Browse files
Player level reward
parent
f536da0c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java
0 → 100644
View file @
b2840b17
package
emu.grasscutter.server.packet.recv
;
import
java.util.LinkedList
;
import
java.util.List
;
import
emu.grasscutter.data.GenshinData
;
import
emu.grasscutter.data.common.RewardItemData
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.PacketHandler
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.TakePlayerLevelRewardReqOuterClass.TakePlayerLevelRewardReq
;
import
emu.grasscutter.server.game.GameSession
;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
emu.grasscutter.server.packet.send.PacketTakePlayerLevelRewardRsp
;
@Opcodes
(
PacketOpcodes
.
TakePlayerLevelRewardReq
)
public
class
HandlerTakePlayerLevelRewardReq
extends
PacketHandler
{
@Override
public
void
handle
(
GameSession
session
,
byte
[]
header
,
byte
[]
payload
)
throws
Exception
{
TakePlayerLevelRewardReq
req
=
TakePlayerLevelRewardReq
.
parseFrom
(
payload
);
int
level
=
req
.
getLevel
();
int
rewardId
=
GenshinData
.
getPlayerLevelDataMap
().
get
(
level
).
getRewardId
();
if
(
rewardId
!=
0
)
{
List
<
RewardItemData
>
rewardItems
=
GenshinData
.
getRewardDataMap
().
get
(
rewardId
).
getRewardItemList
();
List
<
GenshinItem
>
items
=
new
LinkedList
<>();
for
(
RewardItemData
rewardItem
:
rewardItems
)
{
if
(
rewardItem
!=
null
)
{
if
(
rewardItem
.
getItemId
()
!=
0
)
{
items
.
add
(
new
GenshinItem
(
rewardItem
.
getItemId
(),
rewardItem
.
getItemCount
()));
}
}
}
session
.
getPlayer
().
getInventory
().
addItems
(
items
);
session
.
getPlayer
().
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
PlayerUpgradeReward
));
}
session
.
send
(
new
PacketTakePlayerLevelRewardRsp
(
level
,
rewardId
));
}
}
src/main/java/emu/grasscutter/server/packet/send/PacketTakePlayerLevelRewardRsp.java
0 → 100644
View file @
b2840b17
package
emu.grasscutter.server.packet.send
;
import
emu.grasscutter.net.packet.GenshinPacket
;
import
emu.grasscutter.net.packet.PacketOpcodes
;
import
emu.grasscutter.net.proto.TakePlayerLevelRewardRspOuterClass.TakePlayerLevelRewardRsp
;
public
class
PacketTakePlayerLevelRewardRsp
extends
GenshinPacket
{
public
PacketTakePlayerLevelRewardRsp
(
int
level
,
int
rewardId
)
{
super
(
PacketOpcodes
.
TakePlayerLevelRewardRsp
);
int
retcode
=
0
;
if
(
rewardId
==
0
)
{
retcode
=
1
;
}
TakePlayerLevelRewardRsp
proto
=
TakePlayerLevelRewardRsp
.
newBuilder
()
.
setLevel
(
level
)
.
setRewardId
(
rewardId
)
.
setRetcode
(
retcode
)
.
build
();
this
.
setData
(
proto
);
}
}
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