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
eb64b25f
Commit
eb64b25f
authored
May 15, 2022
by
Melledy
Browse files
Implement quest rewards
parent
2628227e
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/data/common/ItemParamData.java
View file @
eb64b25f
package
emu.grasscutter.data.common
;
package
emu.grasscutter.data.common
;
import
com.google.gson.annotations.SerializedName
;
public
class
ItemParamData
{
public
class
ItemParamData
{
@SerializedName
(
value
=
"Id"
,
alternate
={
"ItemId"
})
private
int
Id
;
private
int
Id
;
@SerializedName
(
value
=
"Count"
,
alternate
={
"ItemCount"
})
private
int
Count
;
private
int
Count
;
public
ItemParamData
()
{}
public
ItemParamData
()
{}
...
@@ -14,7 +19,15 @@ public class ItemParamData {
...
@@ -14,7 +19,15 @@ public class ItemParamData {
return
Id
;
return
Id
;
}
}
public
int
getItemId
()
{
return
Id
;
}
public
int
getCount
()
{
public
int
getCount
()
{
return
Count
;
return
Count
;
}
}
public
int
getItemCount
()
{
return
Count
;
}
}
}
src/main/java/emu/grasscutter/data/common/RewardItemData.java
deleted
100644 → 0
View file @
2628227e
package
emu.grasscutter.data.common
;
public
class
RewardItemData
{
private
int
ItemId
;
private
int
ItemCount
;
public
int
getItemId
()
{
return
ItemId
;
}
public
void
setItemId
(
int
itemId
)
{
ItemId
=
itemId
;
}
public
int
getItemCount
()
{
return
ItemCount
;
}
public
void
setItemCount
(
int
itemCount
)
{
ItemCount
=
itemCount
;
}
}
src/main/java/emu/grasscutter/data/def/RewardData.java
View file @
eb64b25f
...
@@ -4,24 +4,24 @@ import java.util.List;
...
@@ -4,24 +4,24 @@ import java.util.List;
import
emu.grasscutter.data.GameResource
;
import
emu.grasscutter.data.GameResource
;
import
emu.grasscutter.data.ResourceType
;
import
emu.grasscutter.data.ResourceType
;
import
emu.grasscutter.data.common.
RewardIte
mData
;
import
emu.grasscutter.data.common.
ItemPara
mData
;
@ResourceType
(
name
=
"RewardExcelConfigData.json"
)
@ResourceType
(
name
=
"RewardExcelConfigData.json"
)
public
class
RewardData
extends
GameResource
{
public
class
RewardData
extends
GameResource
{
public
int
RewardId
;
public
int
RewardId
;
public
List
<
RewardIte
mData
>
RewardItemList
;
public
List
<
ItemPara
mData
>
RewardItemList
;
@Override
@Override
public
int
getId
()
{
public
int
getId
()
{
return
RewardId
;
return
RewardId
;
}
}
public
List
<
RewardIte
mData
>
getRewardItemList
()
{
public
List
<
ItemPara
mData
>
getRewardItemList
()
{
return
RewardItemList
;
return
RewardItemList
;
}
}
@Override
@Override
public
void
onLoad
()
{
public
void
onLoad
()
{
RewardItemList
=
RewardItemList
.
stream
().
filter
(
i
->
i
.
getId
()
>
0
).
toList
();
}
}
}
}
src/main/java/emu/grasscutter/game/inventory/Inventory.java
View file @
eb64b25f
...
@@ -150,6 +150,14 @@ public class Inventory implements Iterable<GameItem> {
...
@@ -150,6 +150,14 @@ public class Inventory implements Iterable<GameItem> {
addItems
(
items
.
stream
().
map
(
param
->
new
GameItem
(
param
.
getItemId
(),
param
.
getCount
())).
toList
(),
null
);
addItems
(
items
.
stream
().
map
(
param
->
new
GameItem
(
param
.
getItemId
(),
param
.
getCount
())).
toList
(),
null
);
}
}
public
void
addItemParamDatas
(
Collection
<
ItemParamData
>
items
)
{
addItemParamDatas
(
items
,
null
);
}
public
void
addItemParamDatas
(
Collection
<
ItemParamData
>
items
,
ActionReason
reason
)
{
addItems
(
items
.
stream
().
map
(
param
->
new
GameItem
(
param
.
getItemId
(),
param
.
getCount
())).
toList
(),
reason
);
}
private
synchronized
GameItem
putItem
(
GameItem
item
)
{
private
synchronized
GameItem
putItem
(
GameItem
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/game/quest/GameMainQuest.java
View file @
eb64b25f
...
@@ -11,8 +11,11 @@ import dev.morphia.annotations.Id;
...
@@ -11,8 +11,11 @@ import dev.morphia.annotations.Id;
import
dev.morphia.annotations.Indexed
;
import
dev.morphia.annotations.Indexed
;
import
dev.morphia.annotations.Transient
;
import
dev.morphia.annotations.Transient
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.custom.MainQuestData
;
import
emu.grasscutter.data.def.RewardData
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.database.DatabaseHelper
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.player.Player
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.quest.enums.ParentQuestState
;
import
emu.grasscutter.game.quest.enums.ParentQuestState
;
import
emu.grasscutter.game.quest.enums.QuestState
;
import
emu.grasscutter.game.quest.enums.QuestState
;
import
emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest
;
import
emu.grasscutter.net.proto.ChildQuestOuterClass.ChildQuest
;
...
@@ -91,9 +94,23 @@ public class GameMainQuest {
...
@@ -91,9 +94,23 @@ public class GameMainQuest {
public
void
finish
()
{
public
void
finish
()
{
this
.
isFinished
=
true
;
this
.
isFinished
=
true
;
this
.
state
=
ParentQuestState
.
PARENT_QUEST_STATE_FINISHED
;
this
.
state
=
ParentQuestState
.
PARENT_QUEST_STATE_FINISHED
;
this
.
getOwner
().
getSession
().
send
(
new
PacketFinishedParentQuestUpdateNotify
(
this
));
this
.
getOwner
().
getSession
().
send
(
new
PacketFinishedParentQuestUpdateNotify
(
this
));
this
.
getOwner
().
getSession
().
send
(
new
PacketCodexDataUpdateNotify
(
this
));
this
.
getOwner
().
getSession
().
send
(
new
PacketCodexDataUpdateNotify
(
this
));
this
.
save
();
this
.
save
();
// Add rewards
MainQuestData
mainQuestData
=
GameData
.
getMainQuestDataMap
().
get
(
this
.
getParentQuestId
());
for
(
int
rewardId
:
mainQuestData
.
getRewardIdList
())
{
RewardData
rewardData
=
GameData
.
getRewardDataMap
().
get
(
rewardId
);
if
(
rewardData
==
null
)
{
continue
;
}
getOwner
().
getInventory
().
addItemParamDatas
(
rewardData
.
getRewardItemList
(),
ActionReason
.
QuestReward
);
}
}
}
public
void
save
()
{
public
void
save
()
{
...
...
src/main/java/emu/grasscutter/server/packet/recv/HandlerTakePlayerLevelRewardReq.java
View file @
eb64b25f
...
@@ -6,7 +6,8 @@ import java.util.Set;
...
@@ -6,7 +6,8 @@ import java.util.Set;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.GameData
;
import
emu.grasscutter.data.common.RewardItemData
;
import
emu.grasscutter.data.common.ItemParamData
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.inventory.GameItem
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.game.props.ActionReason
;
import
emu.grasscutter.net.packet.Opcodes
;
import
emu.grasscutter.net.packet.Opcodes
;
...
@@ -27,17 +28,8 @@ public class HandlerTakePlayerLevelRewardReq extends PacketHandler {
...
@@ -27,17 +28,8 @@ public class HandlerTakePlayerLevelRewardReq extends PacketHandler {
int
rewardId
=
GameData
.
getPlayerLevelDataMap
().
get
(
level
).
getRewardId
();
int
rewardId
=
GameData
.
getPlayerLevelDataMap
().
get
(
level
).
getRewardId
();
if
(
rewardId
!=
0
)
{
if
(
rewardId
!=
0
)
{
List
<
RewardItemData
>
rewardItems
=
GameData
.
getRewardDataMap
().
get
(
rewardId
).
getRewardItemList
();
List
<
ItemParamData
>
rewardItems
=
GameData
.
getRewardDataMap
().
get
(
rewardId
).
getRewardItemList
();
List
<
GameItem
>
items
=
new
LinkedList
<>();
session
.
getPlayer
().
getInventory
().
addItemParamDatas
(
rewardItems
,
ActionReason
.
PlayerUpgradeReward
);
for
(
RewardItemData
rewardItem
:
rewardItems
)
{
if
(
rewardItem
!=
null
)
{
if
(
rewardItem
.
getItemId
()
!=
0
)
{
items
.
add
(
new
GameItem
(
rewardItem
.
getItemId
(),
rewardItem
.
getItemCount
()));
}
}
}
session
.
getPlayer
().
getInventory
().
addItems
(
items
);
session
.
getPlayer
().
sendPacket
(
new
PacketItemAddHintNotify
(
items
,
ActionReason
.
PlayerUpgradeReward
));
Set
<
Integer
>
rewardedLevels
=
session
.
getPlayer
().
getRewardedLevels
();
Set
<
Integer
>
rewardedLevels
=
session
.
getPlayer
().
getRewardedLevels
();
rewardedLevels
.
add
(
level
);
rewardedLevels
.
add
(
level
);
session
.
getPlayer
().
setRewardedLevels
(
rewardedLevels
);
session
.
getPlayer
().
setRewardedLevels
(
rewardedLevels
);
...
...
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