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
d8189554
Commit
d8189554
authored
Apr 26, 2022
by
Melledy
Browse files
Call PacketItemAddHintNotify from addItem
parent
4420918f
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/command/commands/GiveCommand.java
View file @
d8189554
...
@@ -144,13 +144,11 @@ public final class GiveCommand implements CommandHandler {
...
@@ -144,13 +144,11 @@ public final class GiveCommand implements CommandHandler {
}
}
items
.
add
(
item
);
items
.
add
(
item
);
}
}
player
.
getInventory
().
addItems
(
items
);
player
.
getInventory
().
addItems
(
items
,
ActionReason
.
SubfieldDrop
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
SubfieldDrop
));
}
else
{
}
else
{
GenshinItem
genshinItem
=
new
GenshinItem
(
itemData
);
GenshinItem
genshinItem
=
new
GenshinItem
(
itemData
);
genshinItem
.
setCount
(
amount
);
genshinItem
.
setCount
(
amount
);
player
.
getInventory
().
addItem
(
genshinItem
);
player
.
getInventory
().
addItem
(
genshinItem
,
ActionReason
.
SubfieldDrop
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
genshinItem
,
ActionReason
.
SubfieldDrop
));
}
}
}
}
}
}
src/main/java/emu/grasscutter/game/GenshinPlayer.java
View file @
d8189554
...
@@ -584,8 +584,7 @@ public class GenshinPlayer {
...
@@ -584,8 +584,7 @@ public class GenshinPlayer {
moonCardGetTimes
.
add
(
now
);
moonCardGetTimes
.
add
(
now
);
addMoonCardDays
(
1
);
addMoonCardDays
(
1
);
GenshinItem
genshinItem
=
new
GenshinItem
(
201
,
90
);
GenshinItem
genshinItem
=
new
GenshinItem
(
201
,
90
);
getInventory
().
addItem
(
genshinItem
);
getInventory
().
addItem
(
genshinItem
,
ActionReason
.
BlessingRedeemReward
);
session
.
send
(
new
PacketItemAddHintNotify
(
genshinItem
,
ActionReason
.
BlessingRedeemReward
));
session
.
send
(
new
PacketCardProductRewardNotify
(
getMoonCardRemainDays
()));
session
.
send
(
new
PacketCardProductRewardNotify
(
getMoonCardRemainDays
()));
}
}
...
@@ -730,10 +729,9 @@ public class GenshinPlayer {
...
@@ -730,10 +729,9 @@ public class GenshinPlayer {
EntityItem
drop
=
(
EntityItem
)
entity
;
EntityItem
drop
=
(
EntityItem
)
entity
;
GenshinItem
item
=
new
GenshinItem
(
drop
.
getItemData
(),
drop
.
getCount
());
GenshinItem
item
=
new
GenshinItem
(
drop
.
getItemData
(),
drop
.
getCount
());
// Add to inventory
// Add to inventory
boolean
success
=
getInventory
().
addItem
(
item
);
boolean
success
=
getInventory
().
addItem
(
item
,
ActionReason
.
SubfieldDrop
);
if
(
success
)
{
if
(
success
)
{
this
.
sendPacket
(
new
PacketGadgetInteractRsp
(
drop
,
InteractType
.
INTERACT_PICK_ITEM
));
this
.
sendPacket
(
new
PacketGadgetInteractRsp
(
drop
,
InteractType
.
INTERACT_PICK_ITEM
));
this
.
sendPacket
(
new
PacketItemAddHintNotify
(
item
,
ActionReason
.
SubfieldDrop
));
}
}
}
}
...
...
src/main/java/emu/grasscutter/game/inventory/Inventory.java
View file @
d8189554
...
@@ -17,8 +17,10 @@ import emu.grasscutter.game.GenshinPlayer;
...
@@ -17,8 +17,10 @@ import emu.grasscutter.game.GenshinPlayer;
import
emu.grasscutter.game.avatar.AvatarStorage
;
import
emu.grasscutter.game.avatar.AvatarStorage
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.avatar.GenshinAvatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.entity.EntityAvatar
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam
;
import
emu.grasscutter.net.proto.ItemParamOuterClass.ItemParam
;
import
emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify
;
import
emu.grasscutter.server.packet.send.PacketAvatarEquipChangeNotify
;
import
emu.grasscutter.server.packet.send.PacketItemAddHintNotify
;
import
emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify
;
import
emu.grasscutter.server.packet.send.PacketStoreItemChangeNotify
;
import
emu.grasscutter.server.packet.send.PacketStoreItemDelNotify
;
import
emu.grasscutter.server.packet.send.PacketStoreItemDelNotify
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
import
it.unimi.dsi.fastutil.ints.Int2ObjectMap
;
...
@@ -86,7 +88,7 @@ public class Inventory implements Iterable<GenshinItem> {
...
@@ -86,7 +88,7 @@ public class Inventory implements Iterable<GenshinItem> {
return
addItem
(
item
);
return
addItem
(
item
);
}
}
public
boolean
addItem
(
GenshinItem
item
)
{
public
boolean
addItem
(
GenshinItem
item
)
{
GenshinItem
result
=
putItem
(
item
);
GenshinItem
result
=
putItem
(
item
);
...
@@ -98,7 +100,21 @@ public class Inventory implements Iterable<GenshinItem> {
...
@@ -98,7 +100,21 @@ public class Inventory implements Iterable<GenshinItem> {
return
false
;
return
false
;
}
}
public
boolean
addItem
(
GenshinItem
item
,
ActionReason
reason
)
{
boolean
result
=
addItem
(
item
);
if
(
result
&&
reason
!=
null
)
{
getPlayer
().
sendPacket
(
new
PacketItemAddHintNotify
(
item
,
reason
));
}
return
result
;
}
public
void
addItems
(
Collection
<
GenshinItem
>
items
)
{
public
void
addItems
(
Collection
<
GenshinItem
>
items
)
{
this
.
addItems
(
items
,
null
);
}
public
void
addItems
(
Collection
<
GenshinItem
>
items
,
ActionReason
reason
)
{
List
<
GenshinItem
>
changedItems
=
new
LinkedList
<>();
List
<
GenshinItem
>
changedItems
=
new
LinkedList
<>();
for
(
GenshinItem
item
:
items
)
{
for
(
GenshinItem
item
:
items
)
{
...
@@ -108,23 +124,21 @@ public class Inventory implements Iterable<GenshinItem> {
...
@@ -108,23 +124,21 @@ public class Inventory implements Iterable<GenshinItem> {
}
}
}
}
getPlayer
().
sendPacket
(
new
PacketStoreItemChangeNotify
(
changedItems
));
if
(
changedItems
.
size
()
==
0
)
{
}
return
;
}
public
void
addItemParams
(
Collection
<
ItemParam
>
items
)
{
List
<
GenshinItem
>
changedItems
=
new
LinkedList
<>();
for
(
ItemParam
itemParam
:
items
)
{
if
(
reason
!=
null
)
{
GenshinItem
toAdd
=
new
GenshinItem
(
itemParam
.
getItemId
(),
itemParam
.
getCount
());
getPlayer
().
sendPacket
(
new
PacketItemAddHintNotify
(
changedItems
,
reason
));
GenshinItem
result
=
putItem
(
toAdd
);
if
(
result
!=
null
)
{
changedItems
.
add
(
result
);
}
}
}
getPlayer
().
sendPacket
(
new
PacketStoreItemChangeNotify
(
changedItems
));
getPlayer
().
sendPacket
(
new
PacketStoreItemChangeNotify
(
changedItems
));
}
}
public
void
addItemParams
(
Collection
<
ItemParam
>
items
)
{
addItems
(
items
.
stream
().
map
(
param
->
new
GenshinItem
(
param
.
getItemId
(),
param
.
getCount
())).
toList
(),
null
);
}
private
synchronized
GenshinItem
putItem
(
GenshinItem
item
)
{
private
synchronized
GenshinItem
putItem
(
GenshinItem
item
)
{
// Dont add items that dont have a valid item definition.
// Dont add items that dont have a valid item definition.
if
(
item
.
getItemData
()
==
null
)
{
if
(
item
.
getItemData
()
==
null
)
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerAvatarFetterLevelRewardReq.java
View file @
d8189554
...
@@ -44,8 +44,7 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler {
...
@@ -44,8 +44,7 @@ public class HandlerAvatarFetterLevelRewardReq extends PacketHandler {
}
}
GenshinItem
item
=
new
GenshinItem
(
cardId
);
GenshinItem
item
=
new
GenshinItem
(
cardId
);
session
.
getPlayer
().
getInventory
().
addItem
(
item
);
session
.
getPlayer
().
getInventory
().
addItem
(
item
,
ActionReason
.
FetterLevelReward
);
session
.
getPlayer
().
sendPacket
(
new
PacketItemAddHintNotify
(
item
,
ActionReason
.
FetterLevelReward
));
session
.
getPlayer
().
sendPacket
(
new
PacketUnlockNameCardNotify
(
cardId
));
session
.
getPlayer
().
sendPacket
(
new
PacketUnlockNameCardNotify
(
cardId
));
session
.
send
(
new
PacketAvatarFetterDataNotify
(
avatar
));
session
.
send
(
new
PacketAvatarFetterDataNotify
(
avatar
));
session
.
send
(
new
PacketAvatarDataNotify
(
avatar
.
getPlayer
()));
session
.
send
(
new
PacketAvatarDataNotify
(
avatar
.
getPlayer
()));
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketGetMailItemRsp.java
View file @
d8189554
...
@@ -54,8 +54,7 @@ public class PacketGetMailItemRsp extends GenshinPacket {
...
@@ -54,8 +54,7 @@ public class PacketGetMailItemRsp extends GenshinPacket {
genshinItem
.
setCount
(
mailItem
.
itemCount
);
genshinItem
.
setCount
(
mailItem
.
itemCount
);
genshinItem
.
setLevel
(
mailItem
.
itemLevel
);
genshinItem
.
setLevel
(
mailItem
.
itemLevel
);
genshinItem
.
setPromoteLevel
(
promoteLevel
);
genshinItem
.
setPromoteLevel
(
promoteLevel
);
player
.
getInventory
().
addItem
(
genshinItem
);
player
.
getInventory
().
addItem
(
genshinItem
,
ActionReason
.
MailAttachment
);
player
.
sendPacket
(
new
PacketItemAddHintNotify
(
genshinItem
,
ActionReason
.
MailAttachment
));
}
}
message
.
isAttachmentGot
=
true
;
message
.
isAttachmentGot
=
true
;
...
...
src/main/java/emu/grasscutter/server/packet/send/PacketItemAddHintNotify.java
View file @
d8189554
package
emu.grasscutter.server.packet.send
;
package
emu.grasscutter.server.packet.send
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
emu.grasscutter.game.inventory.GenshinItem
;
import
emu.grasscutter.game.inventory.GenshinItem
;
...
@@ -21,7 +22,7 @@ public class PacketItemAddHintNotify extends GenshinPacket {
...
@@ -21,7 +22,7 @@ public class PacketItemAddHintNotify extends GenshinPacket {
this
.
setData
(
proto
);
this
.
setData
(
proto
);
}
}
public
PacketItemAddHintNotify
(
List
<
GenshinItem
>
items
,
ActionReason
reason
)
{
public
PacketItemAddHintNotify
(
Collection
<
GenshinItem
>
items
,
ActionReason
reason
)
{
super
(
PacketOpcodes
.
ItemAddHintNotify
);
super
(
PacketOpcodes
.
ItemAddHintNotify
);
ItemAddHintNotify
.
Builder
proto
=
ItemAddHintNotify
.
newBuilder
()
ItemAddHintNotify
.
Builder
proto
=
ItemAddHintNotify
.
newBuilder
()
...
...
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