mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-24 17:32:52 +08:00
Implement quest rewards
This commit is contained in:
parent
2628227e7e
commit
eb64b25f12
@ -1,7 +1,12 @@
|
|||||||
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 {
|
|||||||
return Id;
|
return Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getItemId() {
|
||||||
|
return Id;
|
||||||
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getItemCount() {
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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.RewardItemData;
|
import emu.grasscutter.data.common.ItemParamData;
|
||||||
|
|
||||||
@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<RewardItemData> RewardItemList;
|
public List<ItemParamData> RewardItemList;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return RewardId;
|
return RewardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RewardItemData> getRewardItemList() {
|
public List<ItemParamData> getRewardItemList() {
|
||||||
return RewardItemList;
|
return RewardItemList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
|
RewardItemList = RewardItemList.stream().filter(i -> i.getId() > 0).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
@ -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 {
|
|||||||
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() {
|
||||||
|
@ -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 {
|
|||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user